]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-3.0-3.15.5-201407131211.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-3.0-3.15.5-201407131211.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 e6b01ed..74dbc85 100644
291 --- a/Makefile
292 +++ b/Makefile
293 @@ -246,7 +246,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
294 HOSTCC = gcc
295 HOSTCXX = g++
296 HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
297 -HOSTCXXFLAGS = -O2
298 +HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
299 +HOSTCFLAGS += $(call cc-option, -Wno-empty-body)
300 +HOSTCXXFLAGS = -O2 -Wall -W -Wno-array-bounds
301
302 ifeq ($(shell $(HOSTCC) -v 2>&1 | grep -c "clang version"), 1)
303 HOSTCFLAGS += -Wno-unused-value -Wno-unused-parameter \
304 @@ -438,8 +440,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
305 # Rules shared between *config targets and build targets
306
307 # Basic helpers built in scripts/
308 -PHONY += scripts_basic
309 -scripts_basic:
310 +PHONY += scripts_basic gcc-plugins
311 +scripts_basic: gcc-plugins
312 $(Q)$(MAKE) $(build)=scripts/basic
313 $(Q)rm -f .tmp_quiet_recordmcount
314
315 @@ -600,6 +602,72 @@ else
316 KBUILD_CFLAGS += -O2
317 endif
318
319 +ifndef DISABLE_PAX_PLUGINS
320 +ifeq ($(call cc-ifversion, -ge, 0408, y), y)
321 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCXX)" "$(HOSTCXX)" "$(CC)")
322 +else
323 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
324 +endif
325 +ifneq ($(PLUGINCC),)
326 +ifdef CONFIG_PAX_CONSTIFY_PLUGIN
327 +CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
328 +endif
329 +ifdef CONFIG_PAX_MEMORY_STACKLEAK
330 +STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
331 +STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
332 +endif
333 +ifdef CONFIG_KALLOCSTAT_PLUGIN
334 +KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
335 +endif
336 +ifdef CONFIG_PAX_KERNEXEC_PLUGIN
337 +KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
338 +KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
339 +KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
340 +endif
341 +ifdef CONFIG_GRKERNSEC_RANDSTRUCT
342 +RANDSTRUCT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/randomize_layout_plugin.so -DRANDSTRUCT_PLUGIN
343 +ifdef CONFIG_GRKERNSEC_RANDSTRUCT_PERFORMANCE
344 +RANDSTRUCT_PLUGIN_CFLAGS += -fplugin-arg-randomize_layout_plugin-performance-mode
345 +endif
346 +endif
347 +ifdef CONFIG_CHECKER_PLUGIN
348 +ifeq ($(call cc-ifversion, -ge, 0406, y), y)
349 +CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
350 +endif
351 +endif
352 +COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
353 +ifdef CONFIG_PAX_SIZE_OVERFLOW
354 +SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
355 +endif
356 +ifdef CONFIG_PAX_LATENT_ENTROPY
357 +LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
358 +endif
359 +ifdef CONFIG_PAX_MEMORY_STRUCTLEAK
360 +STRUCTLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/structleak_plugin.so -DSTRUCTLEAK_PLUGIN
361 +endif
362 +GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
363 +GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
364 +GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS) $(STRUCTLEAK_PLUGIN_CFLAGS)
365 +GCC_PLUGINS_CFLAGS += $(RANDSTRUCT_PLUGIN_CFLAGS)
366 +GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
367 +export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN LATENT_ENTROPY_PLUGIN_CFLAGS
368 +ifeq ($(KBUILD_EXTMOD),)
369 +gcc-plugins:
370 + $(Q)$(MAKE) $(build)=tools/gcc
371 +else
372 +gcc-plugins: ;
373 +endif
374 +else
375 +gcc-plugins:
376 +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
377 + $(error Your gcc installation does not support plugins. If the necessary headers for plugin support are missing, they should be installed. On Debian, apt-get install gcc-<ver>-plugin-dev. If you choose to ignore this error and lessen the improvements provided by this patch, re-run make with the DISABLE_PAX_PLUGINS=y argument.))
378 +else
379 + $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
380 +endif
381 + $(Q)echo "PAX_MEMORY_STACKLEAK, constification, PAX_LATENT_ENTROPY and other features will be less secure. PAX_SIZE_OVERFLOW will not be active."
382 +endif
383 +endif
384 +
385 include $(srctree)/arch/$(SRCARCH)/Makefile
386
387 ifdef CONFIG_READABLE_ASM
388 @@ -816,7 +884,7 @@ export mod_sign_cmd
389
390
391 ifeq ($(KBUILD_EXTMOD),)
392 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
393 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
394
395 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
396 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
397 @@ -865,6 +933,8 @@ endif
398
399 # The actual objects are generated when descending,
400 # make sure no implicit rule kicks in
401 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
402 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
403 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
404
405 # Handle descending into subdirectories listed in $(vmlinux-dirs)
406 @@ -874,7 +944,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
407 # Error messages still appears in the original language
408
409 PHONY += $(vmlinux-dirs)
410 -$(vmlinux-dirs): prepare scripts
411 +$(vmlinux-dirs): gcc-plugins prepare scripts
412 $(Q)$(MAKE) $(build)=$@
413
414 define filechk_kernel.release
415 @@ -917,10 +987,13 @@ prepare1: prepare2 $(version_h) include/generated/utsrelease.h \
416
417 archprepare: archheaders archscripts prepare1 scripts_basic
418
419 +prepare0: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
420 +prepare0: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
421 prepare0: archprepare FORCE
422 $(Q)$(MAKE) $(build)=.
423
424 # All the preparing..
425 +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
426 prepare: prepare0
427
428 # Generate some files
429 @@ -1028,6 +1101,8 @@ all: modules
430 # using awk while concatenating to the final file.
431
432 PHONY += modules
433 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
434 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
435 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
436 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
437 @$(kecho) ' Building modules, stage 2.';
438 @@ -1043,7 +1118,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
439
440 # Target to prepare building external modules
441 PHONY += modules_prepare
442 -modules_prepare: prepare scripts
443 +modules_prepare: gcc-plugins prepare scripts
444
445 # Target to install modules
446 PHONY += modules_install
447 @@ -1109,7 +1184,10 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
448 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
449 signing_key.priv signing_key.x509 x509.genkey \
450 extra_certificates signing_key.x509.keyid \
451 - signing_key.x509.signer include/linux/version.h
452 + signing_key.x509.signer include/linux/version.h \
453 + tools/gcc/size_overflow_plugin/size_overflow_hash_aux.h \
454 + tools/gcc/size_overflow_plugin/size_overflow_hash.h \
455 + tools/gcc/randomize_layout_seed.h
456
457 # clean - Delete most, but leave enough to build external modules
458 #
459 @@ -1148,7 +1226,7 @@ distclean: mrproper
460 @find $(srctree) $(RCS_FIND_IGNORE) \
461 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
462 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
463 - -o -name '.*.rej' -o -name '*%' -o -name 'core' \) \
464 + -o -name '.*.rej' -o -name '*.so' -o -name '*%' -o -name 'core' \) \
465 -type f -print | xargs rm -f
466
467
468 @@ -1309,6 +1387,8 @@ PHONY += $(module-dirs) modules
469 $(module-dirs): crmodverdir $(objtree)/Module.symvers
470 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
471
472 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
473 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
474 modules: $(module-dirs)
475 @$(kecho) ' Building modules, stage 2.';
476 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
477 @@ -1448,17 +1528,21 @@ else
478 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
479 endif
480
481 -%.s: %.c prepare scripts FORCE
482 +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
483 +%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
484 +%.s: %.c gcc-plugins prepare scripts FORCE
485 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
486 %.i: %.c prepare scripts FORCE
487 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
488 -%.o: %.c prepare scripts FORCE
489 +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
490 +%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
491 +%.o: %.c gcc-plugins prepare scripts FORCE
492 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
493 %.lst: %.c prepare scripts FORCE
494 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
495 -%.s: %.S prepare scripts FORCE
496 +%.s: %.S gcc-plugins prepare scripts FORCE
497 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
498 -%.o: %.S prepare scripts FORCE
499 +%.o: %.S gcc-plugins prepare scripts FORCE
500 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
501 %.symtypes: %.c prepare scripts FORCE
502 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
503 @@ -1468,11 +1552,15 @@ endif
504 $(cmd_crmodverdir)
505 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
506 $(build)=$(build-dir)
507 -%/: prepare scripts FORCE
508 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
509 +%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
510 +%/: gcc-plugins prepare scripts FORCE
511 $(cmd_crmodverdir)
512 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
513 $(build)=$(build-dir)
514 -%.ko: prepare scripts FORCE
515 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
516 +%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
517 +%.ko: gcc-plugins prepare scripts FORCE
518 $(cmd_crmodverdir)
519 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
520 $(build)=$(build-dir) $(@:.ko=.o)
521 diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
522 index 78b03ef..da28a51 100644
523 --- a/arch/alpha/include/asm/atomic.h
524 +++ b/arch/alpha/include/asm/atomic.h
525 @@ -292,6 +292,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
526 #define atomic_dec(v) atomic_sub(1,(v))
527 #define atomic64_dec(v) atomic64_sub(1,(v))
528
529 +#define atomic64_read_unchecked(v) atomic64_read(v)
530 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
531 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
532 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
533 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
534 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
535 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
536 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
537 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
538 +
539 #define smp_mb__before_atomic_dec() smp_mb()
540 #define smp_mb__after_atomic_dec() smp_mb()
541 #define smp_mb__before_atomic_inc() smp_mb()
542 diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
543 index ad368a9..fbe0f25 100644
544 --- a/arch/alpha/include/asm/cache.h
545 +++ b/arch/alpha/include/asm/cache.h
546 @@ -4,19 +4,19 @@
547 #ifndef __ARCH_ALPHA_CACHE_H
548 #define __ARCH_ALPHA_CACHE_H
549
550 +#include <linux/const.h>
551
552 /* Bytes per L1 (data) cache line. */
553 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
554 -# define L1_CACHE_BYTES 64
555 # define L1_CACHE_SHIFT 6
556 #else
557 /* Both EV4 and EV5 are write-through, read-allocate,
558 direct-mapped, physical.
559 */
560 -# define L1_CACHE_BYTES 32
561 # define L1_CACHE_SHIFT 5
562 #endif
563
564 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
565 #define SMP_CACHE_BYTES L1_CACHE_BYTES
566
567 #endif
568 diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
569 index 968d999..d36b2df 100644
570 --- a/arch/alpha/include/asm/elf.h
571 +++ b/arch/alpha/include/asm/elf.h
572 @@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
573
574 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
575
576 +#ifdef CONFIG_PAX_ASLR
577 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
578 +
579 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
580 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
581 +#endif
582 +
583 /* $0 is set by ld.so to a pointer to a function which might be
584 registered using atexit. This provides a mean for the dynamic
585 linker to call DT_FINI functions for shared libraries that have
586 diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
587 index aab14a0..b4fa3e7 100644
588 --- a/arch/alpha/include/asm/pgalloc.h
589 +++ b/arch/alpha/include/asm/pgalloc.h
590 @@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
591 pgd_set(pgd, pmd);
592 }
593
594 +static inline void
595 +pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
596 +{
597 + pgd_populate(mm, pgd, pmd);
598 +}
599 +
600 extern pgd_t *pgd_alloc(struct mm_struct *mm);
601
602 static inline void
603 diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
604 index d8f9b7e..f6222fa 100644
605 --- a/arch/alpha/include/asm/pgtable.h
606 +++ b/arch/alpha/include/asm/pgtable.h
607 @@ -102,6 +102,17 @@ struct vm_area_struct;
608 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
609 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
610 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
611 +
612 +#ifdef CONFIG_PAX_PAGEEXEC
613 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
614 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
615 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
616 +#else
617 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
618 +# define PAGE_COPY_NOEXEC PAGE_COPY
619 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
620 +#endif
621 +
622 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
623
624 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
625 diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
626 index 2fd00b7..cfd5069 100644
627 --- a/arch/alpha/kernel/module.c
628 +++ b/arch/alpha/kernel/module.c
629 @@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
630
631 /* The small sections were sorted to the end of the segment.
632 The following should definitely cover them. */
633 - gp = (u64)me->module_core + me->core_size - 0x8000;
634 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
635 got = sechdrs[me->arch.gotsecindex].sh_addr;
636
637 for (i = 0; i < n; i++) {
638 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
639 index 1402fcc..0b1abd2 100644
640 --- a/arch/alpha/kernel/osf_sys.c
641 +++ b/arch/alpha/kernel/osf_sys.c
642 @@ -1298,10 +1298,11 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
643 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
644
645 static unsigned long
646 -arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
647 - unsigned long limit)
648 +arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
649 + unsigned long limit, unsigned long flags)
650 {
651 struct vm_unmapped_area_info info;
652 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
653
654 info.flags = 0;
655 info.length = len;
656 @@ -1309,6 +1310,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
657 info.high_limit = limit;
658 info.align_mask = 0;
659 info.align_offset = 0;
660 + info.threadstack_offset = offset;
661 return vm_unmapped_area(&info);
662 }
663
664 @@ -1341,20 +1343,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
665 merely specific addresses, but regions of memory -- perhaps
666 this feature should be incorporated into all ports? */
667
668 +#ifdef CONFIG_PAX_RANDMMAP
669 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
670 +#endif
671 +
672 if (addr) {
673 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
674 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
675 if (addr != (unsigned long) -ENOMEM)
676 return addr;
677 }
678
679 /* Next, try allocating at TASK_UNMAPPED_BASE. */
680 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
681 - len, limit);
682 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
683 +
684 if (addr != (unsigned long) -ENOMEM)
685 return addr;
686
687 /* Finally, try allocating in low memory. */
688 - addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
689 + addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
690
691 return addr;
692 }
693 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
694 index 98838a0..b304fb4 100644
695 --- a/arch/alpha/mm/fault.c
696 +++ b/arch/alpha/mm/fault.c
697 @@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
698 __reload_thread(pcb);
699 }
700
701 +#ifdef CONFIG_PAX_PAGEEXEC
702 +/*
703 + * PaX: decide what to do with offenders (regs->pc = fault address)
704 + *
705 + * returns 1 when task should be killed
706 + * 2 when patched PLT trampoline was detected
707 + * 3 when unpatched PLT trampoline was detected
708 + */
709 +static int pax_handle_fetch_fault(struct pt_regs *regs)
710 +{
711 +
712 +#ifdef CONFIG_PAX_EMUPLT
713 + int err;
714 +
715 + do { /* PaX: patched PLT emulation #1 */
716 + unsigned int ldah, ldq, jmp;
717 +
718 + err = get_user(ldah, (unsigned int *)regs->pc);
719 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
720 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
721 +
722 + if (err)
723 + break;
724 +
725 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
726 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
727 + jmp == 0x6BFB0000U)
728 + {
729 + unsigned long r27, addr;
730 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
731 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
732 +
733 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
734 + err = get_user(r27, (unsigned long *)addr);
735 + if (err)
736 + break;
737 +
738 + regs->r27 = r27;
739 + regs->pc = r27;
740 + return 2;
741 + }
742 + } while (0);
743 +
744 + do { /* PaX: patched PLT emulation #2 */
745 + unsigned int ldah, lda, br;
746 +
747 + err = get_user(ldah, (unsigned int *)regs->pc);
748 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
749 + err |= get_user(br, (unsigned int *)(regs->pc+8));
750 +
751 + if (err)
752 + break;
753 +
754 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
755 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
756 + (br & 0xFFE00000U) == 0xC3E00000U)
757 + {
758 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
759 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
760 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
761 +
762 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
763 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
764 + return 2;
765 + }
766 + } while (0);
767 +
768 + do { /* PaX: unpatched PLT emulation */
769 + unsigned int br;
770 +
771 + err = get_user(br, (unsigned int *)regs->pc);
772 +
773 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
774 + unsigned int br2, ldq, nop, jmp;
775 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
776 +
777 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
778 + err = get_user(br2, (unsigned int *)addr);
779 + err |= get_user(ldq, (unsigned int *)(addr+4));
780 + err |= get_user(nop, (unsigned int *)(addr+8));
781 + err |= get_user(jmp, (unsigned int *)(addr+12));
782 + err |= get_user(resolver, (unsigned long *)(addr+16));
783 +
784 + if (err)
785 + break;
786 +
787 + if (br2 == 0xC3600000U &&
788 + ldq == 0xA77B000CU &&
789 + nop == 0x47FF041FU &&
790 + jmp == 0x6B7B0000U)
791 + {
792 + regs->r28 = regs->pc+4;
793 + regs->r27 = addr+16;
794 + regs->pc = resolver;
795 + return 3;
796 + }
797 + }
798 + } while (0);
799 +#endif
800 +
801 + return 1;
802 +}
803 +
804 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
805 +{
806 + unsigned long i;
807 +
808 + printk(KERN_ERR "PAX: bytes at PC: ");
809 + for (i = 0; i < 5; i++) {
810 + unsigned int c;
811 + if (get_user(c, (unsigned int *)pc+i))
812 + printk(KERN_CONT "???????? ");
813 + else
814 + printk(KERN_CONT "%08x ", c);
815 + }
816 + printk("\n");
817 +}
818 +#endif
819
820 /*
821 * This routine handles page faults. It determines the address,
822 @@ -133,8 +251,29 @@ retry:
823 good_area:
824 si_code = SEGV_ACCERR;
825 if (cause < 0) {
826 - if (!(vma->vm_flags & VM_EXEC))
827 + if (!(vma->vm_flags & VM_EXEC)) {
828 +
829 +#ifdef CONFIG_PAX_PAGEEXEC
830 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
831 + goto bad_area;
832 +
833 + up_read(&mm->mmap_sem);
834 + switch (pax_handle_fetch_fault(regs)) {
835 +
836 +#ifdef CONFIG_PAX_EMUPLT
837 + case 2:
838 + case 3:
839 + return;
840 +#endif
841 +
842 + }
843 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
844 + do_group_exit(SIGKILL);
845 +#else
846 goto bad_area;
847 +#endif
848 +
849 + }
850 } else if (!cause) {
851 /* Allow reads even for write-only mappings */
852 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
853 diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
854 index db3c541..a1acc89 100644
855 --- a/arch/arm/Kconfig
856 +++ b/arch/arm/Kconfig
857 @@ -1877,7 +1877,7 @@ config ALIGNMENT_TRAP
858
859 config UACCESS_WITH_MEMCPY
860 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
861 - depends on MMU
862 + depends on MMU && !PAX_MEMORY_UDEREF
863 default y if CPU_FEROCEON
864 help
865 Implement faster copy_to_user and clear_user methods for CPU
866 @@ -2141,6 +2141,7 @@ config XIP_PHYS_ADDR
867 config KEXEC
868 bool "Kexec system call (EXPERIMENTAL)"
869 depends on (!SMP || PM_SLEEP_SMP)
870 + depends on !GRKERNSEC_KMEM
871 help
872 kexec is a system call that implements the ability to shutdown your
873 current kernel, and to start another kernel. It is like a reboot
874 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
875 index 9a92fd7..3502a80 100644
876 --- a/arch/arm/include/asm/atomic.h
877 +++ b/arch/arm/include/asm/atomic.h
878 @@ -18,17 +18,35 @@
879 #include <asm/barrier.h>
880 #include <asm/cmpxchg.h>
881
882 +#ifdef CONFIG_GENERIC_ATOMIC64
883 +#include <asm-generic/atomic64.h>
884 +#endif
885 +
886 #define ATOMIC_INIT(i) { (i) }
887
888 #ifdef __KERNEL__
889
890 +#define _ASM_EXTABLE(from, to) \
891 +" .pushsection __ex_table,\"a\"\n"\
892 +" .align 3\n" \
893 +" .long " #from ", " #to"\n" \
894 +" .popsection"
895 +
896 /*
897 * On ARM, ordinary assignment (str instruction) doesn't clear the local
898 * strex/ldrex monitor on some implementations. The reason we can use it for
899 * atomic_set() is the clrex or dummy strex done on every exception return.
900 */
901 #define atomic_read(v) (*(volatile int *)&(v)->counter)
902 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
903 +{
904 + return v->counter;
905 +}
906 #define atomic_set(v,i) (((v)->counter) = (i))
907 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
908 +{
909 + v->counter = i;
910 +}
911
912 #if __LINUX_ARM_ARCH__ >= 6
913
914 @@ -44,6 +62,36 @@ static inline void atomic_add(int i, atomic_t *v)
915
916 prefetchw(&v->counter);
917 __asm__ __volatile__("@ atomic_add\n"
918 +"1: ldrex %1, [%3]\n"
919 +" adds %0, %1, %4\n"
920 +
921 +#ifdef CONFIG_PAX_REFCOUNT
922 +" bvc 3f\n"
923 +"2: bkpt 0xf103\n"
924 +"3:\n"
925 +#endif
926 +
927 +" strex %1, %0, [%3]\n"
928 +" teq %1, #0\n"
929 +" bne 1b"
930 +
931 +#ifdef CONFIG_PAX_REFCOUNT
932 +"\n4:\n"
933 + _ASM_EXTABLE(2b, 4b)
934 +#endif
935 +
936 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
937 + : "r" (&v->counter), "Ir" (i)
938 + : "cc");
939 +}
940 +
941 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
942 +{
943 + unsigned long tmp;
944 + int result;
945 +
946 + prefetchw(&v->counter);
947 + __asm__ __volatile__("@ atomic_add_unchecked\n"
948 "1: ldrex %0, [%3]\n"
949 " add %0, %0, %4\n"
950 " strex %1, %0, [%3]\n"
951 @@ -63,6 +111,43 @@ static inline int atomic_add_return(int i, atomic_t *v)
952 prefetchw(&v->counter);
953
954 __asm__ __volatile__("@ atomic_add_return\n"
955 +"1: ldrex %1, [%3]\n"
956 +" adds %0, %1, %4\n"
957 +
958 +#ifdef CONFIG_PAX_REFCOUNT
959 +" bvc 3f\n"
960 +" mov %0, %1\n"
961 +"2: bkpt 0xf103\n"
962 +"3:\n"
963 +#endif
964 +
965 +" strex %1, %0, [%3]\n"
966 +" teq %1, #0\n"
967 +" bne 1b"
968 +
969 +#ifdef CONFIG_PAX_REFCOUNT
970 +"\n4:\n"
971 + _ASM_EXTABLE(2b, 4b)
972 +#endif
973 +
974 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
975 + : "r" (&v->counter), "Ir" (i)
976 + : "cc");
977 +
978 + smp_mb();
979 +
980 + return result;
981 +}
982 +
983 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
984 +{
985 + unsigned long tmp;
986 + int result;
987 +
988 + smp_mb();
989 + prefetchw(&v->counter);
990 +
991 + __asm__ __volatile__("@ atomic_add_return_unchecked\n"
992 "1: ldrex %0, [%3]\n"
993 " add %0, %0, %4\n"
994 " strex %1, %0, [%3]\n"
995 @@ -84,6 +169,36 @@ static inline void atomic_sub(int i, atomic_t *v)
996
997 prefetchw(&v->counter);
998 __asm__ __volatile__("@ atomic_sub\n"
999 +"1: ldrex %1, [%3]\n"
1000 +" subs %0, %1, %4\n"
1001 +
1002 +#ifdef CONFIG_PAX_REFCOUNT
1003 +" bvc 3f\n"
1004 +"2: bkpt 0xf103\n"
1005 +"3:\n"
1006 +#endif
1007 +
1008 +" strex %1, %0, [%3]\n"
1009 +" teq %1, #0\n"
1010 +" bne 1b"
1011 +
1012 +#ifdef CONFIG_PAX_REFCOUNT
1013 +"\n4:\n"
1014 + _ASM_EXTABLE(2b, 4b)
1015 +#endif
1016 +
1017 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1018 + : "r" (&v->counter), "Ir" (i)
1019 + : "cc");
1020 +}
1021 +
1022 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1023 +{
1024 + unsigned long tmp;
1025 + int result;
1026 +
1027 + prefetchw(&v->counter);
1028 + __asm__ __volatile__("@ atomic_sub_unchecked\n"
1029 "1: ldrex %0, [%3]\n"
1030 " sub %0, %0, %4\n"
1031 " strex %1, %0, [%3]\n"
1032 @@ -103,11 +218,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1033 prefetchw(&v->counter);
1034
1035 __asm__ __volatile__("@ atomic_sub_return\n"
1036 -"1: ldrex %0, [%3]\n"
1037 -" sub %0, %0, %4\n"
1038 +"1: ldrex %1, [%3]\n"
1039 +" subs %0, %1, %4\n"
1040 +
1041 +#ifdef CONFIG_PAX_REFCOUNT
1042 +" bvc 3f\n"
1043 +" mov %0, %1\n"
1044 +"2: bkpt 0xf103\n"
1045 +"3:\n"
1046 +#endif
1047 +
1048 " strex %1, %0, [%3]\n"
1049 " teq %1, #0\n"
1050 " bne 1b"
1051 +
1052 +#ifdef CONFIG_PAX_REFCOUNT
1053 +"\n4:\n"
1054 + _ASM_EXTABLE(2b, 4b)
1055 +#endif
1056 +
1057 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1058 : "r" (&v->counter), "Ir" (i)
1059 : "cc");
1060 @@ -152,12 +281,24 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1061 __asm__ __volatile__ ("@ atomic_add_unless\n"
1062 "1: ldrex %0, [%4]\n"
1063 " teq %0, %5\n"
1064 -" beq 2f\n"
1065 -" add %1, %0, %6\n"
1066 +" beq 4f\n"
1067 +" adds %1, %0, %6\n"
1068 +
1069 +#ifdef CONFIG_PAX_REFCOUNT
1070 +" bvc 3f\n"
1071 +"2: bkpt 0xf103\n"
1072 +"3:\n"
1073 +#endif
1074 +
1075 " strex %2, %1, [%4]\n"
1076 " teq %2, #0\n"
1077 " bne 1b\n"
1078 -"2:"
1079 +"4:"
1080 +
1081 +#ifdef CONFIG_PAX_REFCOUNT
1082 + _ASM_EXTABLE(2b, 4b)
1083 +#endif
1084 +
1085 : "=&r" (oldval), "=&r" (newval), "=&r" (tmp), "+Qo" (v->counter)
1086 : "r" (&v->counter), "r" (u), "r" (a)
1087 : "cc");
1088 @@ -168,6 +309,28 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1089 return oldval;
1090 }
1091
1092 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1093 +{
1094 + unsigned long oldval, res;
1095 +
1096 + smp_mb();
1097 +
1098 + do {
1099 + __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1100 + "ldrex %1, [%3]\n"
1101 + "mov %0, #0\n"
1102 + "teq %1, %4\n"
1103 + "strexeq %0, %5, [%3]\n"
1104 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1105 + : "r" (&ptr->counter), "Ir" (old), "r" (new)
1106 + : "cc");
1107 + } while (res);
1108 +
1109 + smp_mb();
1110 +
1111 + return oldval;
1112 +}
1113 +
1114 #else /* ARM_ARCH_6 */
1115
1116 #ifdef CONFIG_SMP
1117 @@ -186,7 +349,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1118
1119 return val;
1120 }
1121 +
1122 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1123 +{
1124 + return atomic_add_return(i, v);
1125 +}
1126 +
1127 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1128 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1129 +{
1130 + (void) atomic_add_return(i, v);
1131 +}
1132
1133 static inline int atomic_sub_return(int i, atomic_t *v)
1134 {
1135 @@ -201,6 +374,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1136 return val;
1137 }
1138 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1139 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1140 +{
1141 + (void) atomic_sub_return(i, v);
1142 +}
1143
1144 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1145 {
1146 @@ -216,6 +393,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1147 return ret;
1148 }
1149
1150 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1151 +{
1152 + return atomic_cmpxchg(v, old, new);
1153 +}
1154 +
1155 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1156 {
1157 int c, old;
1158 @@ -229,13 +411,33 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1159 #endif /* __LINUX_ARM_ARCH__ */
1160
1161 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1162 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1163 +{
1164 + return xchg(&v->counter, new);
1165 +}
1166
1167 #define atomic_inc(v) atomic_add(1, v)
1168 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1169 +{
1170 + atomic_add_unchecked(1, v);
1171 +}
1172 #define atomic_dec(v) atomic_sub(1, v)
1173 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1174 +{
1175 + atomic_sub_unchecked(1, v);
1176 +}
1177
1178 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1179 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1180 +{
1181 + return atomic_add_return_unchecked(1, v) == 0;
1182 +}
1183 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1184 #define atomic_inc_return(v) (atomic_add_return(1, v))
1185 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1186 +{
1187 + return atomic_add_return_unchecked(1, v);
1188 +}
1189 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1190 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1191
1192 @@ -251,6 +453,14 @@ typedef struct {
1193 long long counter;
1194 } atomic64_t;
1195
1196 +#ifdef CONFIG_PAX_REFCOUNT
1197 +typedef struct {
1198 + long long counter;
1199 +} atomic64_unchecked_t;
1200 +#else
1201 +typedef atomic64_t atomic64_unchecked_t;
1202 +#endif
1203 +
1204 #define ATOMIC64_INIT(i) { (i) }
1205
1206 #ifdef CONFIG_ARM_LPAE
1207 @@ -267,6 +477,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1208 return result;
1209 }
1210
1211 +static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1212 +{
1213 + long long result;
1214 +
1215 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1216 +" ldrd %0, %H0, [%1]"
1217 + : "=&r" (result)
1218 + : "r" (&v->counter), "Qo" (v->counter)
1219 + );
1220 +
1221 + return result;
1222 +}
1223 +
1224 static inline void atomic64_set(atomic64_t *v, long long i)
1225 {
1226 __asm__ __volatile__("@ atomic64_set\n"
1227 @@ -275,6 +498,15 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1228 : "r" (&v->counter), "r" (i)
1229 );
1230 }
1231 +
1232 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1233 +{
1234 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1235 +" strd %2, %H2, [%1]"
1236 + : "=Qo" (v->counter)
1237 + : "r" (&v->counter), "r" (i)
1238 + );
1239 +}
1240 #else
1241 static inline long long atomic64_read(const atomic64_t *v)
1242 {
1243 @@ -289,6 +521,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1244 return result;
1245 }
1246
1247 +static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1248 +{
1249 + long long result;
1250 +
1251 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1252 +" ldrexd %0, %H0, [%1]"
1253 + : "=&r" (result)
1254 + : "r" (&v->counter), "Qo" (v->counter)
1255 + );
1256 +
1257 + return result;
1258 +}
1259 +
1260 static inline void atomic64_set(atomic64_t *v, long long i)
1261 {
1262 long long tmp;
1263 @@ -303,6 +548,21 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1264 : "r" (&v->counter), "r" (i)
1265 : "cc");
1266 }
1267 +
1268 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1269 +{
1270 + long long tmp;
1271 +
1272 + prefetchw(&v->counter);
1273 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1274 +"1: ldrexd %0, %H0, [%2]\n"
1275 +" strexd %0, %3, %H3, [%2]\n"
1276 +" teq %0, #0\n"
1277 +" bne 1b"
1278 + : "=&r" (tmp), "=Qo" (v->counter)
1279 + : "r" (&v->counter), "r" (i)
1280 + : "cc");
1281 +}
1282 #endif
1283
1284 static inline void atomic64_add(long long i, atomic64_t *v)
1285 @@ -314,6 +574,37 @@ static inline void atomic64_add(long long i, atomic64_t *v)
1286 __asm__ __volatile__("@ atomic64_add\n"
1287 "1: ldrexd %0, %H0, [%3]\n"
1288 " adds %Q0, %Q0, %Q4\n"
1289 +" adcs %R0, %R0, %R4\n"
1290 +
1291 +#ifdef CONFIG_PAX_REFCOUNT
1292 +" bvc 3f\n"
1293 +"2: bkpt 0xf103\n"
1294 +"3:\n"
1295 +#endif
1296 +
1297 +" strexd %1, %0, %H0, [%3]\n"
1298 +" teq %1, #0\n"
1299 +" bne 1b"
1300 +
1301 +#ifdef CONFIG_PAX_REFCOUNT
1302 +"\n4:\n"
1303 + _ASM_EXTABLE(2b, 4b)
1304 +#endif
1305 +
1306 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1307 + : "r" (&v->counter), "r" (i)
1308 + : "cc");
1309 +}
1310 +
1311 +static inline void atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
1312 +{
1313 + long long result;
1314 + unsigned long tmp;
1315 +
1316 + prefetchw(&v->counter);
1317 + __asm__ __volatile__("@ atomic64_add_unchecked\n"
1318 +"1: ldrexd %0, %H0, [%3]\n"
1319 +" adds %Q0, %Q0, %Q4\n"
1320 " adc %R0, %R0, %R4\n"
1321 " strexd %1, %0, %H0, [%3]\n"
1322 " teq %1, #0\n"
1323 @@ -334,6 +625,44 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
1324 __asm__ __volatile__("@ atomic64_add_return\n"
1325 "1: ldrexd %0, %H0, [%3]\n"
1326 " adds %Q0, %Q0, %Q4\n"
1327 +" adcs %R0, %R0, %R4\n"
1328 +
1329 +#ifdef CONFIG_PAX_REFCOUNT
1330 +" bvc 3f\n"
1331 +" mov %0, %1\n"
1332 +" mov %H0, %H1\n"
1333 +"2: bkpt 0xf103\n"
1334 +"3:\n"
1335 +#endif
1336 +
1337 +" strexd %1, %0, %H0, [%3]\n"
1338 +" teq %1, #0\n"
1339 +" bne 1b"
1340 +
1341 +#ifdef CONFIG_PAX_REFCOUNT
1342 +"\n4:\n"
1343 + _ASM_EXTABLE(2b, 4b)
1344 +#endif
1345 +
1346 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1347 + : "r" (&v->counter), "r" (i)
1348 + : "cc");
1349 +
1350 + smp_mb();
1351 +
1352 + return result;
1353 +}
1354 +
1355 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
1356 +{
1357 + long long result;
1358 + unsigned long tmp;
1359 +
1360 + smp_mb();
1361 +
1362 + __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1363 +"1: ldrexd %0, %H0, [%3]\n"
1364 +" adds %Q0, %Q0, %Q4\n"
1365 " adc %R0, %R0, %R4\n"
1366 " strexd %1, %0, %H0, [%3]\n"
1367 " teq %1, #0\n"
1368 @@ -356,6 +685,37 @@ static inline void atomic64_sub(long long i, atomic64_t *v)
1369 __asm__ __volatile__("@ atomic64_sub\n"
1370 "1: ldrexd %0, %H0, [%3]\n"
1371 " subs %Q0, %Q0, %Q4\n"
1372 +" sbcs %R0, %R0, %R4\n"
1373 +
1374 +#ifdef CONFIG_PAX_REFCOUNT
1375 +" bvc 3f\n"
1376 +"2: bkpt 0xf103\n"
1377 +"3:\n"
1378 +#endif
1379 +
1380 +" strexd %1, %0, %H0, [%3]\n"
1381 +" teq %1, #0\n"
1382 +" bne 1b"
1383 +
1384 +#ifdef CONFIG_PAX_REFCOUNT
1385 +"\n4:\n"
1386 + _ASM_EXTABLE(2b, 4b)
1387 +#endif
1388 +
1389 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1390 + : "r" (&v->counter), "r" (i)
1391 + : "cc");
1392 +}
1393 +
1394 +static inline void atomic64_sub_unchecked(long long i, atomic64_unchecked_t *v)
1395 +{
1396 + long long result;
1397 + unsigned long tmp;
1398 +
1399 + prefetchw(&v->counter);
1400 + __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1401 +"1: ldrexd %0, %H0, [%3]\n"
1402 +" subs %Q0, %Q0, %Q4\n"
1403 " sbc %R0, %R0, %R4\n"
1404 " strexd %1, %0, %H0, [%3]\n"
1405 " teq %1, #0\n"
1406 @@ -376,16 +736,29 @@ static inline long long atomic64_sub_return(long long i, atomic64_t *v)
1407 __asm__ __volatile__("@ atomic64_sub_return\n"
1408 "1: ldrexd %0, %H0, [%3]\n"
1409 " subs %Q0, %Q0, %Q4\n"
1410 -" sbc %R0, %R0, %R4\n"
1411 +" sbcs %R0, %R0, %R4\n"
1412 +
1413 +#ifdef CONFIG_PAX_REFCOUNT
1414 +" bvc 3f\n"
1415 +" mov %0, %1\n"
1416 +" mov %H0, %H1\n"
1417 +"2: bkpt 0xf103\n"
1418 +"3:\n"
1419 +#endif
1420 +
1421 " strexd %1, %0, %H0, [%3]\n"
1422 " teq %1, #0\n"
1423 " bne 1b"
1424 +
1425 +#ifdef CONFIG_PAX_REFCOUNT
1426 +"\n4:\n"
1427 + _ASM_EXTABLE(2b, 4b)
1428 +#endif
1429 +
1430 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1431 : "r" (&v->counter), "r" (i)
1432 : "cc");
1433
1434 - smp_mb();
1435 -
1436 return result;
1437 }
1438
1439 @@ -415,6 +788,31 @@ static inline long long atomic64_cmpxchg(atomic64_t *ptr, long long old,
1440 return oldval;
1441 }
1442
1443 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, long long old,
1444 + long long new)
1445 +{
1446 + long long oldval;
1447 + unsigned long res;
1448 +
1449 + smp_mb();
1450 +
1451 + do {
1452 + __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1453 + "ldrexd %1, %H1, [%3]\n"
1454 + "mov %0, #0\n"
1455 + "teq %1, %4\n"
1456 + "teqeq %H1, %H4\n"
1457 + "strexdeq %0, %5, %H5, [%3]"
1458 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1459 + : "r" (&ptr->counter), "r" (old), "r" (new)
1460 + : "cc");
1461 + } while (res);
1462 +
1463 + smp_mb();
1464 +
1465 + return oldval;
1466 +}
1467 +
1468 static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1469 {
1470 long long result;
1471 @@ -440,21 +838,35 @@ static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1472 static inline long long atomic64_dec_if_positive(atomic64_t *v)
1473 {
1474 long long result;
1475 - unsigned long tmp;
1476 + u64 tmp;
1477
1478 smp_mb();
1479 prefetchw(&v->counter);
1480
1481 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1482 -"1: ldrexd %0, %H0, [%3]\n"
1483 -" subs %Q0, %Q0, #1\n"
1484 -" sbc %R0, %R0, #0\n"
1485 +"1: ldrexd %1, %H1, [%3]\n"
1486 +" subs %Q0, %Q1, #1\n"
1487 +" sbcs %R0, %R1, #0\n"
1488 +
1489 +#ifdef CONFIG_PAX_REFCOUNT
1490 +" bvc 3f\n"
1491 +" mov %Q0, %Q1\n"
1492 +" mov %R0, %R1\n"
1493 +"2: bkpt 0xf103\n"
1494 +"3:\n"
1495 +#endif
1496 +
1497 " teq %R0, #0\n"
1498 -" bmi 2f\n"
1499 +" bmi 4f\n"
1500 " strexd %1, %0, %H0, [%3]\n"
1501 " teq %1, #0\n"
1502 " bne 1b\n"
1503 -"2:"
1504 +"4:\n"
1505 +
1506 +#ifdef CONFIG_PAX_REFCOUNT
1507 + _ASM_EXTABLE(2b, 4b)
1508 +#endif
1509 +
1510 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1511 : "r" (&v->counter)
1512 : "cc");
1513 @@ -478,13 +890,25 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1514 " teq %0, %5\n"
1515 " teqeq %H0, %H5\n"
1516 " moveq %1, #0\n"
1517 -" beq 2f\n"
1518 +" beq 4f\n"
1519 " adds %Q0, %Q0, %Q6\n"
1520 -" adc %R0, %R0, %R6\n"
1521 +" adcs %R0, %R0, %R6\n"
1522 +
1523 +#ifdef CONFIG_PAX_REFCOUNT
1524 +" bvc 3f\n"
1525 +"2: bkpt 0xf103\n"
1526 +"3:\n"
1527 +#endif
1528 +
1529 " strexd %2, %0, %H0, [%4]\n"
1530 " teq %2, #0\n"
1531 " bne 1b\n"
1532 -"2:"
1533 +"4:\n"
1534 +
1535 +#ifdef CONFIG_PAX_REFCOUNT
1536 + _ASM_EXTABLE(2b, 4b)
1537 +#endif
1538 +
1539 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1540 : "r" (&v->counter), "r" (u), "r" (a)
1541 : "cc");
1542 @@ -497,10 +921,13 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1543
1544 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1545 #define atomic64_inc(v) atomic64_add(1LL, (v))
1546 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1547 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1548 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1549 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1550 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1551 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1552 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1553 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1554 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1555 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1556 diff --git a/arch/arm/include/asm/barrier.h b/arch/arm/include/asm/barrier.h
1557 index 2f59f74..1594659 100644
1558 --- a/arch/arm/include/asm/barrier.h
1559 +++ b/arch/arm/include/asm/barrier.h
1560 @@ -63,7 +63,7 @@
1561 do { \
1562 compiletime_assert_atomic_type(*p); \
1563 smp_mb(); \
1564 - ACCESS_ONCE(*p) = (v); \
1565 + ACCESS_ONCE_RW(*p) = (v); \
1566 } while (0)
1567
1568 #define smp_load_acquire(p) \
1569 diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1570 index 75fe66b..ba3dee4 100644
1571 --- a/arch/arm/include/asm/cache.h
1572 +++ b/arch/arm/include/asm/cache.h
1573 @@ -4,8 +4,10 @@
1574 #ifndef __ASMARM_CACHE_H
1575 #define __ASMARM_CACHE_H
1576
1577 +#include <linux/const.h>
1578 +
1579 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1580 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1581 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1582
1583 /*
1584 * Memory returned by kmalloc() may be used for DMA, so we must make
1585 @@ -24,5 +26,6 @@
1586 #endif
1587
1588 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1589 +#define __read_only __attribute__ ((__section__(".data..read_only")))
1590
1591 #endif
1592 diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1593 index 8b8b616..d973d24 100644
1594 --- a/arch/arm/include/asm/cacheflush.h
1595 +++ b/arch/arm/include/asm/cacheflush.h
1596 @@ -116,7 +116,7 @@ struct cpu_cache_fns {
1597 void (*dma_unmap_area)(const void *, size_t, int);
1598
1599 void (*dma_flush_range)(const void *, const void *);
1600 -};
1601 +} __no_const;
1602
1603 /*
1604 * Select the calling method
1605 diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1606 index 5233151..87a71fa 100644
1607 --- a/arch/arm/include/asm/checksum.h
1608 +++ b/arch/arm/include/asm/checksum.h
1609 @@ -37,7 +37,19 @@ __wsum
1610 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1611
1612 __wsum
1613 -csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1614 +__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1615 +
1616 +static inline __wsum
1617 +csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1618 +{
1619 + __wsum ret;
1620 + pax_open_userland();
1621 + ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1622 + pax_close_userland();
1623 + return ret;
1624 +}
1625 +
1626 +
1627
1628 /*
1629 * Fold a partial checksum without adding pseudo headers
1630 diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1631 index abb2c37..96db950 100644
1632 --- a/arch/arm/include/asm/cmpxchg.h
1633 +++ b/arch/arm/include/asm/cmpxchg.h
1634 @@ -104,6 +104,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1635
1636 #define xchg(ptr,x) \
1637 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1638 +#define xchg_unchecked(ptr,x) \
1639 + ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1640
1641 #include <asm-generic/cmpxchg-local.h>
1642
1643 diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1644 index 6ddbe44..b5e38b1 100644
1645 --- a/arch/arm/include/asm/domain.h
1646 +++ b/arch/arm/include/asm/domain.h
1647 @@ -48,18 +48,37 @@
1648 * Domain types
1649 */
1650 #define DOMAIN_NOACCESS 0
1651 -#define DOMAIN_CLIENT 1
1652 #ifdef CONFIG_CPU_USE_DOMAINS
1653 +#define DOMAIN_USERCLIENT 1
1654 +#define DOMAIN_KERNELCLIENT 1
1655 #define DOMAIN_MANAGER 3
1656 +#define DOMAIN_VECTORS DOMAIN_USER
1657 #else
1658 +
1659 +#ifdef CONFIG_PAX_KERNEXEC
1660 #define DOMAIN_MANAGER 1
1661 +#define DOMAIN_KERNEXEC 3
1662 +#else
1663 +#define DOMAIN_MANAGER 1
1664 +#endif
1665 +
1666 +#ifdef CONFIG_PAX_MEMORY_UDEREF
1667 +#define DOMAIN_USERCLIENT 0
1668 +#define DOMAIN_UDEREF 1
1669 +#define DOMAIN_VECTORS DOMAIN_KERNEL
1670 +#else
1671 +#define DOMAIN_USERCLIENT 1
1672 +#define DOMAIN_VECTORS DOMAIN_USER
1673 +#endif
1674 +#define DOMAIN_KERNELCLIENT 1
1675 +
1676 #endif
1677
1678 #define domain_val(dom,type) ((type) << (2*(dom)))
1679
1680 #ifndef __ASSEMBLY__
1681
1682 -#ifdef CONFIG_CPU_USE_DOMAINS
1683 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1684 static inline void set_domain(unsigned val)
1685 {
1686 asm volatile(
1687 @@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1688 isb();
1689 }
1690
1691 -#define modify_domain(dom,type) \
1692 - do { \
1693 - struct thread_info *thread = current_thread_info(); \
1694 - unsigned int domain = thread->cpu_domain; \
1695 - domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1696 - thread->cpu_domain = domain | domain_val(dom, type); \
1697 - set_domain(thread->cpu_domain); \
1698 - } while (0)
1699 -
1700 +extern void modify_domain(unsigned int dom, unsigned int type);
1701 #else
1702 static inline void set_domain(unsigned val) { }
1703 static inline void modify_domain(unsigned dom, unsigned type) { }
1704 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1705 index f4b46d3..abc9b2b 100644
1706 --- a/arch/arm/include/asm/elf.h
1707 +++ b/arch/arm/include/asm/elf.h
1708 @@ -114,7 +114,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1709 the loader. We need to make sure that it is out of the way of the program
1710 that it will "exec", and that there is sufficient room for the brk. */
1711
1712 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1713 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1714 +
1715 +#ifdef CONFIG_PAX_ASLR
1716 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1717 +
1718 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1719 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1720 +#endif
1721
1722 /* When the program starts, a1 contains a pointer to a function to be
1723 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1724 @@ -124,10 +131,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1725 extern void elf_set_personality(const struct elf32_hdr *);
1726 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1727
1728 -struct mm_struct;
1729 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1730 -#define arch_randomize_brk arch_randomize_brk
1731 -
1732 #ifdef CONFIG_MMU
1733 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
1734 struct linux_binprm;
1735 diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1736 index de53547..52b9a28 100644
1737 --- a/arch/arm/include/asm/fncpy.h
1738 +++ b/arch/arm/include/asm/fncpy.h
1739 @@ -81,7 +81,9 @@
1740 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1741 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1742 \
1743 + pax_open_kernel(); \
1744 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1745 + pax_close_kernel(); \
1746 flush_icache_range((unsigned long)(dest_buf), \
1747 (unsigned long)(dest_buf) + (size)); \
1748 \
1749 diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1750 index 53e69da..3fdc896 100644
1751 --- a/arch/arm/include/asm/futex.h
1752 +++ b/arch/arm/include/asm/futex.h
1753 @@ -46,6 +46,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1754 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1755 return -EFAULT;
1756
1757 + pax_open_userland();
1758 +
1759 smp_mb();
1760 /* Prefetching cannot fault */
1761 prefetchw(uaddr);
1762 @@ -63,6 +65,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1763 : "cc", "memory");
1764 smp_mb();
1765
1766 + pax_close_userland();
1767 +
1768 *uval = val;
1769 return ret;
1770 }
1771 @@ -93,6 +97,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1772 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1773 return -EFAULT;
1774
1775 + pax_open_userland();
1776 +
1777 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1778 "1: " TUSER(ldr) " %1, [%4]\n"
1779 " teq %1, %2\n"
1780 @@ -103,6 +109,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1781 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1782 : "cc", "memory");
1783
1784 + pax_close_userland();
1785 +
1786 *uval = val;
1787 return ret;
1788 }
1789 @@ -125,6 +133,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1790 return -EFAULT;
1791
1792 pagefault_disable(); /* implies preempt_disable() */
1793 + pax_open_userland();
1794
1795 switch (op) {
1796 case FUTEX_OP_SET:
1797 @@ -146,6 +155,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1798 ret = -ENOSYS;
1799 }
1800
1801 + pax_close_userland();
1802 pagefault_enable(); /* subsumes preempt_enable() */
1803
1804 if (!ret) {
1805 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1806 index 83eb2f7..ed77159 100644
1807 --- a/arch/arm/include/asm/kmap_types.h
1808 +++ b/arch/arm/include/asm/kmap_types.h
1809 @@ -4,6 +4,6 @@
1810 /*
1811 * This is the "bare minimum". AIO seems to require this.
1812 */
1813 -#define KM_TYPE_NR 16
1814 +#define KM_TYPE_NR 17
1815
1816 #endif
1817 diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1818 index 9e614a1..3302cca 100644
1819 --- a/arch/arm/include/asm/mach/dma.h
1820 +++ b/arch/arm/include/asm/mach/dma.h
1821 @@ -22,7 +22,7 @@ struct dma_ops {
1822 int (*residue)(unsigned int, dma_t *); /* optional */
1823 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1824 const char *type;
1825 -};
1826 +} __do_const;
1827
1828 struct dma_struct {
1829 void *addr; /* single DMA address */
1830 diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1831 index f98c7f3..e5c626d 100644
1832 --- a/arch/arm/include/asm/mach/map.h
1833 +++ b/arch/arm/include/asm/mach/map.h
1834 @@ -23,17 +23,19 @@ struct map_desc {
1835
1836 /* types 0-3 are defined in asm/io.h */
1837 enum {
1838 - MT_UNCACHED = 4,
1839 - MT_CACHECLEAN,
1840 - MT_MINICLEAN,
1841 + MT_UNCACHED_RW = 4,
1842 + MT_CACHECLEAN_RO,
1843 + MT_MINICLEAN_RO,
1844 MT_LOW_VECTORS,
1845 MT_HIGH_VECTORS,
1846 - MT_MEMORY_RWX,
1847 + __MT_MEMORY_RWX,
1848 MT_MEMORY_RW,
1849 - MT_ROM,
1850 - MT_MEMORY_RWX_NONCACHED,
1851 + MT_MEMORY_RX,
1852 + MT_ROM_RX,
1853 + MT_MEMORY_RW_NONCACHED,
1854 + MT_MEMORY_RX_NONCACHED,
1855 MT_MEMORY_RW_DTCM,
1856 - MT_MEMORY_RWX_ITCM,
1857 + MT_MEMORY_RX_ITCM,
1858 MT_MEMORY_RW_SO,
1859 MT_MEMORY_DMA_READY,
1860 };
1861 diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1862 index f94784f..9a09a4a 100644
1863 --- a/arch/arm/include/asm/outercache.h
1864 +++ b/arch/arm/include/asm/outercache.h
1865 @@ -35,7 +35,7 @@ struct outer_cache_fns {
1866 #endif
1867 void (*set_debug)(unsigned long);
1868 void (*resume)(void);
1869 -};
1870 +} __no_const;
1871
1872 extern struct outer_cache_fns outer_cache;
1873
1874 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1875 index 4355f0e..cd9168e 100644
1876 --- a/arch/arm/include/asm/page.h
1877 +++ b/arch/arm/include/asm/page.h
1878 @@ -23,6 +23,7 @@
1879
1880 #else
1881
1882 +#include <linux/compiler.h>
1883 #include <asm/glue.h>
1884
1885 /*
1886 @@ -114,7 +115,7 @@ struct cpu_user_fns {
1887 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1888 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1889 unsigned long vaddr, struct vm_area_struct *vma);
1890 -};
1891 +} __no_const;
1892
1893 #ifdef MULTI_USER
1894 extern struct cpu_user_fns cpu_user;
1895 diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1896 index 78a7793..e3dc06c 100644
1897 --- a/arch/arm/include/asm/pgalloc.h
1898 +++ b/arch/arm/include/asm/pgalloc.h
1899 @@ -17,6 +17,7 @@
1900 #include <asm/processor.h>
1901 #include <asm/cacheflush.h>
1902 #include <asm/tlbflush.h>
1903 +#include <asm/system_info.h>
1904
1905 #define check_pgt_cache() do { } while (0)
1906
1907 @@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1908 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1909 }
1910
1911 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1912 +{
1913 + pud_populate(mm, pud, pmd);
1914 +}
1915 +
1916 #else /* !CONFIG_ARM_LPAE */
1917
1918 /*
1919 @@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1920 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1921 #define pmd_free(mm, pmd) do { } while (0)
1922 #define pud_populate(mm,pmd,pte) BUG()
1923 +#define pud_populate_kernel(mm,pmd,pte) BUG()
1924
1925 #endif /* CONFIG_ARM_LPAE */
1926
1927 @@ -128,6 +135,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1928 __free_page(pte);
1929 }
1930
1931 +static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1932 +{
1933 +#ifdef CONFIG_ARM_LPAE
1934 + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1935 +#else
1936 + if (addr & SECTION_SIZE)
1937 + pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1938 + else
1939 + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1940 +#endif
1941 + flush_pmd_entry(pmdp);
1942 +}
1943 +
1944 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1945 pmdval_t prot)
1946 {
1947 @@ -157,7 +177,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1948 static inline void
1949 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1950 {
1951 - __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1952 + __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1953 }
1954 #define pmd_pgtable(pmd) pmd_page(pmd)
1955
1956 diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1957 index 5cfba15..f415e1a 100644
1958 --- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1959 +++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1960 @@ -20,12 +20,15 @@
1961 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1962 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1963 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1964 +#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1965 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1966 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1967 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1968 +
1969 /*
1970 * - section
1971 */
1972 +#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1973 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1974 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1975 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1976 @@ -37,6 +40,7 @@
1977 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1978 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1979 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1980 +#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1981
1982 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1983 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1984 @@ -66,6 +70,7 @@
1985 * - extended small page/tiny page
1986 */
1987 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1988 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1989 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1990 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1991 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1992 diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1993 index 219ac88..73ec32a 100644
1994 --- a/arch/arm/include/asm/pgtable-2level.h
1995 +++ b/arch/arm/include/asm/pgtable-2level.h
1996 @@ -126,6 +126,9 @@
1997 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1998 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
1999
2000 +/* Two-level page tables only have PXN in the PGD, not in the PTE. */
2001 +#define L_PTE_PXN (_AT(pteval_t, 0))
2002 +
2003 /*
2004 * These are the memory types, defined to be compatible with
2005 * pre-ARMv6 CPUs cacheable and bufferable bits: XXCB
2006 diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
2007 index 626989f..9d67a33 100644
2008 --- a/arch/arm/include/asm/pgtable-3level-hwdef.h
2009 +++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
2010 @@ -75,6 +75,7 @@
2011 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
2012 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
2013 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
2014 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
2015 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
2016
2017 /*
2018 diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
2019 index 85c60ad..b0bbd7e 100644
2020 --- a/arch/arm/include/asm/pgtable-3level.h
2021 +++ b/arch/arm/include/asm/pgtable-3level.h
2022 @@ -82,6 +82,7 @@
2023 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
2024 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
2025 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
2026 +#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
2027 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
2028 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
2029 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
2030 @@ -95,6 +96,7 @@
2031 /*
2032 * To be used in assembly code with the upper page attributes.
2033 */
2034 +#define L_PTE_PXN_HIGH (1 << (53 - 32))
2035 #define L_PTE_XN_HIGH (1 << (54 - 32))
2036 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
2037
2038 diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
2039 index 5478e5d..f5b5cb3 100644
2040 --- a/arch/arm/include/asm/pgtable.h
2041 +++ b/arch/arm/include/asm/pgtable.h
2042 @@ -33,6 +33,9 @@
2043 #include <asm/pgtable-2level.h>
2044 #endif
2045
2046 +#define ktla_ktva(addr) (addr)
2047 +#define ktva_ktla(addr) (addr)
2048 +
2049 /*
2050 * Just any arbitrary offset to the start of the vmalloc VM area: the
2051 * current 8MB value just means that there will be a 8MB "hole" after the
2052 @@ -48,6 +51,9 @@
2053 #define LIBRARY_TEXT_START 0x0c000000
2054
2055 #ifndef __ASSEMBLY__
2056 +extern pteval_t __supported_pte_mask;
2057 +extern pmdval_t __supported_pmd_mask;
2058 +
2059 extern void __pte_error(const char *file, int line, pte_t);
2060 extern void __pmd_error(const char *file, int line, pmd_t);
2061 extern void __pgd_error(const char *file, int line, pgd_t);
2062 @@ -56,6 +62,48 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2063 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
2064 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
2065
2066 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
2067 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
2068 +
2069 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2070 +#include <asm/domain.h>
2071 +#include <linux/thread_info.h>
2072 +#include <linux/preempt.h>
2073 +
2074 +static inline int test_domain(int domain, int domaintype)
2075 +{
2076 + return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
2077 +}
2078 +#endif
2079 +
2080 +#ifdef CONFIG_PAX_KERNEXEC
2081 +static inline unsigned long pax_open_kernel(void) {
2082 +#ifdef CONFIG_ARM_LPAE
2083 + /* TODO */
2084 +#else
2085 + preempt_disable();
2086 + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
2087 + modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2088 +#endif
2089 + return 0;
2090 +}
2091 +
2092 +static inline unsigned long pax_close_kernel(void) {
2093 +#ifdef CONFIG_ARM_LPAE
2094 + /* TODO */
2095 +#else
2096 + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2097 + /* DOMAIN_MANAGER = "client" under KERNEXEC */
2098 + modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2099 + preempt_enable_no_resched();
2100 +#endif
2101 + return 0;
2102 +}
2103 +#else
2104 +static inline unsigned long pax_open_kernel(void) { return 0; }
2105 +static inline unsigned long pax_close_kernel(void) { return 0; }
2106 +#endif
2107 +
2108 /*
2109 * This is the lowest virtual address we can permit any user space
2110 * mapping to be mapped at. This is particularly important for
2111 @@ -75,8 +123,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2112 /*
2113 * The pgprot_* and protection_map entries will be fixed up in runtime
2114 * to include the cachable and bufferable bits based on memory policy,
2115 - * as well as any architecture dependent bits like global/ASID and SMP
2116 - * shared mapping bits.
2117 + * as well as any architecture dependent bits like global/ASID, PXN,
2118 + * and SMP shared mapping bits.
2119 */
2120 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2121
2122 @@ -265,7 +313,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
2123 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2124 {
2125 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2126 - L_PTE_NONE | L_PTE_VALID;
2127 + L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2128 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2129 return pte;
2130 }
2131 diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
2132 index c4ae171..ea0c0c2 100644
2133 --- a/arch/arm/include/asm/psci.h
2134 +++ b/arch/arm/include/asm/psci.h
2135 @@ -29,7 +29,7 @@ struct psci_operations {
2136 int (*cpu_off)(struct psci_power_state state);
2137 int (*cpu_on)(unsigned long cpuid, unsigned long entry_point);
2138 int (*migrate)(unsigned long cpuid);
2139 -};
2140 +} __no_const;
2141
2142 extern struct psci_operations psci_ops;
2143 extern struct smp_operations psci_smp_ops;
2144 diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2145 index 2ec765c..beb1fe16 100644
2146 --- a/arch/arm/include/asm/smp.h
2147 +++ b/arch/arm/include/asm/smp.h
2148 @@ -113,7 +113,7 @@ struct smp_operations {
2149 int (*cpu_disable)(unsigned int cpu);
2150 #endif
2151 #endif
2152 -};
2153 +} __no_const;
2154
2155 struct of_cpu_method {
2156 const char *method;
2157 diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2158 index f989d7c..e8aa7f0 100644
2159 --- a/arch/arm/include/asm/thread_info.h
2160 +++ b/arch/arm/include/asm/thread_info.h
2161 @@ -88,9 +88,9 @@ struct thread_info {
2162 .flags = 0, \
2163 .preempt_count = INIT_PREEMPT_COUNT, \
2164 .addr_limit = KERNEL_DS, \
2165 - .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2166 - domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2167 - domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2168 + .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2169 + domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2170 + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2171 .restart_block = { \
2172 .fn = do_no_restart_syscall, \
2173 }, \
2174 @@ -158,7 +158,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2175 #define TIF_SYSCALL_AUDIT 9
2176 #define TIF_SYSCALL_TRACEPOINT 10
2177 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2178 -#define TIF_NOHZ 12 /* in adaptive nohz mode */
2179 +/* within 8 bits of TIF_SYSCALL_TRACE
2180 + * to meet flexible second operand requirements
2181 + */
2182 +#define TIF_GRSEC_SETXID 12
2183 +#define TIF_NOHZ 13 /* in adaptive nohz mode */
2184 #define TIF_USING_IWMMXT 17
2185 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2186 #define TIF_RESTORE_SIGMASK 20
2187 @@ -172,10 +176,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2188 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2189 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2190 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2191 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2192
2193 /* Checks for any syscall work in entry-common.S */
2194 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2195 - _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2196 + _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2197
2198 /*
2199 * Change these and you break ASM code in entry-common.S
2200 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2201 index 75d9579..b5b40e4 100644
2202 --- a/arch/arm/include/asm/uaccess.h
2203 +++ b/arch/arm/include/asm/uaccess.h
2204 @@ -18,6 +18,7 @@
2205 #include <asm/domain.h>
2206 #include <asm/unified.h>
2207 #include <asm/compiler.h>
2208 +#include <asm/pgtable.h>
2209
2210 #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
2211 #include <asm-generic/uaccess-unaligned.h>
2212 @@ -70,11 +71,38 @@ extern int __put_user_bad(void);
2213 static inline void set_fs(mm_segment_t fs)
2214 {
2215 current_thread_info()->addr_limit = fs;
2216 - modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2217 + modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2218 }
2219
2220 #define segment_eq(a,b) ((a) == (b))
2221
2222 +#define __HAVE_ARCH_PAX_OPEN_USERLAND
2223 +#define __HAVE_ARCH_PAX_CLOSE_USERLAND
2224 +
2225 +static inline void pax_open_userland(void)
2226 +{
2227 +
2228 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2229 + if (segment_eq(get_fs(), USER_DS)) {
2230 + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2231 + modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2232 + }
2233 +#endif
2234 +
2235 +}
2236 +
2237 +static inline void pax_close_userland(void)
2238 +{
2239 +
2240 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2241 + if (segment_eq(get_fs(), USER_DS)) {
2242 + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2243 + modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2244 + }
2245 +#endif
2246 +
2247 +}
2248 +
2249 #define __addr_ok(addr) ({ \
2250 unsigned long flag; \
2251 __asm__("cmp %2, %0; movlo %0, #0" \
2252 @@ -150,8 +178,12 @@ extern int __get_user_4(void *);
2253
2254 #define get_user(x,p) \
2255 ({ \
2256 + int __e; \
2257 might_fault(); \
2258 - __get_user_check(x,p); \
2259 + pax_open_userland(); \
2260 + __e = __get_user_check(x,p); \
2261 + pax_close_userland(); \
2262 + __e; \
2263 })
2264
2265 extern int __put_user_1(void *, unsigned int);
2266 @@ -196,8 +228,12 @@ extern int __put_user_8(void *, unsigned long long);
2267
2268 #define put_user(x,p) \
2269 ({ \
2270 + int __e; \
2271 might_fault(); \
2272 - __put_user_check(x,p); \
2273 + pax_open_userland(); \
2274 + __e = __put_user_check(x,p); \
2275 + pax_close_userland(); \
2276 + __e; \
2277 })
2278
2279 #else /* CONFIG_MMU */
2280 @@ -221,6 +257,7 @@ static inline void set_fs(mm_segment_t fs)
2281
2282 #endif /* CONFIG_MMU */
2283
2284 +#define access_ok_noprefault(type,addr,size) access_ok((type),(addr),(size))
2285 #define access_ok(type,addr,size) (__range_ok(addr,size) == 0)
2286
2287 #define user_addr_max() \
2288 @@ -238,13 +275,17 @@ static inline void set_fs(mm_segment_t fs)
2289 #define __get_user(x,ptr) \
2290 ({ \
2291 long __gu_err = 0; \
2292 + pax_open_userland(); \
2293 __get_user_err((x),(ptr),__gu_err); \
2294 + pax_close_userland(); \
2295 __gu_err; \
2296 })
2297
2298 #define __get_user_error(x,ptr,err) \
2299 ({ \
2300 + pax_open_userland(); \
2301 __get_user_err((x),(ptr),err); \
2302 + pax_close_userland(); \
2303 (void) 0; \
2304 })
2305
2306 @@ -320,13 +361,17 @@ do { \
2307 #define __put_user(x,ptr) \
2308 ({ \
2309 long __pu_err = 0; \
2310 + pax_open_userland(); \
2311 __put_user_err((x),(ptr),__pu_err); \
2312 + pax_close_userland(); \
2313 __pu_err; \
2314 })
2315
2316 #define __put_user_error(x,ptr,err) \
2317 ({ \
2318 + pax_open_userland(); \
2319 __put_user_err((x),(ptr),err); \
2320 + pax_close_userland(); \
2321 (void) 0; \
2322 })
2323
2324 @@ -426,11 +471,44 @@ do { \
2325
2326
2327 #ifdef CONFIG_MMU
2328 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2329 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2330 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2331 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2332 +
2333 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2334 +{
2335 + unsigned long ret;
2336 +
2337 + check_object_size(to, n, false);
2338 + pax_open_userland();
2339 + ret = ___copy_from_user(to, from, n);
2340 + pax_close_userland();
2341 + return ret;
2342 +}
2343 +
2344 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2345 +{
2346 + unsigned long ret;
2347 +
2348 + check_object_size(from, n, true);
2349 + pax_open_userland();
2350 + ret = ___copy_to_user(to, from, n);
2351 + pax_close_userland();
2352 + return ret;
2353 +}
2354 +
2355 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2356 -extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2357 +extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2358 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2359 +
2360 +static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2361 +{
2362 + unsigned long ret;
2363 + pax_open_userland();
2364 + ret = ___clear_user(addr, n);
2365 + pax_close_userland();
2366 + return ret;
2367 +}
2368 +
2369 #else
2370 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2371 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2372 @@ -439,6 +517,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2373
2374 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2375 {
2376 + if ((long)n < 0)
2377 + return n;
2378 +
2379 if (access_ok(VERIFY_READ, from, n))
2380 n = __copy_from_user(to, from, n);
2381 else /* security hole - plug it */
2382 @@ -448,6 +529,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2383
2384 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2385 {
2386 + if ((long)n < 0)
2387 + return n;
2388 +
2389 if (access_ok(VERIFY_WRITE, to, n))
2390 n = __copy_to_user(to, from, n);
2391 return n;
2392 diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2393 index 5af0ed1..cea83883 100644
2394 --- a/arch/arm/include/uapi/asm/ptrace.h
2395 +++ b/arch/arm/include/uapi/asm/ptrace.h
2396 @@ -92,7 +92,7 @@
2397 * ARMv7 groups of PSR bits
2398 */
2399 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2400 -#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2401 +#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2402 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2403 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2404
2405 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2406 index f7b450f..f5364c5 100644
2407 --- a/arch/arm/kernel/armksyms.c
2408 +++ b/arch/arm/kernel/armksyms.c
2409 @@ -55,7 +55,7 @@ EXPORT_SYMBOL(arm_delay_ops);
2410
2411 /* networking */
2412 EXPORT_SYMBOL(csum_partial);
2413 -EXPORT_SYMBOL(csum_partial_copy_from_user);
2414 +EXPORT_SYMBOL(__csum_partial_copy_from_user);
2415 EXPORT_SYMBOL(csum_partial_copy_nocheck);
2416 EXPORT_SYMBOL(__csum_ipv6_magic);
2417
2418 @@ -91,9 +91,9 @@ EXPORT_SYMBOL(__memzero);
2419 #ifdef CONFIG_MMU
2420 EXPORT_SYMBOL(copy_page);
2421
2422 -EXPORT_SYMBOL(__copy_from_user);
2423 -EXPORT_SYMBOL(__copy_to_user);
2424 -EXPORT_SYMBOL(__clear_user);
2425 +EXPORT_SYMBOL(___copy_from_user);
2426 +EXPORT_SYMBOL(___copy_to_user);
2427 +EXPORT_SYMBOL(___clear_user);
2428
2429 EXPORT_SYMBOL(__get_user_1);
2430 EXPORT_SYMBOL(__get_user_2);
2431 diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2432 index 1879e8d..b2207fc 100644
2433 --- a/arch/arm/kernel/entry-armv.S
2434 +++ b/arch/arm/kernel/entry-armv.S
2435 @@ -47,6 +47,87 @@
2436 9997:
2437 .endm
2438
2439 + .macro pax_enter_kernel
2440 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2441 + @ make aligned space for saved DACR
2442 + sub sp, sp, #8
2443 + @ save regs
2444 + stmdb sp!, {r1, r2}
2445 + @ read DACR from cpu_domain into r1
2446 + mov r2, sp
2447 + @ assume 8K pages, since we have to split the immediate in two
2448 + bic r2, r2, #(0x1fc0)
2449 + bic r2, r2, #(0x3f)
2450 + ldr r1, [r2, #TI_CPU_DOMAIN]
2451 + @ store old DACR on stack
2452 + str r1, [sp, #8]
2453 +#ifdef CONFIG_PAX_KERNEXEC
2454 + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2455 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2456 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2457 +#endif
2458 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2459 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2460 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2461 +#endif
2462 + @ write r1 to current_thread_info()->cpu_domain
2463 + str r1, [r2, #TI_CPU_DOMAIN]
2464 + @ write r1 to DACR
2465 + mcr p15, 0, r1, c3, c0, 0
2466 + @ instruction sync
2467 + instr_sync
2468 + @ restore regs
2469 + ldmia sp!, {r1, r2}
2470 +#endif
2471 + .endm
2472 +
2473 + .macro pax_open_userland
2474 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2475 + @ save regs
2476 + stmdb sp!, {r0, r1}
2477 + @ read DACR from cpu_domain into r1
2478 + mov r0, sp
2479 + @ assume 8K pages, since we have to split the immediate in two
2480 + bic r0, r0, #(0x1fc0)
2481 + bic r0, r0, #(0x3f)
2482 + ldr r1, [r0, #TI_CPU_DOMAIN]
2483 + @ set current DOMAIN_USER to DOMAIN_CLIENT
2484 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2485 + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2486 + @ write r1 to current_thread_info()->cpu_domain
2487 + str r1, [r0, #TI_CPU_DOMAIN]
2488 + @ write r1 to DACR
2489 + mcr p15, 0, r1, c3, c0, 0
2490 + @ instruction sync
2491 + instr_sync
2492 + @ restore regs
2493 + ldmia sp!, {r0, r1}
2494 +#endif
2495 + .endm
2496 +
2497 + .macro pax_close_userland
2498 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2499 + @ save regs
2500 + stmdb sp!, {r0, r1}
2501 + @ read DACR from cpu_domain into r1
2502 + mov r0, sp
2503 + @ assume 8K pages, since we have to split the immediate in two
2504 + bic r0, r0, #(0x1fc0)
2505 + bic r0, r0, #(0x3f)
2506 + ldr r1, [r0, #TI_CPU_DOMAIN]
2507 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2508 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2509 + @ write r1 to current_thread_info()->cpu_domain
2510 + str r1, [r0, #TI_CPU_DOMAIN]
2511 + @ write r1 to DACR
2512 + mcr p15, 0, r1, c3, c0, 0
2513 + @ instruction sync
2514 + instr_sync
2515 + @ restore regs
2516 + ldmia sp!, {r0, r1}
2517 +#endif
2518 + .endm
2519 +
2520 .macro pabt_helper
2521 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2522 #ifdef MULTI_PABORT
2523 @@ -89,11 +170,15 @@
2524 * Invalid mode handlers
2525 */
2526 .macro inv_entry, reason
2527 +
2528 + pax_enter_kernel
2529 +
2530 sub sp, sp, #S_FRAME_SIZE
2531 ARM( stmib sp, {r1 - lr} )
2532 THUMB( stmia sp, {r0 - r12} )
2533 THUMB( str sp, [sp, #S_SP] )
2534 THUMB( str lr, [sp, #S_LR] )
2535 +
2536 mov r1, #\reason
2537 .endm
2538
2539 @@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2540 .macro svc_entry, stack_hole=0
2541 UNWIND(.fnstart )
2542 UNWIND(.save {r0 - pc} )
2543 +
2544 + pax_enter_kernel
2545 +
2546 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2547 +
2548 #ifdef CONFIG_THUMB2_KERNEL
2549 SPFIX( str r0, [sp] ) @ temporarily saved
2550 SPFIX( mov r0, sp )
2551 @@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2552 ldmia r0, {r3 - r5}
2553 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2554 mov r6, #-1 @ "" "" "" ""
2555 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2556 + @ offset sp by 8 as done in pax_enter_kernel
2557 + add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2558 +#else
2559 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2560 +#endif
2561 SPFIX( addeq r2, r2, #4 )
2562 str r3, [sp, #-4]! @ save the "real" r0 copied
2563 @ from the exception stack
2564 @@ -317,6 +411,9 @@ ENDPROC(__pabt_svc)
2565 .macro usr_entry
2566 UNWIND(.fnstart )
2567 UNWIND(.cantunwind ) @ don't unwind the user space
2568 +
2569 + pax_enter_kernel_user
2570 +
2571 sub sp, sp, #S_FRAME_SIZE
2572 ARM( stmib sp, {r1 - r12} )
2573 THUMB( stmia sp, {r0 - r12} )
2574 @@ -416,7 +513,9 @@ __und_usr:
2575 tst r3, #PSR_T_BIT @ Thumb mode?
2576 bne __und_usr_thumb
2577 sub r4, r2, #4 @ ARM instr at LR - 4
2578 + pax_open_userland
2579 1: ldrt r0, [r4]
2580 + pax_close_userland
2581 ARM_BE8(rev r0, r0) @ little endian instruction
2582
2583 @ r0 = 32-bit ARM instruction which caused the exception
2584 @@ -450,11 +549,15 @@ __und_usr_thumb:
2585 */
2586 .arch armv6t2
2587 #endif
2588 + pax_open_userland
2589 2: ldrht r5, [r4]
2590 + pax_close_userland
2591 ARM_BE8(rev16 r5, r5) @ little endian instruction
2592 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2593 blo __und_usr_fault_16 @ 16bit undefined instruction
2594 + pax_open_userland
2595 3: ldrht r0, [r2]
2596 + pax_close_userland
2597 ARM_BE8(rev16 r0, r0) @ little endian instruction
2598 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2599 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2600 @@ -484,7 +587,8 @@ ENDPROC(__und_usr)
2601 */
2602 .pushsection .fixup, "ax"
2603 .align 2
2604 -4: mov pc, r9
2605 +4: pax_close_userland
2606 + mov pc, r9
2607 .popsection
2608 .pushsection __ex_table,"a"
2609 .long 1b, 4b
2610 @@ -694,7 +798,7 @@ ENTRY(__switch_to)
2611 THUMB( str lr, [ip], #4 )
2612 ldr r4, [r2, #TI_TP_VALUE]
2613 ldr r5, [r2, #TI_TP_VALUE + 4]
2614 -#ifdef CONFIG_CPU_USE_DOMAINS
2615 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2616 ldr r6, [r2, #TI_CPU_DOMAIN]
2617 #endif
2618 switch_tls r1, r4, r5, r3, r7
2619 @@ -703,7 +807,7 @@ ENTRY(__switch_to)
2620 ldr r8, =__stack_chk_guard
2621 ldr r7, [r7, #TSK_STACK_CANARY]
2622 #endif
2623 -#ifdef CONFIG_CPU_USE_DOMAINS
2624 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2625 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2626 #endif
2627 mov r5, r0
2628 diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2629 index a2dcafd..1048b5a 100644
2630 --- a/arch/arm/kernel/entry-common.S
2631 +++ b/arch/arm/kernel/entry-common.S
2632 @@ -10,18 +10,46 @@
2633
2634 #include <asm/unistd.h>
2635 #include <asm/ftrace.h>
2636 +#include <asm/domain.h>
2637 #include <asm/unwind.h>
2638
2639 +#include "entry-header.S"
2640 +
2641 #ifdef CONFIG_NEED_RET_TO_USER
2642 #include <mach/entry-macro.S>
2643 #else
2644 .macro arch_ret_to_user, tmp1, tmp2
2645 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2646 + @ save regs
2647 + stmdb sp!, {r1, r2}
2648 + @ read DACR from cpu_domain into r1
2649 + mov r2, sp
2650 + @ assume 8K pages, since we have to split the immediate in two
2651 + bic r2, r2, #(0x1fc0)
2652 + bic r2, r2, #(0x3f)
2653 + ldr r1, [r2, #TI_CPU_DOMAIN]
2654 +#ifdef CONFIG_PAX_KERNEXEC
2655 + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2656 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2657 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2658 +#endif
2659 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2660 + @ set current DOMAIN_USER to DOMAIN_UDEREF
2661 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2662 + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2663 +#endif
2664 + @ write r1 to current_thread_info()->cpu_domain
2665 + str r1, [r2, #TI_CPU_DOMAIN]
2666 + @ write r1 to DACR
2667 + mcr p15, 0, r1, c3, c0, 0
2668 + @ instruction sync
2669 + instr_sync
2670 + @ restore regs
2671 + ldmia sp!, {r1, r2}
2672 +#endif
2673 .endm
2674 #endif
2675
2676 -#include "entry-header.S"
2677 -
2678 -
2679 .align 5
2680 /*
2681 * This is the fast syscall return path. We do as little as
2682 @@ -411,6 +439,12 @@ ENTRY(vector_swi)
2683 USER( ldr scno, [lr, #-4] ) @ get SWI instruction
2684 #endif
2685
2686 + /*
2687 + * do this here to avoid a performance hit of wrapping the code above
2688 + * that directly dereferences userland to parse the SWI instruction
2689 + */
2690 + pax_enter_kernel_user
2691 +
2692 adr tbl, sys_call_table @ load syscall table pointer
2693
2694 #if defined(CONFIG_OABI_COMPAT)
2695 diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2696 index efb208d..d34bd02 100644
2697 --- a/arch/arm/kernel/entry-header.S
2698 +++ b/arch/arm/kernel/entry-header.S
2699 @@ -188,6 +188,60 @@
2700 msr cpsr_c, \rtemp @ switch back to the SVC mode
2701 .endm
2702
2703 + .macro pax_enter_kernel_user
2704 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2705 + @ save regs
2706 + stmdb sp!, {r0, r1}
2707 + @ read DACR from cpu_domain into r1
2708 + mov r0, sp
2709 + @ assume 8K pages, since we have to split the immediate in two
2710 + bic r0, r0, #(0x1fc0)
2711 + bic r0, r0, #(0x3f)
2712 + ldr r1, [r0, #TI_CPU_DOMAIN]
2713 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2714 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2715 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2716 +#endif
2717 +#ifdef CONFIG_PAX_KERNEXEC
2718 + @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2719 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2720 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2721 +#endif
2722 + @ write r1 to current_thread_info()->cpu_domain
2723 + str r1, [r0, #TI_CPU_DOMAIN]
2724 + @ write r1 to DACR
2725 + mcr p15, 0, r1, c3, c0, 0
2726 + @ instruction sync
2727 + instr_sync
2728 + @ restore regs
2729 + ldmia sp!, {r0, r1}
2730 +#endif
2731 + .endm
2732 +
2733 + .macro pax_exit_kernel
2734 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2735 + @ save regs
2736 + stmdb sp!, {r0, r1}
2737 + @ read old DACR from stack into r1
2738 + ldr r1, [sp, #(8 + S_SP)]
2739 + sub r1, r1, #8
2740 + ldr r1, [r1]
2741 +
2742 + @ write r1 to current_thread_info()->cpu_domain
2743 + mov r0, sp
2744 + @ assume 8K pages, since we have to split the immediate in two
2745 + bic r0, r0, #(0x1fc0)
2746 + bic r0, r0, #(0x3f)
2747 + str r1, [r0, #TI_CPU_DOMAIN]
2748 + @ write r1 to DACR
2749 + mcr p15, 0, r1, c3, c0, 0
2750 + @ instruction sync
2751 + instr_sync
2752 + @ restore regs
2753 + ldmia sp!, {r0, r1}
2754 +#endif
2755 + .endm
2756 +
2757 #ifndef CONFIG_THUMB2_KERNEL
2758 .macro svc_exit, rpsr, irq = 0
2759 .if \irq != 0
2760 @@ -207,6 +261,9 @@
2761 blne trace_hardirqs_off
2762 #endif
2763 .endif
2764 +
2765 + pax_exit_kernel
2766 +
2767 msr spsr_cxsf, \rpsr
2768 #if defined(CONFIG_CPU_V6)
2769 ldr r0, [sp]
2770 @@ -265,6 +322,9 @@
2771 blne trace_hardirqs_off
2772 #endif
2773 .endif
2774 +
2775 + pax_exit_kernel
2776 +
2777 ldr lr, [sp, #S_SP] @ top of the stack
2778 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2779 clrex @ clear the exclusive monitor
2780 diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2781 index 918875d..cd5fa27 100644
2782 --- a/arch/arm/kernel/fiq.c
2783 +++ b/arch/arm/kernel/fiq.c
2784 @@ -87,7 +87,10 @@ void set_fiq_handler(void *start, unsigned int length)
2785 void *base = vectors_page;
2786 unsigned offset = FIQ_OFFSET;
2787
2788 + pax_open_kernel();
2789 memcpy(base + offset, start, length);
2790 + pax_close_kernel();
2791 +
2792 if (!cache_is_vipt_nonaliasing())
2793 flush_icache_range((unsigned long)base + offset, offset +
2794 length);
2795 diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2796 index 591d6e4..8322a26 100644
2797 --- a/arch/arm/kernel/head.S
2798 +++ b/arch/arm/kernel/head.S
2799 @@ -437,7 +437,7 @@ __enable_mmu:
2800 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2801 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2802 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2803 - domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2804 + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2805 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2806 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2807 #endif
2808 diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2809 index 45e4781..8eac93d 100644
2810 --- a/arch/arm/kernel/module.c
2811 +++ b/arch/arm/kernel/module.c
2812 @@ -38,12 +38,39 @@
2813 #endif
2814
2815 #ifdef CONFIG_MMU
2816 -void *module_alloc(unsigned long size)
2817 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2818 {
2819 + if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2820 + return NULL;
2821 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2822 - GFP_KERNEL, PAGE_KERNEL_EXEC, NUMA_NO_NODE,
2823 + GFP_KERNEL, prot, NUMA_NO_NODE,
2824 __builtin_return_address(0));
2825 }
2826 +
2827 +void *module_alloc(unsigned long size)
2828 +{
2829 +
2830 +#ifdef CONFIG_PAX_KERNEXEC
2831 + return __module_alloc(size, PAGE_KERNEL);
2832 +#else
2833 + return __module_alloc(size, PAGE_KERNEL_EXEC);
2834 +#endif
2835 +
2836 +}
2837 +
2838 +#ifdef CONFIG_PAX_KERNEXEC
2839 +void module_free_exec(struct module *mod, void *module_region)
2840 +{
2841 + module_free(mod, module_region);
2842 +}
2843 +EXPORT_SYMBOL(module_free_exec);
2844 +
2845 +void *module_alloc_exec(unsigned long size)
2846 +{
2847 + return __module_alloc(size, PAGE_KERNEL_EXEC);
2848 +}
2849 +EXPORT_SYMBOL(module_alloc_exec);
2850 +#endif
2851 #endif
2852
2853 int
2854 diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2855 index 07314af..c46655c 100644
2856 --- a/arch/arm/kernel/patch.c
2857 +++ b/arch/arm/kernel/patch.c
2858 @@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2859 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2860 int size;
2861
2862 + pax_open_kernel();
2863 if (thumb2 && __opcode_is_thumb16(insn)) {
2864 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2865 size = sizeof(u16);
2866 @@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2867 *(u32 *)addr = insn;
2868 size = sizeof(u32);
2869 }
2870 + pax_close_kernel();
2871
2872 flush_icache_range((uintptr_t)(addr),
2873 (uintptr_t)(addr) + size);
2874 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2875 index 81ef686..f4130b8 100644
2876 --- a/arch/arm/kernel/process.c
2877 +++ b/arch/arm/kernel/process.c
2878 @@ -212,6 +212,7 @@ void machine_power_off(void)
2879
2880 if (pm_power_off)
2881 pm_power_off();
2882 + BUG();
2883 }
2884
2885 /*
2886 @@ -225,7 +226,7 @@ void machine_power_off(void)
2887 * executing pre-reset code, and using RAM that the primary CPU's code wishes
2888 * to use. Implementing such co-ordination would be essentially impossible.
2889 */
2890 -void machine_restart(char *cmd)
2891 +__noreturn void machine_restart(char *cmd)
2892 {
2893 local_irq_disable();
2894 smp_send_stop();
2895 @@ -248,8 +249,8 @@ void __show_regs(struct pt_regs *regs)
2896
2897 show_regs_print_info(KERN_DEFAULT);
2898
2899 - print_symbol("PC is at %s\n", instruction_pointer(regs));
2900 - print_symbol("LR is at %s\n", regs->ARM_lr);
2901 + printk("PC is at %pA\n", (void *)instruction_pointer(regs));
2902 + printk("LR is at %pA\n", (void *)regs->ARM_lr);
2903 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2904 "sp : %08lx ip : %08lx fp : %08lx\n",
2905 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2906 @@ -425,12 +426,6 @@ unsigned long get_wchan(struct task_struct *p)
2907 return 0;
2908 }
2909
2910 -unsigned long arch_randomize_brk(struct mm_struct *mm)
2911 -{
2912 - unsigned long range_end = mm->brk + 0x02000000;
2913 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2914 -}
2915 -
2916 #ifdef CONFIG_MMU
2917 #ifdef CONFIG_KUSER_HELPERS
2918 /*
2919 @@ -446,7 +441,7 @@ static struct vm_area_struct gate_vma = {
2920
2921 static int __init gate_vma_init(void)
2922 {
2923 - gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
2924 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
2925 return 0;
2926 }
2927 arch_initcall(gate_vma_init);
2928 @@ -472,41 +467,16 @@ int in_gate_area_no_mm(unsigned long addr)
2929
2930 const char *arch_vma_name(struct vm_area_struct *vma)
2931 {
2932 - return is_gate_vma(vma) ? "[vectors]" :
2933 - (vma->vm_mm && vma->vm_start == vma->vm_mm->context.sigpage) ?
2934 - "[sigpage]" : NULL;
2935 + return is_gate_vma(vma) ? "[vectors]" : NULL;
2936 }
2937
2938 -static struct page *signal_page;
2939 -extern struct page *get_signal_page(void);
2940 -
2941 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
2942 {
2943 struct mm_struct *mm = current->mm;
2944 - unsigned long addr;
2945 - int ret;
2946 -
2947 - if (!signal_page)
2948 - signal_page = get_signal_page();
2949 - if (!signal_page)
2950 - return -ENOMEM;
2951
2952 down_write(&mm->mmap_sem);
2953 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
2954 - if (IS_ERR_VALUE(addr)) {
2955 - ret = addr;
2956 - goto up_fail;
2957 - }
2958 -
2959 - ret = install_special_mapping(mm, addr, PAGE_SIZE,
2960 - VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
2961 - &signal_page);
2962 -
2963 - if (ret == 0)
2964 - mm->context.sigpage = addr;
2965 -
2966 - up_fail:
2967 + mm->context.sigpage = (PAGE_OFFSET + (get_random_int() % 0x3FFEFFE0)) & 0xFFFFFFFC;
2968 up_write(&mm->mmap_sem);
2969 - return ret;
2970 + return 0;
2971 }
2972 #endif
2973 diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
2974 index 4693188..4596c5e 100644
2975 --- a/arch/arm/kernel/psci.c
2976 +++ b/arch/arm/kernel/psci.c
2977 @@ -24,7 +24,7 @@
2978 #include <asm/opcodes-virt.h>
2979 #include <asm/psci.h>
2980
2981 -struct psci_operations psci_ops;
2982 +struct psci_operations psci_ops __read_only;
2983
2984 static int (*invoke_psci_fn)(u32, u32, u32, u32);
2985
2986 diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2987 index 0dd3b79..b67388e 100644
2988 --- a/arch/arm/kernel/ptrace.c
2989 +++ b/arch/arm/kernel/ptrace.c
2990 @@ -908,7 +908,7 @@ enum ptrace_syscall_dir {
2991 PTRACE_SYSCALL_EXIT,
2992 };
2993
2994 -static int tracehook_report_syscall(struct pt_regs *regs,
2995 +static void tracehook_report_syscall(struct pt_regs *regs,
2996 enum ptrace_syscall_dir dir)
2997 {
2998 unsigned long ip;
2999 @@ -926,19 +926,29 @@ static int tracehook_report_syscall(struct pt_regs *regs,
3000 current_thread_info()->syscall = -1;
3001
3002 regs->ARM_ip = ip;
3003 - return current_thread_info()->syscall;
3004 }
3005
3006 +#ifdef CONFIG_GRKERNSEC_SETXID
3007 +extern void gr_delayed_cred_worker(void);
3008 +#endif
3009 +
3010 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
3011 {
3012 current_thread_info()->syscall = scno;
3013
3014 +#ifdef CONFIG_GRKERNSEC_SETXID
3015 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
3016 + gr_delayed_cred_worker();
3017 +#endif
3018 +
3019 /* Do the secure computing check first; failures should be fast. */
3020 if (secure_computing(scno) == -1)
3021 return -1;
3022
3023 if (test_thread_flag(TIF_SYSCALL_TRACE))
3024 - scno = tracehook_report_syscall(regs, PTRACE_SYSCALL_ENTER);
3025 + tracehook_report_syscall(regs, PTRACE_SYSCALL_ENTER);
3026 +
3027 + scno = current_thread_info()->syscall;
3028
3029 if (test_thread_flag(TIF_SYSCALL_TRACEPOINT))
3030 trace_sys_enter(regs, scno);
3031 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
3032 index 50e198c..a8b5f49 100644
3033 --- a/arch/arm/kernel/setup.c
3034 +++ b/arch/arm/kernel/setup.c
3035 @@ -103,21 +103,23 @@ EXPORT_SYMBOL(elf_hwcap);
3036 unsigned int elf_hwcap2 __read_mostly;
3037 EXPORT_SYMBOL(elf_hwcap2);
3038
3039 +pteval_t __supported_pte_mask __read_only;
3040 +pmdval_t __supported_pmd_mask __read_only;
3041
3042 #ifdef MULTI_CPU
3043 -struct processor processor __read_mostly;
3044 +struct processor processor __read_only;
3045 #endif
3046 #ifdef MULTI_TLB
3047 -struct cpu_tlb_fns cpu_tlb __read_mostly;
3048 +struct cpu_tlb_fns cpu_tlb __read_only;
3049 #endif
3050 #ifdef MULTI_USER
3051 -struct cpu_user_fns cpu_user __read_mostly;
3052 +struct cpu_user_fns cpu_user __read_only;
3053 #endif
3054 #ifdef MULTI_CACHE
3055 -struct cpu_cache_fns cpu_cache __read_mostly;
3056 +struct cpu_cache_fns cpu_cache __read_only;
3057 #endif
3058 #ifdef CONFIG_OUTER_CACHE
3059 -struct outer_cache_fns outer_cache __read_mostly;
3060 +struct outer_cache_fns outer_cache __read_only;
3061 EXPORT_SYMBOL(outer_cache);
3062 #endif
3063
3064 @@ -250,9 +252,13 @@ static int __get_cpu_architecture(void)
3065 asm("mrc p15, 0, %0, c0, c1, 4"
3066 : "=r" (mmfr0));
3067 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
3068 - (mmfr0 & 0x000000f0) >= 0x00000030)
3069 + (mmfr0 & 0x000000f0) >= 0x00000030) {
3070 cpu_arch = CPU_ARCH_ARMv7;
3071 - else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3072 + if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
3073 + __supported_pte_mask |= L_PTE_PXN;
3074 + __supported_pmd_mask |= PMD_PXNTABLE;
3075 + }
3076 + } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3077 (mmfr0 & 0x000000f0) == 0x00000020)
3078 cpu_arch = CPU_ARCH_ARMv6;
3079 else
3080 diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
3081 index bd19834..e4d8c66 100644
3082 --- a/arch/arm/kernel/signal.c
3083 +++ b/arch/arm/kernel/signal.c
3084 @@ -24,8 +24,6 @@
3085
3086 extern const unsigned long sigreturn_codes[7];
3087
3088 -static unsigned long signal_return_offset;
3089 -
3090 #ifdef CONFIG_CRUNCH
3091 static int preserve_crunch_context(struct crunch_sigframe __user *frame)
3092 {
3093 @@ -396,8 +394,7 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
3094 * except when the MPU has protected the vectors
3095 * page from PL0
3096 */
3097 - retcode = mm->context.sigpage + signal_return_offset +
3098 - (idx << 2) + thumb;
3099 + retcode = mm->context.sigpage + (idx << 2) + thumb;
3100 } else
3101 #endif
3102 {
3103 @@ -604,33 +601,3 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
3104 } while (thread_flags & _TIF_WORK_MASK);
3105 return 0;
3106 }
3107 -
3108 -struct page *get_signal_page(void)
3109 -{
3110 - unsigned long ptr;
3111 - unsigned offset;
3112 - struct page *page;
3113 - void *addr;
3114 -
3115 - page = alloc_pages(GFP_KERNEL, 0);
3116 -
3117 - if (!page)
3118 - return NULL;
3119 -
3120 - addr = page_address(page);
3121 -
3122 - /* Give the signal return code some randomness */
3123 - offset = 0x200 + (get_random_int() & 0x7fc);
3124 - signal_return_offset = offset;
3125 -
3126 - /*
3127 - * Copy signal return handlers into the vector page, and
3128 - * set sigreturn to be a pointer to these.
3129 - */
3130 - memcpy(addr + offset, sigreturn_codes, sizeof(sigreturn_codes));
3131 -
3132 - ptr = (unsigned long)addr + offset;
3133 - flush_icache_range(ptr, ptr + sizeof(sigreturn_codes));
3134 -
3135 - return page;
3136 -}
3137 diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3138 index 7c4fada..8581286 100644
3139 --- a/arch/arm/kernel/smp.c
3140 +++ b/arch/arm/kernel/smp.c
3141 @@ -73,7 +73,7 @@ enum ipi_msg_type {
3142
3143 static DECLARE_COMPLETION(cpu_running);
3144
3145 -static struct smp_operations smp_ops;
3146 +static struct smp_operations smp_ops __read_only;
3147
3148 void __init smp_set_ops(struct smp_operations *ops)
3149 {
3150 diff --git a/arch/arm/kernel/tcm.c b/arch/arm/kernel/tcm.c
3151 index 7a3be1d..b00c7de 100644
3152 --- a/arch/arm/kernel/tcm.c
3153 +++ b/arch/arm/kernel/tcm.c
3154 @@ -61,7 +61,7 @@ static struct map_desc itcm_iomap[] __initdata = {
3155 .virtual = ITCM_OFFSET,
3156 .pfn = __phys_to_pfn(ITCM_OFFSET),
3157 .length = 0,
3158 - .type = MT_MEMORY_RWX_ITCM,
3159 + .type = MT_MEMORY_RX_ITCM,
3160 }
3161 };
3162
3163 @@ -267,7 +267,9 @@ no_dtcm:
3164 start = &__sitcm_text;
3165 end = &__eitcm_text;
3166 ram = &__itcm_start;
3167 + pax_open_kernel();
3168 memcpy(start, ram, itcm_code_sz);
3169 + pax_close_kernel();
3170 pr_debug("CPU ITCM: copied code from %p - %p\n",
3171 start, end);
3172 itcm_present = true;
3173 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3174 index abd2fc0..895dbb6 100644
3175 --- a/arch/arm/kernel/traps.c
3176 +++ b/arch/arm/kernel/traps.c
3177 @@ -62,7 +62,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3178 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3179 {
3180 #ifdef CONFIG_KALLSYMS
3181 - printk("[<%08lx>] (%ps) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3182 + printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3183 #else
3184 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3185 #endif
3186 @@ -264,6 +264,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3187 static int die_owner = -1;
3188 static unsigned int die_nest_count;
3189
3190 +extern void gr_handle_kernel_exploit(void);
3191 +
3192 static unsigned long oops_begin(void)
3193 {
3194 int cpu;
3195 @@ -306,6 +308,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3196 panic("Fatal exception in interrupt");
3197 if (panic_on_oops)
3198 panic("Fatal exception");
3199 +
3200 + gr_handle_kernel_exploit();
3201 +
3202 if (signr)
3203 do_exit(signr);
3204 }
3205 @@ -643,7 +648,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
3206 * The user helper at 0xffff0fe0 must be used instead.
3207 * (see entry-armv.S for details)
3208 */
3209 + pax_open_kernel();
3210 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
3211 + pax_close_kernel();
3212 }
3213 return 0;
3214
3215 @@ -900,7 +907,11 @@ void __init early_trap_init(void *vectors_base)
3216 kuser_init(vectors_base);
3217
3218 flush_icache_range(vectors, vectors + PAGE_SIZE * 2);
3219 - modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3220 +
3221 +#ifndef CONFIG_PAX_MEMORY_UDEREF
3222 + modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3223 +#endif
3224 +
3225 #else /* ifndef CONFIG_CPU_V7M */
3226 /*
3227 * on V7-M there is no need to copy the vector table to a dedicated
3228 diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3229 index 7bcee5c..e2f3249 100644
3230 --- a/arch/arm/kernel/vmlinux.lds.S
3231 +++ b/arch/arm/kernel/vmlinux.lds.S
3232 @@ -8,7 +8,11 @@
3233 #include <asm/thread_info.h>
3234 #include <asm/memory.h>
3235 #include <asm/page.h>
3236 -
3237 +
3238 +#ifdef CONFIG_PAX_KERNEXEC
3239 +#include <asm/pgtable.h>
3240 +#endif
3241 +
3242 #define PROC_INFO \
3243 . = ALIGN(4); \
3244 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3245 @@ -34,7 +38,7 @@
3246 #endif
3247
3248 #if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \
3249 - defined(CONFIG_GENERIC_BUG)
3250 + defined(CONFIG_GENERIC_BUG) || defined(CONFIG_PAX_REFCOUNT)
3251 #define ARM_EXIT_KEEP(x) x
3252 #define ARM_EXIT_DISCARD(x)
3253 #else
3254 @@ -90,6 +94,11 @@ SECTIONS
3255 _text = .;
3256 HEAD_TEXT
3257 }
3258 +
3259 +#ifdef CONFIG_PAX_KERNEXEC
3260 + . = ALIGN(1<<SECTION_SHIFT);
3261 +#endif
3262 +
3263 .text : { /* Real text segment */
3264 _stext = .; /* Text and read-only data */
3265 __exception_text_start = .;
3266 @@ -112,6 +121,8 @@ SECTIONS
3267 ARM_CPU_KEEP(PROC_INFO)
3268 }
3269
3270 + _etext = .; /* End of text section */
3271 +
3272 RO_DATA(PAGE_SIZE)
3273
3274 . = ALIGN(4);
3275 @@ -142,7 +153,9 @@ SECTIONS
3276
3277 NOTES
3278
3279 - _etext = .; /* End of text and rodata section */
3280 +#ifdef CONFIG_PAX_KERNEXEC
3281 + . = ALIGN(1<<SECTION_SHIFT);
3282 +#endif
3283
3284 #ifndef CONFIG_XIP_KERNEL
3285 . = ALIGN(PAGE_SIZE);
3286 @@ -220,6 +233,11 @@ SECTIONS
3287 . = PAGE_OFFSET + TEXT_OFFSET;
3288 #else
3289 __init_end = .;
3290 +
3291 +#ifdef CONFIG_PAX_KERNEXEC
3292 + . = ALIGN(1<<SECTION_SHIFT);
3293 +#endif
3294 +
3295 . = ALIGN(THREAD_SIZE);
3296 __data_loc = .;
3297 #endif
3298 diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
3299 index f0e50a0..8d5d36c 100644
3300 --- a/arch/arm/kvm/arm.c
3301 +++ b/arch/arm/kvm/arm.c
3302 @@ -57,7 +57,7 @@ static unsigned long hyp_default_vectors;
3303 static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu);
3304
3305 /* The VMID used in the VTTBR */
3306 -static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
3307 +static atomic64_unchecked_t kvm_vmid_gen = ATOMIC64_INIT(1);
3308 static u8 kvm_next_vmid;
3309 static DEFINE_SPINLOCK(kvm_vmid_lock);
3310
3311 @@ -408,7 +408,7 @@ void force_vm_exit(const cpumask_t *mask)
3312 */
3313 static bool need_new_vmid_gen(struct kvm *kvm)
3314 {
3315 - return unlikely(kvm->arch.vmid_gen != atomic64_read(&kvm_vmid_gen));
3316 + return unlikely(kvm->arch.vmid_gen != atomic64_read_unchecked(&kvm_vmid_gen));
3317 }
3318
3319 /**
3320 @@ -441,7 +441,7 @@ static void update_vttbr(struct kvm *kvm)
3321
3322 /* First user of a new VMID generation? */
3323 if (unlikely(kvm_next_vmid == 0)) {
3324 - atomic64_inc(&kvm_vmid_gen);
3325 + atomic64_inc_unchecked(&kvm_vmid_gen);
3326 kvm_next_vmid = 1;
3327
3328 /*
3329 @@ -458,7 +458,7 @@ static void update_vttbr(struct kvm *kvm)
3330 kvm_call_hyp(__kvm_flush_vm_context);
3331 }
3332
3333 - kvm->arch.vmid_gen = atomic64_read(&kvm_vmid_gen);
3334 + kvm->arch.vmid_gen = atomic64_read_unchecked(&kvm_vmid_gen);
3335 kvm->arch.vmid = kvm_next_vmid;
3336 kvm_next_vmid++;
3337
3338 diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3339 index 14a0d98..7771a7d 100644
3340 --- a/arch/arm/lib/clear_user.S
3341 +++ b/arch/arm/lib/clear_user.S
3342 @@ -12,14 +12,14 @@
3343
3344 .text
3345
3346 -/* Prototype: int __clear_user(void *addr, size_t sz)
3347 +/* Prototype: int ___clear_user(void *addr, size_t sz)
3348 * Purpose : clear some user memory
3349 * Params : addr - user memory address to clear
3350 * : sz - number of bytes to clear
3351 * Returns : number of bytes NOT cleared
3352 */
3353 ENTRY(__clear_user_std)
3354 -WEAK(__clear_user)
3355 +WEAK(___clear_user)
3356 stmfd sp!, {r1, lr}
3357 mov r2, #0
3358 cmp r1, #4
3359 @@ -44,7 +44,7 @@ WEAK(__clear_user)
3360 USER( strnebt r2, [r0])
3361 mov r0, #0
3362 ldmfd sp!, {r1, pc}
3363 -ENDPROC(__clear_user)
3364 +ENDPROC(___clear_user)
3365 ENDPROC(__clear_user_std)
3366
3367 .pushsection .fixup,"ax"
3368 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3369 index 66a477a..bee61d3 100644
3370 --- a/arch/arm/lib/copy_from_user.S
3371 +++ b/arch/arm/lib/copy_from_user.S
3372 @@ -16,7 +16,7 @@
3373 /*
3374 * Prototype:
3375 *
3376 - * size_t __copy_from_user(void *to, const void *from, size_t n)
3377 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
3378 *
3379 * Purpose:
3380 *
3381 @@ -84,11 +84,11 @@
3382
3383 .text
3384
3385 -ENTRY(__copy_from_user)
3386 +ENTRY(___copy_from_user)
3387
3388 #include "copy_template.S"
3389
3390 -ENDPROC(__copy_from_user)
3391 +ENDPROC(___copy_from_user)
3392
3393 .pushsection .fixup,"ax"
3394 .align 0
3395 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3396 index 6ee2f67..d1cce76 100644
3397 --- a/arch/arm/lib/copy_page.S
3398 +++ b/arch/arm/lib/copy_page.S
3399 @@ -10,6 +10,7 @@
3400 * ASM optimised string functions
3401 */
3402 #include <linux/linkage.h>
3403 +#include <linux/const.h>
3404 #include <asm/assembler.h>
3405 #include <asm/asm-offsets.h>
3406 #include <asm/cache.h>
3407 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3408 index d066df6..df28194 100644
3409 --- a/arch/arm/lib/copy_to_user.S
3410 +++ b/arch/arm/lib/copy_to_user.S
3411 @@ -16,7 +16,7 @@
3412 /*
3413 * Prototype:
3414 *
3415 - * size_t __copy_to_user(void *to, const void *from, size_t n)
3416 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
3417 *
3418 * Purpose:
3419 *
3420 @@ -88,11 +88,11 @@
3421 .text
3422
3423 ENTRY(__copy_to_user_std)
3424 -WEAK(__copy_to_user)
3425 +WEAK(___copy_to_user)
3426
3427 #include "copy_template.S"
3428
3429 -ENDPROC(__copy_to_user)
3430 +ENDPROC(___copy_to_user)
3431 ENDPROC(__copy_to_user_std)
3432
3433 .pushsection .fixup,"ax"
3434 diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3435 index 7d08b43..f7ca7ea 100644
3436 --- a/arch/arm/lib/csumpartialcopyuser.S
3437 +++ b/arch/arm/lib/csumpartialcopyuser.S
3438 @@ -57,8 +57,8 @@
3439 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3440 */
3441
3442 -#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3443 -#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3444 +#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3445 +#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3446
3447 #include "csumpartialcopygeneric.S"
3448
3449 diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3450 index 5306de3..aed6d03 100644
3451 --- a/arch/arm/lib/delay.c
3452 +++ b/arch/arm/lib/delay.c
3453 @@ -28,7 +28,7 @@
3454 /*
3455 * Default to the loop-based delay implementation.
3456 */
3457 -struct arm_delay_ops arm_delay_ops = {
3458 +struct arm_delay_ops arm_delay_ops __read_only = {
3459 .delay = __loop_delay,
3460 .const_udelay = __loop_const_udelay,
3461 .udelay = __loop_udelay,
3462 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3463 index 3e58d71..029817c 100644
3464 --- a/arch/arm/lib/uaccess_with_memcpy.c
3465 +++ b/arch/arm/lib/uaccess_with_memcpy.c
3466 @@ -136,7 +136,7 @@ out:
3467 }
3468
3469 unsigned long
3470 -__copy_to_user(void __user *to, const void *from, unsigned long n)
3471 +___copy_to_user(void __user *to, const void *from, unsigned long n)
3472 {
3473 /*
3474 * This test is stubbed out of the main function above to keep
3475 @@ -190,7 +190,7 @@ out:
3476 return n;
3477 }
3478
3479 -unsigned long __clear_user(void __user *addr, unsigned long n)
3480 +unsigned long ___clear_user(void __user *addr, unsigned long n)
3481 {
3482 /* See rational for this in __copy_to_user() above. */
3483 if (n < 64)
3484 diff --git a/arch/arm/mach-at91/setup.c b/arch/arm/mach-at91/setup.c
3485 index f7a07a5..258e1f7 100644
3486 --- a/arch/arm/mach-at91/setup.c
3487 +++ b/arch/arm/mach-at91/setup.c
3488 @@ -81,7 +81,7 @@ void __init at91_init_sram(int bank, unsigned long base, unsigned int length)
3489
3490 desc->pfn = __phys_to_pfn(base);
3491 desc->length = length;
3492 - desc->type = MT_MEMORY_RWX_NONCACHED;
3493 + desc->type = MT_MEMORY_RW_NONCACHED;
3494
3495 pr_info("AT91: sram at 0x%lx of 0x%x mapped at 0x%lx\n",
3496 base, length, desc->virtual);
3497 diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3498 index 255f33a..507b157 100644
3499 --- a/arch/arm/mach-kirkwood/common.c
3500 +++ b/arch/arm/mach-kirkwood/common.c
3501 @@ -157,7 +157,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3502 clk_gate_ops.disable(hw);
3503 }
3504
3505 -static struct clk_ops clk_gate_fn_ops;
3506 +static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3507 +{
3508 + return clk_gate_ops.is_enabled(hw);
3509 +}
3510 +
3511 +static struct clk_ops clk_gate_fn_ops = {
3512 + .enable = clk_gate_fn_enable,
3513 + .disable = clk_gate_fn_disable,
3514 + .is_enabled = clk_gate_fn_is_enabled,
3515 +};
3516
3517 static struct clk __init *clk_register_gate_fn(struct device *dev,
3518 const char *name,
3519 @@ -191,14 +200,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3520 gate_fn->fn_en = fn_en;
3521 gate_fn->fn_dis = fn_dis;
3522
3523 - /* ops is the gate ops, but with our enable/disable functions */
3524 - if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3525 - clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3526 - clk_gate_fn_ops = clk_gate_ops;
3527 - clk_gate_fn_ops.enable = clk_gate_fn_enable;
3528 - clk_gate_fn_ops.disable = clk_gate_fn_disable;
3529 - }
3530 -
3531 clk = clk_register(dev, &gate_fn->gate.hw);
3532
3533 if (IS_ERR(clk))
3534 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3535 index aead77a..a2253fa 100644
3536 --- a/arch/arm/mach-omap2/board-n8x0.c
3537 +++ b/arch/arm/mach-omap2/board-n8x0.c
3538 @@ -568,7 +568,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3539 }
3540 #endif
3541
3542 -static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3543 +static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3544 .late_init = n8x0_menelaus_late_init,
3545 };
3546
3547 diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3548 index 9fe8c94..c014a4d 100644
3549 --- a/arch/arm/mach-omap2/gpmc.c
3550 +++ b/arch/arm/mach-omap2/gpmc.c
3551 @@ -148,7 +148,6 @@ struct omap3_gpmc_regs {
3552 };
3553
3554 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3555 -static struct irq_chip gpmc_irq_chip;
3556 static int gpmc_irq_start;
3557
3558 static struct resource gpmc_mem_root;
3559 @@ -727,6 +726,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3560
3561 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3562
3563 +static struct irq_chip gpmc_irq_chip = {
3564 + .name = "gpmc",
3565 + .irq_startup = gpmc_irq_noop_ret,
3566 + .irq_enable = gpmc_irq_enable,
3567 + .irq_disable = gpmc_irq_disable,
3568 + .irq_shutdown = gpmc_irq_noop,
3569 + .irq_ack = gpmc_irq_noop,
3570 + .irq_mask = gpmc_irq_noop,
3571 + .irq_unmask = gpmc_irq_noop,
3572 +
3573 +};
3574 +
3575 static int gpmc_setup_irq(void)
3576 {
3577 int i;
3578 @@ -741,15 +752,6 @@ static int gpmc_setup_irq(void)
3579 return gpmc_irq_start;
3580 }
3581
3582 - gpmc_irq_chip.name = "gpmc";
3583 - gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3584 - gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3585 - gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3586 - gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3587 - gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3588 - gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3589 - gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3590 -
3591 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3592 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3593
3594 diff --git a/arch/arm/mach-omap2/omap-mpuss-lowpower.c b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3595 index 667915d..2ee1219 100644
3596 --- a/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3597 +++ b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3598 @@ -84,7 +84,7 @@ struct cpu_pm_ops {
3599 int (*finish_suspend)(unsigned long cpu_state);
3600 void (*resume)(void);
3601 void (*scu_prepare)(unsigned int cpu_id, unsigned int cpu_state);
3602 -};
3603 +} __no_const;
3604
3605 static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
3606 static struct powerdomain *mpuss_pd;
3607 @@ -102,7 +102,7 @@ static void dummy_cpu_resume(void)
3608 static void dummy_scu_prepare(unsigned int cpu_id, unsigned int cpu_state)
3609 {}
3610
3611 -struct cpu_pm_ops omap_pm_ops = {
3612 +static struct cpu_pm_ops omap_pm_ops __read_only = {
3613 .finish_suspend = default_finish_suspend,
3614 .resume = dummy_cpu_resume,
3615 .scu_prepare = dummy_scu_prepare,
3616 diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3617 index 693fe48..c15ea73 100644
3618 --- a/arch/arm/mach-omap2/omap-wakeupgen.c
3619 +++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3620 @@ -343,7 +343,7 @@ static int irq_cpu_hotplug_notify(struct notifier_block *self,
3621 return NOTIFY_OK;
3622 }
3623
3624 -static struct notifier_block __refdata irq_hotplug_notifier = {
3625 +static struct notifier_block irq_hotplug_notifier = {
3626 .notifier_call = irq_cpu_hotplug_notify,
3627 };
3628
3629 diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3630 index 01ef59d..32ae28a8 100644
3631 --- a/arch/arm/mach-omap2/omap_device.c
3632 +++ b/arch/arm/mach-omap2/omap_device.c
3633 @@ -510,7 +510,7 @@ void omap_device_delete(struct omap_device *od)
3634 struct platform_device __init *omap_device_build(const char *pdev_name,
3635 int pdev_id,
3636 struct omap_hwmod *oh,
3637 - void *pdata, int pdata_len)
3638 + const void *pdata, int pdata_len)
3639 {
3640 struct omap_hwmod *ohs[] = { oh };
3641
3642 @@ -538,7 +538,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3643 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3644 int pdev_id,
3645 struct omap_hwmod **ohs,
3646 - int oh_cnt, void *pdata,
3647 + int oh_cnt, const void *pdata,
3648 int pdata_len)
3649 {
3650 int ret = -ENOMEM;
3651 diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3652 index 78c02b3..c94109a 100644
3653 --- a/arch/arm/mach-omap2/omap_device.h
3654 +++ b/arch/arm/mach-omap2/omap_device.h
3655 @@ -72,12 +72,12 @@ int omap_device_idle(struct platform_device *pdev);
3656 /* Core code interface */
3657
3658 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3659 - struct omap_hwmod *oh, void *pdata,
3660 + struct omap_hwmod *oh, const void *pdata,
3661 int pdata_len);
3662
3663 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3664 struct omap_hwmod **oh, int oh_cnt,
3665 - void *pdata, int pdata_len);
3666 + const void *pdata, int pdata_len);
3667
3668 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3669 struct omap_hwmod **ohs, int oh_cnt);
3670 diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3671 index 66c60fe..c78950d 100644
3672 --- a/arch/arm/mach-omap2/omap_hwmod.c
3673 +++ b/arch/arm/mach-omap2/omap_hwmod.c
3674 @@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
3675 int (*init_clkdm)(struct omap_hwmod *oh);
3676 void (*update_context_lost)(struct omap_hwmod *oh);
3677 int (*get_context_lost)(struct omap_hwmod *oh);
3678 -};
3679 +} __no_const;
3680
3681 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3682 -static struct omap_hwmod_soc_ops soc_ops;
3683 +static struct omap_hwmod_soc_ops soc_ops __read_only;
3684
3685 /* omap_hwmod_list contains all registered struct omap_hwmods */
3686 static LIST_HEAD(omap_hwmod_list);
3687 diff --git a/arch/arm/mach-omap2/powerdomains43xx_data.c b/arch/arm/mach-omap2/powerdomains43xx_data.c
3688 index 95fee54..cfa9cf1 100644
3689 --- a/arch/arm/mach-omap2/powerdomains43xx_data.c
3690 +++ b/arch/arm/mach-omap2/powerdomains43xx_data.c
3691 @@ -10,6 +10,7 @@
3692
3693 #include <linux/kernel.h>
3694 #include <linux/init.h>
3695 +#include <asm/pgtable.h>
3696
3697 #include "powerdomain.h"
3698
3699 @@ -129,7 +130,9 @@ static int am43xx_check_vcvp(void)
3700
3701 void __init am43xx_powerdomains_init(void)
3702 {
3703 - omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3704 + pax_open_kernel();
3705 + *(void **)&omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3706 + pax_close_kernel();
3707 pwrdm_register_platform_funcs(&omap4_pwrdm_operations);
3708 pwrdm_register_pwrdms(powerdomains_am43xx);
3709 pwrdm_complete_init();
3710 diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3711 index d15c7bb..b2d1f0c 100644
3712 --- a/arch/arm/mach-omap2/wd_timer.c
3713 +++ b/arch/arm/mach-omap2/wd_timer.c
3714 @@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3715 struct omap_hwmod *oh;
3716 char *oh_name = "wd_timer2";
3717 char *dev_name = "omap_wdt";
3718 - struct omap_wd_timer_platform_data pdata;
3719 + static struct omap_wd_timer_platform_data pdata = {
3720 + .read_reset_sources = prm_read_reset_sources
3721 + };
3722
3723 if (!cpu_class_is_omap2() || of_have_populated_dt())
3724 return 0;
3725 @@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3726 return -EINVAL;
3727 }
3728
3729 - pdata.read_reset_sources = prm_read_reset_sources;
3730 -
3731 pdev = omap_device_build(dev_name, id, oh, &pdata,
3732 sizeof(struct omap_wd_timer_platform_data));
3733 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3734 diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
3735 index b82dcae..44ee5b6 100644
3736 --- a/arch/arm/mach-tegra/cpuidle-tegra20.c
3737 +++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
3738 @@ -180,7 +180,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
3739 bool entered_lp2 = false;
3740
3741 if (tegra_pending_sgi())
3742 - ACCESS_ONCE(abort_flag) = true;
3743 + ACCESS_ONCE_RW(abort_flag) = true;
3744
3745 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
3746
3747 diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
3748 index 2dea8b5..6499da2 100644
3749 --- a/arch/arm/mach-ux500/setup.h
3750 +++ b/arch/arm/mach-ux500/setup.h
3751 @@ -33,13 +33,6 @@ extern void ux500_timer_init(void);
3752 .type = MT_DEVICE, \
3753 }
3754
3755 -#define __MEM_DEV_DESC(x, sz) { \
3756 - .virtual = IO_ADDRESS(x), \
3757 - .pfn = __phys_to_pfn(x), \
3758 - .length = sz, \
3759 - .type = MT_MEMORY_RWX, \
3760 -}
3761 -
3762 extern struct smp_operations ux500_smp_ops;
3763 extern void ux500_cpu_die(unsigned int cpu);
3764
3765 diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3766 index 5bf7c3c..571e67e 100644
3767 --- a/arch/arm/mm/Kconfig
3768 +++ b/arch/arm/mm/Kconfig
3769 @@ -446,6 +446,7 @@ config CPU_32v5
3770
3771 config CPU_32v6
3772 bool
3773 + select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3774 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3775
3776 config CPU_32v6K
3777 @@ -600,6 +601,7 @@ config CPU_CP15_MPU
3778
3779 config CPU_USE_DOMAINS
3780 bool
3781 + depends on !ARM_LPAE && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3782 help
3783 This option enables or disables the use of domain switching
3784 via the set_fs() function.
3785 @@ -799,6 +801,7 @@ config NEED_KUSER_HELPERS
3786 config KUSER_HELPERS
3787 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
3788 default y
3789 + depends on !(CPU_V6 || CPU_V6K || CPU_V7) || GRKERNSEC_OLD_ARM_USERLAND
3790 help
3791 Warning: disabling this option may break user programs.
3792
3793 @@ -811,7 +814,7 @@ config KUSER_HELPERS
3794 See Documentation/arm/kernel_user_helpers.txt for details.
3795
3796 However, the fixed address nature of these helpers can be used
3797 - by ROP (return orientated programming) authors when creating
3798 + by ROP (Return Oriented Programming) authors when creating
3799 exploits.
3800
3801 If all of the binaries and libraries which run on your platform
3802 diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3803 index 9240364..a2b8cf3 100644
3804 --- a/arch/arm/mm/alignment.c
3805 +++ b/arch/arm/mm/alignment.c
3806 @@ -212,10 +212,12 @@ union offset_union {
3807 #define __get16_unaligned_check(ins,val,addr) \
3808 do { \
3809 unsigned int err = 0, v, a = addr; \
3810 + pax_open_userland(); \
3811 __get8_unaligned_check(ins,v,a,err); \
3812 val = v << ((BE) ? 8 : 0); \
3813 __get8_unaligned_check(ins,v,a,err); \
3814 val |= v << ((BE) ? 0 : 8); \
3815 + pax_close_userland(); \
3816 if (err) \
3817 goto fault; \
3818 } while (0)
3819 @@ -229,6 +231,7 @@ union offset_union {
3820 #define __get32_unaligned_check(ins,val,addr) \
3821 do { \
3822 unsigned int err = 0, v, a = addr; \
3823 + pax_open_userland(); \
3824 __get8_unaligned_check(ins,v,a,err); \
3825 val = v << ((BE) ? 24 : 0); \
3826 __get8_unaligned_check(ins,v,a,err); \
3827 @@ -237,6 +240,7 @@ union offset_union {
3828 val |= v << ((BE) ? 8 : 16); \
3829 __get8_unaligned_check(ins,v,a,err); \
3830 val |= v << ((BE) ? 0 : 24); \
3831 + pax_close_userland(); \
3832 if (err) \
3833 goto fault; \
3834 } while (0)
3835 @@ -250,6 +254,7 @@ union offset_union {
3836 #define __put16_unaligned_check(ins,val,addr) \
3837 do { \
3838 unsigned int err = 0, v = val, a = addr; \
3839 + pax_open_userland(); \
3840 __asm__( FIRST_BYTE_16 \
3841 ARM( "1: "ins" %1, [%2], #1\n" ) \
3842 THUMB( "1: "ins" %1, [%2]\n" ) \
3843 @@ -269,6 +274,7 @@ union offset_union {
3844 " .popsection\n" \
3845 : "=r" (err), "=&r" (v), "=&r" (a) \
3846 : "0" (err), "1" (v), "2" (a)); \
3847 + pax_close_userland(); \
3848 if (err) \
3849 goto fault; \
3850 } while (0)
3851 @@ -282,6 +288,7 @@ union offset_union {
3852 #define __put32_unaligned_check(ins,val,addr) \
3853 do { \
3854 unsigned int err = 0, v = val, a = addr; \
3855 + pax_open_userland(); \
3856 __asm__( FIRST_BYTE_32 \
3857 ARM( "1: "ins" %1, [%2], #1\n" ) \
3858 THUMB( "1: "ins" %1, [%2]\n" ) \
3859 @@ -311,6 +318,7 @@ union offset_union {
3860 " .popsection\n" \
3861 : "=r" (err), "=&r" (v), "=&r" (a) \
3862 : "0" (err), "1" (v), "2" (a)); \
3863 + pax_close_userland(); \
3864 if (err) \
3865 goto fault; \
3866 } while (0)
3867 diff --git a/arch/arm/mm/cache-l2x0.c b/arch/arm/mm/cache-l2x0.c
3868 index 7abde2c..9df495f 100644
3869 --- a/arch/arm/mm/cache-l2x0.c
3870 +++ b/arch/arm/mm/cache-l2x0.c
3871 @@ -46,7 +46,7 @@ struct l2x0_of_data {
3872 void (*setup)(const struct device_node *, u32 *, u32 *);
3873 void (*save)(void);
3874 struct outer_cache_fns outer_cache;
3875 -};
3876 +} __do_const;
3877
3878 static bool of_init = false;
3879
3880 diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
3881 index 6eb97b3..ac509f6 100644
3882 --- a/arch/arm/mm/context.c
3883 +++ b/arch/arm/mm/context.c
3884 @@ -43,7 +43,7 @@
3885 #define NUM_USER_ASIDS ASID_FIRST_VERSION
3886
3887 static DEFINE_RAW_SPINLOCK(cpu_asid_lock);
3888 -static atomic64_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3889 +static atomic64_unchecked_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3890 static DECLARE_BITMAP(asid_map, NUM_USER_ASIDS);
3891
3892 static DEFINE_PER_CPU(atomic64_t, active_asids);
3893 @@ -182,7 +182,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3894 {
3895 static u32 cur_idx = 1;
3896 u64 asid = atomic64_read(&mm->context.id);
3897 - u64 generation = atomic64_read(&asid_generation);
3898 + u64 generation = atomic64_read_unchecked(&asid_generation);
3899
3900 if (asid != 0 && is_reserved_asid(asid)) {
3901 /*
3902 @@ -203,7 +203,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3903 */
3904 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, cur_idx);
3905 if (asid == NUM_USER_ASIDS) {
3906 - generation = atomic64_add_return(ASID_FIRST_VERSION,
3907 + generation = atomic64_add_return_unchecked(ASID_FIRST_VERSION,
3908 &asid_generation);
3909 flush_context(cpu);
3910 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3911 @@ -234,14 +234,14 @@ void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk)
3912 cpu_set_reserved_ttbr0();
3913
3914 asid = atomic64_read(&mm->context.id);
3915 - if (!((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS)
3916 + if (!((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS)
3917 && atomic64_xchg(&per_cpu(active_asids, cpu), asid))
3918 goto switch_mm_fastpath;
3919
3920 raw_spin_lock_irqsave(&cpu_asid_lock, flags);
3921 /* Check that our ASID belongs to the current generation. */
3922 asid = atomic64_read(&mm->context.id);
3923 - if ((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS) {
3924 + if ((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS) {
3925 asid = new_context(mm, cpu);
3926 atomic64_set(&mm->context.id, asid);
3927 }
3928 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3929 index eb8830a..5360ce7 100644
3930 --- a/arch/arm/mm/fault.c
3931 +++ b/arch/arm/mm/fault.c
3932 @@ -25,6 +25,7 @@
3933 #include <asm/system_misc.h>
3934 #include <asm/system_info.h>
3935 #include <asm/tlbflush.h>
3936 +#include <asm/sections.h>
3937
3938 #include "fault.h"
3939
3940 @@ -138,6 +139,31 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3941 if (fixup_exception(regs))
3942 return;
3943
3944 +#ifdef CONFIG_PAX_MEMORY_UDEREF
3945 + if (addr < TASK_SIZE) {
3946 + if (current->signal->curr_ip)
3947 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
3948 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3949 + else
3950 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3951 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3952 + }
3953 +#endif
3954 +
3955 +#ifdef CONFIG_PAX_KERNEXEC
3956 + if ((fsr & FSR_WRITE) &&
3957 + (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3958 + (MODULES_VADDR <= addr && addr < MODULES_END)))
3959 + {
3960 + if (current->signal->curr_ip)
3961 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
3962 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3963 + else
3964 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3965 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3966 + }
3967 +#endif
3968 +
3969 /*
3970 * No handler, we'll have to terminate things with extreme prejudice.
3971 */
3972 @@ -174,6 +200,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3973 }
3974 #endif
3975
3976 +#ifdef CONFIG_PAX_PAGEEXEC
3977 + if (fsr & FSR_LNX_PF) {
3978 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3979 + do_group_exit(SIGKILL);
3980 + }
3981 +#endif
3982 +
3983 tsk->thread.address = addr;
3984 tsk->thread.error_code = fsr;
3985 tsk->thread.trap_no = 14;
3986 @@ -401,6 +434,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3987 }
3988 #endif /* CONFIG_MMU */
3989
3990 +#ifdef CONFIG_PAX_PAGEEXEC
3991 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3992 +{
3993 + long i;
3994 +
3995 + printk(KERN_ERR "PAX: bytes at PC: ");
3996 + for (i = 0; i < 20; i++) {
3997 + unsigned char c;
3998 + if (get_user(c, (__force unsigned char __user *)pc+i))
3999 + printk(KERN_CONT "?? ");
4000 + else
4001 + printk(KERN_CONT "%02x ", c);
4002 + }
4003 + printk("\n");
4004 +
4005 + printk(KERN_ERR "PAX: bytes at SP-4: ");
4006 + for (i = -1; i < 20; i++) {
4007 + unsigned long c;
4008 + if (get_user(c, (__force unsigned long __user *)sp+i))
4009 + printk(KERN_CONT "???????? ");
4010 + else
4011 + printk(KERN_CONT "%08lx ", c);
4012 + }
4013 + printk("\n");
4014 +}
4015 +#endif
4016 +
4017 /*
4018 * First Level Translation Fault Handler
4019 *
4020 @@ -548,9 +608,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
4021 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
4022 struct siginfo info;
4023
4024 +#ifdef CONFIG_PAX_MEMORY_UDEREF
4025 + if (addr < TASK_SIZE && is_domain_fault(fsr)) {
4026 + if (current->signal->curr_ip)
4027 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
4028 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4029 + else
4030 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
4031 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
4032 + goto die;
4033 + }
4034 +#endif
4035 +
4036 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
4037 return;
4038
4039 +die:
4040 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
4041 inf->name, fsr, addr);
4042
4043 @@ -574,15 +647,98 @@ hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *
4044 ifsr_info[nr].name = name;
4045 }
4046
4047 +asmlinkage int sys_sigreturn(struct pt_regs *regs);
4048 +asmlinkage int sys_rt_sigreturn(struct pt_regs *regs);
4049 +
4050 asmlinkage void __exception
4051 do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
4052 {
4053 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
4054 struct siginfo info;
4055 + unsigned long pc = instruction_pointer(regs);
4056 +
4057 + if (user_mode(regs)) {
4058 + unsigned long sigpage = current->mm->context.sigpage;
4059 +
4060 + if (sigpage <= pc && pc < sigpage + 7*4) {
4061 + if (pc < sigpage + 3*4)
4062 + sys_sigreturn(regs);
4063 + else
4064 + sys_rt_sigreturn(regs);
4065 + return;
4066 + }
4067 + if (pc == 0xffff0f60UL) {
4068 + /*
4069 + * PaX: __kuser_cmpxchg64 emulation
4070 + */
4071 + // TODO
4072 + //regs->ARM_pc = regs->ARM_lr;
4073 + //return;
4074 + }
4075 + if (pc == 0xffff0fa0UL) {
4076 + /*
4077 + * PaX: __kuser_memory_barrier emulation
4078 + */
4079 + // dmb(); implied by the exception
4080 + regs->ARM_pc = regs->ARM_lr;
4081 + return;
4082 + }
4083 + if (pc == 0xffff0fc0UL) {
4084 + /*
4085 + * PaX: __kuser_cmpxchg emulation
4086 + */
4087 + // TODO
4088 + //long new;
4089 + //int op;
4090 +
4091 + //op = FUTEX_OP_SET << 28;
4092 + //new = futex_atomic_op_inuser(op, regs->ARM_r2);
4093 + //regs->ARM_r0 = old != new;
4094 + //regs->ARM_pc = regs->ARM_lr;
4095 + //return;
4096 + }
4097 + if (pc == 0xffff0fe0UL) {
4098 + /*
4099 + * PaX: __kuser_get_tls emulation
4100 + */
4101 + regs->ARM_r0 = current_thread_info()->tp_value[0];
4102 + regs->ARM_pc = regs->ARM_lr;
4103 + return;
4104 + }
4105 + }
4106 +
4107 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4108 + else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
4109 + if (current->signal->curr_ip)
4110 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", &current->signal->curr_ip, current->comm, task_pid_nr(current),
4111 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4112 + pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4113 + else
4114 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
4115 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4116 + pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4117 + goto die;
4118 + }
4119 +#endif
4120 +
4121 +#ifdef CONFIG_PAX_REFCOUNT
4122 + if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
4123 + unsigned int bkpt;
4124 +
4125 + if (!probe_kernel_address(pc, bkpt) && cpu_to_le32(bkpt) == 0xe12f1073) {
4126 + current->thread.error_code = ifsr;
4127 + current->thread.trap_no = 0;
4128 + pax_report_refcount_overflow(regs);
4129 + fixup_exception(regs);
4130 + return;
4131 + }
4132 + }
4133 +#endif
4134
4135 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
4136 return;
4137
4138 +die:
4139 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
4140 inf->name, ifsr, addr);
4141
4142 diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
4143 index cf08bdf..772656c 100644
4144 --- a/arch/arm/mm/fault.h
4145 +++ b/arch/arm/mm/fault.h
4146 @@ -3,6 +3,7 @@
4147
4148 /*
4149 * Fault status register encodings. We steal bit 31 for our own purposes.
4150 + * Set when the FSR value is from an instruction fault.
4151 */
4152 #define FSR_LNX_PF (1 << 31)
4153 #define FSR_WRITE (1 << 11)
4154 @@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
4155 }
4156 #endif
4157
4158 +/* valid for LPAE and !LPAE */
4159 +static inline int is_xn_fault(unsigned int fsr)
4160 +{
4161 + return ((fsr_fs(fsr) & 0x3c) == 0xc);
4162 +}
4163 +
4164 +static inline int is_domain_fault(unsigned int fsr)
4165 +{
4166 + return ((fsr_fs(fsr) & 0xD) == 0x9);
4167 +}
4168 +
4169 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
4170 unsigned long search_exception_table(unsigned long addr);
4171
4172 diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
4173 index 2a77ba8..68e6a7a 100644
4174 --- a/arch/arm/mm/init.c
4175 +++ b/arch/arm/mm/init.c
4176 @@ -30,6 +30,8 @@
4177 #include <asm/setup.h>
4178 #include <asm/tlb.h>
4179 #include <asm/fixmap.h>
4180 +#include <asm/system_info.h>
4181 +#include <asm/cp15.h>
4182
4183 #include <asm/mach/arch.h>
4184 #include <asm/mach/map.h>
4185 @@ -627,7 +629,46 @@ void free_initmem(void)
4186 {
4187 #ifdef CONFIG_HAVE_TCM
4188 extern char __tcm_start, __tcm_end;
4189 +#endif
4190
4191 +#ifdef CONFIG_PAX_KERNEXEC
4192 + unsigned long addr;
4193 + pgd_t *pgd;
4194 + pud_t *pud;
4195 + pmd_t *pmd;
4196 + int cpu_arch = cpu_architecture();
4197 + unsigned int cr = get_cr();
4198 +
4199 + if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
4200 + /* make pages tables, etc before .text NX */
4201 + for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
4202 + pgd = pgd_offset_k(addr);
4203 + pud = pud_offset(pgd, addr);
4204 + pmd = pmd_offset(pud, addr);
4205 + __section_update(pmd, addr, PMD_SECT_XN);
4206 + }
4207 + /* make init NX */
4208 + for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
4209 + pgd = pgd_offset_k(addr);
4210 + pud = pud_offset(pgd, addr);
4211 + pmd = pmd_offset(pud, addr);
4212 + __section_update(pmd, addr, PMD_SECT_XN);
4213 + }
4214 + /* make kernel code/rodata RX */
4215 + for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
4216 + pgd = pgd_offset_k(addr);
4217 + pud = pud_offset(pgd, addr);
4218 + pmd = pmd_offset(pud, addr);
4219 +#ifdef CONFIG_ARM_LPAE
4220 + __section_update(pmd, addr, PMD_SECT_RDONLY);
4221 +#else
4222 + __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
4223 +#endif
4224 + }
4225 + }
4226 +#endif
4227 +
4228 +#ifdef CONFIG_HAVE_TCM
4229 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
4230 free_reserved_area(&__tcm_start, &__tcm_end, -1, "TCM link");
4231 #endif
4232 diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
4233 index f9c32ba..8540068 100644
4234 --- a/arch/arm/mm/ioremap.c
4235 +++ b/arch/arm/mm/ioremap.c
4236 @@ -392,9 +392,9 @@ __arm_ioremap_exec(phys_addr_t phys_addr, size_t size, bool cached)
4237 unsigned int mtype;
4238
4239 if (cached)
4240 - mtype = MT_MEMORY_RWX;
4241 + mtype = MT_MEMORY_RX;
4242 else
4243 - mtype = MT_MEMORY_RWX_NONCACHED;
4244 + mtype = MT_MEMORY_RX_NONCACHED;
4245
4246 return __arm_ioremap_caller(phys_addr, size, mtype,
4247 __builtin_return_address(0));
4248 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
4249 index 5e85ed3..b10a7ed 100644
4250 --- a/arch/arm/mm/mmap.c
4251 +++ b/arch/arm/mm/mmap.c
4252 @@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4253 struct vm_area_struct *vma;
4254 int do_align = 0;
4255 int aliasing = cache_is_vipt_aliasing();
4256 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4257 struct vm_unmapped_area_info info;
4258
4259 /*
4260 @@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4261 if (len > TASK_SIZE)
4262 return -ENOMEM;
4263
4264 +#ifdef CONFIG_PAX_RANDMMAP
4265 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4266 +#endif
4267 +
4268 if (addr) {
4269 if (do_align)
4270 addr = COLOUR_ALIGN(addr, pgoff);
4271 @@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4272 addr = PAGE_ALIGN(addr);
4273
4274 vma = find_vma(mm, addr);
4275 - if (TASK_SIZE - len >= addr &&
4276 - (!vma || addr + len <= vma->vm_start))
4277 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4278 return addr;
4279 }
4280
4281 @@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4282 info.high_limit = TASK_SIZE;
4283 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4284 info.align_offset = pgoff << PAGE_SHIFT;
4285 + info.threadstack_offset = offset;
4286 return vm_unmapped_area(&info);
4287 }
4288
4289 @@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4290 unsigned long addr = addr0;
4291 int do_align = 0;
4292 int aliasing = cache_is_vipt_aliasing();
4293 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4294 struct vm_unmapped_area_info info;
4295
4296 /*
4297 @@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4298 return addr;
4299 }
4300
4301 +#ifdef CONFIG_PAX_RANDMMAP
4302 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4303 +#endif
4304 +
4305 /* requesting a specific address */
4306 if (addr) {
4307 if (do_align)
4308 @@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4309 else
4310 addr = PAGE_ALIGN(addr);
4311 vma = find_vma(mm, addr);
4312 - if (TASK_SIZE - len >= addr &&
4313 - (!vma || addr + len <= vma->vm_start))
4314 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4315 return addr;
4316 }
4317
4318 @@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4319 info.high_limit = mm->mmap_base;
4320 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4321 info.align_offset = pgoff << PAGE_SHIFT;
4322 + info.threadstack_offset = offset;
4323 addr = vm_unmapped_area(&info);
4324
4325 /*
4326 @@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4327 {
4328 unsigned long random_factor = 0UL;
4329
4330 +#ifdef CONFIG_PAX_RANDMMAP
4331 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4332 +#endif
4333 +
4334 /* 8 bits of randomness in 20 address space bits */
4335 if ((current->flags & PF_RANDOMIZE) &&
4336 !(current->personality & ADDR_NO_RANDOMIZE))
4337 @@ -180,9 +194,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4338
4339 if (mmap_is_legacy()) {
4340 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4341 +
4342 +#ifdef CONFIG_PAX_RANDMMAP
4343 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4344 + mm->mmap_base += mm->delta_mmap;
4345 +#endif
4346 +
4347 mm->get_unmapped_area = arch_get_unmapped_area;
4348 } else {
4349 mm->mmap_base = mmap_base(random_factor);
4350 +
4351 +#ifdef CONFIG_PAX_RANDMMAP
4352 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4353 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4354 +#endif
4355 +
4356 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4357 }
4358 }
4359 diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4360 index b68c6b2..f66c492 100644
4361 --- a/arch/arm/mm/mmu.c
4362 +++ b/arch/arm/mm/mmu.c
4363 @@ -39,6 +39,22 @@
4364 #include "mm.h"
4365 #include "tcm.h"
4366
4367 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4368 +void modify_domain(unsigned int dom, unsigned int type)
4369 +{
4370 + struct thread_info *thread = current_thread_info();
4371 + unsigned int domain = thread->cpu_domain;
4372 + /*
4373 + * DOMAIN_MANAGER might be defined to some other value,
4374 + * use the arch-defined constant
4375 + */
4376 + domain &= ~domain_val(dom, 3);
4377 + thread->cpu_domain = domain | domain_val(dom, type);
4378 + set_domain(thread->cpu_domain);
4379 +}
4380 +EXPORT_SYMBOL(modify_domain);
4381 +#endif
4382 +
4383 /*
4384 * empty_zero_page is a special page that is used for
4385 * zero-initialized data and COW.
4386 @@ -235,7 +251,15 @@ __setup("noalign", noalign_setup);
4387 #define PROT_PTE_S2_DEVICE PROT_PTE_DEVICE
4388 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4389
4390 -static struct mem_type mem_types[] = {
4391 +#ifdef CONFIG_PAX_KERNEXEC
4392 +#define L_PTE_KERNEXEC L_PTE_RDONLY
4393 +#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4394 +#else
4395 +#define L_PTE_KERNEXEC L_PTE_DIRTY
4396 +#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4397 +#endif
4398 +
4399 +static struct mem_type mem_types[] __read_only = {
4400 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4401 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4402 L_PTE_SHARED,
4403 @@ -264,19 +288,19 @@ static struct mem_type mem_types[] = {
4404 .prot_sect = PROT_SECT_DEVICE,
4405 .domain = DOMAIN_IO,
4406 },
4407 - [MT_UNCACHED] = {
4408 + [MT_UNCACHED_RW] = {
4409 .prot_pte = PROT_PTE_DEVICE,
4410 .prot_l1 = PMD_TYPE_TABLE,
4411 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4412 .domain = DOMAIN_IO,
4413 },
4414 - [MT_CACHECLEAN] = {
4415 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4416 + [MT_CACHECLEAN_RO] = {
4417 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_RDONLY,
4418 .domain = DOMAIN_KERNEL,
4419 },
4420 #ifndef CONFIG_ARM_LPAE
4421 - [MT_MINICLEAN] = {
4422 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4423 + [MT_MINICLEAN_RO] = {
4424 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_XN | PMD_SECT_RDONLY,
4425 .domain = DOMAIN_KERNEL,
4426 },
4427 #endif
4428 @@ -284,15 +308,15 @@ static struct mem_type mem_types[] = {
4429 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4430 L_PTE_RDONLY,
4431 .prot_l1 = PMD_TYPE_TABLE,
4432 - .domain = DOMAIN_USER,
4433 + .domain = DOMAIN_VECTORS,
4434 },
4435 [MT_HIGH_VECTORS] = {
4436 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4437 L_PTE_USER | L_PTE_RDONLY,
4438 .prot_l1 = PMD_TYPE_TABLE,
4439 - .domain = DOMAIN_USER,
4440 + .domain = DOMAIN_VECTORS,
4441 },
4442 - [MT_MEMORY_RWX] = {
4443 + [__MT_MEMORY_RWX] = {
4444 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4445 .prot_l1 = PMD_TYPE_TABLE,
4446 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4447 @@ -305,17 +329,30 @@ static struct mem_type mem_types[] = {
4448 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4449 .domain = DOMAIN_KERNEL,
4450 },
4451 - [MT_ROM] = {
4452 - .prot_sect = PMD_TYPE_SECT,
4453 + [MT_MEMORY_RX] = {
4454 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4455 + .prot_l1 = PMD_TYPE_TABLE,
4456 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4457 + .domain = DOMAIN_KERNEL,
4458 + },
4459 + [MT_ROM_RX] = {
4460 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4461 .domain = DOMAIN_KERNEL,
4462 },
4463 - [MT_MEMORY_RWX_NONCACHED] = {
4464 + [MT_MEMORY_RW_NONCACHED] = {
4465 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4466 L_PTE_MT_BUFFERABLE,
4467 .prot_l1 = PMD_TYPE_TABLE,
4468 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4469 .domain = DOMAIN_KERNEL,
4470 },
4471 + [MT_MEMORY_RX_NONCACHED] = {
4472 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC |
4473 + L_PTE_MT_BUFFERABLE,
4474 + .prot_l1 = PMD_TYPE_TABLE,
4475 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4476 + .domain = DOMAIN_KERNEL,
4477 + },
4478 [MT_MEMORY_RW_DTCM] = {
4479 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4480 L_PTE_XN,
4481 @@ -323,9 +360,10 @@ static struct mem_type mem_types[] = {
4482 .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4483 .domain = DOMAIN_KERNEL,
4484 },
4485 - [MT_MEMORY_RWX_ITCM] = {
4486 - .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4487 + [MT_MEMORY_RX_ITCM] = {
4488 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4489 .prot_l1 = PMD_TYPE_TABLE,
4490 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4491 .domain = DOMAIN_KERNEL,
4492 },
4493 [MT_MEMORY_RW_SO] = {
4494 @@ -534,9 +572,14 @@ static void __init build_mem_type_table(void)
4495 * Mark cache clean areas and XIP ROM read only
4496 * from SVC mode and no access from userspace.
4497 */
4498 - mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4499 - mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4500 - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4501 + mem_types[MT_ROM_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4502 +#ifdef CONFIG_PAX_KERNEXEC
4503 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4504 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4505 + mem_types[MT_MEMORY_RX_ITCM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4506 +#endif
4507 + mem_types[MT_MINICLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4508 + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4509 #endif
4510
4511 if (is_smp()) {
4512 @@ -552,13 +595,17 @@ static void __init build_mem_type_table(void)
4513 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4514 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4515 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4516 - mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4517 - mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4518 + mem_types[__MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4519 + mem_types[__MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4520 mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4521 mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4522 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4523 + mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4524 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4525 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_S;
4526 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_pte |= L_PTE_SHARED;
4527 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_S;
4528 + mem_types[MT_MEMORY_RW_NONCACHED].prot_pte |= L_PTE_SHARED;
4529 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_S;
4530 + mem_types[MT_MEMORY_RX_NONCACHED].prot_pte |= L_PTE_SHARED;
4531 }
4532 }
4533
4534 @@ -569,15 +616,20 @@ static void __init build_mem_type_table(void)
4535 if (cpu_arch >= CPU_ARCH_ARMv6) {
4536 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4537 /* Non-cacheable Normal is XCB = 001 */
4538 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
4539 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
4540 + PMD_SECT_BUFFERED;
4541 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
4542 PMD_SECT_BUFFERED;
4543 } else {
4544 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4545 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |=
4546 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |=
4547 + PMD_SECT_TEX(1);
4548 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |=
4549 PMD_SECT_TEX(1);
4550 }
4551 } else {
4552 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4553 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4554 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4555 }
4556
4557 #ifdef CONFIG_ARM_LPAE
4558 @@ -593,6 +645,8 @@ static void __init build_mem_type_table(void)
4559 vecs_pgprot |= PTE_EXT_AF;
4560 #endif
4561
4562 + user_pgprot |= __supported_pte_mask;
4563 +
4564 for (i = 0; i < 16; i++) {
4565 pteval_t v = pgprot_val(protection_map[i]);
4566 protection_map[i] = __pgprot(v | user_pgprot);
4567 @@ -610,21 +664,24 @@ static void __init build_mem_type_table(void)
4568
4569 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4570 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4571 - mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4572 - mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4573 + mem_types[__MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4574 + mem_types[__MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4575 mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4576 mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4577 + mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4578 + mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4579 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4580 - mem_types[MT_MEMORY_RWX_NONCACHED].prot_sect |= ecc_mask;
4581 - mem_types[MT_ROM].prot_sect |= cp->pmd;
4582 + mem_types[MT_MEMORY_RW_NONCACHED].prot_sect |= ecc_mask;
4583 + mem_types[MT_MEMORY_RX_NONCACHED].prot_sect |= ecc_mask;
4584 + mem_types[MT_ROM_RX].prot_sect |= cp->pmd;
4585
4586 switch (cp->pmd) {
4587 case PMD_SECT_WT:
4588 - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WT;
4589 + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WT;
4590 break;
4591 case PMD_SECT_WB:
4592 case PMD_SECT_WBWA:
4593 - mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_WB;
4594 + mem_types[MT_CACHECLEAN_RO].prot_sect |= PMD_SECT_WB;
4595 break;
4596 }
4597 pr_info("Memory policy: %sData cache %s\n",
4598 @@ -842,7 +899,7 @@ static void __init create_mapping(struct map_desc *md)
4599 return;
4600 }
4601
4602 - if ((md->type == MT_DEVICE || md->type == MT_ROM) &&
4603 + if ((md->type == MT_DEVICE || md->type == MT_ROM_RX) &&
4604 md->virtual >= PAGE_OFFSET &&
4605 (md->virtual < VMALLOC_START || md->virtual >= VMALLOC_END)) {
4606 printk(KERN_WARNING "BUG: mapping for 0x%08llx"
4607 @@ -1257,18 +1314,15 @@ void __init arm_mm_memblock_reserve(void)
4608 * called function. This means you can't use any function or debugging
4609 * method which may touch any device, otherwise the kernel _will_ crash.
4610 */
4611 +
4612 +static char vectors[PAGE_SIZE * 2] __read_only __aligned(PAGE_SIZE);
4613 +
4614 static void __init devicemaps_init(const struct machine_desc *mdesc)
4615 {
4616 struct map_desc map;
4617 unsigned long addr;
4618 - void *vectors;
4619
4620 - /*
4621 - * Allocate the vector page early.
4622 - */
4623 - vectors = early_alloc(PAGE_SIZE * 2);
4624 -
4625 - early_trap_init(vectors);
4626 + early_trap_init(&vectors);
4627
4628 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4629 pmd_clear(pmd_off_k(addr));
4630 @@ -1281,7 +1335,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4631 map.pfn = __phys_to_pfn(CONFIG_XIP_PHYS_ADDR & SECTION_MASK);
4632 map.virtual = MODULES_VADDR;
4633 map.length = ((unsigned long)_etext - map.virtual + ~SECTION_MASK) & SECTION_MASK;
4634 - map.type = MT_ROM;
4635 + map.type = MT_ROM_RX;
4636 create_mapping(&map);
4637 #endif
4638
4639 @@ -1292,14 +1346,14 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4640 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS);
4641 map.virtual = FLUSH_BASE;
4642 map.length = SZ_1M;
4643 - map.type = MT_CACHECLEAN;
4644 + map.type = MT_CACHECLEAN_RO;
4645 create_mapping(&map);
4646 #endif
4647 #ifdef FLUSH_BASE_MINICACHE
4648 map.pfn = __phys_to_pfn(FLUSH_BASE_PHYS + SZ_1M);
4649 map.virtual = FLUSH_BASE_MINICACHE;
4650 map.length = SZ_1M;
4651 - map.type = MT_MINICLEAN;
4652 + map.type = MT_MINICLEAN_RO;
4653 create_mapping(&map);
4654 #endif
4655
4656 @@ -1308,7 +1362,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4657 * location (0xffff0000). If we aren't using high-vectors, also
4658 * create a mapping at the low-vectors virtual address.
4659 */
4660 - map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4661 + map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4662 map.virtual = 0xffff0000;
4663 map.length = PAGE_SIZE;
4664 #ifdef CONFIG_KUSER_HELPERS
4665 @@ -1365,8 +1419,10 @@ static void __init kmap_init(void)
4666 static void __init map_lowmem(void)
4667 {
4668 struct memblock_region *reg;
4669 +#ifndef CONFIG_PAX_KERNEXEC
4670 unsigned long kernel_x_start = round_down(__pa(_stext), SECTION_SIZE);
4671 unsigned long kernel_x_end = round_up(__pa(__init_end), SECTION_SIZE);
4672 +#endif
4673
4674 /* Map all the lowmem memory banks. */
4675 for_each_memblock(memory, reg) {
4676 @@ -1379,11 +1435,48 @@ static void __init map_lowmem(void)
4677 if (start >= end)
4678 break;
4679
4680 +#ifdef CONFIG_PAX_KERNEXEC
4681 + map.pfn = __phys_to_pfn(start);
4682 + map.virtual = __phys_to_virt(start);
4683 + map.length = end - start;
4684 +
4685 + if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4686 + struct map_desc kernel;
4687 + struct map_desc initmap;
4688 +
4689 + /* when freeing initmem we will make this RW */
4690 + initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4691 + initmap.virtual = (unsigned long)__init_begin;
4692 + initmap.length = _sdata - __init_begin;
4693 + initmap.type = __MT_MEMORY_RWX;
4694 + create_mapping(&initmap);
4695 +
4696 + /* when freeing initmem we will make this RX */
4697 + kernel.pfn = __phys_to_pfn(__pa(_stext));
4698 + kernel.virtual = (unsigned long)_stext;
4699 + kernel.length = __init_begin - _stext;
4700 + kernel.type = __MT_MEMORY_RWX;
4701 + create_mapping(&kernel);
4702 +
4703 + if (map.virtual < (unsigned long)_stext) {
4704 + map.length = (unsigned long)_stext - map.virtual;
4705 + map.type = __MT_MEMORY_RWX;
4706 + create_mapping(&map);
4707 + }
4708 +
4709 + map.pfn = __phys_to_pfn(__pa(_sdata));
4710 + map.virtual = (unsigned long)_sdata;
4711 + map.length = end - __pa(_sdata);
4712 + }
4713 +
4714 + map.type = MT_MEMORY_RW;
4715 + create_mapping(&map);
4716 +#else
4717 if (end < kernel_x_start || start >= kernel_x_end) {
4718 map.pfn = __phys_to_pfn(start);
4719 map.virtual = __phys_to_virt(start);
4720 map.length = end - start;
4721 - map.type = MT_MEMORY_RWX;
4722 + map.type = __MT_MEMORY_RWX;
4723
4724 create_mapping(&map);
4725 } else {
4726 @@ -1400,7 +1493,7 @@ static void __init map_lowmem(void)
4727 map.pfn = __phys_to_pfn(kernel_x_start);
4728 map.virtual = __phys_to_virt(kernel_x_start);
4729 map.length = kernel_x_end - kernel_x_start;
4730 - map.type = MT_MEMORY_RWX;
4731 + map.type = __MT_MEMORY_RWX;
4732
4733 create_mapping(&map);
4734
4735 @@ -1413,6 +1506,7 @@ static void __init map_lowmem(void)
4736 create_mapping(&map);
4737 }
4738 }
4739 +#endif
4740 }
4741 }
4742
4743 diff --git a/arch/arm/plat-iop/setup.c b/arch/arm/plat-iop/setup.c
4744 index 5b217f4..c23f40e 100644
4745 --- a/arch/arm/plat-iop/setup.c
4746 +++ b/arch/arm/plat-iop/setup.c
4747 @@ -24,7 +24,7 @@ static struct map_desc iop3xx_std_desc[] __initdata = {
4748 .virtual = IOP3XX_PERIPHERAL_VIRT_BASE,
4749 .pfn = __phys_to_pfn(IOP3XX_PERIPHERAL_PHYS_BASE),
4750 .length = IOP3XX_PERIPHERAL_SIZE,
4751 - .type = MT_UNCACHED,
4752 + .type = MT_UNCACHED_RW,
4753 },
4754 };
4755
4756 diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4757 index a5bc92d..0bb4730 100644
4758 --- a/arch/arm/plat-omap/sram.c
4759 +++ b/arch/arm/plat-omap/sram.c
4760 @@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4761 * Looks like we need to preserve some bootloader code at the
4762 * beginning of SRAM for jumping to flash for reboot to work...
4763 */
4764 + pax_open_kernel();
4765 memset_io(omap_sram_base + omap_sram_skip, 0,
4766 omap_sram_size - omap_sram_skip);
4767 + pax_close_kernel();
4768 }
4769 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4770 index ce6d763..cfea917 100644
4771 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4772 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4773 @@ -47,7 +47,7 @@ struct samsung_dma_ops {
4774 int (*started)(unsigned ch);
4775 int (*flush)(unsigned ch);
4776 int (*stop)(unsigned ch);
4777 -};
4778 +} __no_const;
4779
4780 extern void *samsung_dmadev_get_ops(void);
4781 extern void *s3c_dma_get_ops(void);
4782 diff --git a/arch/arm64/include/asm/barrier.h b/arch/arm64/include/asm/barrier.h
4783 index 66eb764..b529b84 100644
4784 --- a/arch/arm64/include/asm/barrier.h
4785 +++ b/arch/arm64/include/asm/barrier.h
4786 @@ -41,7 +41,7 @@
4787 do { \
4788 compiletime_assert_atomic_type(*p); \
4789 smp_mb(); \
4790 - ACCESS_ONCE(*p) = (v); \
4791 + ACCESS_ONCE_RW(*p) = (v); \
4792 } while (0)
4793
4794 #define smp_load_acquire(p) \
4795 diff --git a/arch/arm64/include/asm/uaccess.h b/arch/arm64/include/asm/uaccess.h
4796 index 3bf8f4e..5dd5491 100644
4797 --- a/arch/arm64/include/asm/uaccess.h
4798 +++ b/arch/arm64/include/asm/uaccess.h
4799 @@ -99,6 +99,7 @@ static inline void set_fs(mm_segment_t fs)
4800 flag; \
4801 })
4802
4803 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
4804 #define access_ok(type, addr, size) __range_ok(addr, size)
4805 #define user_addr_max get_fs
4806
4807 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4808 index c3a58a1..78fbf54 100644
4809 --- a/arch/avr32/include/asm/cache.h
4810 +++ b/arch/avr32/include/asm/cache.h
4811 @@ -1,8 +1,10 @@
4812 #ifndef __ASM_AVR32_CACHE_H
4813 #define __ASM_AVR32_CACHE_H
4814
4815 +#include <linux/const.h>
4816 +
4817 #define L1_CACHE_SHIFT 5
4818 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4819 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4820
4821 /*
4822 * Memory returned by kmalloc() may be used for DMA, so we must make
4823 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4824 index d232888..87c8df1 100644
4825 --- a/arch/avr32/include/asm/elf.h
4826 +++ b/arch/avr32/include/asm/elf.h
4827 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4828 the loader. We need to make sure that it is out of the way of the program
4829 that it will "exec", and that there is sufficient room for the brk. */
4830
4831 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4832 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4833
4834 +#ifdef CONFIG_PAX_ASLR
4835 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4836 +
4837 +#define PAX_DELTA_MMAP_LEN 15
4838 +#define PAX_DELTA_STACK_LEN 15
4839 +#endif
4840
4841 /* This yields a mask that user programs can use to figure out what
4842 instruction set this CPU supports. This could be done in user space,
4843 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4844 index 479330b..53717a8 100644
4845 --- a/arch/avr32/include/asm/kmap_types.h
4846 +++ b/arch/avr32/include/asm/kmap_types.h
4847 @@ -2,9 +2,9 @@
4848 #define __ASM_AVR32_KMAP_TYPES_H
4849
4850 #ifdef CONFIG_DEBUG_HIGHMEM
4851 -# define KM_TYPE_NR 29
4852 +# define KM_TYPE_NR 30
4853 #else
4854 -# define KM_TYPE_NR 14
4855 +# define KM_TYPE_NR 15
4856 #endif
4857
4858 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4859 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4860 index 0eca933..eb78c7b 100644
4861 --- a/arch/avr32/mm/fault.c
4862 +++ b/arch/avr32/mm/fault.c
4863 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4864
4865 int exception_trace = 1;
4866
4867 +#ifdef CONFIG_PAX_PAGEEXEC
4868 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4869 +{
4870 + unsigned long i;
4871 +
4872 + printk(KERN_ERR "PAX: bytes at PC: ");
4873 + for (i = 0; i < 20; i++) {
4874 + unsigned char c;
4875 + if (get_user(c, (unsigned char *)pc+i))
4876 + printk(KERN_CONT "???????? ");
4877 + else
4878 + printk(KERN_CONT "%02x ", c);
4879 + }
4880 + printk("\n");
4881 +}
4882 +#endif
4883 +
4884 /*
4885 * This routine handles page faults. It determines the address and the
4886 * problem, and then passes it off to one of the appropriate routines.
4887 @@ -176,6 +193,16 @@ bad_area:
4888 up_read(&mm->mmap_sem);
4889
4890 if (user_mode(regs)) {
4891 +
4892 +#ifdef CONFIG_PAX_PAGEEXEC
4893 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4894 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4895 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4896 + do_group_exit(SIGKILL);
4897 + }
4898 + }
4899 +#endif
4900 +
4901 if (exception_trace && printk_ratelimit())
4902 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4903 "sp %08lx ecr %lu\n",
4904 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4905 index 568885a..f8008df 100644
4906 --- a/arch/blackfin/include/asm/cache.h
4907 +++ b/arch/blackfin/include/asm/cache.h
4908 @@ -7,6 +7,7 @@
4909 #ifndef __ARCH_BLACKFIN_CACHE_H
4910 #define __ARCH_BLACKFIN_CACHE_H
4911
4912 +#include <linux/const.h>
4913 #include <linux/linkage.h> /* for asmlinkage */
4914
4915 /*
4916 @@ -14,7 +15,7 @@
4917 * Blackfin loads 32 bytes for cache
4918 */
4919 #define L1_CACHE_SHIFT 5
4920 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4921 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4922 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4923
4924 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4925 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4926 index aea2718..3639a60 100644
4927 --- a/arch/cris/include/arch-v10/arch/cache.h
4928 +++ b/arch/cris/include/arch-v10/arch/cache.h
4929 @@ -1,8 +1,9 @@
4930 #ifndef _ASM_ARCH_CACHE_H
4931 #define _ASM_ARCH_CACHE_H
4932
4933 +#include <linux/const.h>
4934 /* Etrax 100LX have 32-byte cache-lines. */
4935 -#define L1_CACHE_BYTES 32
4936 #define L1_CACHE_SHIFT 5
4937 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4938
4939 #endif /* _ASM_ARCH_CACHE_H */
4940 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4941 index 7caf25d..ee65ac5 100644
4942 --- a/arch/cris/include/arch-v32/arch/cache.h
4943 +++ b/arch/cris/include/arch-v32/arch/cache.h
4944 @@ -1,11 +1,12 @@
4945 #ifndef _ASM_CRIS_ARCH_CACHE_H
4946 #define _ASM_CRIS_ARCH_CACHE_H
4947
4948 +#include <linux/const.h>
4949 #include <arch/hwregs/dma.h>
4950
4951 /* A cache-line is 32 bytes. */
4952 -#define L1_CACHE_BYTES 32
4953 #define L1_CACHE_SHIFT 5
4954 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4955
4956 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4957
4958 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4959 index b86329d..6709906 100644
4960 --- a/arch/frv/include/asm/atomic.h
4961 +++ b/arch/frv/include/asm/atomic.h
4962 @@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4963 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4964 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4965
4966 +#define atomic64_read_unchecked(v) atomic64_read(v)
4967 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4968 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4969 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4970 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4971 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4972 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4973 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4974 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4975 +
4976 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4977 {
4978 int c, old;
4979 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4980 index 2797163..c2a401d 100644
4981 --- a/arch/frv/include/asm/cache.h
4982 +++ b/arch/frv/include/asm/cache.h
4983 @@ -12,10 +12,11 @@
4984 #ifndef __ASM_CACHE_H
4985 #define __ASM_CACHE_H
4986
4987 +#include <linux/const.h>
4988
4989 /* bytes per L1 cache line */
4990 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4991 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4992 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4993
4994 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4995 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4996 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4997 index 43901f2..0d8b865 100644
4998 --- a/arch/frv/include/asm/kmap_types.h
4999 +++ b/arch/frv/include/asm/kmap_types.h
5000 @@ -2,6 +2,6 @@
5001 #ifndef _ASM_KMAP_TYPES_H
5002 #define _ASM_KMAP_TYPES_H
5003
5004 -#define KM_TYPE_NR 17
5005 +#define KM_TYPE_NR 18
5006
5007 #endif
5008 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
5009 index 836f147..4cf23f5 100644
5010 --- a/arch/frv/mm/elf-fdpic.c
5011 +++ b/arch/frv/mm/elf-fdpic.c
5012 @@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5013 {
5014 struct vm_area_struct *vma;
5015 struct vm_unmapped_area_info info;
5016 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
5017
5018 if (len > TASK_SIZE)
5019 return -ENOMEM;
5020 @@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5021 if (addr) {
5022 addr = PAGE_ALIGN(addr);
5023 vma = find_vma(current->mm, addr);
5024 - if (TASK_SIZE - len >= addr &&
5025 - (!vma || addr + len <= vma->vm_start))
5026 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
5027 goto success;
5028 }
5029
5030 @@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5031 info.high_limit = (current->mm->start_stack - 0x00200000);
5032 info.align_mask = 0;
5033 info.align_offset = 0;
5034 + info.threadstack_offset = offset;
5035 addr = vm_unmapped_area(&info);
5036 if (!(addr & ~PAGE_MASK))
5037 goto success;
5038 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
5039 index f4ca594..adc72fd6 100644
5040 --- a/arch/hexagon/include/asm/cache.h
5041 +++ b/arch/hexagon/include/asm/cache.h
5042 @@ -21,9 +21,11 @@
5043 #ifndef __ASM_CACHE_H
5044 #define __ASM_CACHE_H
5045
5046 +#include <linux/const.h>
5047 +
5048 /* Bytes per L1 cache line */
5049 -#define L1_CACHE_SHIFT (5)
5050 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5051 +#define L1_CACHE_SHIFT 5
5052 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5053
5054 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
5055 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
5056 diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
5057 index 12c3afe..b1abab2 100644
5058 --- a/arch/ia64/Kconfig
5059 +++ b/arch/ia64/Kconfig
5060 @@ -546,6 +546,7 @@ source "drivers/sn/Kconfig"
5061 config KEXEC
5062 bool "kexec system call"
5063 depends on !IA64_HP_SIM && (!SMP || HOTPLUG_CPU)
5064 + depends on !GRKERNSEC_KMEM
5065 help
5066 kexec is a system call that implements the ability to shutdown your
5067 current kernel, and to start another kernel. It is like a reboot
5068 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
5069 index 6e6fe18..a6ae668 100644
5070 --- a/arch/ia64/include/asm/atomic.h
5071 +++ b/arch/ia64/include/asm/atomic.h
5072 @@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
5073 #define atomic64_inc(v) atomic64_add(1, (v))
5074 #define atomic64_dec(v) atomic64_sub(1, (v))
5075
5076 +#define atomic64_read_unchecked(v) atomic64_read(v)
5077 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
5078 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
5079 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
5080 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
5081 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
5082 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
5083 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
5084 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
5085 +
5086 /* Atomic operations are already serializing */
5087 #define smp_mb__before_atomic_dec() barrier()
5088 #define smp_mb__after_atomic_dec() barrier()
5089 diff --git a/arch/ia64/include/asm/barrier.h b/arch/ia64/include/asm/barrier.h
5090 index d0a69aa..142f878 100644
5091 --- a/arch/ia64/include/asm/barrier.h
5092 +++ b/arch/ia64/include/asm/barrier.h
5093 @@ -64,7 +64,7 @@
5094 do { \
5095 compiletime_assert_atomic_type(*p); \
5096 barrier(); \
5097 - ACCESS_ONCE(*p) = (v); \
5098 + ACCESS_ONCE_RW(*p) = (v); \
5099 } while (0)
5100
5101 #define smp_load_acquire(p) \
5102 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
5103 index 988254a..e1ee885 100644
5104 --- a/arch/ia64/include/asm/cache.h
5105 +++ b/arch/ia64/include/asm/cache.h
5106 @@ -1,6 +1,7 @@
5107 #ifndef _ASM_IA64_CACHE_H
5108 #define _ASM_IA64_CACHE_H
5109
5110 +#include <linux/const.h>
5111
5112 /*
5113 * Copyright (C) 1998-2000 Hewlett-Packard Co
5114 @@ -9,7 +10,7 @@
5115
5116 /* Bytes per L1 (data) cache line. */
5117 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
5118 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5119 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5120
5121 #ifdef CONFIG_SMP
5122 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
5123 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
5124 index 5a83c5c..4d7f553 100644
5125 --- a/arch/ia64/include/asm/elf.h
5126 +++ b/arch/ia64/include/asm/elf.h
5127 @@ -42,6 +42,13 @@
5128 */
5129 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
5130
5131 +#ifdef CONFIG_PAX_ASLR
5132 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
5133 +
5134 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5135 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
5136 +#endif
5137 +
5138 #define PT_IA_64_UNWIND 0x70000001
5139
5140 /* IA-64 relocations: */
5141 diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
5142 index 5767cdf..7462574 100644
5143 --- a/arch/ia64/include/asm/pgalloc.h
5144 +++ b/arch/ia64/include/asm/pgalloc.h
5145 @@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5146 pgd_val(*pgd_entry) = __pa(pud);
5147 }
5148
5149 +static inline void
5150 +pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
5151 +{
5152 + pgd_populate(mm, pgd_entry, pud);
5153 +}
5154 +
5155 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
5156 {
5157 return quicklist_alloc(0, GFP_KERNEL, NULL);
5158 @@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5159 pud_val(*pud_entry) = __pa(pmd);
5160 }
5161
5162 +static inline void
5163 +pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5164 +{
5165 + pud_populate(mm, pud_entry, pmd);
5166 +}
5167 +
5168 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5169 {
5170 return quicklist_alloc(0, GFP_KERNEL, NULL);
5171 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
5172 index 7935115..c0eca6a 100644
5173 --- a/arch/ia64/include/asm/pgtable.h
5174 +++ b/arch/ia64/include/asm/pgtable.h
5175 @@ -12,7 +12,7 @@
5176 * David Mosberger-Tang <davidm@hpl.hp.com>
5177 */
5178
5179 -
5180 +#include <linux/const.h>
5181 #include <asm/mman.h>
5182 #include <asm/page.h>
5183 #include <asm/processor.h>
5184 @@ -142,6 +142,17 @@
5185 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5186 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5187 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
5188 +
5189 +#ifdef CONFIG_PAX_PAGEEXEC
5190 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
5191 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5192 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5193 +#else
5194 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
5195 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
5196 +# define PAGE_COPY_NOEXEC PAGE_COPY
5197 +#endif
5198 +
5199 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
5200 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
5201 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
5202 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
5203 index 45698cd..e8e2dbc 100644
5204 --- a/arch/ia64/include/asm/spinlock.h
5205 +++ b/arch/ia64/include/asm/spinlock.h
5206 @@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
5207 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
5208
5209 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
5210 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
5211 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
5212 }
5213
5214 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
5215 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
5216 index 449c8c0..3d4b1e9 100644
5217 --- a/arch/ia64/include/asm/uaccess.h
5218 +++ b/arch/ia64/include/asm/uaccess.h
5219 @@ -70,6 +70,7 @@
5220 && ((segment).seg == KERNEL_DS.seg \
5221 || likely(REGION_OFFSET((unsigned long) (addr)) < RGN_MAP_LIMIT))); \
5222 })
5223 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
5224 #define access_ok(type, addr, size) __access_ok((addr), (size), get_fs())
5225
5226 /*
5227 @@ -240,12 +241,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
5228 static inline unsigned long
5229 __copy_to_user (void __user *to, const void *from, unsigned long count)
5230 {
5231 + if (count > INT_MAX)
5232 + return count;
5233 +
5234 + if (!__builtin_constant_p(count))
5235 + check_object_size(from, count, true);
5236 +
5237 return __copy_user(to, (__force void __user *) from, count);
5238 }
5239
5240 static inline unsigned long
5241 __copy_from_user (void *to, const void __user *from, unsigned long count)
5242 {
5243 + if (count > INT_MAX)
5244 + return count;
5245 +
5246 + if (!__builtin_constant_p(count))
5247 + check_object_size(to, count, false);
5248 +
5249 return __copy_user((__force void __user *) to, from, count);
5250 }
5251
5252 @@ -255,10 +268,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5253 ({ \
5254 void __user *__cu_to = (to); \
5255 const void *__cu_from = (from); \
5256 - long __cu_len = (n); \
5257 + unsigned long __cu_len = (n); \
5258 \
5259 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
5260 + if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
5261 + if (!__builtin_constant_p(n)) \
5262 + check_object_size(__cu_from, __cu_len, true); \
5263 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
5264 + } \
5265 __cu_len; \
5266 })
5267
5268 @@ -266,11 +282,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5269 ({ \
5270 void *__cu_to = (to); \
5271 const void __user *__cu_from = (from); \
5272 - long __cu_len = (n); \
5273 + unsigned long __cu_len = (n); \
5274 \
5275 __chk_user_ptr(__cu_from); \
5276 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
5277 + if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
5278 + if (!__builtin_constant_p(n)) \
5279 + check_object_size(__cu_to, __cu_len, false); \
5280 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
5281 + } \
5282 __cu_len; \
5283 })
5284
5285 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
5286 index 24603be..948052d 100644
5287 --- a/arch/ia64/kernel/module.c
5288 +++ b/arch/ia64/kernel/module.c
5289 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
5290 void
5291 module_free (struct module *mod, void *module_region)
5292 {
5293 - if (mod && mod->arch.init_unw_table &&
5294 - module_region == mod->module_init) {
5295 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
5296 unw_remove_unwind_table(mod->arch.init_unw_table);
5297 mod->arch.init_unw_table = NULL;
5298 }
5299 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
5300 }
5301
5302 static inline int
5303 +in_init_rx (const struct module *mod, uint64_t addr)
5304 +{
5305 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
5306 +}
5307 +
5308 +static inline int
5309 +in_init_rw (const struct module *mod, uint64_t addr)
5310 +{
5311 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
5312 +}
5313 +
5314 +static inline int
5315 in_init (const struct module *mod, uint64_t addr)
5316 {
5317 - return addr - (uint64_t) mod->module_init < mod->init_size;
5318 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
5319 +}
5320 +
5321 +static inline int
5322 +in_core_rx (const struct module *mod, uint64_t addr)
5323 +{
5324 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
5325 +}
5326 +
5327 +static inline int
5328 +in_core_rw (const struct module *mod, uint64_t addr)
5329 +{
5330 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
5331 }
5332
5333 static inline int
5334 in_core (const struct module *mod, uint64_t addr)
5335 {
5336 - return addr - (uint64_t) mod->module_core < mod->core_size;
5337 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
5338 }
5339
5340 static inline int
5341 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
5342 break;
5343
5344 case RV_BDREL:
5345 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
5346 + if (in_init_rx(mod, val))
5347 + val -= (uint64_t) mod->module_init_rx;
5348 + else if (in_init_rw(mod, val))
5349 + val -= (uint64_t) mod->module_init_rw;
5350 + else if (in_core_rx(mod, val))
5351 + val -= (uint64_t) mod->module_core_rx;
5352 + else if (in_core_rw(mod, val))
5353 + val -= (uint64_t) mod->module_core_rw;
5354 break;
5355
5356 case RV_LTV:
5357 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
5358 * addresses have been selected...
5359 */
5360 uint64_t gp;
5361 - if (mod->core_size > MAX_LTOFF)
5362 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
5363 /*
5364 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
5365 * at the end of the module.
5366 */
5367 - gp = mod->core_size - MAX_LTOFF / 2;
5368 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
5369 else
5370 - gp = mod->core_size / 2;
5371 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
5372 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
5373 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
5374 mod->arch.gp = gp;
5375 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
5376 }
5377 diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
5378 index c39c3cd..3c77738 100644
5379 --- a/arch/ia64/kernel/palinfo.c
5380 +++ b/arch/ia64/kernel/palinfo.c
5381 @@ -980,7 +980,7 @@ static int palinfo_cpu_callback(struct notifier_block *nfb,
5382 return NOTIFY_OK;
5383 }
5384
5385 -static struct notifier_block __refdata palinfo_cpu_notifier =
5386 +static struct notifier_block palinfo_cpu_notifier =
5387 {
5388 .notifier_call = palinfo_cpu_callback,
5389 .priority = 0,
5390 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5391 index 41e33f8..65180b2a 100644
5392 --- a/arch/ia64/kernel/sys_ia64.c
5393 +++ b/arch/ia64/kernel/sys_ia64.c
5394 @@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5395 unsigned long align_mask = 0;
5396 struct mm_struct *mm = current->mm;
5397 struct vm_unmapped_area_info info;
5398 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5399
5400 if (len > RGN_MAP_LIMIT)
5401 return -ENOMEM;
5402 @@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5403 if (REGION_NUMBER(addr) == RGN_HPAGE)
5404 addr = 0;
5405 #endif
5406 +
5407 +#ifdef CONFIG_PAX_RANDMMAP
5408 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5409 + addr = mm->free_area_cache;
5410 + else
5411 +#endif
5412 +
5413 if (!addr)
5414 addr = TASK_UNMAPPED_BASE;
5415
5416 @@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5417 info.high_limit = TASK_SIZE;
5418 info.align_mask = align_mask;
5419 info.align_offset = 0;
5420 + info.threadstack_offset = offset;
5421 return vm_unmapped_area(&info);
5422 }
5423
5424 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5425 index 84f8a52..7c76178 100644
5426 --- a/arch/ia64/kernel/vmlinux.lds.S
5427 +++ b/arch/ia64/kernel/vmlinux.lds.S
5428 @@ -192,7 +192,7 @@ SECTIONS {
5429 /* Per-cpu data: */
5430 . = ALIGN(PERCPU_PAGE_SIZE);
5431 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5432 - __phys_per_cpu_start = __per_cpu_load;
5433 + __phys_per_cpu_start = per_cpu_load;
5434 /*
5435 * ensure percpu data fits
5436 * into percpu page size
5437 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5438 index 7225dad..2a7c8256 100644
5439 --- a/arch/ia64/mm/fault.c
5440 +++ b/arch/ia64/mm/fault.c
5441 @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5442 return pte_present(pte);
5443 }
5444
5445 +#ifdef CONFIG_PAX_PAGEEXEC
5446 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5447 +{
5448 + unsigned long i;
5449 +
5450 + printk(KERN_ERR "PAX: bytes at PC: ");
5451 + for (i = 0; i < 8; i++) {
5452 + unsigned int c;
5453 + if (get_user(c, (unsigned int *)pc+i))
5454 + printk(KERN_CONT "???????? ");
5455 + else
5456 + printk(KERN_CONT "%08x ", c);
5457 + }
5458 + printk("\n");
5459 +}
5460 +#endif
5461 +
5462 # define VM_READ_BIT 0
5463 # define VM_WRITE_BIT 1
5464 # define VM_EXEC_BIT 2
5465 @@ -151,8 +168,21 @@ retry:
5466 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5467 goto bad_area;
5468
5469 - if ((vma->vm_flags & mask) != mask)
5470 + if ((vma->vm_flags & mask) != mask) {
5471 +
5472 +#ifdef CONFIG_PAX_PAGEEXEC
5473 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5474 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5475 + goto bad_area;
5476 +
5477 + up_read(&mm->mmap_sem);
5478 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5479 + do_group_exit(SIGKILL);
5480 + }
5481 +#endif
5482 +
5483 goto bad_area;
5484 + }
5485
5486 /*
5487 * If for any reason at all we couldn't handle the fault, make
5488 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5489 index 76069c1..c2aa816 100644
5490 --- a/arch/ia64/mm/hugetlbpage.c
5491 +++ b/arch/ia64/mm/hugetlbpage.c
5492 @@ -149,6 +149,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5493 unsigned long pgoff, unsigned long flags)
5494 {
5495 struct vm_unmapped_area_info info;
5496 + unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5497
5498 if (len > RGN_MAP_LIMIT)
5499 return -ENOMEM;
5500 @@ -172,6 +173,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5501 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5502 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5503 info.align_offset = 0;
5504 + info.threadstack_offset = offset;
5505 return vm_unmapped_area(&info);
5506 }
5507
5508 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5509 index 25c3502..560dae7 100644
5510 --- a/arch/ia64/mm/init.c
5511 +++ b/arch/ia64/mm/init.c
5512 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5513 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5514 vma->vm_end = vma->vm_start + PAGE_SIZE;
5515 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5516 +
5517 +#ifdef CONFIG_PAX_PAGEEXEC
5518 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5519 + vma->vm_flags &= ~VM_EXEC;
5520 +
5521 +#ifdef CONFIG_PAX_MPROTECT
5522 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
5523 + vma->vm_flags &= ~VM_MAYEXEC;
5524 +#endif
5525 +
5526 + }
5527 +#endif
5528 +
5529 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5530 down_write(&current->mm->mmap_sem);
5531 if (insert_vm_struct(current->mm, vma)) {
5532 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5533 index 40b3ee9..8c2c112 100644
5534 --- a/arch/m32r/include/asm/cache.h
5535 +++ b/arch/m32r/include/asm/cache.h
5536 @@ -1,8 +1,10 @@
5537 #ifndef _ASM_M32R_CACHE_H
5538 #define _ASM_M32R_CACHE_H
5539
5540 +#include <linux/const.h>
5541 +
5542 /* L1 cache line size */
5543 #define L1_CACHE_SHIFT 4
5544 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5545 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5546
5547 #endif /* _ASM_M32R_CACHE_H */
5548 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5549 index 82abd15..d95ae5d 100644
5550 --- a/arch/m32r/lib/usercopy.c
5551 +++ b/arch/m32r/lib/usercopy.c
5552 @@ -14,6 +14,9 @@
5553 unsigned long
5554 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5555 {
5556 + if ((long)n < 0)
5557 + return n;
5558 +
5559 prefetch(from);
5560 if (access_ok(VERIFY_WRITE, to, n))
5561 __copy_user(to,from,n);
5562 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5563 unsigned long
5564 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5565 {
5566 + if ((long)n < 0)
5567 + return n;
5568 +
5569 prefetchw(to);
5570 if (access_ok(VERIFY_READ, from, n))
5571 __copy_user_zeroing(to,from,n);
5572 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5573 index 0395c51..5f26031 100644
5574 --- a/arch/m68k/include/asm/cache.h
5575 +++ b/arch/m68k/include/asm/cache.h
5576 @@ -4,9 +4,11 @@
5577 #ifndef __ARCH_M68K_CACHE_H
5578 #define __ARCH_M68K_CACHE_H
5579
5580 +#include <linux/const.h>
5581 +
5582 /* bytes per L1 cache line */
5583 #define L1_CACHE_SHIFT 4
5584 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5585 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5586
5587 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5588
5589 diff --git a/arch/metag/include/asm/barrier.h b/arch/metag/include/asm/barrier.h
5590 index 2d6f0de..de5f5ac 100644
5591 --- a/arch/metag/include/asm/barrier.h
5592 +++ b/arch/metag/include/asm/barrier.h
5593 @@ -89,7 +89,7 @@ static inline void fence(void)
5594 do { \
5595 compiletime_assert_atomic_type(*p); \
5596 smp_mb(); \
5597 - ACCESS_ONCE(*p) = (v); \
5598 + ACCESS_ONCE_RW(*p) = (v); \
5599 } while (0)
5600
5601 #define smp_load_acquire(p) \
5602 diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5603 index 3c52fa6..11b2ad8 100644
5604 --- a/arch/metag/mm/hugetlbpage.c
5605 +++ b/arch/metag/mm/hugetlbpage.c
5606 @@ -200,6 +200,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5607 info.high_limit = TASK_SIZE;
5608 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5609 info.align_offset = 0;
5610 + info.threadstack_offset = 0;
5611 return vm_unmapped_area(&info);
5612 }
5613
5614 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5615 index 4efe96a..60e8699 100644
5616 --- a/arch/microblaze/include/asm/cache.h
5617 +++ b/arch/microblaze/include/asm/cache.h
5618 @@ -13,11 +13,12 @@
5619 #ifndef _ASM_MICROBLAZE_CACHE_H
5620 #define _ASM_MICROBLAZE_CACHE_H
5621
5622 +#include <linux/const.h>
5623 #include <asm/registers.h>
5624
5625 #define L1_CACHE_SHIFT 5
5626 /* word-granular cache in microblaze */
5627 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5628 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5629
5630 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5631
5632 diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
5633 index 5cd695f..9a24ad0 100644
5634 --- a/arch/mips/Kconfig
5635 +++ b/arch/mips/Kconfig
5636 @@ -2395,6 +2395,7 @@ source "kernel/Kconfig.preempt"
5637
5638 config KEXEC
5639 bool "Kexec system call"
5640 + depends on !GRKERNSEC_KMEM
5641 help
5642 kexec is a system call that implements the ability to shutdown your
5643 current kernel, and to start another kernel. It is like a reboot
5644 diff --git a/arch/mips/cavium-octeon/dma-octeon.c b/arch/mips/cavium-octeon/dma-octeon.c
5645 index 02f2444..506969c 100644
5646 --- a/arch/mips/cavium-octeon/dma-octeon.c
5647 +++ b/arch/mips/cavium-octeon/dma-octeon.c
5648 @@ -199,7 +199,7 @@ static void octeon_dma_free_coherent(struct device *dev, size_t size,
5649 if (dma_release_from_coherent(dev, order, vaddr))
5650 return;
5651
5652 - swiotlb_free_coherent(dev, size, vaddr, dma_handle);
5653 + swiotlb_free_coherent(dev, size, vaddr, dma_handle, attrs);
5654 }
5655
5656 static dma_addr_t octeon_unity_phys_to_dma(struct device *dev, phys_addr_t paddr)
5657 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5658 index e8eb3d5..2e665d1 100644
5659 --- a/arch/mips/include/asm/atomic.h
5660 +++ b/arch/mips/include/asm/atomic.h
5661 @@ -21,15 +21,39 @@
5662 #include <asm/cmpxchg.h>
5663 #include <asm/war.h>
5664
5665 +#ifdef CONFIG_GENERIC_ATOMIC64
5666 +#include <asm-generic/atomic64.h>
5667 +#endif
5668 +
5669 #define ATOMIC_INIT(i) { (i) }
5670
5671 +#ifdef CONFIG_64BIT
5672 +#define _ASM_EXTABLE(from, to) \
5673 +" .section __ex_table,\"a\"\n" \
5674 +" .dword " #from ", " #to"\n" \
5675 +" .previous\n"
5676 +#else
5677 +#define _ASM_EXTABLE(from, to) \
5678 +" .section __ex_table,\"a\"\n" \
5679 +" .word " #from ", " #to"\n" \
5680 +" .previous\n"
5681 +#endif
5682 +
5683 /*
5684 * atomic_read - read atomic variable
5685 * @v: pointer of type atomic_t
5686 *
5687 * Atomically reads the value of @v.
5688 */
5689 -#define atomic_read(v) (*(volatile int *)&(v)->counter)
5690 +static inline int atomic_read(const atomic_t *v)
5691 +{
5692 + return (*(volatile const int *) &v->counter);
5693 +}
5694 +
5695 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5696 +{
5697 + return (*(volatile const int *) &v->counter);
5698 +}
5699
5700 /*
5701 * atomic_set - set atomic variable
5702 @@ -38,7 +62,15 @@
5703 *
5704 * Atomically sets the value of @v to @i.
5705 */
5706 -#define atomic_set(v, i) ((v)->counter = (i))
5707 +static inline void atomic_set(atomic_t *v, int i)
5708 +{
5709 + v->counter = i;
5710 +}
5711 +
5712 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5713 +{
5714 + v->counter = i;
5715 +}
5716
5717 /*
5718 * atomic_add - add integer to atomic variable
5719 @@ -47,7 +79,67 @@
5720 *
5721 * Atomically adds @i to @v.
5722 */
5723 -static __inline__ void atomic_add(int i, atomic_t * v)
5724 +static __inline__ void atomic_add(int i, atomic_t *v)
5725 +{
5726 + int temp;
5727 +
5728 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5729 + __asm__ __volatile__(
5730 + " .set mips3 \n"
5731 + "1: ll %0, %1 # atomic_add \n"
5732 +#ifdef CONFIG_PAX_REFCOUNT
5733 + /* Exception on overflow. */
5734 + "2: add %0, %2 \n"
5735 +#else
5736 + " addu %0, %2 \n"
5737 +#endif
5738 + " sc %0, %1 \n"
5739 + " beqzl %0, 1b \n"
5740 +#ifdef CONFIG_PAX_REFCOUNT
5741 + "3: \n"
5742 + _ASM_EXTABLE(2b, 3b)
5743 +#endif
5744 + " .set mips0 \n"
5745 + : "=&r" (temp), "+m" (v->counter)
5746 + : "Ir" (i));
5747 + } else if (kernel_uses_llsc) {
5748 + __asm__ __volatile__(
5749 + " .set mips3 \n"
5750 + "1: ll %0, %1 # atomic_add \n"
5751 +#ifdef CONFIG_PAX_REFCOUNT
5752 + /* Exception on overflow. */
5753 + "2: add %0, %2 \n"
5754 +#else
5755 + " addu %0, %2 \n"
5756 +#endif
5757 + " sc %0, %1 \n"
5758 + " beqz %0, 1b \n"
5759 +#ifdef CONFIG_PAX_REFCOUNT
5760 + "3: \n"
5761 + _ASM_EXTABLE(2b, 3b)
5762 +#endif
5763 + " .set mips0 \n"
5764 + : "=&r" (temp), "+m" (v->counter)
5765 + : "Ir" (i));
5766 + } else {
5767 + unsigned long flags;
5768 +
5769 + raw_local_irq_save(flags);
5770 + __asm__ __volatile__(
5771 +#ifdef CONFIG_PAX_REFCOUNT
5772 + /* Exception on overflow. */
5773 + "1: add %0, %1 \n"
5774 + "2: \n"
5775 + _ASM_EXTABLE(1b, 2b)
5776 +#else
5777 + " addu %0, %1 \n"
5778 +#endif
5779 + : "+r" (v->counter) : "Ir" (i));
5780 + raw_local_irq_restore(flags);
5781 + }
5782 +}
5783 +
5784 +static __inline__ void atomic_add_unchecked(int i, atomic_unchecked_t *v)
5785 {
5786 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5787 int temp;
5788 @@ -90,7 +182,67 @@ static __inline__ void atomic_add(int i, atomic_t * v)
5789 *
5790 * Atomically subtracts @i from @v.
5791 */
5792 -static __inline__ void atomic_sub(int i, atomic_t * v)
5793 +static __inline__ void atomic_sub(int i, atomic_t *v)
5794 +{
5795 + int temp;
5796 +
5797 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5798 + __asm__ __volatile__(
5799 + " .set mips3 \n"
5800 + "1: ll %0, %1 # atomic64_sub \n"
5801 +#ifdef CONFIG_PAX_REFCOUNT
5802 + /* Exception on overflow. */
5803 + "2: sub %0, %2 \n"
5804 +#else
5805 + " subu %0, %2 \n"
5806 +#endif
5807 + " sc %0, %1 \n"
5808 + " beqzl %0, 1b \n"
5809 +#ifdef CONFIG_PAX_REFCOUNT
5810 + "3: \n"
5811 + _ASM_EXTABLE(2b, 3b)
5812 +#endif
5813 + " .set mips0 \n"
5814 + : "=&r" (temp), "+m" (v->counter)
5815 + : "Ir" (i));
5816 + } else if (kernel_uses_llsc) {
5817 + __asm__ __volatile__(
5818 + " .set mips3 \n"
5819 + "1: ll %0, %1 # atomic64_sub \n"
5820 +#ifdef CONFIG_PAX_REFCOUNT
5821 + /* Exception on overflow. */
5822 + "2: sub %0, %2 \n"
5823 +#else
5824 + " subu %0, %2 \n"
5825 +#endif
5826 + " sc %0, %1 \n"
5827 + " beqz %0, 1b \n"
5828 +#ifdef CONFIG_PAX_REFCOUNT
5829 + "3: \n"
5830 + _ASM_EXTABLE(2b, 3b)
5831 +#endif
5832 + " .set mips0 \n"
5833 + : "=&r" (temp), "+m" (v->counter)
5834 + : "Ir" (i));
5835 + } else {
5836 + unsigned long flags;
5837 +
5838 + raw_local_irq_save(flags);
5839 + __asm__ __volatile__(
5840 +#ifdef CONFIG_PAX_REFCOUNT
5841 + /* Exception on overflow. */
5842 + "1: sub %0, %1 \n"
5843 + "2: \n"
5844 + _ASM_EXTABLE(1b, 2b)
5845 +#else
5846 + " subu %0, %1 \n"
5847 +#endif
5848 + : "+r" (v->counter) : "Ir" (i));
5849 + raw_local_irq_restore(flags);
5850 + }
5851 +}
5852 +
5853 +static __inline__ void atomic_sub_unchecked(long i, atomic_unchecked_t *v)
5854 {
5855 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5856 int temp;
5857 @@ -129,7 +281,93 @@ static __inline__ void atomic_sub(int i, atomic_t * v)
5858 /*
5859 * Same as above, but return the result value
5860 */
5861 -static __inline__ int atomic_add_return(int i, atomic_t * v)
5862 +static __inline__ int atomic_add_return(int i, atomic_t *v)
5863 +{
5864 + int result;
5865 + int temp;
5866 +
5867 + smp_mb__before_llsc();
5868 +
5869 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5870 + __asm__ __volatile__(
5871 + " .set mips3 \n"
5872 + "1: ll %1, %2 # atomic_add_return \n"
5873 +#ifdef CONFIG_PAX_REFCOUNT
5874 + "2: add %0, %1, %3 \n"
5875 +#else
5876 + " addu %0, %1, %3 \n"
5877 +#endif
5878 + " sc %0, %2 \n"
5879 + " beqzl %0, 1b \n"
5880 +#ifdef CONFIG_PAX_REFCOUNT
5881 + " b 4f \n"
5882 + " .set noreorder \n"
5883 + "3: b 5f \n"
5884 + " move %0, %1 \n"
5885 + " .set reorder \n"
5886 + _ASM_EXTABLE(2b, 3b)
5887 +#endif
5888 + "4: addu %0, %1, %3 \n"
5889 +#ifdef CONFIG_PAX_REFCOUNT
5890 + "5: \n"
5891 +#endif
5892 + " .set mips0 \n"
5893 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5894 + : "Ir" (i));
5895 + } else if (kernel_uses_llsc) {
5896 + __asm__ __volatile__(
5897 + " .set mips3 \n"
5898 + "1: ll %1, %2 # atomic_add_return \n"
5899 +#ifdef CONFIG_PAX_REFCOUNT
5900 + "2: add %0, %1, %3 \n"
5901 +#else
5902 + " addu %0, %1, %3 \n"
5903 +#endif
5904 + " sc %0, %2 \n"
5905 + " bnez %0, 4f \n"
5906 + " b 1b \n"
5907 +#ifdef CONFIG_PAX_REFCOUNT
5908 + " .set noreorder \n"
5909 + "3: b 5f \n"
5910 + " move %0, %1 \n"
5911 + " .set reorder \n"
5912 + _ASM_EXTABLE(2b, 3b)
5913 +#endif
5914 + "4: addu %0, %1, %3 \n"
5915 +#ifdef CONFIG_PAX_REFCOUNT
5916 + "5: \n"
5917 +#endif
5918 + " .set mips0 \n"
5919 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5920 + : "Ir" (i));
5921 + } else {
5922 + unsigned long flags;
5923 +
5924 + raw_local_irq_save(flags);
5925 + __asm__ __volatile__(
5926 + " lw %0, %1 \n"
5927 +#ifdef CONFIG_PAX_REFCOUNT
5928 + /* Exception on overflow. */
5929 + "1: add %0, %2 \n"
5930 +#else
5931 + " addu %0, %2 \n"
5932 +#endif
5933 + " sw %0, %1 \n"
5934 +#ifdef CONFIG_PAX_REFCOUNT
5935 + /* Note: Dest reg is not modified on overflow */
5936 + "2: \n"
5937 + _ASM_EXTABLE(1b, 2b)
5938 +#endif
5939 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5940 + raw_local_irq_restore(flags);
5941 + }
5942 +
5943 + smp_llsc_mb();
5944 +
5945 + return result;
5946 +}
5947 +
5948 +static __inline__ int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5949 {
5950 int result;
5951
5952 @@ -178,7 +416,93 @@ static __inline__ int atomic_add_return(int i, atomic_t * v)
5953 return result;
5954 }
5955
5956 -static __inline__ int atomic_sub_return(int i, atomic_t * v)
5957 +static __inline__ int atomic_sub_return(int i, atomic_t *v)
5958 +{
5959 + int result;
5960 + int temp;
5961 +
5962 + smp_mb__before_llsc();
5963 +
5964 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5965 + __asm__ __volatile__(
5966 + " .set mips3 \n"
5967 + "1: ll %1, %2 # atomic_sub_return \n"
5968 +#ifdef CONFIG_PAX_REFCOUNT
5969 + "2: sub %0, %1, %3 \n"
5970 +#else
5971 + " subu %0, %1, %3 \n"
5972 +#endif
5973 + " sc %0, %2 \n"
5974 + " beqzl %0, 1b \n"
5975 +#ifdef CONFIG_PAX_REFCOUNT
5976 + " b 4f \n"
5977 + " .set noreorder \n"
5978 + "3: b 5f \n"
5979 + " move %0, %1 \n"
5980 + " .set reorder \n"
5981 + _ASM_EXTABLE(2b, 3b)
5982 +#endif
5983 + "4: subu %0, %1, %3 \n"
5984 +#ifdef CONFIG_PAX_REFCOUNT
5985 + "5: \n"
5986 +#endif
5987 + " .set mips0 \n"
5988 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
5989 + : "Ir" (i), "m" (v->counter)
5990 + : "memory");
5991 + } else if (kernel_uses_llsc) {
5992 + __asm__ __volatile__(
5993 + " .set mips3 \n"
5994 + "1: ll %1, %2 # atomic_sub_return \n"
5995 +#ifdef CONFIG_PAX_REFCOUNT
5996 + "2: sub %0, %1, %3 \n"
5997 +#else
5998 + " subu %0, %1, %3 \n"
5999 +#endif
6000 + " sc %0, %2 \n"
6001 + " bnez %0, 4f \n"
6002 + " b 1b \n"
6003 +#ifdef CONFIG_PAX_REFCOUNT
6004 + " .set noreorder \n"
6005 + "3: b 5f \n"
6006 + " move %0, %1 \n"
6007 + " .set reorder \n"
6008 + _ASM_EXTABLE(2b, 3b)
6009 +#endif
6010 + "4: subu %0, %1, %3 \n"
6011 +#ifdef CONFIG_PAX_REFCOUNT
6012 + "5: \n"
6013 +#endif
6014 + " .set mips0 \n"
6015 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6016 + : "Ir" (i));
6017 + } else {
6018 + unsigned long flags;
6019 +
6020 + raw_local_irq_save(flags);
6021 + __asm__ __volatile__(
6022 + " lw %0, %1 \n"
6023 +#ifdef CONFIG_PAX_REFCOUNT
6024 + /* Exception on overflow. */
6025 + "1: sub %0, %2 \n"
6026 +#else
6027 + " subu %0, %2 \n"
6028 +#endif
6029 + " sw %0, %1 \n"
6030 +#ifdef CONFIG_PAX_REFCOUNT
6031 + /* Note: Dest reg is not modified on overflow */
6032 + "2: \n"
6033 + _ASM_EXTABLE(1b, 2b)
6034 +#endif
6035 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6036 + raw_local_irq_restore(flags);
6037 + }
6038 +
6039 + smp_llsc_mb();
6040 +
6041 + return result;
6042 +}
6043 +static __inline__ int atomic_sub_return_unchecked(int i, atomic_unchecked_t *v)
6044 {
6045 int result;
6046
6047 @@ -238,7 +562,7 @@ static __inline__ int atomic_sub_return(int i, atomic_t * v)
6048 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6049 * The function returns the old value of @v minus @i.
6050 */
6051 -static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
6052 +static __inline__ int atomic_sub_if_positive(int i, atomic_t *v)
6053 {
6054 int result;
6055
6056 @@ -295,8 +619,26 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
6057 return result;
6058 }
6059
6060 -#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
6061 -#define atomic_xchg(v, new) (xchg(&((v)->counter), (new)))
6062 +static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
6063 +{
6064 + return cmpxchg(&v->counter, old, new);
6065 +}
6066 +
6067 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old,
6068 + int new)
6069 +{
6070 + return cmpxchg(&(v->counter), old, new);
6071 +}
6072 +
6073 +static inline int atomic_xchg(atomic_t *v, int new)
6074 +{
6075 + return xchg(&v->counter, new);
6076 +}
6077 +
6078 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
6079 +{
6080 + return xchg(&(v->counter), new);
6081 +}
6082
6083 /**
6084 * __atomic_add_unless - add unless the number is a given value
6085 @@ -324,6 +666,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6086
6087 #define atomic_dec_return(v) atomic_sub_return(1, (v))
6088 #define atomic_inc_return(v) atomic_add_return(1, (v))
6089 +static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
6090 +{
6091 + return atomic_add_return_unchecked(1, v);
6092 +}
6093
6094 /*
6095 * atomic_sub_and_test - subtract value from variable and test result
6096 @@ -345,6 +691,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6097 * other cases.
6098 */
6099 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
6100 +static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
6101 +{
6102 + return atomic_add_return_unchecked(1, v) == 0;
6103 +}
6104
6105 /*
6106 * atomic_dec_and_test - decrement by 1 and test
6107 @@ -369,6 +719,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6108 * Atomically increments @v by 1.
6109 */
6110 #define atomic_inc(v) atomic_add(1, (v))
6111 +static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
6112 +{
6113 + atomic_add_unchecked(1, v);
6114 +}
6115
6116 /*
6117 * atomic_dec - decrement and test
6118 @@ -377,6 +731,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6119 * Atomically decrements @v by 1.
6120 */
6121 #define atomic_dec(v) atomic_sub(1, (v))
6122 +static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
6123 +{
6124 + atomic_sub_unchecked(1, v);
6125 +}
6126
6127 /*
6128 * atomic_add_negative - add and test if negative
6129 @@ -398,14 +756,30 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6130 * @v: pointer of type atomic64_t
6131 *
6132 */
6133 -#define atomic64_read(v) (*(volatile long *)&(v)->counter)
6134 +static inline long atomic64_read(const atomic64_t *v)
6135 +{
6136 + return (*(volatile const long *) &v->counter);
6137 +}
6138 +
6139 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
6140 +{
6141 + return (*(volatile const long *) &v->counter);
6142 +}
6143
6144 /*
6145 * atomic64_set - set atomic variable
6146 * @v: pointer of type atomic64_t
6147 * @i: required value
6148 */
6149 -#define atomic64_set(v, i) ((v)->counter = (i))
6150 +static inline void atomic64_set(atomic64_t *v, long i)
6151 +{
6152 + v->counter = i;
6153 +}
6154 +
6155 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
6156 +{
6157 + v->counter = i;
6158 +}
6159
6160 /*
6161 * atomic64_add - add integer to atomic variable
6162 @@ -414,7 +788,66 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
6163 *
6164 * Atomically adds @i to @v.
6165 */
6166 -static __inline__ void atomic64_add(long i, atomic64_t * v)
6167 +static __inline__ void atomic64_add(long i, atomic64_t *v)
6168 +{
6169 + long temp;
6170 +
6171 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6172 + __asm__ __volatile__(
6173 + " .set mips3 \n"
6174 + "1: lld %0, %1 # atomic64_add \n"
6175 +#ifdef CONFIG_PAX_REFCOUNT
6176 + /* Exception on overflow. */
6177 + "2: dadd %0, %2 \n"
6178 +#else
6179 + " daddu %0, %2 \n"
6180 +#endif
6181 + " scd %0, %1 \n"
6182 + " beqzl %0, 1b \n"
6183 +#ifdef CONFIG_PAX_REFCOUNT
6184 + "3: \n"
6185 + _ASM_EXTABLE(2b, 3b)
6186 +#endif
6187 + " .set mips0 \n"
6188 + : "=&r" (temp), "+m" (v->counter)
6189 + : "Ir" (i));
6190 + } else if (kernel_uses_llsc) {
6191 + __asm__ __volatile__(
6192 + " .set mips3 \n"
6193 + "1: lld %0, %1 # atomic64_add \n"
6194 +#ifdef CONFIG_PAX_REFCOUNT
6195 + /* Exception on overflow. */
6196 + "2: dadd %0, %2 \n"
6197 +#else
6198 + " daddu %0, %2 \n"
6199 +#endif
6200 + " scd %0, %1 \n"
6201 + " beqz %0, 1b \n"
6202 +#ifdef CONFIG_PAX_REFCOUNT
6203 + "3: \n"
6204 + _ASM_EXTABLE(2b, 3b)
6205 +#endif
6206 + " .set mips0 \n"
6207 + : "=&r" (temp), "+m" (v->counter)
6208 + : "Ir" (i));
6209 + } else {
6210 + unsigned long flags;
6211 +
6212 + raw_local_irq_save(flags);
6213 + __asm__ __volatile__(
6214 +#ifdef CONFIG_PAX_REFCOUNT
6215 + /* Exception on overflow. */
6216 + "1: dadd %0, %1 \n"
6217 + "2: \n"
6218 + _ASM_EXTABLE(1b, 2b)
6219 +#else
6220 + " daddu %0, %1 \n"
6221 +#endif
6222 + : "+r" (v->counter) : "Ir" (i));
6223 + raw_local_irq_restore(flags);
6224 + }
6225 +}
6226 +static __inline__ void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
6227 {
6228 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6229 long temp;
6230 @@ -457,7 +890,67 @@ static __inline__ void atomic64_add(long i, atomic64_t * v)
6231 *
6232 * Atomically subtracts @i from @v.
6233 */
6234 -static __inline__ void atomic64_sub(long i, atomic64_t * v)
6235 +static __inline__ void atomic64_sub(long i, atomic64_t *v)
6236 +{
6237 + long temp;
6238 +
6239 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6240 + __asm__ __volatile__(
6241 + " .set mips3 \n"
6242 + "1: lld %0, %1 # atomic64_sub \n"
6243 +#ifdef CONFIG_PAX_REFCOUNT
6244 + /* Exception on overflow. */
6245 + "2: dsub %0, %2 \n"
6246 +#else
6247 + " dsubu %0, %2 \n"
6248 +#endif
6249 + " scd %0, %1 \n"
6250 + " beqzl %0, 1b \n"
6251 +#ifdef CONFIG_PAX_REFCOUNT
6252 + "3: \n"
6253 + _ASM_EXTABLE(2b, 3b)
6254 +#endif
6255 + " .set mips0 \n"
6256 + : "=&r" (temp), "+m" (v->counter)
6257 + : "Ir" (i));
6258 + } else if (kernel_uses_llsc) {
6259 + __asm__ __volatile__(
6260 + " .set mips3 \n"
6261 + "1: lld %0, %1 # atomic64_sub \n"
6262 +#ifdef CONFIG_PAX_REFCOUNT
6263 + /* Exception on overflow. */
6264 + "2: dsub %0, %2 \n"
6265 +#else
6266 + " dsubu %0, %2 \n"
6267 +#endif
6268 + " scd %0, %1 \n"
6269 + " beqz %0, 1b \n"
6270 +#ifdef CONFIG_PAX_REFCOUNT
6271 + "3: \n"
6272 + _ASM_EXTABLE(2b, 3b)
6273 +#endif
6274 + " .set mips0 \n"
6275 + : "=&r" (temp), "+m" (v->counter)
6276 + : "Ir" (i));
6277 + } else {
6278 + unsigned long flags;
6279 +
6280 + raw_local_irq_save(flags);
6281 + __asm__ __volatile__(
6282 +#ifdef CONFIG_PAX_REFCOUNT
6283 + /* Exception on overflow. */
6284 + "1: dsub %0, %1 \n"
6285 + "2: \n"
6286 + _ASM_EXTABLE(1b, 2b)
6287 +#else
6288 + " dsubu %0, %1 \n"
6289 +#endif
6290 + : "+r" (v->counter) : "Ir" (i));
6291 + raw_local_irq_restore(flags);
6292 + }
6293 +}
6294 +
6295 +static __inline__ void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
6296 {
6297 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6298 long temp;
6299 @@ -496,7 +989,93 @@ static __inline__ void atomic64_sub(long i, atomic64_t * v)
6300 /*
6301 * Same as above, but return the result value
6302 */
6303 -static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6304 +static __inline__ long atomic64_add_return(long i, atomic64_t *v)
6305 +{
6306 + long result;
6307 + long temp;
6308 +
6309 + smp_mb__before_llsc();
6310 +
6311 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6312 + __asm__ __volatile__(
6313 + " .set mips3 \n"
6314 + "1: lld %1, %2 # atomic64_add_return \n"
6315 +#ifdef CONFIG_PAX_REFCOUNT
6316 + "2: dadd %0, %1, %3 \n"
6317 +#else
6318 + " daddu %0, %1, %3 \n"
6319 +#endif
6320 + " scd %0, %2 \n"
6321 + " beqzl %0, 1b \n"
6322 +#ifdef CONFIG_PAX_REFCOUNT
6323 + " b 4f \n"
6324 + " .set noreorder \n"
6325 + "3: b 5f \n"
6326 + " move %0, %1 \n"
6327 + " .set reorder \n"
6328 + _ASM_EXTABLE(2b, 3b)
6329 +#endif
6330 + "4: daddu %0, %1, %3 \n"
6331 +#ifdef CONFIG_PAX_REFCOUNT
6332 + "5: \n"
6333 +#endif
6334 + " .set mips0 \n"
6335 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6336 + : "Ir" (i));
6337 + } else if (kernel_uses_llsc) {
6338 + __asm__ __volatile__(
6339 + " .set mips3 \n"
6340 + "1: lld %1, %2 # atomic64_add_return \n"
6341 +#ifdef CONFIG_PAX_REFCOUNT
6342 + "2: dadd %0, %1, %3 \n"
6343 +#else
6344 + " daddu %0, %1, %3 \n"
6345 +#endif
6346 + " scd %0, %2 \n"
6347 + " bnez %0, 4f \n"
6348 + " b 1b \n"
6349 +#ifdef CONFIG_PAX_REFCOUNT
6350 + " .set noreorder \n"
6351 + "3: b 5f \n"
6352 + " move %0, %1 \n"
6353 + " .set reorder \n"
6354 + _ASM_EXTABLE(2b, 3b)
6355 +#endif
6356 + "4: daddu %0, %1, %3 \n"
6357 +#ifdef CONFIG_PAX_REFCOUNT
6358 + "5: \n"
6359 +#endif
6360 + " .set mips0 \n"
6361 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6362 + : "Ir" (i), "m" (v->counter)
6363 + : "memory");
6364 + } else {
6365 + unsigned long flags;
6366 +
6367 + raw_local_irq_save(flags);
6368 + __asm__ __volatile__(
6369 + " ld %0, %1 \n"
6370 +#ifdef CONFIG_PAX_REFCOUNT
6371 + /* Exception on overflow. */
6372 + "1: dadd %0, %2 \n"
6373 +#else
6374 + " daddu %0, %2 \n"
6375 +#endif
6376 + " sd %0, %1 \n"
6377 +#ifdef CONFIG_PAX_REFCOUNT
6378 + /* Note: Dest reg is not modified on overflow */
6379 + "2: \n"
6380 + _ASM_EXTABLE(1b, 2b)
6381 +#endif
6382 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6383 + raw_local_irq_restore(flags);
6384 + }
6385 +
6386 + smp_llsc_mb();
6387 +
6388 + return result;
6389 +}
6390 +static __inline__ long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6391 {
6392 long result;
6393
6394 @@ -546,7 +1125,97 @@ static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6395 return result;
6396 }
6397
6398 -static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6399 +static __inline__ long atomic64_sub_return(long i, atomic64_t *v)
6400 +{
6401 + long result;
6402 + long temp;
6403 +
6404 + smp_mb__before_llsc();
6405 +
6406 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6407 + long temp;
6408 +
6409 + __asm__ __volatile__(
6410 + " .set mips3 \n"
6411 + "1: lld %1, %2 # atomic64_sub_return \n"
6412 +#ifdef CONFIG_PAX_REFCOUNT
6413 + "2: dsub %0, %1, %3 \n"
6414 +#else
6415 + " dsubu %0, %1, %3 \n"
6416 +#endif
6417 + " scd %0, %2 \n"
6418 + " beqzl %0, 1b \n"
6419 +#ifdef CONFIG_PAX_REFCOUNT
6420 + " b 4f \n"
6421 + " .set noreorder \n"
6422 + "3: b 5f \n"
6423 + " move %0, %1 \n"
6424 + " .set reorder \n"
6425 + _ASM_EXTABLE(2b, 3b)
6426 +#endif
6427 + "4: dsubu %0, %1, %3 \n"
6428 +#ifdef CONFIG_PAX_REFCOUNT
6429 + "5: \n"
6430 +#endif
6431 + " .set mips0 \n"
6432 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6433 + : "Ir" (i), "m" (v->counter)
6434 + : "memory");
6435 + } else if (kernel_uses_llsc) {
6436 + __asm__ __volatile__(
6437 + " .set mips3 \n"
6438 + "1: lld %1, %2 # atomic64_sub_return \n"
6439 +#ifdef CONFIG_PAX_REFCOUNT
6440 + "2: dsub %0, %1, %3 \n"
6441 +#else
6442 + " dsubu %0, %1, %3 \n"
6443 +#endif
6444 + " scd %0, %2 \n"
6445 + " bnez %0, 4f \n"
6446 + " b 1b \n"
6447 +#ifdef CONFIG_PAX_REFCOUNT
6448 + " .set noreorder \n"
6449 + "3: b 5f \n"
6450 + " move %0, %1 \n"
6451 + " .set reorder \n"
6452 + _ASM_EXTABLE(2b, 3b)
6453 +#endif
6454 + "4: dsubu %0, %1, %3 \n"
6455 +#ifdef CONFIG_PAX_REFCOUNT
6456 + "5: \n"
6457 +#endif
6458 + " .set mips0 \n"
6459 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6460 + : "Ir" (i), "m" (v->counter)
6461 + : "memory");
6462 + } else {
6463 + unsigned long flags;
6464 +
6465 + raw_local_irq_save(flags);
6466 + __asm__ __volatile__(
6467 + " ld %0, %1 \n"
6468 +#ifdef CONFIG_PAX_REFCOUNT
6469 + /* Exception on overflow. */
6470 + "1: dsub %0, %2 \n"
6471 +#else
6472 + " dsubu %0, %2 \n"
6473 +#endif
6474 + " sd %0, %1 \n"
6475 +#ifdef CONFIG_PAX_REFCOUNT
6476 + /* Note: Dest reg is not modified on overflow */
6477 + "2: \n"
6478 + _ASM_EXTABLE(1b, 2b)
6479 +#endif
6480 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6481 + raw_local_irq_restore(flags);
6482 + }
6483 +
6484 + smp_llsc_mb();
6485 +
6486 + return result;
6487 +}
6488 +
6489 +static __inline__ long atomic64_sub_return_unchecked(long i, atomic64_unchecked_t *v)
6490 {
6491 long result;
6492
6493 @@ -605,7 +1274,7 @@ static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6494 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6495 * The function returns the old value of @v minus @i.
6496 */
6497 -static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6498 +static __inline__ long atomic64_sub_if_positive(long i, atomic64_t *v)
6499 {
6500 long result;
6501
6502 @@ -662,9 +1331,26 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6503 return result;
6504 }
6505
6506 -#define atomic64_cmpxchg(v, o, n) \
6507 - ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6508 -#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new)))
6509 +static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
6510 +{
6511 + return cmpxchg(&v->counter, old, new);
6512 +}
6513 +
6514 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old,
6515 + long new)
6516 +{
6517 + return cmpxchg(&(v->counter), old, new);
6518 +}
6519 +
6520 +static inline long atomic64_xchg(atomic64_t *v, long new)
6521 +{
6522 + return xchg(&v->counter, new);
6523 +}
6524 +
6525 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6526 +{
6527 + return xchg(&(v->counter), new);
6528 +}
6529
6530 /**
6531 * atomic64_add_unless - add unless the number is a given value
6532 @@ -694,6 +1380,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6533
6534 #define atomic64_dec_return(v) atomic64_sub_return(1, (v))
6535 #define atomic64_inc_return(v) atomic64_add_return(1, (v))
6536 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1, (v))
6537
6538 /*
6539 * atomic64_sub_and_test - subtract value from variable and test result
6540 @@ -715,6 +1402,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6541 * other cases.
6542 */
6543 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6544 +#define atomic64_inc_and_test_unchecked(v) atomic64_add_return_unchecked(1, (v)) == 0)
6545
6546 /*
6547 * atomic64_dec_and_test - decrement by 1 and test
6548 @@ -739,6 +1427,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6549 * Atomically increments @v by 1.
6550 */
6551 #define atomic64_inc(v) atomic64_add(1, (v))
6552 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1, (v))
6553
6554 /*
6555 * atomic64_dec - decrement and test
6556 @@ -747,6 +1436,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6557 * Atomically decrements @v by 1.
6558 */
6559 #define atomic64_dec(v) atomic64_sub(1, (v))
6560 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1, (v))
6561
6562 /*
6563 * atomic64_add_negative - add and test if negative
6564 diff --git a/arch/mips/include/asm/barrier.h b/arch/mips/include/asm/barrier.h
6565 index e1aa4e4..670b68b 100644
6566 --- a/arch/mips/include/asm/barrier.h
6567 +++ b/arch/mips/include/asm/barrier.h
6568 @@ -184,7 +184,7 @@
6569 do { \
6570 compiletime_assert_atomic_type(*p); \
6571 smp_mb(); \
6572 - ACCESS_ONCE(*p) = (v); \
6573 + ACCESS_ONCE_RW(*p) = (v); \
6574 } while (0)
6575
6576 #define smp_load_acquire(p) \
6577 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
6578 index b4db69f..8f3b093 100644
6579 --- a/arch/mips/include/asm/cache.h
6580 +++ b/arch/mips/include/asm/cache.h
6581 @@ -9,10 +9,11 @@
6582 #ifndef _ASM_CACHE_H
6583 #define _ASM_CACHE_H
6584
6585 +#include <linux/const.h>
6586 #include <kmalloc.h>
6587
6588 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
6589 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6590 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6591
6592 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
6593 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6594 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
6595 index d414405..6bb4ba2 100644
6596 --- a/arch/mips/include/asm/elf.h
6597 +++ b/arch/mips/include/asm/elf.h
6598 @@ -398,13 +398,16 @@ extern const char *__elf_platform;
6599 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
6600 #endif
6601
6602 +#ifdef CONFIG_PAX_ASLR
6603 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6604 +
6605 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6606 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6607 +#endif
6608 +
6609 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
6610 struct linux_binprm;
6611 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6612 int uses_interp);
6613
6614 -struct mm_struct;
6615 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6616 -#define arch_randomize_brk arch_randomize_brk
6617 -
6618 #endif /* _ASM_ELF_H */
6619 diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
6620 index c1f6afa..38cc6e9 100644
6621 --- a/arch/mips/include/asm/exec.h
6622 +++ b/arch/mips/include/asm/exec.h
6623 @@ -12,6 +12,6 @@
6624 #ifndef _ASM_EXEC_H
6625 #define _ASM_EXEC_H
6626
6627 -extern unsigned long arch_align_stack(unsigned long sp);
6628 +#define arch_align_stack(x) ((x) & ~0xfUL)
6629
6630 #endif /* _ASM_EXEC_H */
6631 diff --git a/arch/mips/include/asm/hw_irq.h b/arch/mips/include/asm/hw_irq.h
6632 index 9e8ef59..1139d6b 100644
6633 --- a/arch/mips/include/asm/hw_irq.h
6634 +++ b/arch/mips/include/asm/hw_irq.h
6635 @@ -10,7 +10,7 @@
6636
6637 #include <linux/atomic.h>
6638
6639 -extern atomic_t irq_err_count;
6640 +extern atomic_unchecked_t irq_err_count;
6641
6642 /*
6643 * interrupt-retrigger: NOP for now. This may not be appropriate for all
6644 diff --git a/arch/mips/include/asm/local.h b/arch/mips/include/asm/local.h
6645 index 46dfc3c..a16b13a 100644
6646 --- a/arch/mips/include/asm/local.h
6647 +++ b/arch/mips/include/asm/local.h
6648 @@ -12,15 +12,25 @@ typedef struct
6649 atomic_long_t a;
6650 } local_t;
6651
6652 +typedef struct {
6653 + atomic_long_unchecked_t a;
6654 +} local_unchecked_t;
6655 +
6656 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
6657
6658 #define local_read(l) atomic_long_read(&(l)->a)
6659 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
6660 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
6661 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
6662
6663 #define local_add(i, l) atomic_long_add((i), (&(l)->a))
6664 +#define local_add_unchecked(i, l) atomic_long_add_unchecked((i), (&(l)->a))
6665 #define local_sub(i, l) atomic_long_sub((i), (&(l)->a))
6666 +#define local_sub_unchecked(i, l) atomic_long_sub_unchecked((i), (&(l)->a))
6667 #define local_inc(l) atomic_long_inc(&(l)->a)
6668 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
6669 #define local_dec(l) atomic_long_dec(&(l)->a)
6670 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
6671
6672 /*
6673 * Same as above, but return the result value
6674 @@ -70,6 +80,51 @@ static __inline__ long local_add_return(long i, local_t * l)
6675 return result;
6676 }
6677
6678 +static __inline__ long local_add_return_unchecked(long i, local_unchecked_t * l)
6679 +{
6680 + unsigned long result;
6681 +
6682 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6683 + unsigned long temp;
6684 +
6685 + __asm__ __volatile__(
6686 + " .set mips3 \n"
6687 + "1:" __LL "%1, %2 # local_add_return \n"
6688 + " addu %0, %1, %3 \n"
6689 + __SC "%0, %2 \n"
6690 + " beqzl %0, 1b \n"
6691 + " addu %0, %1, %3 \n"
6692 + " .set mips0 \n"
6693 + : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6694 + : "Ir" (i), "m" (l->a.counter)
6695 + : "memory");
6696 + } else if (kernel_uses_llsc) {
6697 + unsigned long temp;
6698 +
6699 + __asm__ __volatile__(
6700 + " .set mips3 \n"
6701 + "1:" __LL "%1, %2 # local_add_return \n"
6702 + " addu %0, %1, %3 \n"
6703 + __SC "%0, %2 \n"
6704 + " beqz %0, 1b \n"
6705 + " addu %0, %1, %3 \n"
6706 + " .set mips0 \n"
6707 + : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6708 + : "Ir" (i), "m" (l->a.counter)
6709 + : "memory");
6710 + } else {
6711 + unsigned long flags;
6712 +
6713 + local_irq_save(flags);
6714 + result = l->a.counter;
6715 + result += i;
6716 + l->a.counter = result;
6717 + local_irq_restore(flags);
6718 + }
6719 +
6720 + return result;
6721 +}
6722 +
6723 static __inline__ long local_sub_return(long i, local_t * l)
6724 {
6725 unsigned long result;
6726 @@ -117,6 +172,8 @@ static __inline__ long local_sub_return(long i, local_t * l)
6727
6728 #define local_cmpxchg(l, o, n) \
6729 ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6730 +#define local_cmpxchg_unchecked(l, o, n) \
6731 + ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6732 #define local_xchg(l, n) (atomic_long_xchg((&(l)->a), (n)))
6733
6734 /**
6735 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
6736 index 5699ec3..95def83 100644
6737 --- a/arch/mips/include/asm/page.h
6738 +++ b/arch/mips/include/asm/page.h
6739 @@ -120,7 +120,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
6740 #ifdef CONFIG_CPU_MIPS32
6741 typedef struct { unsigned long pte_low, pte_high; } pte_t;
6742 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
6743 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
6744 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
6745 #else
6746 typedef struct { unsigned long long pte; } pte_t;
6747 #define pte_val(x) ((x).pte)
6748 diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
6749 index b336037..5b874cc 100644
6750 --- a/arch/mips/include/asm/pgalloc.h
6751 +++ b/arch/mips/include/asm/pgalloc.h
6752 @@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6753 {
6754 set_pud(pud, __pud((unsigned long)pmd));
6755 }
6756 +
6757 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6758 +{
6759 + pud_populate(mm, pud, pmd);
6760 +}
6761 #endif
6762
6763 /*
6764 diff --git a/arch/mips/include/asm/pgtable.h b/arch/mips/include/asm/pgtable.h
6765 index 008324d..f67c239 100644
6766 --- a/arch/mips/include/asm/pgtable.h
6767 +++ b/arch/mips/include/asm/pgtable.h
6768 @@ -20,6 +20,9 @@
6769 #include <asm/io.h>
6770 #include <asm/pgtable-bits.h>
6771
6772 +#define ktla_ktva(addr) (addr)
6773 +#define ktva_ktla(addr) (addr)
6774 +
6775 struct mm_struct;
6776 struct vm_area_struct;
6777
6778 diff --git a/arch/mips/include/asm/smtc_proc.h b/arch/mips/include/asm/smtc_proc.h
6779 index 25da651..ae2a259 100644
6780 --- a/arch/mips/include/asm/smtc_proc.h
6781 +++ b/arch/mips/include/asm/smtc_proc.h
6782 @@ -18,6 +18,6 @@ extern struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6783
6784 /* Count of number of recoveries of "stolen" FPU access rights on 34K */
6785
6786 -extern atomic_t smtc_fpu_recoveries;
6787 +extern atomic_unchecked_t smtc_fpu_recoveries;
6788
6789 #endif /* __ASM_SMTC_PROC_H */
6790 diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
6791 index d2d961d..a674df0 100644
6792 --- a/arch/mips/include/asm/thread_info.h
6793 +++ b/arch/mips/include/asm/thread_info.h
6794 @@ -105,6 +105,9 @@ static inline struct thread_info *current_thread_info(void)
6795 #define TIF_SECCOMP 4 /* secure computing */
6796 #define TIF_NOTIFY_RESUME 5 /* callback before returning to user */
6797 #define TIF_RESTORE_SIGMASK 9 /* restore signal mask in do_signal() */
6798 +/* li takes a 32bit immediate */
6799 +#define TIF_GRSEC_SETXID 10 /* update credentials on syscall entry/exit */
6800 +
6801 #define TIF_USEDFPU 16 /* FPU was used by this task this quantum (SMP) */
6802 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
6803 #define TIF_NOHZ 19 /* in adaptive nohz mode */
6804 @@ -138,14 +141,16 @@ static inline struct thread_info *current_thread_info(void)
6805 #define _TIF_USEDMSA (1<<TIF_USEDMSA)
6806 #define _TIF_MSA_CTX_LIVE (1<<TIF_MSA_CTX_LIVE)
6807 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6808 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6809
6810 #define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6811 _TIF_SYSCALL_AUDIT | \
6812 - _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
6813 + _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | \
6814 + _TIF_GRSEC_SETXID)
6815
6816 /* work to do in syscall_trace_leave() */
6817 #define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6818 - _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
6819 + _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6820
6821 /* work to do on interrupt/exception return */
6822 #define _TIF_WORK_MASK \
6823 @@ -153,7 +158,7 @@ static inline struct thread_info *current_thread_info(void)
6824 /* work to do on any return to u-space */
6825 #define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | \
6826 _TIF_WORK_SYSCALL_EXIT | \
6827 - _TIF_SYSCALL_TRACEPOINT)
6828 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6829
6830 /*
6831 * We stash processor id into a COP0 register to retrieve it fast
6832 diff --git a/arch/mips/include/asm/uaccess.h b/arch/mips/include/asm/uaccess.h
6833 index a109510..94ee3f6 100644
6834 --- a/arch/mips/include/asm/uaccess.h
6835 +++ b/arch/mips/include/asm/uaccess.h
6836 @@ -130,6 +130,7 @@ extern u64 __ua_limit;
6837 __ok == 0; \
6838 })
6839
6840 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
6841 #define access_ok(type, addr, size) \
6842 likely(__access_ok((addr), (size), __access_mask))
6843
6844 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
6845 index 1188e00..41cf144 100644
6846 --- a/arch/mips/kernel/binfmt_elfn32.c
6847 +++ b/arch/mips/kernel/binfmt_elfn32.c
6848 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6849 #undef ELF_ET_DYN_BASE
6850 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6851
6852 +#ifdef CONFIG_PAX_ASLR
6853 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6854 +
6855 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6856 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6857 +#endif
6858 +
6859 #include <asm/processor.h>
6860 #include <linux/module.h>
6861 #include <linux/elfcore.h>
6862 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
6863 index 7faf5f2..f3d3cf4 100644
6864 --- a/arch/mips/kernel/binfmt_elfo32.c
6865 +++ b/arch/mips/kernel/binfmt_elfo32.c
6866 @@ -70,6 +70,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6867 #undef ELF_ET_DYN_BASE
6868 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6869
6870 +#ifdef CONFIG_PAX_ASLR
6871 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6872 +
6873 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6874 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6875 +#endif
6876 +
6877 #include <asm/processor.h>
6878
6879 /*
6880 diff --git a/arch/mips/kernel/i8259.c b/arch/mips/kernel/i8259.c
6881 index 2b91fe8..fe4f6b4 100644
6882 --- a/arch/mips/kernel/i8259.c
6883 +++ b/arch/mips/kernel/i8259.c
6884 @@ -205,7 +205,7 @@ spurious_8259A_irq:
6885 printk(KERN_DEBUG "spurious 8259A interrupt: IRQ%d.\n", irq);
6886 spurious_irq_mask |= irqmask;
6887 }
6888 - atomic_inc(&irq_err_count);
6889 + atomic_inc_unchecked(&irq_err_count);
6890 /*
6891 * Theoretically we do not have to handle this IRQ,
6892 * but in Linux this does not cause problems and is
6893 diff --git a/arch/mips/kernel/irq-gt641xx.c b/arch/mips/kernel/irq-gt641xx.c
6894 index 44a1f79..2bd6aa3 100644
6895 --- a/arch/mips/kernel/irq-gt641xx.c
6896 +++ b/arch/mips/kernel/irq-gt641xx.c
6897 @@ -110,7 +110,7 @@ void gt641xx_irq_dispatch(void)
6898 }
6899 }
6900
6901 - atomic_inc(&irq_err_count);
6902 + atomic_inc_unchecked(&irq_err_count);
6903 }
6904
6905 void __init gt641xx_irq_init(void)
6906 diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
6907 index d1fea7a..2e591b0 100644
6908 --- a/arch/mips/kernel/irq.c
6909 +++ b/arch/mips/kernel/irq.c
6910 @@ -77,17 +77,17 @@ void ack_bad_irq(unsigned int irq)
6911 printk("unexpected IRQ # %d\n", irq);
6912 }
6913
6914 -atomic_t irq_err_count;
6915 +atomic_unchecked_t irq_err_count;
6916
6917 int arch_show_interrupts(struct seq_file *p, int prec)
6918 {
6919 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
6920 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
6921 return 0;
6922 }
6923
6924 asmlinkage void spurious_interrupt(void)
6925 {
6926 - atomic_inc(&irq_err_count);
6927 + atomic_inc_unchecked(&irq_err_count);
6928 }
6929
6930 void __init init_IRQ(void)
6931 @@ -110,7 +110,10 @@ void __init init_IRQ(void)
6932 #endif
6933 }
6934
6935 +
6936 #ifdef DEBUG_STACKOVERFLOW
6937 +extern void gr_handle_kernel_exploit(void);
6938 +
6939 static inline void check_stack_overflow(void)
6940 {
6941 unsigned long sp;
6942 @@ -126,6 +129,7 @@ static inline void check_stack_overflow(void)
6943 printk("do_IRQ: stack overflow: %ld\n",
6944 sp - sizeof(struct thread_info));
6945 dump_stack();
6946 + gr_handle_kernel_exploit();
6947 }
6948 }
6949 #else
6950 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
6951 index 60e39dc..b4829bf 100644
6952 --- a/arch/mips/kernel/process.c
6953 +++ b/arch/mips/kernel/process.c
6954 @@ -579,15 +579,3 @@ unsigned long get_wchan(struct task_struct *task)
6955 out:
6956 return pc;
6957 }
6958 -
6959 -/*
6960 - * Don't forget that the stack pointer must be aligned on a 8 bytes
6961 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
6962 - */
6963 -unsigned long arch_align_stack(unsigned long sp)
6964 -{
6965 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6966 - sp -= get_random_int() & ~PAGE_MASK;
6967 -
6968 - return sp & ALMASK;
6969 -}
6970 diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
6971 index f639ccd..e4b110d 100644
6972 --- a/arch/mips/kernel/ptrace.c
6973 +++ b/arch/mips/kernel/ptrace.c
6974 @@ -630,6 +630,10 @@ long arch_ptrace(struct task_struct *child, long request,
6975 return ret;
6976 }
6977
6978 +#ifdef CONFIG_GRKERNSEC_SETXID
6979 +extern void gr_delayed_cred_worker(void);
6980 +#endif
6981 +
6982 /*
6983 * Notification of system call entry/exit
6984 * - triggered by current->work.syscall_trace
6985 @@ -646,6 +650,11 @@ asmlinkage long syscall_trace_enter(struct pt_regs *regs, long syscall)
6986 tracehook_report_syscall_entry(regs))
6987 ret = -1;
6988
6989 +#ifdef CONFIG_GRKERNSEC_SETXID
6990 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6991 + gr_delayed_cred_worker();
6992 +#endif
6993 +
6994 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6995 trace_sys_enter(regs, regs->regs[2]);
6996
6997 diff --git a/arch/mips/kernel/reset.c b/arch/mips/kernel/reset.c
6998 index 07fc524..b9d7f28 100644
6999 --- a/arch/mips/kernel/reset.c
7000 +++ b/arch/mips/kernel/reset.c
7001 @@ -13,6 +13,7 @@
7002 #include <linux/reboot.h>
7003
7004 #include <asm/reboot.h>
7005 +#include <asm/bug.h>
7006
7007 /*
7008 * Urgs ... Too many MIPS machines to handle this in a generic way.
7009 @@ -29,16 +30,19 @@ void machine_restart(char *command)
7010 {
7011 if (_machine_restart)
7012 _machine_restart(command);
7013 + BUG();
7014 }
7015
7016 void machine_halt(void)
7017 {
7018 if (_machine_halt)
7019 _machine_halt();
7020 + BUG();
7021 }
7022
7023 void machine_power_off(void)
7024 {
7025 if (pm_power_off)
7026 pm_power_off();
7027 + BUG();
7028 }
7029 diff --git a/arch/mips/kernel/smtc-proc.c b/arch/mips/kernel/smtc-proc.c
7030 index 38635a9..3fcd5e0 100644
7031 --- a/arch/mips/kernel/smtc-proc.c
7032 +++ b/arch/mips/kernel/smtc-proc.c
7033 @@ -31,7 +31,7 @@ unsigned long selfipis[NR_CPUS];
7034
7035 struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
7036
7037 -atomic_t smtc_fpu_recoveries;
7038 +atomic_unchecked_t smtc_fpu_recoveries;
7039
7040 static int smtc_proc_show(struct seq_file *m, void *v)
7041 {
7042 @@ -48,7 +48,7 @@ static int smtc_proc_show(struct seq_file *m, void *v)
7043 for(i = 0; i < NR_CPUS; i++)
7044 seq_printf(m, "%d: %ld\n", i, smtc_cpu_stats[i].selfipis);
7045 seq_printf(m, "%d Recoveries of \"stolen\" FPU\n",
7046 - atomic_read(&smtc_fpu_recoveries));
7047 + atomic_read_unchecked(&smtc_fpu_recoveries));
7048 return 0;
7049 }
7050
7051 @@ -73,7 +73,7 @@ void init_smtc_stats(void)
7052 smtc_cpu_stats[i].selfipis = 0;
7053 }
7054
7055 - atomic_set(&smtc_fpu_recoveries, 0);
7056 + atomic_set_unchecked(&smtc_fpu_recoveries, 0);
7057
7058 proc_create("smtc", 0444, NULL, &smtc_proc_fops);
7059 }
7060 diff --git a/arch/mips/kernel/smtc.c b/arch/mips/kernel/smtc.c
7061 index c1681d6..9f881d1 100644
7062 --- a/arch/mips/kernel/smtc.c
7063 +++ b/arch/mips/kernel/smtc.c
7064 @@ -1359,7 +1359,7 @@ void smtc_soft_dump(void)
7065 }
7066 smtc_ipi_qdump();
7067 printk("%d Recoveries of \"stolen\" FPU\n",
7068 - atomic_read(&smtc_fpu_recoveries));
7069 + atomic_read_unchecked(&smtc_fpu_recoveries));
7070 }
7071
7072
7073 diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
7074 index c24ad5f..9983ab2 100644
7075 --- a/arch/mips/kernel/sync-r4k.c
7076 +++ b/arch/mips/kernel/sync-r4k.c
7077 @@ -20,8 +20,8 @@
7078 #include <asm/mipsregs.h>
7079
7080 static atomic_t count_start_flag = ATOMIC_INIT(0);
7081 -static atomic_t count_count_start = ATOMIC_INIT(0);
7082 -static atomic_t count_count_stop = ATOMIC_INIT(0);
7083 +static atomic_unchecked_t count_count_start = ATOMIC_INIT(0);
7084 +static atomic_unchecked_t count_count_stop = ATOMIC_INIT(0);
7085 static atomic_t count_reference = ATOMIC_INIT(0);
7086
7087 #define COUNTON 100
7088 @@ -68,13 +68,13 @@ void synchronise_count_master(int cpu)
7089
7090 for (i = 0; i < NR_LOOPS; i++) {
7091 /* slaves loop on '!= 2' */
7092 - while (atomic_read(&count_count_start) != 1)
7093 + while (atomic_read_unchecked(&count_count_start) != 1)
7094 mb();
7095 - atomic_set(&count_count_stop, 0);
7096 + atomic_set_unchecked(&count_count_stop, 0);
7097 smp_wmb();
7098
7099 /* this lets the slaves write their count register */
7100 - atomic_inc(&count_count_start);
7101 + atomic_inc_unchecked(&count_count_start);
7102
7103 /*
7104 * Everyone initialises count in the last loop:
7105 @@ -85,11 +85,11 @@ void synchronise_count_master(int cpu)
7106 /*
7107 * Wait for all slaves to leave the synchronization point:
7108 */
7109 - while (atomic_read(&count_count_stop) != 1)
7110 + while (atomic_read_unchecked(&count_count_stop) != 1)
7111 mb();
7112 - atomic_set(&count_count_start, 0);
7113 + atomic_set_unchecked(&count_count_start, 0);
7114 smp_wmb();
7115 - atomic_inc(&count_count_stop);
7116 + atomic_inc_unchecked(&count_count_stop);
7117 }
7118 /* Arrange for an interrupt in a short while */
7119 write_c0_compare(read_c0_count() + COUNTON);
7120 @@ -130,8 +130,8 @@ void synchronise_count_slave(int cpu)
7121 initcount = atomic_read(&count_reference);
7122
7123 for (i = 0; i < NR_LOOPS; i++) {
7124 - atomic_inc(&count_count_start);
7125 - while (atomic_read(&count_count_start) != 2)
7126 + atomic_inc_unchecked(&count_count_start);
7127 + while (atomic_read_unchecked(&count_count_start) != 2)
7128 mb();
7129
7130 /*
7131 @@ -140,8 +140,8 @@ void synchronise_count_slave(int cpu)
7132 if (i == NR_LOOPS-1)
7133 write_c0_count(initcount);
7134
7135 - atomic_inc(&count_count_stop);
7136 - while (atomic_read(&count_count_stop) != 2)
7137 + atomic_inc_unchecked(&count_count_stop);
7138 + while (atomic_read_unchecked(&count_count_stop) != 2)
7139 mb();
7140 }
7141 /* Arrange for an interrupt in a short while */
7142 diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
7143 index 8119ac2..b229939 100644
7144 --- a/arch/mips/kernel/traps.c
7145 +++ b/arch/mips/kernel/traps.c
7146 @@ -695,7 +695,18 @@ asmlinkage void do_ov(struct pt_regs *regs)
7147 siginfo_t info;
7148
7149 prev_state = exception_enter();
7150 - die_if_kernel("Integer overflow", regs);
7151 + if (unlikely(!user_mode(regs))) {
7152 +
7153 +#ifdef CONFIG_PAX_REFCOUNT
7154 + if (fixup_exception(regs)) {
7155 + pax_report_refcount_overflow(regs);
7156 + exception_exit(prev_state);
7157 + return;
7158 + }
7159 +#endif
7160 +
7161 + die("Integer overflow", regs);
7162 + }
7163
7164 info.si_code = FPE_INTOVF;
7165 info.si_signo = SIGFPE;
7166 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
7167 index becc42b..9e43d4b 100644
7168 --- a/arch/mips/mm/fault.c
7169 +++ b/arch/mips/mm/fault.c
7170 @@ -28,6 +28,23 @@
7171 #include <asm/highmem.h> /* For VMALLOC_END */
7172 #include <linux/kdebug.h>
7173
7174 +#ifdef CONFIG_PAX_PAGEEXEC
7175 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7176 +{
7177 + unsigned long i;
7178 +
7179 + printk(KERN_ERR "PAX: bytes at PC: ");
7180 + for (i = 0; i < 5; i++) {
7181 + unsigned int c;
7182 + if (get_user(c, (unsigned int *)pc+i))
7183 + printk(KERN_CONT "???????? ");
7184 + else
7185 + printk(KERN_CONT "%08x ", c);
7186 + }
7187 + printk("\n");
7188 +}
7189 +#endif
7190 +
7191 /*
7192 * This routine handles page faults. It determines the address,
7193 * and the problem, and then passes it off to one of the appropriate
7194 @@ -199,6 +216,14 @@ bad_area:
7195 bad_area_nosemaphore:
7196 /* User mode accesses just cause a SIGSEGV */
7197 if (user_mode(regs)) {
7198 +
7199 +#ifdef CONFIG_PAX_PAGEEXEC
7200 + if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
7201 + pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
7202 + do_group_exit(SIGKILL);
7203 + }
7204 +#endif
7205 +
7206 tsk->thread.cp0_badvaddr = address;
7207 tsk->thread.error_code = write;
7208 #if 0
7209 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
7210 index f1baadd..5472dca 100644
7211 --- a/arch/mips/mm/mmap.c
7212 +++ b/arch/mips/mm/mmap.c
7213 @@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7214 struct vm_area_struct *vma;
7215 unsigned long addr = addr0;
7216 int do_color_align;
7217 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
7218 struct vm_unmapped_area_info info;
7219
7220 if (unlikely(len > TASK_SIZE))
7221 @@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7222 do_color_align = 1;
7223
7224 /* requesting a specific address */
7225 +
7226 +#ifdef CONFIG_PAX_RANDMMAP
7227 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
7228 +#endif
7229 +
7230 if (addr) {
7231 if (do_color_align)
7232 addr = COLOUR_ALIGN(addr, pgoff);
7233 @@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
7234 addr = PAGE_ALIGN(addr);
7235
7236 vma = find_vma(mm, addr);
7237 - if (TASK_SIZE - len >= addr &&
7238 - (!vma || addr + len <= vma->vm_start))
7239 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
7240 return addr;
7241 }
7242
7243 info.length = len;
7244 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
7245 info.align_offset = pgoff << PAGE_SHIFT;
7246 + info.threadstack_offset = offset;
7247
7248 if (dir == DOWN) {
7249 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
7250 @@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7251 {
7252 unsigned long random_factor = 0UL;
7253
7254 +#ifdef CONFIG_PAX_RANDMMAP
7255 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7256 +#endif
7257 +
7258 if (current->flags & PF_RANDOMIZE) {
7259 random_factor = get_random_int();
7260 random_factor = random_factor << PAGE_SHIFT;
7261 @@ -157,40 +167,25 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7262
7263 if (mmap_is_legacy()) {
7264 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
7265 +
7266 +#ifdef CONFIG_PAX_RANDMMAP
7267 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7268 + mm->mmap_base += mm->delta_mmap;
7269 +#endif
7270 +
7271 mm->get_unmapped_area = arch_get_unmapped_area;
7272 } else {
7273 mm->mmap_base = mmap_base(random_factor);
7274 +
7275 +#ifdef CONFIG_PAX_RANDMMAP
7276 + if (mm->pax_flags & MF_PAX_RANDMMAP)
7277 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7278 +#endif
7279 +
7280 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
7281 }
7282 }
7283
7284 -static inline unsigned long brk_rnd(void)
7285 -{
7286 - unsigned long rnd = get_random_int();
7287 -
7288 - rnd = rnd << PAGE_SHIFT;
7289 - /* 8MB for 32bit, 256MB for 64bit */
7290 - if (TASK_IS_32BIT_ADDR)
7291 - rnd = rnd & 0x7ffffful;
7292 - else
7293 - rnd = rnd & 0xffffffful;
7294 -
7295 - return rnd;
7296 -}
7297 -
7298 -unsigned long arch_randomize_brk(struct mm_struct *mm)
7299 -{
7300 - unsigned long base = mm->brk;
7301 - unsigned long ret;
7302 -
7303 - ret = PAGE_ALIGN(base + brk_rnd());
7304 -
7305 - if (ret < mm->brk)
7306 - return mm->brk;
7307 -
7308 - return ret;
7309 -}
7310 -
7311 int __virt_addr_valid(const volatile void *kaddr)
7312 {
7313 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
7314 diff --git a/arch/mips/pci/pci-octeon.c b/arch/mips/pci/pci-octeon.c
7315 index 59cccd9..f39ac2f 100644
7316 --- a/arch/mips/pci/pci-octeon.c
7317 +++ b/arch/mips/pci/pci-octeon.c
7318 @@ -327,8 +327,8 @@ static int octeon_write_config(struct pci_bus *bus, unsigned int devfn,
7319
7320
7321 static struct pci_ops octeon_pci_ops = {
7322 - octeon_read_config,
7323 - octeon_write_config,
7324 + .read = octeon_read_config,
7325 + .write = octeon_write_config,
7326 };
7327
7328 static struct resource octeon_pci_mem_resource = {
7329 diff --git a/arch/mips/pci/pcie-octeon.c b/arch/mips/pci/pcie-octeon.c
7330 index 5e36c33..eb4a17b 100644
7331 --- a/arch/mips/pci/pcie-octeon.c
7332 +++ b/arch/mips/pci/pcie-octeon.c
7333 @@ -1792,8 +1792,8 @@ static int octeon_dummy_write_config(struct pci_bus *bus, unsigned int devfn,
7334 }
7335
7336 static struct pci_ops octeon_pcie0_ops = {
7337 - octeon_pcie0_read_config,
7338 - octeon_pcie0_write_config,
7339 + .read = octeon_pcie0_read_config,
7340 + .write = octeon_pcie0_write_config,
7341 };
7342
7343 static struct resource octeon_pcie0_mem_resource = {
7344 @@ -1813,8 +1813,8 @@ static struct pci_controller octeon_pcie0_controller = {
7345 };
7346
7347 static struct pci_ops octeon_pcie1_ops = {
7348 - octeon_pcie1_read_config,
7349 - octeon_pcie1_write_config,
7350 + .read = octeon_pcie1_read_config,
7351 + .write = octeon_pcie1_write_config,
7352 };
7353
7354 static struct resource octeon_pcie1_mem_resource = {
7355 @@ -1834,8 +1834,8 @@ static struct pci_controller octeon_pcie1_controller = {
7356 };
7357
7358 static struct pci_ops octeon_dummy_ops = {
7359 - octeon_dummy_read_config,
7360 - octeon_dummy_write_config,
7361 + .read = octeon_dummy_read_config,
7362 + .write = octeon_dummy_write_config,
7363 };
7364
7365 static struct resource octeon_dummy_mem_resource = {
7366 diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c
7367 index a2358b4..7cead4f 100644
7368 --- a/arch/mips/sgi-ip27/ip27-nmi.c
7369 +++ b/arch/mips/sgi-ip27/ip27-nmi.c
7370 @@ -187,9 +187,9 @@ void
7371 cont_nmi_dump(void)
7372 {
7373 #ifndef REAL_NMI_SIGNAL
7374 - static atomic_t nmied_cpus = ATOMIC_INIT(0);
7375 + static atomic_unchecked_t nmied_cpus = ATOMIC_INIT(0);
7376
7377 - atomic_inc(&nmied_cpus);
7378 + atomic_inc_unchecked(&nmied_cpus);
7379 #endif
7380 /*
7381 * Only allow 1 cpu to proceed
7382 @@ -233,7 +233,7 @@ cont_nmi_dump(void)
7383 udelay(10000);
7384 }
7385 #else
7386 - while (atomic_read(&nmied_cpus) != num_online_cpus());
7387 + while (atomic_read_unchecked(&nmied_cpus) != num_online_cpus());
7388 #endif
7389
7390 /*
7391 diff --git a/arch/mips/sni/rm200.c b/arch/mips/sni/rm200.c
7392 index a046b30..6799527 100644
7393 --- a/arch/mips/sni/rm200.c
7394 +++ b/arch/mips/sni/rm200.c
7395 @@ -270,7 +270,7 @@ spurious_8259A_irq:
7396 "spurious RM200 8259A interrupt: IRQ%d.\n", irq);
7397 spurious_irq_mask |= irqmask;
7398 }
7399 - atomic_inc(&irq_err_count);
7400 + atomic_inc_unchecked(&irq_err_count);
7401 /*
7402 * Theoretically we do not have to handle this IRQ,
7403 * but in Linux this does not cause problems and is
7404 diff --git a/arch/mips/vr41xx/common/icu.c b/arch/mips/vr41xx/common/icu.c
7405 index 41e873b..34d33a7 100644
7406 --- a/arch/mips/vr41xx/common/icu.c
7407 +++ b/arch/mips/vr41xx/common/icu.c
7408 @@ -653,7 +653,7 @@ static int icu_get_irq(unsigned int irq)
7409
7410 printk(KERN_ERR "spurious ICU interrupt: %04x,%04x\n", pend1, pend2);
7411
7412 - atomic_inc(&irq_err_count);
7413 + atomic_inc_unchecked(&irq_err_count);
7414
7415 return -1;
7416 }
7417 diff --git a/arch/mips/vr41xx/common/irq.c b/arch/mips/vr41xx/common/irq.c
7418 index ae0e4ee..e8f0692 100644
7419 --- a/arch/mips/vr41xx/common/irq.c
7420 +++ b/arch/mips/vr41xx/common/irq.c
7421 @@ -64,7 +64,7 @@ static void irq_dispatch(unsigned int irq)
7422 irq_cascade_t *cascade;
7423
7424 if (irq >= NR_IRQS) {
7425 - atomic_inc(&irq_err_count);
7426 + atomic_inc_unchecked(&irq_err_count);
7427 return;
7428 }
7429
7430 @@ -84,7 +84,7 @@ static void irq_dispatch(unsigned int irq)
7431 ret = cascade->get_irq(irq);
7432 irq = ret;
7433 if (ret < 0)
7434 - atomic_inc(&irq_err_count);
7435 + atomic_inc_unchecked(&irq_err_count);
7436 else
7437 irq_dispatch(irq);
7438 if (!irqd_irq_disabled(idata) && chip->irq_unmask)
7439 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7440 index 967d144..db12197 100644
7441 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
7442 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7443 @@ -11,12 +11,14 @@
7444 #ifndef _ASM_PROC_CACHE_H
7445 #define _ASM_PROC_CACHE_H
7446
7447 +#include <linux/const.h>
7448 +
7449 /* L1 cache */
7450
7451 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7452 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
7453 -#define L1_CACHE_BYTES 16 /* bytes per entry */
7454 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
7455 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7456 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
7457
7458 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7459 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7460 index bcb5df2..84fabd2 100644
7461 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7462 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7463 @@ -16,13 +16,15 @@
7464 #ifndef _ASM_PROC_CACHE_H
7465 #define _ASM_PROC_CACHE_H
7466
7467 +#include <linux/const.h>
7468 +
7469 /*
7470 * L1 cache
7471 */
7472 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7473 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
7474 -#define L1_CACHE_BYTES 32 /* bytes per entry */
7475 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
7476 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7477 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
7478
7479 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7480 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
7481 index 4ce7a01..449202a 100644
7482 --- a/arch/openrisc/include/asm/cache.h
7483 +++ b/arch/openrisc/include/asm/cache.h
7484 @@ -19,11 +19,13 @@
7485 #ifndef __ASM_OPENRISC_CACHE_H
7486 #define __ASM_OPENRISC_CACHE_H
7487
7488 +#include <linux/const.h>
7489 +
7490 /* FIXME: How can we replace these with values from the CPU...
7491 * they shouldn't be hard-coded!
7492 */
7493
7494 -#define L1_CACHE_BYTES 16
7495 #define L1_CACHE_SHIFT 4
7496 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7497
7498 #endif /* __ASM_OPENRISC_CACHE_H */
7499 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
7500 index 472886c..00e7df9 100644
7501 --- a/arch/parisc/include/asm/atomic.h
7502 +++ b/arch/parisc/include/asm/atomic.h
7503 @@ -252,6 +252,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
7504 return dec;
7505 }
7506
7507 +#define atomic64_read_unchecked(v) atomic64_read(v)
7508 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7509 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7510 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7511 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7512 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
7513 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7514 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
7515 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7516 +
7517 #endif /* !CONFIG_64BIT */
7518
7519
7520 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
7521 index 47f11c7..3420df2 100644
7522 --- a/arch/parisc/include/asm/cache.h
7523 +++ b/arch/parisc/include/asm/cache.h
7524 @@ -5,6 +5,7 @@
7525 #ifndef __ARCH_PARISC_CACHE_H
7526 #define __ARCH_PARISC_CACHE_H
7527
7528 +#include <linux/const.h>
7529
7530 /*
7531 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
7532 @@ -15,13 +16,13 @@
7533 * just ruin performance.
7534 */
7535 #ifdef CONFIG_PA20
7536 -#define L1_CACHE_BYTES 64
7537 #define L1_CACHE_SHIFT 6
7538 #else
7539 -#define L1_CACHE_BYTES 32
7540 #define L1_CACHE_SHIFT 5
7541 #endif
7542
7543 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7544 +
7545 #ifndef __ASSEMBLY__
7546
7547 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7548 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
7549 index 3391d06..c23a2cc 100644
7550 --- a/arch/parisc/include/asm/elf.h
7551 +++ b/arch/parisc/include/asm/elf.h
7552 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
7553
7554 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
7555
7556 +#ifdef CONFIG_PAX_ASLR
7557 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
7558 +
7559 +#define PAX_DELTA_MMAP_LEN 16
7560 +#define PAX_DELTA_STACK_LEN 16
7561 +#endif
7562 +
7563 /* This yields a mask that user programs can use to figure out what
7564 instruction set this CPU supports. This could be done in user space,
7565 but it's not easy, and we've already done it here. */
7566 diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
7567 index f213f5b..0af3e8e 100644
7568 --- a/arch/parisc/include/asm/pgalloc.h
7569 +++ b/arch/parisc/include/asm/pgalloc.h
7570 @@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7571 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
7572 }
7573
7574 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7575 +{
7576 + pgd_populate(mm, pgd, pmd);
7577 +}
7578 +
7579 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
7580 {
7581 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
7582 @@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
7583 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
7584 #define pmd_free(mm, x) do { } while (0)
7585 #define pgd_populate(mm, pmd, pte) BUG()
7586 +#define pgd_populate_kernel(mm, pmd, pte) BUG()
7587
7588 #endif
7589
7590 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
7591 index 22b89d1..ce34230 100644
7592 --- a/arch/parisc/include/asm/pgtable.h
7593 +++ b/arch/parisc/include/asm/pgtable.h
7594 @@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
7595 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
7596 #define PAGE_COPY PAGE_EXECREAD
7597 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
7598 +
7599 +#ifdef CONFIG_PAX_PAGEEXEC
7600 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
7601 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7602 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7603 +#else
7604 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
7605 +# define PAGE_COPY_NOEXEC PAGE_COPY
7606 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
7607 +#endif
7608 +
7609 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
7610 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
7611 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
7612 diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
7613 index 4006964..fcb3cc2 100644
7614 --- a/arch/parisc/include/asm/uaccess.h
7615 +++ b/arch/parisc/include/asm/uaccess.h
7616 @@ -246,10 +246,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
7617 const void __user *from,
7618 unsigned long n)
7619 {
7620 - int sz = __compiletime_object_size(to);
7621 + size_t sz = __compiletime_object_size(to);
7622 int ret = -EFAULT;
7623
7624 - if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
7625 + if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
7626 ret = __copy_from_user(to, from, n);
7627 else
7628 copy_from_user_overflow();
7629 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
7630 index 50dfafc..b9fc230 100644
7631 --- a/arch/parisc/kernel/module.c
7632 +++ b/arch/parisc/kernel/module.c
7633 @@ -98,16 +98,38 @@
7634
7635 /* three functions to determine where in the module core
7636 * or init pieces the location is */
7637 +static inline int in_init_rx(struct module *me, void *loc)
7638 +{
7639 + return (loc >= me->module_init_rx &&
7640 + loc < (me->module_init_rx + me->init_size_rx));
7641 +}
7642 +
7643 +static inline int in_init_rw(struct module *me, void *loc)
7644 +{
7645 + return (loc >= me->module_init_rw &&
7646 + loc < (me->module_init_rw + me->init_size_rw));
7647 +}
7648 +
7649 static inline int in_init(struct module *me, void *loc)
7650 {
7651 - return (loc >= me->module_init &&
7652 - loc <= (me->module_init + me->init_size));
7653 + return in_init_rx(me, loc) || in_init_rw(me, loc);
7654 +}
7655 +
7656 +static inline int in_core_rx(struct module *me, void *loc)
7657 +{
7658 + return (loc >= me->module_core_rx &&
7659 + loc < (me->module_core_rx + me->core_size_rx));
7660 +}
7661 +
7662 +static inline int in_core_rw(struct module *me, void *loc)
7663 +{
7664 + return (loc >= me->module_core_rw &&
7665 + loc < (me->module_core_rw + me->core_size_rw));
7666 }
7667
7668 static inline int in_core(struct module *me, void *loc)
7669 {
7670 - return (loc >= me->module_core &&
7671 - loc <= (me->module_core + me->core_size));
7672 + return in_core_rx(me, loc) || in_core_rw(me, loc);
7673 }
7674
7675 static inline int in_local(struct module *me, void *loc)
7676 @@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
7677 }
7678
7679 /* align things a bit */
7680 - me->core_size = ALIGN(me->core_size, 16);
7681 - me->arch.got_offset = me->core_size;
7682 - me->core_size += gots * sizeof(struct got_entry);
7683 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
7684 + me->arch.got_offset = me->core_size_rw;
7685 + me->core_size_rw += gots * sizeof(struct got_entry);
7686
7687 - me->core_size = ALIGN(me->core_size, 16);
7688 - me->arch.fdesc_offset = me->core_size;
7689 - me->core_size += fdescs * sizeof(Elf_Fdesc);
7690 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
7691 + me->arch.fdesc_offset = me->core_size_rw;
7692 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
7693
7694 me->arch.got_max = gots;
7695 me->arch.fdesc_max = fdescs;
7696 @@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7697
7698 BUG_ON(value == 0);
7699
7700 - got = me->module_core + me->arch.got_offset;
7701 + got = me->module_core_rw + me->arch.got_offset;
7702 for (i = 0; got[i].addr; i++)
7703 if (got[i].addr == value)
7704 goto out;
7705 @@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7706 #ifdef CONFIG_64BIT
7707 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7708 {
7709 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
7710 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
7711
7712 if (!value) {
7713 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
7714 @@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7715
7716 /* Create new one */
7717 fdesc->addr = value;
7718 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7719 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7720 return (Elf_Addr)fdesc;
7721 }
7722 #endif /* CONFIG_64BIT */
7723 @@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
7724
7725 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
7726 end = table + sechdrs[me->arch.unwind_section].sh_size;
7727 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7728 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7729
7730 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
7731 me->arch.unwind_section, table, end, gp);
7732 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
7733 index e1ffea2..46ed66e 100644
7734 --- a/arch/parisc/kernel/sys_parisc.c
7735 +++ b/arch/parisc/kernel/sys_parisc.c
7736 @@ -89,6 +89,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7737 unsigned long task_size = TASK_SIZE;
7738 int do_color_align, last_mmap;
7739 struct vm_unmapped_area_info info;
7740 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7741
7742 if (len > task_size)
7743 return -ENOMEM;
7744 @@ -106,6 +107,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7745 goto found_addr;
7746 }
7747
7748 +#ifdef CONFIG_PAX_RANDMMAP
7749 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7750 +#endif
7751 +
7752 if (addr) {
7753 if (do_color_align && last_mmap)
7754 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7755 @@ -124,6 +129,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7756 info.high_limit = mmap_upper_limit();
7757 info.align_mask = last_mmap ? (PAGE_MASK & (SHM_COLOUR - 1)) : 0;
7758 info.align_offset = shared_align_offset(last_mmap, pgoff);
7759 + info.threadstack_offset = offset;
7760 addr = vm_unmapped_area(&info);
7761
7762 found_addr:
7763 @@ -143,6 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7764 unsigned long addr = addr0;
7765 int do_color_align, last_mmap;
7766 struct vm_unmapped_area_info info;
7767 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7768
7769 #ifdef CONFIG_64BIT
7770 /* This should only ever run for 32-bit processes. */
7771 @@ -167,6 +174,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7772 }
7773
7774 /* requesting a specific address */
7775 +#ifdef CONFIG_PAX_RANDMMAP
7776 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
7777 +#endif
7778 +
7779 if (addr) {
7780 if (do_color_align && last_mmap)
7781 addr = COLOR_ALIGN(addr, last_mmap, pgoff);
7782 @@ -184,6 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7783 info.high_limit = mm->mmap_base;
7784 info.align_mask = last_mmap ? (PAGE_MASK & (SHM_COLOUR - 1)) : 0;
7785 info.align_offset = shared_align_offset(last_mmap, pgoff);
7786 + info.threadstack_offset = offset;
7787 addr = vm_unmapped_area(&info);
7788 if (!(addr & ~PAGE_MASK))
7789 goto found_addr;
7790 @@ -249,6 +261,13 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
7791 mm->mmap_legacy_base = mmap_legacy_base();
7792 mm->mmap_base = mmap_upper_limit();
7793
7794 +#ifdef CONFIG_PAX_RANDMMAP
7795 + if (mm->pax_flags & MF_PAX_RANDMMAP) {
7796 + mm->mmap_legacy_base += mm->delta_mmap;
7797 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
7798 + }
7799 +#endif
7800 +
7801 if (mmap_is_legacy()) {
7802 mm->mmap_base = mm->mmap_legacy_base;
7803 mm->get_unmapped_area = arch_get_unmapped_area;
7804 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
7805 index 47ee620..1107387 100644
7806 --- a/arch/parisc/kernel/traps.c
7807 +++ b/arch/parisc/kernel/traps.c
7808 @@ -726,9 +726,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
7809
7810 down_read(&current->mm->mmap_sem);
7811 vma = find_vma(current->mm,regs->iaoq[0]);
7812 - if (vma && (regs->iaoq[0] >= vma->vm_start)
7813 - && (vma->vm_flags & VM_EXEC)) {
7814 -
7815 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
7816 fault_address = regs->iaoq[0];
7817 fault_space = regs->iasq[0];
7818
7819 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
7820 index 3ca9c11..d163ef7 100644
7821 --- a/arch/parisc/mm/fault.c
7822 +++ b/arch/parisc/mm/fault.c
7823 @@ -15,6 +15,7 @@
7824 #include <linux/sched.h>
7825 #include <linux/interrupt.h>
7826 #include <linux/module.h>
7827 +#include <linux/unistd.h>
7828
7829 #include <asm/uaccess.h>
7830 #include <asm/traps.h>
7831 @@ -50,7 +51,7 @@ int show_unhandled_signals = 1;
7832 static unsigned long
7833 parisc_acctyp(unsigned long code, unsigned int inst)
7834 {
7835 - if (code == 6 || code == 16)
7836 + if (code == 6 || code == 7 || code == 16)
7837 return VM_EXEC;
7838
7839 switch (inst & 0xf0000000) {
7840 @@ -136,6 +137,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
7841 }
7842 #endif
7843
7844 +#ifdef CONFIG_PAX_PAGEEXEC
7845 +/*
7846 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
7847 + *
7848 + * returns 1 when task should be killed
7849 + * 2 when rt_sigreturn trampoline was detected
7850 + * 3 when unpatched PLT trampoline was detected
7851 + */
7852 +static int pax_handle_fetch_fault(struct pt_regs *regs)
7853 +{
7854 +
7855 +#ifdef CONFIG_PAX_EMUPLT
7856 + int err;
7857 +
7858 + do { /* PaX: unpatched PLT emulation */
7859 + unsigned int bl, depwi;
7860 +
7861 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
7862 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
7863 +
7864 + if (err)
7865 + break;
7866 +
7867 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
7868 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
7869 +
7870 + err = get_user(ldw, (unsigned int *)addr);
7871 + err |= get_user(bv, (unsigned int *)(addr+4));
7872 + err |= get_user(ldw2, (unsigned int *)(addr+8));
7873 +
7874 + if (err)
7875 + break;
7876 +
7877 + if (ldw == 0x0E801096U &&
7878 + bv == 0xEAC0C000U &&
7879 + ldw2 == 0x0E881095U)
7880 + {
7881 + unsigned int resolver, map;
7882 +
7883 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
7884 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
7885 + if (err)
7886 + break;
7887 +
7888 + regs->gr[20] = instruction_pointer(regs)+8;
7889 + regs->gr[21] = map;
7890 + regs->gr[22] = resolver;
7891 + regs->iaoq[0] = resolver | 3UL;
7892 + regs->iaoq[1] = regs->iaoq[0] + 4;
7893 + return 3;
7894 + }
7895 + }
7896 + } while (0);
7897 +#endif
7898 +
7899 +#ifdef CONFIG_PAX_EMUTRAMP
7900 +
7901 +#ifndef CONFIG_PAX_EMUSIGRT
7902 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
7903 + return 1;
7904 +#endif
7905 +
7906 + do { /* PaX: rt_sigreturn emulation */
7907 + unsigned int ldi1, ldi2, bel, nop;
7908 +
7909 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
7910 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
7911 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
7912 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
7913 +
7914 + if (err)
7915 + break;
7916 +
7917 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
7918 + ldi2 == 0x3414015AU &&
7919 + bel == 0xE4008200U &&
7920 + nop == 0x08000240U)
7921 + {
7922 + regs->gr[25] = (ldi1 & 2) >> 1;
7923 + regs->gr[20] = __NR_rt_sigreturn;
7924 + regs->gr[31] = regs->iaoq[1] + 16;
7925 + regs->sr[0] = regs->iasq[1];
7926 + regs->iaoq[0] = 0x100UL;
7927 + regs->iaoq[1] = regs->iaoq[0] + 4;
7928 + regs->iasq[0] = regs->sr[2];
7929 + regs->iasq[1] = regs->sr[2];
7930 + return 2;
7931 + }
7932 + } while (0);
7933 +#endif
7934 +
7935 + return 1;
7936 +}
7937 +
7938 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7939 +{
7940 + unsigned long i;
7941 +
7942 + printk(KERN_ERR "PAX: bytes at PC: ");
7943 + for (i = 0; i < 5; i++) {
7944 + unsigned int c;
7945 + if (get_user(c, (unsigned int *)pc+i))
7946 + printk(KERN_CONT "???????? ");
7947 + else
7948 + printk(KERN_CONT "%08x ", c);
7949 + }
7950 + printk("\n");
7951 +}
7952 +#endif
7953 +
7954 int fixup_exception(struct pt_regs *regs)
7955 {
7956 const struct exception_table_entry *fix;
7957 @@ -234,8 +345,33 @@ retry:
7958
7959 good_area:
7960
7961 - if ((vma->vm_flags & acc_type) != acc_type)
7962 + if ((vma->vm_flags & acc_type) != acc_type) {
7963 +
7964 +#ifdef CONFIG_PAX_PAGEEXEC
7965 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
7966 + (address & ~3UL) == instruction_pointer(regs))
7967 + {
7968 + up_read(&mm->mmap_sem);
7969 + switch (pax_handle_fetch_fault(regs)) {
7970 +
7971 +#ifdef CONFIG_PAX_EMUPLT
7972 + case 3:
7973 + return;
7974 +#endif
7975 +
7976 +#ifdef CONFIG_PAX_EMUTRAMP
7977 + case 2:
7978 + return;
7979 +#endif
7980 +
7981 + }
7982 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
7983 + do_group_exit(SIGKILL);
7984 + }
7985 +#endif
7986 +
7987 goto bad_area;
7988 + }
7989
7990 /*
7991 * If for any reason at all we couldn't handle the fault, make
7992 diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
7993 index e099899..457d6a8 100644
7994 --- a/arch/powerpc/Kconfig
7995 +++ b/arch/powerpc/Kconfig
7996 @@ -397,6 +397,7 @@ config PPC64_SUPPORTS_MEMORY_FAILURE
7997 config KEXEC
7998 bool "kexec system call"
7999 depends on (PPC_BOOK3S || FSL_BOOKE || (44x && !SMP))
8000 + depends on !GRKERNSEC_KMEM
8001 help
8002 kexec is a system call that implements the ability to shutdown your
8003 current kernel, and to start another kernel. It is like a reboot
8004 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
8005 index e3b1d41..8e81edf 100644
8006 --- a/arch/powerpc/include/asm/atomic.h
8007 +++ b/arch/powerpc/include/asm/atomic.h
8008 @@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
8009 return t1;
8010 }
8011
8012 +#define atomic64_read_unchecked(v) atomic64_read(v)
8013 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
8014 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
8015 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
8016 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
8017 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
8018 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
8019 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
8020 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
8021 +
8022 #endif /* __powerpc64__ */
8023
8024 #endif /* __KERNEL__ */
8025 diff --git a/arch/powerpc/include/asm/barrier.h b/arch/powerpc/include/asm/barrier.h
8026 index f89da80..7f5b05a 100644
8027 --- a/arch/powerpc/include/asm/barrier.h
8028 +++ b/arch/powerpc/include/asm/barrier.h
8029 @@ -73,7 +73,7 @@
8030 do { \
8031 compiletime_assert_atomic_type(*p); \
8032 __lwsync(); \
8033 - ACCESS_ONCE(*p) = (v); \
8034 + ACCESS_ONCE_RW(*p) = (v); \
8035 } while (0)
8036
8037 #define smp_load_acquire(p) \
8038 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
8039 index ed0afc1..0332825 100644
8040 --- a/arch/powerpc/include/asm/cache.h
8041 +++ b/arch/powerpc/include/asm/cache.h
8042 @@ -3,6 +3,7 @@
8043
8044 #ifdef __KERNEL__
8045
8046 +#include <linux/const.h>
8047
8048 /* bytes per L1 cache line */
8049 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
8050 @@ -22,7 +23,7 @@
8051 #define L1_CACHE_SHIFT 7
8052 #endif
8053
8054 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8055 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8056
8057 #define SMP_CACHE_BYTES L1_CACHE_BYTES
8058
8059 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
8060 index 935b5e7..7001d2d 100644
8061 --- a/arch/powerpc/include/asm/elf.h
8062 +++ b/arch/powerpc/include/asm/elf.h
8063 @@ -28,8 +28,19 @@
8064 the loader. We need to make sure that it is out of the way of the program
8065 that it will "exec", and that there is sufficient room for the brk. */
8066
8067 -extern unsigned long randomize_et_dyn(unsigned long base);
8068 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
8069 +#define ELF_ET_DYN_BASE (0x20000000)
8070 +
8071 +#ifdef CONFIG_PAX_ASLR
8072 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
8073 +
8074 +#ifdef __powerpc64__
8075 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
8076 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
8077 +#else
8078 +#define PAX_DELTA_MMAP_LEN 15
8079 +#define PAX_DELTA_STACK_LEN 15
8080 +#endif
8081 +#endif
8082
8083 #define ELF_CORE_EFLAGS (is_elf2_task() ? 2 : 0)
8084
8085 @@ -127,10 +138,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
8086 (0x7ff >> (PAGE_SHIFT - 12)) : \
8087 (0x3ffff >> (PAGE_SHIFT - 12)))
8088
8089 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
8090 -#define arch_randomize_brk arch_randomize_brk
8091 -
8092 -
8093 #ifdef CONFIG_SPU_BASE
8094 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
8095 #define NT_SPU 1
8096 diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
8097 index 8196e9c..d83a9f3 100644
8098 --- a/arch/powerpc/include/asm/exec.h
8099 +++ b/arch/powerpc/include/asm/exec.h
8100 @@ -4,6 +4,6 @@
8101 #ifndef _ASM_POWERPC_EXEC_H
8102 #define _ASM_POWERPC_EXEC_H
8103
8104 -extern unsigned long arch_align_stack(unsigned long sp);
8105 +#define arch_align_stack(x) ((x) & ~0xfUL)
8106
8107 #endif /* _ASM_POWERPC_EXEC_H */
8108 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
8109 index 5acabbd..7ea14fa 100644
8110 --- a/arch/powerpc/include/asm/kmap_types.h
8111 +++ b/arch/powerpc/include/asm/kmap_types.h
8112 @@ -10,7 +10,7 @@
8113 * 2 of the License, or (at your option) any later version.
8114 */
8115
8116 -#define KM_TYPE_NR 16
8117 +#define KM_TYPE_NR 17
8118
8119 #endif /* __KERNEL__ */
8120 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
8121 diff --git a/arch/powerpc/include/asm/local.h b/arch/powerpc/include/asm/local.h
8122 index b8da913..60b608a 100644
8123 --- a/arch/powerpc/include/asm/local.h
8124 +++ b/arch/powerpc/include/asm/local.h
8125 @@ -9,15 +9,26 @@ typedef struct
8126 atomic_long_t a;
8127 } local_t;
8128
8129 +typedef struct
8130 +{
8131 + atomic_long_unchecked_t a;
8132 +} local_unchecked_t;
8133 +
8134 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
8135
8136 #define local_read(l) atomic_long_read(&(l)->a)
8137 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
8138 #define local_set(l,i) atomic_long_set(&(l)->a, (i))
8139 +#define local_set_unchecked(l,i) atomic_long_set_unchecked(&(l)->a, (i))
8140
8141 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
8142 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
8143 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
8144 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
8145 #define local_inc(l) atomic_long_inc(&(l)->a)
8146 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
8147 #define local_dec(l) atomic_long_dec(&(l)->a)
8148 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
8149
8150 static __inline__ long local_add_return(long a, local_t *l)
8151 {
8152 @@ -35,6 +46,7 @@ static __inline__ long local_add_return(long a, local_t *l)
8153
8154 return t;
8155 }
8156 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
8157
8158 #define local_add_negative(a, l) (local_add_return((a), (l)) < 0)
8159
8160 @@ -54,6 +66,7 @@ static __inline__ long local_sub_return(long a, local_t *l)
8161
8162 return t;
8163 }
8164 +#define local_sub_return_unchecked(i, l) atomic_long_sub_return_unchecked((i), (&(l)->a))
8165
8166 static __inline__ long local_inc_return(local_t *l)
8167 {
8168 @@ -101,6 +114,8 @@ static __inline__ long local_dec_return(local_t *l)
8169
8170 #define local_cmpxchg(l, o, n) \
8171 (cmpxchg_local(&((l)->a.counter), (o), (n)))
8172 +#define local_cmpxchg_unchecked(l, o, n) \
8173 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
8174 #define local_xchg(l, n) (xchg_local(&((l)->a.counter), (n)))
8175
8176 /**
8177 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
8178 index 8565c25..2865190 100644
8179 --- a/arch/powerpc/include/asm/mman.h
8180 +++ b/arch/powerpc/include/asm/mman.h
8181 @@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
8182 }
8183 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
8184
8185 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
8186 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
8187 {
8188 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
8189 }
8190 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
8191 index 32e4e21..62afb12 100644
8192 --- a/arch/powerpc/include/asm/page.h
8193 +++ b/arch/powerpc/include/asm/page.h
8194 @@ -230,8 +230,9 @@ extern long long virt_phys_offset;
8195 * and needs to be executable. This means the whole heap ends
8196 * up being executable.
8197 */
8198 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8199 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8200 +#define VM_DATA_DEFAULT_FLAGS32 \
8201 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8202 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8203
8204 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8205 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8206 @@ -259,6 +260,9 @@ extern long long virt_phys_offset;
8207 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
8208 #endif
8209
8210 +#define ktla_ktva(addr) (addr)
8211 +#define ktva_ktla(addr) (addr)
8212 +
8213 #ifndef CONFIG_PPC_BOOK3S_64
8214 /*
8215 * Use the top bit of the higher-level page table entries to indicate whether
8216 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
8217 index 88693ce..ac6f9ab 100644
8218 --- a/arch/powerpc/include/asm/page_64.h
8219 +++ b/arch/powerpc/include/asm/page_64.h
8220 @@ -153,15 +153,18 @@ do { \
8221 * stack by default, so in the absence of a PT_GNU_STACK program header
8222 * we turn execute permission off.
8223 */
8224 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
8225 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8226 +#define VM_STACK_DEFAULT_FLAGS32 \
8227 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
8228 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8229
8230 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
8231 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
8232
8233 +#ifndef CONFIG_PAX_PAGEEXEC
8234 #define VM_STACK_DEFAULT_FLAGS \
8235 (is_32bit_task() ? \
8236 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
8237 +#endif
8238
8239 #include <asm-generic/getorder.h>
8240
8241 diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
8242 index 4b0be20..c15a27d 100644
8243 --- a/arch/powerpc/include/asm/pgalloc-64.h
8244 +++ b/arch/powerpc/include/asm/pgalloc-64.h
8245 @@ -54,6 +54,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
8246 #ifndef CONFIG_PPC_64K_PAGES
8247
8248 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
8249 +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
8250
8251 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
8252 {
8253 @@ -71,6 +72,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8254 pud_set(pud, (unsigned long)pmd);
8255 }
8256
8257 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
8258 +{
8259 + pud_populate(mm, pud, pmd);
8260 +}
8261 +
8262 #define pmd_populate(mm, pmd, pte_page) \
8263 pmd_populate_kernel(mm, pmd, page_address(pte_page))
8264 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
8265 @@ -173,6 +179,7 @@ extern void __tlb_remove_table(void *_table);
8266 #endif
8267
8268 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
8269 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
8270
8271 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
8272 pte_t *pte)
8273 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
8274 index 3ebb188..e17dddf 100644
8275 --- a/arch/powerpc/include/asm/pgtable.h
8276 +++ b/arch/powerpc/include/asm/pgtable.h
8277 @@ -2,6 +2,7 @@
8278 #define _ASM_POWERPC_PGTABLE_H
8279 #ifdef __KERNEL__
8280
8281 +#include <linux/const.h>
8282 #ifndef __ASSEMBLY__
8283 #include <linux/mmdebug.h>
8284 #include <asm/processor.h> /* For TASK_SIZE */
8285 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
8286 index 4aad413..85d86bf 100644
8287 --- a/arch/powerpc/include/asm/pte-hash32.h
8288 +++ b/arch/powerpc/include/asm/pte-hash32.h
8289 @@ -21,6 +21,7 @@
8290 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
8291 #define _PAGE_USER 0x004 /* usermode access allowed */
8292 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
8293 +#define _PAGE_EXEC _PAGE_GUARDED
8294 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
8295 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
8296 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
8297 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
8298 index e5d2e0b..9ac74b1 100644
8299 --- a/arch/powerpc/include/asm/reg.h
8300 +++ b/arch/powerpc/include/asm/reg.h
8301 @@ -249,6 +249,7 @@
8302 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
8303 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
8304 #define DSISR_NOHPTE 0x40000000 /* no translation found */
8305 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
8306 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
8307 #define DSISR_ISSTORE 0x02000000 /* access was a store */
8308 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
8309 diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
8310 index ff51046..b982dd4 100644
8311 --- a/arch/powerpc/include/asm/smp.h
8312 +++ b/arch/powerpc/include/asm/smp.h
8313 @@ -51,7 +51,7 @@ struct smp_ops_t {
8314 int (*cpu_disable)(void);
8315 void (*cpu_die)(unsigned int nr);
8316 int (*cpu_bootable)(unsigned int nr);
8317 -};
8318 +} __no_const;
8319
8320 extern void smp_send_debugger_break(void);
8321 extern void start_secondary_resume(void);
8322 diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
8323 index b034ecd..af7e31f 100644
8324 --- a/arch/powerpc/include/asm/thread_info.h
8325 +++ b/arch/powerpc/include/asm/thread_info.h
8326 @@ -107,6 +107,8 @@ static inline struct thread_info *current_thread_info(void)
8327 #if defined(CONFIG_PPC64)
8328 #define TIF_ELF2ABI 18 /* function descriptors must die! */
8329 #endif
8330 +/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
8331 +#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
8332
8333 /* as above, but as bit values */
8334 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
8335 @@ -125,9 +127,10 @@ static inline struct thread_info *current_thread_info(void)
8336 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
8337 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
8338 #define _TIF_NOHZ (1<<TIF_NOHZ)
8339 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
8340 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
8341 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
8342 - _TIF_NOHZ)
8343 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
8344
8345 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
8346 _TIF_NOTIFY_RESUME | _TIF_UPROBE | \
8347 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
8348 index 9485b43..3bd3c16 100644
8349 --- a/arch/powerpc/include/asm/uaccess.h
8350 +++ b/arch/powerpc/include/asm/uaccess.h
8351 @@ -58,6 +58,7 @@
8352
8353 #endif
8354
8355 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
8356 #define access_ok(type, addr, size) \
8357 (__chk_user_ptr(addr), \
8358 __access_ok((__force unsigned long)(addr), (size), get_fs()))
8359 @@ -318,52 +319,6 @@ do { \
8360 extern unsigned long __copy_tofrom_user(void __user *to,
8361 const void __user *from, unsigned long size);
8362
8363 -#ifndef __powerpc64__
8364 -
8365 -static inline unsigned long copy_from_user(void *to,
8366 - const void __user *from, unsigned long n)
8367 -{
8368 - unsigned long over;
8369 -
8370 - if (access_ok(VERIFY_READ, from, n))
8371 - return __copy_tofrom_user((__force void __user *)to, from, n);
8372 - if ((unsigned long)from < TASK_SIZE) {
8373 - over = (unsigned long)from + n - TASK_SIZE;
8374 - return __copy_tofrom_user((__force void __user *)to, from,
8375 - n - over) + over;
8376 - }
8377 - return n;
8378 -}
8379 -
8380 -static inline unsigned long copy_to_user(void __user *to,
8381 - const void *from, unsigned long n)
8382 -{
8383 - unsigned long over;
8384 -
8385 - if (access_ok(VERIFY_WRITE, to, n))
8386 - return __copy_tofrom_user(to, (__force void __user *)from, n);
8387 - if ((unsigned long)to < TASK_SIZE) {
8388 - over = (unsigned long)to + n - TASK_SIZE;
8389 - return __copy_tofrom_user(to, (__force void __user *)from,
8390 - n - over) + over;
8391 - }
8392 - return n;
8393 -}
8394 -
8395 -#else /* __powerpc64__ */
8396 -
8397 -#define __copy_in_user(to, from, size) \
8398 - __copy_tofrom_user((to), (from), (size))
8399 -
8400 -extern unsigned long copy_from_user(void *to, const void __user *from,
8401 - unsigned long n);
8402 -extern unsigned long copy_to_user(void __user *to, const void *from,
8403 - unsigned long n);
8404 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
8405 - unsigned long n);
8406 -
8407 -#endif /* __powerpc64__ */
8408 -
8409 static inline unsigned long __copy_from_user_inatomic(void *to,
8410 const void __user *from, unsigned long n)
8411 {
8412 @@ -387,6 +342,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
8413 if (ret == 0)
8414 return 0;
8415 }
8416 +
8417 + if (!__builtin_constant_p(n))
8418 + check_object_size(to, n, false);
8419 +
8420 return __copy_tofrom_user((__force void __user *)to, from, n);
8421 }
8422
8423 @@ -413,6 +372,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
8424 if (ret == 0)
8425 return 0;
8426 }
8427 +
8428 + if (!__builtin_constant_p(n))
8429 + check_object_size(from, n, true);
8430 +
8431 return __copy_tofrom_user(to, (__force const void __user *)from, n);
8432 }
8433
8434 @@ -430,6 +393,92 @@ static inline unsigned long __copy_to_user(void __user *to,
8435 return __copy_to_user_inatomic(to, from, size);
8436 }
8437
8438 +#ifndef __powerpc64__
8439 +
8440 +static inline unsigned long __must_check copy_from_user(void *to,
8441 + const void __user *from, unsigned long n)
8442 +{
8443 + unsigned long over;
8444 +
8445 + if ((long)n < 0)
8446 + return n;
8447 +
8448 + if (access_ok(VERIFY_READ, from, n)) {
8449 + if (!__builtin_constant_p(n))
8450 + check_object_size(to, n, false);
8451 + return __copy_tofrom_user((__force void __user *)to, from, n);
8452 + }
8453 + if ((unsigned long)from < TASK_SIZE) {
8454 + over = (unsigned long)from + n - TASK_SIZE;
8455 + if (!__builtin_constant_p(n - over))
8456 + check_object_size(to, n - over, false);
8457 + return __copy_tofrom_user((__force void __user *)to, from,
8458 + n - over) + over;
8459 + }
8460 + return n;
8461 +}
8462 +
8463 +static inline unsigned long __must_check copy_to_user(void __user *to,
8464 + const void *from, unsigned long n)
8465 +{
8466 + unsigned long over;
8467 +
8468 + if ((long)n < 0)
8469 + return n;
8470 +
8471 + if (access_ok(VERIFY_WRITE, to, n)) {
8472 + if (!__builtin_constant_p(n))
8473 + check_object_size(from, n, true);
8474 + return __copy_tofrom_user(to, (__force void __user *)from, n);
8475 + }
8476 + if ((unsigned long)to < TASK_SIZE) {
8477 + over = (unsigned long)to + n - TASK_SIZE;
8478 + if (!__builtin_constant_p(n))
8479 + check_object_size(from, n - over, true);
8480 + return __copy_tofrom_user(to, (__force void __user *)from,
8481 + n - over) + over;
8482 + }
8483 + return n;
8484 +}
8485 +
8486 +#else /* __powerpc64__ */
8487 +
8488 +#define __copy_in_user(to, from, size) \
8489 + __copy_tofrom_user((to), (from), (size))
8490 +
8491 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
8492 +{
8493 + if ((long)n < 0 || n > INT_MAX)
8494 + return n;
8495 +
8496 + if (!__builtin_constant_p(n))
8497 + check_object_size(to, n, false);
8498 +
8499 + if (likely(access_ok(VERIFY_READ, from, n)))
8500 + n = __copy_from_user(to, from, n);
8501 + else
8502 + memset(to, 0, n);
8503 + return n;
8504 +}
8505 +
8506 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
8507 +{
8508 + if ((long)n < 0 || n > INT_MAX)
8509 + return n;
8510 +
8511 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
8512 + if (!__builtin_constant_p(n))
8513 + check_object_size(from, n, true);
8514 + n = __copy_to_user(to, from, n);
8515 + }
8516 + return n;
8517 +}
8518 +
8519 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
8520 + unsigned long n);
8521 +
8522 +#endif /* __powerpc64__ */
8523 +
8524 extern unsigned long __clear_user(void __user *addr, unsigned long size);
8525
8526 static inline unsigned long clear_user(void __user *addr, unsigned long size)
8527 diff --git a/arch/powerpc/kernel/Makefile b/arch/powerpc/kernel/Makefile
8528 index fcc9a89..07be2bb 100644
8529 --- a/arch/powerpc/kernel/Makefile
8530 +++ b/arch/powerpc/kernel/Makefile
8531 @@ -26,6 +26,8 @@ CFLAGS_REMOVE_ftrace.o = -pg -mno-sched-epilog
8532 CFLAGS_REMOVE_time.o = -pg -mno-sched-epilog
8533 endif
8534
8535 +CFLAGS_REMOVE_prom_init.o += $(LATENT_ENTROPY_PLUGIN_CFLAGS)
8536 +
8537 obj-y := cputable.o ptrace.o syscalls.o \
8538 irq.o align.o signal_32.o pmc.o vdso.o \
8539 process.o systbl.o idle.o \
8540 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
8541 index c1bee3c..5b42583 100644
8542 --- a/arch/powerpc/kernel/exceptions-64e.S
8543 +++ b/arch/powerpc/kernel/exceptions-64e.S
8544 @@ -1010,6 +1010,7 @@ storage_fault_common:
8545 std r14,_DAR(r1)
8546 std r15,_DSISR(r1)
8547 addi r3,r1,STACK_FRAME_OVERHEAD
8548 + bl .save_nvgprs
8549 mr r4,r14
8550 mr r5,r15
8551 ld r14,PACA_EXGEN+EX_R14(r13)
8552 @@ -1018,8 +1019,7 @@ storage_fault_common:
8553 cmpdi r3,0
8554 bne- 1f
8555 b .ret_from_except_lite
8556 -1: bl .save_nvgprs
8557 - mr r5,r3
8558 +1: mr r5,r3
8559 addi r3,r1,STACK_FRAME_OVERHEAD
8560 ld r4,_DAR(r1)
8561 bl .bad_page_fault
8562 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
8563 index 3afd391..18f9e36 100644
8564 --- a/arch/powerpc/kernel/exceptions-64s.S
8565 +++ b/arch/powerpc/kernel/exceptions-64s.S
8566 @@ -1587,10 +1587,10 @@ handle_page_fault:
8567 11: ld r4,_DAR(r1)
8568 ld r5,_DSISR(r1)
8569 addi r3,r1,STACK_FRAME_OVERHEAD
8570 + bl .save_nvgprs
8571 bl .do_page_fault
8572 cmpdi r3,0
8573 beq+ 12f
8574 - bl .save_nvgprs
8575 mr r5,r3
8576 addi r3,r1,STACK_FRAME_OVERHEAD
8577 lwz r4,_DAR(r1)
8578 diff --git a/arch/powerpc/kernel/irq.c b/arch/powerpc/kernel/irq.c
8579 index ca1cd74..6f0241a 100644
8580 --- a/arch/powerpc/kernel/irq.c
8581 +++ b/arch/powerpc/kernel/irq.c
8582 @@ -447,6 +447,8 @@ void migrate_irqs(void)
8583 }
8584 #endif
8585
8586 +extern void gr_handle_kernel_exploit(void);
8587 +
8588 static inline void check_stack_overflow(void)
8589 {
8590 #ifdef CONFIG_DEBUG_STACKOVERFLOW
8591 @@ -459,6 +461,7 @@ static inline void check_stack_overflow(void)
8592 printk("do_IRQ: stack overflow: %ld\n",
8593 sp - sizeof(struct thread_info));
8594 dump_stack();
8595 + gr_handle_kernel_exploit();
8596 }
8597 #endif
8598 }
8599 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
8600 index 6cff040..74ac5d1 100644
8601 --- a/arch/powerpc/kernel/module_32.c
8602 +++ b/arch/powerpc/kernel/module_32.c
8603 @@ -161,7 +161,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
8604 me->arch.core_plt_section = i;
8605 }
8606 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
8607 - printk("Module doesn't contain .plt or .init.plt sections.\n");
8608 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
8609 return -ENOEXEC;
8610 }
8611
8612 @@ -191,11 +191,16 @@ static uint32_t do_plt_call(void *location,
8613
8614 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
8615 /* Init, or core PLT? */
8616 - if (location >= mod->module_core
8617 - && location < mod->module_core + mod->core_size)
8618 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
8619 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
8620 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
8621 - else
8622 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
8623 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
8624 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
8625 + else {
8626 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
8627 + return ~0UL;
8628 + }
8629
8630 /* Find this entry, or if that fails, the next avail. entry */
8631 while (entry->jump[0]) {
8632 @@ -299,7 +304,7 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
8633 }
8634 #ifdef CONFIG_DYNAMIC_FTRACE
8635 module->arch.tramp =
8636 - do_plt_call(module->module_core,
8637 + do_plt_call(module->module_core_rx,
8638 (unsigned long)ftrace_caller,
8639 sechdrs, module);
8640 #endif
8641 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
8642 index 31d0215..206af70 100644
8643 --- a/arch/powerpc/kernel/process.c
8644 +++ b/arch/powerpc/kernel/process.c
8645 @@ -1031,8 +1031,8 @@ void show_regs(struct pt_regs * regs)
8646 * Lookup NIP late so we have the best change of getting the
8647 * above info out without failing
8648 */
8649 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
8650 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
8651 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
8652 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
8653 #endif
8654 show_stack(current, (unsigned long *) regs->gpr[1]);
8655 if (!user_mode(regs))
8656 @@ -1554,10 +1554,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8657 newsp = stack[0];
8658 ip = stack[STACK_FRAME_LR_SAVE];
8659 if (!firstframe || ip != lr) {
8660 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
8661 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
8662 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8663 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
8664 - printk(" (%pS)",
8665 + printk(" (%pA)",
8666 (void *)current->ret_stack[curr_frame].ret);
8667 curr_frame--;
8668 }
8669 @@ -1577,7 +1577,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8670 struct pt_regs *regs = (struct pt_regs *)
8671 (sp + STACK_FRAME_OVERHEAD);
8672 lr = regs->link;
8673 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
8674 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
8675 regs->trap, (void *)regs->nip, (void *)lr);
8676 firstframe = 1;
8677 }
8678 @@ -1613,58 +1613,3 @@ void notrace __ppc64_runlatch_off(void)
8679 mtspr(SPRN_CTRLT, ctrl);
8680 }
8681 #endif /* CONFIG_PPC64 */
8682 -
8683 -unsigned long arch_align_stack(unsigned long sp)
8684 -{
8685 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8686 - sp -= get_random_int() & ~PAGE_MASK;
8687 - return sp & ~0xf;
8688 -}
8689 -
8690 -static inline unsigned long brk_rnd(void)
8691 -{
8692 - unsigned long rnd = 0;
8693 -
8694 - /* 8MB for 32bit, 1GB for 64bit */
8695 - if (is_32bit_task())
8696 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
8697 - else
8698 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
8699 -
8700 - return rnd << PAGE_SHIFT;
8701 -}
8702 -
8703 -unsigned long arch_randomize_brk(struct mm_struct *mm)
8704 -{
8705 - unsigned long base = mm->brk;
8706 - unsigned long ret;
8707 -
8708 -#ifdef CONFIG_PPC_STD_MMU_64
8709 - /*
8710 - * If we are using 1TB segments and we are allowed to randomise
8711 - * the heap, we can put it above 1TB so it is backed by a 1TB
8712 - * segment. Otherwise the heap will be in the bottom 1TB
8713 - * which always uses 256MB segments and this may result in a
8714 - * performance penalty.
8715 - */
8716 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
8717 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
8718 -#endif
8719 -
8720 - ret = PAGE_ALIGN(base + brk_rnd());
8721 -
8722 - if (ret < mm->brk)
8723 - return mm->brk;
8724 -
8725 - return ret;
8726 -}
8727 -
8728 -unsigned long randomize_et_dyn(unsigned long base)
8729 -{
8730 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8731 -
8732 - if (ret < base)
8733 - return base;
8734 -
8735 - return ret;
8736 -}
8737 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
8738 index 2e3d2bf..35df241 100644
8739 --- a/arch/powerpc/kernel/ptrace.c
8740 +++ b/arch/powerpc/kernel/ptrace.c
8741 @@ -1762,6 +1762,10 @@ long arch_ptrace(struct task_struct *child, long request,
8742 return ret;
8743 }
8744
8745 +#ifdef CONFIG_GRKERNSEC_SETXID
8746 +extern void gr_delayed_cred_worker(void);
8747 +#endif
8748 +
8749 /*
8750 * We must return the syscall number to actually look up in the table.
8751 * This can be -1L to skip running any syscall at all.
8752 @@ -1774,6 +1778,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
8753
8754 secure_computing_strict(regs->gpr[0]);
8755
8756 +#ifdef CONFIG_GRKERNSEC_SETXID
8757 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8758 + gr_delayed_cred_worker();
8759 +#endif
8760 +
8761 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
8762 tracehook_report_syscall_entry(regs))
8763 /*
8764 @@ -1808,6 +1817,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
8765 {
8766 int step;
8767
8768 +#ifdef CONFIG_GRKERNSEC_SETXID
8769 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8770 + gr_delayed_cred_worker();
8771 +#endif
8772 +
8773 audit_syscall_exit(regs);
8774
8775 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8776 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
8777 index 4e47db6..6dcc96e 100644
8778 --- a/arch/powerpc/kernel/signal_32.c
8779 +++ b/arch/powerpc/kernel/signal_32.c
8780 @@ -1013,7 +1013,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
8781 /* Save user registers on the stack */
8782 frame = &rt_sf->uc.uc_mcontext;
8783 addr = frame;
8784 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
8785 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8786 sigret = 0;
8787 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
8788 } else {
8789 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
8790 index d501dc4..e5a0de0 100644
8791 --- a/arch/powerpc/kernel/signal_64.c
8792 +++ b/arch/powerpc/kernel/signal_64.c
8793 @@ -760,7 +760,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
8794 current->thread.fp_state.fpscr = 0;
8795
8796 /* Set up to return from userspace. */
8797 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
8798 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8799 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
8800 } else {
8801 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
8802 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
8803 index 1bd7ca2..9b78c2f 100644
8804 --- a/arch/powerpc/kernel/traps.c
8805 +++ b/arch/powerpc/kernel/traps.c
8806 @@ -142,6 +142,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
8807 return flags;
8808 }
8809
8810 +extern void gr_handle_kernel_exploit(void);
8811 +
8812 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8813 int signr)
8814 {
8815 @@ -191,6 +193,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8816 panic("Fatal exception in interrupt");
8817 if (panic_on_oops)
8818 panic("Fatal exception");
8819 +
8820 + gr_handle_kernel_exploit();
8821 +
8822 do_exit(signr);
8823 }
8824
8825 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
8826 index ce74c33..0803371 100644
8827 --- a/arch/powerpc/kernel/vdso.c
8828 +++ b/arch/powerpc/kernel/vdso.c
8829 @@ -35,6 +35,7 @@
8830 #include <asm/vdso.h>
8831 #include <asm/vdso_datapage.h>
8832 #include <asm/setup.h>
8833 +#include <asm/mman.h>
8834
8835 #undef DEBUG
8836
8837 @@ -221,7 +222,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8838 vdso_base = VDSO32_MBASE;
8839 #endif
8840
8841 - current->mm->context.vdso_base = 0;
8842 + current->mm->context.vdso_base = ~0UL;
8843
8844 /* vDSO has a problem and was disabled, just don't "enable" it for the
8845 * process
8846 @@ -241,7 +242,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8847 vdso_base = get_unmapped_area(NULL, vdso_base,
8848 (vdso_pages << PAGE_SHIFT) +
8849 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
8850 - 0, 0);
8851 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
8852 if (IS_ERR_VALUE(vdso_base)) {
8853 rc = vdso_base;
8854 goto fail_mmapsem;
8855 diff --git a/arch/powerpc/kvm/powerpc.c b/arch/powerpc/kvm/powerpc.c
8856 index 3cf541a..ab2d825 100644
8857 --- a/arch/powerpc/kvm/powerpc.c
8858 +++ b/arch/powerpc/kvm/powerpc.c
8859 @@ -1153,7 +1153,7 @@ void kvmppc_init_lpid(unsigned long nr_lpids_param)
8860 }
8861 EXPORT_SYMBOL_GPL(kvmppc_init_lpid);
8862
8863 -int kvm_arch_init(void *opaque)
8864 +int kvm_arch_init(const void *opaque)
8865 {
8866 return 0;
8867 }
8868 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
8869 index 5eea6f3..5d10396 100644
8870 --- a/arch/powerpc/lib/usercopy_64.c
8871 +++ b/arch/powerpc/lib/usercopy_64.c
8872 @@ -9,22 +9,6 @@
8873 #include <linux/module.h>
8874 #include <asm/uaccess.h>
8875
8876 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
8877 -{
8878 - if (likely(access_ok(VERIFY_READ, from, n)))
8879 - n = __copy_from_user(to, from, n);
8880 - else
8881 - memset(to, 0, n);
8882 - return n;
8883 -}
8884 -
8885 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
8886 -{
8887 - if (likely(access_ok(VERIFY_WRITE, to, n)))
8888 - n = __copy_to_user(to, from, n);
8889 - return n;
8890 -}
8891 -
8892 unsigned long copy_in_user(void __user *to, const void __user *from,
8893 unsigned long n)
8894 {
8895 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
8896 return n;
8897 }
8898
8899 -EXPORT_SYMBOL(copy_from_user);
8900 -EXPORT_SYMBOL(copy_to_user);
8901 EXPORT_SYMBOL(copy_in_user);
8902
8903 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
8904 index 51ab9e7..7d3c78b 100644
8905 --- a/arch/powerpc/mm/fault.c
8906 +++ b/arch/powerpc/mm/fault.c
8907 @@ -33,6 +33,10 @@
8908 #include <linux/magic.h>
8909 #include <linux/ratelimit.h>
8910 #include <linux/context_tracking.h>
8911 +#include <linux/slab.h>
8912 +#include <linux/pagemap.h>
8913 +#include <linux/compiler.h>
8914 +#include <linux/unistd.h>
8915
8916 #include <asm/firmware.h>
8917 #include <asm/page.h>
8918 @@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
8919 }
8920 #endif
8921
8922 +#ifdef CONFIG_PAX_PAGEEXEC
8923 +/*
8924 + * PaX: decide what to do with offenders (regs->nip = fault address)
8925 + *
8926 + * returns 1 when task should be killed
8927 + */
8928 +static int pax_handle_fetch_fault(struct pt_regs *regs)
8929 +{
8930 + return 1;
8931 +}
8932 +
8933 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8934 +{
8935 + unsigned long i;
8936 +
8937 + printk(KERN_ERR "PAX: bytes at PC: ");
8938 + for (i = 0; i < 5; i++) {
8939 + unsigned int c;
8940 + if (get_user(c, (unsigned int __user *)pc+i))
8941 + printk(KERN_CONT "???????? ");
8942 + else
8943 + printk(KERN_CONT "%08x ", c);
8944 + }
8945 + printk("\n");
8946 +}
8947 +#endif
8948 +
8949 /*
8950 * Check whether the instruction at regs->nip is a store using
8951 * an update addressing form which will update r1.
8952 @@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
8953 * indicate errors in DSISR but can validly be set in SRR1.
8954 */
8955 if (trap == 0x400)
8956 - error_code &= 0x48200000;
8957 + error_code &= 0x58200000;
8958 else
8959 is_write = error_code & DSISR_ISSTORE;
8960 #else
8961 @@ -378,7 +409,7 @@ good_area:
8962 * "undefined". Of those that can be set, this is the only
8963 * one which seems bad.
8964 */
8965 - if (error_code & 0x10000000)
8966 + if (error_code & DSISR_GUARDED)
8967 /* Guarded storage error. */
8968 goto bad_area;
8969 #endif /* CONFIG_8xx */
8970 @@ -393,7 +424,7 @@ good_area:
8971 * processors use the same I/D cache coherency mechanism
8972 * as embedded.
8973 */
8974 - if (error_code & DSISR_PROTFAULT)
8975 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
8976 goto bad_area;
8977 #endif /* CONFIG_PPC_STD_MMU */
8978
8979 @@ -483,6 +514,23 @@ bad_area:
8980 bad_area_nosemaphore:
8981 /* User mode accesses cause a SIGSEGV */
8982 if (user_mode(regs)) {
8983 +
8984 +#ifdef CONFIG_PAX_PAGEEXEC
8985 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
8986 +#ifdef CONFIG_PPC_STD_MMU
8987 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
8988 +#else
8989 + if (is_exec && regs->nip == address) {
8990 +#endif
8991 + switch (pax_handle_fetch_fault(regs)) {
8992 + }
8993 +
8994 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
8995 + do_group_exit(SIGKILL);
8996 + }
8997 + }
8998 +#endif
8999 +
9000 _exception(SIGSEGV, regs, code, address);
9001 goto bail;
9002 }
9003 diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
9004 index cb8bdbe..cde4bc7 100644
9005 --- a/arch/powerpc/mm/mmap.c
9006 +++ b/arch/powerpc/mm/mmap.c
9007 @@ -53,10 +53,14 @@ static inline int mmap_is_legacy(void)
9008 return sysctl_legacy_va_layout;
9009 }
9010
9011 -static unsigned long mmap_rnd(void)
9012 +static unsigned long mmap_rnd(struct mm_struct *mm)
9013 {
9014 unsigned long rnd = 0;
9015
9016 +#ifdef CONFIG_PAX_RANDMMAP
9017 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9018 +#endif
9019 +
9020 if (current->flags & PF_RANDOMIZE) {
9021 /* 8MB for 32bit, 1GB for 64bit */
9022 if (is_32bit_task())
9023 @@ -67,7 +71,7 @@ static unsigned long mmap_rnd(void)
9024 return rnd << PAGE_SHIFT;
9025 }
9026
9027 -static inline unsigned long mmap_base(void)
9028 +static inline unsigned long mmap_base(struct mm_struct *mm)
9029 {
9030 unsigned long gap = rlimit(RLIMIT_STACK);
9031
9032 @@ -76,7 +80,7 @@ static inline unsigned long mmap_base(void)
9033 else if (gap > MAX_GAP)
9034 gap = MAX_GAP;
9035
9036 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
9037 + return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd(mm));
9038 }
9039
9040 /*
9041 @@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9042 */
9043 if (mmap_is_legacy()) {
9044 mm->mmap_base = TASK_UNMAPPED_BASE;
9045 +
9046 +#ifdef CONFIG_PAX_RANDMMAP
9047 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9048 + mm->mmap_base += mm->delta_mmap;
9049 +#endif
9050 +
9051 mm->get_unmapped_area = arch_get_unmapped_area;
9052 } else {
9053 - mm->mmap_base = mmap_base();
9054 + mm->mmap_base = mmap_base(mm);
9055 +
9056 +#ifdef CONFIG_PAX_RANDMMAP
9057 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9058 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9059 +#endif
9060 +
9061 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9062 }
9063 }
9064 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
9065 index b0c75cc..ef7fb93 100644
9066 --- a/arch/powerpc/mm/slice.c
9067 +++ b/arch/powerpc/mm/slice.c
9068 @@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
9069 if ((mm->task_size - len) < addr)
9070 return 0;
9071 vma = find_vma(mm, addr);
9072 - return (!vma || (addr + len) <= vma->vm_start);
9073 + return check_heap_stack_gap(vma, addr, len, 0);
9074 }
9075
9076 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
9077 @@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
9078 info.align_offset = 0;
9079
9080 addr = TASK_UNMAPPED_BASE;
9081 +
9082 +#ifdef CONFIG_PAX_RANDMMAP
9083 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9084 + addr += mm->delta_mmap;
9085 +#endif
9086 +
9087 while (addr < TASK_SIZE) {
9088 info.low_limit = addr;
9089 if (!slice_scan_available(addr, available, 1, &addr))
9090 @@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
9091 if (fixed && addr > (mm->task_size - len))
9092 return -ENOMEM;
9093
9094 +#ifdef CONFIG_PAX_RANDMMAP
9095 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
9096 + addr = 0;
9097 +#endif
9098 +
9099 /* If hint, make sure it matches our alignment restrictions */
9100 if (!fixed && addr) {
9101 addr = _ALIGN_UP(addr, 1ul << pshift);
9102 diff --git a/arch/powerpc/platforms/cell/celleb_scc_pciex.c b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9103 index 4278acf..67fd0e6 100644
9104 --- a/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9105 +++ b/arch/powerpc/platforms/cell/celleb_scc_pciex.c
9106 @@ -400,8 +400,8 @@ static int scc_pciex_write_config(struct pci_bus *bus, unsigned int devfn,
9107 }
9108
9109 static struct pci_ops scc_pciex_pci_ops = {
9110 - scc_pciex_read_config,
9111 - scc_pciex_write_config,
9112 + .read = scc_pciex_read_config,
9113 + .write = scc_pciex_write_config,
9114 };
9115
9116 static void pciex_clear_intr_all(unsigned int __iomem *base)
9117 diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
9118 index 9098692..3d54cd1 100644
9119 --- a/arch/powerpc/platforms/cell/spufs/file.c
9120 +++ b/arch/powerpc/platforms/cell/spufs/file.c
9121 @@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
9122 return VM_FAULT_NOPAGE;
9123 }
9124
9125 -static int spufs_mem_mmap_access(struct vm_area_struct *vma,
9126 +static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
9127 unsigned long address,
9128 - void *buf, int len, int write)
9129 + void *buf, size_t len, int write)
9130 {
9131 struct spu_context *ctx = vma->vm_file->private_data;
9132 unsigned long offset = address - vma->vm_start;
9133 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
9134 index 1d47061..0714963 100644
9135 --- a/arch/s390/include/asm/atomic.h
9136 +++ b/arch/s390/include/asm/atomic.h
9137 @@ -412,6 +412,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
9138 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
9139 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9140
9141 +#define atomic64_read_unchecked(v) atomic64_read(v)
9142 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
9143 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
9144 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
9145 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
9146 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
9147 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
9148 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
9149 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
9150 +
9151 #define smp_mb__before_atomic_dec() smp_mb()
9152 #define smp_mb__after_atomic_dec() smp_mb()
9153 #define smp_mb__before_atomic_inc() smp_mb()
9154 diff --git a/arch/s390/include/asm/barrier.h b/arch/s390/include/asm/barrier.h
9155 index 578680f..0eb3b11 100644
9156 --- a/arch/s390/include/asm/barrier.h
9157 +++ b/arch/s390/include/asm/barrier.h
9158 @@ -36,7 +36,7 @@
9159 do { \
9160 compiletime_assert_atomic_type(*p); \
9161 barrier(); \
9162 - ACCESS_ONCE(*p) = (v); \
9163 + ACCESS_ONCE_RW(*p) = (v); \
9164 } while (0)
9165
9166 #define smp_load_acquire(p) \
9167 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
9168 index 4d7ccac..d03d0ad 100644
9169 --- a/arch/s390/include/asm/cache.h
9170 +++ b/arch/s390/include/asm/cache.h
9171 @@ -9,8 +9,10 @@
9172 #ifndef __ARCH_S390_CACHE_H
9173 #define __ARCH_S390_CACHE_H
9174
9175 -#define L1_CACHE_BYTES 256
9176 +#include <linux/const.h>
9177 +
9178 #define L1_CACHE_SHIFT 8
9179 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9180 #define NET_SKB_PAD 32
9181
9182 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9183 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
9184 index 78f4f87..598ce39 100644
9185 --- a/arch/s390/include/asm/elf.h
9186 +++ b/arch/s390/include/asm/elf.h
9187 @@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
9188 the loader. We need to make sure that it is out of the way of the program
9189 that it will "exec", and that there is sufficient room for the brk. */
9190
9191 -extern unsigned long randomize_et_dyn(unsigned long base);
9192 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
9193 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
9194 +
9195 +#ifdef CONFIG_PAX_ASLR
9196 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
9197 +
9198 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9199 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
9200 +#endif
9201
9202 /* This yields a mask that user programs can use to figure out what
9203 instruction set this CPU supports. */
9204 @@ -222,9 +228,6 @@ struct linux_binprm;
9205 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
9206 int arch_setup_additional_pages(struct linux_binprm *, int);
9207
9208 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
9209 -#define arch_randomize_brk arch_randomize_brk
9210 -
9211 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
9212
9213 #endif
9214 diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
9215 index c4a93d6..4d2a9b4 100644
9216 --- a/arch/s390/include/asm/exec.h
9217 +++ b/arch/s390/include/asm/exec.h
9218 @@ -7,6 +7,6 @@
9219 #ifndef __ASM_EXEC_H
9220 #define __ASM_EXEC_H
9221
9222 -extern unsigned long arch_align_stack(unsigned long sp);
9223 +#define arch_align_stack(x) ((x) & ~0xfUL)
9224
9225 #endif /* __ASM_EXEC_H */
9226 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
9227 index 1be64a1..086839d1 100644
9228 --- a/arch/s390/include/asm/uaccess.h
9229 +++ b/arch/s390/include/asm/uaccess.h
9230 @@ -59,6 +59,7 @@ static inline int __range_ok(unsigned long addr, unsigned long size)
9231 __range_ok((unsigned long)(addr), (size)); \
9232 })
9233
9234 +#define access_ok_noprefault(type, addr, size) access_ok((type), (addr), (size))
9235 #define access_ok(type, addr, size) __access_ok(addr, size)
9236
9237 /*
9238 @@ -245,6 +246,10 @@ static inline unsigned long __must_check
9239 copy_to_user(void __user *to, const void *from, unsigned long n)
9240 {
9241 might_fault();
9242 +
9243 + if ((long)n < 0)
9244 + return n;
9245 +
9246 return __copy_to_user(to, from, n);
9247 }
9248
9249 @@ -273,10 +278,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
9250 static inline unsigned long __must_check
9251 copy_from_user(void *to, const void __user *from, unsigned long n)
9252 {
9253 - unsigned int sz = __compiletime_object_size(to);
9254 + size_t sz = __compiletime_object_size(to);
9255
9256 might_fault();
9257 - if (unlikely(sz != -1 && sz < n)) {
9258 +
9259 + if ((long)n < 0)
9260 + return n;
9261 +
9262 + if (unlikely(sz != (size_t)-1 && sz < n)) {
9263 copy_from_user_overflow();
9264 return n;
9265 }
9266 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
9267 index b89b591..fd9609d 100644
9268 --- a/arch/s390/kernel/module.c
9269 +++ b/arch/s390/kernel/module.c
9270 @@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
9271
9272 /* Increase core size by size of got & plt and set start
9273 offsets for got and plt. */
9274 - me->core_size = ALIGN(me->core_size, 4);
9275 - me->arch.got_offset = me->core_size;
9276 - me->core_size += me->arch.got_size;
9277 - me->arch.plt_offset = me->core_size;
9278 - me->core_size += me->arch.plt_size;
9279 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
9280 + me->arch.got_offset = me->core_size_rw;
9281 + me->core_size_rw += me->arch.got_size;
9282 + me->arch.plt_offset = me->core_size_rx;
9283 + me->core_size_rx += me->arch.plt_size;
9284 return 0;
9285 }
9286
9287 @@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9288 if (info->got_initialized == 0) {
9289 Elf_Addr *gotent;
9290
9291 - gotent = me->module_core + me->arch.got_offset +
9292 + gotent = me->module_core_rw + me->arch.got_offset +
9293 info->got_offset;
9294 *gotent = val;
9295 info->got_initialized = 1;
9296 @@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9297 rc = apply_rela_bits(loc, val, 0, 64, 0);
9298 else if (r_type == R_390_GOTENT ||
9299 r_type == R_390_GOTPLTENT) {
9300 - val += (Elf_Addr) me->module_core - loc;
9301 + val += (Elf_Addr) me->module_core_rw - loc;
9302 rc = apply_rela_bits(loc, val, 1, 32, 1);
9303 }
9304 break;
9305 @@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9306 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
9307 if (info->plt_initialized == 0) {
9308 unsigned int *ip;
9309 - ip = me->module_core + me->arch.plt_offset +
9310 + ip = me->module_core_rx + me->arch.plt_offset +
9311 info->plt_offset;
9312 #ifndef CONFIG_64BIT
9313 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
9314 @@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9315 val - loc + 0xffffUL < 0x1ffffeUL) ||
9316 (r_type == R_390_PLT32DBL &&
9317 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
9318 - val = (Elf_Addr) me->module_core +
9319 + val = (Elf_Addr) me->module_core_rx +
9320 me->arch.plt_offset +
9321 info->plt_offset;
9322 val += rela->r_addend - loc;
9323 @@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9324 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
9325 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
9326 val = val + rela->r_addend -
9327 - ((Elf_Addr) me->module_core + me->arch.got_offset);
9328 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
9329 if (r_type == R_390_GOTOFF16)
9330 rc = apply_rela_bits(loc, val, 0, 16, 0);
9331 else if (r_type == R_390_GOTOFF32)
9332 @@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
9333 break;
9334 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
9335 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
9336 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
9337 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
9338 rela->r_addend - loc;
9339 if (r_type == R_390_GOTPC)
9340 rc = apply_rela_bits(loc, val, 1, 32, 0);
9341 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
9342 index dd14532..1dfc145 100644
9343 --- a/arch/s390/kernel/process.c
9344 +++ b/arch/s390/kernel/process.c
9345 @@ -242,37 +242,3 @@ unsigned long get_wchan(struct task_struct *p)
9346 }
9347 return 0;
9348 }
9349 -
9350 -unsigned long arch_align_stack(unsigned long sp)
9351 -{
9352 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
9353 - sp -= get_random_int() & ~PAGE_MASK;
9354 - return sp & ~0xf;
9355 -}
9356 -
9357 -static inline unsigned long brk_rnd(void)
9358 -{
9359 - /* 8MB for 32bit, 1GB for 64bit */
9360 - if (is_32bit_task())
9361 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
9362 - else
9363 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
9364 -}
9365 -
9366 -unsigned long arch_randomize_brk(struct mm_struct *mm)
9367 -{
9368 - unsigned long ret;
9369 -
9370 - ret = PAGE_ALIGN(mm->brk + brk_rnd());
9371 - return (ret > mm->brk) ? ret : mm->brk;
9372 -}
9373 -
9374 -unsigned long randomize_et_dyn(unsigned long base)
9375 -{
9376 - unsigned long ret;
9377 -
9378 - if (!(current->flags & PF_RANDOMIZE))
9379 - return base;
9380 - ret = PAGE_ALIGN(base + brk_rnd());
9381 - return (ret > base) ? ret : base;
9382 -}
9383 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
9384 index 9b436c2..54fbf0a 100644
9385 --- a/arch/s390/mm/mmap.c
9386 +++ b/arch/s390/mm/mmap.c
9387 @@ -95,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9388 */
9389 if (mmap_is_legacy()) {
9390 mm->mmap_base = mmap_base_legacy();
9391 +
9392 +#ifdef CONFIG_PAX_RANDMMAP
9393 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9394 + mm->mmap_base += mm->delta_mmap;
9395 +#endif
9396 +
9397 mm->get_unmapped_area = arch_get_unmapped_area;
9398 } else {
9399 mm->mmap_base = mmap_base();
9400 +
9401 +#ifdef CONFIG_PAX_RANDMMAP
9402 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9403 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9404 +#endif
9405 +
9406 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9407 }
9408 }
9409 @@ -170,9 +182,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9410 */
9411 if (mmap_is_legacy()) {
9412 mm->mmap_base = mmap_base_legacy();
9413 +
9414 +#ifdef CONFIG_PAX_RANDMMAP
9415 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9416 + mm->mmap_base += mm->delta_mmap;
9417 +#endif
9418 +
9419 mm->get_unmapped_area = s390_get_unmapped_area;
9420 } else {
9421 mm->mmap_base = mmap_base();
9422 +
9423 +#ifdef CONFIG_PAX_RANDMMAP
9424 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9425 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9426 +#endif
9427 +
9428 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
9429 }
9430 }
9431 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
9432 index ae3d59f..f65f075 100644
9433 --- a/arch/score/include/asm/cache.h
9434 +++ b/arch/score/include/asm/cache.h
9435 @@ -1,7 +1,9 @@
9436 #ifndef _ASM_SCORE_CACHE_H
9437 #define _ASM_SCORE_CACHE_H
9438
9439 +#include <linux/const.h>
9440 +
9441 #define L1_CACHE_SHIFT 4
9442 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9443 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9444
9445 #endif /* _ASM_SCORE_CACHE_H */
9446 diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
9447 index f9f3cd5..58ff438 100644
9448 --- a/arch/score/include/asm/exec.h
9449 +++ b/arch/score/include/asm/exec.h
9450 @@ -1,6 +1,6 @@
9451 #ifndef _ASM_SCORE_EXEC_H
9452 #define _ASM_SCORE_EXEC_H
9453
9454 -extern unsigned long arch_align_stack(unsigned long sp);
9455 +#define arch_align_stack(x) (x)
9456
9457 #endif /* _ASM_SCORE_EXEC_H */
9458 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
9459 index a1519ad3..e8ac1ff 100644
9460 --- a/arch/score/kernel/process.c
9461 +++ b/arch/score/kernel/process.c
9462 @@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
9463
9464 return task_pt_regs(task)->cp0_epc;
9465 }
9466 -
9467 -unsigned long arch_align_stack(unsigned long sp)
9468 -{
9469 - return sp;
9470 -}
9471 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
9472 index ef9e555..331bd29 100644
9473 --- a/arch/sh/include/asm/cache.h
9474 +++ b/arch/sh/include/asm/cache.h
9475 @@ -9,10 +9,11 @@
9476 #define __ASM_SH_CACHE_H
9477 #ifdef __KERNEL__
9478
9479 +#include <linux/const.h>
9480 #include <linux/init.h>
9481 #include <cpu/cache.h>
9482
9483 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
9484 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9485
9486 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
9487
9488 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
9489 index 6777177..cb5e44f 100644
9490 --- a/arch/sh/mm/mmap.c
9491 +++ b/arch/sh/mm/mmap.c
9492 @@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9493 struct mm_struct *mm = current->mm;
9494 struct vm_area_struct *vma;
9495 int do_colour_align;
9496 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9497 struct vm_unmapped_area_info info;
9498
9499 if (flags & MAP_FIXED) {
9500 @@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9501 if (filp || (flags & MAP_SHARED))
9502 do_colour_align = 1;
9503
9504 +#ifdef CONFIG_PAX_RANDMMAP
9505 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9506 +#endif
9507 +
9508 if (addr) {
9509 if (do_colour_align)
9510 addr = COLOUR_ALIGN(addr, pgoff);
9511 @@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
9512 addr = PAGE_ALIGN(addr);
9513
9514 vma = find_vma(mm, addr);
9515 - if (TASK_SIZE - len >= addr &&
9516 - (!vma || addr + len <= vma->vm_start))
9517 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9518 return addr;
9519 }
9520
9521 info.flags = 0;
9522 info.length = len;
9523 - info.low_limit = TASK_UNMAPPED_BASE;
9524 + info.low_limit = mm->mmap_base;
9525 info.high_limit = TASK_SIZE;
9526 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
9527 info.align_offset = pgoff << PAGE_SHIFT;
9528 @@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9529 struct mm_struct *mm = current->mm;
9530 unsigned long addr = addr0;
9531 int do_colour_align;
9532 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9533 struct vm_unmapped_area_info info;
9534
9535 if (flags & MAP_FIXED) {
9536 @@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9537 if (filp || (flags & MAP_SHARED))
9538 do_colour_align = 1;
9539
9540 +#ifdef CONFIG_PAX_RANDMMAP
9541 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9542 +#endif
9543 +
9544 /* requesting a specific address */
9545 if (addr) {
9546 if (do_colour_align)
9547 @@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9548 addr = PAGE_ALIGN(addr);
9549
9550 vma = find_vma(mm, addr);
9551 - if (TASK_SIZE - len >= addr &&
9552 - (!vma || addr + len <= vma->vm_start))
9553 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9554 return addr;
9555 }
9556
9557 @@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9558 VM_BUG_ON(addr != -ENOMEM);
9559 info.flags = 0;
9560 info.low_limit = TASK_UNMAPPED_BASE;
9561 +
9562 +#ifdef CONFIG_PAX_RANDMMAP
9563 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9564 + info.low_limit += mm->delta_mmap;
9565 +#endif
9566 +
9567 info.high_limit = TASK_SIZE;
9568 addr = vm_unmapped_area(&info);
9569 }
9570 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
9571 index be56a24..443328f 100644
9572 --- a/arch/sparc/include/asm/atomic_64.h
9573 +++ b/arch/sparc/include/asm/atomic_64.h
9574 @@ -14,18 +14,40 @@
9575 #define ATOMIC64_INIT(i) { (i) }
9576
9577 #define atomic_read(v) (*(volatile int *)&(v)->counter)
9578 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9579 +{
9580 + return v->counter;
9581 +}
9582 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
9583 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9584 +{
9585 + return v->counter;
9586 +}
9587
9588 #define atomic_set(v, i) (((v)->counter) = i)
9589 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9590 +{
9591 + v->counter = i;
9592 +}
9593 #define atomic64_set(v, i) (((v)->counter) = i)
9594 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9595 +{
9596 + v->counter = i;
9597 +}
9598
9599 extern void atomic_add(int, atomic_t *);
9600 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
9601 extern void atomic64_add(long, atomic64_t *);
9602 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
9603 extern void atomic_sub(int, atomic_t *);
9604 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
9605 extern void atomic64_sub(long, atomic64_t *);
9606 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
9607
9608 extern int atomic_add_ret(int, atomic_t *);
9609 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
9610 extern long atomic64_add_ret(long, atomic64_t *);
9611 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
9612 extern int atomic_sub_ret(int, atomic_t *);
9613 extern long atomic64_sub_ret(long, atomic64_t *);
9614
9615 @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9616 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
9617
9618 #define atomic_inc_return(v) atomic_add_ret(1, v)
9619 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9620 +{
9621 + return atomic_add_ret_unchecked(1, v);
9622 +}
9623 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
9624 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9625 +{
9626 + return atomic64_add_ret_unchecked(1, v);
9627 +}
9628
9629 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
9630 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
9631
9632 #define atomic_add_return(i, v) atomic_add_ret(i, v)
9633 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9634 +{
9635 + return atomic_add_ret_unchecked(i, v);
9636 +}
9637 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
9638 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
9639 +{
9640 + return atomic64_add_ret_unchecked(i, v);
9641 +}
9642
9643 /*
9644 * atomic_inc_and_test - increment and test
9645 @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9646 * other cases.
9647 */
9648 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
9649 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9650 +{
9651 + return atomic_inc_return_unchecked(v) == 0;
9652 +}
9653 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
9654
9655 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
9656 @@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9657 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
9658
9659 #define atomic_inc(v) atomic_add(1, v)
9660 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9661 +{
9662 + atomic_add_unchecked(1, v);
9663 +}
9664 #define atomic64_inc(v) atomic64_add(1, v)
9665 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9666 +{
9667 + atomic64_add_unchecked(1, v);
9668 +}
9669
9670 #define atomic_dec(v) atomic_sub(1, v)
9671 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9672 +{
9673 + atomic_sub_unchecked(1, v);
9674 +}
9675 #define atomic64_dec(v) atomic64_sub(1, v)
9676 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9677 +{
9678 + atomic64_sub_unchecked(1, v);
9679 +}
9680
9681 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
9682 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
9683
9684 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
9685 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9686 +{
9687 + return cmpxchg(&v->counter, old, new);
9688 +}
9689 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
9690 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9691 +{
9692 + return xchg(&v->counter, new);
9693 +}
9694
9695 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9696 {
9697 - int c, old;
9698 + int c, old, new;
9699 c = atomic_read(v);
9700 for (;;) {
9701 - if (unlikely(c == (u)))
9702 + if (unlikely(c == u))
9703 break;
9704 - old = atomic_cmpxchg((v), c, c + (a));
9705 +
9706 + asm volatile("addcc %2, %0, %0\n"
9707 +
9708 +#ifdef CONFIG_PAX_REFCOUNT
9709 + "tvs %%icc, 6\n"
9710 +#endif
9711 +
9712 + : "=r" (new)
9713 + : "0" (c), "ir" (a)
9714 + : "cc");
9715 +
9716 + old = atomic_cmpxchg(v, c, new);
9717 if (likely(old == c))
9718 break;
9719 c = old;
9720 @@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9721 #define atomic64_cmpxchg(v, o, n) \
9722 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
9723 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
9724 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
9725 +{
9726 + return xchg(&v->counter, new);
9727 +}
9728
9729 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
9730 {
9731 - long c, old;
9732 + long c, old, new;
9733 c = atomic64_read(v);
9734 for (;;) {
9735 - if (unlikely(c == (u)))
9736 + if (unlikely(c == u))
9737 break;
9738 - old = atomic64_cmpxchg((v), c, c + (a));
9739 +
9740 + asm volatile("addcc %2, %0, %0\n"
9741 +
9742 +#ifdef CONFIG_PAX_REFCOUNT
9743 + "tvs %%xcc, 6\n"
9744 +#endif
9745 +
9746 + : "=r" (new)
9747 + : "0" (c), "ir" (a)
9748 + : "cc");
9749 +
9750 + old = atomic64_cmpxchg(v, c, new);
9751 if (likely(old == c))
9752 break;
9753 c = old;
9754 }
9755 - return c != (u);
9756 + return c != u;
9757 }
9758
9759 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9760 diff --git a/arch/sparc/include/asm/barrier_64.h b/arch/sparc/include/asm/barrier_64.h
9761 index b5aad96..99d7465 100644
9762 --- a/arch/sparc/include/asm/barrier_64.h
9763 +++ b/arch/sparc/include/asm/barrier_64.h
9764 @@ -57,7 +57,7 @@ do { __asm__ __volatile__("ba,pt %%xcc, 1f\n\t" \
9765 do { \
9766 compiletime_assert_atomic_type(*p); \
9767 barrier(); \
9768 - ACCESS_ONCE(*p) = (v); \
9769 + ACCESS_ONCE_RW(*p) = (v); \
9770 } while (0)
9771
9772 #define smp_load_acquire(p) \
9773 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
9774 index 5bb6991..5c2132e 100644
9775 --- a/arch/sparc/include/asm/cache.h
9776 +++ b/arch/sparc/include/asm/cache.h
9777 @@ -7,10 +7,12 @@
9778 #ifndef _SPARC_CACHE_H
9779 #define _SPARC_CACHE_H
9780
9781 +#include <linux/const.h>
9782 +
9783 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
9784
9785 #define L1_CACHE_SHIFT 5
9786 -#define L1_CACHE_BYTES 32
9787 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9788
9789 #ifdef CONFIG_SPARC32
9790 #define SMP_CACHE_BYTES_SHIFT 5
9791 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
9792 index a24e41f..47677ff 100644
9793 --- a/arch/sparc/include/asm/elf_32.h
9794 +++ b/arch/sparc/include/asm/elf_32.h
9795 @@ -114,6 +114,13 @@ typedef struct {
9796
9797 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
9798
9799 +#ifdef CONFIG_PAX_ASLR
9800 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
9801 +
9802 +#define PAX_DELTA_MMAP_LEN 16
9803 +#define PAX_DELTA_STACK_LEN 16
9804 +#endif
9805 +
9806 /* This yields a mask that user programs can use to figure out what
9807 instruction set this cpu supports. This can NOT be done in userspace
9808 on Sparc. */
9809 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
9810 index 370ca1e..d4f4a98 100644
9811 --- a/arch/sparc/include/asm/elf_64.h
9812 +++ b/arch/sparc/include/asm/elf_64.h
9813 @@ -189,6 +189,13 @@ typedef struct {
9814 #define ELF_ET_DYN_BASE 0x0000010000000000UL
9815 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
9816
9817 +#ifdef CONFIG_PAX_ASLR
9818 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
9819 +
9820 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
9821 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
9822 +#endif
9823 +
9824 extern unsigned long sparc64_elf_hwcap;
9825 #define ELF_HWCAP sparc64_elf_hwcap
9826
9827 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
9828 index 9b1c36d..209298b 100644
9829 --- a/arch/sparc/include/asm/pgalloc_32.h
9830 +++ b/arch/sparc/include/asm/pgalloc_32.h
9831 @@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
9832 }
9833
9834 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
9835 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
9836
9837 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
9838 unsigned long address)
9839 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
9840 index bcfe063..b333142 100644
9841 --- a/arch/sparc/include/asm/pgalloc_64.h
9842 +++ b/arch/sparc/include/asm/pgalloc_64.h
9843 @@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
9844 }
9845
9846 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
9847 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
9848
9849 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
9850 {
9851 diff --git a/arch/sparc/include/asm/pgtable.h b/arch/sparc/include/asm/pgtable.h
9852 index 59ba6f6..4518128 100644
9853 --- a/arch/sparc/include/asm/pgtable.h
9854 +++ b/arch/sparc/include/asm/pgtable.h
9855 @@ -5,4 +5,8 @@
9856 #else
9857 #include <asm/pgtable_32.h>
9858 #endif
9859 +
9860 +#define ktla_ktva(addr) (addr)
9861 +#define ktva_ktla(addr) (addr)
9862 +
9863 #endif
9864 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
9865 index 502f632..da1917f 100644
9866 --- a/arch/sparc/include/asm/pgtable_32.h
9867 +++ b/arch/sparc/include/asm/pgtable_32.h
9868 @@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
9869 #define PAGE_SHARED SRMMU_PAGE_SHARED
9870 #define PAGE_COPY SRMMU_PAGE_COPY
9871 #define PAGE_READONLY SRMMU_PAGE_RDONLY
9872 +#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
9873 +#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
9874 +#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
9875 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
9876
9877 /* Top-level page directory - dummy used by init-mm.
9878 @@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
9879
9880 /* xwr */
9881 #define __P000 PAGE_NONE
9882 -#define __P001 PAGE_READONLY
9883 -#define __P010 PAGE_COPY
9884 -#define __P011 PAGE_COPY
9885 +#define __P001 PAGE_READONLY_NOEXEC
9886 +#define __P010 PAGE_COPY_NOEXEC
9887 +#define __P011 PAGE_COPY_NOEXEC
9888 #define __P100 PAGE_READONLY
9889 #define __P101 PAGE_READONLY
9890 #define __P110 PAGE_COPY
9891 #define __P111 PAGE_COPY
9892
9893 #define __S000 PAGE_NONE
9894 -#define __S001 PAGE_READONLY
9895 -#define __S010 PAGE_SHARED
9896 -#define __S011 PAGE_SHARED
9897 +#define __S001 PAGE_READONLY_NOEXEC
9898 +#define __S010 PAGE_SHARED_NOEXEC
9899 +#define __S011 PAGE_SHARED_NOEXEC
9900 #define __S100 PAGE_READONLY
9901 #define __S101 PAGE_READONLY
9902 #define __S110 PAGE_SHARED
9903 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
9904 index 79da178..c2eede8 100644
9905 --- a/arch/sparc/include/asm/pgtsrmmu.h
9906 +++ b/arch/sparc/include/asm/pgtsrmmu.h
9907 @@ -115,6 +115,11 @@
9908 SRMMU_EXEC | SRMMU_REF)
9909 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
9910 SRMMU_EXEC | SRMMU_REF)
9911 +
9912 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
9913 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9914 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9915 +
9916 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
9917 SRMMU_DIRTY | SRMMU_REF)
9918
9919 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
9920 index 9689176..63c18ea 100644
9921 --- a/arch/sparc/include/asm/spinlock_64.h
9922 +++ b/arch/sparc/include/asm/spinlock_64.h
9923 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
9924
9925 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
9926
9927 -static void inline arch_read_lock(arch_rwlock_t *lock)
9928 +static inline void arch_read_lock(arch_rwlock_t *lock)
9929 {
9930 unsigned long tmp1, tmp2;
9931
9932 __asm__ __volatile__ (
9933 "1: ldsw [%2], %0\n"
9934 " brlz,pn %0, 2f\n"
9935 -"4: add %0, 1, %1\n"
9936 +"4: addcc %0, 1, %1\n"
9937 +
9938 +#ifdef CONFIG_PAX_REFCOUNT
9939 +" tvs %%icc, 6\n"
9940 +#endif
9941 +
9942 " cas [%2], %0, %1\n"
9943 " cmp %0, %1\n"
9944 " bne,pn %%icc, 1b\n"
9945 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
9946 " .previous"
9947 : "=&r" (tmp1), "=&r" (tmp2)
9948 : "r" (lock)
9949 - : "memory");
9950 + : "memory", "cc");
9951 }
9952
9953 -static int inline arch_read_trylock(arch_rwlock_t *lock)
9954 +static inline int arch_read_trylock(arch_rwlock_t *lock)
9955 {
9956 int tmp1, tmp2;
9957
9958 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9959 "1: ldsw [%2], %0\n"
9960 " brlz,a,pn %0, 2f\n"
9961 " mov 0, %0\n"
9962 -" add %0, 1, %1\n"
9963 +" addcc %0, 1, %1\n"
9964 +
9965 +#ifdef CONFIG_PAX_REFCOUNT
9966 +" tvs %%icc, 6\n"
9967 +#endif
9968 +
9969 " cas [%2], %0, %1\n"
9970 " cmp %0, %1\n"
9971 " bne,pn %%icc, 1b\n"
9972 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9973 return tmp1;
9974 }
9975
9976 -static void inline arch_read_unlock(arch_rwlock_t *lock)
9977 +static inline void arch_read_unlock(arch_rwlock_t *lock)
9978 {
9979 unsigned long tmp1, tmp2;
9980
9981 __asm__ __volatile__(
9982 "1: lduw [%2], %0\n"
9983 -" sub %0, 1, %1\n"
9984 +" subcc %0, 1, %1\n"
9985 +
9986 +#ifdef CONFIG_PAX_REFCOUNT
9987 +" tvs %%icc, 6\n"
9988 +#endif
9989 +
9990 " cas [%2], %0, %1\n"
9991 " cmp %0, %1\n"
9992 " bne,pn %%xcc, 1b\n"
9993 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
9994 : "memory");
9995 }
9996
9997 -static void inline arch_write_lock(arch_rwlock_t *lock)
9998 +static inline void arch_write_lock(arch_rwlock_t *lock)
9999 {
10000 unsigned long mask, tmp1, tmp2;
10001
10002 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
10003 : "memory");
10004 }
10005
10006 -static void inline arch_write_unlock(arch_rwlock_t *lock)
10007 +static inline void arch_write_unlock(arch_rwlock_t *lock)
10008 {
10009 __asm__ __volatile__(
10010 " stw %%g0, [%0]"
10011 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
10012 : "memory");
10013 }
10014
10015 -static int inline arch_write_trylock(arch_rwlock_t *lock)
10016 +static inline int arch_write_trylock(arch_rwlock_t *lock)
10017 {
10018 unsigned long mask, tmp1, tmp2, result;
10019
10020 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
10021 index 96efa7a..16858bf 100644
10022 --- a/arch/sparc/include/asm/thread_info_32.h
10023 +++ b/arch/sparc/include/asm/thread_info_32.h
10024 @@ -49,6 +49,8 @@ struct thread_info {
10025 unsigned long w_saved;
10026
10027 struct restart_block restart_block;
10028 +
10029 + unsigned long lowest_stack;
10030 };
10031
10032 /*
10033 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
10034 index a5f01ac..703b554 100644
10035 --- a/arch/sparc/include/asm/thread_info_64.h
10036 +++ b/arch/sparc/include/asm/thread_info_64.h
10037 @@ -63,6 +63,8 @@ struct thread_info {
10038 struct pt_regs *kern_una_regs;
10039 unsigned int kern_una_insn;
10040
10041 + unsigned long lowest_stack;
10042 +
10043 unsigned long fpregs[0] __attribute__ ((aligned(64)));
10044 };
10045
10046 @@ -188,12 +190,13 @@ register struct thread_info *current_thread_info_reg asm("g6");
10047 #define TIF_NEED_RESCHED 3 /* rescheduling necessary */
10048 /* flag bit 4 is available */
10049 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
10050 -/* flag bit 6 is available */
10051 +#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
10052 #define TIF_32BIT 7 /* 32-bit binary */
10053 #define TIF_NOHZ 8 /* in adaptive nohz mode */
10054 #define TIF_SECCOMP 9 /* secure computing */
10055 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
10056 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
10057 +
10058 /* NOTE: Thread flags >= 12 should be ones we have no interest
10059 * in using in assembly, else we can't use the mask as
10060 * an immediate value in instructions such as andcc.
10061 @@ -213,12 +216,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
10062 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
10063 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
10064 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
10065 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
10066
10067 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
10068 _TIF_DO_NOTIFY_RESUME_MASK | \
10069 _TIF_NEED_RESCHED)
10070 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
10071
10072 +#define _TIF_WORK_SYSCALL \
10073 + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
10074 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
10075 +
10076 +
10077 /*
10078 * Thread-synchronous status.
10079 *
10080 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
10081 index 0167d26..767bb0c 100644
10082 --- a/arch/sparc/include/asm/uaccess.h
10083 +++ b/arch/sparc/include/asm/uaccess.h
10084 @@ -1,5 +1,6 @@
10085 #ifndef ___ASM_SPARC_UACCESS_H
10086 #define ___ASM_SPARC_UACCESS_H
10087 +
10088 #if defined(__sparc__) && defined(__arch64__)
10089 #include <asm/uaccess_64.h>
10090 #else
10091 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
10092 index 53a28dd..50c38c3 100644
10093 --- a/arch/sparc/include/asm/uaccess_32.h
10094 +++ b/arch/sparc/include/asm/uaccess_32.h
10095 @@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
10096
10097 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
10098 {
10099 - if (n && __access_ok((unsigned long) to, n))
10100 + if ((long)n < 0)
10101 + return n;
10102 +
10103 + if (n && __access_ok((unsigned long) to, n)) {
10104 + if (!__builtin_constant_p(n))
10105 + check_object_size(from, n, true);
10106 return __copy_user(to, (__force void __user *) from, n);
10107 - else
10108 + } else
10109 return n;
10110 }
10111
10112 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
10113 {
10114 + if ((long)n < 0)
10115 + return n;
10116 +
10117 + if (!__builtin_constant_p(n))
10118 + check_object_size(from, n, true);
10119 +
10120 return __copy_user(to, (__force void __user *) from, n);
10121 }
10122
10123 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
10124 {
10125 - if (n && __access_ok((unsigned long) from, n))
10126 + if ((long)n < 0)
10127 + return n;
10128 +
10129 + if (n && __access_ok((unsigned long) from, n)) {
10130 + if (!__builtin_constant_p(n))
10131 + check_object_size(to, n, false);
10132 return __copy_user((__force void __user *) to, from, n);
10133 - else
10134 + } else
10135 return n;
10136 }
10137
10138 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
10139 {
10140 + if ((long)n < 0)
10141 + return n;
10142 +
10143 return __copy_user((__force void __user *) to, from, n);
10144 }
10145
10146 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
10147 index ad7e178..c9e7423 100644
10148 --- a/arch/sparc/include/asm/uaccess_64.h
10149 +++ b/arch/sparc/include/asm/uaccess_64.h
10150 @@ -10,6 +10,7 @@
10151 #include <linux/compiler.h>
10152 #include <linux/string.h>
10153 #include <linux/thread_info.h>
10154 +#include <linux/kernel.h>
10155 #include <asm/asi.h>
10156 #include <asm/spitfire.h>
10157 #include <asm-generic/uaccess-unaligned.h>
10158 @@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
10159 static inline unsigned long __must_check
10160 copy_from_user(void *to, const void __user *from, unsigned long size)
10161 {
10162 - unsigned long ret = ___copy_from_user(to, from, size);
10163 + unsigned long ret;
10164
10165 + if ((long)size < 0 || size > INT_MAX)
10166 + return size;
10167 +
10168 + if (!__builtin_constant_p(size))
10169 + check_object_size(to, size, false);
10170 +
10171 + ret = ___copy_from_user(to, from, size);
10172 if (unlikely(ret))
10173 ret = copy_from_user_fixup(to, from, size);
10174
10175 @@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
10176 static inline unsigned long __must_check
10177 copy_to_user(void __user *to, const void *from, unsigned long size)
10178 {
10179 - unsigned long ret = ___copy_to_user(to, from, size);
10180 + unsigned long ret;
10181
10182 + if ((long)size < 0 || size > INT_MAX)
10183 + return size;
10184 +
10185 + if (!__builtin_constant_p(size))
10186 + check_object_size(from, size, true);
10187 +
10188 + ret = ___copy_to_user(to, from, size);
10189 if (unlikely(ret))
10190 ret = copy_to_user_fixup(to, from, size);
10191 return ret;
10192 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
10193 index d15cc17..d0ae796 100644
10194 --- a/arch/sparc/kernel/Makefile
10195 +++ b/arch/sparc/kernel/Makefile
10196 @@ -4,7 +4,7 @@
10197 #
10198
10199 asflags-y := -ansi
10200 -ccflags-y := -Werror
10201 +#ccflags-y := -Werror
10202
10203 extra-y := head_$(BITS).o
10204
10205 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
10206 index 510baec..9ff2607 100644
10207 --- a/arch/sparc/kernel/process_32.c
10208 +++ b/arch/sparc/kernel/process_32.c
10209 @@ -115,14 +115,14 @@ void show_regs(struct pt_regs *r)
10210
10211 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
10212 r->psr, r->pc, r->npc, r->y, print_tainted());
10213 - printk("PC: <%pS>\n", (void *) r->pc);
10214 + printk("PC: <%pA>\n", (void *) r->pc);
10215 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10216 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
10217 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
10218 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10219 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
10220 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
10221 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
10222 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
10223
10224 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
10225 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
10226 @@ -159,7 +159,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10227 rw = (struct reg_window32 *) fp;
10228 pc = rw->ins[7];
10229 printk("[%08lx : ", pc);
10230 - printk("%pS ] ", (void *) pc);
10231 + printk("%pA ] ", (void *) pc);
10232 fp = rw->ins[6];
10233 } while (++count < 16);
10234 printk("\n");
10235 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
10236 index d7b4967..2edf827 100644
10237 --- a/arch/sparc/kernel/process_64.c
10238 +++ b/arch/sparc/kernel/process_64.c
10239 @@ -161,7 +161,7 @@ static void show_regwindow(struct pt_regs *regs)
10240 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
10241 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
10242 if (regs->tstate & TSTATE_PRIV)
10243 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
10244 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
10245 }
10246
10247 void show_regs(struct pt_regs *regs)
10248 @@ -170,7 +170,7 @@ void show_regs(struct pt_regs *regs)
10249
10250 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
10251 regs->tpc, regs->tnpc, regs->y, print_tainted());
10252 - printk("TPC: <%pS>\n", (void *) regs->tpc);
10253 + printk("TPC: <%pA>\n", (void *) regs->tpc);
10254 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
10255 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
10256 regs->u_regs[3]);
10257 @@ -183,7 +183,7 @@ void show_regs(struct pt_regs *regs)
10258 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
10259 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
10260 regs->u_regs[15]);
10261 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
10262 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
10263 show_regwindow(regs);
10264 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
10265 }
10266 @@ -272,7 +272,7 @@ void arch_trigger_all_cpu_backtrace(void)
10267 ((tp && tp->task) ? tp->task->pid : -1));
10268
10269 if (gp->tstate & TSTATE_PRIV) {
10270 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
10271 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
10272 (void *) gp->tpc,
10273 (void *) gp->o7,
10274 (void *) gp->i7,
10275 diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
10276 index 79cc0d1..ec62734 100644
10277 --- a/arch/sparc/kernel/prom_common.c
10278 +++ b/arch/sparc/kernel/prom_common.c
10279 @@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
10280
10281 unsigned int prom_early_allocated __initdata;
10282
10283 -static struct of_pdt_ops prom_sparc_ops __initdata = {
10284 +static struct of_pdt_ops prom_sparc_ops __initconst = {
10285 .nextprop = prom_common_nextprop,
10286 .getproplen = prom_getproplen,
10287 .getproperty = prom_getproperty,
10288 diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
10289 index c13c9f2..d572c34 100644
10290 --- a/arch/sparc/kernel/ptrace_64.c
10291 +++ b/arch/sparc/kernel/ptrace_64.c
10292 @@ -1060,6 +1060,10 @@ long arch_ptrace(struct task_struct *child, long request,
10293 return ret;
10294 }
10295
10296 +#ifdef CONFIG_GRKERNSEC_SETXID
10297 +extern void gr_delayed_cred_worker(void);
10298 +#endif
10299 +
10300 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10301 {
10302 int ret = 0;
10303 @@ -1070,6 +1074,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
10304 if (test_thread_flag(TIF_NOHZ))
10305 user_exit();
10306
10307 +#ifdef CONFIG_GRKERNSEC_SETXID
10308 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10309 + gr_delayed_cred_worker();
10310 +#endif
10311 +
10312 if (test_thread_flag(TIF_SYSCALL_TRACE))
10313 ret = tracehook_report_syscall_entry(regs);
10314
10315 @@ -1093,6 +1102,11 @@ asmlinkage void syscall_trace_leave(struct pt_regs *regs)
10316 if (test_thread_flag(TIF_NOHZ))
10317 user_exit();
10318
10319 +#ifdef CONFIG_GRKERNSEC_SETXID
10320 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
10321 + gr_delayed_cred_worker();
10322 +#endif
10323 +
10324 audit_syscall_exit(regs);
10325
10326 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
10327 diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
10328 index 745a363..b5566b1 100644
10329 --- a/arch/sparc/kernel/smp_64.c
10330 +++ b/arch/sparc/kernel/smp_64.c
10331 @@ -868,8 +868,8 @@ extern unsigned long xcall_flush_dcache_page_cheetah;
10332 extern unsigned long xcall_flush_dcache_page_spitfire;
10333
10334 #ifdef CONFIG_DEBUG_DCFLUSH
10335 -extern atomic_t dcpage_flushes;
10336 -extern atomic_t dcpage_flushes_xcall;
10337 +extern atomic_unchecked_t dcpage_flushes;
10338 +extern atomic_unchecked_t dcpage_flushes_xcall;
10339 #endif
10340
10341 static inline void __local_flush_dcache_page(struct page *page)
10342 @@ -893,7 +893,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10343 return;
10344
10345 #ifdef CONFIG_DEBUG_DCFLUSH
10346 - atomic_inc(&dcpage_flushes);
10347 + atomic_inc_unchecked(&dcpage_flushes);
10348 #endif
10349
10350 this_cpu = get_cpu();
10351 @@ -917,7 +917,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
10352 xcall_deliver(data0, __pa(pg_addr),
10353 (u64) pg_addr, cpumask_of(cpu));
10354 #ifdef CONFIG_DEBUG_DCFLUSH
10355 - atomic_inc(&dcpage_flushes_xcall);
10356 + atomic_inc_unchecked(&dcpage_flushes_xcall);
10357 #endif
10358 }
10359 }
10360 @@ -936,7 +936,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10361 preempt_disable();
10362
10363 #ifdef CONFIG_DEBUG_DCFLUSH
10364 - atomic_inc(&dcpage_flushes);
10365 + atomic_inc_unchecked(&dcpage_flushes);
10366 #endif
10367 data0 = 0;
10368 pg_addr = page_address(page);
10369 @@ -953,7 +953,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
10370 xcall_deliver(data0, __pa(pg_addr),
10371 (u64) pg_addr, cpu_online_mask);
10372 #ifdef CONFIG_DEBUG_DCFLUSH
10373 - atomic_inc(&dcpage_flushes_xcall);
10374 + atomic_inc_unchecked(&dcpage_flushes_xcall);
10375 #endif
10376 }
10377 __local_flush_dcache_page(page);
10378 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
10379 index 3a8d184..49498a8 100644
10380 --- a/arch/sparc/kernel/sys_sparc_32.c
10381 +++ b/arch/sparc/kernel/sys_sparc_32.c
10382 @@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10383 if (len > TASK_SIZE - PAGE_SIZE)
10384 return -ENOMEM;
10385 if (!addr)
10386 - addr = TASK_UNMAPPED_BASE;
10387 + addr = current->mm->mmap_base;
10388
10389 info.flags = 0;
10390 info.length = len;
10391 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
10392 index beb0b5a..5a153f7 100644
10393 --- a/arch/sparc/kernel/sys_sparc_64.c
10394 +++ b/arch/sparc/kernel/sys_sparc_64.c
10395 @@ -88,13 +88,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10396 struct vm_area_struct * vma;
10397 unsigned long task_size = TASK_SIZE;
10398 int do_color_align;
10399 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10400 struct vm_unmapped_area_info info;
10401
10402 if (flags & MAP_FIXED) {
10403 /* We do not accept a shared mapping if it would violate
10404 * cache aliasing constraints.
10405 */
10406 - if ((flags & MAP_SHARED) &&
10407 + if ((filp || (flags & MAP_SHARED)) &&
10408 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10409 return -EINVAL;
10410 return addr;
10411 @@ -109,6 +110,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10412 if (filp || (flags & MAP_SHARED))
10413 do_color_align = 1;
10414
10415 +#ifdef CONFIG_PAX_RANDMMAP
10416 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10417 +#endif
10418 +
10419 if (addr) {
10420 if (do_color_align)
10421 addr = COLOR_ALIGN(addr, pgoff);
10422 @@ -116,22 +121,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
10423 addr = PAGE_ALIGN(addr);
10424
10425 vma = find_vma(mm, addr);
10426 - if (task_size - len >= addr &&
10427 - (!vma || addr + len <= vma->vm_start))
10428 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10429 return addr;
10430 }
10431
10432 info.flags = 0;
10433 info.length = len;
10434 - info.low_limit = TASK_UNMAPPED_BASE;
10435 + info.low_limit = mm->mmap_base;
10436 info.high_limit = min(task_size, VA_EXCLUDE_START);
10437 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10438 info.align_offset = pgoff << PAGE_SHIFT;
10439 + info.threadstack_offset = offset;
10440 addr = vm_unmapped_area(&info);
10441
10442 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
10443 VM_BUG_ON(addr != -ENOMEM);
10444 info.low_limit = VA_EXCLUDE_END;
10445 +
10446 +#ifdef CONFIG_PAX_RANDMMAP
10447 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10448 + info.low_limit += mm->delta_mmap;
10449 +#endif
10450 +
10451 info.high_limit = task_size;
10452 addr = vm_unmapped_area(&info);
10453 }
10454 @@ -149,6 +160,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10455 unsigned long task_size = STACK_TOP32;
10456 unsigned long addr = addr0;
10457 int do_color_align;
10458 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
10459 struct vm_unmapped_area_info info;
10460
10461 /* This should only ever run for 32-bit processes. */
10462 @@ -158,7 +170,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10463 /* We do not accept a shared mapping if it would violate
10464 * cache aliasing constraints.
10465 */
10466 - if ((flags & MAP_SHARED) &&
10467 + if ((filp || (flags & MAP_SHARED)) &&
10468 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
10469 return -EINVAL;
10470 return addr;
10471 @@ -171,6 +183,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10472 if (filp || (flags & MAP_SHARED))
10473 do_color_align = 1;
10474
10475 +#ifdef CONFIG_PAX_RANDMMAP
10476 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10477 +#endif
10478 +
10479 /* requesting a specific address */
10480 if (addr) {
10481 if (do_color_align)
10482 @@ -179,8 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10483 addr = PAGE_ALIGN(addr);
10484
10485 vma = find_vma(mm, addr);
10486 - if (task_size - len >= addr &&
10487 - (!vma || addr + len <= vma->vm_start))
10488 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
10489 return addr;
10490 }
10491
10492 @@ -190,6 +205,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10493 info.high_limit = mm->mmap_base;
10494 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
10495 info.align_offset = pgoff << PAGE_SHIFT;
10496 + info.threadstack_offset = offset;
10497 addr = vm_unmapped_area(&info);
10498
10499 /*
10500 @@ -202,6 +218,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
10501 VM_BUG_ON(addr != -ENOMEM);
10502 info.flags = 0;
10503 info.low_limit = TASK_UNMAPPED_BASE;
10504 +
10505 +#ifdef CONFIG_PAX_RANDMMAP
10506 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10507 + info.low_limit += mm->delta_mmap;
10508 +#endif
10509 +
10510 info.high_limit = STACK_TOP32;
10511 addr = vm_unmapped_area(&info);
10512 }
10513 @@ -258,10 +280,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
10514 EXPORT_SYMBOL(get_fb_unmapped_area);
10515
10516 /* Essentially the same as PowerPC. */
10517 -static unsigned long mmap_rnd(void)
10518 +static unsigned long mmap_rnd(struct mm_struct *mm)
10519 {
10520 unsigned long rnd = 0UL;
10521
10522 +#ifdef CONFIG_PAX_RANDMMAP
10523 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
10524 +#endif
10525 +
10526 if (current->flags & PF_RANDOMIZE) {
10527 unsigned long val = get_random_int();
10528 if (test_thread_flag(TIF_32BIT))
10529 @@ -274,7 +300,7 @@ static unsigned long mmap_rnd(void)
10530
10531 void arch_pick_mmap_layout(struct mm_struct *mm)
10532 {
10533 - unsigned long random_factor = mmap_rnd();
10534 + unsigned long random_factor = mmap_rnd(mm);
10535 unsigned long gap;
10536
10537 /*
10538 @@ -287,6 +313,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10539 gap == RLIM_INFINITY ||
10540 sysctl_legacy_va_layout) {
10541 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
10542 +
10543 +#ifdef CONFIG_PAX_RANDMMAP
10544 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10545 + mm->mmap_base += mm->delta_mmap;
10546 +#endif
10547 +
10548 mm->get_unmapped_area = arch_get_unmapped_area;
10549 } else {
10550 /* We know it's 32-bit */
10551 @@ -298,6 +330,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
10552 gap = (task_size / 6 * 5);
10553
10554 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
10555 +
10556 +#ifdef CONFIG_PAX_RANDMMAP
10557 + if (mm->pax_flags & MF_PAX_RANDMMAP)
10558 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
10559 +#endif
10560 +
10561 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
10562 }
10563 }
10564 diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
10565 index 33a17e7..d87fb1f 100644
10566 --- a/arch/sparc/kernel/syscalls.S
10567 +++ b/arch/sparc/kernel/syscalls.S
10568 @@ -52,7 +52,7 @@ sys32_rt_sigreturn:
10569 #endif
10570 .align 32
10571 1: ldx [%g6 + TI_FLAGS], %l5
10572 - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10573 + andcc %l5, _TIF_WORK_SYSCALL, %g0
10574 be,pt %icc, rtrap
10575 nop
10576 call syscall_trace_leave
10577 @@ -184,7 +184,7 @@ linux_sparc_syscall32:
10578
10579 srl %i3, 0, %o3 ! IEU0
10580 srl %i2, 0, %o2 ! IEU0 Group
10581 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10582 + andcc %l0, _TIF_WORK_SYSCALL, %g0
10583 bne,pn %icc, linux_syscall_trace32 ! CTI
10584 mov %i0, %l5 ! IEU1
10585 5: call %l7 ! CTI Group brk forced
10586 @@ -208,7 +208,7 @@ linux_sparc_syscall:
10587
10588 mov %i3, %o3 ! IEU1
10589 mov %i4, %o4 ! IEU0 Group
10590 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10591 + andcc %l0, _TIF_WORK_SYSCALL, %g0
10592 bne,pn %icc, linux_syscall_trace ! CTI Group
10593 mov %i0, %l5 ! IEU0
10594 2: call %l7 ! CTI Group brk forced
10595 @@ -223,7 +223,7 @@ ret_sys_call:
10596
10597 cmp %o0, -ERESTART_RESTARTBLOCK
10598 bgeu,pn %xcc, 1f
10599 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
10600 + andcc %l0, _TIF_WORK_SYSCALL, %g0
10601 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
10602
10603 2:
10604 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
10605 index 6629829..036032d 100644
10606 --- a/arch/sparc/kernel/traps_32.c
10607 +++ b/arch/sparc/kernel/traps_32.c
10608 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
10609 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
10610 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
10611
10612 +extern void gr_handle_kernel_exploit(void);
10613 +
10614 void die_if_kernel(char *str, struct pt_regs *regs)
10615 {
10616 static int die_counter;
10617 @@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10618 count++ < 30 &&
10619 (((unsigned long) rw) >= PAGE_OFFSET) &&
10620 !(((unsigned long) rw) & 0x7)) {
10621 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
10622 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
10623 (void *) rw->ins[7]);
10624 rw = (struct reg_window32 *)rw->ins[6];
10625 }
10626 }
10627 printk("Instruction DUMP:");
10628 instruction_dump ((unsigned long *) regs->pc);
10629 - if(regs->psr & PSR_PS)
10630 + if(regs->psr & PSR_PS) {
10631 + gr_handle_kernel_exploit();
10632 do_exit(SIGKILL);
10633 + }
10634 do_exit(SIGSEGV);
10635 }
10636
10637 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
10638 index 4ced92f..965eeed 100644
10639 --- a/arch/sparc/kernel/traps_64.c
10640 +++ b/arch/sparc/kernel/traps_64.c
10641 @@ -77,7 +77,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
10642 i + 1,
10643 p->trapstack[i].tstate, p->trapstack[i].tpc,
10644 p->trapstack[i].tnpc, p->trapstack[i].tt);
10645 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
10646 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
10647 }
10648 }
10649
10650 @@ -97,6 +97,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
10651
10652 lvl -= 0x100;
10653 if (regs->tstate & TSTATE_PRIV) {
10654 +
10655 +#ifdef CONFIG_PAX_REFCOUNT
10656 + if (lvl == 6)
10657 + pax_report_refcount_overflow(regs);
10658 +#endif
10659 +
10660 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
10661 die_if_kernel(buffer, regs);
10662 }
10663 @@ -115,11 +121,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
10664 void bad_trap_tl1(struct pt_regs *regs, long lvl)
10665 {
10666 char buffer[32];
10667 -
10668 +
10669 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
10670 0, lvl, SIGTRAP) == NOTIFY_STOP)
10671 return;
10672
10673 +#ifdef CONFIG_PAX_REFCOUNT
10674 + if (lvl == 6)
10675 + pax_report_refcount_overflow(regs);
10676 +#endif
10677 +
10678 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
10679
10680 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
10681 @@ -1149,7 +1160,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
10682 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
10683 printk("%s" "ERROR(%d): ",
10684 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
10685 - printk("TPC<%pS>\n", (void *) regs->tpc);
10686 + printk("TPC<%pA>\n", (void *) regs->tpc);
10687 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
10688 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
10689 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
10690 @@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10691 smp_processor_id(),
10692 (type & 0x1) ? 'I' : 'D',
10693 regs->tpc);
10694 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
10695 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
10696 panic("Irrecoverable Cheetah+ parity error.");
10697 }
10698
10699 @@ -1764,7 +1775,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10700 smp_processor_id(),
10701 (type & 0x1) ? 'I' : 'D',
10702 regs->tpc);
10703 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
10704 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
10705 }
10706
10707 struct sun4v_error_entry {
10708 @@ -1837,8 +1848,8 @@ struct sun4v_error_entry {
10709 /*0x38*/u64 reserved_5;
10710 };
10711
10712 -static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10713 -static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10714 +static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10715 +static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10716
10717 static const char *sun4v_err_type_to_str(u8 type)
10718 {
10719 @@ -1930,7 +1941,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
10720 }
10721
10722 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10723 - int cpu, const char *pfx, atomic_t *ocnt)
10724 + int cpu, const char *pfx, atomic_unchecked_t *ocnt)
10725 {
10726 u64 *raw_ptr = (u64 *) ent;
10727 u32 attrs;
10728 @@ -1988,8 +1999,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10729
10730 show_regs(regs);
10731
10732 - if ((cnt = atomic_read(ocnt)) != 0) {
10733 - atomic_set(ocnt, 0);
10734 + if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
10735 + atomic_set_unchecked(ocnt, 0);
10736 wmb();
10737 printk("%s: Queue overflowed %d times.\n",
10738 pfx, cnt);
10739 @@ -2046,7 +2057,7 @@ out:
10740 */
10741 void sun4v_resum_overflow(struct pt_regs *regs)
10742 {
10743 - atomic_inc(&sun4v_resum_oflow_cnt);
10744 + atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
10745 }
10746
10747 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
10748 @@ -2099,7 +2110,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
10749 /* XXX Actually even this can make not that much sense. Perhaps
10750 * XXX we should just pull the plug and panic directly from here?
10751 */
10752 - atomic_inc(&sun4v_nonresum_oflow_cnt);
10753 + atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
10754 }
10755
10756 unsigned long sun4v_err_itlb_vaddr;
10757 @@ -2114,9 +2125,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
10758
10759 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
10760 regs->tpc, tl);
10761 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
10762 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
10763 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10764 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
10765 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
10766 (void *) regs->u_regs[UREG_I7]);
10767 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
10768 "pte[%lx] error[%lx]\n",
10769 @@ -2138,9 +2149,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
10770
10771 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
10772 regs->tpc, tl);
10773 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
10774 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
10775 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10776 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
10777 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
10778 (void *) regs->u_regs[UREG_I7]);
10779 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
10780 "pte[%lx] error[%lx]\n",
10781 @@ -2359,13 +2370,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10782 fp = (unsigned long)sf->fp + STACK_BIAS;
10783 }
10784
10785 - printk(" [%016lx] %pS\n", pc, (void *) pc);
10786 + printk(" [%016lx] %pA\n", pc, (void *) pc);
10787 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
10788 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
10789 int index = tsk->curr_ret_stack;
10790 if (tsk->ret_stack && index >= graph) {
10791 pc = tsk->ret_stack[index - graph].ret;
10792 - printk(" [%016lx] %pS\n", pc, (void *) pc);
10793 + printk(" [%016lx] %pA\n", pc, (void *) pc);
10794 graph++;
10795 }
10796 }
10797 @@ -2383,6 +2394,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
10798 return (struct reg_window *) (fp + STACK_BIAS);
10799 }
10800
10801 +extern void gr_handle_kernel_exploit(void);
10802 +
10803 void die_if_kernel(char *str, struct pt_regs *regs)
10804 {
10805 static int die_counter;
10806 @@ -2411,7 +2424,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10807 while (rw &&
10808 count++ < 30 &&
10809 kstack_valid(tp, (unsigned long) rw)) {
10810 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
10811 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
10812 (void *) rw->ins[7]);
10813
10814 rw = kernel_stack_up(rw);
10815 @@ -2424,8 +2437,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10816 }
10817 user_instruction_dump ((unsigned int __user *) regs->tpc);
10818 }
10819 - if (regs->tstate & TSTATE_PRIV)
10820 + if (regs->tstate & TSTATE_PRIV) {
10821 + gr_handle_kernel_exploit();
10822 do_exit(SIGKILL);
10823 + }
10824 do_exit(SIGSEGV);
10825 }
10826 EXPORT_SYMBOL(die_if_kernel);
10827 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
10828 index 35ab8b6..9046547 100644
10829 --- a/arch/sparc/kernel/unaligned_64.c
10830 +++ b/arch/sparc/kernel/unaligned_64.c
10831 @@ -295,7 +295,7 @@ static void log_unaligned(struct pt_regs *regs)
10832 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
10833
10834 if (__ratelimit(&ratelimit)) {
10835 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
10836 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
10837 regs->tpc, (void *) regs->tpc);
10838 }
10839 }
10840 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
10841 index dbe119b..089c7c1 100644
10842 --- a/arch/sparc/lib/Makefile
10843 +++ b/arch/sparc/lib/Makefile
10844 @@ -2,7 +2,7 @@
10845 #
10846
10847 asflags-y := -ansi -DST_DIV0=0x02
10848 -ccflags-y := -Werror
10849 +#ccflags-y := -Werror
10850
10851 lib-$(CONFIG_SPARC32) += ashrdi3.o
10852 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
10853 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
10854 index 85c233d..68500e0 100644
10855 --- a/arch/sparc/lib/atomic_64.S
10856 +++ b/arch/sparc/lib/atomic_64.S
10857 @@ -17,7 +17,12 @@
10858 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10859 BACKOFF_SETUP(%o2)
10860 1: lduw [%o1], %g1
10861 - add %g1, %o0, %g7
10862 + addcc %g1, %o0, %g7
10863 +
10864 +#ifdef CONFIG_PAX_REFCOUNT
10865 + tvs %icc, 6
10866 +#endif
10867 +
10868 cas [%o1], %g1, %g7
10869 cmp %g1, %g7
10870 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10871 @@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10872 2: BACKOFF_SPIN(%o2, %o3, 1b)
10873 ENDPROC(atomic_add)
10874
10875 +ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10876 + BACKOFF_SETUP(%o2)
10877 +1: lduw [%o1], %g1
10878 + add %g1, %o0, %g7
10879 + cas [%o1], %g1, %g7
10880 + cmp %g1, %g7
10881 + bne,pn %icc, 2f
10882 + nop
10883 + retl
10884 + nop
10885 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10886 +ENDPROC(atomic_add_unchecked)
10887 +
10888 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10889 BACKOFF_SETUP(%o2)
10890 1: lduw [%o1], %g1
10891 - sub %g1, %o0, %g7
10892 + subcc %g1, %o0, %g7
10893 +
10894 +#ifdef CONFIG_PAX_REFCOUNT
10895 + tvs %icc, 6
10896 +#endif
10897 +
10898 cas [%o1], %g1, %g7
10899 cmp %g1, %g7
10900 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10901 @@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10902 2: BACKOFF_SPIN(%o2, %o3, 1b)
10903 ENDPROC(atomic_sub)
10904
10905 +ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10906 + BACKOFF_SETUP(%o2)
10907 +1: lduw [%o1], %g1
10908 + sub %g1, %o0, %g7
10909 + cas [%o1], %g1, %g7
10910 + cmp %g1, %g7
10911 + bne,pn %icc, 2f
10912 + nop
10913 + retl
10914 + nop
10915 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10916 +ENDPROC(atomic_sub_unchecked)
10917 +
10918 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10919 BACKOFF_SETUP(%o2)
10920 1: lduw [%o1], %g1
10921 - add %g1, %o0, %g7
10922 + addcc %g1, %o0, %g7
10923 +
10924 +#ifdef CONFIG_PAX_REFCOUNT
10925 + tvs %icc, 6
10926 +#endif
10927 +
10928 cas [%o1], %g1, %g7
10929 cmp %g1, %g7
10930 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10931 @@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10932 2: BACKOFF_SPIN(%o2, %o3, 1b)
10933 ENDPROC(atomic_add_ret)
10934
10935 +ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10936 + BACKOFF_SETUP(%o2)
10937 +1: lduw [%o1], %g1
10938 + addcc %g1, %o0, %g7
10939 + cas [%o1], %g1, %g7
10940 + cmp %g1, %g7
10941 + bne,pn %icc, 2f
10942 + add %g7, %o0, %g7
10943 + sra %g7, 0, %o0
10944 + retl
10945 + nop
10946 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10947 +ENDPROC(atomic_add_ret_unchecked)
10948 +
10949 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10950 BACKOFF_SETUP(%o2)
10951 1: lduw [%o1], %g1
10952 - sub %g1, %o0, %g7
10953 + subcc %g1, %o0, %g7
10954 +
10955 +#ifdef CONFIG_PAX_REFCOUNT
10956 + tvs %icc, 6
10957 +#endif
10958 +
10959 cas [%o1], %g1, %g7
10960 cmp %g1, %g7
10961 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10962 @@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
10963 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10964 BACKOFF_SETUP(%o2)
10965 1: ldx [%o1], %g1
10966 - add %g1, %o0, %g7
10967 + addcc %g1, %o0, %g7
10968 +
10969 +#ifdef CONFIG_PAX_REFCOUNT
10970 + tvs %xcc, 6
10971 +#endif
10972 +
10973 casx [%o1], %g1, %g7
10974 cmp %g1, %g7
10975 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10976 @@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10977 2: BACKOFF_SPIN(%o2, %o3, 1b)
10978 ENDPROC(atomic64_add)
10979
10980 +ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10981 + BACKOFF_SETUP(%o2)
10982 +1: ldx [%o1], %g1
10983 + addcc %g1, %o0, %g7
10984 + casx [%o1], %g1, %g7
10985 + cmp %g1, %g7
10986 + bne,pn %xcc, 2f
10987 + nop
10988 + retl
10989 + nop
10990 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10991 +ENDPROC(atomic64_add_unchecked)
10992 +
10993 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10994 BACKOFF_SETUP(%o2)
10995 1: ldx [%o1], %g1
10996 - sub %g1, %o0, %g7
10997 + subcc %g1, %o0, %g7
10998 +
10999 +#ifdef CONFIG_PAX_REFCOUNT
11000 + tvs %xcc, 6
11001 +#endif
11002 +
11003 casx [%o1], %g1, %g7
11004 cmp %g1, %g7
11005 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11006 @@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
11007 2: BACKOFF_SPIN(%o2, %o3, 1b)
11008 ENDPROC(atomic64_sub)
11009
11010 +ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
11011 + BACKOFF_SETUP(%o2)
11012 +1: ldx [%o1], %g1
11013 + subcc %g1, %o0, %g7
11014 + casx [%o1], %g1, %g7
11015 + cmp %g1, %g7
11016 + bne,pn %xcc, 2f
11017 + nop
11018 + retl
11019 + nop
11020 +2: BACKOFF_SPIN(%o2, %o3, 1b)
11021 +ENDPROC(atomic64_sub_unchecked)
11022 +
11023 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11024 BACKOFF_SETUP(%o2)
11025 1: ldx [%o1], %g1
11026 - add %g1, %o0, %g7
11027 + addcc %g1, %o0, %g7
11028 +
11029 +#ifdef CONFIG_PAX_REFCOUNT
11030 + tvs %xcc, 6
11031 +#endif
11032 +
11033 casx [%o1], %g1, %g7
11034 cmp %g1, %g7
11035 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11036 @@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
11037 2: BACKOFF_SPIN(%o2, %o3, 1b)
11038 ENDPROC(atomic64_add_ret)
11039
11040 +ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
11041 + BACKOFF_SETUP(%o2)
11042 +1: ldx [%o1], %g1
11043 + addcc %g1, %o0, %g7
11044 + casx [%o1], %g1, %g7
11045 + cmp %g1, %g7
11046 + bne,pn %xcc, 2f
11047 + add %g7, %o0, %g7
11048 + mov %g7, %o0
11049 + retl
11050 + nop
11051 +2: BACKOFF_SPIN(%o2, %o3, 1b)
11052 +ENDPROC(atomic64_add_ret_unchecked)
11053 +
11054 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
11055 BACKOFF_SETUP(%o2)
11056 1: ldx [%o1], %g1
11057 - sub %g1, %o0, %g7
11058 + subcc %g1, %o0, %g7
11059 +
11060 +#ifdef CONFIG_PAX_REFCOUNT
11061 + tvs %xcc, 6
11062 +#endif
11063 +
11064 casx [%o1], %g1, %g7
11065 cmp %g1, %g7
11066 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
11067 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
11068 index 323335b..ed85ea2 100644
11069 --- a/arch/sparc/lib/ksyms.c
11070 +++ b/arch/sparc/lib/ksyms.c
11071 @@ -100,12 +100,18 @@ EXPORT_SYMBOL(__clear_user);
11072
11073 /* Atomic counter implementation. */
11074 EXPORT_SYMBOL(atomic_add);
11075 +EXPORT_SYMBOL(atomic_add_unchecked);
11076 EXPORT_SYMBOL(atomic_add_ret);
11077 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
11078 EXPORT_SYMBOL(atomic_sub);
11079 +EXPORT_SYMBOL(atomic_sub_unchecked);
11080 EXPORT_SYMBOL(atomic_sub_ret);
11081 EXPORT_SYMBOL(atomic64_add);
11082 +EXPORT_SYMBOL(atomic64_add_unchecked);
11083 EXPORT_SYMBOL(atomic64_add_ret);
11084 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
11085 EXPORT_SYMBOL(atomic64_sub);
11086 +EXPORT_SYMBOL(atomic64_sub_unchecked);
11087 EXPORT_SYMBOL(atomic64_sub_ret);
11088 EXPORT_SYMBOL(atomic64_dec_if_positive);
11089
11090 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
11091 index 30c3ecc..736f015 100644
11092 --- a/arch/sparc/mm/Makefile
11093 +++ b/arch/sparc/mm/Makefile
11094 @@ -2,7 +2,7 @@
11095 #
11096
11097 asflags-y := -ansi
11098 -ccflags-y := -Werror
11099 +#ccflags-y := -Werror
11100
11101 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
11102 obj-y += fault_$(BITS).o
11103 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
11104 index 59dbd46..1dd7f5e 100644
11105 --- a/arch/sparc/mm/fault_32.c
11106 +++ b/arch/sparc/mm/fault_32.c
11107 @@ -21,6 +21,9 @@
11108 #include <linux/perf_event.h>
11109 #include <linux/interrupt.h>
11110 #include <linux/kdebug.h>
11111 +#include <linux/slab.h>
11112 +#include <linux/pagemap.h>
11113 +#include <linux/compiler.h>
11114
11115 #include <asm/page.h>
11116 #include <asm/pgtable.h>
11117 @@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
11118 return safe_compute_effective_address(regs, insn);
11119 }
11120
11121 +#ifdef CONFIG_PAX_PAGEEXEC
11122 +#ifdef CONFIG_PAX_DLRESOLVE
11123 +static void pax_emuplt_close(struct vm_area_struct *vma)
11124 +{
11125 + vma->vm_mm->call_dl_resolve = 0UL;
11126 +}
11127 +
11128 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11129 +{
11130 + unsigned int *kaddr;
11131 +
11132 + vmf->page = alloc_page(GFP_HIGHUSER);
11133 + if (!vmf->page)
11134 + return VM_FAULT_OOM;
11135 +
11136 + kaddr = kmap(vmf->page);
11137 + memset(kaddr, 0, PAGE_SIZE);
11138 + kaddr[0] = 0x9DE3BFA8U; /* save */
11139 + flush_dcache_page(vmf->page);
11140 + kunmap(vmf->page);
11141 + return VM_FAULT_MAJOR;
11142 +}
11143 +
11144 +static const struct vm_operations_struct pax_vm_ops = {
11145 + .close = pax_emuplt_close,
11146 + .fault = pax_emuplt_fault
11147 +};
11148 +
11149 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11150 +{
11151 + int ret;
11152 +
11153 + INIT_LIST_HEAD(&vma->anon_vma_chain);
11154 + vma->vm_mm = current->mm;
11155 + vma->vm_start = addr;
11156 + vma->vm_end = addr + PAGE_SIZE;
11157 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11158 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11159 + vma->vm_ops = &pax_vm_ops;
11160 +
11161 + ret = insert_vm_struct(current->mm, vma);
11162 + if (ret)
11163 + return ret;
11164 +
11165 + ++current->mm->total_vm;
11166 + return 0;
11167 +}
11168 +#endif
11169 +
11170 +/*
11171 + * PaX: decide what to do with offenders (regs->pc = fault address)
11172 + *
11173 + * returns 1 when task should be killed
11174 + * 2 when patched PLT trampoline was detected
11175 + * 3 when unpatched PLT trampoline was detected
11176 + */
11177 +static int pax_handle_fetch_fault(struct pt_regs *regs)
11178 +{
11179 +
11180 +#ifdef CONFIG_PAX_EMUPLT
11181 + int err;
11182 +
11183 + do { /* PaX: patched PLT emulation #1 */
11184 + unsigned int sethi1, sethi2, jmpl;
11185 +
11186 + err = get_user(sethi1, (unsigned int *)regs->pc);
11187 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
11188 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
11189 +
11190 + if (err)
11191 + break;
11192 +
11193 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11194 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
11195 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
11196 + {
11197 + unsigned int addr;
11198 +
11199 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11200 + addr = regs->u_regs[UREG_G1];
11201 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11202 + regs->pc = addr;
11203 + regs->npc = addr+4;
11204 + return 2;
11205 + }
11206 + } while (0);
11207 +
11208 + do { /* PaX: patched PLT emulation #2 */
11209 + unsigned int ba;
11210 +
11211 + err = get_user(ba, (unsigned int *)regs->pc);
11212 +
11213 + if (err)
11214 + break;
11215 +
11216 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11217 + unsigned int addr;
11218 +
11219 + if ((ba & 0xFFC00000U) == 0x30800000U)
11220 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11221 + else
11222 + addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11223 + regs->pc = addr;
11224 + regs->npc = addr+4;
11225 + return 2;
11226 + }
11227 + } while (0);
11228 +
11229 + do { /* PaX: patched PLT emulation #3 */
11230 + unsigned int sethi, bajmpl, nop;
11231 +
11232 + err = get_user(sethi, (unsigned int *)regs->pc);
11233 + err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
11234 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
11235 +
11236 + if (err)
11237 + break;
11238 +
11239 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11240 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11241 + nop == 0x01000000U)
11242 + {
11243 + unsigned int addr;
11244 +
11245 + addr = (sethi & 0x003FFFFFU) << 10;
11246 + regs->u_regs[UREG_G1] = addr;
11247 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11248 + addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11249 + else
11250 + addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11251 + regs->pc = addr;
11252 + regs->npc = addr+4;
11253 + return 2;
11254 + }
11255 + } while (0);
11256 +
11257 + do { /* PaX: unpatched PLT emulation step 1 */
11258 + unsigned int sethi, ba, nop;
11259 +
11260 + err = get_user(sethi, (unsigned int *)regs->pc);
11261 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
11262 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
11263 +
11264 + if (err)
11265 + break;
11266 +
11267 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11268 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11269 + nop == 0x01000000U)
11270 + {
11271 + unsigned int addr, save, call;
11272 +
11273 + if ((ba & 0xFFC00000U) == 0x30800000U)
11274 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
11275 + else
11276 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
11277 +
11278 + err = get_user(save, (unsigned int *)addr);
11279 + err |= get_user(call, (unsigned int *)(addr+4));
11280 + err |= get_user(nop, (unsigned int *)(addr+8));
11281 + if (err)
11282 + break;
11283 +
11284 +#ifdef CONFIG_PAX_DLRESOLVE
11285 + if (save == 0x9DE3BFA8U &&
11286 + (call & 0xC0000000U) == 0x40000000U &&
11287 + nop == 0x01000000U)
11288 + {
11289 + struct vm_area_struct *vma;
11290 + unsigned long call_dl_resolve;
11291 +
11292 + down_read(&current->mm->mmap_sem);
11293 + call_dl_resolve = current->mm->call_dl_resolve;
11294 + up_read(&current->mm->mmap_sem);
11295 + if (likely(call_dl_resolve))
11296 + goto emulate;
11297 +
11298 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11299 +
11300 + down_write(&current->mm->mmap_sem);
11301 + if (current->mm->call_dl_resolve) {
11302 + call_dl_resolve = current->mm->call_dl_resolve;
11303 + up_write(&current->mm->mmap_sem);
11304 + if (vma)
11305 + kmem_cache_free(vm_area_cachep, vma);
11306 + goto emulate;
11307 + }
11308 +
11309 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11310 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11311 + up_write(&current->mm->mmap_sem);
11312 + if (vma)
11313 + kmem_cache_free(vm_area_cachep, vma);
11314 + return 1;
11315 + }
11316 +
11317 + if (pax_insert_vma(vma, call_dl_resolve)) {
11318 + up_write(&current->mm->mmap_sem);
11319 + kmem_cache_free(vm_area_cachep, vma);
11320 + return 1;
11321 + }
11322 +
11323 + current->mm->call_dl_resolve = call_dl_resolve;
11324 + up_write(&current->mm->mmap_sem);
11325 +
11326 +emulate:
11327 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11328 + regs->pc = call_dl_resolve;
11329 + regs->npc = addr+4;
11330 + return 3;
11331 + }
11332 +#endif
11333 +
11334 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11335 + if ((save & 0xFFC00000U) == 0x05000000U &&
11336 + (call & 0xFFFFE000U) == 0x85C0A000U &&
11337 + nop == 0x01000000U)
11338 + {
11339 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11340 + regs->u_regs[UREG_G2] = addr + 4;
11341 + addr = (save & 0x003FFFFFU) << 10;
11342 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
11343 + regs->pc = addr;
11344 + regs->npc = addr+4;
11345 + return 3;
11346 + }
11347 + }
11348 + } while (0);
11349 +
11350 + do { /* PaX: unpatched PLT emulation step 2 */
11351 + unsigned int save, call, nop;
11352 +
11353 + err = get_user(save, (unsigned int *)(regs->pc-4));
11354 + err |= get_user(call, (unsigned int *)regs->pc);
11355 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
11356 + if (err)
11357 + break;
11358 +
11359 + if (save == 0x9DE3BFA8U &&
11360 + (call & 0xC0000000U) == 0x40000000U &&
11361 + nop == 0x01000000U)
11362 + {
11363 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
11364 +
11365 + regs->u_regs[UREG_RETPC] = regs->pc;
11366 + regs->pc = dl_resolve;
11367 + regs->npc = dl_resolve+4;
11368 + return 3;
11369 + }
11370 + } while (0);
11371 +#endif
11372 +
11373 + return 1;
11374 +}
11375 +
11376 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11377 +{
11378 + unsigned long i;
11379 +
11380 + printk(KERN_ERR "PAX: bytes at PC: ");
11381 + for (i = 0; i < 8; i++) {
11382 + unsigned int c;
11383 + if (get_user(c, (unsigned int *)pc+i))
11384 + printk(KERN_CONT "???????? ");
11385 + else
11386 + printk(KERN_CONT "%08x ", c);
11387 + }
11388 + printk("\n");
11389 +}
11390 +#endif
11391 +
11392 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
11393 int text_fault)
11394 {
11395 @@ -229,6 +503,24 @@ good_area:
11396 if (!(vma->vm_flags & VM_WRITE))
11397 goto bad_area;
11398 } else {
11399 +
11400 +#ifdef CONFIG_PAX_PAGEEXEC
11401 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
11402 + up_read(&mm->mmap_sem);
11403 + switch (pax_handle_fetch_fault(regs)) {
11404 +
11405 +#ifdef CONFIG_PAX_EMUPLT
11406 + case 2:
11407 + case 3:
11408 + return;
11409 +#endif
11410 +
11411 + }
11412 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
11413 + do_group_exit(SIGKILL);
11414 + }
11415 +#endif
11416 +
11417 /* Allow reads even for write-only mappings */
11418 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
11419 goto bad_area;
11420 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
11421 index 4ced3fc..234f1e4 100644
11422 --- a/arch/sparc/mm/fault_64.c
11423 +++ b/arch/sparc/mm/fault_64.c
11424 @@ -22,6 +22,9 @@
11425 #include <linux/kdebug.h>
11426 #include <linux/percpu.h>
11427 #include <linux/context_tracking.h>
11428 +#include <linux/slab.h>
11429 +#include <linux/pagemap.h>
11430 +#include <linux/compiler.h>
11431
11432 #include <asm/page.h>
11433 #include <asm/pgtable.h>
11434 @@ -75,7 +78,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
11435 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
11436 regs->tpc);
11437 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
11438 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
11439 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
11440 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
11441 dump_stack();
11442 unhandled_fault(regs->tpc, current, regs);
11443 @@ -281,6 +284,466 @@ static void noinline __kprobes bogus_32bit_fault_tpc(struct pt_regs *regs)
11444 show_regs(regs);
11445 }
11446
11447 +#ifdef CONFIG_PAX_PAGEEXEC
11448 +#ifdef CONFIG_PAX_DLRESOLVE
11449 +static void pax_emuplt_close(struct vm_area_struct *vma)
11450 +{
11451 + vma->vm_mm->call_dl_resolve = 0UL;
11452 +}
11453 +
11454 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
11455 +{
11456 + unsigned int *kaddr;
11457 +
11458 + vmf->page = alloc_page(GFP_HIGHUSER);
11459 + if (!vmf->page)
11460 + return VM_FAULT_OOM;
11461 +
11462 + kaddr = kmap(vmf->page);
11463 + memset(kaddr, 0, PAGE_SIZE);
11464 + kaddr[0] = 0x9DE3BFA8U; /* save */
11465 + flush_dcache_page(vmf->page);
11466 + kunmap(vmf->page);
11467 + return VM_FAULT_MAJOR;
11468 +}
11469 +
11470 +static const struct vm_operations_struct pax_vm_ops = {
11471 + .close = pax_emuplt_close,
11472 + .fault = pax_emuplt_fault
11473 +};
11474 +
11475 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
11476 +{
11477 + int ret;
11478 +
11479 + INIT_LIST_HEAD(&vma->anon_vma_chain);
11480 + vma->vm_mm = current->mm;
11481 + vma->vm_start = addr;
11482 + vma->vm_end = addr + PAGE_SIZE;
11483 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
11484 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
11485 + vma->vm_ops = &pax_vm_ops;
11486 +
11487 + ret = insert_vm_struct(current->mm, vma);
11488 + if (ret)
11489 + return ret;
11490 +
11491 + ++current->mm->total_vm;
11492 + return 0;
11493 +}
11494 +#endif
11495 +
11496 +/*
11497 + * PaX: decide what to do with offenders (regs->tpc = fault address)
11498 + *
11499 + * returns 1 when task should be killed
11500 + * 2 when patched PLT trampoline was detected
11501 + * 3 when unpatched PLT trampoline was detected
11502 + */
11503 +static int pax_handle_fetch_fault(struct pt_regs *regs)
11504 +{
11505 +
11506 +#ifdef CONFIG_PAX_EMUPLT
11507 + int err;
11508 +
11509 + do { /* PaX: patched PLT emulation #1 */
11510 + unsigned int sethi1, sethi2, jmpl;
11511 +
11512 + err = get_user(sethi1, (unsigned int *)regs->tpc);
11513 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
11514 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
11515 +
11516 + if (err)
11517 + break;
11518 +
11519 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
11520 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
11521 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
11522 + {
11523 + unsigned long addr;
11524 +
11525 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
11526 + addr = regs->u_regs[UREG_G1];
11527 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11528 +
11529 + if (test_thread_flag(TIF_32BIT))
11530 + addr &= 0xFFFFFFFFUL;
11531 +
11532 + regs->tpc = addr;
11533 + regs->tnpc = addr+4;
11534 + return 2;
11535 + }
11536 + } while (0);
11537 +
11538 + do { /* PaX: patched PLT emulation #2 */
11539 + unsigned int ba;
11540 +
11541 + err = get_user(ba, (unsigned int *)regs->tpc);
11542 +
11543 + if (err)
11544 + break;
11545 +
11546 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
11547 + unsigned long addr;
11548 +
11549 + if ((ba & 0xFFC00000U) == 0x30800000U)
11550 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11551 + else
11552 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11553 +
11554 + if (test_thread_flag(TIF_32BIT))
11555 + addr &= 0xFFFFFFFFUL;
11556 +
11557 + regs->tpc = addr;
11558 + regs->tnpc = addr+4;
11559 + return 2;
11560 + }
11561 + } while (0);
11562 +
11563 + do { /* PaX: patched PLT emulation #3 */
11564 + unsigned int sethi, bajmpl, nop;
11565 +
11566 + err = get_user(sethi, (unsigned int *)regs->tpc);
11567 + err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
11568 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11569 +
11570 + if (err)
11571 + break;
11572 +
11573 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11574 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
11575 + nop == 0x01000000U)
11576 + {
11577 + unsigned long addr;
11578 +
11579 + addr = (sethi & 0x003FFFFFU) << 10;
11580 + regs->u_regs[UREG_G1] = addr;
11581 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
11582 + addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11583 + else
11584 + addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11585 +
11586 + if (test_thread_flag(TIF_32BIT))
11587 + addr &= 0xFFFFFFFFUL;
11588 +
11589 + regs->tpc = addr;
11590 + regs->tnpc = addr+4;
11591 + return 2;
11592 + }
11593 + } while (0);
11594 +
11595 + do { /* PaX: patched PLT emulation #4 */
11596 + unsigned int sethi, mov1, call, mov2;
11597 +
11598 + err = get_user(sethi, (unsigned int *)regs->tpc);
11599 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
11600 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
11601 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
11602 +
11603 + if (err)
11604 + break;
11605 +
11606 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11607 + mov1 == 0x8210000FU &&
11608 + (call & 0xC0000000U) == 0x40000000U &&
11609 + mov2 == 0x9E100001U)
11610 + {
11611 + unsigned long addr;
11612 +
11613 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
11614 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11615 +
11616 + if (test_thread_flag(TIF_32BIT))
11617 + addr &= 0xFFFFFFFFUL;
11618 +
11619 + regs->tpc = addr;
11620 + regs->tnpc = addr+4;
11621 + return 2;
11622 + }
11623 + } while (0);
11624 +
11625 + do { /* PaX: patched PLT emulation #5 */
11626 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
11627 +
11628 + err = get_user(sethi, (unsigned int *)regs->tpc);
11629 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11630 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11631 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
11632 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
11633 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
11634 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
11635 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
11636 +
11637 + if (err)
11638 + break;
11639 +
11640 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11641 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
11642 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11643 + (or1 & 0xFFFFE000U) == 0x82106000U &&
11644 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
11645 + sllx == 0x83287020U &&
11646 + jmpl == 0x81C04005U &&
11647 + nop == 0x01000000U)
11648 + {
11649 + unsigned long addr;
11650 +
11651 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11652 + regs->u_regs[UREG_G1] <<= 32;
11653 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11654 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11655 + regs->tpc = addr;
11656 + regs->tnpc = addr+4;
11657 + return 2;
11658 + }
11659 + } while (0);
11660 +
11661 + do { /* PaX: patched PLT emulation #6 */
11662 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
11663 +
11664 + err = get_user(sethi, (unsigned int *)regs->tpc);
11665 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11666 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11667 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
11668 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
11669 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
11670 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
11671 +
11672 + if (err)
11673 + break;
11674 +
11675 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11676 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
11677 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11678 + sllx == 0x83287020U &&
11679 + (or & 0xFFFFE000U) == 0x8A116000U &&
11680 + jmpl == 0x81C04005U &&
11681 + nop == 0x01000000U)
11682 + {
11683 + unsigned long addr;
11684 +
11685 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
11686 + regs->u_regs[UREG_G1] <<= 32;
11687 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
11688 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11689 + regs->tpc = addr;
11690 + regs->tnpc = addr+4;
11691 + return 2;
11692 + }
11693 + } while (0);
11694 +
11695 + do { /* PaX: unpatched PLT emulation step 1 */
11696 + unsigned int sethi, ba, nop;
11697 +
11698 + err = get_user(sethi, (unsigned int *)regs->tpc);
11699 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11700 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11701 +
11702 + if (err)
11703 + break;
11704 +
11705 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11706 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11707 + nop == 0x01000000U)
11708 + {
11709 + unsigned long addr;
11710 + unsigned int save, call;
11711 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
11712 +
11713 + if ((ba & 0xFFC00000U) == 0x30800000U)
11714 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11715 + else
11716 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11717 +
11718 + if (test_thread_flag(TIF_32BIT))
11719 + addr &= 0xFFFFFFFFUL;
11720 +
11721 + err = get_user(save, (unsigned int *)addr);
11722 + err |= get_user(call, (unsigned int *)(addr+4));
11723 + err |= get_user(nop, (unsigned int *)(addr+8));
11724 + if (err)
11725 + break;
11726 +
11727 +#ifdef CONFIG_PAX_DLRESOLVE
11728 + if (save == 0x9DE3BFA8U &&
11729 + (call & 0xC0000000U) == 0x40000000U &&
11730 + nop == 0x01000000U)
11731 + {
11732 + struct vm_area_struct *vma;
11733 + unsigned long call_dl_resolve;
11734 +
11735 + down_read(&current->mm->mmap_sem);
11736 + call_dl_resolve = current->mm->call_dl_resolve;
11737 + up_read(&current->mm->mmap_sem);
11738 + if (likely(call_dl_resolve))
11739 + goto emulate;
11740 +
11741 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11742 +
11743 + down_write(&current->mm->mmap_sem);
11744 + if (current->mm->call_dl_resolve) {
11745 + call_dl_resolve = current->mm->call_dl_resolve;
11746 + up_write(&current->mm->mmap_sem);
11747 + if (vma)
11748 + kmem_cache_free(vm_area_cachep, vma);
11749 + goto emulate;
11750 + }
11751 +
11752 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11753 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11754 + up_write(&current->mm->mmap_sem);
11755 + if (vma)
11756 + kmem_cache_free(vm_area_cachep, vma);
11757 + return 1;
11758 + }
11759 +
11760 + if (pax_insert_vma(vma, call_dl_resolve)) {
11761 + up_write(&current->mm->mmap_sem);
11762 + kmem_cache_free(vm_area_cachep, vma);
11763 + return 1;
11764 + }
11765 +
11766 + current->mm->call_dl_resolve = call_dl_resolve;
11767 + up_write(&current->mm->mmap_sem);
11768 +
11769 +emulate:
11770 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11771 + regs->tpc = call_dl_resolve;
11772 + regs->tnpc = addr+4;
11773 + return 3;
11774 + }
11775 +#endif
11776 +
11777 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11778 + if ((save & 0xFFC00000U) == 0x05000000U &&
11779 + (call & 0xFFFFE000U) == 0x85C0A000U &&
11780 + nop == 0x01000000U)
11781 + {
11782 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11783 + regs->u_regs[UREG_G2] = addr + 4;
11784 + addr = (save & 0x003FFFFFU) << 10;
11785 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11786 +
11787 + if (test_thread_flag(TIF_32BIT))
11788 + addr &= 0xFFFFFFFFUL;
11789 +
11790 + regs->tpc = addr;
11791 + regs->tnpc = addr+4;
11792 + return 3;
11793 + }
11794 +
11795 + /* PaX: 64-bit PLT stub */
11796 + err = get_user(sethi1, (unsigned int *)addr);
11797 + err |= get_user(sethi2, (unsigned int *)(addr+4));
11798 + err |= get_user(or1, (unsigned int *)(addr+8));
11799 + err |= get_user(or2, (unsigned int *)(addr+12));
11800 + err |= get_user(sllx, (unsigned int *)(addr+16));
11801 + err |= get_user(add, (unsigned int *)(addr+20));
11802 + err |= get_user(jmpl, (unsigned int *)(addr+24));
11803 + err |= get_user(nop, (unsigned int *)(addr+28));
11804 + if (err)
11805 + break;
11806 +
11807 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
11808 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11809 + (or1 & 0xFFFFE000U) == 0x88112000U &&
11810 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
11811 + sllx == 0x89293020U &&
11812 + add == 0x8A010005U &&
11813 + jmpl == 0x89C14000U &&
11814 + nop == 0x01000000U)
11815 + {
11816 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11817 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11818 + regs->u_regs[UREG_G4] <<= 32;
11819 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11820 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
11821 + regs->u_regs[UREG_G4] = addr + 24;
11822 + addr = regs->u_regs[UREG_G5];
11823 + regs->tpc = addr;
11824 + regs->tnpc = addr+4;
11825 + return 3;
11826 + }
11827 + }
11828 + } while (0);
11829 +
11830 +#ifdef CONFIG_PAX_DLRESOLVE
11831 + do { /* PaX: unpatched PLT emulation step 2 */
11832 + unsigned int save, call, nop;
11833 +
11834 + err = get_user(save, (unsigned int *)(regs->tpc-4));
11835 + err |= get_user(call, (unsigned int *)regs->tpc);
11836 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
11837 + if (err)
11838 + break;
11839 +
11840 + if (save == 0x9DE3BFA8U &&
11841 + (call & 0xC0000000U) == 0x40000000U &&
11842 + nop == 0x01000000U)
11843 + {
11844 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11845 +
11846 + if (test_thread_flag(TIF_32BIT))
11847 + dl_resolve &= 0xFFFFFFFFUL;
11848 +
11849 + regs->u_regs[UREG_RETPC] = regs->tpc;
11850 + regs->tpc = dl_resolve;
11851 + regs->tnpc = dl_resolve+4;
11852 + return 3;
11853 + }
11854 + } while (0);
11855 +#endif
11856 +
11857 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
11858 + unsigned int sethi, ba, nop;
11859 +
11860 + err = get_user(sethi, (unsigned int *)regs->tpc);
11861 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11862 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11863 +
11864 + if (err)
11865 + break;
11866 +
11867 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11868 + (ba & 0xFFF00000U) == 0x30600000U &&
11869 + nop == 0x01000000U)
11870 + {
11871 + unsigned long addr;
11872 +
11873 + addr = (sethi & 0x003FFFFFU) << 10;
11874 + regs->u_regs[UREG_G1] = addr;
11875 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11876 +
11877 + if (test_thread_flag(TIF_32BIT))
11878 + addr &= 0xFFFFFFFFUL;
11879 +
11880 + regs->tpc = addr;
11881 + regs->tnpc = addr+4;
11882 + return 2;
11883 + }
11884 + } while (0);
11885 +
11886 +#endif
11887 +
11888 + return 1;
11889 +}
11890 +
11891 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11892 +{
11893 + unsigned long i;
11894 +
11895 + printk(KERN_ERR "PAX: bytes at PC: ");
11896 + for (i = 0; i < 8; i++) {
11897 + unsigned int c;
11898 + if (get_user(c, (unsigned int *)pc+i))
11899 + printk(KERN_CONT "???????? ");
11900 + else
11901 + printk(KERN_CONT "%08x ", c);
11902 + }
11903 + printk("\n");
11904 +}
11905 +#endif
11906 +
11907 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
11908 {
11909 enum ctx_state prev_state = exception_enter();
11910 @@ -352,6 +815,29 @@ retry:
11911 if (!vma)
11912 goto bad_area;
11913
11914 +#ifdef CONFIG_PAX_PAGEEXEC
11915 + /* PaX: detect ITLB misses on non-exec pages */
11916 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
11917 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
11918 + {
11919 + if (address != regs->tpc)
11920 + goto good_area;
11921 +
11922 + up_read(&mm->mmap_sem);
11923 + switch (pax_handle_fetch_fault(regs)) {
11924 +
11925 +#ifdef CONFIG_PAX_EMUPLT
11926 + case 2:
11927 + case 3:
11928 + return;
11929 +#endif
11930 +
11931 + }
11932 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
11933 + do_group_exit(SIGKILL);
11934 + }
11935 +#endif
11936 +
11937 /* Pure DTLB misses do not tell us whether the fault causing
11938 * load/store/atomic was a write or not, it only says that there
11939 * was no match. So in such a case we (carefully) read the
11940 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
11941 index d329537..2c3746a 100644
11942 --- a/arch/sparc/mm/hugetlbpage.c
11943 +++ b/arch/sparc/mm/hugetlbpage.c
11944 @@ -25,8 +25,10 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11945 unsigned long addr,
11946 unsigned long len,
11947 unsigned long pgoff,
11948 - unsigned long flags)
11949 + unsigned long flags,
11950 + unsigned long offset)
11951 {
11952 + struct mm_struct *mm = current->mm;
11953 unsigned long task_size = TASK_SIZE;
11954 struct vm_unmapped_area_info info;
11955
11956 @@ -35,15 +37,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11957
11958 info.flags = 0;
11959 info.length = len;
11960 - info.low_limit = TASK_UNMAPPED_BASE;
11961 + info.low_limit = mm->mmap_base;
11962 info.high_limit = min(task_size, VA_EXCLUDE_START);
11963 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11964 info.align_offset = 0;
11965 + info.threadstack_offset = offset;
11966 addr = vm_unmapped_area(&info);
11967
11968 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
11969 VM_BUG_ON(addr != -ENOMEM);
11970 info.low_limit = VA_EXCLUDE_END;
11971 +
11972 +#ifdef CONFIG_PAX_RANDMMAP
11973 + if (mm->pax_flags & MF_PAX_RANDMMAP)
11974 + info.low_limit += mm->delta_mmap;
11975 +#endif
11976 +
11977 info.high_limit = task_size;
11978 addr = vm_unmapped_area(&info);
11979 }
11980 @@ -55,7 +64,8 @@ static unsigned long
11981 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11982 const unsigned long len,
11983 const unsigned long pgoff,
11984 - const unsigned long flags)
11985 + const unsigned long flags,
11986 + const unsigned long offset)
11987 {
11988 struct mm_struct *mm = current->mm;
11989 unsigned long addr = addr0;
11990 @@ -70,6 +80,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11991 info.high_limit = mm->mmap_base;
11992 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11993 info.align_offset = 0;
11994 + info.threadstack_offset = offset;
11995 addr = vm_unmapped_area(&info);
11996
11997 /*
11998 @@ -82,6 +93,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11999 VM_BUG_ON(addr != -ENOMEM);
12000 info.flags = 0;
12001 info.low_limit = TASK_UNMAPPED_BASE;
12002 +
12003 +#ifdef CONFIG_PAX_RANDMMAP
12004 + if (mm->pax_flags & MF_PAX_RANDMMAP)
12005 + info.low_limit += mm->delta_mmap;
12006 +#endif
12007 +
12008 info.high_limit = STACK_TOP32;
12009 addr = vm_unmapped_area(&info);
12010 }
12011 @@ -96,6 +113,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
12012 struct mm_struct *mm = current->mm;
12013 struct vm_area_struct *vma;
12014 unsigned long task_size = TASK_SIZE;
12015 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
12016
12017 if (test_thread_flag(TIF_32BIT))
12018 task_size = STACK_TOP32;
12019 @@ -111,19 +129,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
12020 return addr;
12021 }
12022
12023 +#ifdef CONFIG_PAX_RANDMMAP
12024 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
12025 +#endif
12026 +
12027 if (addr) {
12028 addr = ALIGN(addr, HPAGE_SIZE);
12029 vma = find_vma(mm, addr);
12030 - if (task_size - len >= addr &&
12031 - (!vma || addr + len <= vma->vm_start))
12032 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
12033 return addr;
12034 }
12035 if (mm->get_unmapped_area == arch_get_unmapped_area)
12036 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
12037 - pgoff, flags);
12038 + pgoff, flags, offset);
12039 else
12040 return hugetlb_get_unmapped_area_topdown(file, addr, len,
12041 - pgoff, flags);
12042 + pgoff, flags, offset);
12043 }
12044
12045 pte_t *huge_pte_alloc(struct mm_struct *mm,
12046 diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
12047 index ed3c969..42fe48d 100644
12048 --- a/arch/sparc/mm/init_64.c
12049 +++ b/arch/sparc/mm/init_64.c
12050 @@ -188,9 +188,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
12051 int num_kernel_image_mappings;
12052
12053 #ifdef CONFIG_DEBUG_DCFLUSH
12054 -atomic_t dcpage_flushes = ATOMIC_INIT(0);
12055 +atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
12056 #ifdef CONFIG_SMP
12057 -atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
12058 +atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
12059 #endif
12060 #endif
12061
12062 @@ -198,7 +198,7 @@ inline void flush_dcache_page_impl(struct page *page)
12063 {
12064 BUG_ON(tlb_type == hypervisor);
12065 #ifdef CONFIG_DEBUG_DCFLUSH
12066 - atomic_inc(&dcpage_flushes);
12067 + atomic_inc_unchecked(&dcpage_flushes);
12068 #endif
12069
12070 #ifdef DCACHE_ALIASING_POSSIBLE
12071 @@ -466,10 +466,10 @@ void mmu_info(struct seq_file *m)
12072
12073 #ifdef CONFIG_DEBUG_DCFLUSH
12074 seq_printf(m, "DCPageFlushes\t: %d\n",
12075 - atomic_read(&dcpage_flushes));
12076 + atomic_read_unchecked(&dcpage_flushes));
12077 #ifdef CONFIG_SMP
12078 seq_printf(m, "DCPageFlushesXC\t: %d\n",
12079 - atomic_read(&dcpage_flushes_xcall));
12080 + atomic_read_unchecked(&dcpage_flushes_xcall));
12081 #endif /* CONFIG_SMP */
12082 #endif /* CONFIG_DEBUG_DCFLUSH */
12083 }
12084 diff --git a/arch/tile/Kconfig b/arch/tile/Kconfig
12085 index 85258ca..df97c79 100644
12086 --- a/arch/tile/Kconfig
12087 +++ b/arch/tile/Kconfig
12088 @@ -190,6 +190,7 @@ source "kernel/Kconfig.hz"
12089
12090 config KEXEC
12091 bool "kexec system call"
12092 + depends on !GRKERNSEC_KMEM
12093 ---help---
12094 kexec is a system call that implements the ability to shutdown your
12095 current kernel, and to start another kernel. It is like a reboot
12096 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
12097 index ad220ee..2f537b3 100644
12098 --- a/arch/tile/include/asm/atomic_64.h
12099 +++ b/arch/tile/include/asm/atomic_64.h
12100 @@ -105,6 +105,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
12101
12102 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
12103
12104 +#define atomic64_read_unchecked(v) atomic64_read(v)
12105 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
12106 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
12107 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
12108 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
12109 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
12110 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
12111 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
12112 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
12113 +
12114 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
12115 #define smp_mb__before_atomic_dec() smp_mb()
12116 #define smp_mb__after_atomic_dec() smp_mb()
12117 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
12118 index 6160761..00cac88 100644
12119 --- a/arch/tile/include/asm/cache.h
12120 +++ b/arch/tile/include/asm/cache.h
12121 @@ -15,11 +15,12 @@
12122 #ifndef _ASM_TILE_CACHE_H
12123 #define _ASM_TILE_CACHE_H
12124
12125 +#include <linux/const.h>
12126 #include <arch/chip.h>
12127
12128 /* bytes per L1 data cache line */
12129 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
12130 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12131 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12132
12133 /* bytes per L2 cache line */
12134 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
12135 diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
12136 index b6cde32..c0cb736 100644
12137 --- a/arch/tile/include/asm/uaccess.h
12138 +++ b/arch/tile/include/asm/uaccess.h
12139 @@ -414,9 +414,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
12140 const void __user *from,
12141 unsigned long n)
12142 {
12143 - int sz = __compiletime_object_size(to);
12144 + size_t sz = __compiletime_object_size(to);
12145
12146 - if (likely(sz == -1 || sz >= n))
12147 + if (likely(sz == (size_t)-1 || sz >= n))
12148 n = _copy_from_user(to, from, n);
12149 else
12150 copy_from_user_overflow();
12151 diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
12152 index e514899..f8743c4 100644
12153 --- a/arch/tile/mm/hugetlbpage.c
12154 +++ b/arch/tile/mm/hugetlbpage.c
12155 @@ -207,6 +207,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
12156 info.high_limit = TASK_SIZE;
12157 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12158 info.align_offset = 0;
12159 + info.threadstack_offset = 0;
12160 return vm_unmapped_area(&info);
12161 }
12162
12163 @@ -224,6 +225,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
12164 info.high_limit = current->mm->mmap_base;
12165 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
12166 info.align_offset = 0;
12167 + info.threadstack_offset = 0;
12168 addr = vm_unmapped_area(&info);
12169
12170 /*
12171 diff --git a/arch/um/Makefile b/arch/um/Makefile
12172 index 36e658a..71a5c5a 100644
12173 --- a/arch/um/Makefile
12174 +++ b/arch/um/Makefile
12175 @@ -72,6 +72,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
12176 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
12177 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
12178
12179 +ifdef CONSTIFY_PLUGIN
12180 +USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12181 +endif
12182 +
12183 #This will adjust *FLAGS accordingly to the platform.
12184 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
12185
12186 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
12187 index 19e1bdd..3665b77 100644
12188 --- a/arch/um/include/asm/cache.h
12189 +++ b/arch/um/include/asm/cache.h
12190 @@ -1,6 +1,7 @@
12191 #ifndef __UM_CACHE_H
12192 #define __UM_CACHE_H
12193
12194 +#include <linux/const.h>
12195
12196 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
12197 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
12198 @@ -12,6 +13,6 @@
12199 # define L1_CACHE_SHIFT 5
12200 #endif
12201
12202 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12203 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12204
12205 #endif
12206 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
12207 index 2e0a6b1..a64d0f5 100644
12208 --- a/arch/um/include/asm/kmap_types.h
12209 +++ b/arch/um/include/asm/kmap_types.h
12210 @@ -8,6 +8,6 @@
12211
12212 /* No more #include "asm/arch/kmap_types.h" ! */
12213
12214 -#define KM_TYPE_NR 14
12215 +#define KM_TYPE_NR 15
12216
12217 #endif
12218 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
12219 index 5ff53d9..5850cdf 100644
12220 --- a/arch/um/include/asm/page.h
12221 +++ b/arch/um/include/asm/page.h
12222 @@ -14,6 +14,9 @@
12223 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
12224 #define PAGE_MASK (~(PAGE_SIZE-1))
12225
12226 +#define ktla_ktva(addr) (addr)
12227 +#define ktva_ktla(addr) (addr)
12228 +
12229 #ifndef __ASSEMBLY__
12230
12231 struct page;
12232 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
12233 index 0032f92..cd151e0 100644
12234 --- a/arch/um/include/asm/pgtable-3level.h
12235 +++ b/arch/um/include/asm/pgtable-3level.h
12236 @@ -58,6 +58,7 @@
12237 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
12238 #define pud_populate(mm, pud, pmd) \
12239 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
12240 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
12241
12242 #ifdef CONFIG_64BIT
12243 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
12244 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
12245 index f17bca8..48adb87 100644
12246 --- a/arch/um/kernel/process.c
12247 +++ b/arch/um/kernel/process.c
12248 @@ -356,22 +356,6 @@ int singlestepping(void * t)
12249 return 2;
12250 }
12251
12252 -/*
12253 - * Only x86 and x86_64 have an arch_align_stack().
12254 - * All other arches have "#define arch_align_stack(x) (x)"
12255 - * in their asm/exec.h
12256 - * As this is included in UML from asm-um/system-generic.h,
12257 - * we can use it to behave as the subarch does.
12258 - */
12259 -#ifndef arch_align_stack
12260 -unsigned long arch_align_stack(unsigned long sp)
12261 -{
12262 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
12263 - sp -= get_random_int() % 8192;
12264 - return sp & ~0xf;
12265 -}
12266 -#endif
12267 -
12268 unsigned long get_wchan(struct task_struct *p)
12269 {
12270 unsigned long stack_page, sp, ip;
12271 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
12272 index ad8f795..2c7eec6 100644
12273 --- a/arch/unicore32/include/asm/cache.h
12274 +++ b/arch/unicore32/include/asm/cache.h
12275 @@ -12,8 +12,10 @@
12276 #ifndef __UNICORE_CACHE_H__
12277 #define __UNICORE_CACHE_H__
12278
12279 -#define L1_CACHE_SHIFT (5)
12280 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
12281 +#include <linux/const.h>
12282 +
12283 +#define L1_CACHE_SHIFT 5
12284 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
12285
12286 /*
12287 * Memory returned by kmalloc() may be used for DMA, so we must make
12288 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
12289 index 6b8b429..7b21fe4 100644
12290 --- a/arch/x86/Kconfig
12291 +++ b/arch/x86/Kconfig
12292 @@ -127,7 +127,7 @@ config X86
12293 select RTC_LIB
12294 select HAVE_DEBUG_STACKOVERFLOW
12295 select HAVE_IRQ_EXIT_ON_IRQ_STACK if X86_64
12296 - select HAVE_CC_STACKPROTECTOR
12297 + select HAVE_CC_STACKPROTECTOR if X86_64 || !PAX_MEMORY_UDEREF
12298 select GENERIC_CPU_AUTOPROBE
12299 select HAVE_ARCH_AUDITSYSCALL
12300
12301 @@ -251,7 +251,7 @@ config X86_HT
12302
12303 config X86_32_LAZY_GS
12304 def_bool y
12305 - depends on X86_32 && !CC_STACKPROTECTOR
12306 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
12307
12308 config ARCH_HWEIGHT_CFLAGS
12309 string
12310 @@ -545,6 +545,7 @@ config SCHED_OMIT_FRAME_POINTER
12311
12312 menuconfig HYPERVISOR_GUEST
12313 bool "Linux guest support"
12314 + depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_GUEST || (GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_XEN)
12315 ---help---
12316 Say Y here to enable options for running Linux under various hyper-
12317 visors. This option enables basic hypervisor detection and platform
12318 @@ -1054,6 +1055,7 @@ choice
12319
12320 config NOHIGHMEM
12321 bool "off"
12322 + depends on !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12323 ---help---
12324 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
12325 However, the address space of 32-bit x86 processors is only 4
12326 @@ -1090,6 +1092,7 @@ config NOHIGHMEM
12327
12328 config HIGHMEM4G
12329 bool "4GB"
12330 + depends on !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
12331 ---help---
12332 Select this if you have a 32-bit processor and between 1 and 4
12333 gigabytes of physical RAM.
12334 @@ -1142,7 +1145,7 @@ config PAGE_OFFSET
12335 hex
12336 default 0xB0000000 if VMSPLIT_3G_OPT
12337 default 0x80000000 if VMSPLIT_2G
12338 - default 0x78000000 if VMSPLIT_2G_OPT
12339 + default 0x70000000 if VMSPLIT_2G_OPT
12340 default 0x40000000 if VMSPLIT_1G
12341 default 0xC0000000
12342 depends on X86_32
12343 @@ -1555,6 +1558,7 @@ source kernel/Kconfig.hz
12344
12345 config KEXEC
12346 bool "kexec system call"
12347 + depends on !GRKERNSEC_KMEM
12348 ---help---
12349 kexec is a system call that implements the ability to shutdown your
12350 current kernel, and to start another kernel. It is like a reboot
12351 @@ -1706,7 +1710,9 @@ config X86_NEED_RELOCS
12352
12353 config PHYSICAL_ALIGN
12354 hex "Alignment value to which kernel should be aligned"
12355 - default "0x200000"
12356 + default "0x1000000"
12357 + range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
12358 + range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
12359 range 0x2000 0x1000000 if X86_32
12360 range 0x200000 0x1000000 if X86_64
12361 ---help---
12362 @@ -1789,6 +1795,7 @@ config COMPAT_VDSO
12363 def_bool n
12364 prompt "Disable the 32-bit vDSO (needed for glibc 2.3.3)"
12365 depends on X86_32 || IA32_EMULATION
12366 + depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
12367 ---help---
12368 Certain buggy versions of glibc will crash if they are
12369 presented with a 32-bit vDSO that is not mapped at the address
12370 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
12371 index 6983314..54ad7e8 100644
12372 --- a/arch/x86/Kconfig.cpu
12373 +++ b/arch/x86/Kconfig.cpu
12374 @@ -319,7 +319,7 @@ config X86_PPRO_FENCE
12375
12376 config X86_F00F_BUG
12377 def_bool y
12378 - depends on M586MMX || M586TSC || M586 || M486
12379 + depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
12380
12381 config X86_INVD_BUG
12382 def_bool y
12383 @@ -327,7 +327,7 @@ config X86_INVD_BUG
12384
12385 config X86_ALIGNMENT_16
12386 def_bool y
12387 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12388 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
12389
12390 config X86_INTEL_USERCOPY
12391 def_bool y
12392 @@ -369,7 +369,7 @@ config X86_CMPXCHG64
12393 # generates cmov.
12394 config X86_CMOV
12395 def_bool y
12396 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12397 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
12398
12399 config X86_MINIMUM_CPU_FAMILY
12400 int
12401 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
12402 index 61bd2ad..50b625d 100644
12403 --- a/arch/x86/Kconfig.debug
12404 +++ b/arch/x86/Kconfig.debug
12405 @@ -93,7 +93,7 @@ config EFI_PGT_DUMP
12406 config DEBUG_RODATA
12407 bool "Write protect kernel read-only data structures"
12408 default y
12409 - depends on DEBUG_KERNEL
12410 + depends on DEBUG_KERNEL && BROKEN
12411 ---help---
12412 Mark the kernel read-only data as write-protected in the pagetables,
12413 in order to catch accidental (and incorrect) writes to such const
12414 @@ -111,7 +111,7 @@ config DEBUG_RODATA_TEST
12415
12416 config DEBUG_SET_MODULE_RONX
12417 bool "Set loadable kernel module data as NX and text as RO"
12418 - depends on MODULES
12419 + depends on MODULES && BROKEN
12420 ---help---
12421 This option helps catch unintended modifications to loadable
12422 kernel module's text and read-only data. It also prevents execution
12423 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
12424 index 33f71b0..c2cefa2 100644
12425 --- a/arch/x86/Makefile
12426 +++ b/arch/x86/Makefile
12427 @@ -71,9 +71,6 @@ ifeq ($(CONFIG_X86_32),y)
12428 # CPU-specific tuning. Anything which can be shared with UML should go here.
12429 include $(srctree)/arch/x86/Makefile_32.cpu
12430 KBUILD_CFLAGS += $(cflags-y)
12431 -
12432 - # temporary until string.h is fixed
12433 - KBUILD_CFLAGS += -ffreestanding
12434 else
12435 BITS := 64
12436 UTS_MACHINE := x86_64
12437 @@ -114,6 +111,9 @@ else
12438 KBUILD_CFLAGS += $(call cc-option,-maccumulate-outgoing-args)
12439 endif
12440
12441 +# temporary until string.h is fixed
12442 +KBUILD_CFLAGS += -ffreestanding
12443 +
12444 # Make sure compiler does not have buggy stack-protector support.
12445 ifdef CONFIG_CC_STACKPROTECTOR
12446 cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
12447 @@ -271,3 +271,12 @@ define archhelp
12448 echo ' FDINITRD=file initrd for the booted kernel'
12449 echo ' kvmconfig - Enable additional options for guest kernel support'
12450 endef
12451 +
12452 +define OLD_LD
12453 +
12454 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
12455 +*** Please upgrade your binutils to 2.18 or newer
12456 +endef
12457 +
12458 +archprepare:
12459 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
12460 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
12461 index dbe8dd2..2f0a98f 100644
12462 --- a/arch/x86/boot/Makefile
12463 +++ b/arch/x86/boot/Makefile
12464 @@ -52,6 +52,9 @@ $(obj)/cpustr.h: $(obj)/mkcpustr FORCE
12465 # ---------------------------------------------------------------------------
12466
12467 KBUILD_CFLAGS := $(USERINCLUDE) $(REALMODE_CFLAGS) -D_SETUP
12468 +ifdef CONSTIFY_PLUGIN
12469 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12470 +endif
12471 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12472 GCOV_PROFILE := n
12473
12474 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
12475 index 878e4b9..20537ab 100644
12476 --- a/arch/x86/boot/bitops.h
12477 +++ b/arch/x86/boot/bitops.h
12478 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12479 u8 v;
12480 const u32 *p = (const u32 *)addr;
12481
12482 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12483 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
12484 return v;
12485 }
12486
12487 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
12488
12489 static inline void set_bit(int nr, void *addr)
12490 {
12491 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12492 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
12493 }
12494
12495 #endif /* BOOT_BITOPS_H */
12496 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
12497 index bd49ec6..94c7f58 100644
12498 --- a/arch/x86/boot/boot.h
12499 +++ b/arch/x86/boot/boot.h
12500 @@ -84,7 +84,7 @@ static inline void io_delay(void)
12501 static inline u16 ds(void)
12502 {
12503 u16 seg;
12504 - asm("movw %%ds,%0" : "=rm" (seg));
12505 + asm volatile("movw %%ds,%0" : "=rm" (seg));
12506 return seg;
12507 }
12508
12509 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
12510 index 0fcd913..3bb5c42 100644
12511 --- a/arch/x86/boot/compressed/Makefile
12512 +++ b/arch/x86/boot/compressed/Makefile
12513 @@ -16,6 +16,9 @@ KBUILD_CFLAGS += $(cflags-y)
12514 KBUILD_CFLAGS += -mno-mmx -mno-sse
12515 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
12516 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
12517 +ifdef CONSTIFY_PLUGIN
12518 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
12519 +endif
12520
12521 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
12522 GCOV_PROFILE := n
12523 diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
12524 index a53440e..c3dbf1e 100644
12525 --- a/arch/x86/boot/compressed/efi_stub_32.S
12526 +++ b/arch/x86/boot/compressed/efi_stub_32.S
12527 @@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
12528 * parameter 2, ..., param n. To make things easy, we save the return
12529 * address of efi_call_phys in a global variable.
12530 */
12531 - popl %ecx
12532 - movl %ecx, saved_return_addr(%edx)
12533 - /* get the function pointer into ECX*/
12534 - popl %ecx
12535 - movl %ecx, efi_rt_function_ptr(%edx)
12536 + popl saved_return_addr(%edx)
12537 + popl efi_rt_function_ptr(%edx)
12538
12539 /*
12540 * 3. Call the physical function.
12541 */
12542 - call *%ecx
12543 + call *efi_rt_function_ptr(%edx)
12544
12545 /*
12546 * 4. Balance the stack. And because EAX contain the return value,
12547 @@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
12548 1: popl %edx
12549 subl $1b, %edx
12550
12551 - movl efi_rt_function_ptr(%edx), %ecx
12552 - pushl %ecx
12553 + pushl efi_rt_function_ptr(%edx)
12554
12555 /*
12556 * 10. Push the saved return address onto the stack and return.
12557 */
12558 - movl saved_return_addr(%edx), %ecx
12559 - pushl %ecx
12560 - ret
12561 + jmpl *saved_return_addr(%edx)
12562 ENDPROC(efi_call_phys)
12563 .previous
12564
12565 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
12566 index cbed140..5f2ca57 100644
12567 --- a/arch/x86/boot/compressed/head_32.S
12568 +++ b/arch/x86/boot/compressed/head_32.S
12569 @@ -140,10 +140,10 @@ preferred_addr:
12570 addl %eax, %ebx
12571 notl %eax
12572 andl %eax, %ebx
12573 - cmpl $LOAD_PHYSICAL_ADDR, %ebx
12574 + cmpl $____LOAD_PHYSICAL_ADDR, %ebx
12575 jge 1f
12576 #endif
12577 - movl $LOAD_PHYSICAL_ADDR, %ebx
12578 + movl $____LOAD_PHYSICAL_ADDR, %ebx
12579 1:
12580
12581 /* Target address to relocate to for decompression */
12582 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
12583 index 0d558ee..58f257e 100644
12584 --- a/arch/x86/boot/compressed/head_64.S
12585 +++ b/arch/x86/boot/compressed/head_64.S
12586 @@ -94,10 +94,10 @@ ENTRY(startup_32)
12587 addl %eax, %ebx
12588 notl %eax
12589 andl %eax, %ebx
12590 - cmpl $LOAD_PHYSICAL_ADDR, %ebx
12591 + cmpl $____LOAD_PHYSICAL_ADDR, %ebx
12592 jge 1f
12593 #endif
12594 - movl $LOAD_PHYSICAL_ADDR, %ebx
12595 + movl $____LOAD_PHYSICAL_ADDR, %ebx
12596 1:
12597
12598 /* Target address to relocate to for decompression */
12599 @@ -322,10 +322,10 @@ preferred_addr:
12600 addq %rax, %rbp
12601 notq %rax
12602 andq %rax, %rbp
12603 - cmpq $LOAD_PHYSICAL_ADDR, %rbp
12604 + cmpq $____LOAD_PHYSICAL_ADDR, %rbp
12605 jge 1f
12606 #endif
12607 - movq $LOAD_PHYSICAL_ADDR, %rbp
12608 + movq $____LOAD_PHYSICAL_ADDR, %rbp
12609 1:
12610
12611 /* Target address to relocate to for decompression */
12612 @@ -431,8 +431,8 @@ gdt:
12613 .long gdt
12614 .word 0
12615 .quad 0x0000000000000000 /* NULL descriptor */
12616 - .quad 0x00af9a000000ffff /* __KERNEL_CS */
12617 - .quad 0x00cf92000000ffff /* __KERNEL_DS */
12618 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
12619 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
12620 .quad 0x0080890000000000 /* TS descriptor */
12621 .quad 0x0000000000000000 /* TS continued */
12622 gdt_end:
12623 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
12624 index 57ab74d..7c52182 100644
12625 --- a/arch/x86/boot/compressed/misc.c
12626 +++ b/arch/x86/boot/compressed/misc.c
12627 @@ -242,7 +242,7 @@ static void handle_relocations(void *output, unsigned long output_len)
12628 * Calculate the delta between where vmlinux was linked to load
12629 * and where it was actually loaded.
12630 */
12631 - delta = min_addr - LOAD_PHYSICAL_ADDR;
12632 + delta = min_addr - ____LOAD_PHYSICAL_ADDR;
12633 if (!delta) {
12634 debug_putstr("No relocation needed... ");
12635 return;
12636 @@ -312,7 +312,7 @@ static void parse_elf(void *output)
12637 Elf32_Ehdr ehdr;
12638 Elf32_Phdr *phdrs, *phdr;
12639 #endif
12640 - void *dest;
12641 + void *dest, *prev;
12642 int i;
12643
12644 memcpy(&ehdr, output, sizeof(ehdr));
12645 @@ -339,13 +339,16 @@ static void parse_elf(void *output)
12646 case PT_LOAD:
12647 #ifdef CONFIG_RELOCATABLE
12648 dest = output;
12649 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
12650 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
12651 #else
12652 dest = (void *)(phdr->p_paddr);
12653 #endif
12654 memcpy(dest,
12655 output + phdr->p_offset,
12656 phdr->p_filesz);
12657 + if (i)
12658 + memset(prev, 0xff, dest - prev);
12659 + prev = dest + phdr->p_filesz;
12660 break;
12661 default: /* Ignore other PT_* */ break;
12662 }
12663 @@ -395,7 +398,7 @@ asmlinkage __visible void *decompress_kernel(void *rmode, memptr heap,
12664 error("Destination address too large");
12665 #endif
12666 #ifndef CONFIG_RELOCATABLE
12667 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
12668 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
12669 error("Wrong destination address");
12670 #endif
12671
12672 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
12673 index 1fd7d57..0f7d096 100644
12674 --- a/arch/x86/boot/cpucheck.c
12675 +++ b/arch/x86/boot/cpucheck.c
12676 @@ -125,9 +125,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12677 u32 ecx = MSR_K7_HWCR;
12678 u32 eax, edx;
12679
12680 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12681 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12682 eax &= ~(1 << 15);
12683 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12684 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12685
12686 get_cpuflags(); /* Make sure it really did something */
12687 err = check_cpuflags();
12688 @@ -140,9 +140,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12689 u32 ecx = MSR_VIA_FCR;
12690 u32 eax, edx;
12691
12692 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12693 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12694 eax |= (1<<1)|(1<<7);
12695 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12696 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12697
12698 set_bit(X86_FEATURE_CX8, cpu.flags);
12699 err = check_cpuflags();
12700 @@ -153,12 +153,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12701 u32 eax, edx;
12702 u32 level = 1;
12703
12704 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12705 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12706 - asm("cpuid"
12707 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12708 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12709 + asm volatile("cpuid"
12710 : "+a" (level), "=d" (cpu.flags[0])
12711 : : "ecx", "ebx");
12712 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12713 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12714
12715 err = check_cpuflags();
12716 } else if (err == 0x01 &&
12717 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
12718 index 84c2234..3ef6360 100644
12719 --- a/arch/x86/boot/header.S
12720 +++ b/arch/x86/boot/header.S
12721 @@ -420,10 +420,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
12722 # single linked list of
12723 # struct setup_data
12724
12725 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
12726 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
12727
12728 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
12729 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
12730 +#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
12731 +#else
12732 #define VO_INIT_SIZE (VO__end - VO__text)
12733 +#endif
12734 #if ZO_INIT_SIZE > VO_INIT_SIZE
12735 #define INIT_SIZE ZO_INIT_SIZE
12736 #else
12737 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
12738 index db75d07..8e6d0af 100644
12739 --- a/arch/x86/boot/memory.c
12740 +++ b/arch/x86/boot/memory.c
12741 @@ -19,7 +19,7 @@
12742
12743 static int detect_memory_e820(void)
12744 {
12745 - int count = 0;
12746 + unsigned int count = 0;
12747 struct biosregs ireg, oreg;
12748 struct e820entry *desc = boot_params.e820_map;
12749 static struct e820entry buf; /* static so it is zeroed */
12750 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
12751 index ba3e100..6501b8f 100644
12752 --- a/arch/x86/boot/video-vesa.c
12753 +++ b/arch/x86/boot/video-vesa.c
12754 @@ -201,6 +201,7 @@ static void vesa_store_pm_info(void)
12755
12756 boot_params.screen_info.vesapm_seg = oreg.es;
12757 boot_params.screen_info.vesapm_off = oreg.di;
12758 + boot_params.screen_info.vesapm_size = oreg.cx;
12759 }
12760
12761 /*
12762 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
12763 index 43eda28..5ab5fdb 100644
12764 --- a/arch/x86/boot/video.c
12765 +++ b/arch/x86/boot/video.c
12766 @@ -96,7 +96,7 @@ static void store_mode_params(void)
12767 static unsigned int get_entry(void)
12768 {
12769 char entry_buf[4];
12770 - int i, len = 0;
12771 + unsigned int i, len = 0;
12772 int key;
12773 unsigned int v;
12774
12775 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
12776 index 9105655..41779c1 100644
12777 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
12778 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
12779 @@ -8,6 +8,8 @@
12780 * including this sentence is retained in full.
12781 */
12782
12783 +#include <asm/alternative-asm.h>
12784 +
12785 .extern crypto_ft_tab
12786 .extern crypto_it_tab
12787 .extern crypto_fl_tab
12788 @@ -70,6 +72,8 @@
12789 je B192; \
12790 leaq 32(r9),r9;
12791
12792 +#define ret pax_force_retaddr; ret
12793 +
12794 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
12795 movq r1,r2; \
12796 movq r3,r4; \
12797 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
12798 index 477e9d7..c92c7d8 100644
12799 --- a/arch/x86/crypto/aesni-intel_asm.S
12800 +++ b/arch/x86/crypto/aesni-intel_asm.S
12801 @@ -31,6 +31,7 @@
12802
12803 #include <linux/linkage.h>
12804 #include <asm/inst.h>
12805 +#include <asm/alternative-asm.h>
12806
12807 #ifdef __x86_64__
12808 .data
12809 @@ -205,7 +206,7 @@ enc: .octa 0x2
12810 * num_initial_blocks = b mod 4
12811 * encrypt the initial num_initial_blocks blocks and apply ghash on
12812 * the ciphertext
12813 -* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12814 +* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12815 * are clobbered
12816 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
12817 */
12818 @@ -214,8 +215,8 @@ enc: .octa 0x2
12819 .macro INITIAL_BLOCKS_DEC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
12820 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
12821 mov arg7, %r10 # %r10 = AAD
12822 - mov arg8, %r12 # %r12 = aadLen
12823 - mov %r12, %r11
12824 + mov arg8, %r15 # %r15 = aadLen
12825 + mov %r15, %r11
12826 pxor %xmm\i, %xmm\i
12827 _get_AAD_loop\num_initial_blocks\operation:
12828 movd (%r10), \TMP1
12829 @@ -223,15 +224,15 @@ _get_AAD_loop\num_initial_blocks\operation:
12830 psrldq $4, %xmm\i
12831 pxor \TMP1, %xmm\i
12832 add $4, %r10
12833 - sub $4, %r12
12834 + sub $4, %r15
12835 jne _get_AAD_loop\num_initial_blocks\operation
12836 cmp $16, %r11
12837 je _get_AAD_loop2_done\num_initial_blocks\operation
12838 - mov $16, %r12
12839 + mov $16, %r15
12840 _get_AAD_loop2\num_initial_blocks\operation:
12841 psrldq $4, %xmm\i
12842 - sub $4, %r12
12843 - cmp %r11, %r12
12844 + sub $4, %r15
12845 + cmp %r11, %r15
12846 jne _get_AAD_loop2\num_initial_blocks\operation
12847 _get_AAD_loop2_done\num_initial_blocks\operation:
12848 movdqa SHUF_MASK(%rip), %xmm14
12849 @@ -443,7 +444,7 @@ _initial_blocks_done\num_initial_blocks\operation:
12850 * num_initial_blocks = b mod 4
12851 * encrypt the initial num_initial_blocks blocks and apply ghash on
12852 * the ciphertext
12853 -* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12854 +* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12855 * are clobbered
12856 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
12857 */
12858 @@ -452,8 +453,8 @@ _initial_blocks_done\num_initial_blocks\operation:
12859 .macro INITIAL_BLOCKS_ENC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
12860 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
12861 mov arg7, %r10 # %r10 = AAD
12862 - mov arg8, %r12 # %r12 = aadLen
12863 - mov %r12, %r11
12864 + mov arg8, %r15 # %r15 = aadLen
12865 + mov %r15, %r11
12866 pxor %xmm\i, %xmm\i
12867 _get_AAD_loop\num_initial_blocks\operation:
12868 movd (%r10), \TMP1
12869 @@ -461,15 +462,15 @@ _get_AAD_loop\num_initial_blocks\operation:
12870 psrldq $4, %xmm\i
12871 pxor \TMP1, %xmm\i
12872 add $4, %r10
12873 - sub $4, %r12
12874 + sub $4, %r15
12875 jne _get_AAD_loop\num_initial_blocks\operation
12876 cmp $16, %r11
12877 je _get_AAD_loop2_done\num_initial_blocks\operation
12878 - mov $16, %r12
12879 + mov $16, %r15
12880 _get_AAD_loop2\num_initial_blocks\operation:
12881 psrldq $4, %xmm\i
12882 - sub $4, %r12
12883 - cmp %r11, %r12
12884 + sub $4, %r15
12885 + cmp %r11, %r15
12886 jne _get_AAD_loop2\num_initial_blocks\operation
12887 _get_AAD_loop2_done\num_initial_blocks\operation:
12888 movdqa SHUF_MASK(%rip), %xmm14
12889 @@ -1269,7 +1270,7 @@ TMP7 XMM1 XMM2 XMM3 XMM4 XMMDst
12890 *
12891 *****************************************************************************/
12892 ENTRY(aesni_gcm_dec)
12893 - push %r12
12894 + push %r15
12895 push %r13
12896 push %r14
12897 mov %rsp, %r14
12898 @@ -1279,8 +1280,8 @@ ENTRY(aesni_gcm_dec)
12899 */
12900 sub $VARIABLE_OFFSET, %rsp
12901 and $~63, %rsp # align rsp to 64 bytes
12902 - mov %arg6, %r12
12903 - movdqu (%r12), %xmm13 # %xmm13 = HashKey
12904 + mov %arg6, %r15
12905 + movdqu (%r15), %xmm13 # %xmm13 = HashKey
12906 movdqa SHUF_MASK(%rip), %xmm2
12907 PSHUFB_XMM %xmm2, %xmm13
12908
12909 @@ -1308,10 +1309,10 @@ ENTRY(aesni_gcm_dec)
12910 movdqa %xmm13, HashKey(%rsp) # store HashKey<<1 (mod poly)
12911 mov %arg4, %r13 # save the number of bytes of plaintext/ciphertext
12912 and $-16, %r13 # %r13 = %r13 - (%r13 mod 16)
12913 - mov %r13, %r12
12914 - and $(3<<4), %r12
12915 + mov %r13, %r15
12916 + and $(3<<4), %r15
12917 jz _initial_num_blocks_is_0_decrypt
12918 - cmp $(2<<4), %r12
12919 + cmp $(2<<4), %r15
12920 jb _initial_num_blocks_is_1_decrypt
12921 je _initial_num_blocks_is_2_decrypt
12922 _initial_num_blocks_is_3_decrypt:
12923 @@ -1361,16 +1362,16 @@ _zero_cipher_left_decrypt:
12924 sub $16, %r11
12925 add %r13, %r11
12926 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte block
12927 - lea SHIFT_MASK+16(%rip), %r12
12928 - sub %r13, %r12
12929 + lea SHIFT_MASK+16(%rip), %r15
12930 + sub %r13, %r15
12931 # adjust the shuffle mask pointer to be able to shift 16-%r13 bytes
12932 # (%r13 is the number of bytes in plaintext mod 16)
12933 - movdqu (%r12), %xmm2 # get the appropriate shuffle mask
12934 + movdqu (%r15), %xmm2 # get the appropriate shuffle mask
12935 PSHUFB_XMM %xmm2, %xmm1 # right shift 16-%r13 butes
12936
12937 movdqa %xmm1, %xmm2
12938 pxor %xmm1, %xmm0 # Ciphertext XOR E(K, Yn)
12939 - movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
12940 + movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
12941 # get the appropriate mask to mask out top 16-%r13 bytes of %xmm0
12942 pand %xmm1, %xmm0 # mask out top 16-%r13 bytes of %xmm0
12943 pand %xmm1, %xmm2
12944 @@ -1399,9 +1400,9 @@ _less_than_8_bytes_left_decrypt:
12945 sub $1, %r13
12946 jne _less_than_8_bytes_left_decrypt
12947 _multiple_of_16_bytes_decrypt:
12948 - mov arg8, %r12 # %r13 = aadLen (number of bytes)
12949 - shl $3, %r12 # convert into number of bits
12950 - movd %r12d, %xmm15 # len(A) in %xmm15
12951 + mov arg8, %r15 # %r13 = aadLen (number of bytes)
12952 + shl $3, %r15 # convert into number of bits
12953 + movd %r15d, %xmm15 # len(A) in %xmm15
12954 shl $3, %arg4 # len(C) in bits (*128)
12955 MOVQ_R64_XMM %arg4, %xmm1
12956 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
12957 @@ -1440,7 +1441,8 @@ _return_T_done_decrypt:
12958 mov %r14, %rsp
12959 pop %r14
12960 pop %r13
12961 - pop %r12
12962 + pop %r15
12963 + pax_force_retaddr
12964 ret
12965 ENDPROC(aesni_gcm_dec)
12966
12967 @@ -1529,7 +1531,7 @@ ENDPROC(aesni_gcm_dec)
12968 * poly = x^128 + x^127 + x^126 + x^121 + 1
12969 ***************************************************************************/
12970 ENTRY(aesni_gcm_enc)
12971 - push %r12
12972 + push %r15
12973 push %r13
12974 push %r14
12975 mov %rsp, %r14
12976 @@ -1539,8 +1541,8 @@ ENTRY(aesni_gcm_enc)
12977 #
12978 sub $VARIABLE_OFFSET, %rsp
12979 and $~63, %rsp
12980 - mov %arg6, %r12
12981 - movdqu (%r12), %xmm13
12982 + mov %arg6, %r15
12983 + movdqu (%r15), %xmm13
12984 movdqa SHUF_MASK(%rip), %xmm2
12985 PSHUFB_XMM %xmm2, %xmm13
12986
12987 @@ -1564,13 +1566,13 @@ ENTRY(aesni_gcm_enc)
12988 movdqa %xmm13, HashKey(%rsp)
12989 mov %arg4, %r13 # %xmm13 holds HashKey<<1 (mod poly)
12990 and $-16, %r13
12991 - mov %r13, %r12
12992 + mov %r13, %r15
12993
12994 # Encrypt first few blocks
12995
12996 - and $(3<<4), %r12
12997 + and $(3<<4), %r15
12998 jz _initial_num_blocks_is_0_encrypt
12999 - cmp $(2<<4), %r12
13000 + cmp $(2<<4), %r15
13001 jb _initial_num_blocks_is_1_encrypt
13002 je _initial_num_blocks_is_2_encrypt
13003 _initial_num_blocks_is_3_encrypt:
13004 @@ -1623,14 +1625,14 @@ _zero_cipher_left_encrypt:
13005 sub $16, %r11
13006 add %r13, %r11
13007 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte blocks
13008 - lea SHIFT_MASK+16(%rip), %r12
13009 - sub %r13, %r12
13010 + lea SHIFT_MASK+16(%rip), %r15
13011 + sub %r13, %r15
13012 # adjust the shuffle mask pointer to be able to shift 16-r13 bytes
13013 # (%r13 is the number of bytes in plaintext mod 16)
13014 - movdqu (%r12), %xmm2 # get the appropriate shuffle mask
13015 + movdqu (%r15), %xmm2 # get the appropriate shuffle mask
13016 PSHUFB_XMM %xmm2, %xmm1 # shift right 16-r13 byte
13017 pxor %xmm1, %xmm0 # Plaintext XOR Encrypt(K, Yn)
13018 - movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
13019 + movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
13020 # get the appropriate mask to mask out top 16-r13 bytes of xmm0
13021 pand %xmm1, %xmm0 # mask out top 16-r13 bytes of xmm0
13022 movdqa SHUF_MASK(%rip), %xmm10
13023 @@ -1663,9 +1665,9 @@ _less_than_8_bytes_left_encrypt:
13024 sub $1, %r13
13025 jne _less_than_8_bytes_left_encrypt
13026 _multiple_of_16_bytes_encrypt:
13027 - mov arg8, %r12 # %r12 = addLen (number of bytes)
13028 - shl $3, %r12
13029 - movd %r12d, %xmm15 # len(A) in %xmm15
13030 + mov arg8, %r15 # %r15 = addLen (number of bytes)
13031 + shl $3, %r15
13032 + movd %r15d, %xmm15 # len(A) in %xmm15
13033 shl $3, %arg4 # len(C) in bits (*128)
13034 MOVQ_R64_XMM %arg4, %xmm1
13035 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
13036 @@ -1704,7 +1706,8 @@ _return_T_done_encrypt:
13037 mov %r14, %rsp
13038 pop %r14
13039 pop %r13
13040 - pop %r12
13041 + pop %r15
13042 + pax_force_retaddr
13043 ret
13044 ENDPROC(aesni_gcm_enc)
13045
13046 @@ -1722,6 +1725,7 @@ _key_expansion_256a:
13047 pxor %xmm1, %xmm0
13048 movaps %xmm0, (TKEYP)
13049 add $0x10, TKEYP
13050 + pax_force_retaddr
13051 ret
13052 ENDPROC(_key_expansion_128)
13053 ENDPROC(_key_expansion_256a)
13054 @@ -1748,6 +1752,7 @@ _key_expansion_192a:
13055 shufps $0b01001110, %xmm2, %xmm1
13056 movaps %xmm1, 0x10(TKEYP)
13057 add $0x20, TKEYP
13058 + pax_force_retaddr
13059 ret
13060 ENDPROC(_key_expansion_192a)
13061
13062 @@ -1768,6 +1773,7 @@ _key_expansion_192b:
13063
13064 movaps %xmm0, (TKEYP)
13065 add $0x10, TKEYP
13066 + pax_force_retaddr
13067 ret
13068 ENDPROC(_key_expansion_192b)
13069
13070 @@ -1781,6 +1787,7 @@ _key_expansion_256b:
13071 pxor %xmm1, %xmm2
13072 movaps %xmm2, (TKEYP)
13073 add $0x10, TKEYP
13074 + pax_force_retaddr
13075 ret
13076 ENDPROC(_key_expansion_256b)
13077
13078 @@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
13079 #ifndef __x86_64__
13080 popl KEYP
13081 #endif
13082 + pax_force_retaddr
13083 ret
13084 ENDPROC(aesni_set_key)
13085
13086 @@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
13087 popl KLEN
13088 popl KEYP
13089 #endif
13090 + pax_force_retaddr
13091 ret
13092 ENDPROC(aesni_enc)
13093
13094 @@ -1974,6 +1983,7 @@ _aesni_enc1:
13095 AESENC KEY STATE
13096 movaps 0x70(TKEYP), KEY
13097 AESENCLAST KEY STATE
13098 + pax_force_retaddr
13099 ret
13100 ENDPROC(_aesni_enc1)
13101
13102 @@ -2083,6 +2093,7 @@ _aesni_enc4:
13103 AESENCLAST KEY STATE2
13104 AESENCLAST KEY STATE3
13105 AESENCLAST KEY STATE4
13106 + pax_force_retaddr
13107 ret
13108 ENDPROC(_aesni_enc4)
13109
13110 @@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
13111 popl KLEN
13112 popl KEYP
13113 #endif
13114 + pax_force_retaddr
13115 ret
13116 ENDPROC(aesni_dec)
13117
13118 @@ -2164,6 +2176,7 @@ _aesni_dec1:
13119 AESDEC KEY STATE
13120 movaps 0x70(TKEYP), KEY
13121 AESDECLAST KEY STATE
13122 + pax_force_retaddr
13123 ret
13124 ENDPROC(_aesni_dec1)
13125
13126 @@ -2273,6 +2286,7 @@ _aesni_dec4:
13127 AESDECLAST KEY STATE2
13128 AESDECLAST KEY STATE3
13129 AESDECLAST KEY STATE4
13130 + pax_force_retaddr
13131 ret
13132 ENDPROC(_aesni_dec4)
13133
13134 @@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
13135 popl KEYP
13136 popl LEN
13137 #endif
13138 + pax_force_retaddr
13139 ret
13140 ENDPROC(aesni_ecb_enc)
13141
13142 @@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
13143 popl KEYP
13144 popl LEN
13145 #endif
13146 + pax_force_retaddr
13147 ret
13148 ENDPROC(aesni_ecb_dec)
13149
13150 @@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
13151 popl LEN
13152 popl IVP
13153 #endif
13154 + pax_force_retaddr
13155 ret
13156 ENDPROC(aesni_cbc_enc)
13157
13158 @@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
13159 popl LEN
13160 popl IVP
13161 #endif
13162 + pax_force_retaddr
13163 ret
13164 ENDPROC(aesni_cbc_dec)
13165
13166 @@ -2550,6 +2568,7 @@ _aesni_inc_init:
13167 mov $1, TCTR_LOW
13168 MOVQ_R64_XMM TCTR_LOW INC
13169 MOVQ_R64_XMM CTR TCTR_LOW
13170 + pax_force_retaddr
13171 ret
13172 ENDPROC(_aesni_inc_init)
13173
13174 @@ -2579,6 +2598,7 @@ _aesni_inc:
13175 .Linc_low:
13176 movaps CTR, IV
13177 PSHUFB_XMM BSWAP_MASK IV
13178 + pax_force_retaddr
13179 ret
13180 ENDPROC(_aesni_inc)
13181
13182 @@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
13183 .Lctr_enc_ret:
13184 movups IV, (IVP)
13185 .Lctr_enc_just_ret:
13186 + pax_force_retaddr
13187 ret
13188 ENDPROC(aesni_ctr_enc)
13189
13190 @@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
13191 pxor INC, STATE4
13192 movdqu STATE4, 0x70(OUTP)
13193
13194 + pax_force_retaddr
13195 ret
13196 ENDPROC(aesni_xts_crypt8)
13197
13198 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13199 index 246c670..466e2d6 100644
13200 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
13201 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
13202 @@ -21,6 +21,7 @@
13203 */
13204
13205 #include <linux/linkage.h>
13206 +#include <asm/alternative-asm.h>
13207
13208 .file "blowfish-x86_64-asm.S"
13209 .text
13210 @@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
13211 jnz .L__enc_xor;
13212
13213 write_block();
13214 + pax_force_retaddr
13215 ret;
13216 .L__enc_xor:
13217 xor_block();
13218 + pax_force_retaddr
13219 ret;
13220 ENDPROC(__blowfish_enc_blk)
13221
13222 @@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
13223
13224 movq %r11, %rbp;
13225
13226 + pax_force_retaddr
13227 ret;
13228 ENDPROC(blowfish_dec_blk)
13229
13230 @@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
13231
13232 popq %rbx;
13233 popq %rbp;
13234 + pax_force_retaddr
13235 ret;
13236
13237 .L__enc_xor4:
13238 @@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
13239
13240 popq %rbx;
13241 popq %rbp;
13242 + pax_force_retaddr
13243 ret;
13244 ENDPROC(__blowfish_enc_blk_4way)
13245
13246 @@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
13247 popq %rbx;
13248 popq %rbp;
13249
13250 + pax_force_retaddr
13251 ret;
13252 ENDPROC(blowfish_dec_blk_4way)
13253 diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13254 index ce71f92..1dce7ec 100644
13255 --- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13256 +++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
13257 @@ -16,6 +16,7 @@
13258 */
13259
13260 #include <linux/linkage.h>
13261 +#include <asm/alternative-asm.h>
13262
13263 #define CAMELLIA_TABLE_BYTE_LEN 272
13264
13265 @@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13266 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
13267 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
13268 %rcx, (%r9));
13269 + pax_force_retaddr
13270 ret;
13271 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13272
13273 @@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13274 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
13275 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
13276 %rax, (%r9));
13277 + pax_force_retaddr
13278 ret;
13279 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13280
13281 @@ -780,6 +783,7 @@ __camellia_enc_blk16:
13282 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13283 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
13284
13285 + pax_force_retaddr
13286 ret;
13287
13288 .align 8
13289 @@ -865,6 +869,7 @@ __camellia_dec_blk16:
13290 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
13291 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
13292
13293 + pax_force_retaddr
13294 ret;
13295
13296 .align 8
13297 @@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
13298 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13299 %xmm8, %rsi);
13300
13301 + pax_force_retaddr
13302 ret;
13303 ENDPROC(camellia_ecb_enc_16way)
13304
13305 @@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
13306 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13307 %xmm8, %rsi);
13308
13309 + pax_force_retaddr
13310 ret;
13311 ENDPROC(camellia_ecb_dec_16way)
13312
13313 @@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
13314 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13315 %xmm8, %rsi);
13316
13317 + pax_force_retaddr
13318 ret;
13319 ENDPROC(camellia_cbc_dec_16way)
13320
13321 @@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
13322 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13323 %xmm8, %rsi);
13324
13325 + pax_force_retaddr
13326 ret;
13327 ENDPROC(camellia_ctr_16way)
13328
13329 @@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
13330 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
13331 %xmm8, %rsi);
13332
13333 + pax_force_retaddr
13334 ret;
13335 ENDPROC(camellia_xts_crypt_16way)
13336
13337 diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13338 index 0e0b886..5a3123c 100644
13339 --- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13340 +++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
13341 @@ -11,6 +11,7 @@
13342 */
13343
13344 #include <linux/linkage.h>
13345 +#include <asm/alternative-asm.h>
13346
13347 #define CAMELLIA_TABLE_BYTE_LEN 272
13348
13349 @@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
13350 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
13351 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
13352 %rcx, (%r9));
13353 + pax_force_retaddr
13354 ret;
13355 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
13356
13357 @@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
13358 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
13359 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
13360 %rax, (%r9));
13361 + pax_force_retaddr
13362 ret;
13363 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
13364
13365 @@ -820,6 +823,7 @@ __camellia_enc_blk32:
13366 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13367 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
13368
13369 + pax_force_retaddr
13370 ret;
13371
13372 .align 8
13373 @@ -905,6 +909,7 @@ __camellia_dec_blk32:
13374 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
13375 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
13376
13377 + pax_force_retaddr
13378 ret;
13379
13380 .align 8
13381 @@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
13382
13383 vzeroupper;
13384
13385 + pax_force_retaddr
13386 ret;
13387 ENDPROC(camellia_ecb_enc_32way)
13388
13389 @@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
13390
13391 vzeroupper;
13392
13393 + pax_force_retaddr
13394 ret;
13395 ENDPROC(camellia_ecb_dec_32way)
13396
13397 @@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
13398
13399 vzeroupper;
13400
13401 + pax_force_retaddr
13402 ret;
13403 ENDPROC(camellia_cbc_dec_32way)
13404
13405 @@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
13406
13407 vzeroupper;
13408
13409 + pax_force_retaddr
13410 ret;
13411 ENDPROC(camellia_ctr_32way)
13412
13413 @@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
13414
13415 vzeroupper;
13416
13417 + pax_force_retaddr
13418 ret;
13419 ENDPROC(camellia_xts_crypt_32way)
13420
13421 diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
13422 index 310319c..db3d7b5 100644
13423 --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
13424 +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
13425 @@ -21,6 +21,7 @@
13426 */
13427
13428 #include <linux/linkage.h>
13429 +#include <asm/alternative-asm.h>
13430
13431 .file "camellia-x86_64-asm_64.S"
13432 .text
13433 @@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
13434 enc_outunpack(mov, RT1);
13435
13436 movq RRBP, %rbp;
13437 + pax_force_retaddr
13438 ret;
13439
13440 .L__enc_xor:
13441 enc_outunpack(xor, RT1);
13442
13443 movq RRBP, %rbp;
13444 + pax_force_retaddr
13445 ret;
13446 ENDPROC(__camellia_enc_blk)
13447
13448 @@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
13449 dec_outunpack();
13450
13451 movq RRBP, %rbp;
13452 + pax_force_retaddr
13453 ret;
13454 ENDPROC(camellia_dec_blk)
13455
13456 @@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
13457
13458 movq RRBP, %rbp;
13459 popq %rbx;
13460 + pax_force_retaddr
13461 ret;
13462
13463 .L__enc2_xor:
13464 @@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
13465
13466 movq RRBP, %rbp;
13467 popq %rbx;
13468 + pax_force_retaddr
13469 ret;
13470 ENDPROC(__camellia_enc_blk_2way)
13471
13472 @@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
13473
13474 movq RRBP, %rbp;
13475 movq RXOR, %rbx;
13476 + pax_force_retaddr
13477 ret;
13478 ENDPROC(camellia_dec_blk_2way)
13479 diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13480 index c35fd5d..2d8c7db 100644
13481 --- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13482 +++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
13483 @@ -24,6 +24,7 @@
13484 */
13485
13486 #include <linux/linkage.h>
13487 +#include <asm/alternative-asm.h>
13488
13489 .file "cast5-avx-x86_64-asm_64.S"
13490
13491 @@ -281,6 +282,7 @@ __cast5_enc_blk16:
13492 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13493 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13494
13495 + pax_force_retaddr
13496 ret;
13497 ENDPROC(__cast5_enc_blk16)
13498
13499 @@ -352,6 +354,7 @@ __cast5_dec_blk16:
13500 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
13501 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
13502
13503 + pax_force_retaddr
13504 ret;
13505
13506 .L__skip_dec:
13507 @@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
13508 vmovdqu RR4, (6*4*4)(%r11);
13509 vmovdqu RL4, (7*4*4)(%r11);
13510
13511 + pax_force_retaddr
13512 ret;
13513 ENDPROC(cast5_ecb_enc_16way)
13514
13515 @@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
13516 vmovdqu RR4, (6*4*4)(%r11);
13517 vmovdqu RL4, (7*4*4)(%r11);
13518
13519 + pax_force_retaddr
13520 ret;
13521 ENDPROC(cast5_ecb_dec_16way)
13522
13523 @@ -430,10 +435,10 @@ ENTRY(cast5_cbc_dec_16way)
13524 * %rdx: src
13525 */
13526
13527 - pushq %r12;
13528 + pushq %r14;
13529
13530 movq %rsi, %r11;
13531 - movq %rdx, %r12;
13532 + movq %rdx, %r14;
13533
13534 vmovdqu (0*16)(%rdx), RL1;
13535 vmovdqu (1*16)(%rdx), RR1;
13536 @@ -447,16 +452,16 @@ ENTRY(cast5_cbc_dec_16way)
13537 call __cast5_dec_blk16;
13538
13539 /* xor with src */
13540 - vmovq (%r12), RX;
13541 + vmovq (%r14), RX;
13542 vpshufd $0x4f, RX, RX;
13543 vpxor RX, RR1, RR1;
13544 - vpxor 0*16+8(%r12), RL1, RL1;
13545 - vpxor 1*16+8(%r12), RR2, RR2;
13546 - vpxor 2*16+8(%r12), RL2, RL2;
13547 - vpxor 3*16+8(%r12), RR3, RR3;
13548 - vpxor 4*16+8(%r12), RL3, RL3;
13549 - vpxor 5*16+8(%r12), RR4, RR4;
13550 - vpxor 6*16+8(%r12), RL4, RL4;
13551 + vpxor 0*16+8(%r14), RL1, RL1;
13552 + vpxor 1*16+8(%r14), RR2, RR2;
13553 + vpxor 2*16+8(%r14), RL2, RL2;
13554 + vpxor 3*16+8(%r14), RR3, RR3;
13555 + vpxor 4*16+8(%r14), RL3, RL3;
13556 + vpxor 5*16+8(%r14), RR4, RR4;
13557 + vpxor 6*16+8(%r14), RL4, RL4;
13558
13559 vmovdqu RR1, (0*16)(%r11);
13560 vmovdqu RL1, (1*16)(%r11);
13561 @@ -467,8 +472,9 @@ ENTRY(cast5_cbc_dec_16way)
13562 vmovdqu RR4, (6*16)(%r11);
13563 vmovdqu RL4, (7*16)(%r11);
13564
13565 - popq %r12;
13566 + popq %r14;
13567
13568 + pax_force_retaddr
13569 ret;
13570 ENDPROC(cast5_cbc_dec_16way)
13571
13572 @@ -480,10 +486,10 @@ ENTRY(cast5_ctr_16way)
13573 * %rcx: iv (big endian, 64bit)
13574 */
13575
13576 - pushq %r12;
13577 + pushq %r14;
13578
13579 movq %rsi, %r11;
13580 - movq %rdx, %r12;
13581 + movq %rdx, %r14;
13582
13583 vpcmpeqd RTMP, RTMP, RTMP;
13584 vpsrldq $8, RTMP, RTMP; /* low: -1, high: 0 */
13585 @@ -523,14 +529,14 @@ ENTRY(cast5_ctr_16way)
13586 call __cast5_enc_blk16;
13587
13588 /* dst = src ^ iv */
13589 - vpxor (0*16)(%r12), RR1, RR1;
13590 - vpxor (1*16)(%r12), RL1, RL1;
13591 - vpxor (2*16)(%r12), RR2, RR2;
13592 - vpxor (3*16)(%r12), RL2, RL2;
13593 - vpxor (4*16)(%r12), RR3, RR3;
13594 - vpxor (5*16)(%r12), RL3, RL3;
13595 - vpxor (6*16)(%r12), RR4, RR4;
13596 - vpxor (7*16)(%r12), RL4, RL4;
13597 + vpxor (0*16)(%r14), RR1, RR1;
13598 + vpxor (1*16)(%r14), RL1, RL1;
13599 + vpxor (2*16)(%r14), RR2, RR2;
13600 + vpxor (3*16)(%r14), RL2, RL2;
13601 + vpxor (4*16)(%r14), RR3, RR3;
13602 + vpxor (5*16)(%r14), RL3, RL3;
13603 + vpxor (6*16)(%r14), RR4, RR4;
13604 + vpxor (7*16)(%r14), RL4, RL4;
13605 vmovdqu RR1, (0*16)(%r11);
13606 vmovdqu RL1, (1*16)(%r11);
13607 vmovdqu RR2, (2*16)(%r11);
13608 @@ -540,7 +546,8 @@ ENTRY(cast5_ctr_16way)
13609 vmovdqu RR4, (6*16)(%r11);
13610 vmovdqu RL4, (7*16)(%r11);
13611
13612 - popq %r12;
13613 + popq %r14;
13614
13615 + pax_force_retaddr
13616 ret;
13617 ENDPROC(cast5_ctr_16way)
13618 diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13619 index e3531f8..e123f35 100644
13620 --- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13621 +++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13622 @@ -24,6 +24,7 @@
13623 */
13624
13625 #include <linux/linkage.h>
13626 +#include <asm/alternative-asm.h>
13627 #include "glue_helper-asm-avx.S"
13628
13629 .file "cast6-avx-x86_64-asm_64.S"
13630 @@ -295,6 +296,7 @@ __cast6_enc_blk8:
13631 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13632 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13633
13634 + pax_force_retaddr
13635 ret;
13636 ENDPROC(__cast6_enc_blk8)
13637
13638 @@ -340,6 +342,7 @@ __cast6_dec_blk8:
13639 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13640 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13641
13642 + pax_force_retaddr
13643 ret;
13644 ENDPROC(__cast6_dec_blk8)
13645
13646 @@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
13647
13648 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13649
13650 + pax_force_retaddr
13651 ret;
13652 ENDPROC(cast6_ecb_enc_8way)
13653
13654 @@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
13655
13656 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13657
13658 + pax_force_retaddr
13659 ret;
13660 ENDPROC(cast6_ecb_dec_8way)
13661
13662 @@ -386,19 +391,20 @@ ENTRY(cast6_cbc_dec_8way)
13663 * %rdx: src
13664 */
13665
13666 - pushq %r12;
13667 + pushq %r14;
13668
13669 movq %rsi, %r11;
13670 - movq %rdx, %r12;
13671 + movq %rdx, %r14;
13672
13673 load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13674
13675 call __cast6_dec_blk8;
13676
13677 - store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13678 + store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13679
13680 - popq %r12;
13681 + popq %r14;
13682
13683 + pax_force_retaddr
13684 ret;
13685 ENDPROC(cast6_cbc_dec_8way)
13686
13687 @@ -410,20 +416,21 @@ ENTRY(cast6_ctr_8way)
13688 * %rcx: iv (little endian, 128bit)
13689 */
13690
13691 - pushq %r12;
13692 + pushq %r14;
13693
13694 movq %rsi, %r11;
13695 - movq %rdx, %r12;
13696 + movq %rdx, %r14;
13697
13698 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
13699 RD2, RX, RKR, RKM);
13700
13701 call __cast6_enc_blk8;
13702
13703 - store_ctr_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13704 + store_ctr_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13705
13706 - popq %r12;
13707 + popq %r14;
13708
13709 + pax_force_retaddr
13710 ret;
13711 ENDPROC(cast6_ctr_8way)
13712
13713 @@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
13714 /* dst <= regs xor IVs(in dst) */
13715 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13716
13717 + pax_force_retaddr
13718 ret;
13719 ENDPROC(cast6_xts_enc_8way)
13720
13721 @@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
13722 /* dst <= regs xor IVs(in dst) */
13723 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13724
13725 + pax_force_retaddr
13726 ret;
13727 ENDPROC(cast6_xts_dec_8way)
13728 diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13729 index dbc4339..de6e120 100644
13730 --- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13731 +++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13732 @@ -45,6 +45,7 @@
13733
13734 #include <asm/inst.h>
13735 #include <linux/linkage.h>
13736 +#include <asm/alternative-asm.h>
13737
13738 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
13739
13740 @@ -312,6 +313,7 @@ do_return:
13741 popq %rsi
13742 popq %rdi
13743 popq %rbx
13744 + pax_force_retaddr
13745 ret
13746
13747 ################################################################
13748 diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
13749 index 185fad4..ff4cd36 100644
13750 --- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
13751 +++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
13752 @@ -18,6 +18,7 @@
13753
13754 #include <linux/linkage.h>
13755 #include <asm/inst.h>
13756 +#include <asm/alternative-asm.h>
13757
13758 .data
13759
13760 @@ -89,6 +90,7 @@ __clmul_gf128mul_ble:
13761 psrlq $1, T2
13762 pxor T2, T1
13763 pxor T1, DATA
13764 + pax_force_retaddr
13765 ret
13766 ENDPROC(__clmul_gf128mul_ble)
13767
13768 @@ -101,6 +103,7 @@ ENTRY(clmul_ghash_mul)
13769 call __clmul_gf128mul_ble
13770 PSHUFB_XMM BSWAP DATA
13771 movups DATA, (%rdi)
13772 + pax_force_retaddr
13773 ret
13774 ENDPROC(clmul_ghash_mul)
13775
13776 @@ -128,5 +131,6 @@ ENTRY(clmul_ghash_update)
13777 PSHUFB_XMM BSWAP DATA
13778 movups DATA, (%rdi)
13779 .Lupdate_just_ret:
13780 + pax_force_retaddr
13781 ret
13782 ENDPROC(clmul_ghash_update)
13783 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
13784 index 9279e0b..c4b3d2c 100644
13785 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
13786 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
13787 @@ -1,4 +1,5 @@
13788 #include <linux/linkage.h>
13789 +#include <asm/alternative-asm.h>
13790
13791 # enter salsa20_encrypt_bytes
13792 ENTRY(salsa20_encrypt_bytes)
13793 @@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
13794 add %r11,%rsp
13795 mov %rdi,%rax
13796 mov %rsi,%rdx
13797 + pax_force_retaddr
13798 ret
13799 # bytesatleast65:
13800 ._bytesatleast65:
13801 @@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
13802 add %r11,%rsp
13803 mov %rdi,%rax
13804 mov %rsi,%rdx
13805 + pax_force_retaddr
13806 ret
13807 ENDPROC(salsa20_keysetup)
13808
13809 @@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
13810 add %r11,%rsp
13811 mov %rdi,%rax
13812 mov %rsi,%rdx
13813 + pax_force_retaddr
13814 ret
13815 ENDPROC(salsa20_ivsetup)
13816 diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13817 index 2f202f4..d9164d6 100644
13818 --- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13819 +++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13820 @@ -24,6 +24,7 @@
13821 */
13822
13823 #include <linux/linkage.h>
13824 +#include <asm/alternative-asm.h>
13825 #include "glue_helper-asm-avx.S"
13826
13827 .file "serpent-avx-x86_64-asm_64.S"
13828 @@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
13829 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13830 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13831
13832 + pax_force_retaddr
13833 ret;
13834 ENDPROC(__serpent_enc_blk8_avx)
13835
13836 @@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
13837 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13838 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13839
13840 + pax_force_retaddr
13841 ret;
13842 ENDPROC(__serpent_dec_blk8_avx)
13843
13844 @@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
13845
13846 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13847
13848 + pax_force_retaddr
13849 ret;
13850 ENDPROC(serpent_ecb_enc_8way_avx)
13851
13852 @@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
13853
13854 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13855
13856 + pax_force_retaddr
13857 ret;
13858 ENDPROC(serpent_ecb_dec_8way_avx)
13859
13860 @@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
13861
13862 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13863
13864 + pax_force_retaddr
13865 ret;
13866 ENDPROC(serpent_cbc_dec_8way_avx)
13867
13868 @@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
13869
13870 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13871
13872 + pax_force_retaddr
13873 ret;
13874 ENDPROC(serpent_ctr_8way_avx)
13875
13876 @@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
13877 /* dst <= regs xor IVs(in dst) */
13878 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13879
13880 + pax_force_retaddr
13881 ret;
13882 ENDPROC(serpent_xts_enc_8way_avx)
13883
13884 @@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
13885 /* dst <= regs xor IVs(in dst) */
13886 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13887
13888 + pax_force_retaddr
13889 ret;
13890 ENDPROC(serpent_xts_dec_8way_avx)
13891 diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
13892 index b222085..abd483c 100644
13893 --- a/arch/x86/crypto/serpent-avx2-asm_64.S
13894 +++ b/arch/x86/crypto/serpent-avx2-asm_64.S
13895 @@ -15,6 +15,7 @@
13896 */
13897
13898 #include <linux/linkage.h>
13899 +#include <asm/alternative-asm.h>
13900 #include "glue_helper-asm-avx2.S"
13901
13902 .file "serpent-avx2-asm_64.S"
13903 @@ -610,6 +611,7 @@ __serpent_enc_blk16:
13904 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13905 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13906
13907 + pax_force_retaddr
13908 ret;
13909 ENDPROC(__serpent_enc_blk16)
13910
13911 @@ -664,6 +666,7 @@ __serpent_dec_blk16:
13912 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13913 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13914
13915 + pax_force_retaddr
13916 ret;
13917 ENDPROC(__serpent_dec_blk16)
13918
13919 @@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
13920
13921 vzeroupper;
13922
13923 + pax_force_retaddr
13924 ret;
13925 ENDPROC(serpent_ecb_enc_16way)
13926
13927 @@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
13928
13929 vzeroupper;
13930
13931 + pax_force_retaddr
13932 ret;
13933 ENDPROC(serpent_ecb_dec_16way)
13934
13935 @@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
13936
13937 vzeroupper;
13938
13939 + pax_force_retaddr
13940 ret;
13941 ENDPROC(serpent_cbc_dec_16way)
13942
13943 @@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
13944
13945 vzeroupper;
13946
13947 + pax_force_retaddr
13948 ret;
13949 ENDPROC(serpent_ctr_16way)
13950
13951 @@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
13952
13953 vzeroupper;
13954
13955 + pax_force_retaddr
13956 ret;
13957 ENDPROC(serpent_xts_enc_16way)
13958
13959 @@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
13960
13961 vzeroupper;
13962
13963 + pax_force_retaddr
13964 ret;
13965 ENDPROC(serpent_xts_dec_16way)
13966 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13967 index acc066c..1559cc4 100644
13968 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13969 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13970 @@ -25,6 +25,7 @@
13971 */
13972
13973 #include <linux/linkage.h>
13974 +#include <asm/alternative-asm.h>
13975
13976 .file "serpent-sse2-x86_64-asm_64.S"
13977 .text
13978 @@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
13979 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13980 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13981
13982 + pax_force_retaddr
13983 ret;
13984
13985 .L__enc_xor8:
13986 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13987 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13988
13989 + pax_force_retaddr
13990 ret;
13991 ENDPROC(__serpent_enc_blk_8way)
13992
13993 @@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
13994 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13995 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13996
13997 + pax_force_retaddr
13998 ret;
13999 ENDPROC(serpent_dec_blk_8way)
14000 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
14001 index a410950..9dfe7ad 100644
14002 --- a/arch/x86/crypto/sha1_ssse3_asm.S
14003 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
14004 @@ -29,6 +29,7 @@
14005 */
14006
14007 #include <linux/linkage.h>
14008 +#include <asm/alternative-asm.h>
14009
14010 #define CTX %rdi // arg1
14011 #define BUF %rsi // arg2
14012 @@ -75,9 +76,9 @@
14013
14014 push %rbx
14015 push %rbp
14016 - push %r12
14017 + push %r14
14018
14019 - mov %rsp, %r12
14020 + mov %rsp, %r14
14021 sub $64, %rsp # allocate workspace
14022 and $~15, %rsp # align stack
14023
14024 @@ -99,11 +100,12 @@
14025 xor %rax, %rax
14026 rep stosq
14027
14028 - mov %r12, %rsp # deallocate workspace
14029 + mov %r14, %rsp # deallocate workspace
14030
14031 - pop %r12
14032 + pop %r14
14033 pop %rbp
14034 pop %rbx
14035 + pax_force_retaddr
14036 ret
14037
14038 ENDPROC(\name)
14039 diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
14040 index 642f156..51a513c 100644
14041 --- a/arch/x86/crypto/sha256-avx-asm.S
14042 +++ b/arch/x86/crypto/sha256-avx-asm.S
14043 @@ -49,6 +49,7 @@
14044
14045 #ifdef CONFIG_AS_AVX
14046 #include <linux/linkage.h>
14047 +#include <asm/alternative-asm.h>
14048
14049 ## assume buffers not aligned
14050 #define VMOVDQ vmovdqu
14051 @@ -460,6 +461,7 @@ done_hash:
14052 popq %r13
14053 popq %rbp
14054 popq %rbx
14055 + pax_force_retaddr
14056 ret
14057 ENDPROC(sha256_transform_avx)
14058
14059 diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
14060 index 9e86944..3795e6a 100644
14061 --- a/arch/x86/crypto/sha256-avx2-asm.S
14062 +++ b/arch/x86/crypto/sha256-avx2-asm.S
14063 @@ -50,6 +50,7 @@
14064
14065 #ifdef CONFIG_AS_AVX2
14066 #include <linux/linkage.h>
14067 +#include <asm/alternative-asm.h>
14068
14069 ## assume buffers not aligned
14070 #define VMOVDQ vmovdqu
14071 @@ -720,6 +721,7 @@ done_hash:
14072 popq %r12
14073 popq %rbp
14074 popq %rbx
14075 + pax_force_retaddr
14076 ret
14077 ENDPROC(sha256_transform_rorx)
14078
14079 diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
14080 index f833b74..8c62a9e 100644
14081 --- a/arch/x86/crypto/sha256-ssse3-asm.S
14082 +++ b/arch/x86/crypto/sha256-ssse3-asm.S
14083 @@ -47,6 +47,7 @@
14084 ########################################################################
14085
14086 #include <linux/linkage.h>
14087 +#include <asm/alternative-asm.h>
14088
14089 ## assume buffers not aligned
14090 #define MOVDQ movdqu
14091 @@ -471,6 +472,7 @@ done_hash:
14092 popq %rbp
14093 popq %rbx
14094
14095 + pax_force_retaddr
14096 ret
14097 ENDPROC(sha256_transform_ssse3)
14098
14099 diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
14100 index 974dde9..a823ff9 100644
14101 --- a/arch/x86/crypto/sha512-avx-asm.S
14102 +++ b/arch/x86/crypto/sha512-avx-asm.S
14103 @@ -49,6 +49,7 @@
14104
14105 #ifdef CONFIG_AS_AVX
14106 #include <linux/linkage.h>
14107 +#include <asm/alternative-asm.h>
14108
14109 .text
14110
14111 @@ -364,6 +365,7 @@ updateblock:
14112 mov frame_RSPSAVE(%rsp), %rsp
14113
14114 nowork:
14115 + pax_force_retaddr
14116 ret
14117 ENDPROC(sha512_transform_avx)
14118
14119 diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
14120 index 568b961..ed20c37 100644
14121 --- a/arch/x86/crypto/sha512-avx2-asm.S
14122 +++ b/arch/x86/crypto/sha512-avx2-asm.S
14123 @@ -51,6 +51,7 @@
14124
14125 #ifdef CONFIG_AS_AVX2
14126 #include <linux/linkage.h>
14127 +#include <asm/alternative-asm.h>
14128
14129 .text
14130
14131 @@ -678,6 +679,7 @@ done_hash:
14132
14133 # Restore Stack Pointer
14134 mov frame_RSPSAVE(%rsp), %rsp
14135 + pax_force_retaddr
14136 ret
14137 ENDPROC(sha512_transform_rorx)
14138
14139 diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
14140 index fb56855..6edd768 100644
14141 --- a/arch/x86/crypto/sha512-ssse3-asm.S
14142 +++ b/arch/x86/crypto/sha512-ssse3-asm.S
14143 @@ -48,6 +48,7 @@
14144 ########################################################################
14145
14146 #include <linux/linkage.h>
14147 +#include <asm/alternative-asm.h>
14148
14149 .text
14150
14151 @@ -363,6 +364,7 @@ updateblock:
14152 mov frame_RSPSAVE(%rsp), %rsp
14153
14154 nowork:
14155 + pax_force_retaddr
14156 ret
14157 ENDPROC(sha512_transform_ssse3)
14158
14159 diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14160 index 0505813..b067311 100644
14161 --- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14162 +++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
14163 @@ -24,6 +24,7 @@
14164 */
14165
14166 #include <linux/linkage.h>
14167 +#include <asm/alternative-asm.h>
14168 #include "glue_helper-asm-avx.S"
14169
14170 .file "twofish-avx-x86_64-asm_64.S"
14171 @@ -284,6 +285,7 @@ __twofish_enc_blk8:
14172 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
14173 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
14174
14175 + pax_force_retaddr
14176 ret;
14177 ENDPROC(__twofish_enc_blk8)
14178
14179 @@ -324,6 +326,7 @@ __twofish_dec_blk8:
14180 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
14181 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
14182
14183 + pax_force_retaddr
14184 ret;
14185 ENDPROC(__twofish_dec_blk8)
14186
14187 @@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
14188
14189 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14190
14191 + pax_force_retaddr
14192 ret;
14193 ENDPROC(twofish_ecb_enc_8way)
14194
14195 @@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
14196
14197 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14198
14199 + pax_force_retaddr
14200 ret;
14201 ENDPROC(twofish_ecb_dec_8way)
14202
14203 @@ -370,19 +375,20 @@ ENTRY(twofish_cbc_dec_8way)
14204 * %rdx: src
14205 */
14206
14207 - pushq %r12;
14208 + pushq %r14;
14209
14210 movq %rsi, %r11;
14211 - movq %rdx, %r12;
14212 + movq %rdx, %r14;
14213
14214 load_8way(%rdx, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14215
14216 call __twofish_dec_blk8;
14217
14218 - store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14219 + store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14220
14221 - popq %r12;
14222 + popq %r14;
14223
14224 + pax_force_retaddr
14225 ret;
14226 ENDPROC(twofish_cbc_dec_8way)
14227
14228 @@ -394,20 +400,21 @@ ENTRY(twofish_ctr_8way)
14229 * %rcx: iv (little endian, 128bit)
14230 */
14231
14232 - pushq %r12;
14233 + pushq %r14;
14234
14235 movq %rsi, %r11;
14236 - movq %rdx, %r12;
14237 + movq %rdx, %r14;
14238
14239 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
14240 RD2, RX0, RX1, RY0);
14241
14242 call __twofish_enc_blk8;
14243
14244 - store_ctr_8way(%r12, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14245 + store_ctr_8way(%r14, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14246
14247 - popq %r12;
14248 + popq %r14;
14249
14250 + pax_force_retaddr
14251 ret;
14252 ENDPROC(twofish_ctr_8way)
14253
14254 @@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
14255 /* dst <= regs xor IVs(in dst) */
14256 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
14257
14258 + pax_force_retaddr
14259 ret;
14260 ENDPROC(twofish_xts_enc_8way)
14261
14262 @@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
14263 /* dst <= regs xor IVs(in dst) */
14264 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
14265
14266 + pax_force_retaddr
14267 ret;
14268 ENDPROC(twofish_xts_dec_8way)
14269 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14270 index 1c3b7ce..02f578d 100644
14271 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14272 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
14273 @@ -21,6 +21,7 @@
14274 */
14275
14276 #include <linux/linkage.h>
14277 +#include <asm/alternative-asm.h>
14278
14279 .file "twofish-x86_64-asm-3way.S"
14280 .text
14281 @@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
14282 popq %r13;
14283 popq %r14;
14284 popq %r15;
14285 + pax_force_retaddr
14286 ret;
14287
14288 .L__enc_xor3:
14289 @@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
14290 popq %r13;
14291 popq %r14;
14292 popq %r15;
14293 + pax_force_retaddr
14294 ret;
14295 ENDPROC(__twofish_enc_blk_3way)
14296
14297 @@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
14298 popq %r13;
14299 popq %r14;
14300 popq %r15;
14301 + pax_force_retaddr
14302 ret;
14303 ENDPROC(twofish_dec_blk_3way)
14304 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
14305 index a039d21..524b8b2 100644
14306 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
14307 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
14308 @@ -22,6 +22,7 @@
14309
14310 #include <linux/linkage.h>
14311 #include <asm/asm-offsets.h>
14312 +#include <asm/alternative-asm.h>
14313
14314 #define a_offset 0
14315 #define b_offset 4
14316 @@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
14317
14318 popq R1
14319 movq $1,%rax
14320 + pax_force_retaddr
14321 ret
14322 ENDPROC(twofish_enc_blk)
14323
14324 @@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
14325
14326 popq R1
14327 movq $1,%rax
14328 + pax_force_retaddr
14329 ret
14330 ENDPROC(twofish_dec_blk)
14331 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
14332 index d21ff89..6da8e6e 100644
14333 --- a/arch/x86/ia32/ia32_aout.c
14334 +++ b/arch/x86/ia32/ia32_aout.c
14335 @@ -153,6 +153,8 @@ static int aout_core_dump(struct coredump_params *cprm)
14336 unsigned long dump_start, dump_size;
14337 struct user32 dump;
14338
14339 + memset(&dump, 0, sizeof(dump));
14340 +
14341 fs = get_fs();
14342 set_fs(KERNEL_DS);
14343 has_dumped = 1;
14344 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
14345 index 2206757..85cbcfa 100644
14346 --- a/arch/x86/ia32/ia32_signal.c
14347 +++ b/arch/x86/ia32/ia32_signal.c
14348 @@ -218,7 +218,7 @@ asmlinkage long sys32_sigreturn(void)
14349 if (__get_user(set.sig[0], &frame->sc.oldmask)
14350 || (_COMPAT_NSIG_WORDS > 1
14351 && __copy_from_user((((char *) &set.sig) + 4),
14352 - &frame->extramask,
14353 + frame->extramask,
14354 sizeof(frame->extramask))))
14355 goto badframe;
14356
14357 @@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
14358 sp -= frame_size;
14359 /* Align the stack pointer according to the i386 ABI,
14360 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
14361 - sp = ((sp + 4) & -16ul) - 4;
14362 + sp = ((sp - 12) & -16ul) - 4;
14363 return (void __user *) sp;
14364 }
14365
14366 @@ -386,7 +386,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14367 restorer = VDSO32_SYMBOL(current->mm->context.vdso,
14368 sigreturn);
14369 else
14370 - restorer = &frame->retcode;
14371 + restorer = frame->retcode;
14372 }
14373
14374 put_user_try {
14375 @@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
14376 * These are actually not used anymore, but left because some
14377 * gdb versions depend on them as a marker.
14378 */
14379 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14380 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14381 } put_user_catch(err);
14382
14383 if (err)
14384 @@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14385 0xb8,
14386 __NR_ia32_rt_sigreturn,
14387 0x80cd,
14388 - 0,
14389 + 0
14390 };
14391
14392 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
14393 @@ -461,16 +461,18 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
14394
14395 if (ksig->ka.sa.sa_flags & SA_RESTORER)
14396 restorer = ksig->ka.sa.sa_restorer;
14397 + else if (current->mm->context.vdso)
14398 + /* Return stub is in 32bit vsyscall page */
14399 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
14400 else
14401 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
14402 - rt_sigreturn);
14403 + restorer = frame->retcode;
14404 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
14405
14406 /*
14407 * Not actually used anymore, but left because some gdb
14408 * versions need it.
14409 */
14410 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
14411 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
14412 } put_user_catch(err);
14413
14414 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
14415 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
14416 index 4299eb0..c0687a7 100644
14417 --- a/arch/x86/ia32/ia32entry.S
14418 +++ b/arch/x86/ia32/ia32entry.S
14419 @@ -15,8 +15,10 @@
14420 #include <asm/irqflags.h>
14421 #include <asm/asm.h>
14422 #include <asm/smap.h>
14423 +#include <asm/pgtable.h>
14424 #include <linux/linkage.h>
14425 #include <linux/err.h>
14426 +#include <asm/alternative-asm.h>
14427
14428 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
14429 #include <linux/elf-em.h>
14430 @@ -62,12 +64,12 @@
14431 */
14432 .macro LOAD_ARGS32 offset, _r9=0
14433 .if \_r9
14434 - movl \offset+16(%rsp),%r9d
14435 + movl \offset+R9(%rsp),%r9d
14436 .endif
14437 - movl \offset+40(%rsp),%ecx
14438 - movl \offset+48(%rsp),%edx
14439 - movl \offset+56(%rsp),%esi
14440 - movl \offset+64(%rsp),%edi
14441 + movl \offset+RCX(%rsp),%ecx
14442 + movl \offset+RDX(%rsp),%edx
14443 + movl \offset+RSI(%rsp),%esi
14444 + movl \offset+RDI(%rsp),%edi
14445 movl %eax,%eax /* zero extension */
14446 .endm
14447
14448 @@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
14449 ENDPROC(native_irq_enable_sysexit)
14450 #endif
14451
14452 + .macro pax_enter_kernel_user
14453 + pax_set_fptr_mask
14454 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14455 + call pax_enter_kernel_user
14456 +#endif
14457 + .endm
14458 +
14459 + .macro pax_exit_kernel_user
14460 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14461 + call pax_exit_kernel_user
14462 +#endif
14463 +#ifdef CONFIG_PAX_RANDKSTACK
14464 + pushq %rax
14465 + pushq %r11
14466 + call pax_randomize_kstack
14467 + popq %r11
14468 + popq %rax
14469 +#endif
14470 + .endm
14471 +
14472 + .macro pax_erase_kstack
14473 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14474 + call pax_erase_kstack
14475 +#endif
14476 + .endm
14477 +
14478 /*
14479 * 32bit SYSENTER instruction entry.
14480 *
14481 @@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
14482 CFI_REGISTER rsp,rbp
14483 SWAPGS_UNSAFE_STACK
14484 movq PER_CPU_VAR(kernel_stack), %rsp
14485 - addq $(KERNEL_STACK_OFFSET),%rsp
14486 - /*
14487 - * No need to follow this irqs on/off section: the syscall
14488 - * disabled irqs, here we enable it straight after entry:
14489 - */
14490 - ENABLE_INTERRUPTS(CLBR_NONE)
14491 movl %ebp,%ebp /* zero extension */
14492 pushq_cfi $__USER32_DS
14493 /*CFI_REL_OFFSET ss,0*/
14494 @@ -135,24 +157,49 @@ ENTRY(ia32_sysenter_target)
14495 CFI_REL_OFFSET rsp,0
14496 pushfq_cfi
14497 /*CFI_REL_OFFSET rflags,0*/
14498 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
14499 - CFI_REGISTER rip,r10
14500 + orl $X86_EFLAGS_IF,(%rsp)
14501 + GET_THREAD_INFO(%r11)
14502 + movl TI_sysenter_return(%r11), %r11d
14503 + CFI_REGISTER rip,r11
14504 pushq_cfi $__USER32_CS
14505 /*CFI_REL_OFFSET cs,0*/
14506 movl %eax, %eax
14507 - pushq_cfi %r10
14508 + pushq_cfi %r11
14509 CFI_REL_OFFSET rip,0
14510 pushq_cfi %rax
14511 cld
14512 SAVE_ARGS 0,1,0
14513 + pax_enter_kernel_user
14514 +
14515 +#ifdef CONFIG_PAX_RANDKSTACK
14516 + pax_erase_kstack
14517 +#endif
14518 +
14519 + /*
14520 + * No need to follow this irqs on/off section: the syscall
14521 + * disabled irqs, here we enable it straight after entry:
14522 + */
14523 + ENABLE_INTERRUPTS(CLBR_NONE)
14524 /* no need to do an access_ok check here because rbp has been
14525 32bit zero extended */
14526 +
14527 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14528 + addq pax_user_shadow_base,%rbp
14529 + ASM_PAX_OPEN_USERLAND
14530 +#endif
14531 +
14532 ASM_STAC
14533 1: movl (%rbp),%ebp
14534 _ASM_EXTABLE(1b,ia32_badarg)
14535 ASM_CLAC
14536 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14537 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14538 +
14539 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14540 + ASM_PAX_CLOSE_USERLAND
14541 +#endif
14542 +
14543 + GET_THREAD_INFO(%r11)
14544 + orl $TS_COMPAT,TI_status(%r11)
14545 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14546 CFI_REMEMBER_STATE
14547 jnz sysenter_tracesys
14548 cmpq $(IA32_NR_syscalls-1),%rax
14549 @@ -162,15 +209,18 @@ sysenter_do_call:
14550 sysenter_dispatch:
14551 call *ia32_sys_call_table(,%rax,8)
14552 movq %rax,RAX-ARGOFFSET(%rsp)
14553 + GET_THREAD_INFO(%r11)
14554 DISABLE_INTERRUPTS(CLBR_NONE)
14555 TRACE_IRQS_OFF
14556 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14557 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14558 jnz sysexit_audit
14559 sysexit_from_sys_call:
14560 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14561 + pax_exit_kernel_user
14562 + pax_erase_kstack
14563 + andl $~TS_COMPAT,TI_status(%r11)
14564 /* clear IF, that popfq doesn't enable interrupts early */
14565 - andl $~0x200,EFLAGS-R11(%rsp)
14566 - movl RIP-R11(%rsp),%edx /* User %eip */
14567 + andl $~X86_EFLAGS_IF,EFLAGS(%rsp)
14568 + movl RIP(%rsp),%edx /* User %eip */
14569 CFI_REGISTER rip,rdx
14570 RESTORE_ARGS 0,24,0,0,0,0
14571 xorq %r8,%r8
14572 @@ -193,6 +243,9 @@ sysexit_from_sys_call:
14573 movl %eax,%esi /* 2nd arg: syscall number */
14574 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
14575 call __audit_syscall_entry
14576 +
14577 + pax_erase_kstack
14578 +
14579 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
14580 cmpq $(IA32_NR_syscalls-1),%rax
14581 ja ia32_badsys
14582 @@ -204,7 +257,7 @@ sysexit_from_sys_call:
14583 .endm
14584
14585 .macro auditsys_exit exit
14586 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14587 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14588 jnz ia32_ret_from_sys_call
14589 TRACE_IRQS_ON
14590 ENABLE_INTERRUPTS(CLBR_NONE)
14591 @@ -215,11 +268,12 @@ sysexit_from_sys_call:
14592 1: setbe %al /* 1 if error, 0 if not */
14593 movzbl %al,%edi /* zero-extend that into %edi */
14594 call __audit_syscall_exit
14595 + GET_THREAD_INFO(%r11)
14596 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
14597 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
14598 DISABLE_INTERRUPTS(CLBR_NONE)
14599 TRACE_IRQS_OFF
14600 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14601 + testl %edi,TI_flags(%r11)
14602 jz \exit
14603 CLEAR_RREGS -ARGOFFSET
14604 jmp int_with_check
14605 @@ -237,7 +291,7 @@ sysexit_audit:
14606
14607 sysenter_tracesys:
14608 #ifdef CONFIG_AUDITSYSCALL
14609 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14610 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14611 jz sysenter_auditsys
14612 #endif
14613 SAVE_REST
14614 @@ -249,6 +303,9 @@ sysenter_tracesys:
14615 RESTORE_REST
14616 cmpq $(IA32_NR_syscalls-1),%rax
14617 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
14618 +
14619 + pax_erase_kstack
14620 +
14621 jmp sysenter_do_call
14622 CFI_ENDPROC
14623 ENDPROC(ia32_sysenter_target)
14624 @@ -276,19 +333,25 @@ ENDPROC(ia32_sysenter_target)
14625 ENTRY(ia32_cstar_target)
14626 CFI_STARTPROC32 simple
14627 CFI_SIGNAL_FRAME
14628 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
14629 + CFI_DEF_CFA rsp,0
14630 CFI_REGISTER rip,rcx
14631 /*CFI_REGISTER rflags,r11*/
14632 SWAPGS_UNSAFE_STACK
14633 movl %esp,%r8d
14634 CFI_REGISTER rsp,r8
14635 movq PER_CPU_VAR(kernel_stack),%rsp
14636 + SAVE_ARGS 8*6,0,0
14637 + pax_enter_kernel_user
14638 +
14639 +#ifdef CONFIG_PAX_RANDKSTACK
14640 + pax_erase_kstack
14641 +#endif
14642 +
14643 /*
14644 * No need to follow this irqs on/off section: the syscall
14645 * disabled irqs and here we enable it straight after entry:
14646 */
14647 ENABLE_INTERRUPTS(CLBR_NONE)
14648 - SAVE_ARGS 8,0,0
14649 movl %eax,%eax /* zero extension */
14650 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
14651 movq %rcx,RIP-ARGOFFSET(%rsp)
14652 @@ -304,12 +367,25 @@ ENTRY(ia32_cstar_target)
14653 /* no need to do an access_ok check here because r8 has been
14654 32bit zero extended */
14655 /* hardware stack frame is complete now */
14656 +
14657 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14658 + ASM_PAX_OPEN_USERLAND
14659 + movq pax_user_shadow_base,%r8
14660 + addq RSP-ARGOFFSET(%rsp),%r8
14661 +#endif
14662 +
14663 ASM_STAC
14664 1: movl (%r8),%r9d
14665 _ASM_EXTABLE(1b,ia32_badarg)
14666 ASM_CLAC
14667 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14668 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14669 +
14670 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14671 + ASM_PAX_CLOSE_USERLAND
14672 +#endif
14673 +
14674 + GET_THREAD_INFO(%r11)
14675 + orl $TS_COMPAT,TI_status(%r11)
14676 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14677 CFI_REMEMBER_STATE
14678 jnz cstar_tracesys
14679 cmpq $IA32_NR_syscalls-1,%rax
14680 @@ -319,13 +395,16 @@ cstar_do_call:
14681 cstar_dispatch:
14682 call *ia32_sys_call_table(,%rax,8)
14683 movq %rax,RAX-ARGOFFSET(%rsp)
14684 + GET_THREAD_INFO(%r11)
14685 DISABLE_INTERRUPTS(CLBR_NONE)
14686 TRACE_IRQS_OFF
14687 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14688 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14689 jnz sysretl_audit
14690 sysretl_from_sys_call:
14691 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14692 - RESTORE_ARGS 0,-ARG_SKIP,0,0,0
14693 + pax_exit_kernel_user
14694 + pax_erase_kstack
14695 + andl $~TS_COMPAT,TI_status(%r11)
14696 + RESTORE_ARGS 0,-ORIG_RAX,0,0,0
14697 movl RIP-ARGOFFSET(%rsp),%ecx
14698 CFI_REGISTER rip,rcx
14699 movl EFLAGS-ARGOFFSET(%rsp),%r11d
14700 @@ -352,7 +431,7 @@ sysretl_audit:
14701
14702 cstar_tracesys:
14703 #ifdef CONFIG_AUDITSYSCALL
14704 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14705 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14706 jz cstar_auditsys
14707 #endif
14708 xchgl %r9d,%ebp
14709 @@ -366,11 +445,19 @@ cstar_tracesys:
14710 xchgl %ebp,%r9d
14711 cmpq $(IA32_NR_syscalls-1),%rax
14712 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
14713 +
14714 + pax_erase_kstack
14715 +
14716 jmp cstar_do_call
14717 END(ia32_cstar_target)
14718
14719 ia32_badarg:
14720 ASM_CLAC
14721 +
14722 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14723 + ASM_PAX_CLOSE_USERLAND
14724 +#endif
14725 +
14726 movq $-EFAULT,%rax
14727 jmp ia32_sysret
14728 CFI_ENDPROC
14729 @@ -407,19 +494,26 @@ ENTRY(ia32_syscall)
14730 CFI_REL_OFFSET rip,RIP-RIP
14731 PARAVIRT_ADJUST_EXCEPTION_FRAME
14732 SWAPGS
14733 - /*
14734 - * No need to follow this irqs on/off section: the syscall
14735 - * disabled irqs and here we enable it straight after entry:
14736 - */
14737 - ENABLE_INTERRUPTS(CLBR_NONE)
14738 movl %eax,%eax
14739 pushq_cfi %rax
14740 cld
14741 /* note the registers are not zero extended to the sf.
14742 this could be a problem. */
14743 SAVE_ARGS 0,1,0
14744 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14745 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14746 + pax_enter_kernel_user
14747 +
14748 +#ifdef CONFIG_PAX_RANDKSTACK
14749 + pax_erase_kstack
14750 +#endif
14751 +
14752 + /*
14753 + * No need to follow this irqs on/off section: the syscall
14754 + * disabled irqs and here we enable it straight after entry:
14755 + */
14756 + ENABLE_INTERRUPTS(CLBR_NONE)
14757 + GET_THREAD_INFO(%r11)
14758 + orl $TS_COMPAT,TI_status(%r11)
14759 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14760 jnz ia32_tracesys
14761 cmpq $(IA32_NR_syscalls-1),%rax
14762 ja ia32_badsys
14763 @@ -442,6 +536,9 @@ ia32_tracesys:
14764 RESTORE_REST
14765 cmpq $(IA32_NR_syscalls-1),%rax
14766 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
14767 +
14768 + pax_erase_kstack
14769 +
14770 jmp ia32_do_call
14771 END(ia32_syscall)
14772
14773 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
14774 index 8e0ceec..af13504 100644
14775 --- a/arch/x86/ia32/sys_ia32.c
14776 +++ b/arch/x86/ia32/sys_ia32.c
14777 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
14778 */
14779 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
14780 {
14781 - typeof(ubuf->st_uid) uid = 0;
14782 - typeof(ubuf->st_gid) gid = 0;
14783 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
14784 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
14785 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
14786 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
14787 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
14788 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
14789 index 372231c..51b537d 100644
14790 --- a/arch/x86/include/asm/alternative-asm.h
14791 +++ b/arch/x86/include/asm/alternative-asm.h
14792 @@ -18,6 +18,45 @@
14793 .endm
14794 #endif
14795
14796 +#ifdef KERNEXEC_PLUGIN
14797 + .macro pax_force_retaddr_bts rip=0
14798 + btsq $63,\rip(%rsp)
14799 + .endm
14800 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
14801 + .macro pax_force_retaddr rip=0, reload=0
14802 + btsq $63,\rip(%rsp)
14803 + .endm
14804 + .macro pax_force_fptr ptr
14805 + btsq $63,\ptr
14806 + .endm
14807 + .macro pax_set_fptr_mask
14808 + .endm
14809 +#endif
14810 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
14811 + .macro pax_force_retaddr rip=0, reload=0
14812 + .if \reload
14813 + pax_set_fptr_mask
14814 + .endif
14815 + orq %r12,\rip(%rsp)
14816 + .endm
14817 + .macro pax_force_fptr ptr
14818 + orq %r12,\ptr
14819 + .endm
14820 + .macro pax_set_fptr_mask
14821 + movabs $0x8000000000000000,%r12
14822 + .endm
14823 +#endif
14824 +#else
14825 + .macro pax_force_retaddr rip=0, reload=0
14826 + .endm
14827 + .macro pax_force_fptr ptr
14828 + .endm
14829 + .macro pax_force_retaddr_bts rip=0
14830 + .endm
14831 + .macro pax_set_fptr_mask
14832 + .endm
14833 +#endif
14834 +
14835 .macro altinstruction_entry orig alt feature orig_len alt_len
14836 .long \orig - .
14837 .long \alt - .
14838 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
14839 index 0a3f9c9..c9d081d 100644
14840 --- a/arch/x86/include/asm/alternative.h
14841 +++ b/arch/x86/include/asm/alternative.h
14842 @@ -106,7 +106,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
14843 ".pushsection .discard,\"aw\",@progbits\n" \
14844 DISCARD_ENTRY(1) \
14845 ".popsection\n" \
14846 - ".pushsection .altinstr_replacement, \"ax\"\n" \
14847 + ".pushsection .altinstr_replacement, \"a\"\n" \
14848 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
14849 ".popsection"
14850
14851 @@ -120,7 +120,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
14852 DISCARD_ENTRY(1) \
14853 DISCARD_ENTRY(2) \
14854 ".popsection\n" \
14855 - ".pushsection .altinstr_replacement, \"ax\"\n" \
14856 + ".pushsection .altinstr_replacement, \"a\"\n" \
14857 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
14858 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
14859 ".popsection"
14860 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
14861 index 19b0eba..12254cd 100644
14862 --- a/arch/x86/include/asm/apic.h
14863 +++ b/arch/x86/include/asm/apic.h
14864 @@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
14865
14866 #ifdef CONFIG_X86_LOCAL_APIC
14867
14868 -extern unsigned int apic_verbosity;
14869 +extern int apic_verbosity;
14870 extern int local_apic_timer_c2_ok;
14871
14872 extern int disable_apic;
14873 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
14874 index 20370c6..a2eb9b0 100644
14875 --- a/arch/x86/include/asm/apm.h
14876 +++ b/arch/x86/include/asm/apm.h
14877 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
14878 __asm__ __volatile__(APM_DO_ZERO_SEGS
14879 "pushl %%edi\n\t"
14880 "pushl %%ebp\n\t"
14881 - "lcall *%%cs:apm_bios_entry\n\t"
14882 + "lcall *%%ss:apm_bios_entry\n\t"
14883 "setc %%al\n\t"
14884 "popl %%ebp\n\t"
14885 "popl %%edi\n\t"
14886 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
14887 __asm__ __volatile__(APM_DO_ZERO_SEGS
14888 "pushl %%edi\n\t"
14889 "pushl %%ebp\n\t"
14890 - "lcall *%%cs:apm_bios_entry\n\t"
14891 + "lcall *%%ss:apm_bios_entry\n\t"
14892 "setc %%bl\n\t"
14893 "popl %%ebp\n\t"
14894 "popl %%edi\n\t"
14895 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
14896 index b17f4f4..9620151 100644
14897 --- a/arch/x86/include/asm/atomic.h
14898 +++ b/arch/x86/include/asm/atomic.h
14899 @@ -23,7 +23,18 @@
14900 */
14901 static inline int atomic_read(const atomic_t *v)
14902 {
14903 - return (*(volatile int *)&(v)->counter);
14904 + return (*(volatile const int *)&(v)->counter);
14905 +}
14906 +
14907 +/**
14908 + * atomic_read_unchecked - read atomic variable
14909 + * @v: pointer of type atomic_unchecked_t
14910 + *
14911 + * Atomically reads the value of @v.
14912 + */
14913 +static inline int __intentional_overflow(-1) atomic_read_unchecked(const atomic_unchecked_t *v)
14914 +{
14915 + return (*(volatile const int *)&(v)->counter);
14916 }
14917
14918 /**
14919 @@ -39,6 +50,18 @@ static inline void atomic_set(atomic_t *v, int i)
14920 }
14921
14922 /**
14923 + * atomic_set_unchecked - set atomic variable
14924 + * @v: pointer of type atomic_unchecked_t
14925 + * @i: required value
14926 + *
14927 + * Atomically sets the value of @v to @i.
14928 + */
14929 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
14930 +{
14931 + v->counter = i;
14932 +}
14933 +
14934 +/**
14935 * atomic_add - add integer to atomic variable
14936 * @i: integer value to add
14937 * @v: pointer of type atomic_t
14938 @@ -47,7 +70,29 @@ static inline void atomic_set(atomic_t *v, int i)
14939 */
14940 static inline void atomic_add(int i, atomic_t *v)
14941 {
14942 - asm volatile(LOCK_PREFIX "addl %1,%0"
14943 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
14944 +
14945 +#ifdef CONFIG_PAX_REFCOUNT
14946 + "jno 0f\n"
14947 + LOCK_PREFIX "subl %1,%0\n"
14948 + "int $4\n0:\n"
14949 + _ASM_EXTABLE(0b, 0b)
14950 +#endif
14951 +
14952 + : "+m" (v->counter)
14953 + : "ir" (i));
14954 +}
14955 +
14956 +/**
14957 + * atomic_add_unchecked - add integer to atomic variable
14958 + * @i: integer value to add
14959 + * @v: pointer of type atomic_unchecked_t
14960 + *
14961 + * Atomically adds @i to @v.
14962 + */
14963 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
14964 +{
14965 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
14966 : "+m" (v->counter)
14967 : "ir" (i));
14968 }
14969 @@ -61,7 +106,29 @@ static inline void atomic_add(int i, atomic_t *v)
14970 */
14971 static inline void atomic_sub(int i, atomic_t *v)
14972 {
14973 - asm volatile(LOCK_PREFIX "subl %1,%0"
14974 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
14975 +
14976 +#ifdef CONFIG_PAX_REFCOUNT
14977 + "jno 0f\n"
14978 + LOCK_PREFIX "addl %1,%0\n"
14979 + "int $4\n0:\n"
14980 + _ASM_EXTABLE(0b, 0b)
14981 +#endif
14982 +
14983 + : "+m" (v->counter)
14984 + : "ir" (i));
14985 +}
14986 +
14987 +/**
14988 + * atomic_sub_unchecked - subtract integer from atomic variable
14989 + * @i: integer value to subtract
14990 + * @v: pointer of type atomic_unchecked_t
14991 + *
14992 + * Atomically subtracts @i from @v.
14993 + */
14994 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
14995 +{
14996 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
14997 : "+m" (v->counter)
14998 : "ir" (i));
14999 }
15000 @@ -77,7 +144,7 @@ static inline void atomic_sub(int i, atomic_t *v)
15001 */
15002 static inline int atomic_sub_and_test(int i, atomic_t *v)
15003 {
15004 - GEN_BINARY_RMWcc(LOCK_PREFIX "subl", v->counter, "er", i, "%0", "e");
15005 + GEN_BINARY_RMWcc(LOCK_PREFIX "subl", LOCK_PREFIX "addl", v->counter, "er", i, "%0", "e");
15006 }
15007
15008 /**
15009 @@ -88,7 +155,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
15010 */
15011 static inline void atomic_inc(atomic_t *v)
15012 {
15013 - asm volatile(LOCK_PREFIX "incl %0"
15014 + asm volatile(LOCK_PREFIX "incl %0\n"
15015 +
15016 +#ifdef CONFIG_PAX_REFCOUNT
15017 + "jno 0f\n"
15018 + LOCK_PREFIX "decl %0\n"
15019 + "int $4\n0:\n"
15020 + _ASM_EXTABLE(0b, 0b)
15021 +#endif
15022 +
15023 + : "+m" (v->counter));
15024 +}
15025 +
15026 +/**
15027 + * atomic_inc_unchecked - increment atomic variable
15028 + * @v: pointer of type atomic_unchecked_t
15029 + *
15030 + * Atomically increments @v by 1.
15031 + */
15032 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
15033 +{
15034 + asm volatile(LOCK_PREFIX "incl %0\n"
15035 : "+m" (v->counter));
15036 }
15037
15038 @@ -100,7 +187,27 @@ static inline void atomic_inc(atomic_t *v)
15039 */
15040 static inline void atomic_dec(atomic_t *v)
15041 {
15042 - asm volatile(LOCK_PREFIX "decl %0"
15043 + asm volatile(LOCK_PREFIX "decl %0\n"
15044 +
15045 +#ifdef CONFIG_PAX_REFCOUNT
15046 + "jno 0f\n"
15047 + LOCK_PREFIX "incl %0\n"
15048 + "int $4\n0:\n"
15049 + _ASM_EXTABLE(0b, 0b)
15050 +#endif
15051 +
15052 + : "+m" (v->counter));
15053 +}
15054 +
15055 +/**
15056 + * atomic_dec_unchecked - decrement atomic variable
15057 + * @v: pointer of type atomic_unchecked_t
15058 + *
15059 + * Atomically decrements @v by 1.
15060 + */
15061 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
15062 +{
15063 + asm volatile(LOCK_PREFIX "decl %0\n"
15064 : "+m" (v->counter));
15065 }
15066
15067 @@ -114,7 +221,7 @@ static inline void atomic_dec(atomic_t *v)
15068 */
15069 static inline int atomic_dec_and_test(atomic_t *v)
15070 {
15071 - GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", "e");
15072 + GEN_UNARY_RMWcc(LOCK_PREFIX "decl", LOCK_PREFIX "incl", v->counter, "%0", "e");
15073 }
15074
15075 /**
15076 @@ -127,7 +234,20 @@ static inline int atomic_dec_and_test(atomic_t *v)
15077 */
15078 static inline int atomic_inc_and_test(atomic_t *v)
15079 {
15080 - GEN_UNARY_RMWcc(LOCK_PREFIX "incl", v->counter, "%0", "e");
15081 + GEN_UNARY_RMWcc(LOCK_PREFIX "incl", LOCK_PREFIX "decl", v->counter, "%0", "e");
15082 +}
15083 +
15084 +/**
15085 + * atomic_inc_and_test_unchecked - increment and test
15086 + * @v: pointer of type atomic_unchecked_t
15087 + *
15088 + * Atomically increments @v by 1
15089 + * and returns true if the result is zero, or false for all
15090 + * other cases.
15091 + */
15092 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
15093 +{
15094 + GEN_UNARY_RMWcc_unchecked(LOCK_PREFIX "incl", v->counter, "%0", "e");
15095 }
15096
15097 /**
15098 @@ -141,7 +261,7 @@ static inline int atomic_inc_and_test(atomic_t *v)
15099 */
15100 static inline int atomic_add_negative(int i, atomic_t *v)
15101 {
15102 - GEN_BINARY_RMWcc(LOCK_PREFIX "addl", v->counter, "er", i, "%0", "s");
15103 + GEN_BINARY_RMWcc(LOCK_PREFIX "addl", LOCK_PREFIX "subl", v->counter, "er", i, "%0", "s");
15104 }
15105
15106 /**
15107 @@ -153,6 +273,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
15108 */
15109 static inline int atomic_add_return(int i, atomic_t *v)
15110 {
15111 + return i + xadd_check_overflow(&v->counter, i);
15112 +}
15113 +
15114 +/**
15115 + * atomic_add_return_unchecked - add integer and return
15116 + * @i: integer value to add
15117 + * @v: pointer of type atomic_unchecked_t
15118 + *
15119 + * Atomically adds @i to @v and returns @i + @v
15120 + */
15121 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
15122 +{
15123 return i + xadd(&v->counter, i);
15124 }
15125
15126 @@ -169,9 +301,18 @@ static inline int atomic_sub_return(int i, atomic_t *v)
15127 }
15128
15129 #define atomic_inc_return(v) (atomic_add_return(1, v))
15130 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
15131 +{
15132 + return atomic_add_return_unchecked(1, v);
15133 +}
15134 #define atomic_dec_return(v) (atomic_sub_return(1, v))
15135
15136 -static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
15137 +static inline int __intentional_overflow(-1) atomic_cmpxchg(atomic_t *v, int old, int new)
15138 +{
15139 + return cmpxchg(&v->counter, old, new);
15140 +}
15141 +
15142 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
15143 {
15144 return cmpxchg(&v->counter, old, new);
15145 }
15146 @@ -181,6 +322,11 @@ static inline int atomic_xchg(atomic_t *v, int new)
15147 return xchg(&v->counter, new);
15148 }
15149
15150 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
15151 +{
15152 + return xchg(&v->counter, new);
15153 +}
15154 +
15155 /**
15156 * __atomic_add_unless - add unless the number is already a given value
15157 * @v: pointer of type atomic_t
15158 @@ -190,14 +336,27 @@ static inline int atomic_xchg(atomic_t *v, int new)
15159 * Atomically adds @a to @v, so long as @v was not already @u.
15160 * Returns the old value of @v.
15161 */
15162 -static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15163 +static inline int __intentional_overflow(-1) __atomic_add_unless(atomic_t *v, int a, int u)
15164 {
15165 - int c, old;
15166 + int c, old, new;
15167 c = atomic_read(v);
15168 for (;;) {
15169 - if (unlikely(c == (u)))
15170 + if (unlikely(c == u))
15171 break;
15172 - old = atomic_cmpxchg((v), c, c + (a));
15173 +
15174 + asm volatile("addl %2,%0\n"
15175 +
15176 +#ifdef CONFIG_PAX_REFCOUNT
15177 + "jno 0f\n"
15178 + "subl %2,%0\n"
15179 + "int $4\n0:\n"
15180 + _ASM_EXTABLE(0b, 0b)
15181 +#endif
15182 +
15183 + : "=r" (new)
15184 + : "0" (c), "ir" (a));
15185 +
15186 + old = atomic_cmpxchg(v, c, new);
15187 if (likely(old == c))
15188 break;
15189 c = old;
15190 @@ -206,6 +365,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
15191 }
15192
15193 /**
15194 + * atomic_inc_not_zero_hint - increment if not null
15195 + * @v: pointer of type atomic_t
15196 + * @hint: probable value of the atomic before the increment
15197 + *
15198 + * This version of atomic_inc_not_zero() gives a hint of probable
15199 + * value of the atomic. This helps processor to not read the memory
15200 + * before doing the atomic read/modify/write cycle, lowering
15201 + * number of bus transactions on some arches.
15202 + *
15203 + * Returns: 0 if increment was not done, 1 otherwise.
15204 + */
15205 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
15206 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
15207 +{
15208 + int val, c = hint, new;
15209 +
15210 + /* sanity test, should be removed by compiler if hint is a constant */
15211 + if (!hint)
15212 + return __atomic_add_unless(v, 1, 0);
15213 +
15214 + do {
15215 + asm volatile("incl %0\n"
15216 +
15217 +#ifdef CONFIG_PAX_REFCOUNT
15218 + "jno 0f\n"
15219 + "decl %0\n"
15220 + "int $4\n0:\n"
15221 + _ASM_EXTABLE(0b, 0b)
15222 +#endif
15223 +
15224 + : "=r" (new)
15225 + : "0" (c));
15226 +
15227 + val = atomic_cmpxchg(v, c, new);
15228 + if (val == c)
15229 + return 1;
15230 + c = val;
15231 + } while (c);
15232 +
15233 + return 0;
15234 +}
15235 +
15236 +/**
15237 * atomic_inc_short - increment of a short integer
15238 * @v: pointer to type int
15239 *
15240 @@ -234,14 +436,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
15241 #endif
15242
15243 /* These are x86-specific, used by some header files */
15244 -#define atomic_clear_mask(mask, addr) \
15245 - asm volatile(LOCK_PREFIX "andl %0,%1" \
15246 - : : "r" (~(mask)), "m" (*(addr)) : "memory")
15247 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
15248 +{
15249 + asm volatile(LOCK_PREFIX "andl %1,%0"
15250 + : "+m" (v->counter)
15251 + : "r" (~(mask))
15252 + : "memory");
15253 +}
15254
15255 -#define atomic_set_mask(mask, addr) \
15256 - asm volatile(LOCK_PREFIX "orl %0,%1" \
15257 - : : "r" ((unsigned)(mask)), "m" (*(addr)) \
15258 - : "memory")
15259 +static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15260 +{
15261 + asm volatile(LOCK_PREFIX "andl %1,%0"
15262 + : "+m" (v->counter)
15263 + : "r" (~(mask))
15264 + : "memory");
15265 +}
15266 +
15267 +static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
15268 +{
15269 + asm volatile(LOCK_PREFIX "orl %1,%0"
15270 + : "+m" (v->counter)
15271 + : "r" (mask)
15272 + : "memory");
15273 +}
15274 +
15275 +static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
15276 +{
15277 + asm volatile(LOCK_PREFIX "orl %1,%0"
15278 + : "+m" (v->counter)
15279 + : "r" (mask)
15280 + : "memory");
15281 +}
15282
15283 /* Atomic operations are already serializing on x86 */
15284 #define smp_mb__before_atomic_dec() barrier()
15285 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
15286 index b154de7..bf18a5a 100644
15287 --- a/arch/x86/include/asm/atomic64_32.h
15288 +++ b/arch/x86/include/asm/atomic64_32.h
15289 @@ -12,6 +12,14 @@ typedef struct {
15290 u64 __aligned(8) counter;
15291 } atomic64_t;
15292
15293 +#ifdef CONFIG_PAX_REFCOUNT
15294 +typedef struct {
15295 + u64 __aligned(8) counter;
15296 +} atomic64_unchecked_t;
15297 +#else
15298 +typedef atomic64_t atomic64_unchecked_t;
15299 +#endif
15300 +
15301 #define ATOMIC64_INIT(val) { (val) }
15302
15303 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
15304 @@ -37,21 +45,31 @@ typedef struct {
15305 ATOMIC64_DECL_ONE(sym##_386)
15306
15307 ATOMIC64_DECL_ONE(add_386);
15308 +ATOMIC64_DECL_ONE(add_unchecked_386);
15309 ATOMIC64_DECL_ONE(sub_386);
15310 +ATOMIC64_DECL_ONE(sub_unchecked_386);
15311 ATOMIC64_DECL_ONE(inc_386);
15312 +ATOMIC64_DECL_ONE(inc_unchecked_386);
15313 ATOMIC64_DECL_ONE(dec_386);
15314 +ATOMIC64_DECL_ONE(dec_unchecked_386);
15315 #endif
15316
15317 #define alternative_atomic64(f, out, in...) \
15318 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
15319
15320 ATOMIC64_DECL(read);
15321 +ATOMIC64_DECL(read_unchecked);
15322 ATOMIC64_DECL(set);
15323 +ATOMIC64_DECL(set_unchecked);
15324 ATOMIC64_DECL(xchg);
15325 ATOMIC64_DECL(add_return);
15326 +ATOMIC64_DECL(add_return_unchecked);
15327 ATOMIC64_DECL(sub_return);
15328 +ATOMIC64_DECL(sub_return_unchecked);
15329 ATOMIC64_DECL(inc_return);
15330 +ATOMIC64_DECL(inc_return_unchecked);
15331 ATOMIC64_DECL(dec_return);
15332 +ATOMIC64_DECL(dec_return_unchecked);
15333 ATOMIC64_DECL(dec_if_positive);
15334 ATOMIC64_DECL(inc_not_zero);
15335 ATOMIC64_DECL(add_unless);
15336 @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
15337 }
15338
15339 /**
15340 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
15341 + * @p: pointer to type atomic64_unchecked_t
15342 + * @o: expected value
15343 + * @n: new value
15344 + *
15345 + * Atomically sets @v to @n if it was equal to @o and returns
15346 + * the old value.
15347 + */
15348 +
15349 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
15350 +{
15351 + return cmpxchg64(&v->counter, o, n);
15352 +}
15353 +
15354 +/**
15355 * atomic64_xchg - xchg atomic64 variable
15356 * @v: pointer to type atomic64_t
15357 * @n: value to assign
15358 @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
15359 }
15360
15361 /**
15362 + * atomic64_set_unchecked - set atomic64 variable
15363 + * @v: pointer to type atomic64_unchecked_t
15364 + * @n: value to assign
15365 + *
15366 + * Atomically sets the value of @v to @n.
15367 + */
15368 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
15369 +{
15370 + unsigned high = (unsigned)(i >> 32);
15371 + unsigned low = (unsigned)i;
15372 + alternative_atomic64(set, /* no output */,
15373 + "S" (v), "b" (low), "c" (high)
15374 + : "eax", "edx", "memory");
15375 +}
15376 +
15377 +/**
15378 * atomic64_read - read atomic64 variable
15379 * @v: pointer to type atomic64_t
15380 *
15381 @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
15382 }
15383
15384 /**
15385 + * atomic64_read_unchecked - read atomic64 variable
15386 + * @v: pointer to type atomic64_unchecked_t
15387 + *
15388 + * Atomically reads the value of @v and returns it.
15389 + */
15390 +static inline long long __intentional_overflow(-1) atomic64_read_unchecked(atomic64_unchecked_t *v)
15391 +{
15392 + long long r;
15393 + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
15394 + return r;
15395 + }
15396 +
15397 +/**
15398 * atomic64_add_return - add and return
15399 * @i: integer value to add
15400 * @v: pointer to type atomic64_t
15401 @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
15402 return i;
15403 }
15404
15405 +/**
15406 + * atomic64_add_return_unchecked - add and return
15407 + * @i: integer value to add
15408 + * @v: pointer to type atomic64_unchecked_t
15409 + *
15410 + * Atomically adds @i to @v and returns @i + *@v
15411 + */
15412 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
15413 +{
15414 + alternative_atomic64(add_return_unchecked,
15415 + ASM_OUTPUT2("+A" (i), "+c" (v)),
15416 + ASM_NO_INPUT_CLOBBER("memory"));
15417 + return i;
15418 +}
15419 +
15420 /*
15421 * Other variants with different arithmetic operators:
15422 */
15423 @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
15424 return a;
15425 }
15426
15427 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15428 +{
15429 + long long a;
15430 + alternative_atomic64(inc_return_unchecked, "=&A" (a),
15431 + "S" (v) : "memory", "ecx");
15432 + return a;
15433 +}
15434 +
15435 static inline long long atomic64_dec_return(atomic64_t *v)
15436 {
15437 long long a;
15438 @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
15439 }
15440
15441 /**
15442 + * atomic64_add_unchecked - add integer to atomic64 variable
15443 + * @i: integer value to add
15444 + * @v: pointer to type atomic64_unchecked_t
15445 + *
15446 + * Atomically adds @i to @v.
15447 + */
15448 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
15449 +{
15450 + __alternative_atomic64(add_unchecked, add_return_unchecked,
15451 + ASM_OUTPUT2("+A" (i), "+c" (v)),
15452 + ASM_NO_INPUT_CLOBBER("memory"));
15453 + return i;
15454 +}
15455 +
15456 +/**
15457 * atomic64_sub - subtract the atomic64 variable
15458 * @i: integer value to subtract
15459 * @v: pointer to type atomic64_t
15460 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
15461 index 46e9052..ae45136 100644
15462 --- a/arch/x86/include/asm/atomic64_64.h
15463 +++ b/arch/x86/include/asm/atomic64_64.h
15464 @@ -18,7 +18,19 @@
15465 */
15466 static inline long atomic64_read(const atomic64_t *v)
15467 {
15468 - return (*(volatile long *)&(v)->counter);
15469 + return (*(volatile const long *)&(v)->counter);
15470 +}
15471 +
15472 +/**
15473 + * atomic64_read_unchecked - read atomic64 variable
15474 + * @v: pointer of type atomic64_unchecked_t
15475 + *
15476 + * Atomically reads the value of @v.
15477 + * Doesn't imply a read memory barrier.
15478 + */
15479 +static inline long __intentional_overflow(-1) atomic64_read_unchecked(const atomic64_unchecked_t *v)
15480 +{
15481 + return (*(volatile const long *)&(v)->counter);
15482 }
15483
15484 /**
15485 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
15486 }
15487
15488 /**
15489 + * atomic64_set_unchecked - set atomic64 variable
15490 + * @v: pointer to type atomic64_unchecked_t
15491 + * @i: required value
15492 + *
15493 + * Atomically sets the value of @v to @i.
15494 + */
15495 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
15496 +{
15497 + v->counter = i;
15498 +}
15499 +
15500 +/**
15501 * atomic64_add - add integer to atomic64 variable
15502 * @i: integer value to add
15503 * @v: pointer to type atomic64_t
15504 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
15505 */
15506 static inline void atomic64_add(long i, atomic64_t *v)
15507 {
15508 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
15509 +
15510 +#ifdef CONFIG_PAX_REFCOUNT
15511 + "jno 0f\n"
15512 + LOCK_PREFIX "subq %1,%0\n"
15513 + "int $4\n0:\n"
15514 + _ASM_EXTABLE(0b, 0b)
15515 +#endif
15516 +
15517 + : "=m" (v->counter)
15518 + : "er" (i), "m" (v->counter));
15519 +}
15520 +
15521 +/**
15522 + * atomic64_add_unchecked - add integer to atomic64 variable
15523 + * @i: integer value to add
15524 + * @v: pointer to type atomic64_unchecked_t
15525 + *
15526 + * Atomically adds @i to @v.
15527 + */
15528 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
15529 +{
15530 asm volatile(LOCK_PREFIX "addq %1,%0"
15531 : "=m" (v->counter)
15532 : "er" (i), "m" (v->counter));
15533 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
15534 */
15535 static inline void atomic64_sub(long i, atomic64_t *v)
15536 {
15537 - asm volatile(LOCK_PREFIX "subq %1,%0"
15538 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
15539 +
15540 +#ifdef CONFIG_PAX_REFCOUNT
15541 + "jno 0f\n"
15542 + LOCK_PREFIX "addq %1,%0\n"
15543 + "int $4\n0:\n"
15544 + _ASM_EXTABLE(0b, 0b)
15545 +#endif
15546 +
15547 + : "=m" (v->counter)
15548 + : "er" (i), "m" (v->counter));
15549 +}
15550 +
15551 +/**
15552 + * atomic64_sub_unchecked - subtract the atomic64 variable
15553 + * @i: integer value to subtract
15554 + * @v: pointer to type atomic64_unchecked_t
15555 + *
15556 + * Atomically subtracts @i from @v.
15557 + */
15558 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
15559 +{
15560 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
15561 : "=m" (v->counter)
15562 : "er" (i), "m" (v->counter));
15563 }
15564 @@ -72,7 +140,7 @@ static inline void atomic64_sub(long i, atomic64_t *v)
15565 */
15566 static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15567 {
15568 - GEN_BINARY_RMWcc(LOCK_PREFIX "subq", v->counter, "er", i, "%0", "e");
15569 + GEN_BINARY_RMWcc(LOCK_PREFIX "subq", LOCK_PREFIX "addq", v->counter, "er", i, "%0", "e");
15570 }
15571
15572 /**
15573 @@ -83,6 +151,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15574 */
15575 static inline void atomic64_inc(atomic64_t *v)
15576 {
15577 + asm volatile(LOCK_PREFIX "incq %0\n"
15578 +
15579 +#ifdef CONFIG_PAX_REFCOUNT
15580 + "jno 0f\n"
15581 + LOCK_PREFIX "decq %0\n"
15582 + "int $4\n0:\n"
15583 + _ASM_EXTABLE(0b, 0b)
15584 +#endif
15585 +
15586 + : "=m" (v->counter)
15587 + : "m" (v->counter));
15588 +}
15589 +
15590 +/**
15591 + * atomic64_inc_unchecked - increment atomic64 variable
15592 + * @v: pointer to type atomic64_unchecked_t
15593 + *
15594 + * Atomically increments @v by 1.
15595 + */
15596 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
15597 +{
15598 asm volatile(LOCK_PREFIX "incq %0"
15599 : "=m" (v->counter)
15600 : "m" (v->counter));
15601 @@ -96,7 +185,28 @@ static inline void atomic64_inc(atomic64_t *v)
15602 */
15603 static inline void atomic64_dec(atomic64_t *v)
15604 {
15605 - asm volatile(LOCK_PREFIX "decq %0"
15606 + asm volatile(LOCK_PREFIX "decq %0\n"
15607 +
15608 +#ifdef CONFIG_PAX_REFCOUNT
15609 + "jno 0f\n"
15610 + LOCK_PREFIX "incq %0\n"
15611 + "int $4\n0:\n"
15612 + _ASM_EXTABLE(0b, 0b)
15613 +#endif
15614 +
15615 + : "=m" (v->counter)
15616 + : "m" (v->counter));
15617 +}
15618 +
15619 +/**
15620 + * atomic64_dec_unchecked - decrement atomic64 variable
15621 + * @v: pointer to type atomic64_t
15622 + *
15623 + * Atomically decrements @v by 1.
15624 + */
15625 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
15626 +{
15627 + asm volatile(LOCK_PREFIX "decq %0\n"
15628 : "=m" (v->counter)
15629 : "m" (v->counter));
15630 }
15631 @@ -111,7 +221,7 @@ static inline void atomic64_dec(atomic64_t *v)
15632 */
15633 static inline int atomic64_dec_and_test(atomic64_t *v)
15634 {
15635 - GEN_UNARY_RMWcc(LOCK_PREFIX "decq", v->counter, "%0", "e");
15636 + GEN_UNARY_RMWcc(LOCK_PREFIX "decq", LOCK_PREFIX "incq", v->counter, "%0", "e");
15637 }
15638
15639 /**
15640 @@ -124,7 +234,7 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
15641 */
15642 static inline int atomic64_inc_and_test(atomic64_t *v)
15643 {
15644 - GEN_UNARY_RMWcc(LOCK_PREFIX "incq", v->counter, "%0", "e");
15645 + GEN_UNARY_RMWcc(LOCK_PREFIX "incq", LOCK_PREFIX "decq", v->counter, "%0", "e");
15646 }
15647
15648 /**
15649 @@ -138,7 +248,7 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
15650 */
15651 static inline int atomic64_add_negative(long i, atomic64_t *v)
15652 {
15653 - GEN_BINARY_RMWcc(LOCK_PREFIX "addq", v->counter, "er", i, "%0", "s");
15654 + GEN_BINARY_RMWcc(LOCK_PREFIX "addq", LOCK_PREFIX "subq", v->counter, "er", i, "%0", "s");
15655 }
15656
15657 /**
15658 @@ -150,6 +260,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
15659 */
15660 static inline long atomic64_add_return(long i, atomic64_t *v)
15661 {
15662 + return i + xadd_check_overflow(&v->counter, i);
15663 +}
15664 +
15665 +/**
15666 + * atomic64_add_return_unchecked - add and return
15667 + * @i: integer value to add
15668 + * @v: pointer to type atomic64_unchecked_t
15669 + *
15670 + * Atomically adds @i to @v and returns @i + @v
15671 + */
15672 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
15673 +{
15674 return i + xadd(&v->counter, i);
15675 }
15676
15677 @@ -159,6 +281,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
15678 }
15679
15680 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
15681 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15682 +{
15683 + return atomic64_add_return_unchecked(1, v);
15684 +}
15685 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
15686
15687 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15688 @@ -166,6 +292,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15689 return cmpxchg(&v->counter, old, new);
15690 }
15691
15692 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
15693 +{
15694 + return cmpxchg(&v->counter, old, new);
15695 +}
15696 +
15697 static inline long atomic64_xchg(atomic64_t *v, long new)
15698 {
15699 return xchg(&v->counter, new);
15700 @@ -182,17 +313,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
15701 */
15702 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
15703 {
15704 - long c, old;
15705 + long c, old, new;
15706 c = atomic64_read(v);
15707 for (;;) {
15708 - if (unlikely(c == (u)))
15709 + if (unlikely(c == u))
15710 break;
15711 - old = atomic64_cmpxchg((v), c, c + (a));
15712 +
15713 + asm volatile("add %2,%0\n"
15714 +
15715 +#ifdef CONFIG_PAX_REFCOUNT
15716 + "jno 0f\n"
15717 + "sub %2,%0\n"
15718 + "int $4\n0:\n"
15719 + _ASM_EXTABLE(0b, 0b)
15720 +#endif
15721 +
15722 + : "=r" (new)
15723 + : "0" (c), "ir" (a));
15724 +
15725 + old = atomic64_cmpxchg(v, c, new);
15726 if (likely(old == c))
15727 break;
15728 c = old;
15729 }
15730 - return c != (u);
15731 + return c != u;
15732 }
15733
15734 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
15735 diff --git a/arch/x86/include/asm/barrier.h b/arch/x86/include/asm/barrier.h
15736 index 69bbb48..32517fe 100644
15737 --- a/arch/x86/include/asm/barrier.h
15738 +++ b/arch/x86/include/asm/barrier.h
15739 @@ -107,7 +107,7 @@
15740 do { \
15741 compiletime_assert_atomic_type(*p); \
15742 smp_mb(); \
15743 - ACCESS_ONCE(*p) = (v); \
15744 + ACCESS_ONCE_RW(*p) = (v); \
15745 } while (0)
15746
15747 #define smp_load_acquire(p) \
15748 @@ -124,7 +124,7 @@ do { \
15749 do { \
15750 compiletime_assert_atomic_type(*p); \
15751 barrier(); \
15752 - ACCESS_ONCE(*p) = (v); \
15753 + ACCESS_ONCE_RW(*p) = (v); \
15754 } while (0)
15755
15756 #define smp_load_acquire(p) \
15757 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
15758 index 9fc1af7..776d75a 100644
15759 --- a/arch/x86/include/asm/bitops.h
15760 +++ b/arch/x86/include/asm/bitops.h
15761 @@ -49,7 +49,7 @@
15762 * a mask operation on a byte.
15763 */
15764 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
15765 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
15766 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
15767 #define CONST_MASK(nr) (1 << ((nr) & 7))
15768
15769 /**
15770 @@ -205,7 +205,7 @@ static inline void change_bit(long nr, volatile unsigned long *addr)
15771 */
15772 static inline int test_and_set_bit(long nr, volatile unsigned long *addr)
15773 {
15774 - GEN_BINARY_RMWcc(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
15775 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
15776 }
15777
15778 /**
15779 @@ -251,7 +251,7 @@ static inline int __test_and_set_bit(long nr, volatile unsigned long *addr)
15780 */
15781 static inline int test_and_clear_bit(long nr, volatile unsigned long *addr)
15782 {
15783 - GEN_BINARY_RMWcc(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
15784 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
15785 }
15786
15787 /**
15788 @@ -304,7 +304,7 @@ static inline int __test_and_change_bit(long nr, volatile unsigned long *addr)
15789 */
15790 static inline int test_and_change_bit(long nr, volatile unsigned long *addr)
15791 {
15792 - GEN_BINARY_RMWcc(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
15793 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
15794 }
15795
15796 static __always_inline int constant_test_bit(long nr, const volatile unsigned long *addr)
15797 @@ -345,7 +345,7 @@ static int test_bit(int nr, const volatile unsigned long *addr);
15798 *
15799 * Undefined if no bit exists, so code should check against 0 first.
15800 */
15801 -static inline unsigned long __ffs(unsigned long word)
15802 +static inline unsigned long __intentional_overflow(-1) __ffs(unsigned long word)
15803 {
15804 asm("rep; bsf %1,%0"
15805 : "=r" (word)
15806 @@ -359,7 +359,7 @@ static inline unsigned long __ffs(unsigned long word)
15807 *
15808 * Undefined if no zero exists, so code should check against ~0UL first.
15809 */
15810 -static inline unsigned long ffz(unsigned long word)
15811 +static inline unsigned long __intentional_overflow(-1) ffz(unsigned long word)
15812 {
15813 asm("rep; bsf %1,%0"
15814 : "=r" (word)
15815 @@ -373,7 +373,7 @@ static inline unsigned long ffz(unsigned long word)
15816 *
15817 * Undefined if no set bit exists, so code should check against 0 first.
15818 */
15819 -static inline unsigned long __fls(unsigned long word)
15820 +static inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
15821 {
15822 asm("bsr %1,%0"
15823 : "=r" (word)
15824 @@ -436,7 +436,7 @@ static inline int ffs(int x)
15825 * set bit if value is nonzero. The last (most significant) bit is
15826 * at position 32.
15827 */
15828 -static inline int fls(int x)
15829 +static inline int __intentional_overflow(-1) fls(int x)
15830 {
15831 int r;
15832
15833 @@ -478,7 +478,7 @@ static inline int fls(int x)
15834 * at position 64.
15835 */
15836 #ifdef CONFIG_X86_64
15837 -static __always_inline int fls64(__u64 x)
15838 +static __always_inline __intentional_overflow(-1) int fls64(__u64 x)
15839 {
15840 int bitpos = -1;
15841 /*
15842 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
15843 index 4fa687a..60f2d39 100644
15844 --- a/arch/x86/include/asm/boot.h
15845 +++ b/arch/x86/include/asm/boot.h
15846 @@ -6,10 +6,15 @@
15847 #include <uapi/asm/boot.h>
15848
15849 /* Physical address where kernel should be loaded. */
15850 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
15851 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
15852 + (CONFIG_PHYSICAL_ALIGN - 1)) \
15853 & ~(CONFIG_PHYSICAL_ALIGN - 1))
15854
15855 +#ifndef __ASSEMBLY__
15856 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
15857 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
15858 +#endif
15859 +
15860 /* Minimum kernel alignment, as a power of two */
15861 #ifdef CONFIG_X86_64
15862 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
15863 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
15864 index 48f99f1..d78ebf9 100644
15865 --- a/arch/x86/include/asm/cache.h
15866 +++ b/arch/x86/include/asm/cache.h
15867 @@ -5,12 +5,13 @@
15868
15869 /* L1 cache line size */
15870 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
15871 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
15872 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
15873
15874 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
15875 +#define __read_only __attribute__((__section__(".data..read_only")))
15876
15877 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
15878 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
15879 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
15880
15881 #ifdef CONFIG_X86_VSMP
15882 #ifdef CONFIG_SMP
15883 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
15884 index 9863ee3..4a1f8e1 100644
15885 --- a/arch/x86/include/asm/cacheflush.h
15886 +++ b/arch/x86/include/asm/cacheflush.h
15887 @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
15888 unsigned long pg_flags = pg->flags & _PGMT_MASK;
15889
15890 if (pg_flags == _PGMT_DEFAULT)
15891 - return -1;
15892 + return ~0UL;
15893 else if (pg_flags == _PGMT_WC)
15894 return _PAGE_CACHE_WC;
15895 else if (pg_flags == _PGMT_UC_MINUS)
15896 diff --git a/arch/x86/include/asm/calling.h b/arch/x86/include/asm/calling.h
15897 index cb4c73b..c473c29 100644
15898 --- a/arch/x86/include/asm/calling.h
15899 +++ b/arch/x86/include/asm/calling.h
15900 @@ -82,103 +82,113 @@ For 32-bit we have the following conventions - kernel is built with
15901 #define RSP 152
15902 #define SS 160
15903
15904 -#define ARGOFFSET R11
15905 -#define SWFRAME ORIG_RAX
15906 +#define ARGOFFSET R15
15907
15908 .macro SAVE_ARGS addskip=0, save_rcx=1, save_r891011=1
15909 - subq $9*8+\addskip, %rsp
15910 - CFI_ADJUST_CFA_OFFSET 9*8+\addskip
15911 - movq_cfi rdi, 8*8
15912 - movq_cfi rsi, 7*8
15913 - movq_cfi rdx, 6*8
15914 + subq $ORIG_RAX-ARGOFFSET+\addskip, %rsp
15915 + CFI_ADJUST_CFA_OFFSET ORIG_RAX-ARGOFFSET+\addskip
15916 + movq_cfi rdi, RDI
15917 + movq_cfi rsi, RSI
15918 + movq_cfi rdx, RDX
15919
15920 .if \save_rcx
15921 - movq_cfi rcx, 5*8
15922 + movq_cfi rcx, RCX
15923 .endif
15924
15925 - movq_cfi rax, 4*8
15926 + movq_cfi rax, RAX
15927
15928 .if \save_r891011
15929 - movq_cfi r8, 3*8
15930 - movq_cfi r9, 2*8
15931 - movq_cfi r10, 1*8
15932 - movq_cfi r11, 0*8
15933 + movq_cfi r8, R8
15934 + movq_cfi r9, R9
15935 + movq_cfi r10, R10
15936 + movq_cfi r11, R11
15937 .endif
15938
15939 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15940 + movq_cfi r12, R12
15941 +#endif
15942 +
15943 .endm
15944
15945 -#define ARG_SKIP (9*8)
15946 +#define ARG_SKIP ORIG_RAX
15947
15948 .macro RESTORE_ARGS rstor_rax=1, addskip=0, rstor_rcx=1, rstor_r11=1, \
15949 rstor_r8910=1, rstor_rdx=1
15950 +
15951 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15952 + movq_cfi_restore R12, r12
15953 +#endif
15954 +
15955 .if \rstor_r11
15956 - movq_cfi_restore 0*8, r11
15957 + movq_cfi_restore R11, r11
15958 .endif
15959
15960 .if \rstor_r8910
15961 - movq_cfi_restore 1*8, r10
15962 - movq_cfi_restore 2*8, r9
15963 - movq_cfi_restore 3*8, r8
15964 + movq_cfi_restore R10, r10
15965 + movq_cfi_restore R9, r9
15966 + movq_cfi_restore R8, r8
15967 .endif
15968
15969 .if \rstor_rax
15970 - movq_cfi_restore 4*8, rax
15971 + movq_cfi_restore RAX, rax
15972 .endif
15973
15974 .if \rstor_rcx
15975 - movq_cfi_restore 5*8, rcx
15976 + movq_cfi_restore RCX, rcx
15977 .endif
15978
15979 .if \rstor_rdx
15980 - movq_cfi_restore 6*8, rdx
15981 + movq_cfi_restore RDX, rdx
15982 .endif
15983
15984 - movq_cfi_restore 7*8, rsi
15985 - movq_cfi_restore 8*8, rdi
15986 + movq_cfi_restore RSI, rsi
15987 + movq_cfi_restore RDI, rdi
15988
15989 - .if ARG_SKIP+\addskip > 0
15990 - addq $ARG_SKIP+\addskip, %rsp
15991 - CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip)
15992 + .if ORIG_RAX+\addskip > 0
15993 + addq $ORIG_RAX+\addskip, %rsp
15994 + CFI_ADJUST_CFA_OFFSET -(ORIG_RAX+\addskip)
15995 .endif
15996 .endm
15997
15998 - .macro LOAD_ARGS offset, skiprax=0
15999 - movq \offset(%rsp), %r11
16000 - movq \offset+8(%rsp), %r10
16001 - movq \offset+16(%rsp), %r9
16002 - movq \offset+24(%rsp), %r8
16003 - movq \offset+40(%rsp), %rcx
16004 - movq \offset+48(%rsp), %rdx
16005 - movq \offset+56(%rsp), %rsi
16006 - movq \offset+64(%rsp), %rdi
16007 + .macro LOAD_ARGS skiprax=0
16008 + movq R11(%rsp), %r11
16009 + movq R10(%rsp), %r10
16010 + movq R9(%rsp), %r9
16011 + movq R8(%rsp), %r8
16012 + movq RCX(%rsp), %rcx
16013 + movq RDX(%rsp), %rdx
16014 + movq RSI(%rsp), %rsi
16015 + movq RDI(%rsp), %rdi
16016 .if \skiprax
16017 .else
16018 - movq \offset+72(%rsp), %rax
16019 + movq RAX(%rsp), %rax
16020 .endif
16021 .endm
16022
16023 -#define REST_SKIP (6*8)
16024 -
16025 .macro SAVE_REST
16026 - subq $REST_SKIP, %rsp
16027 - CFI_ADJUST_CFA_OFFSET REST_SKIP
16028 - movq_cfi rbx, 5*8
16029 - movq_cfi rbp, 4*8
16030 - movq_cfi r12, 3*8
16031 - movq_cfi r13, 2*8
16032 - movq_cfi r14, 1*8
16033 - movq_cfi r15, 0*8
16034 + movq_cfi rbx, RBX
16035 + movq_cfi rbp, RBP
16036 +
16037 +#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16038 + movq_cfi r12, R12
16039 +#endif
16040 +
16041 + movq_cfi r13, R13
16042 + movq_cfi r14, R14
16043 + movq_cfi r15, R15
16044 .endm
16045
16046 .macro RESTORE_REST
16047 - movq_cfi_restore 0*8, r15
16048 - movq_cfi_restore 1*8, r14
16049 - movq_cfi_restore 2*8, r13
16050 - movq_cfi_restore 3*8, r12
16051 - movq_cfi_restore 4*8, rbp
16052 - movq_cfi_restore 5*8, rbx
16053 - addq $REST_SKIP, %rsp
16054 - CFI_ADJUST_CFA_OFFSET -(REST_SKIP)
16055 + movq_cfi_restore R15, r15
16056 + movq_cfi_restore R14, r14
16057 + movq_cfi_restore R13, r13
16058 +
16059 +#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
16060 + movq_cfi_restore R12, r12
16061 +#endif
16062 +
16063 + movq_cfi_restore RBP, rbp
16064 + movq_cfi_restore RBX, rbx
16065 .endm
16066
16067 .macro SAVE_ALL
16068 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
16069 index f50de69..2b0a458 100644
16070 --- a/arch/x86/include/asm/checksum_32.h
16071 +++ b/arch/x86/include/asm/checksum_32.h
16072 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
16073 int len, __wsum sum,
16074 int *src_err_ptr, int *dst_err_ptr);
16075
16076 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
16077 + int len, __wsum sum,
16078 + int *src_err_ptr, int *dst_err_ptr);
16079 +
16080 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
16081 + int len, __wsum sum,
16082 + int *src_err_ptr, int *dst_err_ptr);
16083 +
16084 /*
16085 * Note: when you get a NULL pointer exception here this means someone
16086 * passed in an incorrect kernel address to one of these functions.
16087 @@ -53,7 +61,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
16088
16089 might_sleep();
16090 stac();
16091 - ret = csum_partial_copy_generic((__force void *)src, dst,
16092 + ret = csum_partial_copy_generic_from_user((__force void *)src, dst,
16093 len, sum, err_ptr, NULL);
16094 clac();
16095
16096 @@ -187,7 +195,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
16097 might_sleep();
16098 if (access_ok(VERIFY_WRITE, dst, len)) {
16099 stac();
16100 - ret = csum_partial_copy_generic(src, (__force void *)dst,
16101 + ret = csum_partial_copy_generic_to_user(src, (__force void *)dst,
16102 len, sum, NULL, err_ptr);
16103 clac();
16104 return ret;
16105 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
16106 index d47786a..2d8883e 100644
16107 --- a/arch/x86/include/asm/cmpxchg.h
16108 +++ b/arch/x86/include/asm/cmpxchg.h
16109 @@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
16110 __compiletime_error("Bad argument size for cmpxchg");
16111 extern void __xadd_wrong_size(void)
16112 __compiletime_error("Bad argument size for xadd");
16113 +extern void __xadd_check_overflow_wrong_size(void)
16114 + __compiletime_error("Bad argument size for xadd_check_overflow");
16115 extern void __add_wrong_size(void)
16116 __compiletime_error("Bad argument size for add");
16117 +extern void __add_check_overflow_wrong_size(void)
16118 + __compiletime_error("Bad argument size for add_check_overflow");
16119
16120 /*
16121 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
16122 @@ -67,6 +71,38 @@ extern void __add_wrong_size(void)
16123 __ret; \
16124 })
16125
16126 +#ifdef CONFIG_PAX_REFCOUNT
16127 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
16128 + ({ \
16129 + __typeof__ (*(ptr)) __ret = (arg); \
16130 + switch (sizeof(*(ptr))) { \
16131 + case __X86_CASE_L: \
16132 + asm volatile (lock #op "l %0, %1\n" \
16133 + "jno 0f\n" \
16134 + "mov %0,%1\n" \
16135 + "int $4\n0:\n" \
16136 + _ASM_EXTABLE(0b, 0b) \
16137 + : "+r" (__ret), "+m" (*(ptr)) \
16138 + : : "memory", "cc"); \
16139 + break; \
16140 + case __X86_CASE_Q: \
16141 + asm volatile (lock #op "q %q0, %1\n" \
16142 + "jno 0f\n" \
16143 + "mov %0,%1\n" \
16144 + "int $4\n0:\n" \
16145 + _ASM_EXTABLE(0b, 0b) \
16146 + : "+r" (__ret), "+m" (*(ptr)) \
16147 + : : "memory", "cc"); \
16148 + break; \
16149 + default: \
16150 + __ ## op ## _check_overflow_wrong_size(); \
16151 + } \
16152 + __ret; \
16153 + })
16154 +#else
16155 +#define __xchg_op_check_overflow(ptr, arg, op, lock) __xchg_op(ptr, arg, op, lock)
16156 +#endif
16157 +
16158 /*
16159 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
16160 * Since this is generally used to protect other memory information, we
16161 @@ -167,6 +203,9 @@ extern void __add_wrong_size(void)
16162 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
16163 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
16164
16165 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
16166 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
16167 +
16168 #define __add(ptr, inc, lock) \
16169 ({ \
16170 __typeof__ (*(ptr)) __ret = (inc); \
16171 diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
16172 index 59c6c40..5e0b22c 100644
16173 --- a/arch/x86/include/asm/compat.h
16174 +++ b/arch/x86/include/asm/compat.h
16175 @@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
16176 typedef u32 compat_uint_t;
16177 typedef u32 compat_ulong_t;
16178 typedef u64 __attribute__((aligned(4))) compat_u64;
16179 -typedef u32 compat_uptr_t;
16180 +typedef u32 __user compat_uptr_t;
16181
16182 struct compat_timespec {
16183 compat_time_t tv_sec;
16184 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
16185 index e265ff9..72c253b 100644
16186 --- a/arch/x86/include/asm/cpufeature.h
16187 +++ b/arch/x86/include/asm/cpufeature.h
16188 @@ -203,7 +203,7 @@
16189 #define X86_FEATURE_DECODEASSISTS (8*32+12) /* AMD Decode Assists support */
16190 #define X86_FEATURE_PAUSEFILTER (8*32+13) /* AMD filtered pause intercept */
16191 #define X86_FEATURE_PFTHRESHOLD (8*32+14) /* AMD pause filter threshold */
16192 -
16193 +#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
16194
16195 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
16196 #define X86_FEATURE_FSGSBASE (9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
16197 @@ -211,7 +211,7 @@
16198 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
16199 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
16200 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
16201 -#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
16202 +#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
16203 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
16204 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
16205 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
16206 @@ -359,6 +359,7 @@ extern const char * const x86_power_flags[32];
16207 #undef cpu_has_centaur_mcr
16208 #define cpu_has_centaur_mcr 0
16209
16210 +#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
16211 #endif /* CONFIG_X86_64 */
16212
16213 #if __GNUC__ >= 4
16214 @@ -411,7 +412,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16215
16216 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
16217 t_warn:
16218 - warn_pre_alternatives();
16219 + if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
16220 + warn_pre_alternatives();
16221 return false;
16222 #endif
16223
16224 @@ -431,7 +433,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
16225 ".section .discard,\"aw\",@progbits\n"
16226 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16227 ".previous\n"
16228 - ".section .altinstr_replacement,\"ax\"\n"
16229 + ".section .altinstr_replacement,\"a\"\n"
16230 "3: movb $1,%0\n"
16231 "4:\n"
16232 ".previous\n"
16233 @@ -468,7 +470,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16234 " .byte 2b - 1b\n" /* src len */
16235 " .byte 4f - 3f\n" /* repl len */
16236 ".previous\n"
16237 - ".section .altinstr_replacement,\"ax\"\n"
16238 + ".section .altinstr_replacement,\"a\"\n"
16239 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
16240 "4:\n"
16241 ".previous\n"
16242 @@ -501,7 +503,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16243 ".section .discard,\"aw\",@progbits\n"
16244 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
16245 ".previous\n"
16246 - ".section .altinstr_replacement,\"ax\"\n"
16247 + ".section .altinstr_replacement,\"a\"\n"
16248 "3: movb $0,%0\n"
16249 "4:\n"
16250 ".previous\n"
16251 @@ -515,7 +517,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
16252 ".section .discard,\"aw\",@progbits\n"
16253 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
16254 ".previous\n"
16255 - ".section .altinstr_replacement,\"ax\"\n"
16256 + ".section .altinstr_replacement,\"a\"\n"
16257 "5: movb $1,%0\n"
16258 "6:\n"
16259 ".previous\n"
16260 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
16261 index 50d033a..37deb26 100644
16262 --- a/arch/x86/include/asm/desc.h
16263 +++ b/arch/x86/include/asm/desc.h
16264 @@ -4,6 +4,7 @@
16265 #include <asm/desc_defs.h>
16266 #include <asm/ldt.h>
16267 #include <asm/mmu.h>
16268 +#include <asm/pgtable.h>
16269
16270 #include <linux/smp.h>
16271 #include <linux/percpu.h>
16272 @@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16273
16274 desc->type = (info->read_exec_only ^ 1) << 1;
16275 desc->type |= info->contents << 2;
16276 + desc->type |= info->seg_not_present ^ 1;
16277
16278 desc->s = 1;
16279 desc->dpl = 0x3;
16280 @@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
16281 }
16282
16283 extern struct desc_ptr idt_descr;
16284 -extern gate_desc idt_table[];
16285 -extern struct desc_ptr debug_idt_descr;
16286 -extern gate_desc debug_idt_table[];
16287 -
16288 -struct gdt_page {
16289 - struct desc_struct gdt[GDT_ENTRIES];
16290 -} __attribute__((aligned(PAGE_SIZE)));
16291 -
16292 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
16293 +extern gate_desc idt_table[IDT_ENTRIES];
16294 +extern const struct desc_ptr debug_idt_descr;
16295 +extern gate_desc debug_idt_table[IDT_ENTRIES];
16296
16297 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
16298 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
16299 {
16300 - return per_cpu(gdt_page, cpu).gdt;
16301 + return cpu_gdt_table[cpu];
16302 }
16303
16304 #ifdef CONFIG_X86_64
16305 @@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
16306 unsigned long base, unsigned dpl, unsigned flags,
16307 unsigned short seg)
16308 {
16309 - gate->a = (seg << 16) | (base & 0xffff);
16310 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
16311 + gate->gate.offset_low = base;
16312 + gate->gate.seg = seg;
16313 + gate->gate.reserved = 0;
16314 + gate->gate.type = type;
16315 + gate->gate.s = 0;
16316 + gate->gate.dpl = dpl;
16317 + gate->gate.p = 1;
16318 + gate->gate.offset_high = base >> 16;
16319 }
16320
16321 #endif
16322 @@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
16323
16324 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
16325 {
16326 + pax_open_kernel();
16327 memcpy(&idt[entry], gate, sizeof(*gate));
16328 + pax_close_kernel();
16329 }
16330
16331 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
16332 {
16333 + pax_open_kernel();
16334 memcpy(&ldt[entry], desc, 8);
16335 + pax_close_kernel();
16336 }
16337
16338 static inline void
16339 @@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
16340 default: size = sizeof(*gdt); break;
16341 }
16342
16343 + pax_open_kernel();
16344 memcpy(&gdt[entry], desc, size);
16345 + pax_close_kernel();
16346 }
16347
16348 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
16349 @@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
16350
16351 static inline void native_load_tr_desc(void)
16352 {
16353 + pax_open_kernel();
16354 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
16355 + pax_close_kernel();
16356 }
16357
16358 static inline void native_load_gdt(const struct desc_ptr *dtr)
16359 @@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
16360 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
16361 unsigned int i;
16362
16363 + pax_open_kernel();
16364 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
16365 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
16366 + pax_close_kernel();
16367 }
16368
16369 #define _LDT_empty(info) \
16370 @@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
16371 preempt_enable();
16372 }
16373
16374 -static inline unsigned long get_desc_base(const struct desc_struct *desc)
16375 +static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
16376 {
16377 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
16378 }
16379 @@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
16380 }
16381
16382 #ifdef CONFIG_X86_64
16383 -static inline void set_nmi_gate(int gate, void *addr)
16384 +static inline void set_nmi_gate(int gate, const void *addr)
16385 {
16386 gate_desc s;
16387
16388 @@ -321,14 +334,14 @@ static inline void set_nmi_gate(int gate, void *addr)
16389 #endif
16390
16391 #ifdef CONFIG_TRACING
16392 -extern struct desc_ptr trace_idt_descr;
16393 -extern gate_desc trace_idt_table[];
16394 +extern const struct desc_ptr trace_idt_descr;
16395 +extern gate_desc trace_idt_table[IDT_ENTRIES];
16396 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16397 {
16398 write_idt_entry(trace_idt_table, entry, gate);
16399 }
16400
16401 -static inline void _trace_set_gate(int gate, unsigned type, void *addr,
16402 +static inline void _trace_set_gate(int gate, unsigned type, const void *addr,
16403 unsigned dpl, unsigned ist, unsigned seg)
16404 {
16405 gate_desc s;
16406 @@ -348,7 +361,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
16407 #define _trace_set_gate(gate, type, addr, dpl, ist, seg)
16408 #endif
16409
16410 -static inline void _set_gate(int gate, unsigned type, void *addr,
16411 +static inline void _set_gate(int gate, unsigned type, const void *addr,
16412 unsigned dpl, unsigned ist, unsigned seg)
16413 {
16414 gate_desc s;
16415 @@ -371,9 +384,9 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
16416 #define set_intr_gate(n, addr) \
16417 do { \
16418 BUG_ON((unsigned)n > 0xFF); \
16419 - _set_gate(n, GATE_INTERRUPT, (void *)addr, 0, 0, \
16420 + _set_gate(n, GATE_INTERRUPT, (const void *)addr, 0, 0, \
16421 __KERNEL_CS); \
16422 - _trace_set_gate(n, GATE_INTERRUPT, (void *)trace_##addr,\
16423 + _trace_set_gate(n, GATE_INTERRUPT, (const void *)trace_##addr,\
16424 0, 0, __KERNEL_CS); \
16425 } while (0)
16426
16427 @@ -401,19 +414,19 @@ static inline void alloc_system_vector(int vector)
16428 /*
16429 * This routine sets up an interrupt gate at directory privilege level 3.
16430 */
16431 -static inline void set_system_intr_gate(unsigned int n, void *addr)
16432 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
16433 {
16434 BUG_ON((unsigned)n > 0xFF);
16435 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
16436 }
16437
16438 -static inline void set_system_trap_gate(unsigned int n, void *addr)
16439 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
16440 {
16441 BUG_ON((unsigned)n > 0xFF);
16442 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
16443 }
16444
16445 -static inline void set_trap_gate(unsigned int n, void *addr)
16446 +static inline void set_trap_gate(unsigned int n, const void *addr)
16447 {
16448 BUG_ON((unsigned)n > 0xFF);
16449 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
16450 @@ -422,16 +435,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
16451 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
16452 {
16453 BUG_ON((unsigned)n > 0xFF);
16454 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
16455 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
16456 }
16457
16458 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
16459 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
16460 {
16461 BUG_ON((unsigned)n > 0xFF);
16462 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
16463 }
16464
16465 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
16466 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
16467 {
16468 BUG_ON((unsigned)n > 0xFF);
16469 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
16470 @@ -503,4 +516,17 @@ static inline void load_current_idt(void)
16471 else
16472 load_idt((const struct desc_ptr *)&idt_descr);
16473 }
16474 +
16475 +#ifdef CONFIG_X86_32
16476 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
16477 +{
16478 + struct desc_struct d;
16479 +
16480 + if (likely(limit))
16481 + limit = (limit - 1UL) >> PAGE_SHIFT;
16482 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
16483 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
16484 +}
16485 +#endif
16486 +
16487 #endif /* _ASM_X86_DESC_H */
16488 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
16489 index 278441f..b95a174 100644
16490 --- a/arch/x86/include/asm/desc_defs.h
16491 +++ b/arch/x86/include/asm/desc_defs.h
16492 @@ -31,6 +31,12 @@ struct desc_struct {
16493 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
16494 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
16495 };
16496 + struct {
16497 + u16 offset_low;
16498 + u16 seg;
16499 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
16500 + unsigned offset_high: 16;
16501 + } gate;
16502 };
16503 } __attribute__((packed));
16504
16505 diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
16506 index ced283a..ffe04cc 100644
16507 --- a/arch/x86/include/asm/div64.h
16508 +++ b/arch/x86/include/asm/div64.h
16509 @@ -39,7 +39,7 @@
16510 __mod; \
16511 })
16512
16513 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16514 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
16515 {
16516 union {
16517 u64 v64;
16518 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
16519 index 2c71182..731124d 100644
16520 --- a/arch/x86/include/asm/elf.h
16521 +++ b/arch/x86/include/asm/elf.h
16522 @@ -243,7 +243,25 @@ extern int force_personality32;
16523 the loader. We need to make sure that it is out of the way of the program
16524 that it will "exec", and that there is sufficient room for the brk. */
16525
16526 +#ifdef CONFIG_PAX_SEGMEXEC
16527 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
16528 +#else
16529 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
16530 +#endif
16531 +
16532 +#ifdef CONFIG_PAX_ASLR
16533 +#ifdef CONFIG_X86_32
16534 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
16535 +
16536 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16537 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
16538 +#else
16539 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
16540 +
16541 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16542 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
16543 +#endif
16544 +#endif
16545
16546 /* This yields a mask that user programs can use to figure out what
16547 instruction set this CPU supports. This could be done in user space,
16548 @@ -292,16 +310,12 @@ do { \
16549
16550 #define ARCH_DLINFO \
16551 do { \
16552 - if (vdso_enabled) \
16553 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16554 - (unsigned long)current->mm->context.vdso); \
16555 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16556 } while (0)
16557
16558 #define ARCH_DLINFO_X32 \
16559 do { \
16560 - if (vdso_enabled) \
16561 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
16562 - (unsigned long)current->mm->context.vdso); \
16563 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
16564 } while (0)
16565
16566 #define AT_SYSINFO 32
16567 @@ -316,7 +330,7 @@ else \
16568
16569 #endif /* !CONFIG_X86_32 */
16570
16571 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
16572 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
16573
16574 #define VDSO_ENTRY \
16575 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
16576 @@ -332,9 +346,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
16577 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
16578 #define compat_arch_setup_additional_pages syscall32_setup_pages
16579
16580 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
16581 -#define arch_randomize_brk arch_randomize_brk
16582 -
16583 /*
16584 * True on X86_32 or when emulating IA32 on X86_64
16585 */
16586 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
16587 index 77a99ac..39ff7f5 100644
16588 --- a/arch/x86/include/asm/emergency-restart.h
16589 +++ b/arch/x86/include/asm/emergency-restart.h
16590 @@ -1,6 +1,6 @@
16591 #ifndef _ASM_X86_EMERGENCY_RESTART_H
16592 #define _ASM_X86_EMERGENCY_RESTART_H
16593
16594 -extern void machine_emergency_restart(void);
16595 +extern void machine_emergency_restart(void) __noreturn;
16596
16597 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
16598 diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
16599 index 1c7eefe..d0e4702 100644
16600 --- a/arch/x86/include/asm/floppy.h
16601 +++ b/arch/x86/include/asm/floppy.h
16602 @@ -229,18 +229,18 @@ static struct fd_routine_l {
16603 int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
16604 } fd_routine[] = {
16605 {
16606 - request_dma,
16607 - free_dma,
16608 - get_dma_residue,
16609 - dma_mem_alloc,
16610 - hard_dma_setup
16611 + ._request_dma = request_dma,
16612 + ._free_dma = free_dma,
16613 + ._get_dma_residue = get_dma_residue,
16614 + ._dma_mem_alloc = dma_mem_alloc,
16615 + ._dma_setup = hard_dma_setup
16616 },
16617 {
16618 - vdma_request_dma,
16619 - vdma_nop,
16620 - vdma_get_dma_residue,
16621 - vdma_mem_alloc,
16622 - vdma_dma_setup
16623 + ._request_dma = vdma_request_dma,
16624 + ._free_dma = vdma_nop,
16625 + ._get_dma_residue = vdma_get_dma_residue,
16626 + ._dma_mem_alloc = vdma_mem_alloc,
16627 + ._dma_setup = vdma_dma_setup
16628 }
16629 };
16630
16631 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
16632 index cea1c76..6c0d79b 100644
16633 --- a/arch/x86/include/asm/fpu-internal.h
16634 +++ b/arch/x86/include/asm/fpu-internal.h
16635 @@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16636 #define user_insn(insn, output, input...) \
16637 ({ \
16638 int err; \
16639 + pax_open_userland(); \
16640 asm volatile(ASM_STAC "\n" \
16641 - "1:" #insn "\n\t" \
16642 + "1:" \
16643 + __copyuser_seg \
16644 + #insn "\n\t" \
16645 "2: " ASM_CLAC "\n" \
16646 ".section .fixup,\"ax\"\n" \
16647 "3: movl $-1,%[err]\n" \
16648 @@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16649 _ASM_EXTABLE(1b, 3b) \
16650 : [err] "=r" (err), output \
16651 : "0"(0), input); \
16652 + pax_close_userland(); \
16653 err; \
16654 })
16655
16656 @@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
16657 "fnclex\n\t"
16658 "emms\n\t"
16659 "fildl %P[addr]" /* set F?P to defined value */
16660 - : : [addr] "m" (tsk->thread.fpu.has_fpu));
16661 + : : [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
16662 }
16663
16664 return fpu_restore_checking(&tsk->thread.fpu);
16665 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
16666 index b4c1f54..e290c08 100644
16667 --- a/arch/x86/include/asm/futex.h
16668 +++ b/arch/x86/include/asm/futex.h
16669 @@ -12,6 +12,7 @@
16670 #include <asm/smap.h>
16671
16672 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
16673 + typecheck(u32 __user *, uaddr); \
16674 asm volatile("\t" ASM_STAC "\n" \
16675 "1:\t" insn "\n" \
16676 "2:\t" ASM_CLAC "\n" \
16677 @@ -20,15 +21,16 @@
16678 "\tjmp\t2b\n" \
16679 "\t.previous\n" \
16680 _ASM_EXTABLE(1b, 3b) \
16681 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
16682 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
16683 : "i" (-EFAULT), "0" (oparg), "1" (0))
16684
16685 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
16686 + typecheck(u32 __user *, uaddr); \
16687 asm volatile("\t" ASM_STAC "\n" \
16688 "1:\tmovl %2, %0\n" \
16689 "\tmovl\t%0, %3\n" \
16690 "\t" insn "\n" \
16691 - "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
16692 + "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
16693 "\tjnz\t1b\n" \
16694 "3:\t" ASM_CLAC "\n" \
16695 "\t.section .fixup,\"ax\"\n" \
16696 @@ -38,7 +40,7 @@
16697 _ASM_EXTABLE(1b, 4b) \
16698 _ASM_EXTABLE(2b, 4b) \
16699 : "=&a" (oldval), "=&r" (ret), \
16700 - "+m" (*uaddr), "=&r" (tem) \
16701 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
16702 : "r" (oparg), "i" (-EFAULT), "1" (0))
16703
16704 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16705 @@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16706
16707 pagefault_disable();
16708
16709 + pax_open_userland();
16710 switch (op) {
16711 case FUTEX_OP_SET:
16712 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
16713 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
16714 break;
16715 case FUTEX_OP_ADD:
16716 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
16717 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
16718 uaddr, oparg);
16719 break;
16720 case FUTEX_OP_OR:
16721 @@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16722 default:
16723 ret = -ENOSYS;
16724 }
16725 + pax_close_userland();
16726
16727 pagefault_enable();
16728
16729 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
16730 index a307b75..ec74ca2 100644
16731 --- a/arch/x86/include/asm/hw_irq.h
16732 +++ b/arch/x86/include/asm/hw_irq.h
16733 @@ -164,8 +164,8 @@ extern void setup_ioapic_dest(void);
16734 extern void enable_IO_APIC(void);
16735
16736 /* Statistics */
16737 -extern atomic_t irq_err_count;
16738 -extern atomic_t irq_mis_count;
16739 +extern atomic_unchecked_t irq_err_count;
16740 +extern atomic_unchecked_t irq_mis_count;
16741
16742 /* EISA */
16743 extern void eisa_set_level_irq(unsigned int irq);
16744 diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
16745 index a203659..9889f1c 100644
16746 --- a/arch/x86/include/asm/i8259.h
16747 +++ b/arch/x86/include/asm/i8259.h
16748 @@ -62,7 +62,7 @@ struct legacy_pic {
16749 void (*init)(int auto_eoi);
16750 int (*irq_pending)(unsigned int irq);
16751 void (*make_irq)(unsigned int irq);
16752 -};
16753 +} __do_const;
16754
16755 extern struct legacy_pic *legacy_pic;
16756 extern struct legacy_pic null_legacy_pic;
16757 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
16758 index b8237d8..3e8864e 100644
16759 --- a/arch/x86/include/asm/io.h
16760 +++ b/arch/x86/include/asm/io.h
16761 @@ -52,12 +52,12 @@ static inline void name(type val, volatile void __iomem *addr) \
16762 "m" (*(volatile type __force *)addr) barrier); }
16763
16764 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
16765 -build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
16766 -build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
16767 +build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
16768 +build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
16769
16770 build_mmio_read(__readb, "b", unsigned char, "=q", )
16771 -build_mmio_read(__readw, "w", unsigned short, "=r", )
16772 -build_mmio_read(__readl, "l", unsigned int, "=r", )
16773 +build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
16774 +build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
16775
16776 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
16777 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
16778 @@ -109,7 +109,7 @@ build_mmio_write(writeq, "q", unsigned long, "r", :"memory")
16779 * this function
16780 */
16781
16782 -static inline phys_addr_t virt_to_phys(volatile void *address)
16783 +static inline phys_addr_t __intentional_overflow(-1) virt_to_phys(volatile void *address)
16784 {
16785 return __pa(address);
16786 }
16787 @@ -185,7 +185,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
16788 return ioremap_nocache(offset, size);
16789 }
16790
16791 -extern void iounmap(volatile void __iomem *addr);
16792 +extern void iounmap(const volatile void __iomem *addr);
16793
16794 extern void set_iounmap_nonlazy(void);
16795
16796 @@ -195,6 +195,17 @@ extern void set_iounmap_nonlazy(void);
16797
16798 #include <linux/vmalloc.h>
16799
16800 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
16801 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
16802 +{
16803 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
16804 +}
16805 +
16806 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
16807 +{
16808 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
16809 +}
16810 +
16811 /*
16812 * Convert a virtual cached pointer to an uncached pointer
16813 */
16814 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
16815 index bba3cf8..06bc8da 100644
16816 --- a/arch/x86/include/asm/irqflags.h
16817 +++ b/arch/x86/include/asm/irqflags.h
16818 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
16819 sti; \
16820 sysexit
16821
16822 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
16823 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
16824 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
16825 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
16826 +
16827 #else
16828 #define INTERRUPT_RETURN iret
16829 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
16830 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
16831 index 9454c16..e4100e3 100644
16832 --- a/arch/x86/include/asm/kprobes.h
16833 +++ b/arch/x86/include/asm/kprobes.h
16834 @@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
16835 #define RELATIVEJUMP_SIZE 5
16836 #define RELATIVECALL_OPCODE 0xe8
16837 #define RELATIVE_ADDR_SIZE 4
16838 -#define MAX_STACK_SIZE 64
16839 -#define MIN_STACK_SIZE(ADDR) \
16840 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
16841 - THREAD_SIZE - (unsigned long)(ADDR))) \
16842 - ? (MAX_STACK_SIZE) \
16843 - : (((unsigned long)current_thread_info()) + \
16844 - THREAD_SIZE - (unsigned long)(ADDR)))
16845 +#define MAX_STACK_SIZE 64UL
16846 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
16847
16848 #define flush_insn_slot(p) do { } while (0)
16849
16850 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
16851 index 4ad6560..75c7bdd 100644
16852 --- a/arch/x86/include/asm/local.h
16853 +++ b/arch/x86/include/asm/local.h
16854 @@ -10,33 +10,97 @@ typedef struct {
16855 atomic_long_t a;
16856 } local_t;
16857
16858 +typedef struct {
16859 + atomic_long_unchecked_t a;
16860 +} local_unchecked_t;
16861 +
16862 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
16863
16864 #define local_read(l) atomic_long_read(&(l)->a)
16865 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
16866 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
16867 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
16868
16869 static inline void local_inc(local_t *l)
16870 {
16871 - asm volatile(_ASM_INC "%0"
16872 + asm volatile(_ASM_INC "%0\n"
16873 +
16874 +#ifdef CONFIG_PAX_REFCOUNT
16875 + "jno 0f\n"
16876 + _ASM_DEC "%0\n"
16877 + "int $4\n0:\n"
16878 + _ASM_EXTABLE(0b, 0b)
16879 +#endif
16880 +
16881 + : "+m" (l->a.counter));
16882 +}
16883 +
16884 +static inline void local_inc_unchecked(local_unchecked_t *l)
16885 +{
16886 + asm volatile(_ASM_INC "%0\n"
16887 : "+m" (l->a.counter));
16888 }
16889
16890 static inline void local_dec(local_t *l)
16891 {
16892 - asm volatile(_ASM_DEC "%0"
16893 + asm volatile(_ASM_DEC "%0\n"
16894 +
16895 +#ifdef CONFIG_PAX_REFCOUNT
16896 + "jno 0f\n"
16897 + _ASM_INC "%0\n"
16898 + "int $4\n0:\n"
16899 + _ASM_EXTABLE(0b, 0b)
16900 +#endif
16901 +
16902 + : "+m" (l->a.counter));
16903 +}
16904 +
16905 +static inline void local_dec_unchecked(local_unchecked_t *l)
16906 +{
16907 + asm volatile(_ASM_DEC "%0\n"
16908 : "+m" (l->a.counter));
16909 }
16910
16911 static inline void local_add(long i, local_t *l)
16912 {
16913 - asm volatile(_ASM_ADD "%1,%0"
16914 + asm volatile(_ASM_ADD "%1,%0\n"
16915 +
16916 +#ifdef CONFIG_PAX_REFCOUNT
16917 + "jno 0f\n"
16918 + _ASM_SUB "%1,%0\n"
16919 + "int $4\n0:\n"
16920 + _ASM_EXTABLE(0b, 0b)
16921 +#endif
16922 +
16923 + : "+m" (l->a.counter)
16924 + : "ir" (i));
16925 +}
16926 +
16927 +static inline void local_add_unchecked(long i, local_unchecked_t *l)
16928 +{
16929 + asm volatile(_ASM_ADD "%1,%0\n"
16930 : "+m" (l->a.counter)
16931 : "ir" (i));
16932 }
16933
16934 static inline void local_sub(long i, local_t *l)
16935 {
16936 - asm volatile(_ASM_SUB "%1,%0"
16937 + asm volatile(_ASM_SUB "%1,%0\n"
16938 +
16939 +#ifdef CONFIG_PAX_REFCOUNT
16940 + "jno 0f\n"
16941 + _ASM_ADD "%1,%0\n"
16942 + "int $4\n0:\n"
16943 + _ASM_EXTABLE(0b, 0b)
16944 +#endif
16945 +
16946 + : "+m" (l->a.counter)
16947 + : "ir" (i));
16948 +}
16949 +
16950 +static inline void local_sub_unchecked(long i, local_unchecked_t *l)
16951 +{
16952 + asm volatile(_ASM_SUB "%1,%0\n"
16953 : "+m" (l->a.counter)
16954 : "ir" (i));
16955 }
16956 @@ -52,7 +116,7 @@ static inline void local_sub(long i, local_t *l)
16957 */
16958 static inline int local_sub_and_test(long i, local_t *l)
16959 {
16960 - GEN_BINARY_RMWcc(_ASM_SUB, l->a.counter, "er", i, "%0", "e");
16961 + GEN_BINARY_RMWcc(_ASM_SUB, _ASM_ADD, l->a.counter, "er", i, "%0", "e");
16962 }
16963
16964 /**
16965 @@ -65,7 +129,7 @@ static inline int local_sub_and_test(long i, local_t *l)
16966 */
16967 static inline int local_dec_and_test(local_t *l)
16968 {
16969 - GEN_UNARY_RMWcc(_ASM_DEC, l->a.counter, "%0", "e");
16970 + GEN_UNARY_RMWcc(_ASM_DEC, _ASM_INC, l->a.counter, "%0", "e");
16971 }
16972
16973 /**
16974 @@ -78,7 +142,7 @@ static inline int local_dec_and_test(local_t *l)
16975 */
16976 static inline int local_inc_and_test(local_t *l)
16977 {
16978 - GEN_UNARY_RMWcc(_ASM_INC, l->a.counter, "%0", "e");
16979 + GEN_UNARY_RMWcc(_ASM_INC, _ASM_DEC, l->a.counter, "%0", "e");
16980 }
16981
16982 /**
16983 @@ -92,7 +156,7 @@ static inline int local_inc_and_test(local_t *l)
16984 */
16985 static inline int local_add_negative(long i, local_t *l)
16986 {
16987 - GEN_BINARY_RMWcc(_ASM_ADD, l->a.counter, "er", i, "%0", "s");
16988 + GEN_BINARY_RMWcc(_ASM_ADD, _ASM_SUB, l->a.counter, "er", i, "%0", "s");
16989 }
16990
16991 /**
16992 @@ -105,6 +169,30 @@ static inline int local_add_negative(long i, local_t *l)
16993 static inline long local_add_return(long i, local_t *l)
16994 {
16995 long __i = i;
16996 + asm volatile(_ASM_XADD "%0, %1\n"
16997 +
16998 +#ifdef CONFIG_PAX_REFCOUNT
16999 + "jno 0f\n"
17000 + _ASM_MOV "%0,%1\n"
17001 + "int $4\n0:\n"
17002 + _ASM_EXTABLE(0b, 0b)
17003 +#endif
17004 +
17005 + : "+r" (i), "+m" (l->a.counter)
17006 + : : "memory");
17007 + return i + __i;
17008 +}
17009 +
17010 +/**
17011 + * local_add_return_unchecked - add and return
17012 + * @i: integer value to add
17013 + * @l: pointer to type local_unchecked_t
17014 + *
17015 + * Atomically adds @i to @l and returns @i + @l
17016 + */
17017 +static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
17018 +{
17019 + long __i = i;
17020 asm volatile(_ASM_XADD "%0, %1;"
17021 : "+r" (i), "+m" (l->a.counter)
17022 : : "memory");
17023 @@ -121,6 +209,8 @@ static inline long local_sub_return(long i, local_t *l)
17024
17025 #define local_cmpxchg(l, o, n) \
17026 (cmpxchg_local(&((l)->a.counter), (o), (n)))
17027 +#define local_cmpxchg_unchecked(l, o, n) \
17028 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
17029 /* Always has a lock prefix */
17030 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
17031
17032 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
17033 new file mode 100644
17034 index 0000000..2bfd3ba
17035 --- /dev/null
17036 +++ b/arch/x86/include/asm/mman.h
17037 @@ -0,0 +1,15 @@
17038 +#ifndef _X86_MMAN_H
17039 +#define _X86_MMAN_H
17040 +
17041 +#include <uapi/asm/mman.h>
17042 +
17043 +#ifdef __KERNEL__
17044 +#ifndef __ASSEMBLY__
17045 +#ifdef CONFIG_X86_32
17046 +#define arch_mmap_check i386_mmap_check
17047 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
17048 +#endif
17049 +#endif
17050 +#endif
17051 +
17052 +#endif /* X86_MMAN_H */
17053 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
17054 index 5f55e69..e20bfb1 100644
17055 --- a/arch/x86/include/asm/mmu.h
17056 +++ b/arch/x86/include/asm/mmu.h
17057 @@ -9,7 +9,7 @@
17058 * we put the segment information here.
17059 */
17060 typedef struct {
17061 - void *ldt;
17062 + struct desc_struct *ldt;
17063 int size;
17064
17065 #ifdef CONFIG_X86_64
17066 @@ -18,7 +18,19 @@ typedef struct {
17067 #endif
17068
17069 struct mutex lock;
17070 - void *vdso;
17071 + unsigned long vdso;
17072 +
17073 +#ifdef CONFIG_X86_32
17074 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
17075 + unsigned long user_cs_base;
17076 + unsigned long user_cs_limit;
17077 +
17078 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17079 + cpumask_t cpu_user_cs_mask;
17080 +#endif
17081 +
17082 +#endif
17083 +#endif
17084 } mm_context_t;
17085
17086 #ifdef CONFIG_SMP
17087 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
17088 index be12c53..4d24039 100644
17089 --- a/arch/x86/include/asm/mmu_context.h
17090 +++ b/arch/x86/include/asm/mmu_context.h
17091 @@ -24,6 +24,20 @@ void destroy_context(struct mm_struct *mm);
17092
17093 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
17094 {
17095 +
17096 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17097 + if (!(static_cpu_has(X86_FEATURE_PCID))) {
17098 + unsigned int i;
17099 + pgd_t *pgd;
17100 +
17101 + pax_open_kernel();
17102 + pgd = get_cpu_pgd(smp_processor_id(), kernel);
17103 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
17104 + set_pgd_batched(pgd+i, native_make_pgd(0));
17105 + pax_close_kernel();
17106 + }
17107 +#endif
17108 +
17109 #ifdef CONFIG_SMP
17110 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
17111 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
17112 @@ -34,16 +48,59 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17113 struct task_struct *tsk)
17114 {
17115 unsigned cpu = smp_processor_id();
17116 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17117 + int tlbstate = TLBSTATE_OK;
17118 +#endif
17119
17120 if (likely(prev != next)) {
17121 #ifdef CONFIG_SMP
17122 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17123 + tlbstate = this_cpu_read(cpu_tlbstate.state);
17124 +#endif
17125 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17126 this_cpu_write(cpu_tlbstate.active_mm, next);
17127 #endif
17128 cpumask_set_cpu(cpu, mm_cpumask(next));
17129
17130 /* Re-load page tables */
17131 +#ifdef CONFIG_PAX_PER_CPU_PGD
17132 + pax_open_kernel();
17133 +
17134 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17135 + if (static_cpu_has(X86_FEATURE_PCID))
17136 + __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17137 + else
17138 +#endif
17139 +
17140 + __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17141 + __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17142 + pax_close_kernel();
17143 + BUG_ON((__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL) != (read_cr3() & __PHYSICAL_MASK) && (__pa(get_cpu_pgd(cpu, user)) | PCID_USER) != (read_cr3() & __PHYSICAL_MASK));
17144 +
17145 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17146 + if (static_cpu_has(X86_FEATURE_PCID)) {
17147 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
17148 + u64 descriptor[2];
17149 + descriptor[0] = PCID_USER;
17150 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17151 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17152 + descriptor[0] = PCID_KERNEL;
17153 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17154 + }
17155 + } else {
17156 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17157 + if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17158 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17159 + else
17160 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17161 + }
17162 + } else
17163 +#endif
17164 +
17165 + load_cr3(get_cpu_pgd(cpu, kernel));
17166 +#else
17167 load_cr3(next->pgd);
17168 +#endif
17169
17170 /* Stop flush ipis for the previous mm */
17171 cpumask_clear_cpu(cpu, mm_cpumask(prev));
17172 @@ -51,9 +108,67 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17173 /* Load the LDT, if the LDT is different: */
17174 if (unlikely(prev->context.ldt != next->context.ldt))
17175 load_LDT_nolock(&next->context);
17176 +
17177 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
17178 + if (!(__supported_pte_mask & _PAGE_NX)) {
17179 + smp_mb__before_clear_bit();
17180 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
17181 + smp_mb__after_clear_bit();
17182 + cpu_set(cpu, next->context.cpu_user_cs_mask);
17183 + }
17184 +#endif
17185 +
17186 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17187 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
17188 + prev->context.user_cs_limit != next->context.user_cs_limit))
17189 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17190 +#ifdef CONFIG_SMP
17191 + else if (unlikely(tlbstate != TLBSTATE_OK))
17192 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17193 +#endif
17194 +#endif
17195 +
17196 }
17197 + else {
17198 +
17199 +#ifdef CONFIG_PAX_PER_CPU_PGD
17200 + pax_open_kernel();
17201 +
17202 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17203 + if (static_cpu_has(X86_FEATURE_PCID))
17204 + __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
17205 + else
17206 +#endif
17207 +
17208 + __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
17209 + __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
17210 + pax_close_kernel();
17211 + BUG_ON((__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL) != (read_cr3() & __PHYSICAL_MASK) && (__pa(get_cpu_pgd(cpu, user)) | PCID_USER) != (read_cr3() & __PHYSICAL_MASK));
17212 +
17213 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17214 + if (static_cpu_has(X86_FEATURE_PCID)) {
17215 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
17216 + u64 descriptor[2];
17217 + descriptor[0] = PCID_USER;
17218 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17219 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
17220 + descriptor[0] = PCID_KERNEL;
17221 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
17222 + }
17223 + } else {
17224 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
17225 + if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
17226 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
17227 + else
17228 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
17229 + }
17230 + } else
17231 +#endif
17232 +
17233 + load_cr3(get_cpu_pgd(cpu, kernel));
17234 +#endif
17235 +
17236 #ifdef CONFIG_SMP
17237 - else {
17238 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
17239 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
17240
17241 @@ -70,11 +185,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
17242 * tlb flush IPI delivery. We must reload CR3
17243 * to make sure to use no freed page tables.
17244 */
17245 +
17246 +#ifndef CONFIG_PAX_PER_CPU_PGD
17247 load_cr3(next->pgd);
17248 +#endif
17249 +
17250 load_LDT_nolock(&next->context);
17251 +
17252 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
17253 + if (!(__supported_pte_mask & _PAGE_NX))
17254 + cpu_set(cpu, next->context.cpu_user_cs_mask);
17255 +#endif
17256 +
17257 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
17258 +#ifdef CONFIG_PAX_PAGEEXEC
17259 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
17260 +#endif
17261 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
17262 +#endif
17263 +
17264 }
17265 +#endif
17266 }
17267 -#endif
17268 }
17269
17270 #define activate_mm(prev, next) \
17271 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
17272 index e3b7819..b257c64 100644
17273 --- a/arch/x86/include/asm/module.h
17274 +++ b/arch/x86/include/asm/module.h
17275 @@ -5,6 +5,7 @@
17276
17277 #ifdef CONFIG_X86_64
17278 /* X86_64 does not define MODULE_PROC_FAMILY */
17279 +#define MODULE_PROC_FAMILY ""
17280 #elif defined CONFIG_M486
17281 #define MODULE_PROC_FAMILY "486 "
17282 #elif defined CONFIG_M586
17283 @@ -57,8 +58,20 @@
17284 #error unknown processor family
17285 #endif
17286
17287 -#ifdef CONFIG_X86_32
17288 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
17289 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
17290 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
17291 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
17292 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
17293 +#else
17294 +#define MODULE_PAX_KERNEXEC ""
17295 #endif
17296
17297 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17298 +#define MODULE_PAX_UDEREF "UDEREF "
17299 +#else
17300 +#define MODULE_PAX_UDEREF ""
17301 +#endif
17302 +
17303 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
17304 +
17305 #endif /* _ASM_X86_MODULE_H */
17306 diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
17307 index 5f2fc44..106caa6 100644
17308 --- a/arch/x86/include/asm/nmi.h
17309 +++ b/arch/x86/include/asm/nmi.h
17310 @@ -36,26 +36,35 @@ enum {
17311
17312 typedef int (*nmi_handler_t)(unsigned int, struct pt_regs *);
17313
17314 +struct nmiaction;
17315 +
17316 +struct nmiwork {
17317 + const struct nmiaction *action;
17318 + u64 max_duration;
17319 + struct irq_work irq_work;
17320 +};
17321 +
17322 struct nmiaction {
17323 struct list_head list;
17324 nmi_handler_t handler;
17325 - u64 max_duration;
17326 - struct irq_work irq_work;
17327 unsigned long flags;
17328 const char *name;
17329 -};
17330 + struct nmiwork *work;
17331 +} __do_const;
17332
17333 #define register_nmi_handler(t, fn, fg, n, init...) \
17334 ({ \
17335 - static struct nmiaction init fn##_na = { \
17336 + static struct nmiwork fn##_nw; \
17337 + static const struct nmiaction init fn##_na = { \
17338 .handler = (fn), \
17339 .name = (n), \
17340 .flags = (fg), \
17341 + .work = &fn##_nw, \
17342 }; \
17343 __register_nmi_handler((t), &fn##_na); \
17344 })
17345
17346 -int __register_nmi_handler(unsigned int, struct nmiaction *);
17347 +int __register_nmi_handler(unsigned int, const struct nmiaction *);
17348
17349 void unregister_nmi_handler(unsigned int, const char *);
17350
17351 diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
17352 index 775873d..04cd306 100644
17353 --- a/arch/x86/include/asm/page.h
17354 +++ b/arch/x86/include/asm/page.h
17355 @@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17356 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
17357
17358 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
17359 +#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
17360
17361 #define __boot_va(x) __va(x)
17362 #define __boot_pa(x) __pa(x)
17363 @@ -60,11 +61,21 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
17364 * virt_to_page(kaddr) returns a valid pointer if and only if
17365 * virt_addr_valid(kaddr) returns true.
17366 */
17367 -#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
17368 #define pfn_to_kaddr(pfn) __va((pfn) << PAGE_SHIFT)
17369 extern bool __virt_addr_valid(unsigned long kaddr);
17370 #define virt_addr_valid(kaddr) __virt_addr_valid((unsigned long) (kaddr))
17371
17372 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
17373 +#define virt_to_page(kaddr) \
17374 + ({ \
17375 + const void *__kaddr = (const void *)(kaddr); \
17376 + BUG_ON(!virt_addr_valid(__kaddr)); \
17377 + pfn_to_page(__pa(__kaddr) >> PAGE_SHIFT); \
17378 + })
17379 +#else
17380 +#define virt_to_page(kaddr) pfn_to_page(__pa(kaddr) >> PAGE_SHIFT)
17381 +#endif
17382 +
17383 #endif /* __ASSEMBLY__ */
17384
17385 #include <asm-generic/memory_model.h>
17386 diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
17387 index 0f1ddee..e2fc3d1 100644
17388 --- a/arch/x86/include/asm/page_64.h
17389 +++ b/arch/x86/include/asm/page_64.h
17390 @@ -7,9 +7,9 @@
17391
17392 /* duplicated to the one in bootmem.h */
17393 extern unsigned long max_pfn;
17394 -extern unsigned long phys_base;
17395 +extern const unsigned long phys_base;
17396
17397 -static inline unsigned long __phys_addr_nodebug(unsigned long x)
17398 +static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
17399 {
17400 unsigned long y = x - __START_KERNEL_map;
17401
17402 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
17403 index cd6e1610..70f4418 100644
17404 --- a/arch/x86/include/asm/paravirt.h
17405 +++ b/arch/x86/include/asm/paravirt.h
17406 @@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
17407 return (pmd_t) { ret };
17408 }
17409
17410 -static inline pmdval_t pmd_val(pmd_t pmd)
17411 +static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
17412 {
17413 pmdval_t ret;
17414
17415 @@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
17416 val);
17417 }
17418
17419 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
17420 +{
17421 + pgdval_t val = native_pgd_val(pgd);
17422 +
17423 + if (sizeof(pgdval_t) > sizeof(long))
17424 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
17425 + val, (u64)val >> 32);
17426 + else
17427 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
17428 + val);
17429 +}
17430 +
17431 static inline void pgd_clear(pgd_t *pgdp)
17432 {
17433 set_pgd(pgdp, __pgd(0));
17434 @@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
17435 pv_mmu_ops.set_fixmap(idx, phys, flags);
17436 }
17437
17438 +#ifdef CONFIG_PAX_KERNEXEC
17439 +static inline unsigned long pax_open_kernel(void)
17440 +{
17441 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
17442 +}
17443 +
17444 +static inline unsigned long pax_close_kernel(void)
17445 +{
17446 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
17447 +}
17448 +#else
17449 +static inline unsigned long pax_open_kernel(void) { return 0; }
17450 +static inline unsigned long pax_close_kernel(void) { return 0; }
17451 +#endif
17452 +
17453 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
17454
17455 static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock,
17456 @@ -906,7 +933,7 @@ extern void default_banner(void);
17457
17458 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
17459 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
17460 -#define PARA_INDIRECT(addr) *%cs:addr
17461 +#define PARA_INDIRECT(addr) *%ss:addr
17462 #endif
17463
17464 #define INTERRUPT_RETURN \
17465 @@ -981,6 +1008,21 @@ extern void default_banner(void);
17466 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
17467 CLBR_NONE, \
17468 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
17469 +
17470 +#define GET_CR0_INTO_RDI \
17471 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
17472 + mov %rax,%rdi
17473 +
17474 +#define SET_RDI_INTO_CR0 \
17475 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
17476 +
17477 +#define GET_CR3_INTO_RDI \
17478 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
17479 + mov %rax,%rdi
17480 +
17481 +#define SET_RDI_INTO_CR3 \
17482 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
17483 +
17484 #endif /* CONFIG_X86_32 */
17485
17486 #endif /* __ASSEMBLY__ */
17487 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
17488 index 7549b8b..f0edfda 100644
17489 --- a/arch/x86/include/asm/paravirt_types.h
17490 +++ b/arch/x86/include/asm/paravirt_types.h
17491 @@ -84,7 +84,7 @@ struct pv_init_ops {
17492 */
17493 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
17494 unsigned long addr, unsigned len);
17495 -};
17496 +} __no_const __no_randomize_layout;
17497
17498
17499 struct pv_lazy_ops {
17500 @@ -92,13 +92,13 @@ struct pv_lazy_ops {
17501 void (*enter)(void);
17502 void (*leave)(void);
17503 void (*flush)(void);
17504 -};
17505 +} __no_randomize_layout;
17506
17507 struct pv_time_ops {
17508 unsigned long long (*sched_clock)(void);
17509 unsigned long long (*steal_clock)(int cpu);
17510 unsigned long (*get_tsc_khz)(void);
17511 -};
17512 +} __no_const __no_randomize_layout;
17513
17514 struct pv_cpu_ops {
17515 /* hooks for various privileged instructions */
17516 @@ -192,7 +192,7 @@ struct pv_cpu_ops {
17517
17518 void (*start_context_switch)(struct task_struct *prev);
17519 void (*end_context_switch)(struct task_struct *next);
17520 -};
17521 +} __no_const __no_randomize_layout;
17522
17523 struct pv_irq_ops {
17524 /*
17525 @@ -215,7 +215,7 @@ struct pv_irq_ops {
17526 #ifdef CONFIG_X86_64
17527 void (*adjust_exception_frame)(void);
17528 #endif
17529 -};
17530 +} __no_randomize_layout;
17531
17532 struct pv_apic_ops {
17533 #ifdef CONFIG_X86_LOCAL_APIC
17534 @@ -223,7 +223,7 @@ struct pv_apic_ops {
17535 unsigned long start_eip,
17536 unsigned long start_esp);
17537 #endif
17538 -};
17539 +} __no_const __no_randomize_layout;
17540
17541 struct pv_mmu_ops {
17542 unsigned long (*read_cr2)(void);
17543 @@ -313,6 +313,7 @@ struct pv_mmu_ops {
17544 struct paravirt_callee_save make_pud;
17545
17546 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
17547 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
17548 #endif /* PAGETABLE_LEVELS == 4 */
17549 #endif /* PAGETABLE_LEVELS >= 3 */
17550
17551 @@ -324,7 +325,13 @@ struct pv_mmu_ops {
17552 an mfn. We can tell which is which from the index. */
17553 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
17554 phys_addr_t phys, pgprot_t flags);
17555 -};
17556 +
17557 +#ifdef CONFIG_PAX_KERNEXEC
17558 + unsigned long (*pax_open_kernel)(void);
17559 + unsigned long (*pax_close_kernel)(void);
17560 +#endif
17561 +
17562 +} __no_randomize_layout;
17563
17564 struct arch_spinlock;
17565 #ifdef CONFIG_SMP
17566 @@ -336,11 +343,14 @@ typedef u16 __ticket_t;
17567 struct pv_lock_ops {
17568 struct paravirt_callee_save lock_spinning;
17569 void (*unlock_kick)(struct arch_spinlock *lock, __ticket_t ticket);
17570 -};
17571 +} __no_randomize_layout;
17572
17573 /* This contains all the paravirt structures: we get a convenient
17574 * number for each function using the offset which we use to indicate
17575 - * what to patch. */
17576 + * what to patch.
17577 + * shouldn't be randomized due to the "NEAT TRICK" in paravirt.c
17578 + */
17579 +
17580 struct paravirt_patch_template {
17581 struct pv_init_ops pv_init_ops;
17582 struct pv_time_ops pv_time_ops;
17583 @@ -349,7 +359,7 @@ struct paravirt_patch_template {
17584 struct pv_apic_ops pv_apic_ops;
17585 struct pv_mmu_ops pv_mmu_ops;
17586 struct pv_lock_ops pv_lock_ops;
17587 -};
17588 +} __no_randomize_layout;
17589
17590 extern struct pv_info pv_info;
17591 extern struct pv_init_ops pv_init_ops;
17592 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
17593 index c4412e9..90e88c5 100644
17594 --- a/arch/x86/include/asm/pgalloc.h
17595 +++ b/arch/x86/include/asm/pgalloc.h
17596 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
17597 pmd_t *pmd, pte_t *pte)
17598 {
17599 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17600 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
17601 +}
17602 +
17603 +static inline void pmd_populate_user(struct mm_struct *mm,
17604 + pmd_t *pmd, pte_t *pte)
17605 +{
17606 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
17607 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
17608 }
17609
17610 @@ -108,12 +115,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
17611
17612 #ifdef CONFIG_X86_PAE
17613 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
17614 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
17615 +{
17616 + pud_populate(mm, pudp, pmd);
17617 +}
17618 #else /* !CONFIG_X86_PAE */
17619 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17620 {
17621 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17622 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
17623 }
17624 +
17625 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
17626 +{
17627 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17628 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
17629 +}
17630 #endif /* CONFIG_X86_PAE */
17631
17632 #if PAGETABLE_LEVELS > 3
17633 @@ -123,6 +140,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17634 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
17635 }
17636
17637 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17638 +{
17639 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
17640 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
17641 +}
17642 +
17643 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
17644 {
17645 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
17646 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
17647 index 0d193e2..bf59aeb 100644
17648 --- a/arch/x86/include/asm/pgtable-2level.h
17649 +++ b/arch/x86/include/asm/pgtable-2level.h
17650 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
17651
17652 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17653 {
17654 + pax_open_kernel();
17655 *pmdp = pmd;
17656 + pax_close_kernel();
17657 }
17658
17659 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17660 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
17661 index 81bb91b..9392125 100644
17662 --- a/arch/x86/include/asm/pgtable-3level.h
17663 +++ b/arch/x86/include/asm/pgtable-3level.h
17664 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17665
17666 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17667 {
17668 + pax_open_kernel();
17669 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
17670 + pax_close_kernel();
17671 }
17672
17673 static inline void native_set_pud(pud_t *pudp, pud_t pud)
17674 {
17675 + pax_open_kernel();
17676 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
17677 + pax_close_kernel();
17678 }
17679
17680 /*
17681 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
17682 index b459ddf..b44081b 100644
17683 --- a/arch/x86/include/asm/pgtable.h
17684 +++ b/arch/x86/include/asm/pgtable.h
17685 @@ -46,6 +46,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17686
17687 #ifndef __PAGETABLE_PUD_FOLDED
17688 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
17689 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
17690 #define pgd_clear(pgd) native_pgd_clear(pgd)
17691 #endif
17692
17693 @@ -83,12 +84,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17694
17695 #define arch_end_context_switch(prev) do {} while(0)
17696
17697 +#define pax_open_kernel() native_pax_open_kernel()
17698 +#define pax_close_kernel() native_pax_close_kernel()
17699 #endif /* CONFIG_PARAVIRT */
17700
17701 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
17702 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
17703 +
17704 +#ifdef CONFIG_PAX_KERNEXEC
17705 +static inline unsigned long native_pax_open_kernel(void)
17706 +{
17707 + unsigned long cr0;
17708 +
17709 + preempt_disable();
17710 + barrier();
17711 + cr0 = read_cr0() ^ X86_CR0_WP;
17712 + BUG_ON(cr0 & X86_CR0_WP);
17713 + write_cr0(cr0);
17714 + return cr0 ^ X86_CR0_WP;
17715 +}
17716 +
17717 +static inline unsigned long native_pax_close_kernel(void)
17718 +{
17719 + unsigned long cr0;
17720 +
17721 + cr0 = read_cr0() ^ X86_CR0_WP;
17722 + BUG_ON(!(cr0 & X86_CR0_WP));
17723 + write_cr0(cr0);
17724 + barrier();
17725 + preempt_enable_no_resched();
17726 + return cr0 ^ X86_CR0_WP;
17727 +}
17728 +#else
17729 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
17730 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
17731 +#endif
17732 +
17733 /*
17734 * The following only work if pte_present() is true.
17735 * Undefined behaviour if not..
17736 */
17737 +static inline int pte_user(pte_t pte)
17738 +{
17739 + return pte_val(pte) & _PAGE_USER;
17740 +}
17741 +
17742 static inline int pte_dirty(pte_t pte)
17743 {
17744 return pte_flags(pte) & _PAGE_DIRTY;
17745 @@ -149,6 +189,11 @@ static inline unsigned long pud_pfn(pud_t pud)
17746 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
17747 }
17748
17749 +static inline unsigned long pgd_pfn(pgd_t pgd)
17750 +{
17751 + return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
17752 +}
17753 +
17754 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
17755
17756 static inline int pmd_large(pmd_t pte)
17757 @@ -202,9 +247,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
17758 return pte_clear_flags(pte, _PAGE_RW);
17759 }
17760
17761 +static inline pte_t pte_mkread(pte_t pte)
17762 +{
17763 + return __pte(pte_val(pte) | _PAGE_USER);
17764 +}
17765 +
17766 static inline pte_t pte_mkexec(pte_t pte)
17767 {
17768 - return pte_clear_flags(pte, _PAGE_NX);
17769 +#ifdef CONFIG_X86_PAE
17770 + if (__supported_pte_mask & _PAGE_NX)
17771 + return pte_clear_flags(pte, _PAGE_NX);
17772 + else
17773 +#endif
17774 + return pte_set_flags(pte, _PAGE_USER);
17775 +}
17776 +
17777 +static inline pte_t pte_exprotect(pte_t pte)
17778 +{
17779 +#ifdef CONFIG_X86_PAE
17780 + if (__supported_pte_mask & _PAGE_NX)
17781 + return pte_set_flags(pte, _PAGE_NX);
17782 + else
17783 +#endif
17784 + return pte_clear_flags(pte, _PAGE_USER);
17785 }
17786
17787 static inline pte_t pte_mkdirty(pte_t pte)
17788 @@ -431,6 +496,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
17789 #endif
17790
17791 #ifndef __ASSEMBLY__
17792 +
17793 +#ifdef CONFIG_PAX_PER_CPU_PGD
17794 +extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
17795 +enum cpu_pgd_type {kernel = 0, user = 1};
17796 +static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
17797 +{
17798 + return cpu_pgd[cpu][type];
17799 +}
17800 +#endif
17801 +
17802 #include <linux/mm_types.h>
17803 #include <linux/mmdebug.h>
17804 #include <linux/log2.h>
17805 @@ -571,7 +646,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
17806 * Currently stuck as a macro due to indirect forward reference to
17807 * linux/mmzone.h's __section_mem_map_addr() definition:
17808 */
17809 -#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
17810 +#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
17811
17812 /* Find an entry in the second-level page table.. */
17813 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
17814 @@ -611,7 +686,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
17815 * Currently stuck as a macro due to indirect forward reference to
17816 * linux/mmzone.h's __section_mem_map_addr() definition:
17817 */
17818 -#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
17819 +#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
17820
17821 /* to find an entry in a page-table-directory. */
17822 static inline unsigned long pud_index(unsigned long address)
17823 @@ -626,7 +701,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
17824
17825 static inline int pgd_bad(pgd_t pgd)
17826 {
17827 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
17828 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
17829 }
17830
17831 static inline int pgd_none(pgd_t pgd)
17832 @@ -649,7 +724,12 @@ static inline int pgd_none(pgd_t pgd)
17833 * pgd_offset() returns a (pgd_t *)
17834 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
17835 */
17836 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
17837 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
17838 +
17839 +#ifdef CONFIG_PAX_PER_CPU_PGD
17840 +#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
17841 +#endif
17842 +
17843 /*
17844 * a shortcut which implies the use of the kernel's pgd, instead
17845 * of a process's
17846 @@ -660,6 +740,23 @@ static inline int pgd_none(pgd_t pgd)
17847 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
17848 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
17849
17850 +#ifdef CONFIG_X86_32
17851 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
17852 +#else
17853 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
17854 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
17855 +
17856 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17857 +#ifdef __ASSEMBLY__
17858 +#define pax_user_shadow_base pax_user_shadow_base(%rip)
17859 +#else
17860 +extern unsigned long pax_user_shadow_base;
17861 +extern pgdval_t clone_pgd_mask;
17862 +#endif
17863 +#endif
17864 +
17865 +#endif
17866 +
17867 #ifndef __ASSEMBLY__
17868
17869 extern int direct_gbpages;
17870 @@ -826,11 +923,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
17871 * dst and src can be on the same page, but the range must not overlap,
17872 * and must not cross a page boundary.
17873 */
17874 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
17875 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
17876 {
17877 - memcpy(dst, src, count * sizeof(pgd_t));
17878 + pax_open_kernel();
17879 + while (count--)
17880 + *dst++ = *src++;
17881 + pax_close_kernel();
17882 }
17883
17884 +#ifdef CONFIG_PAX_PER_CPU_PGD
17885 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
17886 +#endif
17887 +
17888 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17889 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
17890 +#else
17891 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
17892 +#endif
17893 +
17894 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
17895 static inline int page_level_shift(enum pg_level level)
17896 {
17897 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
17898 index 9ee3221..b979c6b 100644
17899 --- a/arch/x86/include/asm/pgtable_32.h
17900 +++ b/arch/x86/include/asm/pgtable_32.h
17901 @@ -25,9 +25,6 @@
17902 struct mm_struct;
17903 struct vm_area_struct;
17904
17905 -extern pgd_t swapper_pg_dir[1024];
17906 -extern pgd_t initial_page_table[1024];
17907 -
17908 static inline void pgtable_cache_init(void) { }
17909 static inline void check_pgt_cache(void) { }
17910 void paging_init(void);
17911 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
17912 # include <asm/pgtable-2level.h>
17913 #endif
17914
17915 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
17916 +extern pgd_t initial_page_table[PTRS_PER_PGD];
17917 +#ifdef CONFIG_X86_PAE
17918 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
17919 +#endif
17920 +
17921 #if defined(CONFIG_HIGHPTE)
17922 #define pte_offset_map(dir, address) \
17923 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
17924 @@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
17925 /* Clear a kernel PTE and flush it from the TLB */
17926 #define kpte_clear_flush(ptep, vaddr) \
17927 do { \
17928 + pax_open_kernel(); \
17929 pte_clear(&init_mm, (vaddr), (ptep)); \
17930 + pax_close_kernel(); \
17931 __flush_tlb_one((vaddr)); \
17932 } while (0)
17933
17934 #endif /* !__ASSEMBLY__ */
17935
17936 +#define HAVE_ARCH_UNMAPPED_AREA
17937 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
17938 +
17939 /*
17940 * kern_addr_valid() is (1) for FLATMEM and (0) for
17941 * SPARSEMEM and DISCONTIGMEM
17942 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
17943 index ed5903b..c7fe163 100644
17944 --- a/arch/x86/include/asm/pgtable_32_types.h
17945 +++ b/arch/x86/include/asm/pgtable_32_types.h
17946 @@ -8,7 +8,7 @@
17947 */
17948 #ifdef CONFIG_X86_PAE
17949 # include <asm/pgtable-3level_types.h>
17950 -# define PMD_SIZE (1UL << PMD_SHIFT)
17951 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
17952 # define PMD_MASK (~(PMD_SIZE - 1))
17953 #else
17954 # include <asm/pgtable-2level_types.h>
17955 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
17956 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
17957 #endif
17958
17959 +#ifdef CONFIG_PAX_KERNEXEC
17960 +#ifndef __ASSEMBLY__
17961 +extern unsigned char MODULES_EXEC_VADDR[];
17962 +extern unsigned char MODULES_EXEC_END[];
17963 +#endif
17964 +#include <asm/boot.h>
17965 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
17966 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
17967 +#else
17968 +#define ktla_ktva(addr) (addr)
17969 +#define ktva_ktla(addr) (addr)
17970 +#endif
17971 +
17972 #define MODULES_VADDR VMALLOC_START
17973 #define MODULES_END VMALLOC_END
17974 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
17975 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
17976 index e22c1db..23a625a 100644
17977 --- a/arch/x86/include/asm/pgtable_64.h
17978 +++ b/arch/x86/include/asm/pgtable_64.h
17979 @@ -16,10 +16,14 @@
17980
17981 extern pud_t level3_kernel_pgt[512];
17982 extern pud_t level3_ident_pgt[512];
17983 +extern pud_t level3_vmalloc_start_pgt[512];
17984 +extern pud_t level3_vmalloc_end_pgt[512];
17985 +extern pud_t level3_vmemmap_pgt[512];
17986 +extern pud_t level2_vmemmap_pgt[512];
17987 extern pmd_t level2_kernel_pgt[512];
17988 extern pmd_t level2_fixmap_pgt[512];
17989 -extern pmd_t level2_ident_pgt[512];
17990 -extern pgd_t init_level4_pgt[];
17991 +extern pmd_t level2_ident_pgt[512*2];
17992 +extern pgd_t init_level4_pgt[512];
17993
17994 #define swapper_pg_dir init_level4_pgt
17995
17996 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17997
17998 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17999 {
18000 + pax_open_kernel();
18001 *pmdp = pmd;
18002 + pax_close_kernel();
18003 }
18004
18005 static inline void native_pmd_clear(pmd_t *pmd)
18006 @@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
18007
18008 static inline void native_set_pud(pud_t *pudp, pud_t pud)
18009 {
18010 + pax_open_kernel();
18011 *pudp = pud;
18012 + pax_close_kernel();
18013 }
18014
18015 static inline void native_pud_clear(pud_t *pud)
18016 @@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
18017
18018 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
18019 {
18020 + pax_open_kernel();
18021 + *pgdp = pgd;
18022 + pax_close_kernel();
18023 +}
18024 +
18025 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
18026 +{
18027 *pgdp = pgd;
18028 }
18029
18030 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
18031 index c883bf7..19970b3 100644
18032 --- a/arch/x86/include/asm/pgtable_64_types.h
18033 +++ b/arch/x86/include/asm/pgtable_64_types.h
18034 @@ -61,6 +61,11 @@ typedef struct { pteval_t pte; } pte_t;
18035 #define MODULES_VADDR (__START_KERNEL_map + KERNEL_IMAGE_SIZE)
18036 #define MODULES_END _AC(0xffffffffff000000, UL)
18037 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
18038 +#define MODULES_EXEC_VADDR MODULES_VADDR
18039 +#define MODULES_EXEC_END MODULES_END
18040 +
18041 +#define ktla_ktva(addr) (addr)
18042 +#define ktva_ktla(addr) (addr)
18043
18044 #define EARLY_DYNAMIC_PAGE_TABLES 64
18045
18046 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
18047 index eb3d449..8d95316 100644
18048 --- a/arch/x86/include/asm/pgtable_types.h
18049 +++ b/arch/x86/include/asm/pgtable_types.h
18050 @@ -16,13 +16,12 @@
18051 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
18052 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
18053 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
18054 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
18055 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
18056 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
18057 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
18058 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
18059 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
18060 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
18061 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
18062 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
18063 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
18064 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
18065
18066 /* If _PAGE_BIT_PRESENT is clear, we use these: */
18067 @@ -40,7 +39,6 @@
18068 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
18069 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
18070 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
18071 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
18072 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
18073 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
18074 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
18075 @@ -87,8 +85,10 @@
18076
18077 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
18078 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
18079 -#else
18080 +#elif defined(CONFIG_KMEMCHECK) || defined(CONFIG_MEM_SOFT_DIRTY)
18081 #define _PAGE_NX (_AT(pteval_t, 0))
18082 +#else
18083 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
18084 #endif
18085
18086 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
18087 @@ -147,6 +147,9 @@
18088 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
18089 _PAGE_ACCESSED)
18090
18091 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
18092 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
18093 +
18094 #define __PAGE_KERNEL_EXEC \
18095 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
18096 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
18097 @@ -157,7 +160,7 @@
18098 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
18099 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
18100 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
18101 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
18102 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
18103 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
18104 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
18105 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
18106 @@ -214,7 +217,7 @@
18107 #ifdef CONFIG_X86_64
18108 #define __PAGE_KERNEL_IDENT_LARGE_EXEC __PAGE_KERNEL_LARGE_EXEC
18109 #else
18110 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
18111 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18112 #define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
18113 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
18114 #endif
18115 @@ -253,7 +256,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
18116 {
18117 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
18118 }
18119 +#endif
18120
18121 +#if PAGETABLE_LEVELS == 3
18122 +#include <asm-generic/pgtable-nopud.h>
18123 +#endif
18124 +
18125 +#if PAGETABLE_LEVELS == 2
18126 +#include <asm-generic/pgtable-nopmd.h>
18127 +#endif
18128 +
18129 +#ifndef __ASSEMBLY__
18130 #if PAGETABLE_LEVELS > 3
18131 typedef struct { pudval_t pud; } pud_t;
18132
18133 @@ -267,8 +280,6 @@ static inline pudval_t native_pud_val(pud_t pud)
18134 return pud.pud;
18135 }
18136 #else
18137 -#include <asm-generic/pgtable-nopud.h>
18138 -
18139 static inline pudval_t native_pud_val(pud_t pud)
18140 {
18141 return native_pgd_val(pud.pgd);
18142 @@ -288,8 +299,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
18143 return pmd.pmd;
18144 }
18145 #else
18146 -#include <asm-generic/pgtable-nopmd.h>
18147 -
18148 static inline pmdval_t native_pmd_val(pmd_t pmd)
18149 {
18150 return native_pgd_val(pmd.pud.pgd);
18151 @@ -329,7 +338,6 @@ typedef struct page *pgtable_t;
18152
18153 extern pteval_t __supported_pte_mask;
18154 extern void set_nx(void);
18155 -extern int nx_enabled;
18156
18157 #define pgprot_writecombine pgprot_writecombine
18158 extern pgprot_t pgprot_writecombine(pgprot_t prot);
18159 diff --git a/arch/x86/include/asm/preempt.h b/arch/x86/include/asm/preempt.h
18160 index 7024c12..71c46b9 100644
18161 --- a/arch/x86/include/asm/preempt.h
18162 +++ b/arch/x86/include/asm/preempt.h
18163 @@ -87,7 +87,7 @@ static __always_inline void __preempt_count_sub(int val)
18164 */
18165 static __always_inline bool __preempt_count_dec_and_test(void)
18166 {
18167 - GEN_UNARY_RMWcc("decl", __preempt_count, __percpu_arg(0), "e");
18168 + GEN_UNARY_RMWcc("decl", "incl", __preempt_count, __percpu_arg(0), "e");
18169 }
18170
18171 /*
18172 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
18173 index a4ea023..33aa874 100644
18174 --- a/arch/x86/include/asm/processor.h
18175 +++ b/arch/x86/include/asm/processor.h
18176 @@ -128,7 +128,7 @@ struct cpuinfo_x86 {
18177 /* Index into per_cpu list: */
18178 u16 cpu_index;
18179 u32 microcode;
18180 -} __attribute__((__aligned__(SMP_CACHE_BYTES)));
18181 +} __attribute__((__aligned__(SMP_CACHE_BYTES))) __randomize_layout;
18182
18183 #define X86_VENDOR_INTEL 0
18184 #define X86_VENDOR_CYRIX 1
18185 @@ -199,9 +199,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
18186 : "memory");
18187 }
18188
18189 +/* invpcid (%rdx),%rax */
18190 +#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
18191 +
18192 +#define INVPCID_SINGLE_ADDRESS 0UL
18193 +#define INVPCID_SINGLE_CONTEXT 1UL
18194 +#define INVPCID_ALL_GLOBAL 2UL
18195 +#define INVPCID_ALL_MONGLOBAL 3UL
18196 +
18197 +#define PCID_KERNEL 0UL
18198 +#define PCID_USER 1UL
18199 +#define PCID_NOFLUSH (1UL << 63)
18200 +
18201 static inline void load_cr3(pgd_t *pgdir)
18202 {
18203 - write_cr3(__pa(pgdir));
18204 + write_cr3(__pa(pgdir) | PCID_KERNEL);
18205 }
18206
18207 #ifdef CONFIG_X86_32
18208 @@ -283,7 +295,7 @@ struct tss_struct {
18209
18210 } ____cacheline_aligned;
18211
18212 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
18213 +extern struct tss_struct init_tss[NR_CPUS];
18214
18215 /*
18216 * Save the original ist values for checking stack pointers during debugging
18217 @@ -479,6 +491,7 @@ struct thread_struct {
18218 unsigned short ds;
18219 unsigned short fsindex;
18220 unsigned short gsindex;
18221 + unsigned short ss;
18222 #endif
18223 #ifdef CONFIG_X86_32
18224 unsigned long ip;
18225 @@ -588,29 +601,8 @@ static inline void load_sp0(struct tss_struct *tss,
18226 extern unsigned long mmu_cr4_features;
18227 extern u32 *trampoline_cr4_features;
18228
18229 -static inline void set_in_cr4(unsigned long mask)
18230 -{
18231 - unsigned long cr4;
18232 -
18233 - mmu_cr4_features |= mask;
18234 - if (trampoline_cr4_features)
18235 - *trampoline_cr4_features = mmu_cr4_features;
18236 - cr4 = read_cr4();
18237 - cr4 |= mask;
18238 - write_cr4(cr4);
18239 -}
18240 -
18241 -static inline void clear_in_cr4(unsigned long mask)
18242 -{
18243 - unsigned long cr4;
18244 -
18245 - mmu_cr4_features &= ~mask;
18246 - if (trampoline_cr4_features)
18247 - *trampoline_cr4_features = mmu_cr4_features;
18248 - cr4 = read_cr4();
18249 - cr4 &= ~mask;
18250 - write_cr4(cr4);
18251 -}
18252 +extern void set_in_cr4(unsigned long mask);
18253 +extern void clear_in_cr4(unsigned long mask);
18254
18255 typedef struct {
18256 unsigned long seg;
18257 @@ -836,11 +828,18 @@ static inline void spin_lock_prefetch(const void *x)
18258 */
18259 #define TASK_SIZE PAGE_OFFSET
18260 #define TASK_SIZE_MAX TASK_SIZE
18261 +
18262 +#ifdef CONFIG_PAX_SEGMEXEC
18263 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
18264 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
18265 +#else
18266 #define STACK_TOP TASK_SIZE
18267 -#define STACK_TOP_MAX STACK_TOP
18268 +#endif
18269 +
18270 +#define STACK_TOP_MAX TASK_SIZE
18271
18272 #define INIT_THREAD { \
18273 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
18274 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18275 .vm86_info = NULL, \
18276 .sysenter_cs = __KERNEL_CS, \
18277 .io_bitmap_ptr = NULL, \
18278 @@ -854,7 +853,7 @@ static inline void spin_lock_prefetch(const void *x)
18279 */
18280 #define INIT_TSS { \
18281 .x86_tss = { \
18282 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
18283 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
18284 .ss0 = __KERNEL_DS, \
18285 .ss1 = __KERNEL_CS, \
18286 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
18287 @@ -865,11 +864,7 @@ static inline void spin_lock_prefetch(const void *x)
18288 extern unsigned long thread_saved_pc(struct task_struct *tsk);
18289
18290 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
18291 -#define KSTK_TOP(info) \
18292 -({ \
18293 - unsigned long *__ptr = (unsigned long *)(info); \
18294 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
18295 -})
18296 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
18297
18298 /*
18299 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
18300 @@ -884,7 +879,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18301 #define task_pt_regs(task) \
18302 ({ \
18303 struct pt_regs *__regs__; \
18304 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
18305 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
18306 __regs__ - 1; \
18307 })
18308
18309 @@ -894,13 +889,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18310 /*
18311 * User space process size. 47bits minus one guard page.
18312 */
18313 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
18314 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
18315
18316 /* This decides where the kernel will search for a free chunk of vm
18317 * space during mmap's.
18318 */
18319 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
18320 - 0xc0000000 : 0xFFFFe000)
18321 + 0xc0000000 : 0xFFFFf000)
18322
18323 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
18324 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
18325 @@ -911,11 +906,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
18326 #define STACK_TOP_MAX TASK_SIZE_MAX
18327
18328 #define INIT_THREAD { \
18329 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18330 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18331 }
18332
18333 #define INIT_TSS { \
18334 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
18335 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
18336 }
18337
18338 /*
18339 @@ -943,6 +938,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
18340 */
18341 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
18342
18343 +#ifdef CONFIG_PAX_SEGMEXEC
18344 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
18345 +#endif
18346 +
18347 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
18348
18349 /* Get/set a process' ability to use the timestamp counter instruction */
18350 @@ -969,7 +968,7 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
18351 return 0;
18352 }
18353
18354 -extern unsigned long arch_align_stack(unsigned long sp);
18355 +#define arch_align_stack(x) ((x) & ~0xfUL)
18356 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
18357
18358 void default_idle(void);
18359 @@ -979,6 +978,6 @@ bool xen_set_default_idle(void);
18360 #define xen_set_default_idle 0
18361 #endif
18362
18363 -void stop_this_cpu(void *dummy);
18364 +void stop_this_cpu(void *dummy) __noreturn;
18365 void df_debug(struct pt_regs *regs, long error_code);
18366 #endif /* _ASM_X86_PROCESSOR_H */
18367 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
18368 index 6205f0c..b31a4a4 100644
18369 --- a/arch/x86/include/asm/ptrace.h
18370 +++ b/arch/x86/include/asm/ptrace.h
18371 @@ -84,28 +84,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
18372 }
18373
18374 /*
18375 - * user_mode_vm(regs) determines whether a register set came from user mode.
18376 + * user_mode(regs) determines whether a register set came from user mode.
18377 * This is true if V8086 mode was enabled OR if the register set was from
18378 * protected mode with RPL-3 CS value. This tricky test checks that with
18379 * one comparison. Many places in the kernel can bypass this full check
18380 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
18381 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
18382 + * be used.
18383 */
18384 -static inline int user_mode(struct pt_regs *regs)
18385 +static inline int user_mode_novm(struct pt_regs *regs)
18386 {
18387 #ifdef CONFIG_X86_32
18388 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
18389 #else
18390 - return !!(regs->cs & 3);
18391 + return !!(regs->cs & SEGMENT_RPL_MASK);
18392 #endif
18393 }
18394
18395 -static inline int user_mode_vm(struct pt_regs *regs)
18396 +static inline int user_mode(struct pt_regs *regs)
18397 {
18398 #ifdef CONFIG_X86_32
18399 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
18400 USER_RPL;
18401 #else
18402 - return user_mode(regs);
18403 + return user_mode_novm(regs);
18404 #endif
18405 }
18406
18407 @@ -121,15 +122,16 @@ static inline int v8086_mode(struct pt_regs *regs)
18408 #ifdef CONFIG_X86_64
18409 static inline bool user_64bit_mode(struct pt_regs *regs)
18410 {
18411 + unsigned long cs = regs->cs & 0xffff;
18412 #ifndef CONFIG_PARAVIRT
18413 /*
18414 * On non-paravirt systems, this is the only long mode CPL 3
18415 * selector. We do not allow long mode selectors in the LDT.
18416 */
18417 - return regs->cs == __USER_CS;
18418 + return cs == __USER_CS;
18419 #else
18420 /* Headers are too twisted for this to go in paravirt.h. */
18421 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
18422 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
18423 #endif
18424 }
18425
18426 @@ -180,9 +182,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
18427 * Traps from the kernel do not save sp and ss.
18428 * Use the helper function to retrieve sp.
18429 */
18430 - if (offset == offsetof(struct pt_regs, sp) &&
18431 - regs->cs == __KERNEL_CS)
18432 - return kernel_stack_pointer(regs);
18433 + if (offset == offsetof(struct pt_regs, sp)) {
18434 + unsigned long cs = regs->cs & 0xffff;
18435 + if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
18436 + return kernel_stack_pointer(regs);
18437 + }
18438 #endif
18439 return *(unsigned long *)((unsigned long)regs + offset);
18440 }
18441 diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
18442 index 9c6b890..5305f53 100644
18443 --- a/arch/x86/include/asm/realmode.h
18444 +++ b/arch/x86/include/asm/realmode.h
18445 @@ -22,16 +22,14 @@ struct real_mode_header {
18446 #endif
18447 /* APM/BIOS reboot */
18448 u32 machine_real_restart_asm;
18449 -#ifdef CONFIG_X86_64
18450 u32 machine_real_restart_seg;
18451 -#endif
18452 };
18453
18454 /* This must match data at trampoline_32/64.S */
18455 struct trampoline_header {
18456 #ifdef CONFIG_X86_32
18457 u32 start;
18458 - u16 gdt_pad;
18459 + u16 boot_cs;
18460 u16 gdt_limit;
18461 u32 gdt_base;
18462 #else
18463 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
18464 index a82c4f1..ac45053 100644
18465 --- a/arch/x86/include/asm/reboot.h
18466 +++ b/arch/x86/include/asm/reboot.h
18467 @@ -6,13 +6,13 @@
18468 struct pt_regs;
18469
18470 struct machine_ops {
18471 - void (*restart)(char *cmd);
18472 - void (*halt)(void);
18473 - void (*power_off)(void);
18474 + void (* __noreturn restart)(char *cmd);
18475 + void (* __noreturn halt)(void);
18476 + void (* __noreturn power_off)(void);
18477 void (*shutdown)(void);
18478 void (*crash_shutdown)(struct pt_regs *);
18479 - void (*emergency_restart)(void);
18480 -};
18481 + void (* __noreturn emergency_restart)(void);
18482 +} __no_const;
18483
18484 extern struct machine_ops machine_ops;
18485
18486 diff --git a/arch/x86/include/asm/rmwcc.h b/arch/x86/include/asm/rmwcc.h
18487 index 8f7866a..e442f20 100644
18488 --- a/arch/x86/include/asm/rmwcc.h
18489 +++ b/arch/x86/include/asm/rmwcc.h
18490 @@ -3,7 +3,34 @@
18491
18492 #ifdef CC_HAVE_ASM_GOTO
18493
18494 -#define __GEN_RMWcc(fullop, var, cc, ...) \
18495 +#ifdef CONFIG_PAX_REFCOUNT
18496 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18497 +do { \
18498 + asm_volatile_goto (fullop \
18499 + ";jno 0f\n" \
18500 + fullantiop \
18501 + ";int $4\n0:\n" \
18502 + _ASM_EXTABLE(0b, 0b) \
18503 + ";j" cc " %l[cc_label]" \
18504 + : : "m" (var), ## __VA_ARGS__ \
18505 + : "memory" : cc_label); \
18506 + return 0; \
18507 +cc_label: \
18508 + return 1; \
18509 +} while (0)
18510 +#else
18511 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18512 +do { \
18513 + asm_volatile_goto (fullop ";j" cc " %l[cc_label]" \
18514 + : : "m" (var), ## __VA_ARGS__ \
18515 + : "memory" : cc_label); \
18516 + return 0; \
18517 +cc_label: \
18518 + return 1; \
18519 +} while (0)
18520 +#endif
18521 +
18522 +#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18523 do { \
18524 asm_volatile_goto (fullop "; j" cc " %l[cc_label]" \
18525 : : "m" (var), ## __VA_ARGS__ \
18526 @@ -13,15 +40,46 @@ cc_label: \
18527 return 1; \
18528 } while (0)
18529
18530 -#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18531 - __GEN_RMWcc(op " " arg0, var, cc)
18532 +#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18533 + __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18534
18535 -#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18536 - __GEN_RMWcc(op " %1, " arg0, var, cc, vcon (val))
18537 +#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18538 + __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18539 +
18540 +#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18541 + __GEN_RMWcc(op " %1, " arg0, antiop " %1, " arg0, var, cc, vcon (val))
18542 +
18543 +#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18544 + __GEN_RMWcc_unchecked(op " %1, " arg0, var, cc, vcon (val))
18545
18546 #else /* !CC_HAVE_ASM_GOTO */
18547
18548 -#define __GEN_RMWcc(fullop, var, cc, ...) \
18549 +#ifdef CONFIG_PAX_REFCOUNT
18550 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18551 +do { \
18552 + char c; \
18553 + asm volatile (fullop \
18554 + ";jno 0f\n" \
18555 + fullantiop \
18556 + ";int $4\n0:\n" \
18557 + _ASM_EXTABLE(0b, 0b) \
18558 + "; set" cc " %1" \
18559 + : "+m" (var), "=qm" (c) \
18560 + : __VA_ARGS__ : "memory"); \
18561 + return c != 0; \
18562 +} while (0)
18563 +#else
18564 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
18565 +do { \
18566 + char c; \
18567 + asm volatile (fullop "; set" cc " %1" \
18568 + : "+m" (var), "=qm" (c) \
18569 + : __VA_ARGS__ : "memory"); \
18570 + return c != 0; \
18571 +} while (0)
18572 +#endif
18573 +
18574 +#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
18575 do { \
18576 char c; \
18577 asm volatile (fullop "; set" cc " %1" \
18578 @@ -30,11 +88,17 @@ do { \
18579 return c != 0; \
18580 } while (0)
18581
18582 -#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
18583 - __GEN_RMWcc(op " " arg0, var, cc)
18584 +#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
18585 + __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
18586 +
18587 +#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
18588 + __GEN_RMWcc_unchecked(op " " arg0, var, cc)
18589 +
18590 +#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
18591 + __GEN_RMWcc(op " %2, " arg0, antiop " %2, " arg0, var, cc, vcon (val))
18592
18593 -#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
18594 - __GEN_RMWcc(op " %2, " arg0, var, cc, vcon (val))
18595 +#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
18596 + __GEN_RMWcc_unchecked(op " %2, " arg0, var, cc, vcon (val))
18597
18598 #endif /* CC_HAVE_ASM_GOTO */
18599
18600 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
18601 index cad82c9..2e5c5c1 100644
18602 --- a/arch/x86/include/asm/rwsem.h
18603 +++ b/arch/x86/include/asm/rwsem.h
18604 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
18605 {
18606 asm volatile("# beginning down_read\n\t"
18607 LOCK_PREFIX _ASM_INC "(%1)\n\t"
18608 +
18609 +#ifdef CONFIG_PAX_REFCOUNT
18610 + "jno 0f\n"
18611 + LOCK_PREFIX _ASM_DEC "(%1)\n"
18612 + "int $4\n0:\n"
18613 + _ASM_EXTABLE(0b, 0b)
18614 +#endif
18615 +
18616 /* adds 0x00000001 */
18617 " jns 1f\n"
18618 " call call_rwsem_down_read_failed\n"
18619 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
18620 "1:\n\t"
18621 " mov %1,%2\n\t"
18622 " add %3,%2\n\t"
18623 +
18624 +#ifdef CONFIG_PAX_REFCOUNT
18625 + "jno 0f\n"
18626 + "sub %3,%2\n"
18627 + "int $4\n0:\n"
18628 + _ASM_EXTABLE(0b, 0b)
18629 +#endif
18630 +
18631 " jle 2f\n\t"
18632 LOCK_PREFIX " cmpxchg %2,%0\n\t"
18633 " jnz 1b\n\t"
18634 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
18635 long tmp;
18636 asm volatile("# beginning down_write\n\t"
18637 LOCK_PREFIX " xadd %1,(%2)\n\t"
18638 +
18639 +#ifdef CONFIG_PAX_REFCOUNT
18640 + "jno 0f\n"
18641 + "mov %1,(%2)\n"
18642 + "int $4\n0:\n"
18643 + _ASM_EXTABLE(0b, 0b)
18644 +#endif
18645 +
18646 /* adds 0xffff0001, returns the old value */
18647 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
18648 /* was the active mask 0 before? */
18649 @@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
18650 long tmp;
18651 asm volatile("# beginning __up_read\n\t"
18652 LOCK_PREFIX " xadd %1,(%2)\n\t"
18653 +
18654 +#ifdef CONFIG_PAX_REFCOUNT
18655 + "jno 0f\n"
18656 + "mov %1,(%2)\n"
18657 + "int $4\n0:\n"
18658 + _ASM_EXTABLE(0b, 0b)
18659 +#endif
18660 +
18661 /* subtracts 1, returns the old value */
18662 " jns 1f\n\t"
18663 " call call_rwsem_wake\n" /* expects old value in %edx */
18664 @@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
18665 long tmp;
18666 asm volatile("# beginning __up_write\n\t"
18667 LOCK_PREFIX " xadd %1,(%2)\n\t"
18668 +
18669 +#ifdef CONFIG_PAX_REFCOUNT
18670 + "jno 0f\n"
18671 + "mov %1,(%2)\n"
18672 + "int $4\n0:\n"
18673 + _ASM_EXTABLE(0b, 0b)
18674 +#endif
18675 +
18676 /* subtracts 0xffff0001, returns the old value */
18677 " jns 1f\n\t"
18678 " call call_rwsem_wake\n" /* expects old value in %edx */
18679 @@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18680 {
18681 asm volatile("# beginning __downgrade_write\n\t"
18682 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
18683 +
18684 +#ifdef CONFIG_PAX_REFCOUNT
18685 + "jno 0f\n"
18686 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
18687 + "int $4\n0:\n"
18688 + _ASM_EXTABLE(0b, 0b)
18689 +#endif
18690 +
18691 /*
18692 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
18693 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
18694 @@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18695 */
18696 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18697 {
18698 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
18699 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
18700 +
18701 +#ifdef CONFIG_PAX_REFCOUNT
18702 + "jno 0f\n"
18703 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
18704 + "int $4\n0:\n"
18705 + _ASM_EXTABLE(0b, 0b)
18706 +#endif
18707 +
18708 : "+m" (sem->count)
18709 : "er" (delta));
18710 }
18711 @@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18712 */
18713 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
18714 {
18715 - return delta + xadd(&sem->count, delta);
18716 + return delta + xadd_check_overflow(&sem->count, delta);
18717 }
18718
18719 #endif /* __KERNEL__ */
18720 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
18721 index 6f1c3a8..7744f19 100644
18722 --- a/arch/x86/include/asm/segment.h
18723 +++ b/arch/x86/include/asm/segment.h
18724 @@ -64,10 +64,15 @@
18725 * 26 - ESPFIX small SS
18726 * 27 - per-cpu [ offset to per-cpu data area ]
18727 * 28 - stack_canary-20 [ for stack protector ]
18728 - * 29 - unused
18729 - * 30 - unused
18730 + * 29 - PCI BIOS CS
18731 + * 30 - PCI BIOS DS
18732 * 31 - TSS for double fault handler
18733 */
18734 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
18735 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
18736 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
18737 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
18738 +
18739 #define GDT_ENTRY_TLS_MIN 6
18740 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
18741
18742 @@ -79,6 +84,8 @@
18743
18744 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
18745
18746 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
18747 +
18748 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
18749
18750 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
18751 @@ -104,6 +111,12 @@
18752 #define __KERNEL_STACK_CANARY 0
18753 #endif
18754
18755 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
18756 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
18757 +
18758 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
18759 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
18760 +
18761 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
18762
18763 /*
18764 @@ -141,7 +154,7 @@
18765 */
18766
18767 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
18768 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
18769 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
18770
18771
18772 #else
18773 @@ -165,6 +178,8 @@
18774 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
18775 #define __USER32_DS __USER_DS
18776
18777 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
18778 +
18779 #define GDT_ENTRY_TSS 8 /* needs two entries */
18780 #define GDT_ENTRY_LDT 10 /* needs two entries */
18781 #define GDT_ENTRY_TLS_MIN 12
18782 @@ -173,6 +188,8 @@
18783 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
18784 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
18785
18786 +#define GDT_ENTRY_UDEREF_KERNEL_DS 16
18787 +
18788 /* TLS indexes for 64bit - hardcoded in arch_prctl */
18789 #define FS_TLS 0
18790 #define GS_TLS 1
18791 @@ -180,12 +197,14 @@
18792 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
18793 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
18794
18795 -#define GDT_ENTRIES 16
18796 +#define GDT_ENTRIES 17
18797
18798 #endif
18799
18800 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
18801 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
18802 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
18803 +#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
18804 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
18805 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
18806 #ifndef CONFIG_PARAVIRT
18807 @@ -268,7 +287,7 @@ static inline unsigned long get_limit(unsigned long segment)
18808 {
18809 unsigned long __limit;
18810 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
18811 - return __limit + 1;
18812 + return __limit;
18813 }
18814
18815 #endif /* !__ASSEMBLY__ */
18816 diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
18817 index 8d3120f..352b440 100644
18818 --- a/arch/x86/include/asm/smap.h
18819 +++ b/arch/x86/include/asm/smap.h
18820 @@ -25,11 +25,40 @@
18821
18822 #include <asm/alternative-asm.h>
18823
18824 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18825 +#define ASM_PAX_OPEN_USERLAND \
18826 + 661: jmp 663f; \
18827 + .pushsection .altinstr_replacement, "a" ; \
18828 + 662: pushq %rax; nop; \
18829 + .popsection ; \
18830 + .pushsection .altinstructions, "a" ; \
18831 + altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
18832 + .popsection ; \
18833 + call __pax_open_userland; \
18834 + popq %rax; \
18835 + 663:
18836 +
18837 +#define ASM_PAX_CLOSE_USERLAND \
18838 + 661: jmp 663f; \
18839 + .pushsection .altinstr_replacement, "a" ; \
18840 + 662: pushq %rax; nop; \
18841 + .popsection; \
18842 + .pushsection .altinstructions, "a" ; \
18843 + altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
18844 + .popsection; \
18845 + call __pax_close_userland; \
18846 + popq %rax; \
18847 + 663:
18848 +#else
18849 +#define ASM_PAX_OPEN_USERLAND
18850 +#define ASM_PAX_CLOSE_USERLAND
18851 +#endif
18852 +
18853 #ifdef CONFIG_X86_SMAP
18854
18855 #define ASM_CLAC \
18856 661: ASM_NOP3 ; \
18857 - .pushsection .altinstr_replacement, "ax" ; \
18858 + .pushsection .altinstr_replacement, "a" ; \
18859 662: __ASM_CLAC ; \
18860 .popsection ; \
18861 .pushsection .altinstructions, "a" ; \
18862 @@ -38,7 +67,7 @@
18863
18864 #define ASM_STAC \
18865 661: ASM_NOP3 ; \
18866 - .pushsection .altinstr_replacement, "ax" ; \
18867 + .pushsection .altinstr_replacement, "a" ; \
18868 662: __ASM_STAC ; \
18869 .popsection ; \
18870 .pushsection .altinstructions, "a" ; \
18871 @@ -56,6 +85,37 @@
18872
18873 #include <asm/alternative.h>
18874
18875 +#define __HAVE_ARCH_PAX_OPEN_USERLAND
18876 +#define __HAVE_ARCH_PAX_CLOSE_USERLAND
18877 +
18878 +extern void __pax_open_userland(void);
18879 +static __always_inline unsigned long pax_open_userland(void)
18880 +{
18881 +
18882 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18883 + asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
18884 + :
18885 + : [open] "i" (__pax_open_userland)
18886 + : "memory", "rax");
18887 +#endif
18888 +
18889 + return 0;
18890 +}
18891 +
18892 +extern void __pax_close_userland(void);
18893 +static __always_inline unsigned long pax_close_userland(void)
18894 +{
18895 +
18896 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18897 + asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
18898 + :
18899 + : [close] "i" (__pax_close_userland)
18900 + : "memory", "rax");
18901 +#endif
18902 +
18903 + return 0;
18904 +}
18905 +
18906 #ifdef CONFIG_X86_SMAP
18907
18908 static __always_inline void clac(void)
18909 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
18910 index 8cd27e0..7f05ec8 100644
18911 --- a/arch/x86/include/asm/smp.h
18912 +++ b/arch/x86/include/asm/smp.h
18913 @@ -35,7 +35,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
18914 /* cpus sharing the last level cache: */
18915 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
18916 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
18917 -DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
18918 +DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
18919
18920 static inline struct cpumask *cpu_sibling_mask(int cpu)
18921 {
18922 @@ -78,7 +78,7 @@ struct smp_ops {
18923
18924 void (*send_call_func_ipi)(const struct cpumask *mask);
18925 void (*send_call_func_single_ipi)(int cpu);
18926 -};
18927 +} __no_const;
18928
18929 /* Globals due to paravirt */
18930 extern void set_cpu_sibling_map(int cpu);
18931 @@ -190,14 +190,8 @@ extern unsigned disabled_cpus;
18932 extern int safe_smp_processor_id(void);
18933
18934 #elif defined(CONFIG_X86_64_SMP)
18935 -#define raw_smp_processor_id() (this_cpu_read(cpu_number))
18936 -
18937 -#define stack_smp_processor_id() \
18938 -({ \
18939 - struct thread_info *ti; \
18940 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
18941 - ti->cpu; \
18942 -})
18943 +#define raw_smp_processor_id() (this_cpu_read(cpu_number))
18944 +#define stack_smp_processor_id() raw_smp_processor_id()
18945 #define safe_smp_processor_id() smp_processor_id()
18946
18947 #endif
18948 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
18949 index 0f62f54..cb5d0dd 100644
18950 --- a/arch/x86/include/asm/spinlock.h
18951 +++ b/arch/x86/include/asm/spinlock.h
18952 @@ -222,6 +222,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
18953 static inline void arch_read_lock(arch_rwlock_t *rw)
18954 {
18955 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
18956 +
18957 +#ifdef CONFIG_PAX_REFCOUNT
18958 + "jno 0f\n"
18959 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
18960 + "int $4\n0:\n"
18961 + _ASM_EXTABLE(0b, 0b)
18962 +#endif
18963 +
18964 "jns 1f\n"
18965 "call __read_lock_failed\n\t"
18966 "1:\n"
18967 @@ -231,6 +239,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
18968 static inline void arch_write_lock(arch_rwlock_t *rw)
18969 {
18970 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
18971 +
18972 +#ifdef CONFIG_PAX_REFCOUNT
18973 + "jno 0f\n"
18974 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
18975 + "int $4\n0:\n"
18976 + _ASM_EXTABLE(0b, 0b)
18977 +#endif
18978 +
18979 "jz 1f\n"
18980 "call __write_lock_failed\n\t"
18981 "1:\n"
18982 @@ -260,13 +276,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
18983
18984 static inline void arch_read_unlock(arch_rwlock_t *rw)
18985 {
18986 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
18987 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
18988 +
18989 +#ifdef CONFIG_PAX_REFCOUNT
18990 + "jno 0f\n"
18991 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
18992 + "int $4\n0:\n"
18993 + _ASM_EXTABLE(0b, 0b)
18994 +#endif
18995 +
18996 :"+m" (rw->lock) : : "memory");
18997 }
18998
18999 static inline void arch_write_unlock(arch_rwlock_t *rw)
19000 {
19001 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
19002 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
19003 +
19004 +#ifdef CONFIG_PAX_REFCOUNT
19005 + "jno 0f\n"
19006 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
19007 + "int $4\n0:\n"
19008 + _ASM_EXTABLE(0b, 0b)
19009 +#endif
19010 +
19011 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
19012 }
19013
19014 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
19015 index 6a99859..03cb807 100644
19016 --- a/arch/x86/include/asm/stackprotector.h
19017 +++ b/arch/x86/include/asm/stackprotector.h
19018 @@ -47,7 +47,7 @@
19019 * head_32 for boot CPU and setup_per_cpu_areas() for others.
19020 */
19021 #define GDT_STACK_CANARY_INIT \
19022 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
19023 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
19024
19025 /*
19026 * Initialize the stackprotector canary value.
19027 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
19028
19029 static inline void load_stack_canary_segment(void)
19030 {
19031 -#ifdef CONFIG_X86_32
19032 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
19033 asm volatile ("mov %0, %%gs" : : "r" (0));
19034 #endif
19035 }
19036 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
19037 index 70bbe39..4ae2bd4 100644
19038 --- a/arch/x86/include/asm/stacktrace.h
19039 +++ b/arch/x86/include/asm/stacktrace.h
19040 @@ -11,28 +11,20 @@
19041
19042 extern int kstack_depth_to_print;
19043
19044 -struct thread_info;
19045 +struct task_struct;
19046 struct stacktrace_ops;
19047
19048 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
19049 - unsigned long *stack,
19050 - unsigned long bp,
19051 - const struct stacktrace_ops *ops,
19052 - void *data,
19053 - unsigned long *end,
19054 - int *graph);
19055 +typedef unsigned long walk_stack_t(struct task_struct *task,
19056 + void *stack_start,
19057 + unsigned long *stack,
19058 + unsigned long bp,
19059 + const struct stacktrace_ops *ops,
19060 + void *data,
19061 + unsigned long *end,
19062 + int *graph);
19063
19064 -extern unsigned long
19065 -print_context_stack(struct thread_info *tinfo,
19066 - unsigned long *stack, unsigned long bp,
19067 - const struct stacktrace_ops *ops, void *data,
19068 - unsigned long *end, int *graph);
19069 -
19070 -extern unsigned long
19071 -print_context_stack_bp(struct thread_info *tinfo,
19072 - unsigned long *stack, unsigned long bp,
19073 - const struct stacktrace_ops *ops, void *data,
19074 - unsigned long *end, int *graph);
19075 +extern walk_stack_t print_context_stack;
19076 +extern walk_stack_t print_context_stack_bp;
19077
19078 /* Generic stack tracer with callbacks */
19079
19080 @@ -40,7 +32,7 @@ struct stacktrace_ops {
19081 void (*address)(void *data, unsigned long address, int reliable);
19082 /* On negative return stop dumping */
19083 int (*stack)(void *data, char *name);
19084 - walk_stack_t walk_stack;
19085 + walk_stack_t *walk_stack;
19086 };
19087
19088 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
19089 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
19090 index d7f3b3b..3cc39f1 100644
19091 --- a/arch/x86/include/asm/switch_to.h
19092 +++ b/arch/x86/include/asm/switch_to.h
19093 @@ -108,7 +108,7 @@ do { \
19094 "call __switch_to\n\t" \
19095 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
19096 __switch_canary \
19097 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
19098 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
19099 "movq %%rax,%%rdi\n\t" \
19100 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
19101 "jnz ret_from_fork\n\t" \
19102 @@ -119,7 +119,7 @@ do { \
19103 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
19104 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
19105 [_tif_fork] "i" (_TIF_FORK), \
19106 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
19107 + [thread_info] "m" (current_tinfo), \
19108 [current_task] "m" (current_task) \
19109 __switch_canary_iparam \
19110 : "memory", "cc" __EXTRA_CLOBBER)
19111 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
19112 index 47e5de2..d3dda54 100644
19113 --- a/arch/x86/include/asm/thread_info.h
19114 +++ b/arch/x86/include/asm/thread_info.h
19115 @@ -24,7 +24,6 @@ struct exec_domain;
19116 #include <linux/atomic.h>
19117
19118 struct thread_info {
19119 - struct task_struct *task; /* main task structure */
19120 struct exec_domain *exec_domain; /* execution domain */
19121 __u32 flags; /* low level flags */
19122 __u32 status; /* thread synchronous flags */
19123 @@ -33,13 +32,13 @@ struct thread_info {
19124 mm_segment_t addr_limit;
19125 struct restart_block restart_block;
19126 void __user *sysenter_return;
19127 + unsigned long lowest_stack;
19128 unsigned int sig_on_uaccess_error:1;
19129 unsigned int uaccess_err:1; /* uaccess failed */
19130 };
19131
19132 -#define INIT_THREAD_INFO(tsk) \
19133 +#define INIT_THREAD_INFO \
19134 { \
19135 - .task = &tsk, \
19136 .exec_domain = &default_exec_domain, \
19137 .flags = 0, \
19138 .cpu = 0, \
19139 @@ -50,7 +49,7 @@ struct thread_info {
19140 }, \
19141 }
19142
19143 -#define init_thread_info (init_thread_union.thread_info)
19144 +#define init_thread_info (init_thread_union.stack)
19145 #define init_stack (init_thread_union.stack)
19146
19147 #else /* !__ASSEMBLY__ */
19148 @@ -90,6 +89,7 @@ struct thread_info {
19149 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
19150 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
19151 #define TIF_X32 30 /* 32-bit native x86-64 binary */
19152 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
19153
19154 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
19155 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
19156 @@ -113,17 +113,18 @@ struct thread_info {
19157 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
19158 #define _TIF_ADDR32 (1 << TIF_ADDR32)
19159 #define _TIF_X32 (1 << TIF_X32)
19160 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
19161
19162 /* work to do in syscall_trace_enter() */
19163 #define _TIF_WORK_SYSCALL_ENTRY \
19164 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
19165 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
19166 - _TIF_NOHZ)
19167 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
19168
19169 /* work to do in syscall_trace_leave() */
19170 #define _TIF_WORK_SYSCALL_EXIT \
19171 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
19172 - _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
19173 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
19174
19175 /* work to do on interrupt/exception return */
19176 #define _TIF_WORK_MASK \
19177 @@ -134,7 +135,7 @@ struct thread_info {
19178 /* work to do on any return to user space */
19179 #define _TIF_ALLWORK_MASK \
19180 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
19181 - _TIF_NOHZ)
19182 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
19183
19184 /* Only used for 64 bit */
19185 #define _TIF_DO_NOTIFY_MASK \
19186 @@ -149,7 +150,6 @@ struct thread_info {
19187 #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
19188
19189 #define STACK_WARN (THREAD_SIZE/8)
19190 -#define KERNEL_STACK_OFFSET (5*(BITS_PER_LONG/8))
19191
19192 /*
19193 * macros/functions for gaining access to the thread information structure
19194 @@ -160,26 +160,18 @@ struct thread_info {
19195
19196 DECLARE_PER_CPU(unsigned long, kernel_stack);
19197
19198 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
19199 +
19200 static inline struct thread_info *current_thread_info(void)
19201 {
19202 - struct thread_info *ti;
19203 - ti = (void *)(this_cpu_read_stable(kernel_stack) +
19204 - KERNEL_STACK_OFFSET - THREAD_SIZE);
19205 - return ti;
19206 + return this_cpu_read_stable(current_tinfo);
19207 }
19208
19209 #else /* !__ASSEMBLY__ */
19210
19211 /* how to get the thread information struct from ASM */
19212 #define GET_THREAD_INFO(reg) \
19213 - _ASM_MOV PER_CPU_VAR(kernel_stack),reg ; \
19214 - _ASM_SUB $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg ;
19215 -
19216 -/*
19217 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
19218 - * a certain register (to be used in assembler memory operands).
19219 - */
19220 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
19221 + _ASM_MOV PER_CPU_VAR(current_tinfo),reg ;
19222
19223 #endif
19224
19225 @@ -237,5 +229,12 @@ static inline bool is_ia32_task(void)
19226 extern void arch_task_cache_init(void);
19227 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
19228 extern void arch_release_task_struct(struct task_struct *tsk);
19229 +
19230 +#define __HAVE_THREAD_FUNCTIONS
19231 +#define task_thread_info(task) (&(task)->tinfo)
19232 +#define task_stack_page(task) ((task)->stack)
19233 +#define setup_thread_stack(p, org) do {} while (0)
19234 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
19235 +
19236 #endif
19237 #endif /* _ASM_X86_THREAD_INFO_H */
19238 diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
19239 index 04905bf..49203ca 100644
19240 --- a/arch/x86/include/asm/tlbflush.h
19241 +++ b/arch/x86/include/asm/tlbflush.h
19242 @@ -17,18 +17,44 @@
19243
19244 static inline void __native_flush_tlb(void)
19245 {
19246 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19247 + u64 descriptor[2];
19248 +
19249 + descriptor[0] = PCID_KERNEL;
19250 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_MONGLOBAL) : "memory");
19251 + return;
19252 + }
19253 +
19254 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19255 + if (static_cpu_has(X86_FEATURE_PCID)) {
19256 + unsigned int cpu = raw_get_cpu();
19257 +
19258 + native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
19259 + native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
19260 + raw_put_cpu_no_resched();
19261 + return;
19262 + }
19263 +#endif
19264 +
19265 native_write_cr3(native_read_cr3());
19266 }
19267
19268 static inline void __native_flush_tlb_global_irq_disabled(void)
19269 {
19270 - unsigned long cr4;
19271 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19272 + u64 descriptor[2];
19273
19274 - cr4 = native_read_cr4();
19275 - /* clear PGE */
19276 - native_write_cr4(cr4 & ~X86_CR4_PGE);
19277 - /* write old PGE again and flush TLBs */
19278 - native_write_cr4(cr4);
19279 + descriptor[0] = PCID_KERNEL;
19280 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
19281 + } else {
19282 + unsigned long cr4;
19283 +
19284 + cr4 = native_read_cr4();
19285 + /* clear PGE */
19286 + native_write_cr4(cr4 & ~X86_CR4_PGE);
19287 + /* write old PGE again and flush TLBs */
19288 + native_write_cr4(cr4);
19289 + }
19290 }
19291
19292 static inline void __native_flush_tlb_global(void)
19293 @@ -49,6 +75,41 @@ static inline void __native_flush_tlb_global(void)
19294
19295 static inline void __native_flush_tlb_single(unsigned long addr)
19296 {
19297 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
19298 + u64 descriptor[2];
19299 +
19300 + descriptor[0] = PCID_KERNEL;
19301 + descriptor[1] = addr;
19302 +
19303 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19304 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
19305 + if (addr < TASK_SIZE_MAX)
19306 + descriptor[1] += pax_user_shadow_base;
19307 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19308 + }
19309 +
19310 + descriptor[0] = PCID_USER;
19311 + descriptor[1] = addr;
19312 +#endif
19313 +
19314 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
19315 + return;
19316 + }
19317 +
19318 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19319 + if (static_cpu_has(X86_FEATURE_PCID)) {
19320 + unsigned int cpu = raw_get_cpu();
19321 +
19322 + native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
19323 + asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19324 + native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
19325 + raw_put_cpu_no_resched();
19326 +
19327 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
19328 + addr += pax_user_shadow_base;
19329 + }
19330 +#endif
19331 +
19332 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
19333 }
19334
19335 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
19336 index 0d592e0..7437fcc 100644
19337 --- a/arch/x86/include/asm/uaccess.h
19338 +++ b/arch/x86/include/asm/uaccess.h
19339 @@ -7,6 +7,7 @@
19340 #include <linux/compiler.h>
19341 #include <linux/thread_info.h>
19342 #include <linux/string.h>
19343 +#include <linux/spinlock.h>
19344 #include <asm/asm.h>
19345 #include <asm/page.h>
19346 #include <asm/smap.h>
19347 @@ -29,7 +30,12 @@
19348
19349 #define get_ds() (KERNEL_DS)
19350 #define get_fs() (current_thread_info()->addr_limit)
19351 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19352 +void __set_fs(mm_segment_t x);
19353 +void set_fs(mm_segment_t x);
19354 +#else
19355 #define set_fs(x) (current_thread_info()->addr_limit = (x))
19356 +#endif
19357
19358 #define segment_eq(a, b) ((a).seg == (b).seg)
19359
19360 @@ -85,8 +91,36 @@ static inline bool __chk_range_not_ok(unsigned long addr, unsigned long size, un
19361 * checks that the pointer is in the user space range - after calling
19362 * this function, memory access functions may still return -EFAULT.
19363 */
19364 -#define access_ok(type, addr, size) \
19365 - likely(!__range_not_ok(addr, size, user_addr_max()))
19366 +extern int _cond_resched(void);
19367 +#define access_ok_noprefault(type, addr, size) (likely(!__range_not_ok(addr, size, user_addr_max())))
19368 +#define access_ok(type, addr, size) \
19369 +({ \
19370 + unsigned long __size = size; \
19371 + unsigned long __addr = (unsigned long)addr; \
19372 + bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
19373 + if (__ret_ao && __size) { \
19374 + unsigned long __addr_ao = __addr & PAGE_MASK; \
19375 + unsigned long __end_ao = __addr + __size - 1; \
19376 + if (unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
19377 + while (__addr_ao <= __end_ao) { \
19378 + char __c_ao; \
19379 + __addr_ao += PAGE_SIZE; \
19380 + if (__size > PAGE_SIZE) \
19381 + _cond_resched(); \
19382 + if (__get_user(__c_ao, (char __user *)__addr)) \
19383 + break; \
19384 + if (type != VERIFY_WRITE) { \
19385 + __addr = __addr_ao; \
19386 + continue; \
19387 + } \
19388 + if (__put_user(__c_ao, (char __user *)__addr)) \
19389 + break; \
19390 + __addr = __addr_ao; \
19391 + } \
19392 + } \
19393 + } \
19394 + __ret_ao; \
19395 +})
19396
19397 /*
19398 * The exception table consists of pairs of addresses relative to the
19399 @@ -176,10 +210,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19400 register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \
19401 __chk_user_ptr(ptr); \
19402 might_fault(); \
19403 + pax_open_userland(); \
19404 asm volatile("call __get_user_%P3" \
19405 : "=a" (__ret_gu), "=r" (__val_gu) \
19406 : "0" (ptr), "i" (sizeof(*(ptr)))); \
19407 (x) = (__typeof__(*(ptr))) __val_gu; \
19408 + pax_close_userland(); \
19409 __ret_gu; \
19410 })
19411
19412 @@ -187,13 +223,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19413 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
19414 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
19415
19416 -
19417 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
19418 +#define __copyuser_seg "gs;"
19419 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
19420 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
19421 +#else
19422 +#define __copyuser_seg
19423 +#define __COPYUSER_SET_ES
19424 +#define __COPYUSER_RESTORE_ES
19425 +#endif
19426
19427 #ifdef CONFIG_X86_32
19428 #define __put_user_asm_u64(x, addr, err, errret) \
19429 asm volatile(ASM_STAC "\n" \
19430 - "1: movl %%eax,0(%2)\n" \
19431 - "2: movl %%edx,4(%2)\n" \
19432 + "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
19433 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
19434 "3: " ASM_CLAC "\n" \
19435 ".section .fixup,\"ax\"\n" \
19436 "4: movl %3,%0\n" \
19437 @@ -206,8 +250,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
19438
19439 #define __put_user_asm_ex_u64(x, addr) \
19440 asm volatile(ASM_STAC "\n" \
19441 - "1: movl %%eax,0(%1)\n" \
19442 - "2: movl %%edx,4(%1)\n" \
19443 + "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
19444 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
19445 "3: " ASM_CLAC "\n" \
19446 _ASM_EXTABLE_EX(1b, 2b) \
19447 _ASM_EXTABLE_EX(2b, 3b) \
19448 @@ -257,7 +301,8 @@ extern void __put_user_8(void);
19449 __typeof__(*(ptr)) __pu_val; \
19450 __chk_user_ptr(ptr); \
19451 might_fault(); \
19452 - __pu_val = x; \
19453 + __pu_val = (x); \
19454 + pax_open_userland(); \
19455 switch (sizeof(*(ptr))) { \
19456 case 1: \
19457 __put_user_x(1, __pu_val, ptr, __ret_pu); \
19458 @@ -275,6 +320,7 @@ extern void __put_user_8(void);
19459 __put_user_x(X, __pu_val, ptr, __ret_pu); \
19460 break; \
19461 } \
19462 + pax_close_userland(); \
19463 __ret_pu; \
19464 })
19465
19466 @@ -355,8 +401,10 @@ do { \
19467 } while (0)
19468
19469 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19470 +do { \
19471 + pax_open_userland(); \
19472 asm volatile(ASM_STAC "\n" \
19473 - "1: mov"itype" %2,%"rtype"1\n" \
19474 + "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
19475 "2: " ASM_CLAC "\n" \
19476 ".section .fixup,\"ax\"\n" \
19477 "3: mov %3,%0\n" \
19478 @@ -364,8 +412,10 @@ do { \
19479 " jmp 2b\n" \
19480 ".previous\n" \
19481 _ASM_EXTABLE(1b, 3b) \
19482 - : "=r" (err), ltype(x) \
19483 - : "m" (__m(addr)), "i" (errret), "0" (err))
19484 + : "=r" (err), ltype (x) \
19485 + : "m" (__m(addr)), "i" (errret), "0" (err)); \
19486 + pax_close_userland(); \
19487 +} while (0)
19488
19489 #define __get_user_size_ex(x, ptr, size) \
19490 do { \
19491 @@ -389,7 +439,7 @@ do { \
19492 } while (0)
19493
19494 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
19495 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
19496 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
19497 "2:\n" \
19498 _ASM_EXTABLE_EX(1b, 2b) \
19499 : ltype(x) : "m" (__m(addr)))
19500 @@ -406,13 +456,24 @@ do { \
19501 int __gu_err; \
19502 unsigned long __gu_val; \
19503 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
19504 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
19505 + (x) = (__typeof__(*(ptr)))__gu_val; \
19506 __gu_err; \
19507 })
19508
19509 /* FIXME: this hack is definitely wrong -AK */
19510 struct __large_struct { unsigned long buf[100]; };
19511 -#define __m(x) (*(struct __large_struct __user *)(x))
19512 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19513 +#define ____m(x) \
19514 +({ \
19515 + unsigned long ____x = (unsigned long)(x); \
19516 + if (____x < pax_user_shadow_base) \
19517 + ____x += pax_user_shadow_base; \
19518 + (typeof(x))____x; \
19519 +})
19520 +#else
19521 +#define ____m(x) (x)
19522 +#endif
19523 +#define __m(x) (*(struct __large_struct __user *)____m(x))
19524
19525 /*
19526 * Tell gcc we read from memory instead of writing: this is because
19527 @@ -420,8 +481,10 @@ struct __large_struct { unsigned long buf[100]; };
19528 * aliasing issues.
19529 */
19530 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
19531 +do { \
19532 + pax_open_userland(); \
19533 asm volatile(ASM_STAC "\n" \
19534 - "1: mov"itype" %"rtype"1,%2\n" \
19535 + "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
19536 "2: " ASM_CLAC "\n" \
19537 ".section .fixup,\"ax\"\n" \
19538 "3: mov %3,%0\n" \
19539 @@ -429,10 +492,12 @@ struct __large_struct { unsigned long buf[100]; };
19540 ".previous\n" \
19541 _ASM_EXTABLE(1b, 3b) \
19542 : "=r"(err) \
19543 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
19544 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
19545 + pax_close_userland(); \
19546 +} while (0)
19547
19548 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
19549 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
19550 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
19551 "2:\n" \
19552 _ASM_EXTABLE_EX(1b, 2b) \
19553 : : ltype(x), "m" (__m(addr)))
19554 @@ -442,11 +507,13 @@ struct __large_struct { unsigned long buf[100]; };
19555 */
19556 #define uaccess_try do { \
19557 current_thread_info()->uaccess_err = 0; \
19558 + pax_open_userland(); \
19559 stac(); \
19560 barrier();
19561
19562 #define uaccess_catch(err) \
19563 clac(); \
19564 + pax_close_userland(); \
19565 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
19566 } while (0)
19567
19568 @@ -471,8 +538,12 @@ struct __large_struct { unsigned long buf[100]; };
19569 * On error, the variable @x is set to zero.
19570 */
19571
19572 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19573 +#define __get_user(x, ptr) get_user((x), (ptr))
19574 +#else
19575 #define __get_user(x, ptr) \
19576 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
19577 +#endif
19578
19579 /**
19580 * __put_user: - Write a simple value into user space, with less checking.
19581 @@ -494,8 +565,12 @@ struct __large_struct { unsigned long buf[100]; };
19582 * Returns zero on success, or -EFAULT on error.
19583 */
19584
19585 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19586 +#define __put_user(x, ptr) put_user((x), (ptr))
19587 +#else
19588 #define __put_user(x, ptr) \
19589 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
19590 +#endif
19591
19592 #define __get_user_unaligned __get_user
19593 #define __put_user_unaligned __put_user
19594 @@ -513,7 +588,7 @@ struct __large_struct { unsigned long buf[100]; };
19595 #define get_user_ex(x, ptr) do { \
19596 unsigned long __gue_val; \
19597 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
19598 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
19599 + (x) = (__typeof__(*(ptr)))__gue_val; \
19600 } while (0)
19601
19602 #define put_user_try uaccess_try
19603 @@ -542,18 +617,19 @@ extern void __cmpxchg_wrong_size(void)
19604 __typeof__(ptr) __uval = (uval); \
19605 __typeof__(*(ptr)) __old = (old); \
19606 __typeof__(*(ptr)) __new = (new); \
19607 + pax_open_userland(); \
19608 switch (size) { \
19609 case 1: \
19610 { \
19611 asm volatile("\t" ASM_STAC "\n" \
19612 - "1:\t" LOCK_PREFIX "cmpxchgb %4, %2\n" \
19613 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgb %4, %2\n"\
19614 "2:\t" ASM_CLAC "\n" \
19615 "\t.section .fixup, \"ax\"\n" \
19616 "3:\tmov %3, %0\n" \
19617 "\tjmp 2b\n" \
19618 "\t.previous\n" \
19619 _ASM_EXTABLE(1b, 3b) \
19620 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19621 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19622 : "i" (-EFAULT), "q" (__new), "1" (__old) \
19623 : "memory" \
19624 ); \
19625 @@ -562,14 +638,14 @@ extern void __cmpxchg_wrong_size(void)
19626 case 2: \
19627 { \
19628 asm volatile("\t" ASM_STAC "\n" \
19629 - "1:\t" LOCK_PREFIX "cmpxchgw %4, %2\n" \
19630 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgw %4, %2\n"\
19631 "2:\t" ASM_CLAC "\n" \
19632 "\t.section .fixup, \"ax\"\n" \
19633 "3:\tmov %3, %0\n" \
19634 "\tjmp 2b\n" \
19635 "\t.previous\n" \
19636 _ASM_EXTABLE(1b, 3b) \
19637 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19638 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19639 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19640 : "memory" \
19641 ); \
19642 @@ -578,14 +654,14 @@ extern void __cmpxchg_wrong_size(void)
19643 case 4: \
19644 { \
19645 asm volatile("\t" ASM_STAC "\n" \
19646 - "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n" \
19647 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"\
19648 "2:\t" ASM_CLAC "\n" \
19649 "\t.section .fixup, \"ax\"\n" \
19650 "3:\tmov %3, %0\n" \
19651 "\tjmp 2b\n" \
19652 "\t.previous\n" \
19653 _ASM_EXTABLE(1b, 3b) \
19654 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19655 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19656 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19657 : "memory" \
19658 ); \
19659 @@ -597,14 +673,14 @@ extern void __cmpxchg_wrong_size(void)
19660 __cmpxchg_wrong_size(); \
19661 \
19662 asm volatile("\t" ASM_STAC "\n" \
19663 - "1:\t" LOCK_PREFIX "cmpxchgq %4, %2\n" \
19664 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgq %4, %2\n"\
19665 "2:\t" ASM_CLAC "\n" \
19666 "\t.section .fixup, \"ax\"\n" \
19667 "3:\tmov %3, %0\n" \
19668 "\tjmp 2b\n" \
19669 "\t.previous\n" \
19670 _ASM_EXTABLE(1b, 3b) \
19671 - : "+r" (__ret), "=a" (__old), "+m" (*(ptr)) \
19672 + : "+r" (__ret), "=a" (__old), "+m" (*____m(ptr))\
19673 : "i" (-EFAULT), "r" (__new), "1" (__old) \
19674 : "memory" \
19675 ); \
19676 @@ -613,6 +689,7 @@ extern void __cmpxchg_wrong_size(void)
19677 default: \
19678 __cmpxchg_wrong_size(); \
19679 } \
19680 + pax_close_userland(); \
19681 *__uval = __old; \
19682 __ret; \
19683 })
19684 @@ -636,17 +713,6 @@ extern struct movsl_mask {
19685
19686 #define ARCH_HAS_NOCACHE_UACCESS 1
19687
19688 -#ifdef CONFIG_X86_32
19689 -# include <asm/uaccess_32.h>
19690 -#else
19691 -# include <asm/uaccess_64.h>
19692 -#endif
19693 -
19694 -unsigned long __must_check _copy_from_user(void *to, const void __user *from,
19695 - unsigned n);
19696 -unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19697 - unsigned n);
19698 -
19699 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
19700 # define copy_user_diag __compiletime_error
19701 #else
19702 @@ -656,7 +722,7 @@ unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19703 extern void copy_user_diag("copy_from_user() buffer size is too small")
19704 copy_from_user_overflow(void);
19705 extern void copy_user_diag("copy_to_user() buffer size is too small")
19706 -copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19707 +copy_to_user_overflow(void);
19708
19709 #undef copy_user_diag
19710
19711 @@ -669,7 +735,7 @@ __copy_from_user_overflow(void) __asm__("copy_from_user_overflow");
19712
19713 extern void
19714 __compiletime_warning("copy_to_user() buffer size is not provably correct")
19715 -__copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19716 +__copy_to_user_overflow(void) __asm__("copy_to_user_overflow");
19717 #define __copy_to_user_overflow(size, count) __copy_to_user_overflow()
19718
19719 #else
19720 @@ -684,10 +750,16 @@ __copy_from_user_overflow(int size, unsigned long count)
19721
19722 #endif
19723
19724 +#ifdef CONFIG_X86_32
19725 +# include <asm/uaccess_32.h>
19726 +#else
19727 +# include <asm/uaccess_64.h>
19728 +#endif
19729 +
19730 static inline unsigned long __must_check
19731 copy_from_user(void *to, const void __user *from, unsigned long n)
19732 {
19733 - int sz = __compiletime_object_size(to);
19734 + size_t sz = __compiletime_object_size(to);
19735
19736 might_fault();
19737
19738 @@ -709,12 +781,15 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19739 * case, and do only runtime checking for non-constant sizes.
19740 */
19741
19742 - if (likely(sz < 0 || sz >= n))
19743 - n = _copy_from_user(to, from, n);
19744 - else if(__builtin_constant_p(n))
19745 - copy_from_user_overflow();
19746 - else
19747 - __copy_from_user_overflow(sz, n);
19748 + if (likely(sz != (size_t)-1 && sz < n)) {
19749 + if(__builtin_constant_p(n))
19750 + copy_from_user_overflow();
19751 + else
19752 + __copy_from_user_overflow(sz, n);
19753 + } if (access_ok(VERIFY_READ, from, n))
19754 + n = __copy_from_user(to, from, n);
19755 + else if ((long)n > 0)
19756 + memset(to, 0, n);
19757
19758 return n;
19759 }
19760 @@ -722,17 +797,18 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19761 static inline unsigned long __must_check
19762 copy_to_user(void __user *to, const void *from, unsigned long n)
19763 {
19764 - int sz = __compiletime_object_size(from);
19765 + size_t sz = __compiletime_object_size(from);
19766
19767 might_fault();
19768
19769 /* See the comment in copy_from_user() above. */
19770 - if (likely(sz < 0 || sz >= n))
19771 - n = _copy_to_user(to, from, n);
19772 - else if(__builtin_constant_p(n))
19773 - copy_to_user_overflow();
19774 - else
19775 - __copy_to_user_overflow(sz, n);
19776 + if (likely(sz != (size_t)-1 && sz < n)) {
19777 + if(__builtin_constant_p(n))
19778 + copy_to_user_overflow();
19779 + else
19780 + __copy_to_user_overflow(sz, n);
19781 + } else if (access_ok(VERIFY_WRITE, to, n))
19782 + n = __copy_to_user(to, from, n);
19783
19784 return n;
19785 }
19786 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
19787 index 3c03a5d..1071638 100644
19788 --- a/arch/x86/include/asm/uaccess_32.h
19789 +++ b/arch/x86/include/asm/uaccess_32.h
19790 @@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
19791 static __always_inline unsigned long __must_check
19792 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
19793 {
19794 + if ((long)n < 0)
19795 + return n;
19796 +
19797 + check_object_size(from, n, true);
19798 +
19799 if (__builtin_constant_p(n)) {
19800 unsigned long ret;
19801
19802 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
19803 __copy_to_user(void __user *to, const void *from, unsigned long n)
19804 {
19805 might_fault();
19806 +
19807 return __copy_to_user_inatomic(to, from, n);
19808 }
19809
19810 static __always_inline unsigned long
19811 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
19812 {
19813 + if ((long)n < 0)
19814 + return n;
19815 +
19816 /* Avoid zeroing the tail if the copy fails..
19817 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
19818 * but as the zeroing behaviour is only significant when n is not
19819 @@ -137,6 +146,12 @@ static __always_inline unsigned long
19820 __copy_from_user(void *to, const void __user *from, unsigned long n)
19821 {
19822 might_fault();
19823 +
19824 + if ((long)n < 0)
19825 + return n;
19826 +
19827 + check_object_size(to, n, false);
19828 +
19829 if (__builtin_constant_p(n)) {
19830 unsigned long ret;
19831
19832 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
19833 const void __user *from, unsigned long n)
19834 {
19835 might_fault();
19836 +
19837 + if ((long)n < 0)
19838 + return n;
19839 +
19840 if (__builtin_constant_p(n)) {
19841 unsigned long ret;
19842
19843 @@ -181,7 +200,10 @@ static __always_inline unsigned long
19844 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
19845 unsigned long n)
19846 {
19847 - return __copy_from_user_ll_nocache_nozero(to, from, n);
19848 + if ((long)n < 0)
19849 + return n;
19850 +
19851 + return __copy_from_user_ll_nocache_nozero(to, from, n);
19852 }
19853
19854 #endif /* _ASM_X86_UACCESS_32_H */
19855 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
19856 index 12a26b9..206c200 100644
19857 --- a/arch/x86/include/asm/uaccess_64.h
19858 +++ b/arch/x86/include/asm/uaccess_64.h
19859 @@ -10,6 +10,9 @@
19860 #include <asm/alternative.h>
19861 #include <asm/cpufeature.h>
19862 #include <asm/page.h>
19863 +#include <asm/pgtable.h>
19864 +
19865 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
19866
19867 /*
19868 * Copy To/From Userspace
19869 @@ -17,14 +20,14 @@
19870
19871 /* Handles exceptions in both to and from, but doesn't do access_ok */
19872 __must_check unsigned long
19873 -copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
19874 +copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
19875 __must_check unsigned long
19876 -copy_user_generic_string(void *to, const void *from, unsigned len);
19877 +copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
19878 __must_check unsigned long
19879 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
19880 +copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
19881
19882 static __always_inline __must_check unsigned long
19883 -copy_user_generic(void *to, const void *from, unsigned len)
19884 +copy_user_generic(void *to, const void *from, unsigned long len)
19885 {
19886 unsigned ret;
19887
19888 @@ -46,121 +49,170 @@ copy_user_generic(void *to, const void *from, unsigned len)
19889 }
19890
19891 __must_check unsigned long
19892 -copy_in_user(void __user *to, const void __user *from, unsigned len);
19893 +copy_in_user(void __user *to, const void __user *from, unsigned long len);
19894
19895 static __always_inline __must_check
19896 -int __copy_from_user_nocheck(void *dst, const void __user *src, unsigned size)
19897 +unsigned long __copy_from_user_nocheck(void *dst, const void __user *src, unsigned long size)
19898 {
19899 - int ret = 0;
19900 + size_t sz = __compiletime_object_size(dst);
19901 + unsigned ret = 0;
19902 +
19903 + if (size > INT_MAX)
19904 + return size;
19905 +
19906 + check_object_size(dst, size, false);
19907 +
19908 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19909 + if (!access_ok_noprefault(VERIFY_READ, src, size))
19910 + return size;
19911 +#endif
19912 +
19913 + if (unlikely(sz != (size_t)-1 && sz < size)) {
19914 + if(__builtin_constant_p(size))
19915 + copy_from_user_overflow();
19916 + else
19917 + __copy_from_user_overflow(sz, size);
19918 + return size;
19919 + }
19920
19921 if (!__builtin_constant_p(size))
19922 - return copy_user_generic(dst, (__force void *)src, size);
19923 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
19924 switch (size) {
19925 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
19926 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
19927 ret, "b", "b", "=q", 1);
19928 return ret;
19929 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
19930 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
19931 ret, "w", "w", "=r", 2);
19932 return ret;
19933 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
19934 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
19935 ret, "l", "k", "=r", 4);
19936 return ret;
19937 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
19938 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19939 ret, "q", "", "=r", 8);
19940 return ret;
19941 case 10:
19942 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
19943 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19944 ret, "q", "", "=r", 10);
19945 if (unlikely(ret))
19946 return ret;
19947 __get_user_asm(*(u16 *)(8 + (char *)dst),
19948 - (u16 __user *)(8 + (char __user *)src),
19949 + (const u16 __user *)(8 + (const char __user *)src),
19950 ret, "w", "w", "=r", 2);
19951 return ret;
19952 case 16:
19953 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
19954 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19955 ret, "q", "", "=r", 16);
19956 if (unlikely(ret))
19957 return ret;
19958 __get_user_asm(*(u64 *)(8 + (char *)dst),
19959 - (u64 __user *)(8 + (char __user *)src),
19960 + (const u64 __user *)(8 + (const char __user *)src),
19961 ret, "q", "", "=r", 8);
19962 return ret;
19963 default:
19964 - return copy_user_generic(dst, (__force void *)src, size);
19965 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
19966 }
19967 }
19968
19969 static __always_inline __must_check
19970 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
19971 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
19972 {
19973 might_fault();
19974 return __copy_from_user_nocheck(dst, src, size);
19975 }
19976
19977 static __always_inline __must_check
19978 -int __copy_to_user_nocheck(void __user *dst, const void *src, unsigned size)
19979 +unsigned long __copy_to_user_nocheck(void __user *dst, const void *src, unsigned long size)
19980 {
19981 - int ret = 0;
19982 + size_t sz = __compiletime_object_size(src);
19983 + unsigned ret = 0;
19984 +
19985 + if (size > INT_MAX)
19986 + return size;
19987 +
19988 + check_object_size(src, size, true);
19989 +
19990 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19991 + if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
19992 + return size;
19993 +#endif
19994 +
19995 + if (unlikely(sz != (size_t)-1 && sz < size)) {
19996 + if(__builtin_constant_p(size))
19997 + copy_to_user_overflow();
19998 + else
19999 + __copy_to_user_overflow(sz, size);
20000 + return size;
20001 + }
20002
20003 if (!__builtin_constant_p(size))
20004 - return copy_user_generic((__force void *)dst, src, size);
20005 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
20006 switch (size) {
20007 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
20008 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
20009 ret, "b", "b", "iq", 1);
20010 return ret;
20011 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
20012 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
20013 ret, "w", "w", "ir", 2);
20014 return ret;
20015 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
20016 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
20017 ret, "l", "k", "ir", 4);
20018 return ret;
20019 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
20020 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20021 ret, "q", "", "er", 8);
20022 return ret;
20023 case 10:
20024 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
20025 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20026 ret, "q", "", "er", 10);
20027 if (unlikely(ret))
20028 return ret;
20029 asm("":::"memory");
20030 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
20031 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
20032 ret, "w", "w", "ir", 2);
20033 return ret;
20034 case 16:
20035 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
20036 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
20037 ret, "q", "", "er", 16);
20038 if (unlikely(ret))
20039 return ret;
20040 asm("":::"memory");
20041 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
20042 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
20043 ret, "q", "", "er", 8);
20044 return ret;
20045 default:
20046 - return copy_user_generic((__force void *)dst, src, size);
20047 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
20048 }
20049 }
20050
20051 static __always_inline __must_check
20052 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
20053 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
20054 {
20055 might_fault();
20056 return __copy_to_user_nocheck(dst, src, size);
20057 }
20058
20059 static __always_inline __must_check
20060 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20061 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20062 {
20063 - int ret = 0;
20064 + unsigned ret = 0;
20065
20066 might_fault();
20067 +
20068 + if (size > INT_MAX)
20069 + return size;
20070 +
20071 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20072 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20073 + return size;
20074 + if (!access_ok_noprefault(VERIFY_WRITE, dst, size))
20075 + return size;
20076 +#endif
20077 +
20078 if (!__builtin_constant_p(size))
20079 - return copy_user_generic((__force void *)dst,
20080 - (__force void *)src, size);
20081 + return copy_user_generic((__force_kernel void *)____m(dst),
20082 + (__force_kernel const void *)____m(src), size);
20083 switch (size) {
20084 case 1: {
20085 u8 tmp;
20086 - __get_user_asm(tmp, (u8 __user *)src,
20087 + __get_user_asm(tmp, (const u8 __user *)src,
20088 ret, "b", "b", "=q", 1);
20089 if (likely(!ret))
20090 __put_user_asm(tmp, (u8 __user *)dst,
20091 @@ -169,7 +221,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20092 }
20093 case 2: {
20094 u16 tmp;
20095 - __get_user_asm(tmp, (u16 __user *)src,
20096 + __get_user_asm(tmp, (const u16 __user *)src,
20097 ret, "w", "w", "=r", 2);
20098 if (likely(!ret))
20099 __put_user_asm(tmp, (u16 __user *)dst,
20100 @@ -179,7 +231,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20101
20102 case 4: {
20103 u32 tmp;
20104 - __get_user_asm(tmp, (u32 __user *)src,
20105 + __get_user_asm(tmp, (const u32 __user *)src,
20106 ret, "l", "k", "=r", 4);
20107 if (likely(!ret))
20108 __put_user_asm(tmp, (u32 __user *)dst,
20109 @@ -188,7 +240,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20110 }
20111 case 8: {
20112 u64 tmp;
20113 - __get_user_asm(tmp, (u64 __user *)src,
20114 + __get_user_asm(tmp, (const u64 __user *)src,
20115 ret, "q", "", "=r", 8);
20116 if (likely(!ret))
20117 __put_user_asm(tmp, (u64 __user *)dst,
20118 @@ -196,41 +248,58 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
20119 return ret;
20120 }
20121 default:
20122 - return copy_user_generic((__force void *)dst,
20123 - (__force void *)src, size);
20124 + return copy_user_generic((__force_kernel void *)____m(dst),
20125 + (__force_kernel const void *)____m(src), size);
20126 }
20127 }
20128
20129 -static __must_check __always_inline int
20130 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
20131 +static __must_check __always_inline unsigned long
20132 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
20133 {
20134 return __copy_from_user_nocheck(dst, src, size);
20135 }
20136
20137 -static __must_check __always_inline int
20138 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
20139 +static __must_check __always_inline unsigned long
20140 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
20141 {
20142 return __copy_to_user_nocheck(dst, src, size);
20143 }
20144
20145 -extern long __copy_user_nocache(void *dst, const void __user *src,
20146 - unsigned size, int zerorest);
20147 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
20148 + unsigned long size, int zerorest);
20149
20150 -static inline int
20151 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
20152 +static inline unsigned long
20153 +__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
20154 {
20155 might_fault();
20156 +
20157 + if (size > INT_MAX)
20158 + return size;
20159 +
20160 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20161 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20162 + return size;
20163 +#endif
20164 +
20165 return __copy_user_nocache(dst, src, size, 1);
20166 }
20167
20168 -static inline int
20169 +static inline unsigned long
20170 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
20171 - unsigned size)
20172 + unsigned long size)
20173 {
20174 + if (size > INT_MAX)
20175 + return size;
20176 +
20177 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20178 + if (!access_ok_noprefault(VERIFY_READ, src, size))
20179 + return size;
20180 +#endif
20181 +
20182 return __copy_user_nocache(dst, src, size, 0);
20183 }
20184
20185 unsigned long
20186 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
20187 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
20188
20189 #endif /* _ASM_X86_UACCESS_64_H */
20190 diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
20191 index 5b238981..77fdd78 100644
20192 --- a/arch/x86/include/asm/word-at-a-time.h
20193 +++ b/arch/x86/include/asm/word-at-a-time.h
20194 @@ -11,7 +11,7 @@
20195 * and shift, for example.
20196 */
20197 struct word_at_a_time {
20198 - const unsigned long one_bits, high_bits;
20199 + unsigned long one_bits, high_bits;
20200 };
20201
20202 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
20203 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
20204 index e45e4da..44e8572 100644
20205 --- a/arch/x86/include/asm/x86_init.h
20206 +++ b/arch/x86/include/asm/x86_init.h
20207 @@ -129,7 +129,7 @@ struct x86_init_ops {
20208 struct x86_init_timers timers;
20209 struct x86_init_iommu iommu;
20210 struct x86_init_pci pci;
20211 -};
20212 +} __no_const;
20213
20214 /**
20215 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
20216 @@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
20217 void (*setup_percpu_clockev)(void);
20218 void (*early_percpu_clock_init)(void);
20219 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
20220 -};
20221 +} __no_const;
20222
20223 struct timespec;
20224
20225 @@ -168,7 +168,7 @@ struct x86_platform_ops {
20226 void (*save_sched_clock_state)(void);
20227 void (*restore_sched_clock_state)(void);
20228 void (*apic_post_init)(void);
20229 -};
20230 +} __no_const;
20231
20232 struct pci_dev;
20233 struct msi_msg;
20234 @@ -185,7 +185,7 @@ struct x86_msi_ops {
20235 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
20236 u32 (*msi_mask_irq)(struct msi_desc *desc, u32 mask, u32 flag);
20237 u32 (*msix_mask_irq)(struct msi_desc *desc, u32 flag);
20238 -};
20239 +} __no_const;
20240
20241 struct IO_APIC_route_entry;
20242 struct io_apic_irq_attr;
20243 @@ -206,7 +206,7 @@ struct x86_io_apic_ops {
20244 unsigned int destination, int vector,
20245 struct io_apic_irq_attr *attr);
20246 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
20247 -};
20248 +} __no_const;
20249
20250 extern struct x86_init_ops x86_init;
20251 extern struct x86_cpuinit_ops x86_cpuinit;
20252 diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
20253 index c949923..c22bfa4 100644
20254 --- a/arch/x86/include/asm/xen/page.h
20255 +++ b/arch/x86/include/asm/xen/page.h
20256 @@ -63,7 +63,7 @@ extern int m2p_remove_override(struct page *page,
20257 extern struct page *m2p_find_override(unsigned long mfn);
20258 extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
20259
20260 -static inline unsigned long pfn_to_mfn(unsigned long pfn)
20261 +static inline unsigned long __intentional_overflow(-1) pfn_to_mfn(unsigned long pfn)
20262 {
20263 unsigned long mfn;
20264
20265 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
20266 index d949ef2..479b9d1 100644
20267 --- a/arch/x86/include/asm/xsave.h
20268 +++ b/arch/x86/include/asm/xsave.h
20269 @@ -82,8 +82,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20270 if (unlikely(err))
20271 return -EFAULT;
20272
20273 + pax_open_userland();
20274 __asm__ __volatile__(ASM_STAC "\n"
20275 - "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
20276 + "1:"
20277 + __copyuser_seg
20278 + ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
20279 "2: " ASM_CLAC "\n"
20280 ".section .fixup,\"ax\"\n"
20281 "3: movl $-1,%[err]\n"
20282 @@ -93,18 +96,22 @@ static inline int xsave_user(struct xsave_struct __user *buf)
20283 : [err] "=r" (err)
20284 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
20285 : "memory");
20286 + pax_close_userland();
20287 return err;
20288 }
20289
20290 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20291 {
20292 int err;
20293 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
20294 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
20295 u32 lmask = mask;
20296 u32 hmask = mask >> 32;
20297
20298 + pax_open_userland();
20299 __asm__ __volatile__(ASM_STAC "\n"
20300 - "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20301 + "1:"
20302 + __copyuser_seg
20303 + ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
20304 "2: " ASM_CLAC "\n"
20305 ".section .fixup,\"ax\"\n"
20306 "3: movl $-1,%[err]\n"
20307 @@ -114,6 +121,7 @@ static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
20308 : [err] "=r" (err)
20309 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
20310 : "memory"); /* memory required? */
20311 + pax_close_userland();
20312 return err;
20313 }
20314
20315 diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
20316 index bbae024..e1528f9 100644
20317 --- a/arch/x86/include/uapi/asm/e820.h
20318 +++ b/arch/x86/include/uapi/asm/e820.h
20319 @@ -63,7 +63,7 @@ struct e820map {
20320 #define ISA_START_ADDRESS 0xa0000
20321 #define ISA_END_ADDRESS 0x100000
20322
20323 -#define BIOS_BEGIN 0x000a0000
20324 +#define BIOS_BEGIN 0x000c0000
20325 #define BIOS_END 0x00100000
20326
20327 #define BIOS_ROM_BASE 0xffe00000
20328 diff --git a/arch/x86/include/uapi/asm/ptrace-abi.h b/arch/x86/include/uapi/asm/ptrace-abi.h
20329 index 7b0a55a..ad115bf 100644
20330 --- a/arch/x86/include/uapi/asm/ptrace-abi.h
20331 +++ b/arch/x86/include/uapi/asm/ptrace-abi.h
20332 @@ -49,7 +49,6 @@
20333 #define EFLAGS 144
20334 #define RSP 152
20335 #define SS 160
20336 -#define ARGOFFSET R11
20337 #endif /* __ASSEMBLY__ */
20338
20339 /* top of stack page */
20340 diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
20341 index f4d9600..b45af01 100644
20342 --- a/arch/x86/kernel/Makefile
20343 +++ b/arch/x86/kernel/Makefile
20344 @@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
20345 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
20346 obj-$(CONFIG_IRQ_WORK) += irq_work.o
20347 obj-y += probe_roms.o
20348 -obj-$(CONFIG_X86_32) += i386_ksyms_32.o
20349 +obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
20350 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
20351 obj-y += syscall_$(BITS).o vsyscall_gtod.o
20352 obj-$(CONFIG_X86_64) += vsyscall_64.o
20353 diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
20354 index 86281ff..e046fc2 100644
20355 --- a/arch/x86/kernel/acpi/boot.c
20356 +++ b/arch/x86/kernel/acpi/boot.c
20357 @@ -1296,7 +1296,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
20358 * If your system is blacklisted here, but you find that acpi=force
20359 * works for you, please contact linux-acpi@vger.kernel.org
20360 */
20361 -static struct dmi_system_id __initdata acpi_dmi_table[] = {
20362 +static const struct dmi_system_id __initconst acpi_dmi_table[] = {
20363 /*
20364 * Boxes that need ACPI disabled
20365 */
20366 @@ -1371,7 +1371,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
20367 };
20368
20369 /* second table for DMI checks that should run after early-quirks */
20370 -static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
20371 +static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
20372 /*
20373 * HP laptops which use a DSDT reporting as HP/SB400/10000,
20374 * which includes some code which overrides all temperature
20375 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
20376 index 3136820..e2c6577 100644
20377 --- a/arch/x86/kernel/acpi/sleep.c
20378 +++ b/arch/x86/kernel/acpi/sleep.c
20379 @@ -99,8 +99,12 @@ int x86_acpi_suspend_lowlevel(void)
20380 #else /* CONFIG_64BIT */
20381 #ifdef CONFIG_SMP
20382 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
20383 +
20384 + pax_open_kernel();
20385 early_gdt_descr.address =
20386 (unsigned long)get_cpu_gdt_table(smp_processor_id());
20387 + pax_close_kernel();
20388 +
20389 initial_gs = per_cpu_offset(smp_processor_id());
20390 #endif
20391 initial_code = (unsigned long)wakeup_long64;
20392 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
20393 index 665c6b7..eae4d56 100644
20394 --- a/arch/x86/kernel/acpi/wakeup_32.S
20395 +++ b/arch/x86/kernel/acpi/wakeup_32.S
20396 @@ -29,13 +29,11 @@ wakeup_pmode_return:
20397 # and restore the stack ... but you need gdt for this to work
20398 movl saved_context_esp, %esp
20399
20400 - movl %cs:saved_magic, %eax
20401 - cmpl $0x12345678, %eax
20402 + cmpl $0x12345678, saved_magic
20403 jne bogus_magic
20404
20405 # jump to place where we left off
20406 - movl saved_eip, %eax
20407 - jmp *%eax
20408 + jmp *(saved_eip)
20409
20410 bogus_magic:
20411 jmp bogus_magic
20412 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
20413 index df94598..b7162f9 100644
20414 --- a/arch/x86/kernel/alternative.c
20415 +++ b/arch/x86/kernel/alternative.c
20416 @@ -269,6 +269,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20417 */
20418 for (a = start; a < end; a++) {
20419 instr = (u8 *)&a->instr_offset + a->instr_offset;
20420 +
20421 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20422 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20423 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20424 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20425 +#endif
20426 +
20427 replacement = (u8 *)&a->repl_offset + a->repl_offset;
20428 BUG_ON(a->replacementlen > a->instrlen);
20429 BUG_ON(a->instrlen > sizeof(insnbuf));
20430 @@ -285,6 +292,11 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
20431 add_nops(insnbuf + a->replacementlen,
20432 a->instrlen - a->replacementlen);
20433
20434 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20435 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
20436 + instr = ktva_ktla(instr);
20437 +#endif
20438 +
20439 text_poke_early(instr, insnbuf, a->instrlen);
20440 }
20441 }
20442 @@ -300,10 +312,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
20443 for (poff = start; poff < end; poff++) {
20444 u8 *ptr = (u8 *)poff + *poff;
20445
20446 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20447 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20448 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20449 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20450 +#endif
20451 +
20452 if (!*poff || ptr < text || ptr >= text_end)
20453 continue;
20454 /* turn DS segment override prefix into lock prefix */
20455 - if (*ptr == 0x3e)
20456 + if (*ktla_ktva(ptr) == 0x3e)
20457 text_poke(ptr, ((unsigned char []){0xf0}), 1);
20458 }
20459 mutex_unlock(&text_mutex);
20460 @@ -318,10 +336,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
20461 for (poff = start; poff < end; poff++) {
20462 u8 *ptr = (u8 *)poff + *poff;
20463
20464 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20465 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20466 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
20467 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
20468 +#endif
20469 +
20470 if (!*poff || ptr < text || ptr >= text_end)
20471 continue;
20472 /* turn lock prefix into DS segment override prefix */
20473 - if (*ptr == 0xf0)
20474 + if (*ktla_ktva(ptr) == 0xf0)
20475 text_poke(ptr, ((unsigned char []){0x3E}), 1);
20476 }
20477 mutex_unlock(&text_mutex);
20478 @@ -458,7 +482,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
20479
20480 BUG_ON(p->len > MAX_PATCH_LEN);
20481 /* prep the buffer with the original instructions */
20482 - memcpy(insnbuf, p->instr, p->len);
20483 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
20484 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
20485 (unsigned long)p->instr, p->len);
20486
20487 @@ -505,7 +529,7 @@ void __init alternative_instructions(void)
20488 if (!uniproc_patched || num_possible_cpus() == 1)
20489 free_init_pages("SMP alternatives",
20490 (unsigned long)__smp_locks,
20491 - (unsigned long)__smp_locks_end);
20492 + PAGE_ALIGN((unsigned long)__smp_locks_end));
20493 #endif
20494
20495 apply_paravirt(__parainstructions, __parainstructions_end);
20496 @@ -525,13 +549,17 @@ void __init alternative_instructions(void)
20497 * instructions. And on the local CPU you need to be protected again NMI or MCE
20498 * handlers seeing an inconsistent instruction while you patch.
20499 */
20500 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
20501 +void *__kprobes text_poke_early(void *addr, const void *opcode,
20502 size_t len)
20503 {
20504 unsigned long flags;
20505 local_irq_save(flags);
20506 - memcpy(addr, opcode, len);
20507 +
20508 + pax_open_kernel();
20509 + memcpy(ktla_ktva(addr), opcode, len);
20510 sync_core();
20511 + pax_close_kernel();
20512 +
20513 local_irq_restore(flags);
20514 /* Could also do a CLFLUSH here to speed up CPU recovery; but
20515 that causes hangs on some VIA CPUs. */
20516 @@ -553,36 +581,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
20517 */
20518 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
20519 {
20520 - unsigned long flags;
20521 - char *vaddr;
20522 + unsigned char *vaddr = ktla_ktva(addr);
20523 struct page *pages[2];
20524 - int i;
20525 + size_t i;
20526
20527 if (!core_kernel_text((unsigned long)addr)) {
20528 - pages[0] = vmalloc_to_page(addr);
20529 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
20530 + pages[0] = vmalloc_to_page(vaddr);
20531 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
20532 } else {
20533 - pages[0] = virt_to_page(addr);
20534 + pages[0] = virt_to_page(vaddr);
20535 WARN_ON(!PageReserved(pages[0]));
20536 - pages[1] = virt_to_page(addr + PAGE_SIZE);
20537 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
20538 }
20539 BUG_ON(!pages[0]);
20540 - local_irq_save(flags);
20541 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
20542 - if (pages[1])
20543 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
20544 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
20545 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
20546 - clear_fixmap(FIX_TEXT_POKE0);
20547 - if (pages[1])
20548 - clear_fixmap(FIX_TEXT_POKE1);
20549 - local_flush_tlb();
20550 - sync_core();
20551 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
20552 - that causes hangs on some VIA CPUs. */
20553 + text_poke_early(addr, opcode, len);
20554 for (i = 0; i < len; i++)
20555 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
20556 - local_irq_restore(flags);
20557 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
20558 return addr;
20559 }
20560
20561 @@ -602,7 +616,7 @@ int poke_int3_handler(struct pt_regs *regs)
20562 if (likely(!bp_patching_in_progress))
20563 return 0;
20564
20565 - if (user_mode_vm(regs) || regs->ip != (unsigned long)bp_int3_addr)
20566 + if (user_mode(regs) || regs->ip != (unsigned long)bp_int3_addr)
20567 return 0;
20568
20569 /* set up the specified breakpoint handler */
20570 @@ -636,7 +650,7 @@ int poke_int3_handler(struct pt_regs *regs)
20571 */
20572 void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
20573 {
20574 - unsigned char int3 = 0xcc;
20575 + const unsigned char int3 = 0xcc;
20576
20577 bp_int3_handler = handler;
20578 bp_int3_addr = (u8 *)addr + sizeof(int3);
20579 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
20580 index ad28db7..c538b2c 100644
20581 --- a/arch/x86/kernel/apic/apic.c
20582 +++ b/arch/x86/kernel/apic/apic.c
20583 @@ -201,7 +201,7 @@ int first_system_vector = 0xfe;
20584 /*
20585 * Debug level, exported for io_apic.c
20586 */
20587 -unsigned int apic_verbosity;
20588 +int apic_verbosity;
20589
20590 int pic_mode;
20591
20592 @@ -2000,7 +2000,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
20593 apic_write(APIC_ESR, 0);
20594 v = apic_read(APIC_ESR);
20595 ack_APIC_irq();
20596 - atomic_inc(&irq_err_count);
20597 + atomic_inc_unchecked(&irq_err_count);
20598
20599 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x",
20600 smp_processor_id(), v);
20601 diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
20602 index 7c1b294..e71d27f 100644
20603 --- a/arch/x86/kernel/apic/apic_flat_64.c
20604 +++ b/arch/x86/kernel/apic/apic_flat_64.c
20605 @@ -154,7 +154,7 @@ static int flat_probe(void)
20606 return 1;
20607 }
20608
20609 -static struct apic apic_flat = {
20610 +static struct apic apic_flat __read_only = {
20611 .name = "flat",
20612 .probe = flat_probe,
20613 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
20614 @@ -268,7 +268,7 @@ static int physflat_probe(void)
20615 return 0;
20616 }
20617
20618 -static struct apic apic_physflat = {
20619 +static struct apic apic_physflat __read_only = {
20620
20621 .name = "physical flat",
20622 .probe = physflat_probe,
20623 diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
20624 index 8c7c982..a225910 100644
20625 --- a/arch/x86/kernel/apic/apic_noop.c
20626 +++ b/arch/x86/kernel/apic/apic_noop.c
20627 @@ -118,7 +118,7 @@ static void noop_apic_write(u32 reg, u32 v)
20628 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
20629 }
20630
20631 -struct apic apic_noop = {
20632 +struct apic apic_noop __read_only = {
20633 .name = "noop",
20634 .probe = noop_probe,
20635 .acpi_madt_oem_check = NULL,
20636 diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
20637 index e4840aa..e7d9dac 100644
20638 --- a/arch/x86/kernel/apic/bigsmp_32.c
20639 +++ b/arch/x86/kernel/apic/bigsmp_32.c
20640 @@ -152,7 +152,7 @@ static int probe_bigsmp(void)
20641 return dmi_bigsmp;
20642 }
20643
20644 -static struct apic apic_bigsmp = {
20645 +static struct apic apic_bigsmp __read_only = {
20646
20647 .name = "bigsmp",
20648 .probe = probe_bigsmp,
20649 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
20650 index 992060e..ecdc3b3 100644
20651 --- a/arch/x86/kernel/apic/io_apic.c
20652 +++ b/arch/x86/kernel/apic/io_apic.c
20653 @@ -1057,7 +1057,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
20654 }
20655 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
20656
20657 -void lock_vector_lock(void)
20658 +void lock_vector_lock(void) __acquires(vector_lock)
20659 {
20660 /* Used to the online set of cpus does not change
20661 * during assign_irq_vector.
20662 @@ -1065,7 +1065,7 @@ void lock_vector_lock(void)
20663 raw_spin_lock(&vector_lock);
20664 }
20665
20666 -void unlock_vector_lock(void)
20667 +void unlock_vector_lock(void) __releases(vector_lock)
20668 {
20669 raw_spin_unlock(&vector_lock);
20670 }
20671 @@ -2364,7 +2364,7 @@ static void ack_apic_edge(struct irq_data *data)
20672 ack_APIC_irq();
20673 }
20674
20675 -atomic_t irq_mis_count;
20676 +atomic_unchecked_t irq_mis_count;
20677
20678 #ifdef CONFIG_GENERIC_PENDING_IRQ
20679 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
20680 @@ -2505,7 +2505,7 @@ static void ack_apic_level(struct irq_data *data)
20681 * at the cpu.
20682 */
20683 if (!(v & (1 << (i & 0x1f)))) {
20684 - atomic_inc(&irq_mis_count);
20685 + atomic_inc_unchecked(&irq_mis_count);
20686
20687 eoi_ioapic_irq(irq, cfg);
20688 }
20689 diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
20690 index cceb352..a635fd8 100644
20691 --- a/arch/x86/kernel/apic/probe_32.c
20692 +++ b/arch/x86/kernel/apic/probe_32.c
20693 @@ -72,7 +72,7 @@ static int probe_default(void)
20694 return 1;
20695 }
20696
20697 -static struct apic apic_default = {
20698 +static struct apic apic_default __read_only = {
20699
20700 .name = "default",
20701 .probe = probe_default,
20702 diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
20703 index e66766b..1c008ba 100644
20704 --- a/arch/x86/kernel/apic/x2apic_cluster.c
20705 +++ b/arch/x86/kernel/apic/x2apic_cluster.c
20706 @@ -182,7 +182,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
20707 return notifier_from_errno(err);
20708 }
20709
20710 -static struct notifier_block __refdata x2apic_cpu_notifier = {
20711 +static struct notifier_block x2apic_cpu_notifier = {
20712 .notifier_call = update_clusterinfo,
20713 };
20714
20715 @@ -234,7 +234,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
20716 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
20717 }
20718
20719 -static struct apic apic_x2apic_cluster = {
20720 +static struct apic apic_x2apic_cluster __read_only = {
20721
20722 .name = "cluster x2apic",
20723 .probe = x2apic_cluster_probe,
20724 diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
20725 index 6d600eb..0300c00 100644
20726 --- a/arch/x86/kernel/apic/x2apic_phys.c
20727 +++ b/arch/x86/kernel/apic/x2apic_phys.c
20728 @@ -88,7 +88,7 @@ static int x2apic_phys_probe(void)
20729 return apic == &apic_x2apic_phys;
20730 }
20731
20732 -static struct apic apic_x2apic_phys = {
20733 +static struct apic apic_x2apic_phys __read_only = {
20734
20735 .name = "physical x2apic",
20736 .probe = x2apic_phys_probe,
20737 diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
20738 index 7834389..4ffc9c8 100644
20739 --- a/arch/x86/kernel/apic/x2apic_uv_x.c
20740 +++ b/arch/x86/kernel/apic/x2apic_uv_x.c
20741 @@ -350,7 +350,7 @@ static int uv_probe(void)
20742 return apic == &apic_x2apic_uv_x;
20743 }
20744
20745 -static struct apic __refdata apic_x2apic_uv_x = {
20746 +static struct apic apic_x2apic_uv_x __read_only = {
20747
20748 .name = "UV large system",
20749 .probe = uv_probe,
20750 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
20751 index 3ab0343..814c4787 100644
20752 --- a/arch/x86/kernel/apm_32.c
20753 +++ b/arch/x86/kernel/apm_32.c
20754 @@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
20755 * This is for buggy BIOS's that refer to (real mode) segment 0x40
20756 * even though they are called in protected mode.
20757 */
20758 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
20759 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
20760 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
20761
20762 static const char driver_version[] = "1.16ac"; /* no spaces */
20763 @@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
20764 BUG_ON(cpu != 0);
20765 gdt = get_cpu_gdt_table(cpu);
20766 save_desc_40 = gdt[0x40 / 8];
20767 +
20768 + pax_open_kernel();
20769 gdt[0x40 / 8] = bad_bios_desc;
20770 + pax_close_kernel();
20771
20772 apm_irq_save(flags);
20773 APM_DO_SAVE_SEGS;
20774 @@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
20775 &call->esi);
20776 APM_DO_RESTORE_SEGS;
20777 apm_irq_restore(flags);
20778 +
20779 + pax_open_kernel();
20780 gdt[0x40 / 8] = save_desc_40;
20781 + pax_close_kernel();
20782 +
20783 put_cpu();
20784
20785 return call->eax & 0xff;
20786 @@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
20787 BUG_ON(cpu != 0);
20788 gdt = get_cpu_gdt_table(cpu);
20789 save_desc_40 = gdt[0x40 / 8];
20790 +
20791 + pax_open_kernel();
20792 gdt[0x40 / 8] = bad_bios_desc;
20793 + pax_close_kernel();
20794
20795 apm_irq_save(flags);
20796 APM_DO_SAVE_SEGS;
20797 @@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
20798 &call->eax);
20799 APM_DO_RESTORE_SEGS;
20800 apm_irq_restore(flags);
20801 +
20802 + pax_open_kernel();
20803 gdt[0x40 / 8] = save_desc_40;
20804 + pax_close_kernel();
20805 +
20806 put_cpu();
20807 return error;
20808 }
20809 @@ -2362,12 +2376,15 @@ static int __init apm_init(void)
20810 * code to that CPU.
20811 */
20812 gdt = get_cpu_gdt_table(0);
20813 +
20814 + pax_open_kernel();
20815 set_desc_base(&gdt[APM_CS >> 3],
20816 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
20817 set_desc_base(&gdt[APM_CS_16 >> 3],
20818 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
20819 set_desc_base(&gdt[APM_DS >> 3],
20820 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
20821 + pax_close_kernel();
20822
20823 proc_create("apm", 0, NULL, &apm_file_ops);
20824
20825 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
20826 index 9f6b934..cf5ffb3 100644
20827 --- a/arch/x86/kernel/asm-offsets.c
20828 +++ b/arch/x86/kernel/asm-offsets.c
20829 @@ -32,6 +32,8 @@ void common(void) {
20830 OFFSET(TI_flags, thread_info, flags);
20831 OFFSET(TI_status, thread_info, status);
20832 OFFSET(TI_addr_limit, thread_info, addr_limit);
20833 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
20834 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
20835
20836 BLANK();
20837 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
20838 @@ -52,8 +54,26 @@ void common(void) {
20839 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
20840 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
20841 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
20842 +
20843 +#ifdef CONFIG_PAX_KERNEXEC
20844 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
20845 #endif
20846
20847 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20848 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
20849 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
20850 +#ifdef CONFIG_X86_64
20851 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
20852 +#endif
20853 +#endif
20854 +
20855 +#endif
20856 +
20857 + BLANK();
20858 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
20859 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
20860 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
20861 +
20862 #ifdef CONFIG_XEN
20863 BLANK();
20864 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
20865 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
20866 index e7c798b..2b2019b 100644
20867 --- a/arch/x86/kernel/asm-offsets_64.c
20868 +++ b/arch/x86/kernel/asm-offsets_64.c
20869 @@ -77,6 +77,7 @@ int main(void)
20870 BLANK();
20871 #undef ENTRY
20872
20873 + DEFINE(TSS_size, sizeof(struct tss_struct));
20874 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
20875 BLANK();
20876
20877 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
20878 index 7fd54f0..0691410 100644
20879 --- a/arch/x86/kernel/cpu/Makefile
20880 +++ b/arch/x86/kernel/cpu/Makefile
20881 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
20882 CFLAGS_REMOVE_perf_event.o = -pg
20883 endif
20884
20885 -# Make sure load_percpu_segment has no stackprotector
20886 -nostackp := $(call cc-option, -fno-stack-protector)
20887 -CFLAGS_common.o := $(nostackp)
20888 -
20889 obj-y := intel_cacheinfo.o scattered.o topology.o
20890 obj-y += proc.o capflags.o powerflags.o common.o
20891 obj-y += rdrand.o
20892 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
20893 index ce8b8ff..d7d8851 100644
20894 --- a/arch/x86/kernel/cpu/amd.c
20895 +++ b/arch/x86/kernel/cpu/amd.c
20896 @@ -728,7 +728,7 @@ static void init_amd(struct cpuinfo_x86 *c)
20897 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
20898 {
20899 /* AMD errata T13 (order #21922) */
20900 - if ((c->x86 == 6)) {
20901 + if (c->x86 == 6) {
20902 /* Duron Rev A0 */
20903 if (c->x86_model == 3 && c->x86_mask == 0)
20904 size = 64;
20905 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
20906 index a135239..41fb30a 100644
20907 --- a/arch/x86/kernel/cpu/common.c
20908 +++ b/arch/x86/kernel/cpu/common.c
20909 @@ -88,60 +88,6 @@ static const struct cpu_dev default_cpu = {
20910
20911 static const struct cpu_dev *this_cpu = &default_cpu;
20912
20913 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
20914 -#ifdef CONFIG_X86_64
20915 - /*
20916 - * We need valid kernel segments for data and code in long mode too
20917 - * IRET will check the segment types kkeil 2000/10/28
20918 - * Also sysret mandates a special GDT layout
20919 - *
20920 - * TLS descriptors are currently at a different place compared to i386.
20921 - * Hopefully nobody expects them at a fixed place (Wine?)
20922 - */
20923 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
20924 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
20925 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
20926 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
20927 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
20928 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
20929 -#else
20930 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
20931 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20932 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
20933 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
20934 - /*
20935 - * Segments used for calling PnP BIOS have byte granularity.
20936 - * They code segments and data segments have fixed 64k limits,
20937 - * the transfer segment sizes are set at run time.
20938 - */
20939 - /* 32-bit code */
20940 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
20941 - /* 16-bit code */
20942 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
20943 - /* 16-bit data */
20944 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
20945 - /* 16-bit data */
20946 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
20947 - /* 16-bit data */
20948 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
20949 - /*
20950 - * The APM segments have byte granularity and their bases
20951 - * are set at run time. All have 64k limits.
20952 - */
20953 - /* 32-bit code */
20954 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
20955 - /* 16-bit code */
20956 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
20957 - /* data */
20958 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
20959 -
20960 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20961 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20962 - GDT_STACK_CANARY_INIT
20963 -#endif
20964 -} };
20965 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
20966 -
20967 static int __init x86_xsave_setup(char *s)
20968 {
20969 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
20970 @@ -293,6 +239,59 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
20971 }
20972 }
20973
20974 +#ifdef CONFIG_X86_64
20975 +static __init int setup_disable_pcid(char *arg)
20976 +{
20977 + setup_clear_cpu_cap(X86_FEATURE_PCID);
20978 + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
20979 +
20980 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20981 + if (clone_pgd_mask != ~(pgdval_t)0UL)
20982 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
20983 +#endif
20984 +
20985 + return 1;
20986 +}
20987 +__setup("nopcid", setup_disable_pcid);
20988 +
20989 +static void setup_pcid(struct cpuinfo_x86 *c)
20990 +{
20991 + if (!cpu_has(c, X86_FEATURE_PCID)) {
20992 + clear_cpu_cap(c, X86_FEATURE_INVPCID);
20993 +
20994 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20995 + if (clone_pgd_mask != ~(pgdval_t)0UL) {
20996 + pax_open_kernel();
20997 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
20998 + pax_close_kernel();
20999 + printk("PAX: slow and weak UDEREF enabled\n");
21000 + } else
21001 + printk("PAX: UDEREF disabled\n");
21002 +#endif
21003 +
21004 + return;
21005 + }
21006 +
21007 + printk("PAX: PCID detected\n");
21008 + set_in_cr4(X86_CR4_PCIDE);
21009 +
21010 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21011 + pax_open_kernel();
21012 + clone_pgd_mask = ~(pgdval_t)0UL;
21013 + pax_close_kernel();
21014 + if (pax_user_shadow_base)
21015 + printk("PAX: weak UDEREF enabled\n");
21016 + else {
21017 + set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
21018 + printk("PAX: strong UDEREF enabled\n");
21019 + }
21020 +#endif
21021 +
21022 + if (cpu_has(c, X86_FEATURE_INVPCID))
21023 + printk("PAX: INVPCID detected\n");
21024 +}
21025 +#endif
21026 +
21027 /*
21028 * Some CPU features depend on higher CPUID levels, which may not always
21029 * be available due to CPUID level capping or broken virtualization
21030 @@ -393,7 +392,7 @@ void switch_to_new_gdt(int cpu)
21031 {
21032 struct desc_ptr gdt_descr;
21033
21034 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
21035 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
21036 gdt_descr.size = GDT_SIZE - 1;
21037 load_gdt(&gdt_descr);
21038 /* Reload the per-cpu base */
21039 @@ -883,6 +882,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
21040 setup_smep(c);
21041 setup_smap(c);
21042
21043 +#ifdef CONFIG_X86_64
21044 + setup_pcid(c);
21045 +#endif
21046 +
21047 /*
21048 * The vendor-specific functions might have changed features.
21049 * Now we do "generic changes."
21050 @@ -891,6 +894,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
21051 /* Filter out anything that depends on CPUID levels we don't have */
21052 filter_cpuid_features(c, true);
21053
21054 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
21055 + setup_clear_cpu_cap(X86_FEATURE_SEP);
21056 +#endif
21057 +
21058 /* If the model name is still unset, do table lookup. */
21059 if (!c->x86_model_id[0]) {
21060 const char *p;
21061 @@ -1079,14 +1086,16 @@ static __init int setup_disablecpuid(char *arg)
21062 }
21063 __setup("clearcpuid=", setup_disablecpuid);
21064
21065 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
21066 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
21067 +
21068 DEFINE_PER_CPU(unsigned long, kernel_stack) =
21069 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
21070 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
21071 EXPORT_PER_CPU_SYMBOL(kernel_stack);
21072
21073 #ifdef CONFIG_X86_64
21074 -struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21075 -struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
21076 - (unsigned long) debug_idt_table };
21077 +struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
21078 +const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
21079
21080 DEFINE_PER_CPU_FIRST(union irq_stack_union,
21081 irq_stack_union) __aligned(PAGE_SIZE) __visible;
21082 @@ -1246,7 +1255,7 @@ void cpu_init(void)
21083 load_ucode_ap();
21084
21085 cpu = stack_smp_processor_id();
21086 - t = &per_cpu(init_tss, cpu);
21087 + t = init_tss + cpu;
21088 oist = &per_cpu(orig_ist, cpu);
21089
21090 #ifdef CONFIG_NUMA
21091 @@ -1281,7 +1290,6 @@ void cpu_init(void)
21092 wrmsrl(MSR_KERNEL_GS_BASE, 0);
21093 barrier();
21094
21095 - x86_configure_nx();
21096 enable_x2apic();
21097
21098 /*
21099 @@ -1333,7 +1341,7 @@ void cpu_init(void)
21100 {
21101 int cpu = smp_processor_id();
21102 struct task_struct *curr = current;
21103 - struct tss_struct *t = &per_cpu(init_tss, cpu);
21104 + struct tss_struct *t = init_tss + cpu;
21105 struct thread_struct *thread = &curr->thread;
21106
21107 show_ucode_info_early();
21108 diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
21109 index a952e9c..58a4cbb 100644
21110 --- a/arch/x86/kernel/cpu/intel_cacheinfo.c
21111 +++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
21112 @@ -1014,6 +1014,22 @@ static struct attribute *default_attrs[] = {
21113 };
21114
21115 #ifdef CONFIG_AMD_NB
21116 +static struct attribute *default_attrs_amd_nb[] = {
21117 + &type.attr,
21118 + &level.attr,
21119 + &coherency_line_size.attr,
21120 + &physical_line_partition.attr,
21121 + &ways_of_associativity.attr,
21122 + &number_of_sets.attr,
21123 + &size.attr,
21124 + &shared_cpu_map.attr,
21125 + &shared_cpu_list.attr,
21126 + NULL,
21127 + NULL,
21128 + NULL,
21129 + NULL
21130 +};
21131 +
21132 static struct attribute **amd_l3_attrs(void)
21133 {
21134 static struct attribute **attrs;
21135 @@ -1024,18 +1040,7 @@ static struct attribute **amd_l3_attrs(void)
21136
21137 n = ARRAY_SIZE(default_attrs);
21138
21139 - if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
21140 - n += 2;
21141 -
21142 - if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
21143 - n += 1;
21144 -
21145 - attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
21146 - if (attrs == NULL)
21147 - return attrs = default_attrs;
21148 -
21149 - for (n = 0; default_attrs[n]; n++)
21150 - attrs[n] = default_attrs[n];
21151 + attrs = default_attrs_amd_nb;
21152
21153 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
21154 attrs[n++] = &cache_disable_0.attr;
21155 @@ -1086,6 +1091,13 @@ static struct kobj_type ktype_cache = {
21156 .default_attrs = default_attrs,
21157 };
21158
21159 +#ifdef CONFIG_AMD_NB
21160 +static struct kobj_type ktype_cache_amd_nb = {
21161 + .sysfs_ops = &sysfs_ops,
21162 + .default_attrs = default_attrs_amd_nb,
21163 +};
21164 +#endif
21165 +
21166 static struct kobj_type ktype_percpu_entry = {
21167 .sysfs_ops = &sysfs_ops,
21168 };
21169 @@ -1151,20 +1163,26 @@ static int cache_add_dev(struct device *dev)
21170 return retval;
21171 }
21172
21173 +#ifdef CONFIG_AMD_NB
21174 + amd_l3_attrs();
21175 +#endif
21176 +
21177 for (i = 0; i < num_cache_leaves; i++) {
21178 + struct kobj_type *ktype;
21179 +
21180 this_object = INDEX_KOBJECT_PTR(cpu, i);
21181 this_object->cpu = cpu;
21182 this_object->index = i;
21183
21184 this_leaf = CPUID4_INFO_IDX(cpu, i);
21185
21186 - ktype_cache.default_attrs = default_attrs;
21187 + ktype = &ktype_cache;
21188 #ifdef CONFIG_AMD_NB
21189 if (this_leaf->base.nb)
21190 - ktype_cache.default_attrs = amd_l3_attrs();
21191 + ktype = &ktype_cache_amd_nb;
21192 #endif
21193 retval = kobject_init_and_add(&(this_object->kobj),
21194 - &ktype_cache,
21195 + ktype,
21196 per_cpu(ici_cache_kobject, cpu),
21197 "index%1lu", i);
21198 if (unlikely(retval)) {
21199 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
21200 index 68317c8..c860d41 100644
21201 --- a/arch/x86/kernel/cpu/mcheck/mce.c
21202 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
21203 @@ -45,6 +45,7 @@
21204 #include <asm/processor.h>
21205 #include <asm/mce.h>
21206 #include <asm/msr.h>
21207 +#include <asm/local.h>
21208
21209 #include "mce-internal.h"
21210
21211 @@ -261,7 +262,7 @@ static void print_mce(struct mce *m)
21212 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
21213 m->cs, m->ip);
21214
21215 - if (m->cs == __KERNEL_CS)
21216 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
21217 print_symbol("{%s}", m->ip);
21218 pr_cont("\n");
21219 }
21220 @@ -294,10 +295,10 @@ static void print_mce(struct mce *m)
21221
21222 #define PANIC_TIMEOUT 5 /* 5 seconds */
21223
21224 -static atomic_t mce_paniced;
21225 +static atomic_unchecked_t mce_paniced;
21226
21227 static int fake_panic;
21228 -static atomic_t mce_fake_paniced;
21229 +static atomic_unchecked_t mce_fake_paniced;
21230
21231 /* Panic in progress. Enable interrupts and wait for final IPI */
21232 static void wait_for_panic(void)
21233 @@ -321,7 +322,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21234 /*
21235 * Make sure only one CPU runs in machine check panic
21236 */
21237 - if (atomic_inc_return(&mce_paniced) > 1)
21238 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
21239 wait_for_panic();
21240 barrier();
21241
21242 @@ -329,7 +330,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21243 console_verbose();
21244 } else {
21245 /* Don't log too much for fake panic */
21246 - if (atomic_inc_return(&mce_fake_paniced) > 1)
21247 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
21248 return;
21249 }
21250 /* First print corrected ones that are still unlogged */
21251 @@ -368,7 +369,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
21252 if (!fake_panic) {
21253 if (panic_timeout == 0)
21254 panic_timeout = mca_cfg.panic_timeout;
21255 - panic(msg);
21256 + panic("%s", msg);
21257 } else
21258 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
21259 }
21260 @@ -699,7 +700,7 @@ static int mce_timed_out(u64 *t)
21261 * might have been modified by someone else.
21262 */
21263 rmb();
21264 - if (atomic_read(&mce_paniced))
21265 + if (atomic_read_unchecked(&mce_paniced))
21266 wait_for_panic();
21267 if (!mca_cfg.monarch_timeout)
21268 goto out;
21269 @@ -1680,7 +1681,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
21270 }
21271
21272 /* Call the installed machine check handler for this CPU setup. */
21273 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
21274 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
21275 unexpected_machine_check;
21276
21277 /*
21278 @@ -1703,7 +1704,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21279 return;
21280 }
21281
21282 + pax_open_kernel();
21283 machine_check_vector = do_machine_check;
21284 + pax_close_kernel();
21285
21286 __mcheck_cpu_init_generic();
21287 __mcheck_cpu_init_vendor(c);
21288 @@ -1717,7 +1720,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
21289 */
21290
21291 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
21292 -static int mce_chrdev_open_count; /* #times opened */
21293 +static local_t mce_chrdev_open_count; /* #times opened */
21294 static int mce_chrdev_open_exclu; /* already open exclusive? */
21295
21296 static int mce_chrdev_open(struct inode *inode, struct file *file)
21297 @@ -1725,7 +1728,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21298 spin_lock(&mce_chrdev_state_lock);
21299
21300 if (mce_chrdev_open_exclu ||
21301 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
21302 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
21303 spin_unlock(&mce_chrdev_state_lock);
21304
21305 return -EBUSY;
21306 @@ -1733,7 +1736,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
21307
21308 if (file->f_flags & O_EXCL)
21309 mce_chrdev_open_exclu = 1;
21310 - mce_chrdev_open_count++;
21311 + local_inc(&mce_chrdev_open_count);
21312
21313 spin_unlock(&mce_chrdev_state_lock);
21314
21315 @@ -1744,7 +1747,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
21316 {
21317 spin_lock(&mce_chrdev_state_lock);
21318
21319 - mce_chrdev_open_count--;
21320 + local_dec(&mce_chrdev_open_count);
21321 mce_chrdev_open_exclu = 0;
21322
21323 spin_unlock(&mce_chrdev_state_lock);
21324 @@ -2420,7 +2423,7 @@ static __init void mce_init_banks(void)
21325
21326 for (i = 0; i < mca_cfg.banks; i++) {
21327 struct mce_bank *b = &mce_banks[i];
21328 - struct device_attribute *a = &b->attr;
21329 + device_attribute_no_const *a = &b->attr;
21330
21331 sysfs_attr_init(&a->attr);
21332 a->attr.name = b->attrname;
21333 @@ -2492,7 +2495,7 @@ struct dentry *mce_get_debugfs_dir(void)
21334 static void mce_reset(void)
21335 {
21336 cpu_missing = 0;
21337 - atomic_set(&mce_fake_paniced, 0);
21338 + atomic_set_unchecked(&mce_fake_paniced, 0);
21339 atomic_set(&mce_executing, 0);
21340 atomic_set(&mce_callin, 0);
21341 atomic_set(&global_nwo, 0);
21342 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
21343 index a304298..49b6d06 100644
21344 --- a/arch/x86/kernel/cpu/mcheck/p5.c
21345 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
21346 @@ -10,6 +10,7 @@
21347 #include <asm/processor.h>
21348 #include <asm/mce.h>
21349 #include <asm/msr.h>
21350 +#include <asm/pgtable.h>
21351
21352 /* By default disabled */
21353 int mce_p5_enabled __read_mostly;
21354 @@ -48,7 +49,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
21355 if (!cpu_has(c, X86_FEATURE_MCE))
21356 return;
21357
21358 + pax_open_kernel();
21359 machine_check_vector = pentium_machine_check;
21360 + pax_close_kernel();
21361 /* Make sure the vector pointer is visible before we enable MCEs: */
21362 wmb();
21363
21364 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
21365 index 7dc5564..1273569 100644
21366 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
21367 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
21368 @@ -9,6 +9,7 @@
21369 #include <asm/processor.h>
21370 #include <asm/mce.h>
21371 #include <asm/msr.h>
21372 +#include <asm/pgtable.h>
21373
21374 /* Machine check handler for WinChip C6: */
21375 static void winchip_machine_check(struct pt_regs *regs, long error_code)
21376 @@ -22,7 +23,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
21377 {
21378 u32 lo, hi;
21379
21380 + pax_open_kernel();
21381 machine_check_vector = winchip_machine_check;
21382 + pax_close_kernel();
21383 /* Make sure the vector pointer is visible before we enable MCEs: */
21384 wmb();
21385
21386 diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
21387 index 15c9876..0a43909 100644
21388 --- a/arch/x86/kernel/cpu/microcode/core.c
21389 +++ b/arch/x86/kernel/cpu/microcode/core.c
21390 @@ -513,7 +513,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
21391 return NOTIFY_OK;
21392 }
21393
21394 -static struct notifier_block __refdata mc_cpu_notifier = {
21395 +static struct notifier_block mc_cpu_notifier = {
21396 .notifier_call = mc_cpu_callback,
21397 };
21398
21399 diff --git a/arch/x86/kernel/cpu/microcode/intel.c b/arch/x86/kernel/cpu/microcode/intel.c
21400 index a276fa7..e66810f 100644
21401 --- a/arch/x86/kernel/cpu/microcode/intel.c
21402 +++ b/arch/x86/kernel/cpu/microcode/intel.c
21403 @@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
21404
21405 static int get_ucode_user(void *to, const void *from, size_t n)
21406 {
21407 - return copy_from_user(to, from, n);
21408 + return copy_from_user(to, (const void __force_user *)from, n);
21409 }
21410
21411 static enum ucode_state
21412 request_microcode_user(int cpu, const void __user *buf, size_t size)
21413 {
21414 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
21415 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
21416 }
21417
21418 static void microcode_fini_cpu(int cpu)
21419 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
21420 index f961de9..8a9d332 100644
21421 --- a/arch/x86/kernel/cpu/mtrr/main.c
21422 +++ b/arch/x86/kernel/cpu/mtrr/main.c
21423 @@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
21424 u64 size_or_mask, size_and_mask;
21425 static bool mtrr_aps_delayed_init;
21426
21427 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
21428 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
21429
21430 const struct mtrr_ops *mtrr_if;
21431
21432 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
21433 index df5e41f..816c719 100644
21434 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
21435 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
21436 @@ -25,7 +25,7 @@ struct mtrr_ops {
21437 int (*validate_add_page)(unsigned long base, unsigned long size,
21438 unsigned int type);
21439 int (*have_wrcomb)(void);
21440 -};
21441 +} __do_const;
21442
21443 extern int generic_get_free_region(unsigned long base, unsigned long size,
21444 int replace_reg);
21445 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
21446 index ae407f7..39c5b00 100644
21447 --- a/arch/x86/kernel/cpu/perf_event.c
21448 +++ b/arch/x86/kernel/cpu/perf_event.c
21449 @@ -1367,7 +1367,7 @@ static void __init pmu_check_apic(void)
21450 pr_info("no hardware sampling interrupt available.\n");
21451 }
21452
21453 -static struct attribute_group x86_pmu_format_group = {
21454 +static attribute_group_no_const x86_pmu_format_group = {
21455 .name = "format",
21456 .attrs = NULL,
21457 };
21458 @@ -1466,7 +1466,7 @@ static struct attribute *events_attr[] = {
21459 NULL,
21460 };
21461
21462 -static struct attribute_group x86_pmu_events_group = {
21463 +static attribute_group_no_const x86_pmu_events_group = {
21464 .name = "events",
21465 .attrs = events_attr,
21466 };
21467 @@ -1990,7 +1990,7 @@ static unsigned long get_segment_base(unsigned int segment)
21468 if (idx > GDT_ENTRIES)
21469 return 0;
21470
21471 - desc = __this_cpu_ptr(&gdt_page.gdt[0]);
21472 + desc = get_cpu_gdt_table(smp_processor_id());
21473 }
21474
21475 return get_desc_base(desc + idx);
21476 @@ -2080,7 +2080,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
21477 break;
21478
21479 perf_callchain_store(entry, frame.return_address);
21480 - fp = frame.next_frame;
21481 + fp = (const void __force_user *)frame.next_frame;
21482 }
21483 }
21484
21485 diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21486 index 639d128..e92d7e5 100644
21487 --- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21488 +++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
21489 @@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
21490 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
21491 {
21492 struct attribute **attrs;
21493 - struct attribute_group *attr_group;
21494 + attribute_group_no_const *attr_group;
21495 int i = 0, j;
21496
21497 while (amd_iommu_v2_event_descs[i].attr.attr.name)
21498 diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
21499 index adb02aa..9688c02 100644
21500 --- a/arch/x86/kernel/cpu/perf_event_intel.c
21501 +++ b/arch/x86/kernel/cpu/perf_event_intel.c
21502 @@ -2308,10 +2308,10 @@ __init int intel_pmu_init(void)
21503 x86_pmu.num_counters_fixed = max((int)edx.split.num_counters_fixed, 3);
21504
21505 if (boot_cpu_has(X86_FEATURE_PDCM)) {
21506 - u64 capabilities;
21507 + u64 capabilities = x86_pmu.intel_cap.capabilities;
21508
21509 - rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
21510 - x86_pmu.intel_cap.capabilities = capabilities;
21511 + if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
21512 + x86_pmu.intel_cap.capabilities = capabilities;
21513 }
21514
21515 intel_ds_init();
21516 diff --git a/arch/x86/kernel/cpu/perf_event_intel_rapl.c b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21517 index 619f769..d510008 100644
21518 --- a/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21519 +++ b/arch/x86/kernel/cpu/perf_event_intel_rapl.c
21520 @@ -449,7 +449,7 @@ static struct attribute *rapl_events_hsw_attr[] = {
21521 NULL,
21522 };
21523
21524 -static struct attribute_group rapl_pmu_events_group = {
21525 +static attribute_group_no_const rapl_pmu_events_group __read_only = {
21526 .name = "events",
21527 .attrs = NULL, /* patched at runtime */
21528 };
21529 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21530 index 65bbbea..1438d9e 100644
21531 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21532 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
21533 @@ -3693,7 +3693,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
21534 static int __init uncore_type_init(struct intel_uncore_type *type)
21535 {
21536 struct intel_uncore_pmu *pmus;
21537 - struct attribute_group *attr_group;
21538 + attribute_group_no_const *attr_group;
21539 struct attribute **attrs;
21540 int i, j;
21541
21542 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21543 index 90236f0..54cb20d 100644
21544 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21545 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
21546 @@ -503,7 +503,7 @@ struct intel_uncore_box {
21547 struct uncore_event_desc {
21548 struct kobj_attribute attr;
21549 const char *config;
21550 -};
21551 +} __do_const;
21552
21553 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
21554 { \
21555 diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
21556 index 3225ae6c..ee3c6db 100644
21557 --- a/arch/x86/kernel/cpuid.c
21558 +++ b/arch/x86/kernel/cpuid.c
21559 @@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
21560 return notifier_from_errno(err);
21561 }
21562
21563 -static struct notifier_block __refdata cpuid_class_cpu_notifier =
21564 +static struct notifier_block cpuid_class_cpu_notifier =
21565 {
21566 .notifier_call = cpuid_class_cpu_callback,
21567 };
21568 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
21569 index 507de80..ebaae2a 100644
21570 --- a/arch/x86/kernel/crash.c
21571 +++ b/arch/x86/kernel/crash.c
21572 @@ -58,7 +58,7 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
21573 #ifdef CONFIG_X86_32
21574 struct pt_regs fixed_regs;
21575
21576 - if (!user_mode_vm(regs)) {
21577 + if (!user_mode(regs)) {
21578 crash_fixup_ss_esp(&fixed_regs, regs);
21579 regs = &fixed_regs;
21580 }
21581 diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
21582 index afa64ad..dce67dd 100644
21583 --- a/arch/x86/kernel/crash_dump_64.c
21584 +++ b/arch/x86/kernel/crash_dump_64.c
21585 @@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
21586 return -ENOMEM;
21587
21588 if (userbuf) {
21589 - if (copy_to_user(buf, vaddr + offset, csize)) {
21590 + if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
21591 iounmap(vaddr);
21592 return -EFAULT;
21593 }
21594 diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
21595 index f6dfd93..892ade4 100644
21596 --- a/arch/x86/kernel/doublefault.c
21597 +++ b/arch/x86/kernel/doublefault.c
21598 @@ -12,7 +12,7 @@
21599
21600 #define DOUBLEFAULT_STACKSIZE (1024)
21601 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
21602 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
21603 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
21604
21605 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
21606
21607 @@ -22,7 +22,7 @@ static void doublefault_fn(void)
21608 unsigned long gdt, tss;
21609
21610 native_store_gdt(&gdt_desc);
21611 - gdt = gdt_desc.address;
21612 + gdt = (unsigned long)gdt_desc.address;
21613
21614 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
21615
21616 @@ -59,10 +59,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
21617 /* 0x2 bit is always set */
21618 .flags = X86_EFLAGS_SF | 0x2,
21619 .sp = STACK_START,
21620 - .es = __USER_DS,
21621 + .es = __KERNEL_DS,
21622 .cs = __KERNEL_CS,
21623 .ss = __KERNEL_DS,
21624 - .ds = __USER_DS,
21625 + .ds = __KERNEL_DS,
21626 .fs = __KERNEL_PERCPU,
21627
21628 .__cr3 = __pa_nodebug(swapper_pg_dir),
21629 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
21630 index d9c12d3..7858b62 100644
21631 --- a/arch/x86/kernel/dumpstack.c
21632 +++ b/arch/x86/kernel/dumpstack.c
21633 @@ -2,6 +2,9 @@
21634 * Copyright (C) 1991, 1992 Linus Torvalds
21635 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
21636 */
21637 +#ifdef CONFIG_GRKERNSEC_HIDESYM
21638 +#define __INCLUDED_BY_HIDESYM 1
21639 +#endif
21640 #include <linux/kallsyms.h>
21641 #include <linux/kprobes.h>
21642 #include <linux/uaccess.h>
21643 @@ -40,16 +43,14 @@ void printk_address(unsigned long address)
21644 static void
21645 print_ftrace_graph_addr(unsigned long addr, void *data,
21646 const struct stacktrace_ops *ops,
21647 - struct thread_info *tinfo, int *graph)
21648 + struct task_struct *task, int *graph)
21649 {
21650 - struct task_struct *task;
21651 unsigned long ret_addr;
21652 int index;
21653
21654 if (addr != (unsigned long)return_to_handler)
21655 return;
21656
21657 - task = tinfo->task;
21658 index = task->curr_ret_stack;
21659
21660 if (!task->ret_stack || index < *graph)
21661 @@ -66,7 +67,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21662 static inline void
21663 print_ftrace_graph_addr(unsigned long addr, void *data,
21664 const struct stacktrace_ops *ops,
21665 - struct thread_info *tinfo, int *graph)
21666 + struct task_struct *task, int *graph)
21667 { }
21668 #endif
21669
21670 @@ -77,10 +78,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21671 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
21672 */
21673
21674 -static inline int valid_stack_ptr(struct thread_info *tinfo,
21675 - void *p, unsigned int size, void *end)
21676 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
21677 {
21678 - void *t = tinfo;
21679 if (end) {
21680 if (p < end && p >= (end-THREAD_SIZE))
21681 return 1;
21682 @@ -91,14 +90,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
21683 }
21684
21685 unsigned long
21686 -print_context_stack(struct thread_info *tinfo,
21687 +print_context_stack(struct task_struct *task, void *stack_start,
21688 unsigned long *stack, unsigned long bp,
21689 const struct stacktrace_ops *ops, void *data,
21690 unsigned long *end, int *graph)
21691 {
21692 struct stack_frame *frame = (struct stack_frame *)bp;
21693
21694 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
21695 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
21696 unsigned long addr;
21697
21698 addr = *stack;
21699 @@ -110,7 +109,7 @@ print_context_stack(struct thread_info *tinfo,
21700 } else {
21701 ops->address(data, addr, 0);
21702 }
21703 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21704 + print_ftrace_graph_addr(addr, data, ops, task, graph);
21705 }
21706 stack++;
21707 }
21708 @@ -119,7 +118,7 @@ print_context_stack(struct thread_info *tinfo,
21709 EXPORT_SYMBOL_GPL(print_context_stack);
21710
21711 unsigned long
21712 -print_context_stack_bp(struct thread_info *tinfo,
21713 +print_context_stack_bp(struct task_struct *task, void *stack_start,
21714 unsigned long *stack, unsigned long bp,
21715 const struct stacktrace_ops *ops, void *data,
21716 unsigned long *end, int *graph)
21717 @@ -127,7 +126,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21718 struct stack_frame *frame = (struct stack_frame *)bp;
21719 unsigned long *ret_addr = &frame->return_address;
21720
21721 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
21722 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
21723 unsigned long addr = *ret_addr;
21724
21725 if (!__kernel_text_address(addr))
21726 @@ -136,7 +135,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21727 ops->address(data, addr, 1);
21728 frame = frame->next_frame;
21729 ret_addr = &frame->return_address;
21730 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21731 + print_ftrace_graph_addr(addr, data, ops, task, graph);
21732 }
21733
21734 return (unsigned long)frame;
21735 @@ -155,7 +154,7 @@ static int print_trace_stack(void *data, char *name)
21736 static void print_trace_address(void *data, unsigned long addr, int reliable)
21737 {
21738 touch_nmi_watchdog();
21739 - printk(data);
21740 + printk("%s", (char *)data);
21741 printk_stack_address(addr, reliable);
21742 }
21743
21744 @@ -224,6 +223,8 @@ unsigned __kprobes long oops_begin(void)
21745 }
21746 EXPORT_SYMBOL_GPL(oops_begin);
21747
21748 +extern void gr_handle_kernel_exploit(void);
21749 +
21750 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
21751 {
21752 if (regs && kexec_should_crash(current))
21753 @@ -245,7 +246,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
21754 panic("Fatal exception in interrupt");
21755 if (panic_on_oops)
21756 panic("Fatal exception");
21757 - do_exit(signr);
21758 +
21759 + gr_handle_kernel_exploit();
21760 +
21761 + do_group_exit(signr);
21762 }
21763
21764 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
21765 @@ -273,7 +277,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
21766 print_modules();
21767 show_regs(regs);
21768 #ifdef CONFIG_X86_32
21769 - if (user_mode_vm(regs)) {
21770 + if (user_mode(regs)) {
21771 sp = regs->sp;
21772 ss = regs->ss & 0xffff;
21773 } else {
21774 @@ -301,7 +305,7 @@ void die(const char *str, struct pt_regs *regs, long err)
21775 unsigned long flags = oops_begin();
21776 int sig = SIGSEGV;
21777
21778 - if (!user_mode_vm(regs))
21779 + if (!user_mode(regs))
21780 report_bug(regs->ip, regs);
21781
21782 if (__die(str, regs, err))
21783 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
21784 index 5abd4cd..c65733b 100644
21785 --- a/arch/x86/kernel/dumpstack_32.c
21786 +++ b/arch/x86/kernel/dumpstack_32.c
21787 @@ -61,15 +61,14 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21788 bp = stack_frame(task, regs);
21789
21790 for (;;) {
21791 - struct thread_info *context;
21792 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
21793 void *end_stack;
21794
21795 end_stack = is_hardirq_stack(stack, cpu);
21796 if (!end_stack)
21797 end_stack = is_softirq_stack(stack, cpu);
21798
21799 - context = task_thread_info(task);
21800 - bp = ops->walk_stack(context, stack, bp, ops, data,
21801 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data,
21802 end_stack, &graph);
21803
21804 /* Stop if not on irq stack */
21805 @@ -123,27 +122,28 @@ void show_regs(struct pt_regs *regs)
21806 int i;
21807
21808 show_regs_print_info(KERN_EMERG);
21809 - __show_regs(regs, !user_mode_vm(regs));
21810 + __show_regs(regs, !user_mode(regs));
21811
21812 /*
21813 * When in-kernel, we also print out the stack and code at the
21814 * time of the fault..
21815 */
21816 - if (!user_mode_vm(regs)) {
21817 + if (!user_mode(regs)) {
21818 unsigned int code_prologue = code_bytes * 43 / 64;
21819 unsigned int code_len = code_bytes;
21820 unsigned char c;
21821 u8 *ip;
21822 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
21823
21824 pr_emerg("Stack:\n");
21825 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
21826
21827 pr_emerg("Code:");
21828
21829 - ip = (u8 *)regs->ip - code_prologue;
21830 + ip = (u8 *)regs->ip - code_prologue + cs_base;
21831 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
21832 /* try starting at IP */
21833 - ip = (u8 *)regs->ip;
21834 + ip = (u8 *)regs->ip + cs_base;
21835 code_len = code_len - code_prologue + 1;
21836 }
21837 for (i = 0; i < code_len; i++, ip++) {
21838 @@ -152,7 +152,7 @@ void show_regs(struct pt_regs *regs)
21839 pr_cont(" Bad EIP value.");
21840 break;
21841 }
21842 - if (ip == (u8 *)regs->ip)
21843 + if (ip == (u8 *)regs->ip + cs_base)
21844 pr_cont(" <%02x>", c);
21845 else
21846 pr_cont(" %02x", c);
21847 @@ -165,6 +165,7 @@ int is_valid_bugaddr(unsigned long ip)
21848 {
21849 unsigned short ud2;
21850
21851 + ip = ktla_ktva(ip);
21852 if (ip < PAGE_OFFSET)
21853 return 0;
21854 if (probe_kernel_address((unsigned short *)ip, ud2))
21855 @@ -172,3 +173,15 @@ int is_valid_bugaddr(unsigned long ip)
21856
21857 return ud2 == 0x0b0f;
21858 }
21859 +
21860 +#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
21861 +void pax_check_alloca(unsigned long size)
21862 +{
21863 + unsigned long sp = (unsigned long)&sp, stack_left;
21864 +
21865 + /* all kernel stacks are of the same size */
21866 + stack_left = sp & (THREAD_SIZE - 1);
21867 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
21868 +}
21869 +EXPORT_SYMBOL(pax_check_alloca);
21870 +#endif
21871 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
21872 index 1abcb50..6c8d702 100644
21873 --- a/arch/x86/kernel/dumpstack_64.c
21874 +++ b/arch/x86/kernel/dumpstack_64.c
21875 @@ -154,12 +154,12 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21876 const struct stacktrace_ops *ops, void *data)
21877 {
21878 const unsigned cpu = get_cpu();
21879 - struct thread_info *tinfo;
21880 unsigned long *irq_stack = (unsigned long *)per_cpu(irq_stack_ptr, cpu);
21881 unsigned long dummy;
21882 unsigned used = 0;
21883 int graph = 0;
21884 int done = 0;
21885 + void *stack_start;
21886
21887 if (!task)
21888 task = current;
21889 @@ -180,7 +180,6 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21890 * current stack address. If the stacks consist of nested
21891 * exceptions
21892 */
21893 - tinfo = task_thread_info(task);
21894 while (!done) {
21895 unsigned long *stack_end;
21896 enum stack_type stype;
21897 @@ -203,7 +202,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21898 if (ops->stack(data, id) < 0)
21899 break;
21900
21901 - bp = ops->walk_stack(tinfo, stack, bp, ops,
21902 + bp = ops->walk_stack(task, stack_end - EXCEPTION_STKSZ, stack, bp, ops,
21903 data, stack_end, &graph);
21904 ops->stack(data, "<EOE>");
21905 /*
21906 @@ -211,6 +210,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21907 * second-to-last pointer (index -2 to end) in the
21908 * exception stack:
21909 */
21910 + if ((u16)stack_end[-1] != __KERNEL_DS)
21911 + goto out;
21912 stack = (unsigned long *) stack_end[-2];
21913 done = 0;
21914 break;
21915 @@ -219,7 +220,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21916
21917 if (ops->stack(data, "IRQ") < 0)
21918 break;
21919 - bp = ops->walk_stack(tinfo, stack, bp,
21920 + bp = ops->walk_stack(task, irq_stack, stack, bp,
21921 ops, data, stack_end, &graph);
21922 /*
21923 * We link to the next stack (which would be
21924 @@ -241,7 +242,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21925 /*
21926 * This handles the process stack:
21927 */
21928 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
21929 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
21930 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
21931 +out:
21932 put_cpu();
21933 }
21934 EXPORT_SYMBOL(dump_trace);
21935 @@ -350,3 +353,50 @@ int is_valid_bugaddr(unsigned long ip)
21936
21937 return ud2 == 0x0b0f;
21938 }
21939 +
21940 +#if defined(CONFIG_PAX_MEMORY_STACKLEAK) || defined(CONFIG_PAX_USERCOPY)
21941 +void pax_check_alloca(unsigned long size)
21942 +{
21943 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
21944 + unsigned cpu, used;
21945 + char *id;
21946 +
21947 + /* check the process stack first */
21948 + stack_start = (unsigned long)task_stack_page(current);
21949 + stack_end = stack_start + THREAD_SIZE;
21950 + if (likely(stack_start <= sp && sp < stack_end)) {
21951 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
21952 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
21953 + return;
21954 + }
21955 +
21956 + cpu = get_cpu();
21957 +
21958 + /* check the irq stacks */
21959 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
21960 + stack_start = stack_end - IRQ_STACK_SIZE;
21961 + if (stack_start <= sp && sp < stack_end) {
21962 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
21963 + put_cpu();
21964 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
21965 + return;
21966 + }
21967 +
21968 + /* check the exception stacks */
21969 + used = 0;
21970 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
21971 + stack_start = stack_end - EXCEPTION_STKSZ;
21972 + if (stack_end && stack_start <= sp && sp < stack_end) {
21973 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
21974 + put_cpu();
21975 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
21976 + return;
21977 + }
21978 +
21979 + put_cpu();
21980 +
21981 + /* unknown stack */
21982 + BUG();
21983 +}
21984 +EXPORT_SYMBOL(pax_check_alloca);
21985 +#endif
21986 diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
21987 index 988c00a..4f673b6 100644
21988 --- a/arch/x86/kernel/e820.c
21989 +++ b/arch/x86/kernel/e820.c
21990 @@ -803,8 +803,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
21991
21992 static void early_panic(char *msg)
21993 {
21994 - early_printk(msg);
21995 - panic(msg);
21996 + early_printk("%s", msg);
21997 + panic("%s", msg);
21998 }
21999
22000 static int userdef __initdata;
22001 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
22002 index 01d1c18..8073693 100644
22003 --- a/arch/x86/kernel/early_printk.c
22004 +++ b/arch/x86/kernel/early_printk.c
22005 @@ -7,6 +7,7 @@
22006 #include <linux/pci_regs.h>
22007 #include <linux/pci_ids.h>
22008 #include <linux/errno.h>
22009 +#include <linux/sched.h>
22010 #include <asm/io.h>
22011 #include <asm/processor.h>
22012 #include <asm/fcntl.h>
22013 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
22014 index 6491353..a918952 100644
22015 --- a/arch/x86/kernel/entry_32.S
22016 +++ b/arch/x86/kernel/entry_32.S
22017 @@ -177,13 +177,153 @@
22018 /*CFI_REL_OFFSET gs, PT_GS*/
22019 .endm
22020 .macro SET_KERNEL_GS reg
22021 +
22022 +#ifdef CONFIG_CC_STACKPROTECTOR
22023 movl $(__KERNEL_STACK_CANARY), \reg
22024 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
22025 + movl $(__USER_DS), \reg
22026 +#else
22027 + xorl \reg, \reg
22028 +#endif
22029 +
22030 movl \reg, %gs
22031 .endm
22032
22033 #endif /* CONFIG_X86_32_LAZY_GS */
22034
22035 -.macro SAVE_ALL
22036 +.macro pax_enter_kernel
22037 +#ifdef CONFIG_PAX_KERNEXEC
22038 + call pax_enter_kernel
22039 +#endif
22040 +.endm
22041 +
22042 +.macro pax_exit_kernel
22043 +#ifdef CONFIG_PAX_KERNEXEC
22044 + call pax_exit_kernel
22045 +#endif
22046 +.endm
22047 +
22048 +#ifdef CONFIG_PAX_KERNEXEC
22049 +ENTRY(pax_enter_kernel)
22050 +#ifdef CONFIG_PARAVIRT
22051 + pushl %eax
22052 + pushl %ecx
22053 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
22054 + mov %eax, %esi
22055 +#else
22056 + mov %cr0, %esi
22057 +#endif
22058 + bts $16, %esi
22059 + jnc 1f
22060 + mov %cs, %esi
22061 + cmp $__KERNEL_CS, %esi
22062 + jz 3f
22063 + ljmp $__KERNEL_CS, $3f
22064 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
22065 +2:
22066 +#ifdef CONFIG_PARAVIRT
22067 + mov %esi, %eax
22068 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
22069 +#else
22070 + mov %esi, %cr0
22071 +#endif
22072 +3:
22073 +#ifdef CONFIG_PARAVIRT
22074 + popl %ecx
22075 + popl %eax
22076 +#endif
22077 + ret
22078 +ENDPROC(pax_enter_kernel)
22079 +
22080 +ENTRY(pax_exit_kernel)
22081 +#ifdef CONFIG_PARAVIRT
22082 + pushl %eax
22083 + pushl %ecx
22084 +#endif
22085 + mov %cs, %esi
22086 + cmp $__KERNEXEC_KERNEL_CS, %esi
22087 + jnz 2f
22088 +#ifdef CONFIG_PARAVIRT
22089 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
22090 + mov %eax, %esi
22091 +#else
22092 + mov %cr0, %esi
22093 +#endif
22094 + btr $16, %esi
22095 + ljmp $__KERNEL_CS, $1f
22096 +1:
22097 +#ifdef CONFIG_PARAVIRT
22098 + mov %esi, %eax
22099 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
22100 +#else
22101 + mov %esi, %cr0
22102 +#endif
22103 +2:
22104 +#ifdef CONFIG_PARAVIRT
22105 + popl %ecx
22106 + popl %eax
22107 +#endif
22108 + ret
22109 +ENDPROC(pax_exit_kernel)
22110 +#endif
22111 +
22112 + .macro pax_erase_kstack
22113 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22114 + call pax_erase_kstack
22115 +#endif
22116 + .endm
22117 +
22118 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22119 +/*
22120 + * ebp: thread_info
22121 + */
22122 +ENTRY(pax_erase_kstack)
22123 + pushl %edi
22124 + pushl %ecx
22125 + pushl %eax
22126 +
22127 + mov TI_lowest_stack(%ebp), %edi
22128 + mov $-0xBEEF, %eax
22129 + std
22130 +
22131 +1: mov %edi, %ecx
22132 + and $THREAD_SIZE_asm - 1, %ecx
22133 + shr $2, %ecx
22134 + repne scasl
22135 + jecxz 2f
22136 +
22137 + cmp $2*16, %ecx
22138 + jc 2f
22139 +
22140 + mov $2*16, %ecx
22141 + repe scasl
22142 + jecxz 2f
22143 + jne 1b
22144 +
22145 +2: cld
22146 + mov %esp, %ecx
22147 + sub %edi, %ecx
22148 +
22149 + cmp $THREAD_SIZE_asm, %ecx
22150 + jb 3f
22151 + ud2
22152 +3:
22153 +
22154 + shr $2, %ecx
22155 + rep stosl
22156 +
22157 + mov TI_task_thread_sp0(%ebp), %edi
22158 + sub $128, %edi
22159 + mov %edi, TI_lowest_stack(%ebp)
22160 +
22161 + popl %eax
22162 + popl %ecx
22163 + popl %edi
22164 + ret
22165 +ENDPROC(pax_erase_kstack)
22166 +#endif
22167 +
22168 +.macro __SAVE_ALL _DS
22169 cld
22170 PUSH_GS
22171 pushl_cfi %fs
22172 @@ -206,7 +346,7 @@
22173 CFI_REL_OFFSET ecx, 0
22174 pushl_cfi %ebx
22175 CFI_REL_OFFSET ebx, 0
22176 - movl $(__USER_DS), %edx
22177 + movl $\_DS, %edx
22178 movl %edx, %ds
22179 movl %edx, %es
22180 movl $(__KERNEL_PERCPU), %edx
22181 @@ -214,6 +354,15 @@
22182 SET_KERNEL_GS %edx
22183 .endm
22184
22185 +.macro SAVE_ALL
22186 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22187 + __SAVE_ALL __KERNEL_DS
22188 + pax_enter_kernel
22189 +#else
22190 + __SAVE_ALL __USER_DS
22191 +#endif
22192 +.endm
22193 +
22194 .macro RESTORE_INT_REGS
22195 popl_cfi %ebx
22196 CFI_RESTORE ebx
22197 @@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
22198 popfl_cfi
22199 jmp syscall_exit
22200 CFI_ENDPROC
22201 -END(ret_from_fork)
22202 +ENDPROC(ret_from_fork)
22203
22204 ENTRY(ret_from_kernel_thread)
22205 CFI_STARTPROC
22206 @@ -344,7 +493,15 @@ ret_from_intr:
22207 andl $SEGMENT_RPL_MASK, %eax
22208 #endif
22209 cmpl $USER_RPL, %eax
22210 +
22211 +#ifdef CONFIG_PAX_KERNEXEC
22212 + jae resume_userspace
22213 +
22214 + pax_exit_kernel
22215 + jmp resume_kernel
22216 +#else
22217 jb resume_kernel # not returning to v8086 or userspace
22218 +#endif
22219
22220 ENTRY(resume_userspace)
22221 LOCKDEP_SYS_EXIT
22222 @@ -356,8 +513,8 @@ ENTRY(resume_userspace)
22223 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
22224 # int/exception return?
22225 jne work_pending
22226 - jmp restore_all
22227 -END(ret_from_exception)
22228 + jmp restore_all_pax
22229 +ENDPROC(ret_from_exception)
22230
22231 #ifdef CONFIG_PREEMPT
22232 ENTRY(resume_kernel)
22233 @@ -369,7 +526,7 @@ need_resched:
22234 jz restore_all
22235 call preempt_schedule_irq
22236 jmp need_resched
22237 -END(resume_kernel)
22238 +ENDPROC(resume_kernel)
22239 #endif
22240 CFI_ENDPROC
22241 /*
22242 @@ -403,30 +560,45 @@ sysenter_past_esp:
22243 /*CFI_REL_OFFSET cs, 0*/
22244 /*
22245 * Push current_thread_info()->sysenter_return to the stack.
22246 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
22247 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
22248 */
22249 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
22250 + pushl_cfi $0
22251 CFI_REL_OFFSET eip, 0
22252
22253 pushl_cfi %eax
22254 SAVE_ALL
22255 + GET_THREAD_INFO(%ebp)
22256 + movl TI_sysenter_return(%ebp),%ebp
22257 + movl %ebp,PT_EIP(%esp)
22258 ENABLE_INTERRUPTS(CLBR_NONE)
22259
22260 /*
22261 * Load the potential sixth argument from user stack.
22262 * Careful about security.
22263 */
22264 + movl PT_OLDESP(%esp),%ebp
22265 +
22266 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22267 + mov PT_OLDSS(%esp),%ds
22268 +1: movl %ds:(%ebp),%ebp
22269 + push %ss
22270 + pop %ds
22271 +#else
22272 cmpl $__PAGE_OFFSET-3,%ebp
22273 jae syscall_fault
22274 ASM_STAC
22275 1: movl (%ebp),%ebp
22276 ASM_CLAC
22277 +#endif
22278 +
22279 movl %ebp,PT_EBP(%esp)
22280 _ASM_EXTABLE(1b,syscall_fault)
22281
22282 GET_THREAD_INFO(%ebp)
22283
22284 +#ifdef CONFIG_PAX_RANDKSTACK
22285 + pax_erase_kstack
22286 +#endif
22287 +
22288 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22289 jnz sysenter_audit
22290 sysenter_do_call:
22291 @@ -442,12 +614,24 @@ sysenter_after_call:
22292 testl $_TIF_ALLWORK_MASK, %ecx
22293 jne sysexit_audit
22294 sysenter_exit:
22295 +
22296 +#ifdef CONFIG_PAX_RANDKSTACK
22297 + pushl_cfi %eax
22298 + movl %esp, %eax
22299 + call pax_randomize_kstack
22300 + popl_cfi %eax
22301 +#endif
22302 +
22303 + pax_erase_kstack
22304 +
22305 /* if something modifies registers it must also disable sysexit */
22306 movl PT_EIP(%esp), %edx
22307 movl PT_OLDESP(%esp), %ecx
22308 xorl %ebp,%ebp
22309 TRACE_IRQS_ON
22310 1: mov PT_FS(%esp), %fs
22311 +2: mov PT_DS(%esp), %ds
22312 +3: mov PT_ES(%esp), %es
22313 PTGS_TO_GS
22314 ENABLE_INTERRUPTS_SYSEXIT
22315
22316 @@ -464,6 +648,9 @@ sysenter_audit:
22317 movl %eax,%edx /* 2nd arg: syscall number */
22318 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
22319 call __audit_syscall_entry
22320 +
22321 + pax_erase_kstack
22322 +
22323 pushl_cfi %ebx
22324 movl PT_EAX(%esp),%eax /* reload syscall number */
22325 jmp sysenter_do_call
22326 @@ -489,10 +676,16 @@ sysexit_audit:
22327
22328 CFI_ENDPROC
22329 .pushsection .fixup,"ax"
22330 -2: movl $0,PT_FS(%esp)
22331 +4: movl $0,PT_FS(%esp)
22332 + jmp 1b
22333 +5: movl $0,PT_DS(%esp)
22334 + jmp 1b
22335 +6: movl $0,PT_ES(%esp)
22336 jmp 1b
22337 .popsection
22338 - _ASM_EXTABLE(1b,2b)
22339 + _ASM_EXTABLE(1b,4b)
22340 + _ASM_EXTABLE(2b,5b)
22341 + _ASM_EXTABLE(3b,6b)
22342 PTGS_TO_GS_EX
22343 ENDPROC(ia32_sysenter_target)
22344
22345 @@ -507,6 +700,11 @@ ENTRY(system_call)
22346 pushl_cfi %eax # save orig_eax
22347 SAVE_ALL
22348 GET_THREAD_INFO(%ebp)
22349 +
22350 +#ifdef CONFIG_PAX_RANDKSTACK
22351 + pax_erase_kstack
22352 +#endif
22353 +
22354 # system call tracing in operation / emulation
22355 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
22356 jnz syscall_trace_entry
22357 @@ -525,6 +723,15 @@ syscall_exit:
22358 testl $_TIF_ALLWORK_MASK, %ecx # current->work
22359 jne syscall_exit_work
22360
22361 +restore_all_pax:
22362 +
22363 +#ifdef CONFIG_PAX_RANDKSTACK
22364 + movl %esp, %eax
22365 + call pax_randomize_kstack
22366 +#endif
22367 +
22368 + pax_erase_kstack
22369 +
22370 restore_all:
22371 TRACE_IRQS_IRET
22372 restore_all_notrace:
22373 @@ -576,14 +783,34 @@ ldt_ss:
22374 * compensating for the offset by changing to the ESPFIX segment with
22375 * a base address that matches for the difference.
22376 */
22377 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
22378 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
22379 mov %esp, %edx /* load kernel esp */
22380 mov PT_OLDESP(%esp), %eax /* load userspace esp */
22381 mov %dx, %ax /* eax: new kernel esp */
22382 sub %eax, %edx /* offset (low word is 0) */
22383 +#ifdef CONFIG_SMP
22384 + movl PER_CPU_VAR(cpu_number), %ebx
22385 + shll $PAGE_SHIFT_asm, %ebx
22386 + addl $cpu_gdt_table, %ebx
22387 +#else
22388 + movl $cpu_gdt_table, %ebx
22389 +#endif
22390 shr $16, %edx
22391 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
22392 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
22393 +
22394 +#ifdef CONFIG_PAX_KERNEXEC
22395 + mov %cr0, %esi
22396 + btr $16, %esi
22397 + mov %esi, %cr0
22398 +#endif
22399 +
22400 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
22401 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
22402 +
22403 +#ifdef CONFIG_PAX_KERNEXEC
22404 + bts $16, %esi
22405 + mov %esi, %cr0
22406 +#endif
22407 +
22408 pushl_cfi $__ESPFIX_SS
22409 pushl_cfi %eax /* new kernel esp */
22410 /* Disable interrupts, but do not irqtrace this section: we
22411 @@ -612,20 +839,18 @@ work_resched:
22412 movl TI_flags(%ebp), %ecx
22413 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
22414 # than syscall tracing?
22415 - jz restore_all
22416 + jz restore_all_pax
22417 testb $_TIF_NEED_RESCHED, %cl
22418 jnz work_resched
22419
22420 work_notifysig: # deal with pending signals and
22421 # notify-resume requests
22422 + movl %esp, %eax
22423 #ifdef CONFIG_VM86
22424 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
22425 - movl %esp, %eax
22426 jne work_notifysig_v86 # returning to kernel-space or
22427 # vm86-space
22428 1:
22429 -#else
22430 - movl %esp, %eax
22431 #endif
22432 TRACE_IRQS_ON
22433 ENABLE_INTERRUPTS(CLBR_NONE)
22434 @@ -646,7 +871,7 @@ work_notifysig_v86:
22435 movl %eax, %esp
22436 jmp 1b
22437 #endif
22438 -END(work_pending)
22439 +ENDPROC(work_pending)
22440
22441 # perform syscall exit tracing
22442 ALIGN
22443 @@ -654,11 +879,14 @@ syscall_trace_entry:
22444 movl $-ENOSYS,PT_EAX(%esp)
22445 movl %esp, %eax
22446 call syscall_trace_enter
22447 +
22448 + pax_erase_kstack
22449 +
22450 /* What it returned is what we'll actually use. */
22451 cmpl $(NR_syscalls), %eax
22452 jnae syscall_call
22453 jmp syscall_exit
22454 -END(syscall_trace_entry)
22455 +ENDPROC(syscall_trace_entry)
22456
22457 # perform syscall exit tracing
22458 ALIGN
22459 @@ -671,26 +899,30 @@ syscall_exit_work:
22460 movl %esp, %eax
22461 call syscall_trace_leave
22462 jmp resume_userspace
22463 -END(syscall_exit_work)
22464 +ENDPROC(syscall_exit_work)
22465 CFI_ENDPROC
22466
22467 RING0_INT_FRAME # can't unwind into user space anyway
22468 syscall_fault:
22469 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22470 + push %ss
22471 + pop %ds
22472 +#endif
22473 ASM_CLAC
22474 GET_THREAD_INFO(%ebp)
22475 movl $-EFAULT,PT_EAX(%esp)
22476 jmp resume_userspace
22477 -END(syscall_fault)
22478 +ENDPROC(syscall_fault)
22479
22480 syscall_badsys:
22481 movl $-ENOSYS,PT_EAX(%esp)
22482 jmp syscall_exit
22483 -END(syscall_badsys)
22484 +ENDPROC(syscall_badsys)
22485
22486 sysenter_badsys:
22487 movl $-ENOSYS,PT_EAX(%esp)
22488 jmp sysenter_after_call
22489 -END(syscall_badsys)
22490 +ENDPROC(sysenter_badsys)
22491 CFI_ENDPROC
22492 /*
22493 * End of kprobes section
22494 @@ -706,8 +938,15 @@ END(syscall_badsys)
22495 * normal stack and adjusts ESP with the matching offset.
22496 */
22497 /* fixup the stack */
22498 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
22499 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
22500 +#ifdef CONFIG_SMP
22501 + movl PER_CPU_VAR(cpu_number), %ebx
22502 + shll $PAGE_SHIFT_asm, %ebx
22503 + addl $cpu_gdt_table, %ebx
22504 +#else
22505 + movl $cpu_gdt_table, %ebx
22506 +#endif
22507 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
22508 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
22509 shl $16, %eax
22510 addl %esp, %eax /* the adjusted stack pointer */
22511 pushl_cfi $__KERNEL_DS
22512 @@ -760,7 +999,7 @@ vector=vector+1
22513 .endr
22514 2: jmp common_interrupt
22515 .endr
22516 -END(irq_entries_start)
22517 +ENDPROC(irq_entries_start)
22518
22519 .previous
22520 END(interrupt)
22521 @@ -821,7 +1060,7 @@ ENTRY(coprocessor_error)
22522 pushl_cfi $do_coprocessor_error
22523 jmp error_code
22524 CFI_ENDPROC
22525 -END(coprocessor_error)
22526 +ENDPROC(coprocessor_error)
22527
22528 ENTRY(simd_coprocessor_error)
22529 RING0_INT_FRAME
22530 @@ -834,7 +1073,7 @@ ENTRY(simd_coprocessor_error)
22531 .section .altinstructions,"a"
22532 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
22533 .previous
22534 -.section .altinstr_replacement,"ax"
22535 +.section .altinstr_replacement,"a"
22536 663: pushl $do_simd_coprocessor_error
22537 664:
22538 .previous
22539 @@ -843,7 +1082,7 @@ ENTRY(simd_coprocessor_error)
22540 #endif
22541 jmp error_code
22542 CFI_ENDPROC
22543 -END(simd_coprocessor_error)
22544 +ENDPROC(simd_coprocessor_error)
22545
22546 ENTRY(device_not_available)
22547 RING0_INT_FRAME
22548 @@ -852,18 +1091,18 @@ ENTRY(device_not_available)
22549 pushl_cfi $do_device_not_available
22550 jmp error_code
22551 CFI_ENDPROC
22552 -END(device_not_available)
22553 +ENDPROC(device_not_available)
22554
22555 #ifdef CONFIG_PARAVIRT
22556 ENTRY(native_iret)
22557 iret
22558 _ASM_EXTABLE(native_iret, iret_exc)
22559 -END(native_iret)
22560 +ENDPROC(native_iret)
22561
22562 ENTRY(native_irq_enable_sysexit)
22563 sti
22564 sysexit
22565 -END(native_irq_enable_sysexit)
22566 +ENDPROC(native_irq_enable_sysexit)
22567 #endif
22568
22569 ENTRY(overflow)
22570 @@ -873,7 +1112,7 @@ ENTRY(overflow)
22571 pushl_cfi $do_overflow
22572 jmp error_code
22573 CFI_ENDPROC
22574 -END(overflow)
22575 +ENDPROC(overflow)
22576
22577 ENTRY(bounds)
22578 RING0_INT_FRAME
22579 @@ -882,7 +1121,7 @@ ENTRY(bounds)
22580 pushl_cfi $do_bounds
22581 jmp error_code
22582 CFI_ENDPROC
22583 -END(bounds)
22584 +ENDPROC(bounds)
22585
22586 ENTRY(invalid_op)
22587 RING0_INT_FRAME
22588 @@ -891,7 +1130,7 @@ ENTRY(invalid_op)
22589 pushl_cfi $do_invalid_op
22590 jmp error_code
22591 CFI_ENDPROC
22592 -END(invalid_op)
22593 +ENDPROC(invalid_op)
22594
22595 ENTRY(coprocessor_segment_overrun)
22596 RING0_INT_FRAME
22597 @@ -900,7 +1139,7 @@ ENTRY(coprocessor_segment_overrun)
22598 pushl_cfi $do_coprocessor_segment_overrun
22599 jmp error_code
22600 CFI_ENDPROC
22601 -END(coprocessor_segment_overrun)
22602 +ENDPROC(coprocessor_segment_overrun)
22603
22604 ENTRY(invalid_TSS)
22605 RING0_EC_FRAME
22606 @@ -908,7 +1147,7 @@ ENTRY(invalid_TSS)
22607 pushl_cfi $do_invalid_TSS
22608 jmp error_code
22609 CFI_ENDPROC
22610 -END(invalid_TSS)
22611 +ENDPROC(invalid_TSS)
22612
22613 ENTRY(segment_not_present)
22614 RING0_EC_FRAME
22615 @@ -916,7 +1155,7 @@ ENTRY(segment_not_present)
22616 pushl_cfi $do_segment_not_present
22617 jmp error_code
22618 CFI_ENDPROC
22619 -END(segment_not_present)
22620 +ENDPROC(segment_not_present)
22621
22622 ENTRY(stack_segment)
22623 RING0_EC_FRAME
22624 @@ -924,7 +1163,7 @@ ENTRY(stack_segment)
22625 pushl_cfi $do_stack_segment
22626 jmp error_code
22627 CFI_ENDPROC
22628 -END(stack_segment)
22629 +ENDPROC(stack_segment)
22630
22631 ENTRY(alignment_check)
22632 RING0_EC_FRAME
22633 @@ -932,7 +1171,7 @@ ENTRY(alignment_check)
22634 pushl_cfi $do_alignment_check
22635 jmp error_code
22636 CFI_ENDPROC
22637 -END(alignment_check)
22638 +ENDPROC(alignment_check)
22639
22640 ENTRY(divide_error)
22641 RING0_INT_FRAME
22642 @@ -941,7 +1180,7 @@ ENTRY(divide_error)
22643 pushl_cfi $do_divide_error
22644 jmp error_code
22645 CFI_ENDPROC
22646 -END(divide_error)
22647 +ENDPROC(divide_error)
22648
22649 #ifdef CONFIG_X86_MCE
22650 ENTRY(machine_check)
22651 @@ -951,7 +1190,7 @@ ENTRY(machine_check)
22652 pushl_cfi machine_check_vector
22653 jmp error_code
22654 CFI_ENDPROC
22655 -END(machine_check)
22656 +ENDPROC(machine_check)
22657 #endif
22658
22659 ENTRY(spurious_interrupt_bug)
22660 @@ -961,7 +1200,7 @@ ENTRY(spurious_interrupt_bug)
22661 pushl_cfi $do_spurious_interrupt_bug
22662 jmp error_code
22663 CFI_ENDPROC
22664 -END(spurious_interrupt_bug)
22665 +ENDPROC(spurious_interrupt_bug)
22666 /*
22667 * End of kprobes section
22668 */
22669 @@ -1071,7 +1310,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
22670
22671 ENTRY(mcount)
22672 ret
22673 -END(mcount)
22674 +ENDPROC(mcount)
22675
22676 ENTRY(ftrace_caller)
22677 cmpl $0, function_trace_stop
22678 @@ -1104,7 +1343,7 @@ ftrace_graph_call:
22679 .globl ftrace_stub
22680 ftrace_stub:
22681 ret
22682 -END(ftrace_caller)
22683 +ENDPROC(ftrace_caller)
22684
22685 ENTRY(ftrace_regs_caller)
22686 pushf /* push flags before compare (in cs location) */
22687 @@ -1208,7 +1447,7 @@ trace:
22688 popl %ecx
22689 popl %eax
22690 jmp ftrace_stub
22691 -END(mcount)
22692 +ENDPROC(mcount)
22693 #endif /* CONFIG_DYNAMIC_FTRACE */
22694 #endif /* CONFIG_FUNCTION_TRACER */
22695
22696 @@ -1226,7 +1465,7 @@ ENTRY(ftrace_graph_caller)
22697 popl %ecx
22698 popl %eax
22699 ret
22700 -END(ftrace_graph_caller)
22701 +ENDPROC(ftrace_graph_caller)
22702
22703 .globl return_to_handler
22704 return_to_handler:
22705 @@ -1292,15 +1531,18 @@ error_code:
22706 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
22707 REG_TO_PTGS %ecx
22708 SET_KERNEL_GS %ecx
22709 - movl $(__USER_DS), %ecx
22710 + movl $(__KERNEL_DS), %ecx
22711 movl %ecx, %ds
22712 movl %ecx, %es
22713 +
22714 + pax_enter_kernel
22715 +
22716 TRACE_IRQS_OFF
22717 movl %esp,%eax # pt_regs pointer
22718 call *%edi
22719 jmp ret_from_exception
22720 CFI_ENDPROC
22721 -END(page_fault)
22722 +ENDPROC(page_fault)
22723
22724 /*
22725 * Debug traps and NMI can happen at the one SYSENTER instruction
22726 @@ -1343,7 +1585,7 @@ debug_stack_correct:
22727 call do_debug
22728 jmp ret_from_exception
22729 CFI_ENDPROC
22730 -END(debug)
22731 +ENDPROC(debug)
22732
22733 /*
22734 * NMI is doubly nasty. It can happen _while_ we're handling
22735 @@ -1381,6 +1623,9 @@ nmi_stack_correct:
22736 xorl %edx,%edx # zero error code
22737 movl %esp,%eax # pt_regs pointer
22738 call do_nmi
22739 +
22740 + pax_exit_kernel
22741 +
22742 jmp restore_all_notrace
22743 CFI_ENDPROC
22744
22745 @@ -1417,12 +1662,15 @@ nmi_espfix_stack:
22746 FIXUP_ESPFIX_STACK # %eax == %esp
22747 xorl %edx,%edx # zero error code
22748 call do_nmi
22749 +
22750 + pax_exit_kernel
22751 +
22752 RESTORE_REGS
22753 lss 12+4(%esp), %esp # back to espfix stack
22754 CFI_ADJUST_CFA_OFFSET -24
22755 jmp irq_return
22756 CFI_ENDPROC
22757 -END(nmi)
22758 +ENDPROC(nmi)
22759
22760 ENTRY(int3)
22761 RING0_INT_FRAME
22762 @@ -1435,14 +1683,14 @@ ENTRY(int3)
22763 call do_int3
22764 jmp ret_from_exception
22765 CFI_ENDPROC
22766 -END(int3)
22767 +ENDPROC(int3)
22768
22769 ENTRY(general_protection)
22770 RING0_EC_FRAME
22771 pushl_cfi $do_general_protection
22772 jmp error_code
22773 CFI_ENDPROC
22774 -END(general_protection)
22775 +ENDPROC(general_protection)
22776
22777 #ifdef CONFIG_KVM_GUEST
22778 ENTRY(async_page_fault)
22779 @@ -1451,7 +1699,7 @@ ENTRY(async_page_fault)
22780 pushl_cfi $do_async_page_fault
22781 jmp error_code
22782 CFI_ENDPROC
22783 -END(async_page_fault)
22784 +ENDPROC(async_page_fault)
22785 #endif
22786
22787 /*
22788 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
22789 index 1e96c36..3ff710a 100644
22790 --- a/arch/x86/kernel/entry_64.S
22791 +++ b/arch/x86/kernel/entry_64.S
22792 @@ -59,6 +59,8 @@
22793 #include <asm/context_tracking.h>
22794 #include <asm/smap.h>
22795 #include <linux/err.h>
22796 +#include <asm/pgtable.h>
22797 +#include <asm/alternative-asm.h>
22798
22799 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
22800 #include <linux/elf-em.h>
22801 @@ -80,8 +82,9 @@
22802 #ifdef CONFIG_DYNAMIC_FTRACE
22803
22804 ENTRY(function_hook)
22805 + pax_force_retaddr
22806 retq
22807 -END(function_hook)
22808 +ENDPROC(function_hook)
22809
22810 /* skip is set if stack has been adjusted */
22811 .macro ftrace_caller_setup skip=0
22812 @@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
22813 #endif
22814
22815 GLOBAL(ftrace_stub)
22816 + pax_force_retaddr
22817 retq
22818 -END(ftrace_caller)
22819 +ENDPROC(ftrace_caller)
22820
22821 ENTRY(ftrace_regs_caller)
22822 /* Save the current flags before compare (in SS location)*/
22823 @@ -191,7 +195,7 @@ ftrace_restore_flags:
22824 popfq
22825 jmp ftrace_stub
22826
22827 -END(ftrace_regs_caller)
22828 +ENDPROC(ftrace_regs_caller)
22829
22830
22831 #else /* ! CONFIG_DYNAMIC_FTRACE */
22832 @@ -212,6 +216,7 @@ ENTRY(function_hook)
22833 #endif
22834
22835 GLOBAL(ftrace_stub)
22836 + pax_force_retaddr
22837 retq
22838
22839 trace:
22840 @@ -225,12 +230,13 @@ trace:
22841 #endif
22842 subq $MCOUNT_INSN_SIZE, %rdi
22843
22844 + pax_force_fptr ftrace_trace_function
22845 call *ftrace_trace_function
22846
22847 MCOUNT_RESTORE_FRAME
22848
22849 jmp ftrace_stub
22850 -END(function_hook)
22851 +ENDPROC(function_hook)
22852 #endif /* CONFIG_DYNAMIC_FTRACE */
22853 #endif /* CONFIG_FUNCTION_TRACER */
22854
22855 @@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
22856
22857 MCOUNT_RESTORE_FRAME
22858
22859 + pax_force_retaddr
22860 retq
22861 -END(ftrace_graph_caller)
22862 +ENDPROC(ftrace_graph_caller)
22863
22864 GLOBAL(return_to_handler)
22865 subq $24, %rsp
22866 @@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
22867 movq 8(%rsp), %rdx
22868 movq (%rsp), %rax
22869 addq $24, %rsp
22870 + pax_force_fptr %rdi
22871 jmp *%rdi
22872 +ENDPROC(return_to_handler)
22873 #endif
22874
22875
22876 @@ -284,6 +293,430 @@ ENTRY(native_usergs_sysret64)
22877 ENDPROC(native_usergs_sysret64)
22878 #endif /* CONFIG_PARAVIRT */
22879
22880 + .macro ljmpq sel, off
22881 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
22882 + .byte 0x48; ljmp *1234f(%rip)
22883 + .pushsection .rodata
22884 + .align 16
22885 + 1234: .quad \off; .word \sel
22886 + .popsection
22887 +#else
22888 + pushq $\sel
22889 + pushq $\off
22890 + lretq
22891 +#endif
22892 + .endm
22893 +
22894 + .macro pax_enter_kernel
22895 + pax_set_fptr_mask
22896 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22897 + call pax_enter_kernel
22898 +#endif
22899 + .endm
22900 +
22901 + .macro pax_exit_kernel
22902 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22903 + call pax_exit_kernel
22904 +#endif
22905 +
22906 + .endm
22907 +
22908 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22909 +ENTRY(pax_enter_kernel)
22910 + pushq %rdi
22911 +
22912 +#ifdef CONFIG_PARAVIRT
22913 + PV_SAVE_REGS(CLBR_RDI)
22914 +#endif
22915 +
22916 +#ifdef CONFIG_PAX_KERNEXEC
22917 + GET_CR0_INTO_RDI
22918 + bts $16,%rdi
22919 + jnc 3f
22920 + mov %cs,%edi
22921 + cmp $__KERNEL_CS,%edi
22922 + jnz 2f
22923 +1:
22924 +#endif
22925 +
22926 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22927 + 661: jmp 111f
22928 + .pushsection .altinstr_replacement, "a"
22929 + 662: ASM_NOP2
22930 + .popsection
22931 + .pushsection .altinstructions, "a"
22932 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22933 + .popsection
22934 + GET_CR3_INTO_RDI
22935 + cmp $0,%dil
22936 + jnz 112f
22937 + mov $__KERNEL_DS,%edi
22938 + mov %edi,%ss
22939 + jmp 111f
22940 +112: cmp $1,%dil
22941 + jz 113f
22942 + ud2
22943 +113: sub $4097,%rdi
22944 + bts $63,%rdi
22945 + SET_RDI_INTO_CR3
22946 + mov $__UDEREF_KERNEL_DS,%edi
22947 + mov %edi,%ss
22948 +111:
22949 +#endif
22950 +
22951 +#ifdef CONFIG_PARAVIRT
22952 + PV_RESTORE_REGS(CLBR_RDI)
22953 +#endif
22954 +
22955 + popq %rdi
22956 + pax_force_retaddr
22957 + retq
22958 +
22959 +#ifdef CONFIG_PAX_KERNEXEC
22960 +2: ljmpq __KERNEL_CS,1b
22961 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
22962 +4: SET_RDI_INTO_CR0
22963 + jmp 1b
22964 +#endif
22965 +ENDPROC(pax_enter_kernel)
22966 +
22967 +ENTRY(pax_exit_kernel)
22968 + pushq %rdi
22969 +
22970 +#ifdef CONFIG_PARAVIRT
22971 + PV_SAVE_REGS(CLBR_RDI)
22972 +#endif
22973 +
22974 +#ifdef CONFIG_PAX_KERNEXEC
22975 + mov %cs,%rdi
22976 + cmp $__KERNEXEC_KERNEL_CS,%edi
22977 + jz 2f
22978 + GET_CR0_INTO_RDI
22979 + bts $16,%rdi
22980 + jnc 4f
22981 +1:
22982 +#endif
22983 +
22984 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22985 + 661: jmp 111f
22986 + .pushsection .altinstr_replacement, "a"
22987 + 662: ASM_NOP2
22988 + .popsection
22989 + .pushsection .altinstructions, "a"
22990 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22991 + .popsection
22992 + mov %ss,%edi
22993 + cmp $__UDEREF_KERNEL_DS,%edi
22994 + jnz 111f
22995 + GET_CR3_INTO_RDI
22996 + cmp $0,%dil
22997 + jz 112f
22998 + ud2
22999 +112: add $4097,%rdi
23000 + bts $63,%rdi
23001 + SET_RDI_INTO_CR3
23002 + mov $__KERNEL_DS,%edi
23003 + mov %edi,%ss
23004 +111:
23005 +#endif
23006 +
23007 +#ifdef CONFIG_PARAVIRT
23008 + PV_RESTORE_REGS(CLBR_RDI);
23009 +#endif
23010 +
23011 + popq %rdi
23012 + pax_force_retaddr
23013 + retq
23014 +
23015 +#ifdef CONFIG_PAX_KERNEXEC
23016 +2: GET_CR0_INTO_RDI
23017 + btr $16,%rdi
23018 + jnc 4f
23019 + ljmpq __KERNEL_CS,3f
23020 +3: SET_RDI_INTO_CR0
23021 + jmp 1b
23022 +4: ud2
23023 + jmp 4b
23024 +#endif
23025 +ENDPROC(pax_exit_kernel)
23026 +#endif
23027 +
23028 + .macro pax_enter_kernel_user
23029 + pax_set_fptr_mask
23030 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23031 + call pax_enter_kernel_user
23032 +#endif
23033 + .endm
23034 +
23035 + .macro pax_exit_kernel_user
23036 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23037 + call pax_exit_kernel_user
23038 +#endif
23039 +#ifdef CONFIG_PAX_RANDKSTACK
23040 + pushq %rax
23041 + pushq %r11
23042 + call pax_randomize_kstack
23043 + popq %r11
23044 + popq %rax
23045 +#endif
23046 + .endm
23047 +
23048 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23049 +ENTRY(pax_enter_kernel_user)
23050 + pushq %rdi
23051 + pushq %rbx
23052 +
23053 +#ifdef CONFIG_PARAVIRT
23054 + PV_SAVE_REGS(CLBR_RDI)
23055 +#endif
23056 +
23057 + 661: jmp 111f
23058 + .pushsection .altinstr_replacement, "a"
23059 + 662: ASM_NOP2
23060 + .popsection
23061 + .pushsection .altinstructions, "a"
23062 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23063 + .popsection
23064 + GET_CR3_INTO_RDI
23065 + cmp $1,%dil
23066 + jnz 4f
23067 + sub $4097,%rdi
23068 + bts $63,%rdi
23069 + SET_RDI_INTO_CR3
23070 + jmp 3f
23071 +111:
23072 +
23073 + GET_CR3_INTO_RDI
23074 + mov %rdi,%rbx
23075 + add $__START_KERNEL_map,%rbx
23076 + sub phys_base(%rip),%rbx
23077 +
23078 +#ifdef CONFIG_PARAVIRT
23079 + cmpl $0, pv_info+PARAVIRT_enabled
23080 + jz 1f
23081 + pushq %rdi
23082 + i = 0
23083 + .rept USER_PGD_PTRS
23084 + mov i*8(%rbx),%rsi
23085 + mov $0,%sil
23086 + lea i*8(%rbx),%rdi
23087 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23088 + i = i + 1
23089 + .endr
23090 + popq %rdi
23091 + jmp 2f
23092 +1:
23093 +#endif
23094 +
23095 + i = 0
23096 + .rept USER_PGD_PTRS
23097 + movb $0,i*8(%rbx)
23098 + i = i + 1
23099 + .endr
23100 +
23101 +2: SET_RDI_INTO_CR3
23102 +
23103 +#ifdef CONFIG_PAX_KERNEXEC
23104 + GET_CR0_INTO_RDI
23105 + bts $16,%rdi
23106 + SET_RDI_INTO_CR0
23107 +#endif
23108 +
23109 +3:
23110 +
23111 +#ifdef CONFIG_PARAVIRT
23112 + PV_RESTORE_REGS(CLBR_RDI)
23113 +#endif
23114 +
23115 + popq %rbx
23116 + popq %rdi
23117 + pax_force_retaddr
23118 + retq
23119 +4: ud2
23120 +ENDPROC(pax_enter_kernel_user)
23121 +
23122 +ENTRY(pax_exit_kernel_user)
23123 + pushq %rdi
23124 + pushq %rbx
23125 +
23126 +#ifdef CONFIG_PARAVIRT
23127 + PV_SAVE_REGS(CLBR_RDI)
23128 +#endif
23129 +
23130 + GET_CR3_INTO_RDI
23131 + 661: jmp 1f
23132 + .pushsection .altinstr_replacement, "a"
23133 + 662: ASM_NOP2
23134 + .popsection
23135 + .pushsection .altinstructions, "a"
23136 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23137 + .popsection
23138 + cmp $0,%dil
23139 + jnz 3f
23140 + add $4097,%rdi
23141 + bts $63,%rdi
23142 + SET_RDI_INTO_CR3
23143 + jmp 2f
23144 +1:
23145 +
23146 + mov %rdi,%rbx
23147 +
23148 +#ifdef CONFIG_PAX_KERNEXEC
23149 + GET_CR0_INTO_RDI
23150 + btr $16,%rdi
23151 + jnc 3f
23152 + SET_RDI_INTO_CR0
23153 +#endif
23154 +
23155 + add $__START_KERNEL_map,%rbx
23156 + sub phys_base(%rip),%rbx
23157 +
23158 +#ifdef CONFIG_PARAVIRT
23159 + cmpl $0, pv_info+PARAVIRT_enabled
23160 + jz 1f
23161 + i = 0
23162 + .rept USER_PGD_PTRS
23163 + mov i*8(%rbx),%rsi
23164 + mov $0x67,%sil
23165 + lea i*8(%rbx),%rdi
23166 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
23167 + i = i + 1
23168 + .endr
23169 + jmp 2f
23170 +1:
23171 +#endif
23172 +
23173 + i = 0
23174 + .rept USER_PGD_PTRS
23175 + movb $0x67,i*8(%rbx)
23176 + i = i + 1
23177 + .endr
23178 +2:
23179 +
23180 +#ifdef CONFIG_PARAVIRT
23181 + PV_RESTORE_REGS(CLBR_RDI)
23182 +#endif
23183 +
23184 + popq %rbx
23185 + popq %rdi
23186 + pax_force_retaddr
23187 + retq
23188 +3: ud2
23189 +ENDPROC(pax_exit_kernel_user)
23190 +#endif
23191 +
23192 + .macro pax_enter_kernel_nmi
23193 + pax_set_fptr_mask
23194 +
23195 +#ifdef CONFIG_PAX_KERNEXEC
23196 + GET_CR0_INTO_RDI
23197 + bts $16,%rdi
23198 + jc 110f
23199 + SET_RDI_INTO_CR0
23200 + or $2,%ebx
23201 +110:
23202 +#endif
23203 +
23204 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23205 + 661: jmp 111f
23206 + .pushsection .altinstr_replacement, "a"
23207 + 662: ASM_NOP2
23208 + .popsection
23209 + .pushsection .altinstructions, "a"
23210 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
23211 + .popsection
23212 + GET_CR3_INTO_RDI
23213 + cmp $0,%dil
23214 + jz 111f
23215 + sub $4097,%rdi
23216 + or $4,%ebx
23217 + bts $63,%rdi
23218 + SET_RDI_INTO_CR3
23219 + mov $__UDEREF_KERNEL_DS,%edi
23220 + mov %edi,%ss
23221 +111:
23222 +#endif
23223 + .endm
23224 +
23225 + .macro pax_exit_kernel_nmi
23226 +#ifdef CONFIG_PAX_KERNEXEC
23227 + btr $1,%ebx
23228 + jnc 110f
23229 + GET_CR0_INTO_RDI
23230 + btr $16,%rdi
23231 + SET_RDI_INTO_CR0
23232 +110:
23233 +#endif
23234 +
23235 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23236 + btr $2,%ebx
23237 + jnc 111f
23238 + GET_CR3_INTO_RDI
23239 + add $4097,%rdi
23240 + bts $63,%rdi
23241 + SET_RDI_INTO_CR3
23242 + mov $__KERNEL_DS,%edi
23243 + mov %edi,%ss
23244 +111:
23245 +#endif
23246 + .endm
23247 +
23248 + .macro pax_erase_kstack
23249 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23250 + call pax_erase_kstack
23251 +#endif
23252 + .endm
23253 +
23254 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
23255 +ENTRY(pax_erase_kstack)
23256 + pushq %rdi
23257 + pushq %rcx
23258 + pushq %rax
23259 + pushq %r11
23260 +
23261 + GET_THREAD_INFO(%r11)
23262 + mov TI_lowest_stack(%r11), %rdi
23263 + mov $-0xBEEF, %rax
23264 + std
23265 +
23266 +1: mov %edi, %ecx
23267 + and $THREAD_SIZE_asm - 1, %ecx
23268 + shr $3, %ecx
23269 + repne scasq
23270 + jecxz 2f
23271 +
23272 + cmp $2*8, %ecx
23273 + jc 2f
23274 +
23275 + mov $2*8, %ecx
23276 + repe scasq
23277 + jecxz 2f
23278 + jne 1b
23279 +
23280 +2: cld
23281 + mov %esp, %ecx
23282 + sub %edi, %ecx
23283 +
23284 + cmp $THREAD_SIZE_asm, %rcx
23285 + jb 3f
23286 + ud2
23287 +3:
23288 +
23289 + shr $3, %ecx
23290 + rep stosq
23291 +
23292 + mov TI_task_thread_sp0(%r11), %rdi
23293 + sub $256, %rdi
23294 + mov %rdi, TI_lowest_stack(%r11)
23295 +
23296 + popq %r11
23297 + popq %rax
23298 + popq %rcx
23299 + popq %rdi
23300 + pax_force_retaddr
23301 + ret
23302 +ENDPROC(pax_erase_kstack)
23303 +#endif
23304
23305 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
23306 #ifdef CONFIG_TRACE_IRQFLAGS
23307 @@ -320,7 +753,7 @@ ENDPROC(native_usergs_sysret64)
23308 .endm
23309
23310 .macro TRACE_IRQS_IRETQ_DEBUG offset=ARGOFFSET
23311 - bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
23312 + bt $X86_EFLAGS_IF_BIT,EFLAGS-\offset(%rsp) /* interrupts off? */
23313 jnc 1f
23314 TRACE_IRQS_ON_DEBUG
23315 1:
23316 @@ -358,27 +791,6 @@ ENDPROC(native_usergs_sysret64)
23317 movq \tmp,R11+\offset(%rsp)
23318 .endm
23319
23320 - .macro FAKE_STACK_FRAME child_rip
23321 - /* push in order ss, rsp, eflags, cs, rip */
23322 - xorl %eax, %eax
23323 - pushq_cfi $__KERNEL_DS /* ss */
23324 - /*CFI_REL_OFFSET ss,0*/
23325 - pushq_cfi %rax /* rsp */
23326 - CFI_REL_OFFSET rsp,0
23327 - pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) /* eflags - interrupts on */
23328 - /*CFI_REL_OFFSET rflags,0*/
23329 - pushq_cfi $__KERNEL_CS /* cs */
23330 - /*CFI_REL_OFFSET cs,0*/
23331 - pushq_cfi \child_rip /* rip */
23332 - CFI_REL_OFFSET rip,0
23333 - pushq_cfi %rax /* orig rax */
23334 - .endm
23335 -
23336 - .macro UNFAKE_STACK_FRAME
23337 - addq $8*6, %rsp
23338 - CFI_ADJUST_CFA_OFFSET -(6*8)
23339 - .endm
23340 -
23341 /*
23342 * initial frame state for interrupts (and exceptions without error code)
23343 */
23344 @@ -445,25 +857,26 @@ ENDPROC(native_usergs_sysret64)
23345 /* save partial stack frame */
23346 .macro SAVE_ARGS_IRQ
23347 cld
23348 - /* start from rbp in pt_regs and jump over */
23349 - movq_cfi rdi, (RDI-RBP)
23350 - movq_cfi rsi, (RSI-RBP)
23351 - movq_cfi rdx, (RDX-RBP)
23352 - movq_cfi rcx, (RCX-RBP)
23353 - movq_cfi rax, (RAX-RBP)
23354 - movq_cfi r8, (R8-RBP)
23355 - movq_cfi r9, (R9-RBP)
23356 - movq_cfi r10, (R10-RBP)
23357 - movq_cfi r11, (R11-RBP)
23358 + /* start from r15 in pt_regs and jump over */
23359 + movq_cfi rdi, RDI
23360 + movq_cfi rsi, RSI
23361 + movq_cfi rdx, RDX
23362 + movq_cfi rcx, RCX
23363 + movq_cfi rax, RAX
23364 + movq_cfi r8, R8
23365 + movq_cfi r9, R9
23366 + movq_cfi r10, R10
23367 + movq_cfi r11, R11
23368 + movq_cfi r12, R12
23369
23370 /* Save rbp so that we can unwind from get_irq_regs() */
23371 - movq_cfi rbp, 0
23372 + movq_cfi rbp, RBP
23373
23374 /* Save previous stack value */
23375 movq %rsp, %rsi
23376
23377 - leaq -RBP(%rsp),%rdi /* arg1 for handler */
23378 - testl $3, CS-RBP(%rsi)
23379 + movq %rsp,%rdi /* arg1 for handler */
23380 + testb $3, CS(%rsi)
23381 je 1f
23382 SWAPGS
23383 /*
23384 @@ -483,6 +896,18 @@ ENDPROC(native_usergs_sysret64)
23385 0x06 /* DW_OP_deref */, \
23386 0x08 /* DW_OP_const1u */, SS+8-RBP, \
23387 0x22 /* DW_OP_plus */
23388 +
23389 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23390 + testb $3, CS(%rdi)
23391 + jnz 1f
23392 + pax_enter_kernel
23393 + jmp 2f
23394 +1: pax_enter_kernel_user
23395 +2:
23396 +#else
23397 + pax_enter_kernel
23398 +#endif
23399 +
23400 /* We entered an interrupt context - irqs are off: */
23401 TRACE_IRQS_OFF
23402 .endm
23403 @@ -514,9 +939,52 @@ ENTRY(save_paranoid)
23404 js 1f /* negative -> in kernel */
23405 SWAPGS
23406 xorl %ebx,%ebx
23407 -1: ret
23408 +1:
23409 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23410 + testb $3, CS+8(%rsp)
23411 + jnz 1f
23412 + pax_enter_kernel
23413 + jmp 2f
23414 +1: pax_enter_kernel_user
23415 +2:
23416 +#else
23417 + pax_enter_kernel
23418 +#endif
23419 + pax_force_retaddr
23420 + ret
23421 CFI_ENDPROC
23422 -END(save_paranoid)
23423 +ENDPROC(save_paranoid)
23424 +
23425 +ENTRY(save_paranoid_nmi)
23426 + XCPT_FRAME 1 RDI+8
23427 + cld
23428 + movq_cfi rdi, RDI+8
23429 + movq_cfi rsi, RSI+8
23430 + movq_cfi rdx, RDX+8
23431 + movq_cfi rcx, RCX+8
23432 + movq_cfi rax, RAX+8
23433 + movq_cfi r8, R8+8
23434 + movq_cfi r9, R9+8
23435 + movq_cfi r10, R10+8
23436 + movq_cfi r11, R11+8
23437 + movq_cfi rbx, RBX+8
23438 + movq_cfi rbp, RBP+8
23439 + movq_cfi r12, R12+8
23440 + movq_cfi r13, R13+8
23441 + movq_cfi r14, R14+8
23442 + movq_cfi r15, R15+8
23443 + movl $1,%ebx
23444 + movl $MSR_GS_BASE,%ecx
23445 + rdmsr
23446 + testl %edx,%edx
23447 + js 1f /* negative -> in kernel */
23448 + SWAPGS
23449 + xorl %ebx,%ebx
23450 +1: pax_enter_kernel_nmi
23451 + pax_force_retaddr
23452 + ret
23453 + CFI_ENDPROC
23454 +ENDPROC(save_paranoid_nmi)
23455 .popsection
23456
23457 /*
23458 @@ -538,7 +1006,7 @@ ENTRY(ret_from_fork)
23459
23460 RESTORE_REST
23461
23462 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23463 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
23464 jz 1f
23465
23466 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
23467 @@ -548,15 +1016,13 @@ ENTRY(ret_from_fork)
23468 jmp ret_from_sys_call # go to the SYSRET fastpath
23469
23470 1:
23471 - subq $REST_SKIP, %rsp # leave space for volatiles
23472 - CFI_ADJUST_CFA_OFFSET REST_SKIP
23473 movq %rbp, %rdi
23474 call *%rbx
23475 movl $0, RAX(%rsp)
23476 RESTORE_REST
23477 jmp int_ret_from_sys_call
23478 CFI_ENDPROC
23479 -END(ret_from_fork)
23480 +ENDPROC(ret_from_fork)
23481
23482 /*
23483 * System call entry. Up to 6 arguments in registers are supported.
23484 @@ -593,7 +1059,7 @@ END(ret_from_fork)
23485 ENTRY(system_call)
23486 CFI_STARTPROC simple
23487 CFI_SIGNAL_FRAME
23488 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
23489 + CFI_DEF_CFA rsp,0
23490 CFI_REGISTER rip,rcx
23491 /*CFI_REGISTER rflags,r11*/
23492 SWAPGS_UNSAFE_STACK
23493 @@ -606,16 +1072,23 @@ GLOBAL(system_call_after_swapgs)
23494
23495 movq %rsp,PER_CPU_VAR(old_rsp)
23496 movq PER_CPU_VAR(kernel_stack),%rsp
23497 + SAVE_ARGS 8*6,0
23498 + pax_enter_kernel_user
23499 +
23500 +#ifdef CONFIG_PAX_RANDKSTACK
23501 + pax_erase_kstack
23502 +#endif
23503 +
23504 /*
23505 * No need to follow this irqs off/on section - it's straight
23506 * and short:
23507 */
23508 ENABLE_INTERRUPTS(CLBR_NONE)
23509 - SAVE_ARGS 8,0
23510 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
23511 movq %rcx,RIP-ARGOFFSET(%rsp)
23512 CFI_REL_OFFSET rip,RIP-ARGOFFSET
23513 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23514 + GET_THREAD_INFO(%rcx)
23515 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
23516 jnz tracesys
23517 system_call_fastpath:
23518 #if __SYSCALL_MASK == ~0
23519 @@ -639,10 +1112,13 @@ sysret_check:
23520 LOCKDEP_SYS_EXIT
23521 DISABLE_INTERRUPTS(CLBR_NONE)
23522 TRACE_IRQS_OFF
23523 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
23524 + GET_THREAD_INFO(%rcx)
23525 + movl TI_flags(%rcx),%edx
23526 andl %edi,%edx
23527 jnz sysret_careful
23528 CFI_REMEMBER_STATE
23529 + pax_exit_kernel_user
23530 + pax_erase_kstack
23531 /*
23532 * sysretq will re-enable interrupts:
23533 */
23534 @@ -701,6 +1177,9 @@ auditsys:
23535 movq %rax,%rsi /* 2nd arg: syscall number */
23536 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
23537 call __audit_syscall_entry
23538 +
23539 + pax_erase_kstack
23540 +
23541 LOAD_ARGS 0 /* reload call-clobbered registers */
23542 jmp system_call_fastpath
23543
23544 @@ -722,7 +1201,7 @@ sysret_audit:
23545 /* Do syscall tracing */
23546 tracesys:
23547 #ifdef CONFIG_AUDITSYSCALL
23548 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
23549 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
23550 jz auditsys
23551 #endif
23552 SAVE_REST
23553 @@ -730,12 +1209,15 @@ tracesys:
23554 FIXUP_TOP_OF_STACK %rdi
23555 movq %rsp,%rdi
23556 call syscall_trace_enter
23557 +
23558 + pax_erase_kstack
23559 +
23560 /*
23561 * Reload arg registers from stack in case ptrace changed them.
23562 * We don't reload %rax because syscall_trace_enter() returned
23563 * the value it wants us to use in the table lookup.
23564 */
23565 - LOAD_ARGS ARGOFFSET, 1
23566 + LOAD_ARGS 1
23567 RESTORE_REST
23568 #if __SYSCALL_MASK == ~0
23569 cmpq $__NR_syscall_max,%rax
23570 @@ -765,7 +1247,9 @@ GLOBAL(int_with_check)
23571 andl %edi,%edx
23572 jnz int_careful
23573 andl $~TS_COMPAT,TI_status(%rcx)
23574 - jmp retint_swapgs
23575 + pax_exit_kernel_user
23576 + pax_erase_kstack
23577 + jmp retint_swapgs_pax
23578
23579 /* Either reschedule or signal or syscall exit tracking needed. */
23580 /* First do a reschedule test. */
23581 @@ -811,7 +1295,7 @@ int_restore_rest:
23582 TRACE_IRQS_OFF
23583 jmp int_with_check
23584 CFI_ENDPROC
23585 -END(system_call)
23586 +ENDPROC(system_call)
23587
23588 .macro FORK_LIKE func
23589 ENTRY(stub_\func)
23590 @@ -824,9 +1308,10 @@ ENTRY(stub_\func)
23591 DEFAULT_FRAME 0 8 /* offset 8: return address */
23592 call sys_\func
23593 RESTORE_TOP_OF_STACK %r11, 8
23594 - ret $REST_SKIP /* pop extended registers */
23595 + pax_force_retaddr
23596 + ret
23597 CFI_ENDPROC
23598 -END(stub_\func)
23599 +ENDPROC(stub_\func)
23600 .endm
23601
23602 .macro FIXED_FRAME label,func
23603 @@ -836,9 +1321,10 @@ ENTRY(\label)
23604 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
23605 call \func
23606 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
23607 + pax_force_retaddr
23608 ret
23609 CFI_ENDPROC
23610 -END(\label)
23611 +ENDPROC(\label)
23612 .endm
23613
23614 FORK_LIKE clone
23615 @@ -846,19 +1332,6 @@ END(\label)
23616 FORK_LIKE vfork
23617 FIXED_FRAME stub_iopl, sys_iopl
23618
23619 -ENTRY(ptregscall_common)
23620 - DEFAULT_FRAME 1 8 /* offset 8: return address */
23621 - RESTORE_TOP_OF_STACK %r11, 8
23622 - movq_cfi_restore R15+8, r15
23623 - movq_cfi_restore R14+8, r14
23624 - movq_cfi_restore R13+8, r13
23625 - movq_cfi_restore R12+8, r12
23626 - movq_cfi_restore RBP+8, rbp
23627 - movq_cfi_restore RBX+8, rbx
23628 - ret $REST_SKIP /* pop extended registers */
23629 - CFI_ENDPROC
23630 -END(ptregscall_common)
23631 -
23632 ENTRY(stub_execve)
23633 CFI_STARTPROC
23634 addq $8, %rsp
23635 @@ -870,7 +1343,7 @@ ENTRY(stub_execve)
23636 RESTORE_REST
23637 jmp int_ret_from_sys_call
23638 CFI_ENDPROC
23639 -END(stub_execve)
23640 +ENDPROC(stub_execve)
23641
23642 /*
23643 * sigreturn is special because it needs to restore all registers on return.
23644 @@ -887,7 +1360,7 @@ ENTRY(stub_rt_sigreturn)
23645 RESTORE_REST
23646 jmp int_ret_from_sys_call
23647 CFI_ENDPROC
23648 -END(stub_rt_sigreturn)
23649 +ENDPROC(stub_rt_sigreturn)
23650
23651 #ifdef CONFIG_X86_X32_ABI
23652 ENTRY(stub_x32_rt_sigreturn)
23653 @@ -901,7 +1374,7 @@ ENTRY(stub_x32_rt_sigreturn)
23654 RESTORE_REST
23655 jmp int_ret_from_sys_call
23656 CFI_ENDPROC
23657 -END(stub_x32_rt_sigreturn)
23658 +ENDPROC(stub_x32_rt_sigreturn)
23659
23660 ENTRY(stub_x32_execve)
23661 CFI_STARTPROC
23662 @@ -915,7 +1388,7 @@ ENTRY(stub_x32_execve)
23663 RESTORE_REST
23664 jmp int_ret_from_sys_call
23665 CFI_ENDPROC
23666 -END(stub_x32_execve)
23667 +ENDPROC(stub_x32_execve)
23668
23669 #endif
23670
23671 @@ -952,7 +1425,7 @@ vector=vector+1
23672 2: jmp common_interrupt
23673 .endr
23674 CFI_ENDPROC
23675 -END(irq_entries_start)
23676 +ENDPROC(irq_entries_start)
23677
23678 .previous
23679 END(interrupt)
23680 @@ -969,8 +1442,8 @@ END(interrupt)
23681 /* 0(%rsp): ~(interrupt number) */
23682 .macro interrupt func
23683 /* reserve pt_regs for scratch regs and rbp */
23684 - subq $ORIG_RAX-RBP, %rsp
23685 - CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
23686 + subq $ORIG_RAX, %rsp
23687 + CFI_ADJUST_CFA_OFFSET ORIG_RAX
23688 SAVE_ARGS_IRQ
23689 call \func
23690 .endm
23691 @@ -997,14 +1470,14 @@ ret_from_intr:
23692
23693 /* Restore saved previous stack */
23694 popq %rsi
23695 - CFI_DEF_CFA rsi,SS+8-RBP /* reg/off reset after def_cfa_expr */
23696 - leaq ARGOFFSET-RBP(%rsi), %rsp
23697 + CFI_DEF_CFA rsi,SS+8 /* reg/off reset after def_cfa_expr */
23698 + movq %rsi, %rsp
23699 CFI_DEF_CFA_REGISTER rsp
23700 - CFI_ADJUST_CFA_OFFSET RBP-ARGOFFSET
23701 + CFI_ADJUST_CFA_OFFSET -ARGOFFSET
23702
23703 exit_intr:
23704 GET_THREAD_INFO(%rcx)
23705 - testl $3,CS-ARGOFFSET(%rsp)
23706 + testb $3,CS-ARGOFFSET(%rsp)
23707 je retint_kernel
23708
23709 /* Interrupt came from user space */
23710 @@ -1026,12 +1499,16 @@ retint_swapgs: /* return to user-space */
23711 * The iretq could re-enable interrupts:
23712 */
23713 DISABLE_INTERRUPTS(CLBR_ANY)
23714 + pax_exit_kernel_user
23715 +retint_swapgs_pax:
23716 TRACE_IRQS_IRETQ
23717 SWAPGS
23718 jmp restore_args
23719
23720 retint_restore_args: /* return to kernel space */
23721 DISABLE_INTERRUPTS(CLBR_ANY)
23722 + pax_exit_kernel
23723 + pax_force_retaddr (RIP-ARGOFFSET)
23724 /*
23725 * The iretq could re-enable interrupts:
23726 */
23727 @@ -1112,7 +1589,7 @@ ENTRY(retint_kernel)
23728 #endif
23729
23730 CFI_ENDPROC
23731 -END(common_interrupt)
23732 +ENDPROC(common_interrupt)
23733 /*
23734 * End of kprobes section
23735 */
23736 @@ -1130,7 +1607,7 @@ ENTRY(\sym)
23737 interrupt \do_sym
23738 jmp ret_from_intr
23739 CFI_ENDPROC
23740 -END(\sym)
23741 +ENDPROC(\sym)
23742 .endm
23743
23744 #ifdef CONFIG_TRACING
23745 @@ -1218,7 +1695,7 @@ ENTRY(\sym)
23746 call \do_sym
23747 jmp error_exit /* %ebx: no swapgs flag */
23748 CFI_ENDPROC
23749 -END(\sym)
23750 +ENDPROC(\sym)
23751 .endm
23752
23753 .macro paranoidzeroentry sym do_sym
23754 @@ -1236,10 +1713,10 @@ ENTRY(\sym)
23755 call \do_sym
23756 jmp paranoid_exit /* %ebx: no swapgs flag */
23757 CFI_ENDPROC
23758 -END(\sym)
23759 +ENDPROC(\sym)
23760 .endm
23761
23762 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
23763 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r13)
23764 .macro paranoidzeroentry_ist sym do_sym ist
23765 ENTRY(\sym)
23766 INTR_FRAME
23767 @@ -1252,12 +1729,18 @@ ENTRY(\sym)
23768 TRACE_IRQS_OFF_DEBUG
23769 movq %rsp,%rdi /* pt_regs pointer */
23770 xorl %esi,%esi /* no error code */
23771 +#ifdef CONFIG_SMP
23772 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r13d
23773 + lea init_tss(%r13), %r13
23774 +#else
23775 + lea init_tss(%rip), %r13
23776 +#endif
23777 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
23778 call \do_sym
23779 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
23780 jmp paranoid_exit /* %ebx: no swapgs flag */
23781 CFI_ENDPROC
23782 -END(\sym)
23783 +ENDPROC(\sym)
23784 .endm
23785
23786 .macro errorentry sym do_sym
23787 @@ -1275,7 +1758,7 @@ ENTRY(\sym)
23788 call \do_sym
23789 jmp error_exit /* %ebx: no swapgs flag */
23790 CFI_ENDPROC
23791 -END(\sym)
23792 +ENDPROC(\sym)
23793 .endm
23794
23795 #ifdef CONFIG_TRACING
23796 @@ -1306,7 +1789,7 @@ ENTRY(\sym)
23797 call \do_sym
23798 jmp paranoid_exit /* %ebx: no swapgs flag */
23799 CFI_ENDPROC
23800 -END(\sym)
23801 +ENDPROC(\sym)
23802 .endm
23803
23804 zeroentry divide_error do_divide_error
23805 @@ -1336,9 +1819,10 @@ gs_change:
23806 2: mfence /* workaround */
23807 SWAPGS
23808 popfq_cfi
23809 + pax_force_retaddr
23810 ret
23811 CFI_ENDPROC
23812 -END(native_load_gs_index)
23813 +ENDPROC(native_load_gs_index)
23814
23815 _ASM_EXTABLE(gs_change,bad_gs)
23816 .section .fixup,"ax"
23817 @@ -1366,9 +1850,10 @@ ENTRY(do_softirq_own_stack)
23818 CFI_DEF_CFA_REGISTER rsp
23819 CFI_ADJUST_CFA_OFFSET -8
23820 decl PER_CPU_VAR(irq_count)
23821 + pax_force_retaddr
23822 ret
23823 CFI_ENDPROC
23824 -END(do_softirq_own_stack)
23825 +ENDPROC(do_softirq_own_stack)
23826
23827 #ifdef CONFIG_XEN
23828 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
23829 @@ -1406,7 +1891,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
23830 decl PER_CPU_VAR(irq_count)
23831 jmp error_exit
23832 CFI_ENDPROC
23833 -END(xen_do_hypervisor_callback)
23834 +ENDPROC(xen_do_hypervisor_callback)
23835
23836 /*
23837 * Hypervisor uses this for application faults while it executes.
23838 @@ -1465,7 +1950,7 @@ ENTRY(xen_failsafe_callback)
23839 SAVE_ALL
23840 jmp error_exit
23841 CFI_ENDPROC
23842 -END(xen_failsafe_callback)
23843 +ENDPROC(xen_failsafe_callback)
23844
23845 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
23846 xen_hvm_callback_vector xen_evtchn_do_upcall
23847 @@ -1517,18 +2002,33 @@ ENTRY(paranoid_exit)
23848 DEFAULT_FRAME
23849 DISABLE_INTERRUPTS(CLBR_NONE)
23850 TRACE_IRQS_OFF_DEBUG
23851 - testl %ebx,%ebx /* swapgs needed? */
23852 + testl $1,%ebx /* swapgs needed? */
23853 jnz paranoid_restore
23854 - testl $3,CS(%rsp)
23855 + testb $3,CS(%rsp)
23856 jnz paranoid_userspace
23857 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23858 + pax_exit_kernel
23859 + TRACE_IRQS_IRETQ 0
23860 + SWAPGS_UNSAFE_STACK
23861 + RESTORE_ALL 8
23862 + pax_force_retaddr_bts
23863 + jmp irq_return
23864 +#endif
23865 paranoid_swapgs:
23866 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23867 + pax_exit_kernel_user
23868 +#else
23869 + pax_exit_kernel
23870 +#endif
23871 TRACE_IRQS_IRETQ 0
23872 SWAPGS_UNSAFE_STACK
23873 RESTORE_ALL 8
23874 jmp irq_return
23875 paranoid_restore:
23876 + pax_exit_kernel
23877 TRACE_IRQS_IRETQ_DEBUG 0
23878 RESTORE_ALL 8
23879 + pax_force_retaddr_bts
23880 jmp irq_return
23881 paranoid_userspace:
23882 GET_THREAD_INFO(%rcx)
23883 @@ -1557,7 +2057,7 @@ paranoid_schedule:
23884 TRACE_IRQS_OFF
23885 jmp paranoid_userspace
23886 CFI_ENDPROC
23887 -END(paranoid_exit)
23888 +ENDPROC(paranoid_exit)
23889
23890 /*
23891 * Exception entry point. This expects an error code/orig_rax on the stack.
23892 @@ -1584,12 +2084,23 @@ ENTRY(error_entry)
23893 movq_cfi r14, R14+8
23894 movq_cfi r15, R15+8
23895 xorl %ebx,%ebx
23896 - testl $3,CS+8(%rsp)
23897 + testb $3,CS+8(%rsp)
23898 je error_kernelspace
23899 error_swapgs:
23900 SWAPGS
23901 error_sti:
23902 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23903 + testb $3, CS+8(%rsp)
23904 + jnz 1f
23905 + pax_enter_kernel
23906 + jmp 2f
23907 +1: pax_enter_kernel_user
23908 +2:
23909 +#else
23910 + pax_enter_kernel
23911 +#endif
23912 TRACE_IRQS_OFF
23913 + pax_force_retaddr
23914 ret
23915
23916 /*
23917 @@ -1616,7 +2127,7 @@ bstep_iret:
23918 movq %rcx,RIP+8(%rsp)
23919 jmp error_swapgs
23920 CFI_ENDPROC
23921 -END(error_entry)
23922 +ENDPROC(error_entry)
23923
23924
23925 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
23926 @@ -1627,7 +2138,7 @@ ENTRY(error_exit)
23927 DISABLE_INTERRUPTS(CLBR_NONE)
23928 TRACE_IRQS_OFF
23929 GET_THREAD_INFO(%rcx)
23930 - testl %eax,%eax
23931 + testl $1,%eax
23932 jne retint_kernel
23933 LOCKDEP_SYS_EXIT_IRQ
23934 movl TI_flags(%rcx),%edx
23935 @@ -1636,7 +2147,7 @@ ENTRY(error_exit)
23936 jnz retint_careful
23937 jmp retint_swapgs
23938 CFI_ENDPROC
23939 -END(error_exit)
23940 +ENDPROC(error_exit)
23941
23942 /*
23943 * Test if a given stack is an NMI stack or not.
23944 @@ -1694,9 +2205,11 @@ ENTRY(nmi)
23945 * If %cs was not the kernel segment, then the NMI triggered in user
23946 * space, which means it is definitely not nested.
23947 */
23948 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
23949 + je 1f
23950 cmpl $__KERNEL_CS, 16(%rsp)
23951 jne first_nmi
23952 -
23953 +1:
23954 /*
23955 * Check the special variable on the stack to see if NMIs are
23956 * executing.
23957 @@ -1730,8 +2243,7 @@ nested_nmi:
23958
23959 1:
23960 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
23961 - leaq -1*8(%rsp), %rdx
23962 - movq %rdx, %rsp
23963 + subq $8, %rsp
23964 CFI_ADJUST_CFA_OFFSET 1*8
23965 leaq -10*8(%rsp), %rdx
23966 pushq_cfi $__KERNEL_DS
23967 @@ -1749,6 +2261,7 @@ nested_nmi_out:
23968 CFI_RESTORE rdx
23969
23970 /* No need to check faults here */
23971 +# pax_force_retaddr_bts
23972 INTERRUPT_RETURN
23973
23974 CFI_RESTORE_STATE
23975 @@ -1845,13 +2358,13 @@ end_repeat_nmi:
23976 subq $ORIG_RAX-R15, %rsp
23977 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
23978 /*
23979 - * Use save_paranoid to handle SWAPGS, but no need to use paranoid_exit
23980 + * Use save_paranoid_nmi to handle SWAPGS, but no need to use paranoid_exit
23981 * as we should not be calling schedule in NMI context.
23982 * Even with normal interrupts enabled. An NMI should not be
23983 * setting NEED_RESCHED or anything that normal interrupts and
23984 * exceptions might do.
23985 */
23986 - call save_paranoid
23987 + call save_paranoid_nmi
23988 DEFAULT_FRAME 0
23989
23990 /*
23991 @@ -1861,9 +2374,9 @@ end_repeat_nmi:
23992 * NMI itself takes a page fault, the page fault that was preempted
23993 * will read the information from the NMI page fault and not the
23994 * origin fault. Save it off and restore it if it changes.
23995 - * Use the r12 callee-saved register.
23996 + * Use the r13 callee-saved register.
23997 */
23998 - movq %cr2, %r12
23999 + movq %cr2, %r13
24000
24001 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
24002 movq %rsp,%rdi
24003 @@ -1872,31 +2385,36 @@ end_repeat_nmi:
24004
24005 /* Did the NMI take a page fault? Restore cr2 if it did */
24006 movq %cr2, %rcx
24007 - cmpq %rcx, %r12
24008 + cmpq %rcx, %r13
24009 je 1f
24010 - movq %r12, %cr2
24011 + movq %r13, %cr2
24012 1:
24013
24014 - testl %ebx,%ebx /* swapgs needed? */
24015 + testl $1,%ebx /* swapgs needed? */
24016 jnz nmi_restore
24017 nmi_swapgs:
24018 SWAPGS_UNSAFE_STACK
24019 nmi_restore:
24020 + pax_exit_kernel_nmi
24021 /* Pop the extra iret frame at once */
24022 RESTORE_ALL 6*8
24023 + testb $3, 8(%rsp)
24024 + jnz 1f
24025 + pax_force_retaddr_bts
24026 +1:
24027
24028 /* Clear the NMI executing stack variable */
24029 movq $0, 5*8(%rsp)
24030 jmp irq_return
24031 CFI_ENDPROC
24032 -END(nmi)
24033 +ENDPROC(nmi)
24034
24035 ENTRY(ignore_sysret)
24036 CFI_STARTPROC
24037 mov $-ENOSYS,%eax
24038 sysret
24039 CFI_ENDPROC
24040 -END(ignore_sysret)
24041 +ENDPROC(ignore_sysret)
24042
24043 /*
24044 * End of kprobes section
24045 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
24046 index 52819e8..b6d1dbd 100644
24047 --- a/arch/x86/kernel/ftrace.c
24048 +++ b/arch/x86/kernel/ftrace.c
24049 @@ -104,6 +104,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
24050 {
24051 unsigned char replaced[MCOUNT_INSN_SIZE];
24052
24053 + ip = ktla_ktva(ip);
24054 +
24055 /*
24056 * Note: Due to modules and __init, code can
24057 * disappear and change, we need to protect against faulting
24058 @@ -229,7 +231,7 @@ static int update_ftrace_func(unsigned long ip, void *new)
24059 unsigned char old[MCOUNT_INSN_SIZE];
24060 int ret;
24061
24062 - memcpy(old, (void *)ip, MCOUNT_INSN_SIZE);
24063 + memcpy(old, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE);
24064
24065 ftrace_update_func = ip;
24066 /* Make sure the breakpoints see the ftrace_update_func update */
24067 @@ -306,7 +308,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
24068 * kernel identity mapping to modify code.
24069 */
24070 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
24071 - ip = (unsigned long)__va(__pa_symbol(ip));
24072 + ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
24073
24074 if (probe_kernel_write((void *)ip, val, size))
24075 return -EPERM;
24076 @@ -319,7 +321,7 @@ static int add_break(unsigned long ip, const char *old)
24077 unsigned char replaced[MCOUNT_INSN_SIZE];
24078 unsigned char brk = BREAKPOINT_INSTRUCTION;
24079
24080 - if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
24081 + if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
24082 return -EFAULT;
24083
24084 /* Make sure it is what we expect it to be */
24085 diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
24086 index 068054f..c248bcd 100644
24087 --- a/arch/x86/kernel/head64.c
24088 +++ b/arch/x86/kernel/head64.c
24089 @@ -67,12 +67,12 @@ again:
24090 pgd = *pgd_p;
24091
24092 /*
24093 - * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
24094 - * critical -- __PAGE_OFFSET would point us back into the dynamic
24095 + * The use of __early_va rather than __va here is critical:
24096 + * __va would point us back into the dynamic
24097 * range and we might end up looping forever...
24098 */
24099 if (pgd)
24100 - pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24101 + pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
24102 else {
24103 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24104 reset_early_page_tables();
24105 @@ -82,13 +82,13 @@ again:
24106 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
24107 for (i = 0; i < PTRS_PER_PUD; i++)
24108 pud_p[i] = 0;
24109 - *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24110 + *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
24111 }
24112 pud_p += pud_index(address);
24113 pud = *pud_p;
24114
24115 if (pud)
24116 - pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
24117 + pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
24118 else {
24119 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
24120 reset_early_page_tables();
24121 @@ -98,7 +98,7 @@ again:
24122 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
24123 for (i = 0; i < PTRS_PER_PMD; i++)
24124 pmd_p[i] = 0;
24125 - *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
24126 + *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
24127 }
24128 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
24129 pmd_p[pmd_index(address)] = pmd;
24130 @@ -175,7 +175,6 @@ asmlinkage __visible void __init x86_64_start_kernel(char * real_mode_data)
24131 if (console_loglevel == 10)
24132 early_printk("Kernel alive\n");
24133
24134 - clear_page(init_level4_pgt);
24135 /* set init_level4_pgt kernel high mapping*/
24136 init_level4_pgt[511] = early_level4_pgt[511];
24137
24138 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
24139 index f36bd42..56ee1534 100644
24140 --- a/arch/x86/kernel/head_32.S
24141 +++ b/arch/x86/kernel/head_32.S
24142 @@ -26,6 +26,12 @@
24143 /* Physical address */
24144 #define pa(X) ((X) - __PAGE_OFFSET)
24145
24146 +#ifdef CONFIG_PAX_KERNEXEC
24147 +#define ta(X) (X)
24148 +#else
24149 +#define ta(X) ((X) - __PAGE_OFFSET)
24150 +#endif
24151 +
24152 /*
24153 * References to members of the new_cpu_data structure.
24154 */
24155 @@ -55,11 +61,7 @@
24156 * and small than max_low_pfn, otherwise will waste some page table entries
24157 */
24158
24159 -#if PTRS_PER_PMD > 1
24160 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
24161 -#else
24162 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
24163 -#endif
24164 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
24165
24166 /* Number of possible pages in the lowmem region */
24167 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
24168 @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
24169 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24170
24171 /*
24172 + * Real beginning of normal "text" segment
24173 + */
24174 +ENTRY(stext)
24175 +ENTRY(_stext)
24176 +
24177 +/*
24178 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
24179 * %esi points to the real-mode code as a 32-bit pointer.
24180 * CS and DS must be 4 GB flat segments, but we don't depend on
24181 @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
24182 * can.
24183 */
24184 __HEAD
24185 +
24186 +#ifdef CONFIG_PAX_KERNEXEC
24187 + jmp startup_32
24188 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
24189 +.fill PAGE_SIZE-5,1,0xcc
24190 +#endif
24191 +
24192 ENTRY(startup_32)
24193 movl pa(stack_start),%ecx
24194
24195 @@ -106,6 +121,59 @@ ENTRY(startup_32)
24196 2:
24197 leal -__PAGE_OFFSET(%ecx),%esp
24198
24199 +#ifdef CONFIG_SMP
24200 + movl $pa(cpu_gdt_table),%edi
24201 + movl $__per_cpu_load,%eax
24202 + movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
24203 + rorl $16,%eax
24204 + movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
24205 + movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
24206 + movl $__per_cpu_end - 1,%eax
24207 + subl $__per_cpu_start,%eax
24208 + movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
24209 +#endif
24210 +
24211 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24212 + movl $NR_CPUS,%ecx
24213 + movl $pa(cpu_gdt_table),%edi
24214 +1:
24215 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
24216 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
24217 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
24218 + addl $PAGE_SIZE_asm,%edi
24219 + loop 1b
24220 +#endif
24221 +
24222 +#ifdef CONFIG_PAX_KERNEXEC
24223 + movl $pa(boot_gdt),%edi
24224 + movl $__LOAD_PHYSICAL_ADDR,%eax
24225 + movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
24226 + rorl $16,%eax
24227 + movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
24228 + movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
24229 + rorl $16,%eax
24230 +
24231 + ljmp $(__BOOT_CS),$1f
24232 +1:
24233 +
24234 + movl $NR_CPUS,%ecx
24235 + movl $pa(cpu_gdt_table),%edi
24236 + addl $__PAGE_OFFSET,%eax
24237 +1:
24238 + movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
24239 + movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
24240 + movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
24241 + movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
24242 + rorl $16,%eax
24243 + movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
24244 + movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
24245 + movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
24246 + movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
24247 + rorl $16,%eax
24248 + addl $PAGE_SIZE_asm,%edi
24249 + loop 1b
24250 +#endif
24251 +
24252 /*
24253 * Clear BSS first so that there are no surprises...
24254 */
24255 @@ -201,8 +269,11 @@ ENTRY(startup_32)
24256 movl %eax, pa(max_pfn_mapped)
24257
24258 /* Do early initialization of the fixmap area */
24259 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24260 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
24261 +#ifdef CONFIG_COMPAT_VDSO
24262 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
24263 +#else
24264 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
24265 +#endif
24266 #else /* Not PAE */
24267
24268 page_pde_offset = (__PAGE_OFFSET >> 20);
24269 @@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24270 movl %eax, pa(max_pfn_mapped)
24271
24272 /* Do early initialization of the fixmap area */
24273 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
24274 - movl %eax,pa(initial_page_table+0xffc)
24275 +#ifdef CONFIG_COMPAT_VDSO
24276 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
24277 +#else
24278 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
24279 +#endif
24280 #endif
24281
24282 #ifdef CONFIG_PARAVIRT
24283 @@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
24284 cmpl $num_subarch_entries, %eax
24285 jae bad_subarch
24286
24287 - movl pa(subarch_entries)(,%eax,4), %eax
24288 - subl $__PAGE_OFFSET, %eax
24289 - jmp *%eax
24290 + jmp *pa(subarch_entries)(,%eax,4)
24291
24292 bad_subarch:
24293 WEAK(lguest_entry)
24294 @@ -261,10 +333,10 @@ WEAK(xen_entry)
24295 __INITDATA
24296
24297 subarch_entries:
24298 - .long default_entry /* normal x86/PC */
24299 - .long lguest_entry /* lguest hypervisor */
24300 - .long xen_entry /* Xen hypervisor */
24301 - .long default_entry /* Moorestown MID */
24302 + .long ta(default_entry) /* normal x86/PC */
24303 + .long ta(lguest_entry) /* lguest hypervisor */
24304 + .long ta(xen_entry) /* Xen hypervisor */
24305 + .long ta(default_entry) /* Moorestown MID */
24306 num_subarch_entries = (. - subarch_entries) / 4
24307 .previous
24308 #else
24309 @@ -354,6 +426,7 @@ default_entry:
24310 movl pa(mmu_cr4_features),%eax
24311 movl %eax,%cr4
24312
24313 +#ifdef CONFIG_X86_PAE
24314 testb $X86_CR4_PAE, %al # check if PAE is enabled
24315 jz enable_paging
24316
24317 @@ -382,6 +455,9 @@ default_entry:
24318 /* Make changes effective */
24319 wrmsr
24320
24321 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
24322 +#endif
24323 +
24324 enable_paging:
24325
24326 /*
24327 @@ -449,14 +525,20 @@ is486:
24328 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
24329 movl %eax,%ss # after changing gdt.
24330
24331 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
24332 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
24333 movl %eax,%ds
24334 movl %eax,%es
24335
24336 movl $(__KERNEL_PERCPU), %eax
24337 movl %eax,%fs # set this cpu's percpu
24338
24339 +#ifdef CONFIG_CC_STACKPROTECTOR
24340 movl $(__KERNEL_STACK_CANARY),%eax
24341 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
24342 + movl $(__USER_DS),%eax
24343 +#else
24344 + xorl %eax,%eax
24345 +#endif
24346 movl %eax,%gs
24347
24348 xorl %eax,%eax # Clear LDT
24349 @@ -512,8 +594,11 @@ setup_once:
24350 * relocation. Manually set base address in stack canary
24351 * segment descriptor.
24352 */
24353 - movl $gdt_page,%eax
24354 + movl $cpu_gdt_table,%eax
24355 movl $stack_canary,%ecx
24356 +#ifdef CONFIG_SMP
24357 + addl $__per_cpu_load,%ecx
24358 +#endif
24359 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
24360 shrl $16, %ecx
24361 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
24362 @@ -548,7 +633,7 @@ ENTRY(early_idt_handler)
24363 cmpl $2,(%esp) # X86_TRAP_NMI
24364 je is_nmi # Ignore NMI
24365
24366 - cmpl $2,%ss:early_recursion_flag
24367 + cmpl $1,%ss:early_recursion_flag
24368 je hlt_loop
24369 incl %ss:early_recursion_flag
24370
24371 @@ -586,8 +671,8 @@ ENTRY(early_idt_handler)
24372 pushl (20+6*4)(%esp) /* trapno */
24373 pushl $fault_msg
24374 call printk
24375 -#endif
24376 call dump_stack
24377 +#endif
24378 hlt_loop:
24379 hlt
24380 jmp hlt_loop
24381 @@ -607,8 +692,11 @@ ENDPROC(early_idt_handler)
24382 /* This is the default interrupt "handler" :-) */
24383 ALIGN
24384 ignore_int:
24385 - cld
24386 #ifdef CONFIG_PRINTK
24387 + cmpl $2,%ss:early_recursion_flag
24388 + je hlt_loop
24389 + incl %ss:early_recursion_flag
24390 + cld
24391 pushl %eax
24392 pushl %ecx
24393 pushl %edx
24394 @@ -617,9 +705,6 @@ ignore_int:
24395 movl $(__KERNEL_DS),%eax
24396 movl %eax,%ds
24397 movl %eax,%es
24398 - cmpl $2,early_recursion_flag
24399 - je hlt_loop
24400 - incl early_recursion_flag
24401 pushl 16(%esp)
24402 pushl 24(%esp)
24403 pushl 32(%esp)
24404 @@ -653,29 +738,34 @@ ENTRY(setup_once_ref)
24405 /*
24406 * BSS section
24407 */
24408 -__PAGE_ALIGNED_BSS
24409 - .align PAGE_SIZE
24410 #ifdef CONFIG_X86_PAE
24411 +.section .initial_pg_pmd,"a",@progbits
24412 initial_pg_pmd:
24413 .fill 1024*KPMDS,4,0
24414 #else
24415 +.section .initial_page_table,"a",@progbits
24416 ENTRY(initial_page_table)
24417 .fill 1024,4,0
24418 #endif
24419 +.section .initial_pg_fixmap,"a",@progbits
24420 initial_pg_fixmap:
24421 .fill 1024,4,0
24422 +.section .empty_zero_page,"a",@progbits
24423 ENTRY(empty_zero_page)
24424 .fill 4096,1,0
24425 +.section .swapper_pg_dir,"a",@progbits
24426 ENTRY(swapper_pg_dir)
24427 +#ifdef CONFIG_X86_PAE
24428 + .fill 4,8,0
24429 +#else
24430 .fill 1024,4,0
24431 +#endif
24432
24433 /*
24434 * This starts the data section.
24435 */
24436 #ifdef CONFIG_X86_PAE
24437 -__PAGE_ALIGNED_DATA
24438 - /* Page-aligned for the benefit of paravirt? */
24439 - .align PAGE_SIZE
24440 +.section .initial_page_table,"a",@progbits
24441 ENTRY(initial_page_table)
24442 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
24443 # if KPMDS == 3
24444 @@ -694,12 +784,20 @@ ENTRY(initial_page_table)
24445 # error "Kernel PMDs should be 1, 2 or 3"
24446 # endif
24447 .align PAGE_SIZE /* needs to be page-sized too */
24448 +
24449 +#ifdef CONFIG_PAX_PER_CPU_PGD
24450 +ENTRY(cpu_pgd)
24451 + .rept 2*NR_CPUS
24452 + .fill 4,8,0
24453 + .endr
24454 +#endif
24455 +
24456 #endif
24457
24458 .data
24459 .balign 4
24460 ENTRY(stack_start)
24461 - .long init_thread_union+THREAD_SIZE
24462 + .long init_thread_union+THREAD_SIZE-8
24463
24464 __INITRODATA
24465 int_msg:
24466 @@ -727,7 +825,7 @@ fault_msg:
24467 * segment size, and 32-bit linear address value:
24468 */
24469
24470 - .data
24471 +.section .rodata,"a",@progbits
24472 .globl boot_gdt_descr
24473 .globl idt_descr
24474
24475 @@ -736,7 +834,7 @@ fault_msg:
24476 .word 0 # 32 bit align gdt_desc.address
24477 boot_gdt_descr:
24478 .word __BOOT_DS+7
24479 - .long boot_gdt - __PAGE_OFFSET
24480 + .long pa(boot_gdt)
24481
24482 .word 0 # 32-bit align idt_desc.address
24483 idt_descr:
24484 @@ -747,7 +845,7 @@ idt_descr:
24485 .word 0 # 32 bit align gdt_desc.address
24486 ENTRY(early_gdt_descr)
24487 .word GDT_ENTRIES*8-1
24488 - .long gdt_page /* Overwritten for secondary CPUs */
24489 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
24490
24491 /*
24492 * The boot_gdt must mirror the equivalent in setup.S and is
24493 @@ -756,5 +854,65 @@ ENTRY(early_gdt_descr)
24494 .align L1_CACHE_BYTES
24495 ENTRY(boot_gdt)
24496 .fill GDT_ENTRY_BOOT_CS,8,0
24497 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
24498 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
24499 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
24500 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
24501 +
24502 + .align PAGE_SIZE_asm
24503 +ENTRY(cpu_gdt_table)
24504 + .rept NR_CPUS
24505 + .quad 0x0000000000000000 /* NULL descriptor */
24506 + .quad 0x0000000000000000 /* 0x0b reserved */
24507 + .quad 0x0000000000000000 /* 0x13 reserved */
24508 + .quad 0x0000000000000000 /* 0x1b reserved */
24509 +
24510 +#ifdef CONFIG_PAX_KERNEXEC
24511 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
24512 +#else
24513 + .quad 0x0000000000000000 /* 0x20 unused */
24514 +#endif
24515 +
24516 + .quad 0x0000000000000000 /* 0x28 unused */
24517 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
24518 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
24519 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
24520 + .quad 0x0000000000000000 /* 0x4b reserved */
24521 + .quad 0x0000000000000000 /* 0x53 reserved */
24522 + .quad 0x0000000000000000 /* 0x5b reserved */
24523 +
24524 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
24525 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
24526 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
24527 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
24528 +
24529 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
24530 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
24531 +
24532 + /*
24533 + * Segments used for calling PnP BIOS have byte granularity.
24534 + * The code segments and data segments have fixed 64k limits,
24535 + * the transfer segment sizes are set at run time.
24536 + */
24537 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
24538 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
24539 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
24540 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
24541 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
24542 +
24543 + /*
24544 + * The APM segments have byte granularity and their bases
24545 + * are set at run time. All have 64k limits.
24546 + */
24547 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
24548 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
24549 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
24550 +
24551 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
24552 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
24553 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
24554 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
24555 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
24556 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
24557 +
24558 + /* Be sure this is zeroed to avoid false validations in Xen */
24559 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
24560 + .endr
24561 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
24562 index a468c0a..c7dec74 100644
24563 --- a/arch/x86/kernel/head_64.S
24564 +++ b/arch/x86/kernel/head_64.S
24565 @@ -20,6 +20,8 @@
24566 #include <asm/processor-flags.h>
24567 #include <asm/percpu.h>
24568 #include <asm/nops.h>
24569 +#include <asm/cpufeature.h>
24570 +#include <asm/alternative-asm.h>
24571
24572 #ifdef CONFIG_PARAVIRT
24573 #include <asm/asm-offsets.h>
24574 @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
24575 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
24576 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
24577 L3_START_KERNEL = pud_index(__START_KERNEL_map)
24578 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
24579 +L3_VMALLOC_START = pud_index(VMALLOC_START)
24580 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
24581 +L3_VMALLOC_END = pud_index(VMALLOC_END)
24582 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
24583 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
24584
24585 .text
24586 __HEAD
24587 @@ -89,11 +97,24 @@ startup_64:
24588 * Fixup the physical addresses in the page table
24589 */
24590 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
24591 + addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
24592 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
24593 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
24594 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
24595 + addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
24596
24597 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
24598 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
24599 + addq %rbp, level3_ident_pgt + (0*8)(%rip)
24600 +#ifndef CONFIG_XEN
24601 + addq %rbp, level3_ident_pgt + (1*8)(%rip)
24602 +#endif
24603 +
24604 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
24605 +
24606 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
24607 + addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
24608
24609 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
24610 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
24611
24612 /*
24613 * Set up the identity mapping for the switchover. These
24614 @@ -177,8 +198,8 @@ ENTRY(secondary_startup_64)
24615 movq $(init_level4_pgt - __START_KERNEL_map), %rax
24616 1:
24617
24618 - /* Enable PAE mode and PGE */
24619 - movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
24620 + /* Enable PAE mode and PSE/PGE */
24621 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
24622 movq %rcx, %cr4
24623
24624 /* Setup early boot stage 4 level pagetables. */
24625 @@ -199,10 +220,19 @@ ENTRY(secondary_startup_64)
24626 movl $MSR_EFER, %ecx
24627 rdmsr
24628 btsl $_EFER_SCE, %eax /* Enable System Call */
24629 - btl $20,%edi /* No Execute supported? */
24630 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
24631 jnc 1f
24632 btsl $_EFER_NX, %eax
24633 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
24634 +#ifndef CONFIG_EFI
24635 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_PAGE_OFFSET(%rip)
24636 +#endif
24637 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_START(%rip)
24638 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_END(%rip)
24639 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMEMMAP_START(%rip)
24640 + btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*506(%rip)
24641 + btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*507(%rip)
24642 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
24643 1: wrmsr /* Make changes effective */
24644
24645 /* Setup cr0 */
24646 @@ -282,6 +312,7 @@ ENTRY(secondary_startup_64)
24647 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
24648 * address given in m16:64.
24649 */
24650 + pax_set_fptr_mask
24651 movq initial_code(%rip),%rax
24652 pushq $0 # fake return address to stop unwinder
24653 pushq $__KERNEL_CS # set correct cs
24654 @@ -313,7 +344,7 @@ ENDPROC(start_cpu0)
24655 .quad INIT_PER_CPU_VAR(irq_stack_union)
24656
24657 GLOBAL(stack_start)
24658 - .quad init_thread_union+THREAD_SIZE-8
24659 + .quad init_thread_union+THREAD_SIZE-16
24660 .word 0
24661 __FINITDATA
24662
24663 @@ -391,7 +422,7 @@ ENTRY(early_idt_handler)
24664 call dump_stack
24665 #ifdef CONFIG_KALLSYMS
24666 leaq early_idt_ripmsg(%rip),%rdi
24667 - movq 40(%rsp),%rsi # %rip again
24668 + movq 88(%rsp),%rsi # %rip again
24669 call __print_symbol
24670 #endif
24671 #endif /* EARLY_PRINTK */
24672 @@ -420,6 +451,7 @@ ENDPROC(early_idt_handler)
24673 early_recursion_flag:
24674 .long 0
24675
24676 + .section .rodata,"a",@progbits
24677 #ifdef CONFIG_EARLY_PRINTK
24678 early_idt_msg:
24679 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
24680 @@ -447,29 +479,52 @@ NEXT_PAGE(early_level4_pgt)
24681 NEXT_PAGE(early_dynamic_pgts)
24682 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
24683
24684 - .data
24685 + .section .rodata,"a",@progbits
24686
24687 -#ifndef CONFIG_XEN
24688 NEXT_PAGE(init_level4_pgt)
24689 - .fill 512,8,0
24690 -#else
24691 -NEXT_PAGE(init_level4_pgt)
24692 - .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24693 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
24694 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24695 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
24696 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
24697 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
24698 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
24699 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
24700 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24701 .org init_level4_pgt + L4_START_KERNEL*8, 0
24702 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
24703 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
24704
24705 +#ifdef CONFIG_PAX_PER_CPU_PGD
24706 +NEXT_PAGE(cpu_pgd)
24707 + .rept 2*NR_CPUS
24708 + .fill 512,8,0
24709 + .endr
24710 +#endif
24711 +
24712 NEXT_PAGE(level3_ident_pgt)
24713 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24714 +#ifdef CONFIG_XEN
24715 .fill 511, 8, 0
24716 +#else
24717 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
24718 + .fill 510,8,0
24719 +#endif
24720 +
24721 +NEXT_PAGE(level3_vmalloc_start_pgt)
24722 + .fill 512,8,0
24723 +
24724 +NEXT_PAGE(level3_vmalloc_end_pgt)
24725 + .fill 512,8,0
24726 +
24727 +NEXT_PAGE(level3_vmemmap_pgt)
24728 + .fill L3_VMEMMAP_START,8,0
24729 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24730 +
24731 NEXT_PAGE(level2_ident_pgt)
24732 - /* Since I easily can, map the first 1G.
24733 + /* Since I easily can, map the first 2G.
24734 * Don't set NX because code runs from these pages.
24735 */
24736 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
24737 -#endif
24738 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
24739
24740 NEXT_PAGE(level3_kernel_pgt)
24741 .fill L3_START_KERNEL,8,0
24742 @@ -477,6 +532,9 @@ NEXT_PAGE(level3_kernel_pgt)
24743 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
24744 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
24745
24746 +NEXT_PAGE(level2_vmemmap_pgt)
24747 + .fill 512,8,0
24748 +
24749 NEXT_PAGE(level2_kernel_pgt)
24750 /*
24751 * 512 MB kernel mapping. We spend a full page on this pagetable
24752 @@ -494,28 +552,64 @@ NEXT_PAGE(level2_kernel_pgt)
24753 NEXT_PAGE(level2_fixmap_pgt)
24754 .fill 506,8,0
24755 .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
24756 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
24757 - .fill 5,8,0
24758 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
24759 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
24760 + .fill 4,8,0
24761
24762 NEXT_PAGE(level1_fixmap_pgt)
24763 .fill 512,8,0
24764
24765 +NEXT_PAGE(level1_vsyscall_pgt)
24766 + .fill 512,8,0
24767 +
24768 #undef PMDS
24769
24770 - .data
24771 + .align PAGE_SIZE
24772 +ENTRY(cpu_gdt_table)
24773 + .rept NR_CPUS
24774 + .quad 0x0000000000000000 /* NULL descriptor */
24775 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
24776 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
24777 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
24778 + .quad 0x00cffb000000ffff /* __USER32_CS */
24779 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
24780 + .quad 0x00affb000000ffff /* __USER_CS */
24781 +
24782 +#ifdef CONFIG_PAX_KERNEXEC
24783 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
24784 +#else
24785 + .quad 0x0 /* unused */
24786 +#endif
24787 +
24788 + .quad 0,0 /* TSS */
24789 + .quad 0,0 /* LDT */
24790 + .quad 0,0,0 /* three TLS descriptors */
24791 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
24792 + /* asm/segment.h:GDT_ENTRIES must match this */
24793 +
24794 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24795 + .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
24796 +#else
24797 + .quad 0x0 /* unused */
24798 +#endif
24799 +
24800 + /* zero the remaining page */
24801 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
24802 + .endr
24803 +
24804 .align 16
24805 .globl early_gdt_descr
24806 early_gdt_descr:
24807 .word GDT_ENTRIES*8-1
24808 early_gdt_descr_base:
24809 - .quad INIT_PER_CPU_VAR(gdt_page)
24810 + .quad cpu_gdt_table
24811
24812 ENTRY(phys_base)
24813 /* This must match the first entry in level2_kernel_pgt */
24814 .quad 0x0000000000000000
24815
24816 #include "../../x86/xen/xen-head.S"
24817 -
24818 - __PAGE_ALIGNED_BSS
24819 +
24820 + .section .rodata,"a",@progbits
24821 NEXT_PAGE(empty_zero_page)
24822 .skip PAGE_SIZE
24823 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
24824 index 05fd74f..c3548b1 100644
24825 --- a/arch/x86/kernel/i386_ksyms_32.c
24826 +++ b/arch/x86/kernel/i386_ksyms_32.c
24827 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
24828 EXPORT_SYMBOL(cmpxchg8b_emu);
24829 #endif
24830
24831 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
24832 +
24833 /* Networking helper routines. */
24834 EXPORT_SYMBOL(csum_partial_copy_generic);
24835 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
24836 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
24837
24838 EXPORT_SYMBOL(__get_user_1);
24839 EXPORT_SYMBOL(__get_user_2);
24840 @@ -44,3 +48,11 @@ EXPORT_SYMBOL(___preempt_schedule);
24841 EXPORT_SYMBOL(___preempt_schedule_context);
24842 #endif
24843 #endif
24844 +
24845 +#ifdef CONFIG_PAX_KERNEXEC
24846 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
24847 +#endif
24848 +
24849 +#ifdef CONFIG_PAX_PER_CPU_PGD
24850 +EXPORT_SYMBOL(cpu_pgd);
24851 +#endif
24852 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
24853 index d5dd808..b6432cf 100644
24854 --- a/arch/x86/kernel/i387.c
24855 +++ b/arch/x86/kernel/i387.c
24856 @@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
24857 static inline bool interrupted_user_mode(void)
24858 {
24859 struct pt_regs *regs = get_irq_regs();
24860 - return regs && user_mode_vm(regs);
24861 + return regs && user_mode(regs);
24862 }
24863
24864 /*
24865 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
24866 index 2e977b5..5f2c273 100644
24867 --- a/arch/x86/kernel/i8259.c
24868 +++ b/arch/x86/kernel/i8259.c
24869 @@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
24870 static void make_8259A_irq(unsigned int irq)
24871 {
24872 disable_irq_nosync(irq);
24873 - io_apic_irqs &= ~(1<<irq);
24874 + io_apic_irqs &= ~(1UL<<irq);
24875 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
24876 i8259A_chip.name);
24877 enable_irq(irq);
24878 @@ -209,7 +209,7 @@ spurious_8259A_irq:
24879 "spurious 8259A interrupt: IRQ%d.\n", irq);
24880 spurious_irq_mask |= irqmask;
24881 }
24882 - atomic_inc(&irq_err_count);
24883 + atomic_inc_unchecked(&irq_err_count);
24884 /*
24885 * Theoretically we do not have to handle this IRQ,
24886 * but in Linux this does not cause problems and is
24887 @@ -332,14 +332,16 @@ static void init_8259A(int auto_eoi)
24888 /* (slave's support for AEOI in flat mode is to be investigated) */
24889 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
24890
24891 + pax_open_kernel();
24892 if (auto_eoi)
24893 /*
24894 * In AEOI mode we just have to mask the interrupt
24895 * when acking.
24896 */
24897 - i8259A_chip.irq_mask_ack = disable_8259A_irq;
24898 + *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
24899 else
24900 - i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
24901 + *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
24902 + pax_close_kernel();
24903
24904 udelay(100); /* wait for 8259A to initialize */
24905
24906 diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
24907 index a979b5b..1d6db75 100644
24908 --- a/arch/x86/kernel/io_delay.c
24909 +++ b/arch/x86/kernel/io_delay.c
24910 @@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
24911 * Quirk table for systems that misbehave (lock up, etc.) if port
24912 * 0x80 is used:
24913 */
24914 -static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
24915 +static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
24916 {
24917 .callback = dmi_io_delay_0xed_port,
24918 .ident = "Compaq Presario V6000",
24919 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
24920 index 4ddaf66..49d5c18 100644
24921 --- a/arch/x86/kernel/ioport.c
24922 +++ b/arch/x86/kernel/ioport.c
24923 @@ -6,6 +6,7 @@
24924 #include <linux/sched.h>
24925 #include <linux/kernel.h>
24926 #include <linux/capability.h>
24927 +#include <linux/security.h>
24928 #include <linux/errno.h>
24929 #include <linux/types.h>
24930 #include <linux/ioport.h>
24931 @@ -30,6 +31,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
24932 return -EINVAL;
24933 if (turn_on && !capable(CAP_SYS_RAWIO))
24934 return -EPERM;
24935 +#ifdef CONFIG_GRKERNSEC_IO
24936 + if (turn_on && grsec_disable_privio) {
24937 + gr_handle_ioperm();
24938 + return -ENODEV;
24939 + }
24940 +#endif
24941
24942 /*
24943 * If it's the first ioperm() call in this thread's lifetime, set the
24944 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
24945 * because the ->io_bitmap_max value must match the bitmap
24946 * contents:
24947 */
24948 - tss = &per_cpu(init_tss, get_cpu());
24949 + tss = init_tss + get_cpu();
24950
24951 if (turn_on)
24952 bitmap_clear(t->io_bitmap_ptr, from, num);
24953 @@ -105,6 +112,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
24954 if (level > old) {
24955 if (!capable(CAP_SYS_RAWIO))
24956 return -EPERM;
24957 +#ifdef CONFIG_GRKERNSEC_IO
24958 + if (grsec_disable_privio) {
24959 + gr_handle_iopl();
24960 + return -ENODEV;
24961 + }
24962 +#endif
24963 }
24964 regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
24965 t->iopl = level << 12;
24966 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
24967 index 11ccfb0..ec1e46f 100644
24968 --- a/arch/x86/kernel/irq.c
24969 +++ b/arch/x86/kernel/irq.c
24970 @@ -22,7 +22,7 @@
24971 #define CREATE_TRACE_POINTS
24972 #include <asm/trace/irq_vectors.h>
24973
24974 -atomic_t irq_err_count;
24975 +atomic_unchecked_t irq_err_count;
24976
24977 /* Function pointer for generic interrupt vector handling */
24978 void (*x86_platform_ipi_callback)(void) = NULL;
24979 @@ -132,9 +132,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
24980 seq_printf(p, "%10u ", irq_stats(j)->irq_hv_callback_count);
24981 seq_printf(p, " Hypervisor callback interrupts\n");
24982 #endif
24983 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
24984 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
24985 #if defined(CONFIG_X86_IO_APIC)
24986 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
24987 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
24988 #endif
24989 return 0;
24990 }
24991 @@ -174,7 +174,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
24992
24993 u64 arch_irq_stat(void)
24994 {
24995 - u64 sum = atomic_read(&irq_err_count);
24996 + u64 sum = atomic_read_unchecked(&irq_err_count);
24997 return sum;
24998 }
24999
25000 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
25001 index 63ce838..2ea3e06 100644
25002 --- a/arch/x86/kernel/irq_32.c
25003 +++ b/arch/x86/kernel/irq_32.c
25004 @@ -29,6 +29,8 @@ EXPORT_PER_CPU_SYMBOL(irq_regs);
25005
25006 #ifdef CONFIG_DEBUG_STACKOVERFLOW
25007
25008 +extern void gr_handle_kernel_exploit(void);
25009 +
25010 int sysctl_panic_on_stackoverflow __read_mostly;
25011
25012 /* Debugging check for stack overflow: is there less than 1KB free? */
25013 @@ -39,13 +41,14 @@ static int check_stack_overflow(void)
25014 __asm__ __volatile__("andl %%esp,%0" :
25015 "=r" (sp) : "0" (THREAD_SIZE - 1));
25016
25017 - return sp < (sizeof(struct thread_info) + STACK_WARN);
25018 + return sp < STACK_WARN;
25019 }
25020
25021 static void print_stack_overflow(void)
25022 {
25023 printk(KERN_WARNING "low stack detected by irq handler\n");
25024 dump_stack();
25025 + gr_handle_kernel_exploit();
25026 if (sysctl_panic_on_stackoverflow)
25027 panic("low stack detected by irq handler - check messages\n");
25028 }
25029 @@ -84,10 +87,9 @@ static inline void *current_stack(void)
25030 static inline int
25031 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25032 {
25033 - struct irq_stack *curstk, *irqstk;
25034 + struct irq_stack *irqstk;
25035 u32 *isp, *prev_esp, arg1, arg2;
25036
25037 - curstk = (struct irq_stack *) current_stack();
25038 irqstk = __this_cpu_read(hardirq_stack);
25039
25040 /*
25041 @@ -96,15 +98,19 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25042 * handler) we can't do that and just have to keep using the
25043 * current stack (which is the irq stack already after all)
25044 */
25045 - if (unlikely(curstk == irqstk))
25046 + if (unlikely((void *)current_stack_pointer - (void *)irqstk < THREAD_SIZE))
25047 return 0;
25048
25049 - isp = (u32 *) ((char *)irqstk + sizeof(*irqstk));
25050 + isp = (u32 *) ((char *)irqstk + sizeof(*irqstk) - 8);
25051
25052 /* Save the next esp at the bottom of the stack */
25053 prev_esp = (u32 *)irqstk;
25054 *prev_esp = current_stack_pointer;
25055
25056 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25057 + __set_fs(MAKE_MM_SEG(0));
25058 +#endif
25059 +
25060 if (unlikely(overflow))
25061 call_on_stack(print_stack_overflow, isp);
25062
25063 @@ -115,6 +121,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25064 : "0" (irq), "1" (desc), "2" (isp),
25065 "D" (desc->handle_irq)
25066 : "memory", "cc", "ecx");
25067 +
25068 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25069 + __set_fs(current_thread_info()->addr_limit);
25070 +#endif
25071 +
25072 return 1;
25073 }
25074
25075 @@ -123,32 +134,18 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
25076 */
25077 void irq_ctx_init(int cpu)
25078 {
25079 - struct irq_stack *irqstk;
25080 -
25081 if (per_cpu(hardirq_stack, cpu))
25082 return;
25083
25084 - irqstk = page_address(alloc_pages_node(cpu_to_node(cpu),
25085 - THREADINFO_GFP,
25086 - THREAD_SIZE_ORDER));
25087 - per_cpu(hardirq_stack, cpu) = irqstk;
25088 -
25089 - irqstk = page_address(alloc_pages_node(cpu_to_node(cpu),
25090 - THREADINFO_GFP,
25091 - THREAD_SIZE_ORDER));
25092 - per_cpu(softirq_stack, cpu) = irqstk;
25093 -
25094 - printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
25095 - cpu, per_cpu(hardirq_stack, cpu), per_cpu(softirq_stack, cpu));
25096 + per_cpu(hardirq_stack, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
25097 + per_cpu(softirq_stack, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
25098 }
25099
25100 void do_softirq_own_stack(void)
25101 {
25102 - struct thread_info *curstk;
25103 struct irq_stack *irqstk;
25104 u32 *isp, *prev_esp;
25105
25106 - curstk = current_stack();
25107 irqstk = __this_cpu_read(softirq_stack);
25108
25109 /* build the stack frame on the softirq stack */
25110 @@ -158,7 +155,16 @@ void do_softirq_own_stack(void)
25111 prev_esp = (u32 *)irqstk;
25112 *prev_esp = current_stack_pointer;
25113
25114 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25115 + __set_fs(MAKE_MM_SEG(0));
25116 +#endif
25117 +
25118 call_on_stack(__do_softirq, isp);
25119 +
25120 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25121 + __set_fs(current_thread_info()->addr_limit);
25122 +#endif
25123 +
25124 }
25125
25126 bool handle_irq(unsigned irq, struct pt_regs *regs)
25127 @@ -172,7 +178,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
25128 if (unlikely(!desc))
25129 return false;
25130
25131 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25132 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
25133 if (unlikely(overflow))
25134 print_stack_overflow();
25135 desc->handle_irq(irq, desc);
25136 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
25137 index 4d1c746..55a22d6 100644
25138 --- a/arch/x86/kernel/irq_64.c
25139 +++ b/arch/x86/kernel/irq_64.c
25140 @@ -26,6 +26,8 @@ EXPORT_PER_CPU_SYMBOL(irq_stat);
25141 DEFINE_PER_CPU(struct pt_regs *, irq_regs);
25142 EXPORT_PER_CPU_SYMBOL(irq_regs);
25143
25144 +extern void gr_handle_kernel_exploit(void);
25145 +
25146 int sysctl_panic_on_stackoverflow;
25147
25148 /*
25149 @@ -44,7 +46,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25150 u64 estack_top, estack_bottom;
25151 u64 curbase = (u64)task_stack_page(current);
25152
25153 - if (user_mode_vm(regs))
25154 + if (user_mode(regs))
25155 return;
25156
25157 if (regs->sp >= curbase + sizeof(struct thread_info) +
25158 @@ -69,6 +71,8 @@ static inline void stack_overflow_check(struct pt_regs *regs)
25159 irq_stack_top, irq_stack_bottom,
25160 estack_top, estack_bottom);
25161
25162 + gr_handle_kernel_exploit();
25163 +
25164 if (sysctl_panic_on_stackoverflow)
25165 panic("low stack detected by irq handler - check messages\n");
25166 #endif
25167 diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
25168 index 26d5a55..a01160a 100644
25169 --- a/arch/x86/kernel/jump_label.c
25170 +++ b/arch/x86/kernel/jump_label.c
25171 @@ -51,7 +51,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25172 * Jump label is enabled for the first time.
25173 * So we expect a default_nop...
25174 */
25175 - if (unlikely(memcmp((void *)entry->code, default_nop, 5)
25176 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5)
25177 != 0))
25178 bug_at((void *)entry->code, __LINE__);
25179 } else {
25180 @@ -59,7 +59,7 @@ static void __jump_label_transform(struct jump_entry *entry,
25181 * ...otherwise expect an ideal_nop. Otherwise
25182 * something went horribly wrong.
25183 */
25184 - if (unlikely(memcmp((void *)entry->code, ideal_nop, 5)
25185 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), ideal_nop, 5)
25186 != 0))
25187 bug_at((void *)entry->code, __LINE__);
25188 }
25189 @@ -75,13 +75,13 @@ static void __jump_label_transform(struct jump_entry *entry,
25190 * are converting the default nop to the ideal nop.
25191 */
25192 if (init) {
25193 - if (unlikely(memcmp((void *)entry->code, default_nop, 5) != 0))
25194 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5) != 0))
25195 bug_at((void *)entry->code, __LINE__);
25196 } else {
25197 code.jump = 0xe9;
25198 code.offset = entry->target -
25199 (entry->code + JUMP_LABEL_NOP_SIZE);
25200 - if (unlikely(memcmp((void *)entry->code, &code, 5) != 0))
25201 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), &code, 5) != 0))
25202 bug_at((void *)entry->code, __LINE__);
25203 }
25204 memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
25205 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
25206 index 7ec1d5f..5a7d130 100644
25207 --- a/arch/x86/kernel/kgdb.c
25208 +++ b/arch/x86/kernel/kgdb.c
25209 @@ -126,11 +126,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
25210 #ifdef CONFIG_X86_32
25211 switch (regno) {
25212 case GDB_SS:
25213 - if (!user_mode_vm(regs))
25214 + if (!user_mode(regs))
25215 *(unsigned long *)mem = __KERNEL_DS;
25216 break;
25217 case GDB_SP:
25218 - if (!user_mode_vm(regs))
25219 + if (!user_mode(regs))
25220 *(unsigned long *)mem = kernel_stack_pointer(regs);
25221 break;
25222 case GDB_GS:
25223 @@ -228,7 +228,10 @@ static void kgdb_correct_hw_break(void)
25224 bp->attr.bp_addr = breakinfo[breakno].addr;
25225 bp->attr.bp_len = breakinfo[breakno].len;
25226 bp->attr.bp_type = breakinfo[breakno].type;
25227 - info->address = breakinfo[breakno].addr;
25228 + if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
25229 + info->address = ktla_ktva(breakinfo[breakno].addr);
25230 + else
25231 + info->address = breakinfo[breakno].addr;
25232 info->len = breakinfo[breakno].len;
25233 info->type = breakinfo[breakno].type;
25234 val = arch_install_hw_breakpoint(bp);
25235 @@ -475,12 +478,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
25236 case 'k':
25237 /* clear the trace bit */
25238 linux_regs->flags &= ~X86_EFLAGS_TF;
25239 - atomic_set(&kgdb_cpu_doing_single_step, -1);
25240 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
25241
25242 /* set the trace bit if we're stepping */
25243 if (remcomInBuffer[0] == 's') {
25244 linux_regs->flags |= X86_EFLAGS_TF;
25245 - atomic_set(&kgdb_cpu_doing_single_step,
25246 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
25247 raw_smp_processor_id());
25248 }
25249
25250 @@ -545,7 +548,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
25251
25252 switch (cmd) {
25253 case DIE_DEBUG:
25254 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
25255 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
25256 if (user_mode(regs))
25257 return single_step_cont(regs, args);
25258 break;
25259 @@ -750,11 +753,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25260 #endif /* CONFIG_DEBUG_RODATA */
25261
25262 bpt->type = BP_BREAKPOINT;
25263 - err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
25264 + err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
25265 BREAK_INSTR_SIZE);
25266 if (err)
25267 return err;
25268 - err = probe_kernel_write((char *)bpt->bpt_addr,
25269 + err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25270 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
25271 #ifdef CONFIG_DEBUG_RODATA
25272 if (!err)
25273 @@ -767,7 +770,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
25274 return -EBUSY;
25275 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
25276 BREAK_INSTR_SIZE);
25277 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25278 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25279 if (err)
25280 return err;
25281 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
25282 @@ -792,13 +795,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
25283 if (mutex_is_locked(&text_mutex))
25284 goto knl_write;
25285 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
25286 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
25287 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
25288 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
25289 goto knl_write;
25290 return err;
25291 knl_write:
25292 #endif /* CONFIG_DEBUG_RODATA */
25293 - return probe_kernel_write((char *)bpt->bpt_addr,
25294 + return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
25295 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
25296 }
25297
25298 diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
25299 index 61b17dc..784bfe9 100644
25300 --- a/arch/x86/kernel/kprobes/core.c
25301 +++ b/arch/x86/kernel/kprobes/core.c
25302 @@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
25303 s32 raddr;
25304 } __packed *insn;
25305
25306 - insn = (struct __arch_relative_insn *)from;
25307 + insn = (struct __arch_relative_insn *)ktla_ktva(from);
25308 +
25309 + pax_open_kernel();
25310 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
25311 insn->op = op;
25312 + pax_close_kernel();
25313 }
25314
25315 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
25316 @@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
25317 kprobe_opcode_t opcode;
25318 kprobe_opcode_t *orig_opcodes = opcodes;
25319
25320 - if (search_exception_tables((unsigned long)opcodes))
25321 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
25322 return 0; /* Page fault may occur on this address. */
25323
25324 retry:
25325 @@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
25326 * for the first byte, we can recover the original instruction
25327 * from it and kp->opcode.
25328 */
25329 - memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25330 + memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
25331 buf[0] = kp->opcode;
25332 - return (unsigned long)buf;
25333 + return ktva_ktla((unsigned long)buf);
25334 }
25335
25336 /*
25337 @@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
25338 /* Another subsystem puts a breakpoint, failed to recover */
25339 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
25340 return 0;
25341 + pax_open_kernel();
25342 memcpy(dest, insn.kaddr, insn.length);
25343 + pax_close_kernel();
25344
25345 #ifdef CONFIG_X86_64
25346 if (insn_rip_relative(&insn)) {
25347 @@ -359,7 +364,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
25348 return 0;
25349 }
25350 disp = (u8 *) dest + insn_offset_displacement(&insn);
25351 + pax_open_kernel();
25352 *(s32 *) disp = (s32) newdisp;
25353 + pax_close_kernel();
25354 }
25355 #endif
25356 return insn.length;
25357 @@ -498,7 +505,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
25358 * nor set current_kprobe, because it doesn't use single
25359 * stepping.
25360 */
25361 - regs->ip = (unsigned long)p->ainsn.insn;
25362 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25363 preempt_enable_no_resched();
25364 return;
25365 }
25366 @@ -515,9 +522,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
25367 regs->flags &= ~X86_EFLAGS_IF;
25368 /* single step inline if the instruction is an int3 */
25369 if (p->opcode == BREAKPOINT_INSTRUCTION)
25370 - regs->ip = (unsigned long)p->addr;
25371 + regs->ip = ktla_ktva((unsigned long)p->addr);
25372 else
25373 - regs->ip = (unsigned long)p->ainsn.insn;
25374 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
25375 }
25376
25377 /*
25378 @@ -596,7 +603,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
25379 setup_singlestep(p, regs, kcb, 0);
25380 return 1;
25381 }
25382 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
25383 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
25384 /*
25385 * The breakpoint instruction was removed right
25386 * after we hit it. Another cpu has removed
25387 @@ -642,6 +649,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
25388 " movq %rax, 152(%rsp)\n"
25389 RESTORE_REGS_STRING
25390 " popfq\n"
25391 +#ifdef KERNEXEC_PLUGIN
25392 + " btsq $63,(%rsp)\n"
25393 +#endif
25394 #else
25395 " pushf\n"
25396 SAVE_REGS_STRING
25397 @@ -779,7 +789,7 @@ static void __kprobes
25398 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
25399 {
25400 unsigned long *tos = stack_addr(regs);
25401 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
25402 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
25403 unsigned long orig_ip = (unsigned long)p->addr;
25404 kprobe_opcode_t *insn = p->ainsn.insn;
25405
25406 @@ -959,7 +969,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
25407 struct die_args *args = data;
25408 int ret = NOTIFY_DONE;
25409
25410 - if (args->regs && user_mode_vm(args->regs))
25411 + if (args->regs && user_mode(args->regs))
25412 return ret;
25413
25414 switch (val) {
25415 diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
25416 index 898160b..758cde8 100644
25417 --- a/arch/x86/kernel/kprobes/opt.c
25418 +++ b/arch/x86/kernel/kprobes/opt.c
25419 @@ -79,6 +79,7 @@ found:
25420 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
25421 static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
25422 {
25423 + pax_open_kernel();
25424 #ifdef CONFIG_X86_64
25425 *addr++ = 0x48;
25426 *addr++ = 0xbf;
25427 @@ -86,6 +87,7 @@ static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long v
25428 *addr++ = 0xb8;
25429 #endif
25430 *(unsigned long *)addr = val;
25431 + pax_close_kernel();
25432 }
25433
25434 asm (
25435 @@ -335,7 +337,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25436 * Verify if the address gap is in 2GB range, because this uses
25437 * a relative jump.
25438 */
25439 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
25440 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
25441 if (abs(rel) > 0x7fffffff)
25442 return -ERANGE;
25443
25444 @@ -350,16 +352,18 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
25445 op->optinsn.size = ret;
25446
25447 /* Copy arch-dep-instance from template */
25448 - memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
25449 + pax_open_kernel();
25450 + memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
25451 + pax_close_kernel();
25452
25453 /* Set probe information */
25454 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
25455
25456 /* Set probe function call */
25457 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
25458 + synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
25459
25460 /* Set returning jmp instruction at the tail of out-of-line buffer */
25461 - synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
25462 + synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
25463 (u8 *)op->kp.addr + op->optinsn.size);
25464
25465 flush_icache_range((unsigned long) buf,
25466 @@ -384,7 +388,7 @@ void __kprobes arch_optimize_kprobes(struct list_head *oplist)
25467 WARN_ON(kprobe_disabled(&op->kp));
25468
25469 /* Backup instructions which will be replaced by jump address */
25470 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
25471 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
25472 RELATIVE_ADDR_SIZE);
25473
25474 insn_buf[0] = RELATIVEJUMP_OPCODE;
25475 @@ -433,7 +437,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
25476 /* This kprobe is really able to run optimized path. */
25477 op = container_of(p, struct optimized_kprobe, kp);
25478 /* Detour through copied instructions */
25479 - regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
25480 + regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
25481 if (!reenter)
25482 reset_current_kprobe();
25483 preempt_enable_no_resched();
25484 diff --git a/arch/x86/kernel/ksysfs.c b/arch/x86/kernel/ksysfs.c
25485 index c2bedae..25e7ab60 100644
25486 --- a/arch/x86/kernel/ksysfs.c
25487 +++ b/arch/x86/kernel/ksysfs.c
25488 @@ -184,7 +184,7 @@ out:
25489
25490 static struct kobj_attribute type_attr = __ATTR_RO(type);
25491
25492 -static struct bin_attribute data_attr = {
25493 +static bin_attribute_no_const data_attr __read_only = {
25494 .attr = {
25495 .name = "data",
25496 .mode = S_IRUGO,
25497 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
25498 index dcbbaa1..81ae763 100644
25499 --- a/arch/x86/kernel/ldt.c
25500 +++ b/arch/x86/kernel/ldt.c
25501 @@ -68,13 +68,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
25502 if (reload) {
25503 #ifdef CONFIG_SMP
25504 preempt_disable();
25505 - load_LDT(pc);
25506 + load_LDT_nolock(pc);
25507 if (!cpumask_equal(mm_cpumask(current->mm),
25508 cpumask_of(smp_processor_id())))
25509 smp_call_function(flush_ldt, current->mm, 1);
25510 preempt_enable();
25511 #else
25512 - load_LDT(pc);
25513 + load_LDT_nolock(pc);
25514 #endif
25515 }
25516 if (oldsize) {
25517 @@ -96,7 +96,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
25518 return err;
25519
25520 for (i = 0; i < old->size; i++)
25521 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
25522 + write_ldt_entry(new->ldt, i, old->ldt + i);
25523 return 0;
25524 }
25525
25526 @@ -117,6 +117,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
25527 retval = copy_ldt(&mm->context, &old_mm->context);
25528 mutex_unlock(&old_mm->context.lock);
25529 }
25530 +
25531 + if (tsk == current) {
25532 + mm->context.vdso = 0;
25533 +
25534 +#ifdef CONFIG_X86_32
25535 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
25536 + mm->context.user_cs_base = 0UL;
25537 + mm->context.user_cs_limit = ~0UL;
25538 +
25539 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
25540 + cpus_clear(mm->context.cpu_user_cs_mask);
25541 +#endif
25542 +
25543 +#endif
25544 +#endif
25545 +
25546 + }
25547 +
25548 return retval;
25549 }
25550
25551 @@ -231,6 +249,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
25552 }
25553 }
25554
25555 +#ifdef CONFIG_PAX_SEGMEXEC
25556 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
25557 + error = -EINVAL;
25558 + goto out_unlock;
25559 + }
25560 +#endif
25561 +
25562 /*
25563 * On x86-64 we do not support 16-bit segments due to
25564 * IRET leaking the high bits of the kernel stack address.
25565 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
25566 index 1667b1d..16492c5 100644
25567 --- a/arch/x86/kernel/machine_kexec_32.c
25568 +++ b/arch/x86/kernel/machine_kexec_32.c
25569 @@ -25,7 +25,7 @@
25570 #include <asm/cacheflush.h>
25571 #include <asm/debugreg.h>
25572
25573 -static void set_idt(void *newidt, __u16 limit)
25574 +static void set_idt(struct desc_struct *newidt, __u16 limit)
25575 {
25576 struct desc_ptr curidt;
25577
25578 @@ -37,7 +37,7 @@ static void set_idt(void *newidt, __u16 limit)
25579 }
25580
25581
25582 -static void set_gdt(void *newgdt, __u16 limit)
25583 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
25584 {
25585 struct desc_ptr curgdt;
25586
25587 @@ -215,7 +215,7 @@ void machine_kexec(struct kimage *image)
25588 }
25589
25590 control_page = page_address(image->control_code_page);
25591 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
25592 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
25593
25594 relocate_kernel_ptr = control_page;
25595 page_list[PA_CONTROL_PAGE] = __pa(control_page);
25596 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
25597 index e69f988..da078ea 100644
25598 --- a/arch/x86/kernel/module.c
25599 +++ b/arch/x86/kernel/module.c
25600 @@ -81,17 +81,62 @@ static unsigned long int get_module_load_offset(void)
25601 }
25602 #endif
25603
25604 -void *module_alloc(unsigned long size)
25605 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
25606 {
25607 - if (PAGE_ALIGN(size) > MODULES_LEN)
25608 + if (!size || PAGE_ALIGN(size) > MODULES_LEN)
25609 return NULL;
25610 return __vmalloc_node_range(size, 1,
25611 MODULES_VADDR + get_module_load_offset(),
25612 - MODULES_END, GFP_KERNEL | __GFP_HIGHMEM,
25613 - PAGE_KERNEL_EXEC, NUMA_NO_NODE,
25614 + MODULES_END, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO,
25615 + prot, NUMA_NO_NODE,
25616 __builtin_return_address(0));
25617 }
25618
25619 +void *module_alloc(unsigned long size)
25620 +{
25621 +
25622 +#ifdef CONFIG_PAX_KERNEXEC
25623 + return __module_alloc(size, PAGE_KERNEL);
25624 +#else
25625 + return __module_alloc(size, PAGE_KERNEL_EXEC);
25626 +#endif
25627 +
25628 +}
25629 +
25630 +#ifdef CONFIG_PAX_KERNEXEC
25631 +#ifdef CONFIG_X86_32
25632 +void *module_alloc_exec(unsigned long size)
25633 +{
25634 + struct vm_struct *area;
25635 +
25636 + if (size == 0)
25637 + return NULL;
25638 +
25639 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
25640 +return area ? area->addr : NULL;
25641 +}
25642 +EXPORT_SYMBOL(module_alloc_exec);
25643 +
25644 +void module_free_exec(struct module *mod, void *module_region)
25645 +{
25646 + vunmap(module_region);
25647 +}
25648 +EXPORT_SYMBOL(module_free_exec);
25649 +#else
25650 +void module_free_exec(struct module *mod, void *module_region)
25651 +{
25652 + module_free(mod, module_region);
25653 +}
25654 +EXPORT_SYMBOL(module_free_exec);
25655 +
25656 +void *module_alloc_exec(unsigned long size)
25657 +{
25658 + return __module_alloc(size, PAGE_KERNEL_RX);
25659 +}
25660 +EXPORT_SYMBOL(module_alloc_exec);
25661 +#endif
25662 +#endif
25663 +
25664 #ifdef CONFIG_X86_32
25665 int apply_relocate(Elf32_Shdr *sechdrs,
25666 const char *strtab,
25667 @@ -102,14 +147,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
25668 unsigned int i;
25669 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
25670 Elf32_Sym *sym;
25671 - uint32_t *location;
25672 + uint32_t *plocation, location;
25673
25674 DEBUGP("Applying relocate section %u to %u\n",
25675 relsec, sechdrs[relsec].sh_info);
25676 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
25677 /* This is where to make the change */
25678 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
25679 - + rel[i].r_offset;
25680 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
25681 + location = (uint32_t)plocation;
25682 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
25683 + plocation = ktla_ktva((void *)plocation);
25684 /* This is the symbol it is referring to. Note that all
25685 undefined symbols have been resolved. */
25686 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
25687 @@ -118,11 +165,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
25688 switch (ELF32_R_TYPE(rel[i].r_info)) {
25689 case R_386_32:
25690 /* We add the value into the location given */
25691 - *location += sym->st_value;
25692 + pax_open_kernel();
25693 + *plocation += sym->st_value;
25694 + pax_close_kernel();
25695 break;
25696 case R_386_PC32:
25697 /* Add the value, subtract its position */
25698 - *location += sym->st_value - (uint32_t)location;
25699 + pax_open_kernel();
25700 + *plocation += sym->st_value - location;
25701 + pax_close_kernel();
25702 break;
25703 default:
25704 pr_err("%s: Unknown relocation: %u\n",
25705 @@ -167,21 +218,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
25706 case R_X86_64_NONE:
25707 break;
25708 case R_X86_64_64:
25709 + pax_open_kernel();
25710 *(u64 *)loc = val;
25711 + pax_close_kernel();
25712 break;
25713 case R_X86_64_32:
25714 + pax_open_kernel();
25715 *(u32 *)loc = val;
25716 + pax_close_kernel();
25717 if (val != *(u32 *)loc)
25718 goto overflow;
25719 break;
25720 case R_X86_64_32S:
25721 + pax_open_kernel();
25722 *(s32 *)loc = val;
25723 + pax_close_kernel();
25724 if ((s64)val != *(s32 *)loc)
25725 goto overflow;
25726 break;
25727 case R_X86_64_PC32:
25728 val -= (u64)loc;
25729 + pax_open_kernel();
25730 *(u32 *)loc = val;
25731 + pax_close_kernel();
25732 +
25733 #if 0
25734 if ((s64)val != *(s32 *)loc)
25735 goto overflow;
25736 diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
25737 index c9603ac..9f88728 100644
25738 --- a/arch/x86/kernel/msr.c
25739 +++ b/arch/x86/kernel/msr.c
25740 @@ -37,6 +37,7 @@
25741 #include <linux/notifier.h>
25742 #include <linux/uaccess.h>
25743 #include <linux/gfp.h>
25744 +#include <linux/grsecurity.h>
25745
25746 #include <asm/processor.h>
25747 #include <asm/msr.h>
25748 @@ -103,6 +104,11 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
25749 int err = 0;
25750 ssize_t bytes = 0;
25751
25752 +#ifdef CONFIG_GRKERNSEC_KMEM
25753 + gr_handle_msr_write();
25754 + return -EPERM;
25755 +#endif
25756 +
25757 if (count % 8)
25758 return -EINVAL; /* Invalid chunk size */
25759
25760 @@ -150,6 +156,10 @@ static long msr_ioctl(struct file *file, unsigned int ioc, unsigned long arg)
25761 err = -EBADF;
25762 break;
25763 }
25764 +#ifdef CONFIG_GRKERNSEC_KMEM
25765 + gr_handle_msr_write();
25766 + return -EPERM;
25767 +#endif
25768 if (copy_from_user(&regs, uregs, sizeof regs)) {
25769 err = -EFAULT;
25770 break;
25771 @@ -233,7 +243,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
25772 return notifier_from_errno(err);
25773 }
25774
25775 -static struct notifier_block __refdata msr_class_cpu_notifier = {
25776 +static struct notifier_block msr_class_cpu_notifier = {
25777 .notifier_call = msr_class_cpu_callback,
25778 };
25779
25780 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
25781 index b4872b9..5bf0684 100644
25782 --- a/arch/x86/kernel/nmi.c
25783 +++ b/arch/x86/kernel/nmi.c
25784 @@ -98,16 +98,16 @@ fs_initcall(nmi_warning_debugfs);
25785
25786 static void nmi_max_handler(struct irq_work *w)
25787 {
25788 - struct nmiaction *a = container_of(w, struct nmiaction, irq_work);
25789 + struct nmiwork *n = container_of(w, struct nmiwork, irq_work);
25790 int remainder_ns, decimal_msecs;
25791 - u64 whole_msecs = ACCESS_ONCE(a->max_duration);
25792 + u64 whole_msecs = ACCESS_ONCE(n->max_duration);
25793
25794 remainder_ns = do_div(whole_msecs, (1000 * 1000));
25795 decimal_msecs = remainder_ns / 1000;
25796
25797 printk_ratelimited(KERN_INFO
25798 "INFO: NMI handler (%ps) took too long to run: %lld.%03d msecs\n",
25799 - a->handler, whole_msecs, decimal_msecs);
25800 + n->action->handler, whole_msecs, decimal_msecs);
25801 }
25802
25803 static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2b)
25804 @@ -134,11 +134,11 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
25805 delta = sched_clock() - delta;
25806 trace_nmi_handler(a->handler, (int)delta, thishandled);
25807
25808 - if (delta < nmi_longest_ns || delta < a->max_duration)
25809 + if (delta < nmi_longest_ns || delta < a->work->max_duration)
25810 continue;
25811
25812 - a->max_duration = delta;
25813 - irq_work_queue(&a->irq_work);
25814 + a->work->max_duration = delta;
25815 + irq_work_queue(&a->work->irq_work);
25816 }
25817
25818 rcu_read_unlock();
25819 @@ -147,7 +147,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
25820 return handled;
25821 }
25822
25823 -int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25824 +int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
25825 {
25826 struct nmi_desc *desc = nmi_to_desc(type);
25827 unsigned long flags;
25828 @@ -155,7 +155,8 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25829 if (!action->handler)
25830 return -EINVAL;
25831
25832 - init_irq_work(&action->irq_work, nmi_max_handler);
25833 + action->work->action = action;
25834 + init_irq_work(&action->work->irq_work, nmi_max_handler);
25835
25836 spin_lock_irqsave(&desc->lock, flags);
25837
25838 @@ -173,9 +174,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25839 * event confuses some handlers (kdump uses this flag)
25840 */
25841 if (action->flags & NMI_FLAG_FIRST)
25842 - list_add_rcu(&action->list, &desc->head);
25843 + pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
25844 else
25845 - list_add_tail_rcu(&action->list, &desc->head);
25846 + pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
25847
25848 spin_unlock_irqrestore(&desc->lock, flags);
25849 return 0;
25850 @@ -198,7 +199,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
25851 if (!strcmp(n->name, name)) {
25852 WARN(in_nmi(),
25853 "Trying to free NMI (%s) from NMI context!\n", n->name);
25854 - list_del_rcu(&n->list);
25855 + pax_list_del_rcu((struct list_head *)&n->list);
25856 break;
25857 }
25858 }
25859 @@ -523,6 +524,17 @@ static inline void nmi_nesting_postprocess(void)
25860 dotraplinkage notrace __kprobes void
25861 do_nmi(struct pt_regs *regs, long error_code)
25862 {
25863 +
25864 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25865 + if (!user_mode(regs)) {
25866 + unsigned long cs = regs->cs & 0xFFFF;
25867 + unsigned long ip = ktva_ktla(regs->ip);
25868 +
25869 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
25870 + regs->ip = ip;
25871 + }
25872 +#endif
25873 +
25874 nmi_nesting_preprocess(regs);
25875
25876 nmi_enter();
25877 diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
25878 index 6d9582e..f746287 100644
25879 --- a/arch/x86/kernel/nmi_selftest.c
25880 +++ b/arch/x86/kernel/nmi_selftest.c
25881 @@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
25882 {
25883 /* trap all the unknown NMIs we may generate */
25884 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
25885 - __initdata);
25886 + __initconst);
25887 }
25888
25889 static void __init cleanup_nmi_testsuite(void)
25890 @@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
25891 unsigned long timeout;
25892
25893 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
25894 - NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
25895 + NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
25896 nmi_fail = FAILURE;
25897 return;
25898 }
25899 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
25900 index bbb6c73..24a58ef 100644
25901 --- a/arch/x86/kernel/paravirt-spinlocks.c
25902 +++ b/arch/x86/kernel/paravirt-spinlocks.c
25903 @@ -8,7 +8,7 @@
25904
25905 #include <asm/paravirt.h>
25906
25907 -struct pv_lock_ops pv_lock_ops = {
25908 +struct pv_lock_ops pv_lock_ops __read_only = {
25909 #ifdef CONFIG_SMP
25910 .lock_spinning = __PV_IS_CALLEE_SAVE(paravirt_nop),
25911 .unlock_kick = paravirt_nop,
25912 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
25913 index 1b10af8..45bfbec 100644
25914 --- a/arch/x86/kernel/paravirt.c
25915 +++ b/arch/x86/kernel/paravirt.c
25916 @@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
25917 {
25918 return x;
25919 }
25920 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25921 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
25922 +#endif
25923
25924 void __init default_banner(void)
25925 {
25926 @@ -141,16 +144,20 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
25927
25928 if (opfunc == NULL)
25929 /* If there's no function, patch it with a ud2a (BUG) */
25930 - ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
25931 - else if (opfunc == _paravirt_nop)
25932 + ret = paravirt_patch_insns(insnbuf, len, ktva_ktla(ud2a), ud2a+sizeof(ud2a));
25933 + else if (opfunc == (void *)_paravirt_nop)
25934 /* If the operation is a nop, then nop the callsite */
25935 ret = paravirt_patch_nop();
25936
25937 /* identity functions just return their single argument */
25938 - else if (opfunc == _paravirt_ident_32)
25939 + else if (opfunc == (void *)_paravirt_ident_32)
25940 ret = paravirt_patch_ident_32(insnbuf, len);
25941 - else if (opfunc == _paravirt_ident_64)
25942 + else if (opfunc == (void *)_paravirt_ident_64)
25943 ret = paravirt_patch_ident_64(insnbuf, len);
25944 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25945 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
25946 + ret = paravirt_patch_ident_64(insnbuf, len);
25947 +#endif
25948
25949 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
25950 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
25951 @@ -175,7 +182,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
25952 if (insn_len > len || start == NULL)
25953 insn_len = len;
25954 else
25955 - memcpy(insnbuf, start, insn_len);
25956 + memcpy(insnbuf, ktla_ktva(start), insn_len);
25957
25958 return insn_len;
25959 }
25960 @@ -299,7 +306,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
25961 return this_cpu_read(paravirt_lazy_mode);
25962 }
25963
25964 -struct pv_info pv_info = {
25965 +struct pv_info pv_info __read_only = {
25966 .name = "bare hardware",
25967 .paravirt_enabled = 0,
25968 .kernel_rpl = 0,
25969 @@ -310,16 +317,16 @@ struct pv_info pv_info = {
25970 #endif
25971 };
25972
25973 -struct pv_init_ops pv_init_ops = {
25974 +struct pv_init_ops pv_init_ops __read_only = {
25975 .patch = native_patch,
25976 };
25977
25978 -struct pv_time_ops pv_time_ops = {
25979 +struct pv_time_ops pv_time_ops __read_only = {
25980 .sched_clock = native_sched_clock,
25981 .steal_clock = native_steal_clock,
25982 };
25983
25984 -__visible struct pv_irq_ops pv_irq_ops = {
25985 +__visible struct pv_irq_ops pv_irq_ops __read_only = {
25986 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
25987 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
25988 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
25989 @@ -331,7 +338,7 @@ __visible struct pv_irq_ops pv_irq_ops = {
25990 #endif
25991 };
25992
25993 -__visible struct pv_cpu_ops pv_cpu_ops = {
25994 +__visible struct pv_cpu_ops pv_cpu_ops __read_only = {
25995 .cpuid = native_cpuid,
25996 .get_debugreg = native_get_debugreg,
25997 .set_debugreg = native_set_debugreg,
25998 @@ -389,21 +396,26 @@ __visible struct pv_cpu_ops pv_cpu_ops = {
25999 .end_context_switch = paravirt_nop,
26000 };
26001
26002 -struct pv_apic_ops pv_apic_ops = {
26003 +struct pv_apic_ops pv_apic_ops __read_only= {
26004 #ifdef CONFIG_X86_LOCAL_APIC
26005 .startup_ipi_hook = paravirt_nop,
26006 #endif
26007 };
26008
26009 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
26010 +#ifdef CONFIG_X86_32
26011 +#ifdef CONFIG_X86_PAE
26012 +/* 64-bit pagetable entries */
26013 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
26014 +#else
26015 /* 32-bit pagetable entries */
26016 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
26017 +#endif
26018 #else
26019 /* 64-bit pagetable entries */
26020 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
26021 #endif
26022
26023 -struct pv_mmu_ops pv_mmu_ops = {
26024 +struct pv_mmu_ops pv_mmu_ops __read_only = {
26025
26026 .read_cr2 = native_read_cr2,
26027 .write_cr2 = native_write_cr2,
26028 @@ -453,6 +465,7 @@ struct pv_mmu_ops pv_mmu_ops = {
26029 .make_pud = PTE_IDENT,
26030
26031 .set_pgd = native_set_pgd,
26032 + .set_pgd_batched = native_set_pgd_batched,
26033 #endif
26034 #endif /* PAGETABLE_LEVELS >= 3 */
26035
26036 @@ -473,6 +486,12 @@ struct pv_mmu_ops pv_mmu_ops = {
26037 },
26038
26039 .set_fixmap = native_set_fixmap,
26040 +
26041 +#ifdef CONFIG_PAX_KERNEXEC
26042 + .pax_open_kernel = native_pax_open_kernel,
26043 + .pax_close_kernel = native_pax_close_kernel,
26044 +#endif
26045 +
26046 };
26047
26048 EXPORT_SYMBOL_GPL(pv_time_ops);
26049 diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
26050 index 0497f71..7186c0d 100644
26051 --- a/arch/x86/kernel/pci-calgary_64.c
26052 +++ b/arch/x86/kernel/pci-calgary_64.c
26053 @@ -1347,7 +1347,7 @@ static void __init get_tce_space_from_tar(void)
26054 tce_space = be64_to_cpu(readq(target));
26055 tce_space = tce_space & TAR_SW_BITS;
26056
26057 - tce_space = tce_space & (~specified_table_size);
26058 + tce_space = tce_space & (~(unsigned long)specified_table_size);
26059 info->tce_space = (u64 *)__va(tce_space);
26060 }
26061 }
26062 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
26063 index 35ccf75..7a15747 100644
26064 --- a/arch/x86/kernel/pci-iommu_table.c
26065 +++ b/arch/x86/kernel/pci-iommu_table.c
26066 @@ -2,7 +2,7 @@
26067 #include <asm/iommu_table.h>
26068 #include <linux/string.h>
26069 #include <linux/kallsyms.h>
26070 -
26071 +#include <linux/sched.h>
26072
26073 #define DEBUG 1
26074
26075 diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
26076 index 6c483ba..d10ce2f 100644
26077 --- a/arch/x86/kernel/pci-swiotlb.c
26078 +++ b/arch/x86/kernel/pci-swiotlb.c
26079 @@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
26080 void *vaddr, dma_addr_t dma_addr,
26081 struct dma_attrs *attrs)
26082 {
26083 - swiotlb_free_coherent(dev, size, vaddr, dma_addr);
26084 + swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
26085 }
26086
26087 static struct dma_map_ops swiotlb_dma_ops = {
26088 diff --git a/arch/x86/kernel/preempt.S b/arch/x86/kernel/preempt.S
26089 index ca7f0d5..8996469 100644
26090 --- a/arch/x86/kernel/preempt.S
26091 +++ b/arch/x86/kernel/preempt.S
26092 @@ -3,12 +3,14 @@
26093 #include <asm/dwarf2.h>
26094 #include <asm/asm.h>
26095 #include <asm/calling.h>
26096 +#include <asm/alternative-asm.h>
26097
26098 ENTRY(___preempt_schedule)
26099 CFI_STARTPROC
26100 SAVE_ALL
26101 call preempt_schedule
26102 RESTORE_ALL
26103 + pax_force_retaddr
26104 ret
26105 CFI_ENDPROC
26106
26107 @@ -19,6 +21,7 @@ ENTRY(___preempt_schedule_context)
26108 SAVE_ALL
26109 call preempt_schedule_context
26110 RESTORE_ALL
26111 + pax_force_retaddr
26112 ret
26113 CFI_ENDPROC
26114
26115 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
26116 index 4505e2a..ae28b0d 100644
26117 --- a/arch/x86/kernel/process.c
26118 +++ b/arch/x86/kernel/process.c
26119 @@ -36,7 +36,8 @@
26120 * section. Since TSS's are completely CPU-local, we want them
26121 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
26122 */
26123 -__visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
26124 +struct tss_struct init_tss[NR_CPUS] __visible ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
26125 +EXPORT_SYMBOL(init_tss);
26126
26127 #ifdef CONFIG_X86_64
26128 static DEFINE_PER_CPU(unsigned char, is_idle);
26129 @@ -92,7 +93,7 @@ void arch_task_cache_init(void)
26130 task_xstate_cachep =
26131 kmem_cache_create("task_xstate", xstate_size,
26132 __alignof__(union thread_xstate),
26133 - SLAB_PANIC | SLAB_NOTRACK, NULL);
26134 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
26135 }
26136
26137 /*
26138 @@ -105,7 +106,7 @@ void exit_thread(void)
26139 unsigned long *bp = t->io_bitmap_ptr;
26140
26141 if (bp) {
26142 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
26143 + struct tss_struct *tss = init_tss + get_cpu();
26144
26145 t->io_bitmap_ptr = NULL;
26146 clear_thread_flag(TIF_IO_BITMAP);
26147 @@ -125,6 +126,9 @@ void flush_thread(void)
26148 {
26149 struct task_struct *tsk = current;
26150
26151 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
26152 + loadsegment(gs, 0);
26153 +#endif
26154 flush_ptrace_hw_breakpoint(tsk);
26155 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
26156 drop_init_fpu(tsk);
26157 @@ -271,7 +275,7 @@ static void __exit_idle(void)
26158 void exit_idle(void)
26159 {
26160 /* idle loop has pid 0 */
26161 - if (current->pid)
26162 + if (task_pid_nr(current))
26163 return;
26164 __exit_idle();
26165 }
26166 @@ -324,7 +328,7 @@ bool xen_set_default_idle(void)
26167 return ret;
26168 }
26169 #endif
26170 -void stop_this_cpu(void *dummy)
26171 +__noreturn void stop_this_cpu(void *dummy)
26172 {
26173 local_irq_disable();
26174 /*
26175 @@ -453,16 +457,37 @@ static int __init idle_setup(char *str)
26176 }
26177 early_param("idle", idle_setup);
26178
26179 -unsigned long arch_align_stack(unsigned long sp)
26180 +#ifdef CONFIG_PAX_RANDKSTACK
26181 +void pax_randomize_kstack(struct pt_regs *regs)
26182 {
26183 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
26184 - sp -= get_random_int() % 8192;
26185 - return sp & ~0xf;
26186 -}
26187 + struct thread_struct *thread = &current->thread;
26188 + unsigned long time;
26189
26190 -unsigned long arch_randomize_brk(struct mm_struct *mm)
26191 -{
26192 - unsigned long range_end = mm->brk + 0x02000000;
26193 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
26194 -}
26195 + if (!randomize_va_space)
26196 + return;
26197 +
26198 + if (v8086_mode(regs))
26199 + return;
26200
26201 + rdtscl(time);
26202 +
26203 + /* P4 seems to return a 0 LSB, ignore it */
26204 +#ifdef CONFIG_MPENTIUM4
26205 + time &= 0x3EUL;
26206 + time <<= 2;
26207 +#elif defined(CONFIG_X86_64)
26208 + time &= 0xFUL;
26209 + time <<= 4;
26210 +#else
26211 + time &= 0x1FUL;
26212 + time <<= 3;
26213 +#endif
26214 +
26215 + thread->sp0 ^= time;
26216 + load_sp0(init_tss + smp_processor_id(), thread);
26217 +
26218 +#ifdef CONFIG_X86_64
26219 + this_cpu_write(kernel_stack, thread->sp0);
26220 +#endif
26221 +}
26222 +#endif
26223 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
26224 index 7bc86bb..0ea06e8 100644
26225 --- a/arch/x86/kernel/process_32.c
26226 +++ b/arch/x86/kernel/process_32.c
26227 @@ -64,6 +64,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
26228 unsigned long thread_saved_pc(struct task_struct *tsk)
26229 {
26230 return ((unsigned long *)tsk->thread.sp)[3];
26231 +//XXX return tsk->thread.eip;
26232 }
26233
26234 void __show_regs(struct pt_regs *regs, int all)
26235 @@ -73,19 +74,18 @@ void __show_regs(struct pt_regs *regs, int all)
26236 unsigned long sp;
26237 unsigned short ss, gs;
26238
26239 - if (user_mode_vm(regs)) {
26240 + if (user_mode(regs)) {
26241 sp = regs->sp;
26242 ss = regs->ss & 0xffff;
26243 - gs = get_user_gs(regs);
26244 } else {
26245 sp = kernel_stack_pointer(regs);
26246 savesegment(ss, ss);
26247 - savesegment(gs, gs);
26248 }
26249 + gs = get_user_gs(regs);
26250
26251 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
26252 (u16)regs->cs, regs->ip, regs->flags,
26253 - smp_processor_id());
26254 + raw_smp_processor_id());
26255 print_symbol("EIP is at %s\n", regs->ip);
26256
26257 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
26258 @@ -132,20 +132,21 @@ void release_thread(struct task_struct *dead_task)
26259 int copy_thread(unsigned long clone_flags, unsigned long sp,
26260 unsigned long arg, struct task_struct *p)
26261 {
26262 - struct pt_regs *childregs = task_pt_regs(p);
26263 + struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
26264 struct task_struct *tsk;
26265 int err;
26266
26267 p->thread.sp = (unsigned long) childregs;
26268 p->thread.sp0 = (unsigned long) (childregs+1);
26269 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26270
26271 if (unlikely(p->flags & PF_KTHREAD)) {
26272 /* kernel thread */
26273 memset(childregs, 0, sizeof(struct pt_regs));
26274 p->thread.ip = (unsigned long) ret_from_kernel_thread;
26275 - task_user_gs(p) = __KERNEL_STACK_CANARY;
26276 - childregs->ds = __USER_DS;
26277 - childregs->es = __USER_DS;
26278 + savesegment(gs, childregs->gs);
26279 + childregs->ds = __KERNEL_DS;
26280 + childregs->es = __KERNEL_DS;
26281 childregs->fs = __KERNEL_PERCPU;
26282 childregs->bx = sp; /* function */
26283 childregs->bp = arg;
26284 @@ -252,7 +253,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26285 struct thread_struct *prev = &prev_p->thread,
26286 *next = &next_p->thread;
26287 int cpu = smp_processor_id();
26288 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
26289 + struct tss_struct *tss = init_tss + cpu;
26290 fpu_switch_t fpu;
26291
26292 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
26293 @@ -276,6 +277,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26294 */
26295 lazy_save_gs(prev->gs);
26296
26297 +#ifdef CONFIG_PAX_MEMORY_UDEREF
26298 + __set_fs(task_thread_info(next_p)->addr_limit);
26299 +#endif
26300 +
26301 /*
26302 * Load the per-thread Thread-Local Storage descriptor.
26303 */
26304 @@ -314,9 +319,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26305 */
26306 arch_end_context_switch(next_p);
26307
26308 - this_cpu_write(kernel_stack,
26309 - (unsigned long)task_stack_page(next_p) +
26310 - THREAD_SIZE - KERNEL_STACK_OFFSET);
26311 + this_cpu_write(current_task, next_p);
26312 + this_cpu_write(current_tinfo, &next_p->tinfo);
26313 + this_cpu_write(kernel_stack, next->sp0);
26314
26315 /*
26316 * Restore %gs if needed (which is common)
26317 @@ -326,8 +331,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26318
26319 switch_fpu_finish(next_p, fpu);
26320
26321 - this_cpu_write(current_task, next_p);
26322 -
26323 return prev_p;
26324 }
26325
26326 @@ -357,4 +360,3 @@ unsigned long get_wchan(struct task_struct *p)
26327 } while (count++ < 16);
26328 return 0;
26329 }
26330 -
26331 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
26332 index 898d077..4c458ff 100644
26333 --- a/arch/x86/kernel/process_64.c
26334 +++ b/arch/x86/kernel/process_64.c
26335 @@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26336 struct pt_regs *childregs;
26337 struct task_struct *me = current;
26338
26339 - p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
26340 + p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
26341 childregs = task_pt_regs(p);
26342 p->thread.sp = (unsigned long) childregs;
26343 p->thread.usersp = me->thread.usersp;
26344 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
26345 set_tsk_thread_flag(p, TIF_FORK);
26346 p->thread.fpu_counter = 0;
26347 p->thread.io_bitmap_ptr = NULL;
26348 @@ -172,6 +173,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
26349 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
26350 savesegment(es, p->thread.es);
26351 savesegment(ds, p->thread.ds);
26352 + savesegment(ss, p->thread.ss);
26353 + BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
26354 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
26355
26356 if (unlikely(p->flags & PF_KTHREAD)) {
26357 @@ -280,7 +283,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26358 struct thread_struct *prev = &prev_p->thread;
26359 struct thread_struct *next = &next_p->thread;
26360 int cpu = smp_processor_id();
26361 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
26362 + struct tss_struct *tss = init_tss + cpu;
26363 unsigned fsindex, gsindex;
26364 fpu_switch_t fpu;
26365
26366 @@ -303,6 +306,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26367 if (unlikely(next->ds | prev->ds))
26368 loadsegment(ds, next->ds);
26369
26370 + savesegment(ss, prev->ss);
26371 + if (unlikely(next->ss != prev->ss))
26372 + loadsegment(ss, next->ss);
26373
26374 /* We must save %fs and %gs before load_TLS() because
26375 * %fs and %gs may be cleared by load_TLS().
26376 @@ -362,6 +368,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26377 prev->usersp = this_cpu_read(old_rsp);
26378 this_cpu_write(old_rsp, next->usersp);
26379 this_cpu_write(current_task, next_p);
26380 + this_cpu_write(current_tinfo, &next_p->tinfo);
26381
26382 /*
26383 * If it were not for PREEMPT_ACTIVE we could guarantee that the
26384 @@ -371,9 +378,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
26385 task_thread_info(prev_p)->saved_preempt_count = this_cpu_read(__preempt_count);
26386 this_cpu_write(__preempt_count, task_thread_info(next_p)->saved_preempt_count);
26387
26388 - this_cpu_write(kernel_stack,
26389 - (unsigned long)task_stack_page(next_p) +
26390 - THREAD_SIZE - KERNEL_STACK_OFFSET);
26391 + this_cpu_write(kernel_stack, next->sp0);
26392
26393 /*
26394 * Now maybe reload the debug registers and handle I/O bitmaps
26395 @@ -442,12 +447,11 @@ unsigned long get_wchan(struct task_struct *p)
26396 if (!p || p == current || p->state == TASK_RUNNING)
26397 return 0;
26398 stack = (unsigned long)task_stack_page(p);
26399 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
26400 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
26401 return 0;
26402 fp = *(u64 *)(p->thread.sp);
26403 do {
26404 - if (fp < (unsigned long)stack ||
26405 - fp >= (unsigned long)stack+THREAD_SIZE)
26406 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
26407 return 0;
26408 ip = *(u64 *)(fp+8);
26409 if (!in_sched_functions(ip))
26410 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
26411 index 678c0ad..2fc2a7b 100644
26412 --- a/arch/x86/kernel/ptrace.c
26413 +++ b/arch/x86/kernel/ptrace.c
26414 @@ -186,10 +186,10 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
26415 unsigned long sp = (unsigned long)&regs->sp;
26416 u32 *prev_esp;
26417
26418 - if (context == (sp & ~(THREAD_SIZE - 1)))
26419 + if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
26420 return sp;
26421
26422 - prev_esp = (u32 *)(context);
26423 + prev_esp = *(u32 **)(context);
26424 if (prev_esp)
26425 return (unsigned long)prev_esp;
26426
26427 @@ -452,6 +452,20 @@ static int putreg(struct task_struct *child,
26428 if (child->thread.gs != value)
26429 return do_arch_prctl(child, ARCH_SET_GS, value);
26430 return 0;
26431 +
26432 + case offsetof(struct user_regs_struct,ip):
26433 + /*
26434 + * Protect against any attempt to set ip to an
26435 + * impossible address. There are dragons lurking if the
26436 + * address is noncanonical. (This explicitly allows
26437 + * setting ip to TASK_SIZE_MAX, because user code can do
26438 + * that all by itself by running off the end of its
26439 + * address space.
26440 + */
26441 + if (value > TASK_SIZE_MAX)
26442 + return -EIO;
26443 + break;
26444 +
26445 #endif
26446 }
26447
26448 @@ -588,7 +602,7 @@ static void ptrace_triggered(struct perf_event *bp,
26449 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
26450 {
26451 int i;
26452 - int dr7 = 0;
26453 + unsigned long dr7 = 0;
26454 struct arch_hw_breakpoint *info;
26455
26456 for (i = 0; i < HBP_NUM; i++) {
26457 @@ -822,7 +836,7 @@ long arch_ptrace(struct task_struct *child, long request,
26458 unsigned long addr, unsigned long data)
26459 {
26460 int ret;
26461 - unsigned long __user *datap = (unsigned long __user *)data;
26462 + unsigned long __user *datap = (__force unsigned long __user *)data;
26463
26464 switch (request) {
26465 /* read the word at location addr in the USER area. */
26466 @@ -907,14 +921,14 @@ long arch_ptrace(struct task_struct *child, long request,
26467 if ((int) addr < 0)
26468 return -EIO;
26469 ret = do_get_thread_area(child, addr,
26470 - (struct user_desc __user *)data);
26471 + (__force struct user_desc __user *) data);
26472 break;
26473
26474 case PTRACE_SET_THREAD_AREA:
26475 if ((int) addr < 0)
26476 return -EIO;
26477 ret = do_set_thread_area(child, addr,
26478 - (struct user_desc __user *)data, 0);
26479 + (__force struct user_desc __user *) data, 0);
26480 break;
26481 #endif
26482
26483 @@ -1292,7 +1306,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
26484
26485 #ifdef CONFIG_X86_64
26486
26487 -static struct user_regset x86_64_regsets[] __read_mostly = {
26488 +static user_regset_no_const x86_64_regsets[] __read_only = {
26489 [REGSET_GENERAL] = {
26490 .core_note_type = NT_PRSTATUS,
26491 .n = sizeof(struct user_regs_struct) / sizeof(long),
26492 @@ -1333,7 +1347,7 @@ static const struct user_regset_view user_x86_64_view = {
26493 #endif /* CONFIG_X86_64 */
26494
26495 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
26496 -static struct user_regset x86_32_regsets[] __read_mostly = {
26497 +static user_regset_no_const x86_32_regsets[] __read_only = {
26498 [REGSET_GENERAL] = {
26499 .core_note_type = NT_PRSTATUS,
26500 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
26501 @@ -1386,7 +1400,7 @@ static const struct user_regset_view user_x86_32_view = {
26502 */
26503 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
26504
26505 -void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26506 +void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
26507 {
26508 #ifdef CONFIG_X86_64
26509 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
26510 @@ -1421,7 +1435,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
26511 memset(info, 0, sizeof(*info));
26512 info->si_signo = SIGTRAP;
26513 info->si_code = si_code;
26514 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
26515 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
26516 }
26517
26518 void user_single_step_siginfo(struct task_struct *tsk,
26519 @@ -1450,6 +1464,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
26520 # define IS_IA32 0
26521 #endif
26522
26523 +#ifdef CONFIG_GRKERNSEC_SETXID
26524 +extern void gr_delayed_cred_worker(void);
26525 +#endif
26526 +
26527 /*
26528 * We must return the syscall number to actually look up in the table.
26529 * This can be -1L to skip running any syscall at all.
26530 @@ -1460,6 +1478,11 @@ long syscall_trace_enter(struct pt_regs *regs)
26531
26532 user_exit();
26533
26534 +#ifdef CONFIG_GRKERNSEC_SETXID
26535 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26536 + gr_delayed_cred_worker();
26537 +#endif
26538 +
26539 /*
26540 * If we stepped into a sysenter/syscall insn, it trapped in
26541 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
26542 @@ -1515,6 +1538,11 @@ void syscall_trace_leave(struct pt_regs *regs)
26543 */
26544 user_exit();
26545
26546 +#ifdef CONFIG_GRKERNSEC_SETXID
26547 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
26548 + gr_delayed_cred_worker();
26549 +#endif
26550 +
26551 audit_syscall_exit(regs);
26552
26553 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
26554 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
26555 index 2f355d2..e75ed0a 100644
26556 --- a/arch/x86/kernel/pvclock.c
26557 +++ b/arch/x86/kernel/pvclock.c
26558 @@ -51,11 +51,11 @@ void pvclock_touch_watchdogs(void)
26559 reset_hung_task_detector();
26560 }
26561
26562 -static atomic64_t last_value = ATOMIC64_INIT(0);
26563 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
26564
26565 void pvclock_resume(void)
26566 {
26567 - atomic64_set(&last_value, 0);
26568 + atomic64_set_unchecked(&last_value, 0);
26569 }
26570
26571 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
26572 @@ -105,11 +105,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
26573 * updating at the same time, and one of them could be slightly behind,
26574 * making the assumption that last_value always go forward fail to hold.
26575 */
26576 - last = atomic64_read(&last_value);
26577 + last = atomic64_read_unchecked(&last_value);
26578 do {
26579 if (ret < last)
26580 return last;
26581 - last = atomic64_cmpxchg(&last_value, last, ret);
26582 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
26583 } while (unlikely(last != ret));
26584
26585 return ret;
26586 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
26587 index 52b1157..c6e67c4 100644
26588 --- a/arch/x86/kernel/reboot.c
26589 +++ b/arch/x86/kernel/reboot.c
26590 @@ -68,6 +68,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
26591
26592 void __noreturn machine_real_restart(unsigned int type)
26593 {
26594 +
26595 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
26596 + struct desc_struct *gdt;
26597 +#endif
26598 +
26599 local_irq_disable();
26600
26601 /*
26602 @@ -95,7 +100,29 @@ void __noreturn machine_real_restart(unsigned int type)
26603
26604 /* Jump to the identity-mapped low memory code */
26605 #ifdef CONFIG_X86_32
26606 - asm volatile("jmpl *%0" : :
26607 +
26608 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
26609 + gdt = get_cpu_gdt_table(smp_processor_id());
26610 + pax_open_kernel();
26611 +#ifdef CONFIG_PAX_MEMORY_UDEREF
26612 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
26613 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
26614 + loadsegment(ds, __KERNEL_DS);
26615 + loadsegment(es, __KERNEL_DS);
26616 + loadsegment(ss, __KERNEL_DS);
26617 +#endif
26618 +#ifdef CONFIG_PAX_KERNEXEC
26619 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
26620 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
26621 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
26622 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
26623 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
26624 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
26625 +#endif
26626 + pax_close_kernel();
26627 +#endif
26628 +
26629 + asm volatile("ljmpl *%0" : :
26630 "rm" (real_mode_header->machine_real_restart_asm),
26631 "a" (type));
26632 #else
26633 @@ -486,7 +513,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
26634 * This means that this function can never return, it can misbehave
26635 * by not rebooting properly and hanging.
26636 */
26637 -static void native_machine_emergency_restart(void)
26638 +static void __noreturn native_machine_emergency_restart(void)
26639 {
26640 int i;
26641 int attempt = 0;
26642 @@ -610,13 +637,13 @@ void native_machine_shutdown(void)
26643 #endif
26644 }
26645
26646 -static void __machine_emergency_restart(int emergency)
26647 +static void __noreturn __machine_emergency_restart(int emergency)
26648 {
26649 reboot_emergency = emergency;
26650 machine_ops.emergency_restart();
26651 }
26652
26653 -static void native_machine_restart(char *__unused)
26654 +static void __noreturn native_machine_restart(char *__unused)
26655 {
26656 pr_notice("machine restart\n");
26657
26658 @@ -625,7 +652,7 @@ static void native_machine_restart(char *__unused)
26659 __machine_emergency_restart(0);
26660 }
26661
26662 -static void native_machine_halt(void)
26663 +static void __noreturn native_machine_halt(void)
26664 {
26665 /* Stop other cpus and apics */
26666 machine_shutdown();
26667 @@ -635,7 +662,7 @@ static void native_machine_halt(void)
26668 stop_this_cpu(NULL);
26669 }
26670
26671 -static void native_machine_power_off(void)
26672 +static void __noreturn native_machine_power_off(void)
26673 {
26674 if (pm_power_off) {
26675 if (!reboot_force)
26676 @@ -644,9 +671,10 @@ static void native_machine_power_off(void)
26677 }
26678 /* A fallback in case there is no PM info available */
26679 tboot_shutdown(TB_SHUTDOWN_HALT);
26680 + unreachable();
26681 }
26682
26683 -struct machine_ops machine_ops = {
26684 +struct machine_ops machine_ops __read_only = {
26685 .power_off = native_machine_power_off,
26686 .shutdown = native_machine_shutdown,
26687 .emergency_restart = native_machine_emergency_restart,
26688 diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
26689 index c8e41e9..64049ef 100644
26690 --- a/arch/x86/kernel/reboot_fixups_32.c
26691 +++ b/arch/x86/kernel/reboot_fixups_32.c
26692 @@ -57,7 +57,7 @@ struct device_fixup {
26693 unsigned int vendor;
26694 unsigned int device;
26695 void (*reboot_fixup)(struct pci_dev *);
26696 -};
26697 +} __do_const;
26698
26699 /*
26700 * PCI ids solely used for fixups_table go here
26701 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
26702 index 3fd2c69..a444264 100644
26703 --- a/arch/x86/kernel/relocate_kernel_64.S
26704 +++ b/arch/x86/kernel/relocate_kernel_64.S
26705 @@ -96,8 +96,7 @@ relocate_kernel:
26706
26707 /* jump to identity mapped page */
26708 addq $(identity_mapped - relocate_kernel), %r8
26709 - pushq %r8
26710 - ret
26711 + jmp *%r8
26712
26713 identity_mapped:
26714 /* set return address to 0 if not preserving context */
26715 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
26716 index 09c76d2..7f33fc2 100644
26717 --- a/arch/x86/kernel/setup.c
26718 +++ b/arch/x86/kernel/setup.c
26719 @@ -110,6 +110,7 @@
26720 #include <asm/mce.h>
26721 #include <asm/alternative.h>
26722 #include <asm/prom.h>
26723 +#include <asm/boot.h>
26724
26725 /*
26726 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
26727 @@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
26728 #endif
26729
26730
26731 -#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
26732 -__visible unsigned long mmu_cr4_features;
26733 +#ifdef CONFIG_X86_64
26734 +__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
26735 +#elif defined(CONFIG_X86_PAE)
26736 +__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
26737 #else
26738 -__visible unsigned long mmu_cr4_features = X86_CR4_PAE;
26739 +__visible unsigned long mmu_cr4_features __read_only;
26740 #endif
26741
26742 +void set_in_cr4(unsigned long mask)
26743 +{
26744 + unsigned long cr4 = read_cr4();
26745 +
26746 + if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
26747 + return;
26748 +
26749 + pax_open_kernel();
26750 + mmu_cr4_features |= mask;
26751 + pax_close_kernel();
26752 +
26753 + if (trampoline_cr4_features)
26754 + *trampoline_cr4_features = mmu_cr4_features;
26755 + cr4 |= mask;
26756 + write_cr4(cr4);
26757 +}
26758 +EXPORT_SYMBOL(set_in_cr4);
26759 +
26760 +void clear_in_cr4(unsigned long mask)
26761 +{
26762 + unsigned long cr4 = read_cr4();
26763 +
26764 + if (!(cr4 & mask) && cr4 == mmu_cr4_features)
26765 + return;
26766 +
26767 + pax_open_kernel();
26768 + mmu_cr4_features &= ~mask;
26769 + pax_close_kernel();
26770 +
26771 + if (trampoline_cr4_features)
26772 + *trampoline_cr4_features = mmu_cr4_features;
26773 + cr4 &= ~mask;
26774 + write_cr4(cr4);
26775 +}
26776 +EXPORT_SYMBOL(clear_in_cr4);
26777 +
26778 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
26779 int bootloader_type, bootloader_version;
26780
26781 @@ -772,7 +811,7 @@ static void __init trim_bios_range(void)
26782 * area (640->1Mb) as ram even though it is not.
26783 * take them out.
26784 */
26785 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
26786 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
26787
26788 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
26789 }
26790 @@ -780,7 +819,7 @@ static void __init trim_bios_range(void)
26791 /* called before trim_bios_range() to spare extra sanitize */
26792 static void __init e820_add_kernel_range(void)
26793 {
26794 - u64 start = __pa_symbol(_text);
26795 + u64 start = __pa_symbol(ktla_ktva(_text));
26796 u64 size = __pa_symbol(_end) - start;
26797
26798 /*
26799 @@ -856,8 +895,12 @@ dump_kernel_offset(struct notifier_block *self, unsigned long v, void *p)
26800
26801 void __init setup_arch(char **cmdline_p)
26802 {
26803 +#ifdef CONFIG_X86_32
26804 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
26805 +#else
26806 memblock_reserve(__pa_symbol(_text),
26807 (unsigned long)__bss_stop - (unsigned long)_text);
26808 +#endif
26809
26810 early_reserve_initrd();
26811
26812 @@ -946,14 +989,14 @@ void __init setup_arch(char **cmdline_p)
26813
26814 if (!boot_params.hdr.root_flags)
26815 root_mountflags &= ~MS_RDONLY;
26816 - init_mm.start_code = (unsigned long) _text;
26817 - init_mm.end_code = (unsigned long) _etext;
26818 + init_mm.start_code = ktla_ktva((unsigned long) _text);
26819 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
26820 init_mm.end_data = (unsigned long) _edata;
26821 init_mm.brk = _brk_end;
26822
26823 - code_resource.start = __pa_symbol(_text);
26824 - code_resource.end = __pa_symbol(_etext)-1;
26825 - data_resource.start = __pa_symbol(_etext);
26826 + code_resource.start = __pa_symbol(ktla_ktva(_text));
26827 + code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
26828 + data_resource.start = __pa_symbol(_sdata);
26829 data_resource.end = __pa_symbol(_edata)-1;
26830 bss_resource.start = __pa_symbol(__bss_start);
26831 bss_resource.end = __pa_symbol(__bss_stop)-1;
26832 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
26833 index 5cdff03..80fa283 100644
26834 --- a/arch/x86/kernel/setup_percpu.c
26835 +++ b/arch/x86/kernel/setup_percpu.c
26836 @@ -21,19 +21,17 @@
26837 #include <asm/cpu.h>
26838 #include <asm/stackprotector.h>
26839
26840 -DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
26841 +#ifdef CONFIG_SMP
26842 +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
26843 EXPORT_PER_CPU_SYMBOL(cpu_number);
26844 +#endif
26845
26846 -#ifdef CONFIG_X86_64
26847 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
26848 -#else
26849 -#define BOOT_PERCPU_OFFSET 0
26850 -#endif
26851
26852 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
26853 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
26854
26855 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
26856 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
26857 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
26858 };
26859 EXPORT_SYMBOL(__per_cpu_offset);
26860 @@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
26861 {
26862 #ifdef CONFIG_NEED_MULTIPLE_NODES
26863 pg_data_t *last = NULL;
26864 - unsigned int cpu;
26865 + int cpu;
26866
26867 for_each_possible_cpu(cpu) {
26868 int node = early_cpu_to_node(cpu);
26869 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
26870 {
26871 #ifdef CONFIG_X86_32
26872 struct desc_struct gdt;
26873 + unsigned long base = per_cpu_offset(cpu);
26874
26875 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
26876 - 0x2 | DESCTYPE_S, 0x8);
26877 - gdt.s = 1;
26878 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
26879 + 0x83 | DESCTYPE_S, 0xC);
26880 write_gdt_entry(get_cpu_gdt_table(cpu),
26881 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
26882 #endif
26883 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
26884 /* alrighty, percpu areas up and running */
26885 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
26886 for_each_possible_cpu(cpu) {
26887 +#ifdef CONFIG_CC_STACKPROTECTOR
26888 +#ifdef CONFIG_X86_32
26889 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
26890 +#endif
26891 +#endif
26892 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
26893 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
26894 per_cpu(cpu_number, cpu) = cpu;
26895 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
26896 */
26897 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
26898 #endif
26899 +#ifdef CONFIG_CC_STACKPROTECTOR
26900 +#ifdef CONFIG_X86_32
26901 + if (!cpu)
26902 + per_cpu(stack_canary.canary, cpu) = canary;
26903 +#endif
26904 +#endif
26905 /*
26906 * Up to this point, the boot CPU has been using .init.data
26907 * area. Reload any changed state for the boot CPU.
26908 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
26909 index 9e5de68..16c53cb 100644
26910 --- a/arch/x86/kernel/signal.c
26911 +++ b/arch/x86/kernel/signal.c
26912 @@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
26913 * Align the stack pointer according to the i386 ABI,
26914 * i.e. so that on function entry ((sp + 4) & 15) == 0.
26915 */
26916 - sp = ((sp + 4) & -16ul) - 4;
26917 + sp = ((sp - 12) & -16ul) - 4;
26918 #else /* !CONFIG_X86_32 */
26919 sp = round_down(sp, 16) - 8;
26920 #endif
26921 @@ -298,9 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
26922 }
26923
26924 if (current->mm->context.vdso)
26925 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
26926 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
26927 else
26928 - restorer = &frame->retcode;
26929 + restorer = (void __user *)&frame->retcode;
26930 if (ksig->ka.sa.sa_flags & SA_RESTORER)
26931 restorer = ksig->ka.sa.sa_restorer;
26932
26933 @@ -314,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
26934 * reasons and because gdb uses it as a signature to notice
26935 * signal handler stack frames.
26936 */
26937 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
26938 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
26939
26940 if (err)
26941 return -EFAULT;
26942 @@ -361,7 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
26943 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
26944
26945 /* Set up to return from userspace. */
26946 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
26947 + if (current->mm->context.vdso)
26948 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
26949 + else
26950 + restorer = (void __user *)&frame->retcode;
26951 if (ksig->ka.sa.sa_flags & SA_RESTORER)
26952 restorer = ksig->ka.sa.sa_restorer;
26953 put_user_ex(restorer, &frame->pretcode);
26954 @@ -373,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
26955 * reasons and because gdb uses it as a signature to notice
26956 * signal handler stack frames.
26957 */
26958 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
26959 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
26960 } put_user_catch(err);
26961
26962 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
26963 @@ -609,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
26964 {
26965 int usig = signr_convert(ksig->sig);
26966 sigset_t *set = sigmask_to_save();
26967 - compat_sigset_t *cset = (compat_sigset_t *) set;
26968 + sigset_t sigcopy;
26969 + compat_sigset_t *cset;
26970 +
26971 + sigcopy = *set;
26972 +
26973 + cset = (compat_sigset_t *) &sigcopy;
26974
26975 /* Set up the stack frame */
26976 if (is_ia32_frame()) {
26977 @@ -620,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
26978 } else if (is_x32_frame()) {
26979 return x32_setup_rt_frame(ksig, cset, regs);
26980 } else {
26981 - return __setup_rt_frame(ksig->sig, ksig, set, regs);
26982 + return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
26983 }
26984 }
26985
26986 diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
26987 index be8e1bd..a3d93fa 100644
26988 --- a/arch/x86/kernel/smp.c
26989 +++ b/arch/x86/kernel/smp.c
26990 @@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
26991
26992 __setup("nonmi_ipi", nonmi_ipi_setup);
26993
26994 -struct smp_ops smp_ops = {
26995 +struct smp_ops smp_ops __read_only = {
26996 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
26997 .smp_prepare_cpus = native_smp_prepare_cpus,
26998 .smp_cpus_done = native_smp_cpus_done,
26999 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
27000 index ae2fd975..c0c8d10 100644
27001 --- a/arch/x86/kernel/smpboot.c
27002 +++ b/arch/x86/kernel/smpboot.c
27003 @@ -230,14 +230,17 @@ static void notrace start_secondary(void *unused)
27004
27005 enable_start_cpu0 = 0;
27006
27007 -#ifdef CONFIG_X86_32
27008 + /* otherwise gcc will move up smp_processor_id before the cpu_init */
27009 + barrier();
27010 +
27011 /* switch away from the initial page table */
27012 +#ifdef CONFIG_PAX_PER_CPU_PGD
27013 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
27014 +#else
27015 load_cr3(swapper_pg_dir);
27016 +#endif
27017 __flush_tlb_all();
27018 -#endif
27019
27020 - /* otherwise gcc will move up smp_processor_id before the cpu_init */
27021 - barrier();
27022 /*
27023 * Check TSC synchronization with the BP:
27024 */
27025 @@ -757,8 +760,9 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
27026 alternatives_enable_smp();
27027
27028 idle->thread.sp = (unsigned long) (((struct pt_regs *)
27029 - (THREAD_SIZE + task_stack_page(idle))) - 1);
27030 + (THREAD_SIZE - 16 + task_stack_page(idle))) - 1);
27031 per_cpu(current_task, cpu) = idle;
27032 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
27033
27034 #ifdef CONFIG_X86_32
27035 /* Stack for startup_32 can be just as for start_secondary onwards */
27036 @@ -767,10 +771,10 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
27037 clear_tsk_thread_flag(idle, TIF_FORK);
27038 initial_gs = per_cpu_offset(cpu);
27039 #endif
27040 - per_cpu(kernel_stack, cpu) =
27041 - (unsigned long)task_stack_page(idle) -
27042 - KERNEL_STACK_OFFSET + THREAD_SIZE;
27043 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27044 + pax_open_kernel();
27045 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
27046 + pax_close_kernel();
27047 initial_code = (unsigned long)start_secondary;
27048 stack_start = idle->thread.sp;
27049
27050 @@ -916,6 +920,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
27051 /* the FPU context is blank, nobody can own it */
27052 __cpu_disable_lazy_restore(cpu);
27053
27054 +#ifdef CONFIG_PAX_PER_CPU_PGD
27055 + clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
27056 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27057 + KERNEL_PGD_PTRS);
27058 + clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
27059 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
27060 + KERNEL_PGD_PTRS);
27061 +#endif
27062 +
27063 err = do_boot_cpu(apicid, cpu, tidle);
27064 if (err) {
27065 pr_err("do_boot_cpu failed(%d) to wakeup CPU#%u\n", err, cpu);
27066 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
27067 index 9b4d51d..5d28b58 100644
27068 --- a/arch/x86/kernel/step.c
27069 +++ b/arch/x86/kernel/step.c
27070 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
27071 struct desc_struct *desc;
27072 unsigned long base;
27073
27074 - seg &= ~7UL;
27075 + seg >>= 3;
27076
27077 mutex_lock(&child->mm->context.lock);
27078 - if (unlikely((seg >> 3) >= child->mm->context.size))
27079 + if (unlikely(seg >= child->mm->context.size))
27080 addr = -1L; /* bogus selector, access would fault */
27081 else {
27082 desc = child->mm->context.ldt + seg;
27083 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
27084 addr += base;
27085 }
27086 mutex_unlock(&child->mm->context.lock);
27087 - }
27088 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
27089 + addr = ktla_ktva(addr);
27090
27091 return addr;
27092 }
27093 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
27094 unsigned char opcode[15];
27095 unsigned long addr = convert_ip_to_linear(child, regs);
27096
27097 + if (addr == -EINVAL)
27098 + return 0;
27099 +
27100 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
27101 for (i = 0; i < copied; i++) {
27102 switch (opcode[i]) {
27103 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
27104 new file mode 100644
27105 index 0000000..5877189
27106 --- /dev/null
27107 +++ b/arch/x86/kernel/sys_i386_32.c
27108 @@ -0,0 +1,189 @@
27109 +/*
27110 + * This file contains various random system calls that
27111 + * have a non-standard calling sequence on the Linux/i386
27112 + * platform.
27113 + */
27114 +
27115 +#include <linux/errno.h>
27116 +#include <linux/sched.h>
27117 +#include <linux/mm.h>
27118 +#include <linux/fs.h>
27119 +#include <linux/smp.h>
27120 +#include <linux/sem.h>
27121 +#include <linux/msg.h>
27122 +#include <linux/shm.h>
27123 +#include <linux/stat.h>
27124 +#include <linux/syscalls.h>
27125 +#include <linux/mman.h>
27126 +#include <linux/file.h>
27127 +#include <linux/utsname.h>
27128 +#include <linux/ipc.h>
27129 +#include <linux/elf.h>
27130 +
27131 +#include <linux/uaccess.h>
27132 +#include <linux/unistd.h>
27133 +
27134 +#include <asm/syscalls.h>
27135 +
27136 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
27137 +{
27138 + unsigned long pax_task_size = TASK_SIZE;
27139 +
27140 +#ifdef CONFIG_PAX_SEGMEXEC
27141 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
27142 + pax_task_size = SEGMEXEC_TASK_SIZE;
27143 +#endif
27144 +
27145 + if (flags & MAP_FIXED)
27146 + if (len > pax_task_size || addr > pax_task_size - len)
27147 + return -EINVAL;
27148 +
27149 + return 0;
27150 +}
27151 +
27152 +/*
27153 + * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
27154 + */
27155 +static unsigned long get_align_mask(void)
27156 +{
27157 + if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
27158 + return 0;
27159 +
27160 + if (!(current->flags & PF_RANDOMIZE))
27161 + return 0;
27162 +
27163 + return va_align.mask;
27164 +}
27165 +
27166 +unsigned long
27167 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
27168 + unsigned long len, unsigned long pgoff, unsigned long flags)
27169 +{
27170 + struct mm_struct *mm = current->mm;
27171 + struct vm_area_struct *vma;
27172 + unsigned long pax_task_size = TASK_SIZE;
27173 + struct vm_unmapped_area_info info;
27174 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27175 +
27176 +#ifdef CONFIG_PAX_SEGMEXEC
27177 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
27178 + pax_task_size = SEGMEXEC_TASK_SIZE;
27179 +#endif
27180 +
27181 + pax_task_size -= PAGE_SIZE;
27182 +
27183 + if (len > pax_task_size)
27184 + return -ENOMEM;
27185 +
27186 + if (flags & MAP_FIXED)
27187 + return addr;
27188 +
27189 +#ifdef CONFIG_PAX_RANDMMAP
27190 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27191 +#endif
27192 +
27193 + if (addr) {
27194 + addr = PAGE_ALIGN(addr);
27195 + if (pax_task_size - len >= addr) {
27196 + vma = find_vma(mm, addr);
27197 + if (check_heap_stack_gap(vma, addr, len, offset))
27198 + return addr;
27199 + }
27200 + }
27201 +
27202 + info.flags = 0;
27203 + info.length = len;
27204 + info.align_mask = filp ? get_align_mask() : 0;
27205 + info.align_offset = pgoff << PAGE_SHIFT;
27206 + info.threadstack_offset = offset;
27207 +
27208 +#ifdef CONFIG_PAX_PAGEEXEC
27209 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
27210 + info.low_limit = 0x00110000UL;
27211 + info.high_limit = mm->start_code;
27212 +
27213 +#ifdef CONFIG_PAX_RANDMMAP
27214 + if (mm->pax_flags & MF_PAX_RANDMMAP)
27215 + info.low_limit += mm->delta_mmap & 0x03FFF000UL;
27216 +#endif
27217 +
27218 + if (info.low_limit < info.high_limit) {
27219 + addr = vm_unmapped_area(&info);
27220 + if (!IS_ERR_VALUE(addr))
27221 + return addr;
27222 + }
27223 + } else
27224 +#endif
27225 +
27226 + info.low_limit = mm->mmap_base;
27227 + info.high_limit = pax_task_size;
27228 +
27229 + return vm_unmapped_area(&info);
27230 +}
27231 +
27232 +unsigned long
27233 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27234 + const unsigned long len, const unsigned long pgoff,
27235 + const unsigned long flags)
27236 +{
27237 + struct vm_area_struct *vma;
27238 + struct mm_struct *mm = current->mm;
27239 + unsigned long addr = addr0, pax_task_size = TASK_SIZE;
27240 + struct vm_unmapped_area_info info;
27241 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27242 +
27243 +#ifdef CONFIG_PAX_SEGMEXEC
27244 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
27245 + pax_task_size = SEGMEXEC_TASK_SIZE;
27246 +#endif
27247 +
27248 + pax_task_size -= PAGE_SIZE;
27249 +
27250 + /* requested length too big for entire address space */
27251 + if (len > pax_task_size)
27252 + return -ENOMEM;
27253 +
27254 + if (flags & MAP_FIXED)
27255 + return addr;
27256 +
27257 +#ifdef CONFIG_PAX_PAGEEXEC
27258 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
27259 + goto bottomup;
27260 +#endif
27261 +
27262 +#ifdef CONFIG_PAX_RANDMMAP
27263 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27264 +#endif
27265 +
27266 + /* requesting a specific address */
27267 + if (addr) {
27268 + addr = PAGE_ALIGN(addr);
27269 + if (pax_task_size - len >= addr) {
27270 + vma = find_vma(mm, addr);
27271 + if (check_heap_stack_gap(vma, addr, len, offset))
27272 + return addr;
27273 + }
27274 + }
27275 +
27276 + info.flags = VM_UNMAPPED_AREA_TOPDOWN;
27277 + info.length = len;
27278 + info.low_limit = PAGE_SIZE;
27279 + info.high_limit = mm->mmap_base;
27280 + info.align_mask = filp ? get_align_mask() : 0;
27281 + info.align_offset = pgoff << PAGE_SHIFT;
27282 + info.threadstack_offset = offset;
27283 +
27284 + addr = vm_unmapped_area(&info);
27285 + if (!(addr & ~PAGE_MASK))
27286 + return addr;
27287 + VM_BUG_ON(addr != -ENOMEM);
27288 +
27289 +bottomup:
27290 + /*
27291 + * A failed mmap() very likely causes application failure,
27292 + * so fall back to the bottom-up function here. This scenario
27293 + * can happen with large stack limits and large mmap()
27294 + * allocations.
27295 + */
27296 + return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
27297 +}
27298 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
27299 index 30277e2..5664a29 100644
27300 --- a/arch/x86/kernel/sys_x86_64.c
27301 +++ b/arch/x86/kernel/sys_x86_64.c
27302 @@ -81,8 +81,8 @@ out:
27303 return error;
27304 }
27305
27306 -static void find_start_end(unsigned long flags, unsigned long *begin,
27307 - unsigned long *end)
27308 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
27309 + unsigned long *begin, unsigned long *end)
27310 {
27311 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
27312 unsigned long new_begin;
27313 @@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
27314 *begin = new_begin;
27315 }
27316 } else {
27317 - *begin = current->mm->mmap_legacy_base;
27318 + *begin = mm->mmap_legacy_base;
27319 *end = TASK_SIZE;
27320 }
27321 }
27322 @@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27323 struct vm_area_struct *vma;
27324 struct vm_unmapped_area_info info;
27325 unsigned long begin, end;
27326 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27327
27328 if (flags & MAP_FIXED)
27329 return addr;
27330
27331 - find_start_end(flags, &begin, &end);
27332 + find_start_end(mm, flags, &begin, &end);
27333
27334 if (len > end)
27335 return -ENOMEM;
27336
27337 +#ifdef CONFIG_PAX_RANDMMAP
27338 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27339 +#endif
27340 +
27341 if (addr) {
27342 addr = PAGE_ALIGN(addr);
27343 vma = find_vma(mm, addr);
27344 - if (end - len >= addr &&
27345 - (!vma || addr + len <= vma->vm_start))
27346 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27347 return addr;
27348 }
27349
27350 @@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
27351 info.high_limit = end;
27352 info.align_mask = filp ? get_align_mask() : 0;
27353 info.align_offset = pgoff << PAGE_SHIFT;
27354 + info.threadstack_offset = offset;
27355 return vm_unmapped_area(&info);
27356 }
27357
27358 @@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27359 struct mm_struct *mm = current->mm;
27360 unsigned long addr = addr0;
27361 struct vm_unmapped_area_info info;
27362 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
27363
27364 /* requested length too big for entire address space */
27365 if (len > TASK_SIZE)
27366 @@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27367 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
27368 goto bottomup;
27369
27370 +#ifdef CONFIG_PAX_RANDMMAP
27371 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27372 +#endif
27373 +
27374 /* requesting a specific address */
27375 if (addr) {
27376 addr = PAGE_ALIGN(addr);
27377 vma = find_vma(mm, addr);
27378 - if (TASK_SIZE - len >= addr &&
27379 - (!vma || addr + len <= vma->vm_start))
27380 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
27381 return addr;
27382 }
27383
27384 @@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
27385 info.high_limit = mm->mmap_base;
27386 info.align_mask = filp ? get_align_mask() : 0;
27387 info.align_offset = pgoff << PAGE_SHIFT;
27388 + info.threadstack_offset = offset;
27389 addr = vm_unmapped_area(&info);
27390 if (!(addr & ~PAGE_MASK))
27391 return addr;
27392 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
27393 index 91a4496..bb87552 100644
27394 --- a/arch/x86/kernel/tboot.c
27395 +++ b/arch/x86/kernel/tboot.c
27396 @@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
27397
27398 void tboot_shutdown(u32 shutdown_type)
27399 {
27400 - void (*shutdown)(void);
27401 + void (* __noreturn shutdown)(void);
27402
27403 if (!tboot_enabled())
27404 return;
27405 @@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
27406
27407 switch_to_tboot_pt();
27408
27409 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
27410 + shutdown = (void *)(unsigned long)tboot->shutdown_entry;
27411 shutdown();
27412
27413 /* should not reach here */
27414 @@ -310,7 +310,7 @@ static int tboot_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b)
27415 return -ENODEV;
27416 }
27417
27418 -static atomic_t ap_wfs_count;
27419 +static atomic_unchecked_t ap_wfs_count;
27420
27421 static int tboot_wait_for_aps(int num_aps)
27422 {
27423 @@ -334,9 +334,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
27424 {
27425 switch (action) {
27426 case CPU_DYING:
27427 - atomic_inc(&ap_wfs_count);
27428 + atomic_inc_unchecked(&ap_wfs_count);
27429 if (num_online_cpus() == 1)
27430 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
27431 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
27432 return NOTIFY_BAD;
27433 break;
27434 }
27435 @@ -422,7 +422,7 @@ static __init int tboot_late_init(void)
27436
27437 tboot_create_trampoline();
27438
27439 - atomic_set(&ap_wfs_count, 0);
27440 + atomic_set_unchecked(&ap_wfs_count, 0);
27441 register_hotcpu_notifier(&tboot_cpu_notifier);
27442
27443 #ifdef CONFIG_DEBUG_FS
27444 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
27445 index bf7ef5c..59d0ac9 100644
27446 --- a/arch/x86/kernel/time.c
27447 +++ b/arch/x86/kernel/time.c
27448 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
27449 {
27450 unsigned long pc = instruction_pointer(regs);
27451
27452 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
27453 + if (!user_mode(regs) && in_lock_functions(pc)) {
27454 #ifdef CONFIG_FRAME_POINTER
27455 - return *(unsigned long *)(regs->bp + sizeof(long));
27456 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
27457 #else
27458 unsigned long *sp =
27459 (unsigned long *)kernel_stack_pointer(regs);
27460 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
27461 * or above a saved flags. Eflags has bits 22-31 zero,
27462 * kernel addresses don't.
27463 */
27464 +
27465 +#ifdef CONFIG_PAX_KERNEXEC
27466 + return ktla_ktva(sp[0]);
27467 +#else
27468 if (sp[0] >> 22)
27469 return sp[0];
27470 if (sp[1] >> 22)
27471 return sp[1];
27472 #endif
27473 +
27474 +#endif
27475 }
27476 return pc;
27477 }
27478 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
27479 index f7fec09..9991981 100644
27480 --- a/arch/x86/kernel/tls.c
27481 +++ b/arch/x86/kernel/tls.c
27482 @@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
27483 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
27484 return -EINVAL;
27485
27486 +#ifdef CONFIG_PAX_SEGMEXEC
27487 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
27488 + return -EINVAL;
27489 +#endif
27490 +
27491 set_tls_desc(p, idx, &info, 1);
27492
27493 return 0;
27494 @@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
27495
27496 if (kbuf)
27497 info = kbuf;
27498 - else if (__copy_from_user(infobuf, ubuf, count))
27499 + else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
27500 return -EFAULT;
27501 else
27502 info = infobuf;
27503 diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
27504 index 1c113db..287b42e 100644
27505 --- a/arch/x86/kernel/tracepoint.c
27506 +++ b/arch/x86/kernel/tracepoint.c
27507 @@ -9,11 +9,11 @@
27508 #include <linux/atomic.h>
27509
27510 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
27511 -struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27512 +const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
27513 (unsigned long) trace_idt_table };
27514
27515 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27516 -gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
27517 +gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
27518
27519 static int trace_irq_vector_refcount;
27520 static DEFINE_MUTEX(irq_vector_mutex);
27521 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
27522 index f73b5d4..0adcc9a 100644
27523 --- a/arch/x86/kernel/traps.c
27524 +++ b/arch/x86/kernel/traps.c
27525 @@ -66,7 +66,7 @@
27526 #include <asm/proto.h>
27527
27528 /* No need to be aligned, but done to keep all IDTs defined the same way. */
27529 -gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
27530 +gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
27531 #else
27532 #include <asm/processor-flags.h>
27533 #include <asm/setup.h>
27534 @@ -75,7 +75,7 @@ asmlinkage int system_call(void);
27535 #endif
27536
27537 /* Must be page-aligned because the real IDT is used in a fixmap. */
27538 -gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
27539 +gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
27540
27541 DECLARE_BITMAP(used_vectors, NR_VECTORS);
27542 EXPORT_SYMBOL_GPL(used_vectors);
27543 @@ -107,11 +107,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
27544 }
27545
27546 static int __kprobes
27547 -do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27548 +do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
27549 struct pt_regs *regs, long error_code)
27550 {
27551 #ifdef CONFIG_X86_32
27552 - if (regs->flags & X86_VM_MASK) {
27553 + if (v8086_mode(regs)) {
27554 /*
27555 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
27556 * On nmi (interrupt 2), do_trap should not be called.
27557 @@ -124,12 +124,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27558 return -1;
27559 }
27560 #endif
27561 - if (!user_mode(regs)) {
27562 + if (!user_mode_novm(regs)) {
27563 if (!fixup_exception(regs)) {
27564 tsk->thread.error_code = error_code;
27565 tsk->thread.trap_nr = trapnr;
27566 +
27567 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27568 + if (trapnr == X86_TRAP_SS && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
27569 + str = "PAX: suspicious stack segment fault";
27570 +#endif
27571 +
27572 die(str, regs, error_code);
27573 }
27574 +
27575 +#ifdef CONFIG_PAX_REFCOUNT
27576 + if (trapnr == X86_TRAP_OF)
27577 + pax_report_refcount_overflow(regs);
27578 +#endif
27579 +
27580 return 0;
27581 }
27582
27583 @@ -137,7 +149,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
27584 }
27585
27586 static void __kprobes
27587 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27588 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
27589 long error_code, siginfo_t *info)
27590 {
27591 struct task_struct *tsk = current;
27592 @@ -161,7 +173,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
27593 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
27594 printk_ratelimit()) {
27595 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
27596 - tsk->comm, tsk->pid, str,
27597 + tsk->comm, task_pid_nr(tsk), str,
27598 regs->ip, regs->sp, error_code);
27599 print_vma_addr(" in ", regs->ip);
27600 pr_cont("\n");
27601 @@ -251,6 +263,11 @@ dotraplinkage void do_double_fault(struct pt_regs *regs, long error_code)
27602 tsk->thread.error_code = error_code;
27603 tsk->thread.trap_nr = X86_TRAP_DF;
27604
27605 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
27606 + if ((unsigned long)tsk->stack - regs->sp <= PAGE_SIZE)
27607 + die("grsec: kernel stack overflow detected", regs, error_code);
27608 +#endif
27609 +
27610 #ifdef CONFIG_DOUBLEFAULT
27611 df_debug(regs, error_code);
27612 #endif
27613 @@ -273,7 +290,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
27614 conditional_sti(regs);
27615
27616 #ifdef CONFIG_X86_32
27617 - if (regs->flags & X86_VM_MASK) {
27618 + if (v8086_mode(regs)) {
27619 local_irq_enable();
27620 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
27621 goto exit;
27622 @@ -281,18 +298,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
27623 #endif
27624
27625 tsk = current;
27626 - if (!user_mode(regs)) {
27627 + if (!user_mode_novm(regs)) {
27628 if (fixup_exception(regs))
27629 goto exit;
27630
27631 tsk->thread.error_code = error_code;
27632 tsk->thread.trap_nr = X86_TRAP_GP;
27633 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
27634 - X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
27635 + X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
27636 +
27637 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27638 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
27639 + die("PAX: suspicious general protection fault", regs, error_code);
27640 + else
27641 +#endif
27642 +
27643 die("general protection fault", regs, error_code);
27644 + }
27645 goto exit;
27646 }
27647
27648 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
27649 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
27650 + struct mm_struct *mm = tsk->mm;
27651 + unsigned long limit;
27652 +
27653 + down_write(&mm->mmap_sem);
27654 + limit = mm->context.user_cs_limit;
27655 + if (limit < TASK_SIZE) {
27656 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
27657 + up_write(&mm->mmap_sem);
27658 + return;
27659 + }
27660 + up_write(&mm->mmap_sem);
27661 + }
27662 +#endif
27663 +
27664 tsk->thread.error_code = error_code;
27665 tsk->thread.trap_nr = X86_TRAP_GP;
27666
27667 @@ -453,7 +494,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
27668 /* It's safe to allow irq's after DR6 has been saved */
27669 preempt_conditional_sti(regs);
27670
27671 - if (regs->flags & X86_VM_MASK) {
27672 + if (v8086_mode(regs)) {
27673 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
27674 X86_TRAP_DB);
27675 preempt_conditional_cli(regs);
27676 @@ -468,7 +509,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
27677 * We already checked v86 mode above, so we can check for kernel mode
27678 * by just checking the CPL of CS.
27679 */
27680 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
27681 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
27682 tsk->thread.debugreg6 &= ~DR_STEP;
27683 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
27684 regs->flags &= ~X86_EFLAGS_TF;
27685 @@ -500,7 +541,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
27686 return;
27687 conditional_sti(regs);
27688
27689 - if (!user_mode_vm(regs))
27690 + if (!user_mode(regs))
27691 {
27692 if (!fixup_exception(regs)) {
27693 task->thread.error_code = error_code;
27694 diff --git a/arch/x86/kernel/tsc.c b/arch/x86/kernel/tsc.c
27695 index 57e5ce1..20b0040 100644
27696 --- a/arch/x86/kernel/tsc.c
27697 +++ b/arch/x86/kernel/tsc.c
27698 @@ -150,7 +150,7 @@ static void cyc2ns_write_end(int cpu, struct cyc2ns_data *data)
27699 */
27700 smp_wmb();
27701
27702 - ACCESS_ONCE(c2n->head) = data;
27703 + ACCESS_ONCE_RW(c2n->head) = data;
27704 }
27705
27706 /*
27707 diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
27708 index 2ed8459..7cf329f 100644
27709 --- a/arch/x86/kernel/uprobes.c
27710 +++ b/arch/x86/kernel/uprobes.c
27711 @@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
27712 int ret = NOTIFY_DONE;
27713
27714 /* We are only interested in userspace traps */
27715 - if (regs && !user_mode_vm(regs))
27716 + if (regs && !user_mode(regs))
27717 return NOTIFY_DONE;
27718
27719 switch (val) {
27720 @@ -719,7 +719,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
27721
27722 if (ncopied != rasize) {
27723 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
27724 - "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
27725 + "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
27726
27727 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
27728 }
27729 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
27730 index b9242ba..50c5edd 100644
27731 --- a/arch/x86/kernel/verify_cpu.S
27732 +++ b/arch/x86/kernel/verify_cpu.S
27733 @@ -20,6 +20,7 @@
27734 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
27735 * arch/x86/kernel/trampoline_64.S: secondary processor verification
27736 * arch/x86/kernel/head_32.S: processor startup
27737 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
27738 *
27739 * verify_cpu, returns the status of longmode and SSE in register %eax.
27740 * 0: Success 1: Failure
27741 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
27742 index e8edcf5..27f9344 100644
27743 --- a/arch/x86/kernel/vm86_32.c
27744 +++ b/arch/x86/kernel/vm86_32.c
27745 @@ -44,6 +44,7 @@
27746 #include <linux/ptrace.h>
27747 #include <linux/audit.h>
27748 #include <linux/stddef.h>
27749 +#include <linux/grsecurity.h>
27750
27751 #include <asm/uaccess.h>
27752 #include <asm/io.h>
27753 @@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
27754 do_exit(SIGSEGV);
27755 }
27756
27757 - tss = &per_cpu(init_tss, get_cpu());
27758 + tss = init_tss + get_cpu();
27759 current->thread.sp0 = current->thread.saved_sp0;
27760 current->thread.sysenter_cs = __KERNEL_CS;
27761 load_sp0(tss, &current->thread);
27762 @@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
27763
27764 if (tsk->thread.saved_sp0)
27765 return -EPERM;
27766 +
27767 +#ifdef CONFIG_GRKERNSEC_VM86
27768 + if (!capable(CAP_SYS_RAWIO)) {
27769 + gr_handle_vm86();
27770 + return -EPERM;
27771 + }
27772 +#endif
27773 +
27774 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
27775 offsetof(struct kernel_vm86_struct, vm86plus) -
27776 sizeof(info.regs));
27777 @@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
27778 int tmp;
27779 struct vm86plus_struct __user *v86;
27780
27781 +#ifdef CONFIG_GRKERNSEC_VM86
27782 + if (!capable(CAP_SYS_RAWIO)) {
27783 + gr_handle_vm86();
27784 + return -EPERM;
27785 + }
27786 +#endif
27787 +
27788 tsk = current;
27789 switch (cmd) {
27790 case VM86_REQUEST_IRQ:
27791 @@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
27792 tsk->thread.saved_fs = info->regs32->fs;
27793 tsk->thread.saved_gs = get_user_gs(info->regs32);
27794
27795 - tss = &per_cpu(init_tss, get_cpu());
27796 + tss = init_tss + get_cpu();
27797 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
27798 if (cpu_has_sep)
27799 tsk->thread.sysenter_cs = 0;
27800 @@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
27801 goto cannot_handle;
27802 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
27803 goto cannot_handle;
27804 - intr_ptr = (unsigned long __user *) (i << 2);
27805 + intr_ptr = (__force unsigned long __user *) (i << 2);
27806 if (get_user(segoffs, intr_ptr))
27807 goto cannot_handle;
27808 if ((segoffs >> 16) == BIOSSEG)
27809 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
27810 index 49edf2d..c0d1362 100644
27811 --- a/arch/x86/kernel/vmlinux.lds.S
27812 +++ b/arch/x86/kernel/vmlinux.lds.S
27813 @@ -26,6 +26,13 @@
27814 #include <asm/page_types.h>
27815 #include <asm/cache.h>
27816 #include <asm/boot.h>
27817 +#include <asm/segment.h>
27818 +
27819 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27820 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
27821 +#else
27822 +#define __KERNEL_TEXT_OFFSET 0
27823 +#endif
27824
27825 #undef i386 /* in case the preprocessor is a 32bit one */
27826
27827 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
27828
27829 PHDRS {
27830 text PT_LOAD FLAGS(5); /* R_E */
27831 +#ifdef CONFIG_X86_32
27832 + module PT_LOAD FLAGS(5); /* R_E */
27833 +#endif
27834 +#ifdef CONFIG_XEN
27835 + rodata PT_LOAD FLAGS(5); /* R_E */
27836 +#else
27837 + rodata PT_LOAD FLAGS(4); /* R__ */
27838 +#endif
27839 data PT_LOAD FLAGS(6); /* RW_ */
27840 -#ifdef CONFIG_X86_64
27841 + init.begin PT_LOAD FLAGS(6); /* RW_ */
27842 #ifdef CONFIG_SMP
27843 percpu PT_LOAD FLAGS(6); /* RW_ */
27844 #endif
27845 + text.init PT_LOAD FLAGS(5); /* R_E */
27846 + text.exit PT_LOAD FLAGS(5); /* R_E */
27847 init PT_LOAD FLAGS(7); /* RWE */
27848 -#endif
27849 note PT_NOTE FLAGS(0); /* ___ */
27850 }
27851
27852 SECTIONS
27853 {
27854 #ifdef CONFIG_X86_32
27855 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
27856 - phys_startup_32 = startup_32 - LOAD_OFFSET;
27857 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
27858 #else
27859 - . = __START_KERNEL;
27860 - phys_startup_64 = startup_64 - LOAD_OFFSET;
27861 + . = __START_KERNEL;
27862 #endif
27863
27864 /* Text and read-only data */
27865 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
27866 - _text = .;
27867 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
27868 /* bootstrapping code */
27869 +#ifdef CONFIG_X86_32
27870 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27871 +#else
27872 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27873 +#endif
27874 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27875 + _text = .;
27876 HEAD_TEXT
27877 . = ALIGN(8);
27878 _stext = .;
27879 @@ -104,13 +124,47 @@ SECTIONS
27880 IRQENTRY_TEXT
27881 *(.fixup)
27882 *(.gnu.warning)
27883 - /* End of text section */
27884 - _etext = .;
27885 } :text = 0x9090
27886
27887 - NOTES :text :note
27888 + . += __KERNEL_TEXT_OFFSET;
27889
27890 - EXCEPTION_TABLE(16) :text = 0x9090
27891 +#ifdef CONFIG_X86_32
27892 + . = ALIGN(PAGE_SIZE);
27893 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
27894 +
27895 +#ifdef CONFIG_PAX_KERNEXEC
27896 + MODULES_EXEC_VADDR = .;
27897 + BYTE(0)
27898 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
27899 + . = ALIGN(HPAGE_SIZE) - 1;
27900 + MODULES_EXEC_END = .;
27901 +#endif
27902 +
27903 + } :module
27904 +#endif
27905 +
27906 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
27907 + /* End of text section */
27908 + BYTE(0)
27909 + _etext = . - __KERNEL_TEXT_OFFSET;
27910 + }
27911 +
27912 +#ifdef CONFIG_X86_32
27913 + . = ALIGN(PAGE_SIZE);
27914 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
27915 + . = ALIGN(PAGE_SIZE);
27916 + *(.empty_zero_page)
27917 + *(.initial_pg_fixmap)
27918 + *(.initial_pg_pmd)
27919 + *(.initial_page_table)
27920 + *(.swapper_pg_dir)
27921 + } :rodata
27922 +#endif
27923 +
27924 + . = ALIGN(PAGE_SIZE);
27925 + NOTES :rodata :note
27926 +
27927 + EXCEPTION_TABLE(16) :rodata
27928
27929 #if defined(CONFIG_DEBUG_RODATA)
27930 /* .text should occupy whole number of pages */
27931 @@ -122,16 +176,20 @@ SECTIONS
27932
27933 /* Data */
27934 .data : AT(ADDR(.data) - LOAD_OFFSET) {
27935 +
27936 +#ifdef CONFIG_PAX_KERNEXEC
27937 + . = ALIGN(HPAGE_SIZE);
27938 +#else
27939 + . = ALIGN(PAGE_SIZE);
27940 +#endif
27941 +
27942 /* Start of data section */
27943 _sdata = .;
27944
27945 /* init_task */
27946 INIT_TASK_DATA(THREAD_SIZE)
27947
27948 -#ifdef CONFIG_X86_32
27949 - /* 32 bit has nosave before _edata */
27950 NOSAVE_DATA
27951 -#endif
27952
27953 PAGE_ALIGNED_DATA(PAGE_SIZE)
27954
27955 @@ -174,12 +232,19 @@ SECTIONS
27956 . = ALIGN(__vvar_page + PAGE_SIZE, PAGE_SIZE);
27957
27958 /* Init code and data - will be freed after init */
27959 - . = ALIGN(PAGE_SIZE);
27960 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
27961 + BYTE(0)
27962 +
27963 +#ifdef CONFIG_PAX_KERNEXEC
27964 + . = ALIGN(HPAGE_SIZE);
27965 +#else
27966 + . = ALIGN(PAGE_SIZE);
27967 +#endif
27968 +
27969 __init_begin = .; /* paired with __init_end */
27970 - }
27971 + } :init.begin
27972
27973 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
27974 +#ifdef CONFIG_SMP
27975 /*
27976 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
27977 * output PHDR, so the next output section - .init.text - should
27978 @@ -188,12 +253,27 @@ SECTIONS
27979 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
27980 #endif
27981
27982 - INIT_TEXT_SECTION(PAGE_SIZE)
27983 -#ifdef CONFIG_X86_64
27984 - :init
27985 -#endif
27986 + . = ALIGN(PAGE_SIZE);
27987 + init_begin = .;
27988 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
27989 + VMLINUX_SYMBOL(_sinittext) = .;
27990 + INIT_TEXT
27991 + VMLINUX_SYMBOL(_einittext) = .;
27992 + . = ALIGN(PAGE_SIZE);
27993 + } :text.init
27994
27995 - INIT_DATA_SECTION(16)
27996 + /*
27997 + * .exit.text is discard at runtime, not link time, to deal with
27998 + * references from .altinstructions and .eh_frame
27999 + */
28000 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
28001 + EXIT_TEXT
28002 + . = ALIGN(16);
28003 + } :text.exit
28004 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
28005 +
28006 + . = ALIGN(PAGE_SIZE);
28007 + INIT_DATA_SECTION(16) :init
28008
28009 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
28010 __x86_cpu_dev_start = .;
28011 @@ -264,19 +344,12 @@ SECTIONS
28012 }
28013
28014 . = ALIGN(8);
28015 - /*
28016 - * .exit.text is discard at runtime, not link time, to deal with
28017 - * references from .altinstructions and .eh_frame
28018 - */
28019 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
28020 - EXIT_TEXT
28021 - }
28022
28023 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
28024 EXIT_DATA
28025 }
28026
28027 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
28028 +#ifndef CONFIG_SMP
28029 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
28030 #endif
28031
28032 @@ -295,16 +368,10 @@ SECTIONS
28033 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
28034 __smp_locks = .;
28035 *(.smp_locks)
28036 - . = ALIGN(PAGE_SIZE);
28037 __smp_locks_end = .;
28038 + . = ALIGN(PAGE_SIZE);
28039 }
28040
28041 -#ifdef CONFIG_X86_64
28042 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
28043 - NOSAVE_DATA
28044 - }
28045 -#endif
28046 -
28047 /* BSS */
28048 . = ALIGN(PAGE_SIZE);
28049 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
28050 @@ -320,6 +387,7 @@ SECTIONS
28051 __brk_base = .;
28052 . += 64 * 1024; /* 64k alignment slop space */
28053 *(.brk_reservation) /* areas brk users have reserved */
28054 + . = ALIGN(HPAGE_SIZE);
28055 __brk_limit = .;
28056 }
28057
28058 @@ -346,13 +414,12 @@ SECTIONS
28059 * for the boot processor.
28060 */
28061 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
28062 -INIT_PER_CPU(gdt_page);
28063 INIT_PER_CPU(irq_stack_union);
28064
28065 /*
28066 * Build-time check on the image size:
28067 */
28068 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
28069 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
28070 "kernel image bigger than KERNEL_IMAGE_SIZE");
28071
28072 #ifdef CONFIG_SMP
28073 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
28074 index 8b3b3eb..9395aa9 100644
28075 --- a/arch/x86/kernel/vsyscall_64.c
28076 +++ b/arch/x86/kernel/vsyscall_64.c
28077 @@ -54,15 +54,13 @@
28078
28079 DEFINE_VVAR(int, vgetcpu_mode);
28080
28081 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
28082 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
28083
28084 static int __init vsyscall_setup(char *str)
28085 {
28086 if (str) {
28087 if (!strcmp("emulate", str))
28088 vsyscall_mode = EMULATE;
28089 - else if (!strcmp("native", str))
28090 - vsyscall_mode = NATIVE;
28091 else if (!strcmp("none", str))
28092 vsyscall_mode = NONE;
28093 else
28094 @@ -279,8 +277,7 @@ do_ret:
28095 return true;
28096
28097 sigsegv:
28098 - force_sig(SIGSEGV, current);
28099 - return true;
28100 + do_group_exit(SIGKILL);
28101 }
28102
28103 /*
28104 @@ -332,10 +329,7 @@ void __init map_vsyscall(void)
28105 unsigned long physaddr_vsyscall = __pa_symbol(&__vsyscall_page);
28106 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
28107
28108 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
28109 - vsyscall_mode == NATIVE
28110 - ? PAGE_KERNEL_VSYSCALL
28111 - : PAGE_KERNEL_VVAR);
28112 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
28113 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
28114 (unsigned long)VSYSCALL_START);
28115
28116 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
28117 index 04068192..4d75aa6 100644
28118 --- a/arch/x86/kernel/x8664_ksyms_64.c
28119 +++ b/arch/x86/kernel/x8664_ksyms_64.c
28120 @@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
28121 EXPORT_SYMBOL(copy_user_generic_unrolled);
28122 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
28123 EXPORT_SYMBOL(__copy_user_nocache);
28124 -EXPORT_SYMBOL(_copy_from_user);
28125 -EXPORT_SYMBOL(_copy_to_user);
28126
28127 EXPORT_SYMBOL(copy_page);
28128 EXPORT_SYMBOL(clear_page);
28129 @@ -73,3 +71,7 @@ EXPORT_SYMBOL(___preempt_schedule);
28130 EXPORT_SYMBOL(___preempt_schedule_context);
28131 #endif
28132 #endif
28133 +
28134 +#ifdef CONFIG_PAX_PER_CPU_PGD
28135 +EXPORT_SYMBOL(cpu_pgd);
28136 +#endif
28137 diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
28138 index e48b674..a451dd9 100644
28139 --- a/arch/x86/kernel/x86_init.c
28140 +++ b/arch/x86/kernel/x86_init.c
28141 @@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
28142 static void default_nmi_init(void) { };
28143 static int default_i8042_detect(void) { return 1; };
28144
28145 -struct x86_platform_ops x86_platform = {
28146 +struct x86_platform_ops x86_platform __read_only = {
28147 .calibrate_tsc = native_calibrate_tsc,
28148 .get_wallclock = mach_get_cmos_time,
28149 .set_wallclock = mach_set_rtc_mmss,
28150 @@ -109,7 +109,7 @@ struct x86_platform_ops x86_platform = {
28151 EXPORT_SYMBOL_GPL(x86_platform);
28152
28153 #if defined(CONFIG_PCI_MSI)
28154 -struct x86_msi_ops x86_msi = {
28155 +struct x86_msi_ops x86_msi __read_only = {
28156 .setup_msi_irqs = native_setup_msi_irqs,
28157 .compose_msi_msg = native_compose_msi_msg,
28158 .teardown_msi_irq = native_teardown_msi_irq,
28159 @@ -150,7 +150,7 @@ u32 arch_msix_mask_irq(struct msi_desc *desc, u32 flag)
28160 }
28161 #endif
28162
28163 -struct x86_io_apic_ops x86_io_apic_ops = {
28164 +struct x86_io_apic_ops x86_io_apic_ops __read_only = {
28165 .init = native_io_apic_init_mappings,
28166 .read = native_io_apic_read,
28167 .write = native_io_apic_write,
28168 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
28169 index a4b451c..8dfe1ad 100644
28170 --- a/arch/x86/kernel/xsave.c
28171 +++ b/arch/x86/kernel/xsave.c
28172 @@ -164,18 +164,18 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28173
28174 /* Setup the bytes not touched by the [f]xsave and reserved for SW. */
28175 sw_bytes = ia32_frame ? &fx_sw_reserved_ia32 : &fx_sw_reserved;
28176 - err = __copy_to_user(&x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28177 + err = __copy_to_user(x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
28178
28179 if (!use_xsave())
28180 return err;
28181
28182 - err |= __put_user(FP_XSTATE_MAGIC2, (__u32 *)(buf + xstate_size));
28183 + err |= __put_user(FP_XSTATE_MAGIC2, (__u32 __user *)(buf + xstate_size));
28184
28185 /*
28186 * Read the xstate_bv which we copied (directly from the cpu or
28187 * from the state in task struct) to the user buffers.
28188 */
28189 - err |= __get_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28190 + err |= __get_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28191
28192 /*
28193 * For legacy compatible, we always set FP/SSE bits in the bit
28194 @@ -190,7 +190,7 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
28195 */
28196 xstate_bv |= XSTATE_FPSSE;
28197
28198 - err |= __put_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
28199 + err |= __put_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
28200
28201 return err;
28202 }
28203 @@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
28204 {
28205 int err;
28206
28207 + buf = (struct xsave_struct __user *)____m(buf);
28208 if (use_xsave())
28209 err = xsave_user(buf);
28210 else if (use_fxsr())
28211 @@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
28212 */
28213 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
28214 {
28215 + buf = (void __user *)____m(buf);
28216 if (use_xsave()) {
28217 if ((unsigned long)buf % 64 || fx_only) {
28218 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
28219 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
28220 index f47a104..5ce59a8 100644
28221 --- a/arch/x86/kvm/cpuid.c
28222 +++ b/arch/x86/kvm/cpuid.c
28223 @@ -166,15 +166,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
28224 struct kvm_cpuid2 *cpuid,
28225 struct kvm_cpuid_entry2 __user *entries)
28226 {
28227 - int r;
28228 + int r, i;
28229
28230 r = -E2BIG;
28231 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
28232 goto out;
28233 r = -EFAULT;
28234 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
28235 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28236 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
28237 goto out;
28238 + for (i = 0; i < cpuid->nent; ++i) {
28239 + struct kvm_cpuid_entry2 cpuid_entry;
28240 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
28241 + goto out;
28242 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
28243 + }
28244 vcpu->arch.cpuid_nent = cpuid->nent;
28245 kvm_apic_set_version(vcpu);
28246 kvm_x86_ops->cpuid_update(vcpu);
28247 @@ -189,15 +194,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
28248 struct kvm_cpuid2 *cpuid,
28249 struct kvm_cpuid_entry2 __user *entries)
28250 {
28251 - int r;
28252 + int r, i;
28253
28254 r = -E2BIG;
28255 if (cpuid->nent < vcpu->arch.cpuid_nent)
28256 goto out;
28257 r = -EFAULT;
28258 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
28259 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28260 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
28261 goto out;
28262 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
28263 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
28264 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
28265 + goto out;
28266 + }
28267 return 0;
28268
28269 out:
28270 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
28271 index 0069118..c28ec0a 100644
28272 --- a/arch/x86/kvm/lapic.c
28273 +++ b/arch/x86/kvm/lapic.c
28274 @@ -55,7 +55,7 @@
28275 #define APIC_BUS_CYCLE_NS 1
28276
28277 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
28278 -#define apic_debug(fmt, arg...)
28279 +#define apic_debug(fmt, arg...) do {} while (0)
28280
28281 #define APIC_LVT_NUM 6
28282 /* 14 is the version for Xeon and Pentium 8.4.8*/
28283 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
28284 index 123efd3..ad7726e 100644
28285 --- a/arch/x86/kvm/paging_tmpl.h
28286 +++ b/arch/x86/kvm/paging_tmpl.h
28287 @@ -331,7 +331,7 @@ retry_walk:
28288 if (unlikely(kvm_is_error_hva(host_addr)))
28289 goto error;
28290
28291 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
28292 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
28293 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
28294 goto error;
28295 walker->ptep_user[walker->level - 1] = ptep_user;
28296 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
28297 index 7f4f9c2..67b1db0 100644
28298 --- a/arch/x86/kvm/svm.c
28299 +++ b/arch/x86/kvm/svm.c
28300 @@ -3535,7 +3535,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
28301 int cpu = raw_smp_processor_id();
28302
28303 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
28304 +
28305 + pax_open_kernel();
28306 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
28307 + pax_close_kernel();
28308 +
28309 load_TR_desc();
28310 }
28311
28312 @@ -3936,6 +3940,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
28313 #endif
28314 #endif
28315
28316 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
28317 + __set_fs(current_thread_info()->addr_limit);
28318 +#endif
28319 +
28320 reload_tss(vcpu);
28321
28322 local_irq_disable();
28323 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
28324 index 138ceff..2e584f0 100644
28325 --- a/arch/x86/kvm/vmx.c
28326 +++ b/arch/x86/kvm/vmx.c
28327 @@ -1339,12 +1339,12 @@ static void vmcs_write64(unsigned long field, u64 value)
28328 #endif
28329 }
28330
28331 -static void vmcs_clear_bits(unsigned long field, u32 mask)
28332 +static void vmcs_clear_bits(unsigned long field, unsigned long mask)
28333 {
28334 vmcs_writel(field, vmcs_readl(field) & ~mask);
28335 }
28336
28337 -static void vmcs_set_bits(unsigned long field, u32 mask)
28338 +static void vmcs_set_bits(unsigned long field, unsigned long mask)
28339 {
28340 vmcs_writel(field, vmcs_readl(field) | mask);
28341 }
28342 @@ -1604,7 +1604,11 @@ static void reload_tss(void)
28343 struct desc_struct *descs;
28344
28345 descs = (void *)gdt->address;
28346 +
28347 + pax_open_kernel();
28348 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
28349 + pax_close_kernel();
28350 +
28351 load_TR_desc();
28352 }
28353
28354 @@ -1832,6 +1836,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
28355 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
28356 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
28357
28358 +#ifdef CONFIG_PAX_PER_CPU_PGD
28359 + vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28360 +#endif
28361 +
28362 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
28363 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
28364 vmx->loaded_vmcs->cpu = cpu;
28365 @@ -2121,7 +2129,7 @@ static void setup_msrs(struct vcpu_vmx *vmx)
28366 * reads and returns guest's timestamp counter "register"
28367 * guest_tsc = host_tsc + tsc_offset -- 21.3
28368 */
28369 -static u64 guest_read_tsc(void)
28370 +static u64 __intentional_overflow(-1) guest_read_tsc(void)
28371 {
28372 u64 host_tsc, tsc_offset;
28373
28374 @@ -3093,8 +3101,11 @@ static __init int hardware_setup(void)
28375 if (!cpu_has_vmx_flexpriority())
28376 flexpriority_enabled = 0;
28377
28378 - if (!cpu_has_vmx_tpr_shadow())
28379 - kvm_x86_ops->update_cr8_intercept = NULL;
28380 + if (!cpu_has_vmx_tpr_shadow()) {
28381 + pax_open_kernel();
28382 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28383 + pax_close_kernel();
28384 + }
28385
28386 if (enable_ept && !cpu_has_vmx_ept_2m_page())
28387 kvm_disable_largepages();
28388 @@ -3105,13 +3116,15 @@ static __init int hardware_setup(void)
28389 if (!cpu_has_vmx_apicv())
28390 enable_apicv = 0;
28391
28392 + pax_open_kernel();
28393 if (enable_apicv)
28394 - kvm_x86_ops->update_cr8_intercept = NULL;
28395 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
28396 else {
28397 - kvm_x86_ops->hwapic_irr_update = NULL;
28398 - kvm_x86_ops->deliver_posted_interrupt = NULL;
28399 - kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28400 + *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
28401 + *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
28402 + *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
28403 }
28404 + pax_close_kernel();
28405
28406 if (nested)
28407 nested_vmx_setup_ctls_msrs();
28408 @@ -4235,7 +4248,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28409
28410 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
28411 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
28412 +
28413 +#ifndef CONFIG_PAX_PER_CPU_PGD
28414 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
28415 +#endif
28416
28417 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
28418 #ifdef CONFIG_X86_64
28419 @@ -4257,7 +4273,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
28420 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
28421 vmx->host_idt_base = dt.address;
28422
28423 - vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
28424 + vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
28425
28426 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
28427 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
28428 @@ -7333,6 +7349,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28429 "jmp 2f \n\t"
28430 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
28431 "2: "
28432 +
28433 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28434 + "ljmp %[cs],$3f\n\t"
28435 + "3: "
28436 +#endif
28437 +
28438 /* Save guest registers, load host registers, keep flags */
28439 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
28440 "pop %0 \n\t"
28441 @@ -7385,6 +7407,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28442 #endif
28443 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
28444 [wordsize]"i"(sizeof(ulong))
28445 +
28446 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
28447 + ,[cs]"i"(__KERNEL_CS)
28448 +#endif
28449 +
28450 : "cc", "memory"
28451 #ifdef CONFIG_X86_64
28452 , "rax", "rbx", "rdi", "rsi"
28453 @@ -7398,7 +7425,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28454 if (debugctlmsr)
28455 update_debugctlmsr(debugctlmsr);
28456
28457 -#ifndef CONFIG_X86_64
28458 +#ifdef CONFIG_X86_32
28459 /*
28460 * The sysexit path does not restore ds/es, so we must set them to
28461 * a reasonable value ourselves.
28462 @@ -7407,8 +7434,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
28463 * may be executed in interrupt context, which saves and restore segments
28464 * around it, nullifying its effect.
28465 */
28466 - loadsegment(ds, __USER_DS);
28467 - loadsegment(es, __USER_DS);
28468 + loadsegment(ds, __KERNEL_DS);
28469 + loadsegment(es, __KERNEL_DS);
28470 + loadsegment(ss, __KERNEL_DS);
28471 +
28472 +#ifdef CONFIG_PAX_KERNEXEC
28473 + loadsegment(fs, __KERNEL_PERCPU);
28474 +#endif
28475 +
28476 +#ifdef CONFIG_PAX_MEMORY_UDEREF
28477 + __set_fs(current_thread_info()->addr_limit);
28478 +#endif
28479 +
28480 #endif
28481
28482 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
28483 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
28484 index 5521f7c..691b7a3 100644
28485 --- a/arch/x86/kvm/x86.c
28486 +++ b/arch/x86/kvm/x86.c
28487 @@ -1822,8 +1822,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
28488 {
28489 struct kvm *kvm = vcpu->kvm;
28490 int lm = is_long_mode(vcpu);
28491 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28492 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28493 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
28494 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
28495 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
28496 : kvm->arch.xen_hvm_config.blob_size_32;
28497 u32 page_num = data & ~PAGE_MASK;
28498 @@ -2738,6 +2738,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
28499 if (n < msr_list.nmsrs)
28500 goto out;
28501 r = -EFAULT;
28502 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
28503 + goto out;
28504 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
28505 num_msrs_to_save * sizeof(u32)))
28506 goto out;
28507 @@ -5574,7 +5576,7 @@ static struct notifier_block pvclock_gtod_notifier = {
28508 };
28509 #endif
28510
28511 -int kvm_arch_init(void *opaque)
28512 +int kvm_arch_init(const void *opaque)
28513 {
28514 int r;
28515 struct kvm_x86_ops *ops = opaque;
28516 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
28517 index aae9413..d11e829 100644
28518 --- a/arch/x86/lguest/boot.c
28519 +++ b/arch/x86/lguest/boot.c
28520 @@ -1206,9 +1206,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
28521 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
28522 * Launcher to reboot us.
28523 */
28524 -static void lguest_restart(char *reason)
28525 +static __noreturn void lguest_restart(char *reason)
28526 {
28527 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
28528 + BUG();
28529 }
28530
28531 /*G:050
28532 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
28533 index 00933d5..3a64af9 100644
28534 --- a/arch/x86/lib/atomic64_386_32.S
28535 +++ b/arch/x86/lib/atomic64_386_32.S
28536 @@ -48,6 +48,10 @@ BEGIN(read)
28537 movl (v), %eax
28538 movl 4(v), %edx
28539 RET_ENDP
28540 +BEGIN(read_unchecked)
28541 + movl (v), %eax
28542 + movl 4(v), %edx
28543 +RET_ENDP
28544 #undef v
28545
28546 #define v %esi
28547 @@ -55,6 +59,10 @@ BEGIN(set)
28548 movl %ebx, (v)
28549 movl %ecx, 4(v)
28550 RET_ENDP
28551 +BEGIN(set_unchecked)
28552 + movl %ebx, (v)
28553 + movl %ecx, 4(v)
28554 +RET_ENDP
28555 #undef v
28556
28557 #define v %esi
28558 @@ -70,6 +78,20 @@ RET_ENDP
28559 BEGIN(add)
28560 addl %eax, (v)
28561 adcl %edx, 4(v)
28562 +
28563 +#ifdef CONFIG_PAX_REFCOUNT
28564 + jno 0f
28565 + subl %eax, (v)
28566 + sbbl %edx, 4(v)
28567 + int $4
28568 +0:
28569 + _ASM_EXTABLE(0b, 0b)
28570 +#endif
28571 +
28572 +RET_ENDP
28573 +BEGIN(add_unchecked)
28574 + addl %eax, (v)
28575 + adcl %edx, 4(v)
28576 RET_ENDP
28577 #undef v
28578
28579 @@ -77,6 +99,24 @@ RET_ENDP
28580 BEGIN(add_return)
28581 addl (v), %eax
28582 adcl 4(v), %edx
28583 +
28584 +#ifdef CONFIG_PAX_REFCOUNT
28585 + into
28586 +1234:
28587 + _ASM_EXTABLE(1234b, 2f)
28588 +#endif
28589 +
28590 + movl %eax, (v)
28591 + movl %edx, 4(v)
28592 +
28593 +#ifdef CONFIG_PAX_REFCOUNT
28594 +2:
28595 +#endif
28596 +
28597 +RET_ENDP
28598 +BEGIN(add_return_unchecked)
28599 + addl (v), %eax
28600 + adcl 4(v), %edx
28601 movl %eax, (v)
28602 movl %edx, 4(v)
28603 RET_ENDP
28604 @@ -86,6 +126,20 @@ RET_ENDP
28605 BEGIN(sub)
28606 subl %eax, (v)
28607 sbbl %edx, 4(v)
28608 +
28609 +#ifdef CONFIG_PAX_REFCOUNT
28610 + jno 0f
28611 + addl %eax, (v)
28612 + adcl %edx, 4(v)
28613 + int $4
28614 +0:
28615 + _ASM_EXTABLE(0b, 0b)
28616 +#endif
28617 +
28618 +RET_ENDP
28619 +BEGIN(sub_unchecked)
28620 + subl %eax, (v)
28621 + sbbl %edx, 4(v)
28622 RET_ENDP
28623 #undef v
28624
28625 @@ -96,6 +150,27 @@ BEGIN(sub_return)
28626 sbbl $0, %edx
28627 addl (v), %eax
28628 adcl 4(v), %edx
28629 +
28630 +#ifdef CONFIG_PAX_REFCOUNT
28631 + into
28632 +1234:
28633 + _ASM_EXTABLE(1234b, 2f)
28634 +#endif
28635 +
28636 + movl %eax, (v)
28637 + movl %edx, 4(v)
28638 +
28639 +#ifdef CONFIG_PAX_REFCOUNT
28640 +2:
28641 +#endif
28642 +
28643 +RET_ENDP
28644 +BEGIN(sub_return_unchecked)
28645 + negl %edx
28646 + negl %eax
28647 + sbbl $0, %edx
28648 + addl (v), %eax
28649 + adcl 4(v), %edx
28650 movl %eax, (v)
28651 movl %edx, 4(v)
28652 RET_ENDP
28653 @@ -105,6 +180,20 @@ RET_ENDP
28654 BEGIN(inc)
28655 addl $1, (v)
28656 adcl $0, 4(v)
28657 +
28658 +#ifdef CONFIG_PAX_REFCOUNT
28659 + jno 0f
28660 + subl $1, (v)
28661 + sbbl $0, 4(v)
28662 + int $4
28663 +0:
28664 + _ASM_EXTABLE(0b, 0b)
28665 +#endif
28666 +
28667 +RET_ENDP
28668 +BEGIN(inc_unchecked)
28669 + addl $1, (v)
28670 + adcl $0, 4(v)
28671 RET_ENDP
28672 #undef v
28673
28674 @@ -114,6 +203,26 @@ BEGIN(inc_return)
28675 movl 4(v), %edx
28676 addl $1, %eax
28677 adcl $0, %edx
28678 +
28679 +#ifdef CONFIG_PAX_REFCOUNT
28680 + into
28681 +1234:
28682 + _ASM_EXTABLE(1234b, 2f)
28683 +#endif
28684 +
28685 + movl %eax, (v)
28686 + movl %edx, 4(v)
28687 +
28688 +#ifdef CONFIG_PAX_REFCOUNT
28689 +2:
28690 +#endif
28691 +
28692 +RET_ENDP
28693 +BEGIN(inc_return_unchecked)
28694 + movl (v), %eax
28695 + movl 4(v), %edx
28696 + addl $1, %eax
28697 + adcl $0, %edx
28698 movl %eax, (v)
28699 movl %edx, 4(v)
28700 RET_ENDP
28701 @@ -123,6 +232,20 @@ RET_ENDP
28702 BEGIN(dec)
28703 subl $1, (v)
28704 sbbl $0, 4(v)
28705 +
28706 +#ifdef CONFIG_PAX_REFCOUNT
28707 + jno 0f
28708 + addl $1, (v)
28709 + adcl $0, 4(v)
28710 + int $4
28711 +0:
28712 + _ASM_EXTABLE(0b, 0b)
28713 +#endif
28714 +
28715 +RET_ENDP
28716 +BEGIN(dec_unchecked)
28717 + subl $1, (v)
28718 + sbbl $0, 4(v)
28719 RET_ENDP
28720 #undef v
28721
28722 @@ -132,6 +255,26 @@ BEGIN(dec_return)
28723 movl 4(v), %edx
28724 subl $1, %eax
28725 sbbl $0, %edx
28726 +
28727 +#ifdef CONFIG_PAX_REFCOUNT
28728 + into
28729 +1234:
28730 + _ASM_EXTABLE(1234b, 2f)
28731 +#endif
28732 +
28733 + movl %eax, (v)
28734 + movl %edx, 4(v)
28735 +
28736 +#ifdef CONFIG_PAX_REFCOUNT
28737 +2:
28738 +#endif
28739 +
28740 +RET_ENDP
28741 +BEGIN(dec_return_unchecked)
28742 + movl (v), %eax
28743 + movl 4(v), %edx
28744 + subl $1, %eax
28745 + sbbl $0, %edx
28746 movl %eax, (v)
28747 movl %edx, 4(v)
28748 RET_ENDP
28749 @@ -143,6 +286,13 @@ BEGIN(add_unless)
28750 adcl %edx, %edi
28751 addl (v), %eax
28752 adcl 4(v), %edx
28753 +
28754 +#ifdef CONFIG_PAX_REFCOUNT
28755 + into
28756 +1234:
28757 + _ASM_EXTABLE(1234b, 2f)
28758 +#endif
28759 +
28760 cmpl %eax, %ecx
28761 je 3f
28762 1:
28763 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
28764 1:
28765 addl $1, %eax
28766 adcl $0, %edx
28767 +
28768 +#ifdef CONFIG_PAX_REFCOUNT
28769 + into
28770 +1234:
28771 + _ASM_EXTABLE(1234b, 2f)
28772 +#endif
28773 +
28774 movl %eax, (v)
28775 movl %edx, 4(v)
28776 movl $1, %eax
28777 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
28778 movl 4(v), %edx
28779 subl $1, %eax
28780 sbbl $0, %edx
28781 +
28782 +#ifdef CONFIG_PAX_REFCOUNT
28783 + into
28784 +1234:
28785 + _ASM_EXTABLE(1234b, 1f)
28786 +#endif
28787 +
28788 js 1f
28789 movl %eax, (v)
28790 movl %edx, 4(v)
28791 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
28792 index f5cc9eb..51fa319 100644
28793 --- a/arch/x86/lib/atomic64_cx8_32.S
28794 +++ b/arch/x86/lib/atomic64_cx8_32.S
28795 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
28796 CFI_STARTPROC
28797
28798 read64 %ecx
28799 + pax_force_retaddr
28800 ret
28801 CFI_ENDPROC
28802 ENDPROC(atomic64_read_cx8)
28803
28804 +ENTRY(atomic64_read_unchecked_cx8)
28805 + CFI_STARTPROC
28806 +
28807 + read64 %ecx
28808 + pax_force_retaddr
28809 + ret
28810 + CFI_ENDPROC
28811 +ENDPROC(atomic64_read_unchecked_cx8)
28812 +
28813 ENTRY(atomic64_set_cx8)
28814 CFI_STARTPROC
28815
28816 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
28817 cmpxchg8b (%esi)
28818 jne 1b
28819
28820 + pax_force_retaddr
28821 ret
28822 CFI_ENDPROC
28823 ENDPROC(atomic64_set_cx8)
28824
28825 +ENTRY(atomic64_set_unchecked_cx8)
28826 + CFI_STARTPROC
28827 +
28828 +1:
28829 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
28830 + * are atomic on 586 and newer */
28831 + cmpxchg8b (%esi)
28832 + jne 1b
28833 +
28834 + pax_force_retaddr
28835 + ret
28836 + CFI_ENDPROC
28837 +ENDPROC(atomic64_set_unchecked_cx8)
28838 +
28839 ENTRY(atomic64_xchg_cx8)
28840 CFI_STARTPROC
28841
28842 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
28843 cmpxchg8b (%esi)
28844 jne 1b
28845
28846 + pax_force_retaddr
28847 ret
28848 CFI_ENDPROC
28849 ENDPROC(atomic64_xchg_cx8)
28850
28851 -.macro addsub_return func ins insc
28852 -ENTRY(atomic64_\func\()_return_cx8)
28853 +.macro addsub_return func ins insc unchecked=""
28854 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
28855 CFI_STARTPROC
28856 SAVE ebp
28857 SAVE ebx
28858 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
28859 movl %edx, %ecx
28860 \ins\()l %esi, %ebx
28861 \insc\()l %edi, %ecx
28862 +
28863 +.ifb \unchecked
28864 +#ifdef CONFIG_PAX_REFCOUNT
28865 + into
28866 +2:
28867 + _ASM_EXTABLE(2b, 3f)
28868 +#endif
28869 +.endif
28870 +
28871 LOCK_PREFIX
28872 cmpxchg8b (%ebp)
28873 jne 1b
28874 -
28875 -10:
28876 movl %ebx, %eax
28877 movl %ecx, %edx
28878 +
28879 +.ifb \unchecked
28880 +#ifdef CONFIG_PAX_REFCOUNT
28881 +3:
28882 +#endif
28883 +.endif
28884 +
28885 RESTORE edi
28886 RESTORE esi
28887 RESTORE ebx
28888 RESTORE ebp
28889 + pax_force_retaddr
28890 ret
28891 CFI_ENDPROC
28892 -ENDPROC(atomic64_\func\()_return_cx8)
28893 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
28894 .endm
28895
28896 addsub_return add add adc
28897 addsub_return sub sub sbb
28898 +addsub_return add add adc _unchecked
28899 +addsub_return sub sub sbb _unchecked
28900
28901 -.macro incdec_return func ins insc
28902 -ENTRY(atomic64_\func\()_return_cx8)
28903 +.macro incdec_return func ins insc unchecked=""
28904 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
28905 CFI_STARTPROC
28906 SAVE ebx
28907
28908 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
28909 movl %edx, %ecx
28910 \ins\()l $1, %ebx
28911 \insc\()l $0, %ecx
28912 +
28913 +.ifb \unchecked
28914 +#ifdef CONFIG_PAX_REFCOUNT
28915 + into
28916 +2:
28917 + _ASM_EXTABLE(2b, 3f)
28918 +#endif
28919 +.endif
28920 +
28921 LOCK_PREFIX
28922 cmpxchg8b (%esi)
28923 jne 1b
28924
28925 -10:
28926 movl %ebx, %eax
28927 movl %ecx, %edx
28928 +
28929 +.ifb \unchecked
28930 +#ifdef CONFIG_PAX_REFCOUNT
28931 +3:
28932 +#endif
28933 +.endif
28934 +
28935 RESTORE ebx
28936 + pax_force_retaddr
28937 ret
28938 CFI_ENDPROC
28939 -ENDPROC(atomic64_\func\()_return_cx8)
28940 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
28941 .endm
28942
28943 incdec_return inc add adc
28944 incdec_return dec sub sbb
28945 +incdec_return inc add adc _unchecked
28946 +incdec_return dec sub sbb _unchecked
28947
28948 ENTRY(atomic64_dec_if_positive_cx8)
28949 CFI_STARTPROC
28950 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
28951 movl %edx, %ecx
28952 subl $1, %ebx
28953 sbb $0, %ecx
28954 +
28955 +#ifdef CONFIG_PAX_REFCOUNT
28956 + into
28957 +1234:
28958 + _ASM_EXTABLE(1234b, 2f)
28959 +#endif
28960 +
28961 js 2f
28962 LOCK_PREFIX
28963 cmpxchg8b (%esi)
28964 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
28965 movl %ebx, %eax
28966 movl %ecx, %edx
28967 RESTORE ebx
28968 + pax_force_retaddr
28969 ret
28970 CFI_ENDPROC
28971 ENDPROC(atomic64_dec_if_positive_cx8)
28972 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
28973 movl %edx, %ecx
28974 addl %ebp, %ebx
28975 adcl %edi, %ecx
28976 +
28977 +#ifdef CONFIG_PAX_REFCOUNT
28978 + into
28979 +1234:
28980 + _ASM_EXTABLE(1234b, 3f)
28981 +#endif
28982 +
28983 LOCK_PREFIX
28984 cmpxchg8b (%esi)
28985 jne 1b
28986 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
28987 CFI_ADJUST_CFA_OFFSET -8
28988 RESTORE ebx
28989 RESTORE ebp
28990 + pax_force_retaddr
28991 ret
28992 4:
28993 cmpl %edx, 4(%esp)
28994 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
28995 xorl %ecx, %ecx
28996 addl $1, %ebx
28997 adcl %edx, %ecx
28998 +
28999 +#ifdef CONFIG_PAX_REFCOUNT
29000 + into
29001 +1234:
29002 + _ASM_EXTABLE(1234b, 3f)
29003 +#endif
29004 +
29005 LOCK_PREFIX
29006 cmpxchg8b (%esi)
29007 jne 1b
29008 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
29009 movl $1, %eax
29010 3:
29011 RESTORE ebx
29012 + pax_force_retaddr
29013 ret
29014 CFI_ENDPROC
29015 ENDPROC(atomic64_inc_not_zero_cx8)
29016 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
29017 index e78b8ee..7e173a8 100644
29018 --- a/arch/x86/lib/checksum_32.S
29019 +++ b/arch/x86/lib/checksum_32.S
29020 @@ -29,7 +29,8 @@
29021 #include <asm/dwarf2.h>
29022 #include <asm/errno.h>
29023 #include <asm/asm.h>
29024 -
29025 +#include <asm/segment.h>
29026 +
29027 /*
29028 * computes a partial checksum, e.g. for TCP/UDP fragments
29029 */
29030 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
29031
29032 #define ARGBASE 16
29033 #define FP 12
29034 -
29035 -ENTRY(csum_partial_copy_generic)
29036 +
29037 +ENTRY(csum_partial_copy_generic_to_user)
29038 CFI_STARTPROC
29039 +
29040 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29041 + pushl_cfi %gs
29042 + popl_cfi %es
29043 + jmp csum_partial_copy_generic
29044 +#endif
29045 +
29046 +ENTRY(csum_partial_copy_generic_from_user)
29047 +
29048 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29049 + pushl_cfi %gs
29050 + popl_cfi %ds
29051 +#endif
29052 +
29053 +ENTRY(csum_partial_copy_generic)
29054 subl $4,%esp
29055 CFI_ADJUST_CFA_OFFSET 4
29056 pushl_cfi %edi
29057 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
29058 jmp 4f
29059 SRC(1: movw (%esi), %bx )
29060 addl $2, %esi
29061 -DST( movw %bx, (%edi) )
29062 +DST( movw %bx, %es:(%edi) )
29063 addl $2, %edi
29064 addw %bx, %ax
29065 adcl $0, %eax
29066 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
29067 SRC(1: movl (%esi), %ebx )
29068 SRC( movl 4(%esi), %edx )
29069 adcl %ebx, %eax
29070 -DST( movl %ebx, (%edi) )
29071 +DST( movl %ebx, %es:(%edi) )
29072 adcl %edx, %eax
29073 -DST( movl %edx, 4(%edi) )
29074 +DST( movl %edx, %es:4(%edi) )
29075
29076 SRC( movl 8(%esi), %ebx )
29077 SRC( movl 12(%esi), %edx )
29078 adcl %ebx, %eax
29079 -DST( movl %ebx, 8(%edi) )
29080 +DST( movl %ebx, %es:8(%edi) )
29081 adcl %edx, %eax
29082 -DST( movl %edx, 12(%edi) )
29083 +DST( movl %edx, %es:12(%edi) )
29084
29085 SRC( movl 16(%esi), %ebx )
29086 SRC( movl 20(%esi), %edx )
29087 adcl %ebx, %eax
29088 -DST( movl %ebx, 16(%edi) )
29089 +DST( movl %ebx, %es:16(%edi) )
29090 adcl %edx, %eax
29091 -DST( movl %edx, 20(%edi) )
29092 +DST( movl %edx, %es:20(%edi) )
29093
29094 SRC( movl 24(%esi), %ebx )
29095 SRC( movl 28(%esi), %edx )
29096 adcl %ebx, %eax
29097 -DST( movl %ebx, 24(%edi) )
29098 +DST( movl %ebx, %es:24(%edi) )
29099 adcl %edx, %eax
29100 -DST( movl %edx, 28(%edi) )
29101 +DST( movl %edx, %es:28(%edi) )
29102
29103 lea 32(%esi), %esi
29104 lea 32(%edi), %edi
29105 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
29106 shrl $2, %edx # This clears CF
29107 SRC(3: movl (%esi), %ebx )
29108 adcl %ebx, %eax
29109 -DST( movl %ebx, (%edi) )
29110 +DST( movl %ebx, %es:(%edi) )
29111 lea 4(%esi), %esi
29112 lea 4(%edi), %edi
29113 dec %edx
29114 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
29115 jb 5f
29116 SRC( movw (%esi), %cx )
29117 leal 2(%esi), %esi
29118 -DST( movw %cx, (%edi) )
29119 +DST( movw %cx, %es:(%edi) )
29120 leal 2(%edi), %edi
29121 je 6f
29122 shll $16,%ecx
29123 SRC(5: movb (%esi), %cl )
29124 -DST( movb %cl, (%edi) )
29125 +DST( movb %cl, %es:(%edi) )
29126 6: addl %ecx, %eax
29127 adcl $0, %eax
29128 7:
29129 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
29130
29131 6001:
29132 movl ARGBASE+20(%esp), %ebx # src_err_ptr
29133 - movl $-EFAULT, (%ebx)
29134 + movl $-EFAULT, %ss:(%ebx)
29135
29136 # zero the complete destination - computing the rest
29137 # is too much work
29138 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
29139
29140 6002:
29141 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29142 - movl $-EFAULT,(%ebx)
29143 + movl $-EFAULT,%ss:(%ebx)
29144 jmp 5000b
29145
29146 .previous
29147
29148 + pushl_cfi %ss
29149 + popl_cfi %ds
29150 + pushl_cfi %ss
29151 + popl_cfi %es
29152 popl_cfi %ebx
29153 CFI_RESTORE ebx
29154 popl_cfi %esi
29155 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
29156 popl_cfi %ecx # equivalent to addl $4,%esp
29157 ret
29158 CFI_ENDPROC
29159 -ENDPROC(csum_partial_copy_generic)
29160 +ENDPROC(csum_partial_copy_generic_to_user)
29161
29162 #else
29163
29164 /* Version for PentiumII/PPro */
29165
29166 #define ROUND1(x) \
29167 + nop; nop; nop; \
29168 SRC(movl x(%esi), %ebx ) ; \
29169 addl %ebx, %eax ; \
29170 - DST(movl %ebx, x(%edi) ) ;
29171 + DST(movl %ebx, %es:x(%edi)) ;
29172
29173 #define ROUND(x) \
29174 + nop; nop; nop; \
29175 SRC(movl x(%esi), %ebx ) ; \
29176 adcl %ebx, %eax ; \
29177 - DST(movl %ebx, x(%edi) ) ;
29178 + DST(movl %ebx, %es:x(%edi)) ;
29179
29180 #define ARGBASE 12
29181 -
29182 -ENTRY(csum_partial_copy_generic)
29183 +
29184 +ENTRY(csum_partial_copy_generic_to_user)
29185 CFI_STARTPROC
29186 +
29187 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29188 + pushl_cfi %gs
29189 + popl_cfi %es
29190 + jmp csum_partial_copy_generic
29191 +#endif
29192 +
29193 +ENTRY(csum_partial_copy_generic_from_user)
29194 +
29195 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29196 + pushl_cfi %gs
29197 + popl_cfi %ds
29198 +#endif
29199 +
29200 +ENTRY(csum_partial_copy_generic)
29201 pushl_cfi %ebx
29202 CFI_REL_OFFSET ebx, 0
29203 pushl_cfi %edi
29204 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
29205 subl %ebx, %edi
29206 lea -1(%esi),%edx
29207 andl $-32,%edx
29208 - lea 3f(%ebx,%ebx), %ebx
29209 + lea 3f(%ebx,%ebx,2), %ebx
29210 testl %esi, %esi
29211 jmp *%ebx
29212 1: addl $64,%esi
29213 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
29214 jb 5f
29215 SRC( movw (%esi), %dx )
29216 leal 2(%esi), %esi
29217 -DST( movw %dx, (%edi) )
29218 +DST( movw %dx, %es:(%edi) )
29219 leal 2(%edi), %edi
29220 je 6f
29221 shll $16,%edx
29222 5:
29223 SRC( movb (%esi), %dl )
29224 -DST( movb %dl, (%edi) )
29225 +DST( movb %dl, %es:(%edi) )
29226 6: addl %edx, %eax
29227 adcl $0, %eax
29228 7:
29229 .section .fixup, "ax"
29230 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
29231 - movl $-EFAULT, (%ebx)
29232 + movl $-EFAULT, %ss:(%ebx)
29233 # zero the complete destination (computing the rest is too much work)
29234 movl ARGBASE+8(%esp),%edi # dst
29235 movl ARGBASE+12(%esp),%ecx # len
29236 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
29237 rep; stosb
29238 jmp 7b
29239 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
29240 - movl $-EFAULT, (%ebx)
29241 + movl $-EFAULT, %ss:(%ebx)
29242 jmp 7b
29243 .previous
29244
29245 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29246 + pushl_cfi %ss
29247 + popl_cfi %ds
29248 + pushl_cfi %ss
29249 + popl_cfi %es
29250 +#endif
29251 +
29252 popl_cfi %esi
29253 CFI_RESTORE esi
29254 popl_cfi %edi
29255 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
29256 CFI_RESTORE ebx
29257 ret
29258 CFI_ENDPROC
29259 -ENDPROC(csum_partial_copy_generic)
29260 +ENDPROC(csum_partial_copy_generic_to_user)
29261
29262 #undef ROUND
29263 #undef ROUND1
29264 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
29265 index f2145cf..cea889d 100644
29266 --- a/arch/x86/lib/clear_page_64.S
29267 +++ b/arch/x86/lib/clear_page_64.S
29268 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
29269 movl $4096/8,%ecx
29270 xorl %eax,%eax
29271 rep stosq
29272 + pax_force_retaddr
29273 ret
29274 CFI_ENDPROC
29275 ENDPROC(clear_page_c)
29276 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
29277 movl $4096,%ecx
29278 xorl %eax,%eax
29279 rep stosb
29280 + pax_force_retaddr
29281 ret
29282 CFI_ENDPROC
29283 ENDPROC(clear_page_c_e)
29284 @@ -43,6 +45,7 @@ ENTRY(clear_page)
29285 leaq 64(%rdi),%rdi
29286 jnz .Lloop
29287 nop
29288 + pax_force_retaddr
29289 ret
29290 CFI_ENDPROC
29291 .Lclear_page_end:
29292 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
29293
29294 #include <asm/cpufeature.h>
29295
29296 - .section .altinstr_replacement,"ax"
29297 + .section .altinstr_replacement,"a"
29298 1: .byte 0xeb /* jmp <disp8> */
29299 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
29300 2: .byte 0xeb /* jmp <disp8> */
29301 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
29302 index 1e572c5..2a162cd 100644
29303 --- a/arch/x86/lib/cmpxchg16b_emu.S
29304 +++ b/arch/x86/lib/cmpxchg16b_emu.S
29305 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
29306
29307 popf
29308 mov $1, %al
29309 + pax_force_retaddr
29310 ret
29311
29312 not_same:
29313 popf
29314 xor %al,%al
29315 + pax_force_retaddr
29316 ret
29317
29318 CFI_ENDPROC
29319 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
29320 index 176cca6..e0d658e 100644
29321 --- a/arch/x86/lib/copy_page_64.S
29322 +++ b/arch/x86/lib/copy_page_64.S
29323 @@ -9,6 +9,7 @@ copy_page_rep:
29324 CFI_STARTPROC
29325 movl $4096/8, %ecx
29326 rep movsq
29327 + pax_force_retaddr
29328 ret
29329 CFI_ENDPROC
29330 ENDPROC(copy_page_rep)
29331 @@ -24,8 +25,8 @@ ENTRY(copy_page)
29332 CFI_ADJUST_CFA_OFFSET 2*8
29333 movq %rbx, (%rsp)
29334 CFI_REL_OFFSET rbx, 0
29335 - movq %r12, 1*8(%rsp)
29336 - CFI_REL_OFFSET r12, 1*8
29337 + movq %r13, 1*8(%rsp)
29338 + CFI_REL_OFFSET r13, 1*8
29339
29340 movl $(4096/64)-5, %ecx
29341 .p2align 4
29342 @@ -38,7 +39,7 @@ ENTRY(copy_page)
29343 movq 0x8*4(%rsi), %r9
29344 movq 0x8*5(%rsi), %r10
29345 movq 0x8*6(%rsi), %r11
29346 - movq 0x8*7(%rsi), %r12
29347 + movq 0x8*7(%rsi), %r13
29348
29349 prefetcht0 5*64(%rsi)
29350
29351 @@ -49,7 +50,7 @@ ENTRY(copy_page)
29352 movq %r9, 0x8*4(%rdi)
29353 movq %r10, 0x8*5(%rdi)
29354 movq %r11, 0x8*6(%rdi)
29355 - movq %r12, 0x8*7(%rdi)
29356 + movq %r13, 0x8*7(%rdi)
29357
29358 leaq 64 (%rsi), %rsi
29359 leaq 64 (%rdi), %rdi
29360 @@ -68,7 +69,7 @@ ENTRY(copy_page)
29361 movq 0x8*4(%rsi), %r9
29362 movq 0x8*5(%rsi), %r10
29363 movq 0x8*6(%rsi), %r11
29364 - movq 0x8*7(%rsi), %r12
29365 + movq 0x8*7(%rsi), %r13
29366
29367 movq %rax, 0x8*0(%rdi)
29368 movq %rbx, 0x8*1(%rdi)
29369 @@ -77,7 +78,7 @@ ENTRY(copy_page)
29370 movq %r9, 0x8*4(%rdi)
29371 movq %r10, 0x8*5(%rdi)
29372 movq %r11, 0x8*6(%rdi)
29373 - movq %r12, 0x8*7(%rdi)
29374 + movq %r13, 0x8*7(%rdi)
29375
29376 leaq 64(%rdi), %rdi
29377 leaq 64(%rsi), %rsi
29378 @@ -85,10 +86,11 @@ ENTRY(copy_page)
29379
29380 movq (%rsp), %rbx
29381 CFI_RESTORE rbx
29382 - movq 1*8(%rsp), %r12
29383 - CFI_RESTORE r12
29384 + movq 1*8(%rsp), %r13
29385 + CFI_RESTORE r13
29386 addq $2*8, %rsp
29387 CFI_ADJUST_CFA_OFFSET -2*8
29388 + pax_force_retaddr
29389 ret
29390 .Lcopy_page_end:
29391 CFI_ENDPROC
29392 @@ -99,7 +101,7 @@ ENDPROC(copy_page)
29393
29394 #include <asm/cpufeature.h>
29395
29396 - .section .altinstr_replacement,"ax"
29397 + .section .altinstr_replacement,"a"
29398 1: .byte 0xeb /* jmp <disp8> */
29399 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
29400 2:
29401 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
29402 index dee945d..a84067b 100644
29403 --- a/arch/x86/lib/copy_user_64.S
29404 +++ b/arch/x86/lib/copy_user_64.S
29405 @@ -18,31 +18,7 @@
29406 #include <asm/alternative-asm.h>
29407 #include <asm/asm.h>
29408 #include <asm/smap.h>
29409 -
29410 -/*
29411 - * By placing feature2 after feature1 in altinstructions section, we logically
29412 - * implement:
29413 - * If CPU has feature2, jmp to alt2 is used
29414 - * else if CPU has feature1, jmp to alt1 is used
29415 - * else jmp to orig is used.
29416 - */
29417 - .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
29418 -0:
29419 - .byte 0xe9 /* 32bit jump */
29420 - .long \orig-1f /* by default jump to orig */
29421 -1:
29422 - .section .altinstr_replacement,"ax"
29423 -2: .byte 0xe9 /* near jump with 32bit immediate */
29424 - .long \alt1-1b /* offset */ /* or alternatively to alt1 */
29425 -3: .byte 0xe9 /* near jump with 32bit immediate */
29426 - .long \alt2-1b /* offset */ /* or alternatively to alt2 */
29427 - .previous
29428 -
29429 - .section .altinstructions,"a"
29430 - altinstruction_entry 0b,2b,\feature1,5,5
29431 - altinstruction_entry 0b,3b,\feature2,5,5
29432 - .previous
29433 - .endm
29434 +#include <asm/pgtable.h>
29435
29436 .macro ALIGN_DESTINATION
29437 #ifdef FIX_ALIGNMENT
29438 @@ -70,52 +46,6 @@
29439 #endif
29440 .endm
29441
29442 -/* Standard copy_to_user with segment limit checking */
29443 -ENTRY(_copy_to_user)
29444 - CFI_STARTPROC
29445 - GET_THREAD_INFO(%rax)
29446 - movq %rdi,%rcx
29447 - addq %rdx,%rcx
29448 - jc bad_to_user
29449 - cmpq TI_addr_limit(%rax),%rcx
29450 - ja bad_to_user
29451 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29452 - copy_user_generic_unrolled,copy_user_generic_string, \
29453 - copy_user_enhanced_fast_string
29454 - CFI_ENDPROC
29455 -ENDPROC(_copy_to_user)
29456 -
29457 -/* Standard copy_from_user with segment limit checking */
29458 -ENTRY(_copy_from_user)
29459 - CFI_STARTPROC
29460 - GET_THREAD_INFO(%rax)
29461 - movq %rsi,%rcx
29462 - addq %rdx,%rcx
29463 - jc bad_from_user
29464 - cmpq TI_addr_limit(%rax),%rcx
29465 - ja bad_from_user
29466 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
29467 - copy_user_generic_unrolled,copy_user_generic_string, \
29468 - copy_user_enhanced_fast_string
29469 - CFI_ENDPROC
29470 -ENDPROC(_copy_from_user)
29471 -
29472 - .section .fixup,"ax"
29473 - /* must zero dest */
29474 -ENTRY(bad_from_user)
29475 -bad_from_user:
29476 - CFI_STARTPROC
29477 - movl %edx,%ecx
29478 - xorl %eax,%eax
29479 - rep
29480 - stosb
29481 -bad_to_user:
29482 - movl %edx,%eax
29483 - ret
29484 - CFI_ENDPROC
29485 -ENDPROC(bad_from_user)
29486 - .previous
29487 -
29488 /*
29489 * copy_user_generic_unrolled - memory copy with exception handling.
29490 * This version is for CPUs like P4 that don't have efficient micro
29491 @@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
29492 */
29493 ENTRY(copy_user_generic_unrolled)
29494 CFI_STARTPROC
29495 + ASM_PAX_OPEN_USERLAND
29496 ASM_STAC
29497 cmpl $8,%edx
29498 jb 20f /* less then 8 bytes, go to byte copy loop */
29499 @@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
29500 jnz 21b
29501 23: xor %eax,%eax
29502 ASM_CLAC
29503 + ASM_PAX_CLOSE_USERLAND
29504 + pax_force_retaddr
29505 ret
29506
29507 .section .fixup,"ax"
29508 @@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
29509 */
29510 ENTRY(copy_user_generic_string)
29511 CFI_STARTPROC
29512 + ASM_PAX_OPEN_USERLAND
29513 ASM_STAC
29514 cmpl $8,%edx
29515 jb 2f /* less than 8 bytes, go to byte copy loop */
29516 @@ -249,6 +183,8 @@ ENTRY(copy_user_generic_string)
29517 movsb
29518 xorl %eax,%eax
29519 ASM_CLAC
29520 + ASM_PAX_CLOSE_USERLAND
29521 + pax_force_retaddr
29522 ret
29523
29524 .section .fixup,"ax"
29525 @@ -276,12 +212,15 @@ ENDPROC(copy_user_generic_string)
29526 */
29527 ENTRY(copy_user_enhanced_fast_string)
29528 CFI_STARTPROC
29529 + ASM_PAX_OPEN_USERLAND
29530 ASM_STAC
29531 movl %edx,%ecx
29532 1: rep
29533 movsb
29534 xorl %eax,%eax
29535 ASM_CLAC
29536 + ASM_PAX_CLOSE_USERLAND
29537 + pax_force_retaddr
29538 ret
29539
29540 .section .fixup,"ax"
29541 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
29542 index 6a4f43c..c70fb52 100644
29543 --- a/arch/x86/lib/copy_user_nocache_64.S
29544 +++ b/arch/x86/lib/copy_user_nocache_64.S
29545 @@ -8,6 +8,7 @@
29546
29547 #include <linux/linkage.h>
29548 #include <asm/dwarf2.h>
29549 +#include <asm/alternative-asm.h>
29550
29551 #define FIX_ALIGNMENT 1
29552
29553 @@ -16,6 +17,7 @@
29554 #include <asm/thread_info.h>
29555 #include <asm/asm.h>
29556 #include <asm/smap.h>
29557 +#include <asm/pgtable.h>
29558
29559 .macro ALIGN_DESTINATION
29560 #ifdef FIX_ALIGNMENT
29561 @@ -49,6 +51,16 @@
29562 */
29563 ENTRY(__copy_user_nocache)
29564 CFI_STARTPROC
29565 +
29566 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29567 + mov pax_user_shadow_base,%rcx
29568 + cmp %rcx,%rsi
29569 + jae 1f
29570 + add %rcx,%rsi
29571 +1:
29572 +#endif
29573 +
29574 + ASM_PAX_OPEN_USERLAND
29575 ASM_STAC
29576 cmpl $8,%edx
29577 jb 20f /* less then 8 bytes, go to byte copy loop */
29578 @@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
29579 jnz 21b
29580 23: xorl %eax,%eax
29581 ASM_CLAC
29582 + ASM_PAX_CLOSE_USERLAND
29583 sfence
29584 + pax_force_retaddr
29585 ret
29586
29587 .section .fixup,"ax"
29588 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
29589 index 2419d5f..fe52d0e 100644
29590 --- a/arch/x86/lib/csum-copy_64.S
29591 +++ b/arch/x86/lib/csum-copy_64.S
29592 @@ -9,6 +9,7 @@
29593 #include <asm/dwarf2.h>
29594 #include <asm/errno.h>
29595 #include <asm/asm.h>
29596 +#include <asm/alternative-asm.h>
29597
29598 /*
29599 * Checksum copy with exception handling.
29600 @@ -56,8 +57,8 @@ ENTRY(csum_partial_copy_generic)
29601 CFI_ADJUST_CFA_OFFSET 7*8
29602 movq %rbx, 2*8(%rsp)
29603 CFI_REL_OFFSET rbx, 2*8
29604 - movq %r12, 3*8(%rsp)
29605 - CFI_REL_OFFSET r12, 3*8
29606 + movq %r15, 3*8(%rsp)
29607 + CFI_REL_OFFSET r15, 3*8
29608 movq %r14, 4*8(%rsp)
29609 CFI_REL_OFFSET r14, 4*8
29610 movq %r13, 5*8(%rsp)
29611 @@ -72,16 +73,16 @@ ENTRY(csum_partial_copy_generic)
29612 movl %edx, %ecx
29613
29614 xorl %r9d, %r9d
29615 - movq %rcx, %r12
29616 + movq %rcx, %r15
29617
29618 - shrq $6, %r12
29619 + shrq $6, %r15
29620 jz .Lhandle_tail /* < 64 */
29621
29622 clc
29623
29624 /* main loop. clear in 64 byte blocks */
29625 /* r9: zero, r8: temp2, rbx: temp1, rax: sum, rcx: saved length */
29626 - /* r11: temp3, rdx: temp4, r12 loopcnt */
29627 + /* r11: temp3, rdx: temp4, r15 loopcnt */
29628 /* r10: temp5, rbp: temp6, r14 temp7, r13 temp8 */
29629 .p2align 4
29630 .Lloop:
29631 @@ -115,7 +116,7 @@ ENTRY(csum_partial_copy_generic)
29632 adcq %r14, %rax
29633 adcq %r13, %rax
29634
29635 - decl %r12d
29636 + decl %r15d
29637
29638 dest
29639 movq %rbx, (%rsi)
29640 @@ -210,8 +211,8 @@ ENTRY(csum_partial_copy_generic)
29641 .Lende:
29642 movq 2*8(%rsp), %rbx
29643 CFI_RESTORE rbx
29644 - movq 3*8(%rsp), %r12
29645 - CFI_RESTORE r12
29646 + movq 3*8(%rsp), %r15
29647 + CFI_RESTORE r15
29648 movq 4*8(%rsp), %r14
29649 CFI_RESTORE r14
29650 movq 5*8(%rsp), %r13
29651 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
29652 CFI_RESTORE rbp
29653 addq $7*8, %rsp
29654 CFI_ADJUST_CFA_OFFSET -7*8
29655 + pax_force_retaddr
29656 ret
29657 CFI_RESTORE_STATE
29658
29659 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
29660 index 7609e0e..b449b98 100644
29661 --- a/arch/x86/lib/csum-wrappers_64.c
29662 +++ b/arch/x86/lib/csum-wrappers_64.c
29663 @@ -53,10 +53,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
29664 len -= 2;
29665 }
29666 }
29667 + pax_open_userland();
29668 stac();
29669 - isum = csum_partial_copy_generic((__force const void *)src,
29670 + isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
29671 dst, len, isum, errp, NULL);
29672 clac();
29673 + pax_close_userland();
29674 if (unlikely(*errp))
29675 goto out_err;
29676
29677 @@ -110,10 +112,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
29678 }
29679
29680 *errp = 0;
29681 + pax_open_userland();
29682 stac();
29683 - ret = csum_partial_copy_generic(src, (void __force *)dst,
29684 + ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
29685 len, isum, NULL, errp);
29686 clac();
29687 + pax_close_userland();
29688 return ret;
29689 }
29690 EXPORT_SYMBOL(csum_partial_copy_to_user);
29691 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
29692 index a451235..1daa956 100644
29693 --- a/arch/x86/lib/getuser.S
29694 +++ b/arch/x86/lib/getuser.S
29695 @@ -33,17 +33,40 @@
29696 #include <asm/thread_info.h>
29697 #include <asm/asm.h>
29698 #include <asm/smap.h>
29699 +#include <asm/segment.h>
29700 +#include <asm/pgtable.h>
29701 +#include <asm/alternative-asm.h>
29702 +
29703 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
29704 +#define __copyuser_seg gs;
29705 +#else
29706 +#define __copyuser_seg
29707 +#endif
29708
29709 .text
29710 ENTRY(__get_user_1)
29711 CFI_STARTPROC
29712 +
29713 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29714 GET_THREAD_INFO(%_ASM_DX)
29715 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29716 jae bad_get_user
29717 ASM_STAC
29718 -1: movzbl (%_ASM_AX),%edx
29719 +
29720 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29721 + mov pax_user_shadow_base,%_ASM_DX
29722 + cmp %_ASM_DX,%_ASM_AX
29723 + jae 1234f
29724 + add %_ASM_DX,%_ASM_AX
29725 +1234:
29726 +#endif
29727 +
29728 +#endif
29729 +
29730 +1: __copyuser_seg movzbl (%_ASM_AX),%edx
29731 xor %eax,%eax
29732 ASM_CLAC
29733 + pax_force_retaddr
29734 ret
29735 CFI_ENDPROC
29736 ENDPROC(__get_user_1)
29737 @@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
29738 ENTRY(__get_user_2)
29739 CFI_STARTPROC
29740 add $1,%_ASM_AX
29741 +
29742 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29743 jc bad_get_user
29744 GET_THREAD_INFO(%_ASM_DX)
29745 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29746 jae bad_get_user
29747 ASM_STAC
29748 -2: movzwl -1(%_ASM_AX),%edx
29749 +
29750 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29751 + mov pax_user_shadow_base,%_ASM_DX
29752 + cmp %_ASM_DX,%_ASM_AX
29753 + jae 1234f
29754 + add %_ASM_DX,%_ASM_AX
29755 +1234:
29756 +#endif
29757 +
29758 +#endif
29759 +
29760 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
29761 xor %eax,%eax
29762 ASM_CLAC
29763 + pax_force_retaddr
29764 ret
29765 CFI_ENDPROC
29766 ENDPROC(__get_user_2)
29767 @@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
29768 ENTRY(__get_user_4)
29769 CFI_STARTPROC
29770 add $3,%_ASM_AX
29771 +
29772 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29773 jc bad_get_user
29774 GET_THREAD_INFO(%_ASM_DX)
29775 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29776 jae bad_get_user
29777 ASM_STAC
29778 -3: movl -3(%_ASM_AX),%edx
29779 +
29780 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29781 + mov pax_user_shadow_base,%_ASM_DX
29782 + cmp %_ASM_DX,%_ASM_AX
29783 + jae 1234f
29784 + add %_ASM_DX,%_ASM_AX
29785 +1234:
29786 +#endif
29787 +
29788 +#endif
29789 +
29790 +3: __copyuser_seg movl -3(%_ASM_AX),%edx
29791 xor %eax,%eax
29792 ASM_CLAC
29793 + pax_force_retaddr
29794 ret
29795 CFI_ENDPROC
29796 ENDPROC(__get_user_4)
29797 @@ -86,10 +137,20 @@ ENTRY(__get_user_8)
29798 GET_THREAD_INFO(%_ASM_DX)
29799 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29800 jae bad_get_user
29801 +
29802 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29803 + mov pax_user_shadow_base,%_ASM_DX
29804 + cmp %_ASM_DX,%_ASM_AX
29805 + jae 1234f
29806 + add %_ASM_DX,%_ASM_AX
29807 +1234:
29808 +#endif
29809 +
29810 ASM_STAC
29811 4: movq -7(%_ASM_AX),%rdx
29812 xor %eax,%eax
29813 ASM_CLAC
29814 + pax_force_retaddr
29815 ret
29816 #else
29817 add $7,%_ASM_AX
29818 @@ -98,10 +159,11 @@ ENTRY(__get_user_8)
29819 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29820 jae bad_get_user_8
29821 ASM_STAC
29822 -4: movl -7(%_ASM_AX),%edx
29823 -5: movl -3(%_ASM_AX),%ecx
29824 +4: __copyuser_seg movl -7(%_ASM_AX),%edx
29825 +5: __copyuser_seg movl -3(%_ASM_AX),%ecx
29826 xor %eax,%eax
29827 ASM_CLAC
29828 + pax_force_retaddr
29829 ret
29830 #endif
29831 CFI_ENDPROC
29832 @@ -113,6 +175,7 @@ bad_get_user:
29833 xor %edx,%edx
29834 mov $(-EFAULT),%_ASM_AX
29835 ASM_CLAC
29836 + pax_force_retaddr
29837 ret
29838 CFI_ENDPROC
29839 END(bad_get_user)
29840 @@ -124,6 +187,7 @@ bad_get_user_8:
29841 xor %ecx,%ecx
29842 mov $(-EFAULT),%_ASM_AX
29843 ASM_CLAC
29844 + pax_force_retaddr
29845 ret
29846 CFI_ENDPROC
29847 END(bad_get_user_8)
29848 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
29849 index 54fcffe..7be149e 100644
29850 --- a/arch/x86/lib/insn.c
29851 +++ b/arch/x86/lib/insn.c
29852 @@ -20,8 +20,10 @@
29853
29854 #ifdef __KERNEL__
29855 #include <linux/string.h>
29856 +#include <asm/pgtable_types.h>
29857 #else
29858 #include <string.h>
29859 +#define ktla_ktva(addr) addr
29860 #endif
29861 #include <asm/inat.h>
29862 #include <asm/insn.h>
29863 @@ -53,8 +55,8 @@
29864 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
29865 {
29866 memset(insn, 0, sizeof(*insn));
29867 - insn->kaddr = kaddr;
29868 - insn->next_byte = kaddr;
29869 + insn->kaddr = ktla_ktva(kaddr);
29870 + insn->next_byte = ktla_ktva(kaddr);
29871 insn->x86_64 = x86_64 ? 1 : 0;
29872 insn->opnd_bytes = 4;
29873 if (x86_64)
29874 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
29875 index 05a95e7..326f2fa 100644
29876 --- a/arch/x86/lib/iomap_copy_64.S
29877 +++ b/arch/x86/lib/iomap_copy_64.S
29878 @@ -17,6 +17,7 @@
29879
29880 #include <linux/linkage.h>
29881 #include <asm/dwarf2.h>
29882 +#include <asm/alternative-asm.h>
29883
29884 /*
29885 * override generic version in lib/iomap_copy.c
29886 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
29887 CFI_STARTPROC
29888 movl %edx,%ecx
29889 rep movsd
29890 + pax_force_retaddr
29891 ret
29892 CFI_ENDPROC
29893 ENDPROC(__iowrite32_copy)
29894 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
29895 index 56313a3..0db417e 100644
29896 --- a/arch/x86/lib/memcpy_64.S
29897 +++ b/arch/x86/lib/memcpy_64.S
29898 @@ -24,7 +24,7 @@
29899 * This gets patched over the unrolled variant (below) via the
29900 * alternative instructions framework:
29901 */
29902 - .section .altinstr_replacement, "ax", @progbits
29903 + .section .altinstr_replacement, "a", @progbits
29904 .Lmemcpy_c:
29905 movq %rdi, %rax
29906 movq %rdx, %rcx
29907 @@ -33,6 +33,7 @@
29908 rep movsq
29909 movl %edx, %ecx
29910 rep movsb
29911 + pax_force_retaddr
29912 ret
29913 .Lmemcpy_e:
29914 .previous
29915 @@ -44,11 +45,12 @@
29916 * This gets patched over the unrolled variant (below) via the
29917 * alternative instructions framework:
29918 */
29919 - .section .altinstr_replacement, "ax", @progbits
29920 + .section .altinstr_replacement, "a", @progbits
29921 .Lmemcpy_c_e:
29922 movq %rdi, %rax
29923 movq %rdx, %rcx
29924 rep movsb
29925 + pax_force_retaddr
29926 ret
29927 .Lmemcpy_e_e:
29928 .previous
29929 @@ -136,6 +138,7 @@ ENTRY(memcpy)
29930 movq %r9, 1*8(%rdi)
29931 movq %r10, -2*8(%rdi, %rdx)
29932 movq %r11, -1*8(%rdi, %rdx)
29933 + pax_force_retaddr
29934 retq
29935 .p2align 4
29936 .Lless_16bytes:
29937 @@ -148,6 +151,7 @@ ENTRY(memcpy)
29938 movq -1*8(%rsi, %rdx), %r9
29939 movq %r8, 0*8(%rdi)
29940 movq %r9, -1*8(%rdi, %rdx)
29941 + pax_force_retaddr
29942 retq
29943 .p2align 4
29944 .Lless_8bytes:
29945 @@ -161,6 +165,7 @@ ENTRY(memcpy)
29946 movl -4(%rsi, %rdx), %r8d
29947 movl %ecx, (%rdi)
29948 movl %r8d, -4(%rdi, %rdx)
29949 + pax_force_retaddr
29950 retq
29951 .p2align 4
29952 .Lless_3bytes:
29953 @@ -179,6 +184,7 @@ ENTRY(memcpy)
29954 movb %cl, (%rdi)
29955
29956 .Lend:
29957 + pax_force_retaddr
29958 retq
29959 CFI_ENDPROC
29960 ENDPROC(memcpy)
29961 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
29962 index 65268a6..dd1de11 100644
29963 --- a/arch/x86/lib/memmove_64.S
29964 +++ b/arch/x86/lib/memmove_64.S
29965 @@ -202,14 +202,16 @@ ENTRY(memmove)
29966 movb (%rsi), %r11b
29967 movb %r11b, (%rdi)
29968 13:
29969 + pax_force_retaddr
29970 retq
29971 CFI_ENDPROC
29972
29973 - .section .altinstr_replacement,"ax"
29974 + .section .altinstr_replacement,"a"
29975 .Lmemmove_begin_forward_efs:
29976 /* Forward moving data. */
29977 movq %rdx, %rcx
29978 rep movsb
29979 + pax_force_retaddr
29980 retq
29981 .Lmemmove_end_forward_efs:
29982 .previous
29983 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
29984 index 2dcb380..2eb79fe 100644
29985 --- a/arch/x86/lib/memset_64.S
29986 +++ b/arch/x86/lib/memset_64.S
29987 @@ -16,7 +16,7 @@
29988 *
29989 * rax original destination
29990 */
29991 - .section .altinstr_replacement, "ax", @progbits
29992 + .section .altinstr_replacement, "a", @progbits
29993 .Lmemset_c:
29994 movq %rdi,%r9
29995 movq %rdx,%rcx
29996 @@ -30,6 +30,7 @@
29997 movl %edx,%ecx
29998 rep stosb
29999 movq %r9,%rax
30000 + pax_force_retaddr
30001 ret
30002 .Lmemset_e:
30003 .previous
30004 @@ -45,13 +46,14 @@
30005 *
30006 * rax original destination
30007 */
30008 - .section .altinstr_replacement, "ax", @progbits
30009 + .section .altinstr_replacement, "a", @progbits
30010 .Lmemset_c_e:
30011 movq %rdi,%r9
30012 movb %sil,%al
30013 movq %rdx,%rcx
30014 rep stosb
30015 movq %r9,%rax
30016 + pax_force_retaddr
30017 ret
30018 .Lmemset_e_e:
30019 .previous
30020 @@ -118,6 +120,7 @@ ENTRY(__memset)
30021
30022 .Lende:
30023 movq %r10,%rax
30024 + pax_force_retaddr
30025 ret
30026
30027 CFI_RESTORE_STATE
30028 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
30029 index c9f2d9b..e7fd2c0 100644
30030 --- a/arch/x86/lib/mmx_32.c
30031 +++ b/arch/x86/lib/mmx_32.c
30032 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
30033 {
30034 void *p;
30035 int i;
30036 + unsigned long cr0;
30037
30038 if (unlikely(in_interrupt()))
30039 return __memcpy(to, from, len);
30040 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
30041 kernel_fpu_begin();
30042
30043 __asm__ __volatile__ (
30044 - "1: prefetch (%0)\n" /* This set is 28 bytes */
30045 - " prefetch 64(%0)\n"
30046 - " prefetch 128(%0)\n"
30047 - " prefetch 192(%0)\n"
30048 - " prefetch 256(%0)\n"
30049 + "1: prefetch (%1)\n" /* This set is 28 bytes */
30050 + " prefetch 64(%1)\n"
30051 + " prefetch 128(%1)\n"
30052 + " prefetch 192(%1)\n"
30053 + " prefetch 256(%1)\n"
30054 "2: \n"
30055 ".section .fixup, \"ax\"\n"
30056 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30057 + "3: \n"
30058 +
30059 +#ifdef CONFIG_PAX_KERNEXEC
30060 + " movl %%cr0, %0\n"
30061 + " movl %0, %%eax\n"
30062 + " andl $0xFFFEFFFF, %%eax\n"
30063 + " movl %%eax, %%cr0\n"
30064 +#endif
30065 +
30066 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30067 +
30068 +#ifdef CONFIG_PAX_KERNEXEC
30069 + " movl %0, %%cr0\n"
30070 +#endif
30071 +
30072 " jmp 2b\n"
30073 ".previous\n"
30074 _ASM_EXTABLE(1b, 3b)
30075 - : : "r" (from));
30076 + : "=&r" (cr0) : "r" (from) : "ax");
30077
30078 for ( ; i > 5; i--) {
30079 __asm__ __volatile__ (
30080 - "1: prefetch 320(%0)\n"
30081 - "2: movq (%0), %%mm0\n"
30082 - " movq 8(%0), %%mm1\n"
30083 - " movq 16(%0), %%mm2\n"
30084 - " movq 24(%0), %%mm3\n"
30085 - " movq %%mm0, (%1)\n"
30086 - " movq %%mm1, 8(%1)\n"
30087 - " movq %%mm2, 16(%1)\n"
30088 - " movq %%mm3, 24(%1)\n"
30089 - " movq 32(%0), %%mm0\n"
30090 - " movq 40(%0), %%mm1\n"
30091 - " movq 48(%0), %%mm2\n"
30092 - " movq 56(%0), %%mm3\n"
30093 - " movq %%mm0, 32(%1)\n"
30094 - " movq %%mm1, 40(%1)\n"
30095 - " movq %%mm2, 48(%1)\n"
30096 - " movq %%mm3, 56(%1)\n"
30097 + "1: prefetch 320(%1)\n"
30098 + "2: movq (%1), %%mm0\n"
30099 + " movq 8(%1), %%mm1\n"
30100 + " movq 16(%1), %%mm2\n"
30101 + " movq 24(%1), %%mm3\n"
30102 + " movq %%mm0, (%2)\n"
30103 + " movq %%mm1, 8(%2)\n"
30104 + " movq %%mm2, 16(%2)\n"
30105 + " movq %%mm3, 24(%2)\n"
30106 + " movq 32(%1), %%mm0\n"
30107 + " movq 40(%1), %%mm1\n"
30108 + " movq 48(%1), %%mm2\n"
30109 + " movq 56(%1), %%mm3\n"
30110 + " movq %%mm0, 32(%2)\n"
30111 + " movq %%mm1, 40(%2)\n"
30112 + " movq %%mm2, 48(%2)\n"
30113 + " movq %%mm3, 56(%2)\n"
30114 ".section .fixup, \"ax\"\n"
30115 - "3: movw $0x05EB, 1b\n" /* jmp on 5 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 $0x05EB, 1b\n" /* jmp on 5 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), "r" (to) : "memory");
30135 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30136
30137 from += 64;
30138 to += 64;
30139 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
30140 static void fast_copy_page(void *to, void *from)
30141 {
30142 int i;
30143 + unsigned long cr0;
30144
30145 kernel_fpu_begin();
30146
30147 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
30148 * but that is for later. -AV
30149 */
30150 __asm__ __volatile__(
30151 - "1: prefetch (%0)\n"
30152 - " prefetch 64(%0)\n"
30153 - " prefetch 128(%0)\n"
30154 - " prefetch 192(%0)\n"
30155 - " prefetch 256(%0)\n"
30156 + "1: prefetch (%1)\n"
30157 + " prefetch 64(%1)\n"
30158 + " prefetch 128(%1)\n"
30159 + " prefetch 192(%1)\n"
30160 + " prefetch 256(%1)\n"
30161 "2: \n"
30162 ".section .fixup, \"ax\"\n"
30163 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30164 + "3: \n"
30165 +
30166 +#ifdef CONFIG_PAX_KERNEXEC
30167 + " movl %%cr0, %0\n"
30168 + " movl %0, %%eax\n"
30169 + " andl $0xFFFEFFFF, %%eax\n"
30170 + " movl %%eax, %%cr0\n"
30171 +#endif
30172 +
30173 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30174 +
30175 +#ifdef CONFIG_PAX_KERNEXEC
30176 + " movl %0, %%cr0\n"
30177 +#endif
30178 +
30179 " jmp 2b\n"
30180 ".previous\n"
30181 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
30182 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30183
30184 for (i = 0; i < (4096-320)/64; i++) {
30185 __asm__ __volatile__ (
30186 - "1: prefetch 320(%0)\n"
30187 - "2: movq (%0), %%mm0\n"
30188 - " movntq %%mm0, (%1)\n"
30189 - " movq 8(%0), %%mm1\n"
30190 - " movntq %%mm1, 8(%1)\n"
30191 - " movq 16(%0), %%mm2\n"
30192 - " movntq %%mm2, 16(%1)\n"
30193 - " movq 24(%0), %%mm3\n"
30194 - " movntq %%mm3, 24(%1)\n"
30195 - " movq 32(%0), %%mm4\n"
30196 - " movntq %%mm4, 32(%1)\n"
30197 - " movq 40(%0), %%mm5\n"
30198 - " movntq %%mm5, 40(%1)\n"
30199 - " movq 48(%0), %%mm6\n"
30200 - " movntq %%mm6, 48(%1)\n"
30201 - " movq 56(%0), %%mm7\n"
30202 - " movntq %%mm7, 56(%1)\n"
30203 + "1: prefetch 320(%1)\n"
30204 + "2: movq (%1), %%mm0\n"
30205 + " movntq %%mm0, (%2)\n"
30206 + " movq 8(%1), %%mm1\n"
30207 + " movntq %%mm1, 8(%2)\n"
30208 + " movq 16(%1), %%mm2\n"
30209 + " movntq %%mm2, 16(%2)\n"
30210 + " movq 24(%1), %%mm3\n"
30211 + " movntq %%mm3, 24(%2)\n"
30212 + " movq 32(%1), %%mm4\n"
30213 + " movntq %%mm4, 32(%2)\n"
30214 + " movq 40(%1), %%mm5\n"
30215 + " movntq %%mm5, 40(%2)\n"
30216 + " movq 48(%1), %%mm6\n"
30217 + " movntq %%mm6, 48(%2)\n"
30218 + " movq 56(%1), %%mm7\n"
30219 + " movntq %%mm7, 56(%2)\n"
30220 ".section .fixup, \"ax\"\n"
30221 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30222 + "3:\n"
30223 +
30224 +#ifdef CONFIG_PAX_KERNEXEC
30225 + " movl %%cr0, %0\n"
30226 + " movl %0, %%eax\n"
30227 + " andl $0xFFFEFFFF, %%eax\n"
30228 + " movl %%eax, %%cr0\n"
30229 +#endif
30230 +
30231 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30232 +
30233 +#ifdef CONFIG_PAX_KERNEXEC
30234 + " movl %0, %%cr0\n"
30235 +#endif
30236 +
30237 " jmp 2b\n"
30238 ".previous\n"
30239 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
30240 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30241
30242 from += 64;
30243 to += 64;
30244 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
30245 static void fast_copy_page(void *to, void *from)
30246 {
30247 int i;
30248 + unsigned long cr0;
30249
30250 kernel_fpu_begin();
30251
30252 __asm__ __volatile__ (
30253 - "1: prefetch (%0)\n"
30254 - " prefetch 64(%0)\n"
30255 - " prefetch 128(%0)\n"
30256 - " prefetch 192(%0)\n"
30257 - " prefetch 256(%0)\n"
30258 + "1: prefetch (%1)\n"
30259 + " prefetch 64(%1)\n"
30260 + " prefetch 128(%1)\n"
30261 + " prefetch 192(%1)\n"
30262 + " prefetch 256(%1)\n"
30263 "2: \n"
30264 ".section .fixup, \"ax\"\n"
30265 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30266 + "3: \n"
30267 +
30268 +#ifdef CONFIG_PAX_KERNEXEC
30269 + " movl %%cr0, %0\n"
30270 + " movl %0, %%eax\n"
30271 + " andl $0xFFFEFFFF, %%eax\n"
30272 + " movl %%eax, %%cr0\n"
30273 +#endif
30274 +
30275 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
30276 +
30277 +#ifdef CONFIG_PAX_KERNEXEC
30278 + " movl %0, %%cr0\n"
30279 +#endif
30280 +
30281 " jmp 2b\n"
30282 ".previous\n"
30283 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
30284 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
30285
30286 for (i = 0; i < 4096/64; i++) {
30287 __asm__ __volatile__ (
30288 - "1: prefetch 320(%0)\n"
30289 - "2: movq (%0), %%mm0\n"
30290 - " movq 8(%0), %%mm1\n"
30291 - " movq 16(%0), %%mm2\n"
30292 - " movq 24(%0), %%mm3\n"
30293 - " movq %%mm0, (%1)\n"
30294 - " movq %%mm1, 8(%1)\n"
30295 - " movq %%mm2, 16(%1)\n"
30296 - " movq %%mm3, 24(%1)\n"
30297 - " movq 32(%0), %%mm0\n"
30298 - " movq 40(%0), %%mm1\n"
30299 - " movq 48(%0), %%mm2\n"
30300 - " movq 56(%0), %%mm3\n"
30301 - " movq %%mm0, 32(%1)\n"
30302 - " movq %%mm1, 40(%1)\n"
30303 - " movq %%mm2, 48(%1)\n"
30304 - " movq %%mm3, 56(%1)\n"
30305 + "1: prefetch 320(%1)\n"
30306 + "2: movq (%1), %%mm0\n"
30307 + " movq 8(%1), %%mm1\n"
30308 + " movq 16(%1), %%mm2\n"
30309 + " movq 24(%1), %%mm3\n"
30310 + " movq %%mm0, (%2)\n"
30311 + " movq %%mm1, 8(%2)\n"
30312 + " movq %%mm2, 16(%2)\n"
30313 + " movq %%mm3, 24(%2)\n"
30314 + " movq 32(%1), %%mm0\n"
30315 + " movq 40(%1), %%mm1\n"
30316 + " movq 48(%1), %%mm2\n"
30317 + " movq 56(%1), %%mm3\n"
30318 + " movq %%mm0, 32(%2)\n"
30319 + " movq %%mm1, 40(%2)\n"
30320 + " movq %%mm2, 48(%2)\n"
30321 + " movq %%mm3, 56(%2)\n"
30322 ".section .fixup, \"ax\"\n"
30323 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30324 + "3:\n"
30325 +
30326 +#ifdef CONFIG_PAX_KERNEXEC
30327 + " movl %%cr0, %0\n"
30328 + " movl %0, %%eax\n"
30329 + " andl $0xFFFEFFFF, %%eax\n"
30330 + " movl %%eax, %%cr0\n"
30331 +#endif
30332 +
30333 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
30334 +
30335 +#ifdef CONFIG_PAX_KERNEXEC
30336 + " movl %0, %%cr0\n"
30337 +#endif
30338 +
30339 " jmp 2b\n"
30340 ".previous\n"
30341 _ASM_EXTABLE(1b, 3b)
30342 - : : "r" (from), "r" (to) : "memory");
30343 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
30344
30345 from += 64;
30346 to += 64;
30347 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
30348 index f6d13ee..d789440 100644
30349 --- a/arch/x86/lib/msr-reg.S
30350 +++ b/arch/x86/lib/msr-reg.S
30351 @@ -3,6 +3,7 @@
30352 #include <asm/dwarf2.h>
30353 #include <asm/asm.h>
30354 #include <asm/msr.h>
30355 +#include <asm/alternative-asm.h>
30356
30357 #ifdef CONFIG_X86_64
30358 /*
30359 @@ -37,6 +38,7 @@ ENTRY(\op\()_safe_regs)
30360 movl %edi, 28(%r10)
30361 popq_cfi %rbp
30362 popq_cfi %rbx
30363 + pax_force_retaddr
30364 ret
30365 3:
30366 CFI_RESTORE_STATE
30367 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
30368 index fc6ba17..d4d989d 100644
30369 --- a/arch/x86/lib/putuser.S
30370 +++ b/arch/x86/lib/putuser.S
30371 @@ -16,7 +16,9 @@
30372 #include <asm/errno.h>
30373 #include <asm/asm.h>
30374 #include <asm/smap.h>
30375 -
30376 +#include <asm/segment.h>
30377 +#include <asm/pgtable.h>
30378 +#include <asm/alternative-asm.h>
30379
30380 /*
30381 * __put_user_X
30382 @@ -30,57 +32,125 @@
30383 * as they get called from within inline assembly.
30384 */
30385
30386 -#define ENTER CFI_STARTPROC ; \
30387 - GET_THREAD_INFO(%_ASM_BX)
30388 -#define EXIT ASM_CLAC ; \
30389 - ret ; \
30390 +#define ENTER CFI_STARTPROC
30391 +#define EXIT ASM_CLAC ; \
30392 + pax_force_retaddr ; \
30393 + ret ; \
30394 CFI_ENDPROC
30395
30396 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30397 +#define _DEST %_ASM_CX,%_ASM_BX
30398 +#else
30399 +#define _DEST %_ASM_CX
30400 +#endif
30401 +
30402 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
30403 +#define __copyuser_seg gs;
30404 +#else
30405 +#define __copyuser_seg
30406 +#endif
30407 +
30408 .text
30409 ENTRY(__put_user_1)
30410 ENTER
30411 +
30412 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30413 + GET_THREAD_INFO(%_ASM_BX)
30414 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
30415 jae bad_put_user
30416 ASM_STAC
30417 -1: movb %al,(%_ASM_CX)
30418 +
30419 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30420 + mov pax_user_shadow_base,%_ASM_BX
30421 + cmp %_ASM_BX,%_ASM_CX
30422 + jb 1234f
30423 + xor %ebx,%ebx
30424 +1234:
30425 +#endif
30426 +
30427 +#endif
30428 +
30429 +1: __copyuser_seg movb %al,(_DEST)
30430 xor %eax,%eax
30431 EXIT
30432 ENDPROC(__put_user_1)
30433
30434 ENTRY(__put_user_2)
30435 ENTER
30436 +
30437 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30438 + GET_THREAD_INFO(%_ASM_BX)
30439 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30440 sub $1,%_ASM_BX
30441 cmp %_ASM_BX,%_ASM_CX
30442 jae bad_put_user
30443 ASM_STAC
30444 -2: movw %ax,(%_ASM_CX)
30445 +
30446 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30447 + mov pax_user_shadow_base,%_ASM_BX
30448 + cmp %_ASM_BX,%_ASM_CX
30449 + jb 1234f
30450 + xor %ebx,%ebx
30451 +1234:
30452 +#endif
30453 +
30454 +#endif
30455 +
30456 +2: __copyuser_seg movw %ax,(_DEST)
30457 xor %eax,%eax
30458 EXIT
30459 ENDPROC(__put_user_2)
30460
30461 ENTRY(__put_user_4)
30462 ENTER
30463 +
30464 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30465 + GET_THREAD_INFO(%_ASM_BX)
30466 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30467 sub $3,%_ASM_BX
30468 cmp %_ASM_BX,%_ASM_CX
30469 jae bad_put_user
30470 ASM_STAC
30471 -3: movl %eax,(%_ASM_CX)
30472 +
30473 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30474 + mov pax_user_shadow_base,%_ASM_BX
30475 + cmp %_ASM_BX,%_ASM_CX
30476 + jb 1234f
30477 + xor %ebx,%ebx
30478 +1234:
30479 +#endif
30480 +
30481 +#endif
30482 +
30483 +3: __copyuser_seg movl %eax,(_DEST)
30484 xor %eax,%eax
30485 EXIT
30486 ENDPROC(__put_user_4)
30487
30488 ENTRY(__put_user_8)
30489 ENTER
30490 +
30491 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
30492 + GET_THREAD_INFO(%_ASM_BX)
30493 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
30494 sub $7,%_ASM_BX
30495 cmp %_ASM_BX,%_ASM_CX
30496 jae bad_put_user
30497 ASM_STAC
30498 -4: mov %_ASM_AX,(%_ASM_CX)
30499 +
30500 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30501 + mov pax_user_shadow_base,%_ASM_BX
30502 + cmp %_ASM_BX,%_ASM_CX
30503 + jb 1234f
30504 + xor %ebx,%ebx
30505 +1234:
30506 +#endif
30507 +
30508 +#endif
30509 +
30510 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
30511 #ifdef CONFIG_X86_32
30512 -5: movl %edx,4(%_ASM_CX)
30513 +5: __copyuser_seg movl %edx,4(_DEST)
30514 #endif
30515 xor %eax,%eax
30516 EXIT
30517 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
30518 index 1cad221..de671ee 100644
30519 --- a/arch/x86/lib/rwlock.S
30520 +++ b/arch/x86/lib/rwlock.S
30521 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
30522 FRAME
30523 0: LOCK_PREFIX
30524 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
30525 +
30526 +#ifdef CONFIG_PAX_REFCOUNT
30527 + jno 1234f
30528 + LOCK_PREFIX
30529 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
30530 + int $4
30531 +1234:
30532 + _ASM_EXTABLE(1234b, 1234b)
30533 +#endif
30534 +
30535 1: rep; nop
30536 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
30537 jne 1b
30538 LOCK_PREFIX
30539 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
30540 +
30541 +#ifdef CONFIG_PAX_REFCOUNT
30542 + jno 1234f
30543 + LOCK_PREFIX
30544 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
30545 + int $4
30546 +1234:
30547 + _ASM_EXTABLE(1234b, 1234b)
30548 +#endif
30549 +
30550 jnz 0b
30551 ENDFRAME
30552 + pax_force_retaddr
30553 ret
30554 CFI_ENDPROC
30555 END(__write_lock_failed)
30556 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
30557 FRAME
30558 0: LOCK_PREFIX
30559 READ_LOCK_SIZE(inc) (%__lock_ptr)
30560 +
30561 +#ifdef CONFIG_PAX_REFCOUNT
30562 + jno 1234f
30563 + LOCK_PREFIX
30564 + READ_LOCK_SIZE(dec) (%__lock_ptr)
30565 + int $4
30566 +1234:
30567 + _ASM_EXTABLE(1234b, 1234b)
30568 +#endif
30569 +
30570 1: rep; nop
30571 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
30572 js 1b
30573 LOCK_PREFIX
30574 READ_LOCK_SIZE(dec) (%__lock_ptr)
30575 +
30576 +#ifdef CONFIG_PAX_REFCOUNT
30577 + jno 1234f
30578 + LOCK_PREFIX
30579 + READ_LOCK_SIZE(inc) (%__lock_ptr)
30580 + int $4
30581 +1234:
30582 + _ASM_EXTABLE(1234b, 1234b)
30583 +#endif
30584 +
30585 js 0b
30586 ENDFRAME
30587 + pax_force_retaddr
30588 ret
30589 CFI_ENDPROC
30590 END(__read_lock_failed)
30591 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
30592 index 5dff5f0..cadebf4 100644
30593 --- a/arch/x86/lib/rwsem.S
30594 +++ b/arch/x86/lib/rwsem.S
30595 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
30596 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30597 CFI_RESTORE __ASM_REG(dx)
30598 restore_common_regs
30599 + pax_force_retaddr
30600 ret
30601 CFI_ENDPROC
30602 ENDPROC(call_rwsem_down_read_failed)
30603 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
30604 movq %rax,%rdi
30605 call rwsem_down_write_failed
30606 restore_common_regs
30607 + pax_force_retaddr
30608 ret
30609 CFI_ENDPROC
30610 ENDPROC(call_rwsem_down_write_failed)
30611 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
30612 movq %rax,%rdi
30613 call rwsem_wake
30614 restore_common_regs
30615 -1: ret
30616 +1: pax_force_retaddr
30617 + ret
30618 CFI_ENDPROC
30619 ENDPROC(call_rwsem_wake)
30620
30621 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
30622 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
30623 CFI_RESTORE __ASM_REG(dx)
30624 restore_common_regs
30625 + pax_force_retaddr
30626 ret
30627 CFI_ENDPROC
30628 ENDPROC(call_rwsem_downgrade_wake)
30629 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
30630 index a63efd6..8149fbe 100644
30631 --- a/arch/x86/lib/thunk_64.S
30632 +++ b/arch/x86/lib/thunk_64.S
30633 @@ -8,6 +8,7 @@
30634 #include <linux/linkage.h>
30635 #include <asm/dwarf2.h>
30636 #include <asm/calling.h>
30637 +#include <asm/alternative-asm.h>
30638
30639 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
30640 .macro THUNK name, func, put_ret_addr_in_rdi=0
30641 @@ -15,11 +16,11 @@
30642 \name:
30643 CFI_STARTPROC
30644
30645 - /* this one pushes 9 elems, the next one would be %rIP */
30646 - SAVE_ARGS
30647 + /* this one pushes 15+1 elems, the next one would be %rIP */
30648 + SAVE_ARGS 8
30649
30650 .if \put_ret_addr_in_rdi
30651 - movq_cfi_restore 9*8, rdi
30652 + movq_cfi_restore RIP, rdi
30653 .endif
30654
30655 call \func
30656 @@ -38,8 +39,9 @@
30657
30658 /* SAVE_ARGS below is used only for the .cfi directives it contains. */
30659 CFI_STARTPROC
30660 - SAVE_ARGS
30661 + SAVE_ARGS 8
30662 restore:
30663 - RESTORE_ARGS
30664 + RESTORE_ARGS 1,8
30665 + pax_force_retaddr
30666 ret
30667 CFI_ENDPROC
30668 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
30669 index e2f5e21..4b22130 100644
30670 --- a/arch/x86/lib/usercopy_32.c
30671 +++ b/arch/x86/lib/usercopy_32.c
30672 @@ -42,11 +42,13 @@ do { \
30673 int __d0; \
30674 might_fault(); \
30675 __asm__ __volatile__( \
30676 + __COPYUSER_SET_ES \
30677 ASM_STAC "\n" \
30678 "0: rep; stosl\n" \
30679 " movl %2,%0\n" \
30680 "1: rep; stosb\n" \
30681 "2: " ASM_CLAC "\n" \
30682 + __COPYUSER_RESTORE_ES \
30683 ".section .fixup,\"ax\"\n" \
30684 "3: lea 0(%2,%0,4),%0\n" \
30685 " jmp 2b\n" \
30686 @@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
30687
30688 #ifdef CONFIG_X86_INTEL_USERCOPY
30689 static unsigned long
30690 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
30691 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
30692 {
30693 int d0, d1;
30694 __asm__ __volatile__(
30695 @@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
30696 " .align 2,0x90\n"
30697 "3: movl 0(%4), %%eax\n"
30698 "4: movl 4(%4), %%edx\n"
30699 - "5: movl %%eax, 0(%3)\n"
30700 - "6: movl %%edx, 4(%3)\n"
30701 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
30702 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
30703 "7: movl 8(%4), %%eax\n"
30704 "8: movl 12(%4),%%edx\n"
30705 - "9: movl %%eax, 8(%3)\n"
30706 - "10: movl %%edx, 12(%3)\n"
30707 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
30708 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
30709 "11: movl 16(%4), %%eax\n"
30710 "12: movl 20(%4), %%edx\n"
30711 - "13: movl %%eax, 16(%3)\n"
30712 - "14: movl %%edx, 20(%3)\n"
30713 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
30714 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
30715 "15: movl 24(%4), %%eax\n"
30716 "16: movl 28(%4), %%edx\n"
30717 - "17: movl %%eax, 24(%3)\n"
30718 - "18: movl %%edx, 28(%3)\n"
30719 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
30720 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
30721 "19: movl 32(%4), %%eax\n"
30722 "20: movl 36(%4), %%edx\n"
30723 - "21: movl %%eax, 32(%3)\n"
30724 - "22: movl %%edx, 36(%3)\n"
30725 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
30726 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
30727 "23: movl 40(%4), %%eax\n"
30728 "24: movl 44(%4), %%edx\n"
30729 - "25: movl %%eax, 40(%3)\n"
30730 - "26: movl %%edx, 44(%3)\n"
30731 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
30732 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
30733 "27: movl 48(%4), %%eax\n"
30734 "28: movl 52(%4), %%edx\n"
30735 - "29: movl %%eax, 48(%3)\n"
30736 - "30: movl %%edx, 52(%3)\n"
30737 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
30738 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
30739 "31: movl 56(%4), %%eax\n"
30740 "32: movl 60(%4), %%edx\n"
30741 - "33: movl %%eax, 56(%3)\n"
30742 - "34: movl %%edx, 60(%3)\n"
30743 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
30744 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
30745 " addl $-64, %0\n"
30746 " addl $64, %4\n"
30747 " addl $64, %3\n"
30748 @@ -149,10 +151,116 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
30749 " shrl $2, %0\n"
30750 " andl $3, %%eax\n"
30751 " cld\n"
30752 + __COPYUSER_SET_ES
30753 "99: rep; movsl\n"
30754 "36: movl %%eax, %0\n"
30755 "37: rep; movsb\n"
30756 "100:\n"
30757 + __COPYUSER_RESTORE_ES
30758 + ".section .fixup,\"ax\"\n"
30759 + "101: lea 0(%%eax,%0,4),%0\n"
30760 + " jmp 100b\n"
30761 + ".previous\n"
30762 + _ASM_EXTABLE(1b,100b)
30763 + _ASM_EXTABLE(2b,100b)
30764 + _ASM_EXTABLE(3b,100b)
30765 + _ASM_EXTABLE(4b,100b)
30766 + _ASM_EXTABLE(5b,100b)
30767 + _ASM_EXTABLE(6b,100b)
30768 + _ASM_EXTABLE(7b,100b)
30769 + _ASM_EXTABLE(8b,100b)
30770 + _ASM_EXTABLE(9b,100b)
30771 + _ASM_EXTABLE(10b,100b)
30772 + _ASM_EXTABLE(11b,100b)
30773 + _ASM_EXTABLE(12b,100b)
30774 + _ASM_EXTABLE(13b,100b)
30775 + _ASM_EXTABLE(14b,100b)
30776 + _ASM_EXTABLE(15b,100b)
30777 + _ASM_EXTABLE(16b,100b)
30778 + _ASM_EXTABLE(17b,100b)
30779 + _ASM_EXTABLE(18b,100b)
30780 + _ASM_EXTABLE(19b,100b)
30781 + _ASM_EXTABLE(20b,100b)
30782 + _ASM_EXTABLE(21b,100b)
30783 + _ASM_EXTABLE(22b,100b)
30784 + _ASM_EXTABLE(23b,100b)
30785 + _ASM_EXTABLE(24b,100b)
30786 + _ASM_EXTABLE(25b,100b)
30787 + _ASM_EXTABLE(26b,100b)
30788 + _ASM_EXTABLE(27b,100b)
30789 + _ASM_EXTABLE(28b,100b)
30790 + _ASM_EXTABLE(29b,100b)
30791 + _ASM_EXTABLE(30b,100b)
30792 + _ASM_EXTABLE(31b,100b)
30793 + _ASM_EXTABLE(32b,100b)
30794 + _ASM_EXTABLE(33b,100b)
30795 + _ASM_EXTABLE(34b,100b)
30796 + _ASM_EXTABLE(35b,100b)
30797 + _ASM_EXTABLE(36b,100b)
30798 + _ASM_EXTABLE(37b,100b)
30799 + _ASM_EXTABLE(99b,101b)
30800 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
30801 + : "1"(to), "2"(from), "0"(size)
30802 + : "eax", "edx", "memory");
30803 + return size;
30804 +}
30805 +
30806 +static unsigned long
30807 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
30808 +{
30809 + int d0, d1;
30810 + __asm__ __volatile__(
30811 + " .align 2,0x90\n"
30812 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
30813 + " cmpl $67, %0\n"
30814 + " jbe 3f\n"
30815 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
30816 + " .align 2,0x90\n"
30817 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
30818 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
30819 + "5: movl %%eax, 0(%3)\n"
30820 + "6: movl %%edx, 4(%3)\n"
30821 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
30822 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
30823 + "9: movl %%eax, 8(%3)\n"
30824 + "10: movl %%edx, 12(%3)\n"
30825 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
30826 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
30827 + "13: movl %%eax, 16(%3)\n"
30828 + "14: movl %%edx, 20(%3)\n"
30829 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
30830 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
30831 + "17: movl %%eax, 24(%3)\n"
30832 + "18: movl %%edx, 28(%3)\n"
30833 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
30834 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
30835 + "21: movl %%eax, 32(%3)\n"
30836 + "22: movl %%edx, 36(%3)\n"
30837 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
30838 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
30839 + "25: movl %%eax, 40(%3)\n"
30840 + "26: movl %%edx, 44(%3)\n"
30841 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
30842 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
30843 + "29: movl %%eax, 48(%3)\n"
30844 + "30: movl %%edx, 52(%3)\n"
30845 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
30846 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
30847 + "33: movl %%eax, 56(%3)\n"
30848 + "34: movl %%edx, 60(%3)\n"
30849 + " addl $-64, %0\n"
30850 + " addl $64, %4\n"
30851 + " addl $64, %3\n"
30852 + " cmpl $63, %0\n"
30853 + " ja 1b\n"
30854 + "35: movl %0, %%eax\n"
30855 + " shrl $2, %0\n"
30856 + " andl $3, %%eax\n"
30857 + " cld\n"
30858 + "99: rep; "__copyuser_seg" movsl\n"
30859 + "36: movl %%eax, %0\n"
30860 + "37: rep; "__copyuser_seg" movsb\n"
30861 + "100:\n"
30862 ".section .fixup,\"ax\"\n"
30863 "101: lea 0(%%eax,%0,4),%0\n"
30864 " jmp 100b\n"
30865 @@ -207,41 +315,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
30866 int d0, d1;
30867 __asm__ __volatile__(
30868 " .align 2,0x90\n"
30869 - "0: movl 32(%4), %%eax\n"
30870 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30871 " cmpl $67, %0\n"
30872 " jbe 2f\n"
30873 - "1: movl 64(%4), %%eax\n"
30874 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30875 " .align 2,0x90\n"
30876 - "2: movl 0(%4), %%eax\n"
30877 - "21: movl 4(%4), %%edx\n"
30878 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30879 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30880 " movl %%eax, 0(%3)\n"
30881 " movl %%edx, 4(%3)\n"
30882 - "3: movl 8(%4), %%eax\n"
30883 - "31: movl 12(%4),%%edx\n"
30884 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30885 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30886 " movl %%eax, 8(%3)\n"
30887 " movl %%edx, 12(%3)\n"
30888 - "4: movl 16(%4), %%eax\n"
30889 - "41: movl 20(%4), %%edx\n"
30890 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30891 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30892 " movl %%eax, 16(%3)\n"
30893 " movl %%edx, 20(%3)\n"
30894 - "10: movl 24(%4), %%eax\n"
30895 - "51: movl 28(%4), %%edx\n"
30896 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30897 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30898 " movl %%eax, 24(%3)\n"
30899 " movl %%edx, 28(%3)\n"
30900 - "11: movl 32(%4), %%eax\n"
30901 - "61: movl 36(%4), %%edx\n"
30902 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30903 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30904 " movl %%eax, 32(%3)\n"
30905 " movl %%edx, 36(%3)\n"
30906 - "12: movl 40(%4), %%eax\n"
30907 - "71: movl 44(%4), %%edx\n"
30908 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30909 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30910 " movl %%eax, 40(%3)\n"
30911 " movl %%edx, 44(%3)\n"
30912 - "13: movl 48(%4), %%eax\n"
30913 - "81: movl 52(%4), %%edx\n"
30914 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30915 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30916 " movl %%eax, 48(%3)\n"
30917 " movl %%edx, 52(%3)\n"
30918 - "14: movl 56(%4), %%eax\n"
30919 - "91: movl 60(%4), %%edx\n"
30920 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30921 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30922 " movl %%eax, 56(%3)\n"
30923 " movl %%edx, 60(%3)\n"
30924 " addl $-64, %0\n"
30925 @@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
30926 " shrl $2, %0\n"
30927 " andl $3, %%eax\n"
30928 " cld\n"
30929 - "6: rep; movsl\n"
30930 + "6: rep; "__copyuser_seg" movsl\n"
30931 " movl %%eax,%0\n"
30932 - "7: rep; movsb\n"
30933 + "7: rep; "__copyuser_seg" movsb\n"
30934 "8:\n"
30935 ".section .fixup,\"ax\"\n"
30936 "9: lea 0(%%eax,%0,4),%0\n"
30937 @@ -305,41 +413,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
30938
30939 __asm__ __volatile__(
30940 " .align 2,0x90\n"
30941 - "0: movl 32(%4), %%eax\n"
30942 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30943 " cmpl $67, %0\n"
30944 " jbe 2f\n"
30945 - "1: movl 64(%4), %%eax\n"
30946 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30947 " .align 2,0x90\n"
30948 - "2: movl 0(%4), %%eax\n"
30949 - "21: movl 4(%4), %%edx\n"
30950 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30951 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30952 " movnti %%eax, 0(%3)\n"
30953 " movnti %%edx, 4(%3)\n"
30954 - "3: movl 8(%4), %%eax\n"
30955 - "31: movl 12(%4),%%edx\n"
30956 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30957 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30958 " movnti %%eax, 8(%3)\n"
30959 " movnti %%edx, 12(%3)\n"
30960 - "4: movl 16(%4), %%eax\n"
30961 - "41: movl 20(%4), %%edx\n"
30962 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30963 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30964 " movnti %%eax, 16(%3)\n"
30965 " movnti %%edx, 20(%3)\n"
30966 - "10: movl 24(%4), %%eax\n"
30967 - "51: movl 28(%4), %%edx\n"
30968 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30969 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30970 " movnti %%eax, 24(%3)\n"
30971 " movnti %%edx, 28(%3)\n"
30972 - "11: movl 32(%4), %%eax\n"
30973 - "61: movl 36(%4), %%edx\n"
30974 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30975 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30976 " movnti %%eax, 32(%3)\n"
30977 " movnti %%edx, 36(%3)\n"
30978 - "12: movl 40(%4), %%eax\n"
30979 - "71: movl 44(%4), %%edx\n"
30980 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30981 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30982 " movnti %%eax, 40(%3)\n"
30983 " movnti %%edx, 44(%3)\n"
30984 - "13: movl 48(%4), %%eax\n"
30985 - "81: movl 52(%4), %%edx\n"
30986 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30987 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30988 " movnti %%eax, 48(%3)\n"
30989 " movnti %%edx, 52(%3)\n"
30990 - "14: movl 56(%4), %%eax\n"
30991 - "91: movl 60(%4), %%edx\n"
30992 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30993 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30994 " movnti %%eax, 56(%3)\n"
30995 " movnti %%edx, 60(%3)\n"
30996 " addl $-64, %0\n"
30997 @@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
30998 " shrl $2, %0\n"
30999 " andl $3, %%eax\n"
31000 " cld\n"
31001 - "6: rep; movsl\n"
31002 + "6: rep; "__copyuser_seg" movsl\n"
31003 " movl %%eax,%0\n"
31004 - "7: rep; movsb\n"
31005 + "7: rep; "__copyuser_seg" movsb\n"
31006 "8:\n"
31007 ".section .fixup,\"ax\"\n"
31008 "9: lea 0(%%eax,%0,4),%0\n"
31009 @@ -399,41 +507,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
31010
31011 __asm__ __volatile__(
31012 " .align 2,0x90\n"
31013 - "0: movl 32(%4), %%eax\n"
31014 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
31015 " cmpl $67, %0\n"
31016 " jbe 2f\n"
31017 - "1: movl 64(%4), %%eax\n"
31018 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
31019 " .align 2,0x90\n"
31020 - "2: movl 0(%4), %%eax\n"
31021 - "21: movl 4(%4), %%edx\n"
31022 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
31023 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
31024 " movnti %%eax, 0(%3)\n"
31025 " movnti %%edx, 4(%3)\n"
31026 - "3: movl 8(%4), %%eax\n"
31027 - "31: movl 12(%4),%%edx\n"
31028 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
31029 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
31030 " movnti %%eax, 8(%3)\n"
31031 " movnti %%edx, 12(%3)\n"
31032 - "4: movl 16(%4), %%eax\n"
31033 - "41: movl 20(%4), %%edx\n"
31034 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
31035 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
31036 " movnti %%eax, 16(%3)\n"
31037 " movnti %%edx, 20(%3)\n"
31038 - "10: movl 24(%4), %%eax\n"
31039 - "51: movl 28(%4), %%edx\n"
31040 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
31041 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
31042 " movnti %%eax, 24(%3)\n"
31043 " movnti %%edx, 28(%3)\n"
31044 - "11: movl 32(%4), %%eax\n"
31045 - "61: movl 36(%4), %%edx\n"
31046 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
31047 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
31048 " movnti %%eax, 32(%3)\n"
31049 " movnti %%edx, 36(%3)\n"
31050 - "12: movl 40(%4), %%eax\n"
31051 - "71: movl 44(%4), %%edx\n"
31052 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
31053 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
31054 " movnti %%eax, 40(%3)\n"
31055 " movnti %%edx, 44(%3)\n"
31056 - "13: movl 48(%4), %%eax\n"
31057 - "81: movl 52(%4), %%edx\n"
31058 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
31059 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
31060 " movnti %%eax, 48(%3)\n"
31061 " movnti %%edx, 52(%3)\n"
31062 - "14: movl 56(%4), %%eax\n"
31063 - "91: movl 60(%4), %%edx\n"
31064 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
31065 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
31066 " movnti %%eax, 56(%3)\n"
31067 " movnti %%edx, 60(%3)\n"
31068 " addl $-64, %0\n"
31069 @@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
31070 " shrl $2, %0\n"
31071 " andl $3, %%eax\n"
31072 " cld\n"
31073 - "6: rep; movsl\n"
31074 + "6: rep; "__copyuser_seg" movsl\n"
31075 " movl %%eax,%0\n"
31076 - "7: rep; movsb\n"
31077 + "7: rep; "__copyuser_seg" movsb\n"
31078 "8:\n"
31079 ".section .fixup,\"ax\"\n"
31080 "9: lea 0(%%eax,%0,4),%0\n"
31081 @@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
31082 */
31083 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
31084 unsigned long size);
31085 -unsigned long __copy_user_intel(void __user *to, const void *from,
31086 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
31087 + unsigned long size);
31088 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
31089 unsigned long size);
31090 unsigned long __copy_user_zeroing_intel_nocache(void *to,
31091 const void __user *from, unsigned long size);
31092 #endif /* CONFIG_X86_INTEL_USERCOPY */
31093
31094 /* Generic arbitrary sized copy. */
31095 -#define __copy_user(to, from, size) \
31096 +#define __copy_user(to, from, size, prefix, set, restore) \
31097 do { \
31098 int __d0, __d1, __d2; \
31099 __asm__ __volatile__( \
31100 + set \
31101 " cmp $7,%0\n" \
31102 " jbe 1f\n" \
31103 " movl %1,%0\n" \
31104 " negl %0\n" \
31105 " andl $7,%0\n" \
31106 " subl %0,%3\n" \
31107 - "4: rep; movsb\n" \
31108 + "4: rep; "prefix"movsb\n" \
31109 " movl %3,%0\n" \
31110 " shrl $2,%0\n" \
31111 " andl $3,%3\n" \
31112 " .align 2,0x90\n" \
31113 - "0: rep; movsl\n" \
31114 + "0: rep; "prefix"movsl\n" \
31115 " movl %3,%0\n" \
31116 - "1: rep; movsb\n" \
31117 + "1: rep; "prefix"movsb\n" \
31118 "2:\n" \
31119 + restore \
31120 ".section .fixup,\"ax\"\n" \
31121 "5: addl %3,%0\n" \
31122 " jmp 2b\n" \
31123 @@ -538,14 +650,14 @@ do { \
31124 " negl %0\n" \
31125 " andl $7,%0\n" \
31126 " subl %0,%3\n" \
31127 - "4: rep; movsb\n" \
31128 + "4: rep; "__copyuser_seg"movsb\n" \
31129 " movl %3,%0\n" \
31130 " shrl $2,%0\n" \
31131 " andl $3,%3\n" \
31132 " .align 2,0x90\n" \
31133 - "0: rep; movsl\n" \
31134 + "0: rep; "__copyuser_seg"movsl\n" \
31135 " movl %3,%0\n" \
31136 - "1: rep; movsb\n" \
31137 + "1: rep; "__copyuser_seg"movsb\n" \
31138 "2:\n" \
31139 ".section .fixup,\"ax\"\n" \
31140 "5: addl %3,%0\n" \
31141 @@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
31142 {
31143 stac();
31144 if (movsl_is_ok(to, from, n))
31145 - __copy_user(to, from, n);
31146 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
31147 else
31148 - n = __copy_user_intel(to, from, n);
31149 + n = __generic_copy_to_user_intel(to, from, n);
31150 clac();
31151 return n;
31152 }
31153 @@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
31154 {
31155 stac();
31156 if (movsl_is_ok(to, from, n))
31157 - __copy_user(to, from, n);
31158 + __copy_user(to, from, n, __copyuser_seg, "", "");
31159 else
31160 - n = __copy_user_intel((void __user *)to,
31161 - (const void *)from, n);
31162 + n = __generic_copy_from_user_intel(to, from, n);
31163 clac();
31164 return n;
31165 }
31166 @@ -632,58 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
31167 if (n > 64 && cpu_has_xmm2)
31168 n = __copy_user_intel_nocache(to, from, n);
31169 else
31170 - __copy_user(to, from, n);
31171 + __copy_user(to, from, n, __copyuser_seg, "", "");
31172 #else
31173 - __copy_user(to, from, n);
31174 + __copy_user(to, from, n, __copyuser_seg, "", "");
31175 #endif
31176 clac();
31177 return n;
31178 }
31179 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
31180
31181 -/**
31182 - * copy_to_user: - Copy a block of data into user space.
31183 - * @to: Destination address, in user space.
31184 - * @from: Source address, in kernel space.
31185 - * @n: Number of bytes to copy.
31186 - *
31187 - * Context: User context only. This function may sleep.
31188 - *
31189 - * Copy data from kernel space to user space.
31190 - *
31191 - * Returns number of bytes that could not be copied.
31192 - * On success, this will be zero.
31193 - */
31194 -unsigned long _copy_to_user(void __user *to, const void *from, unsigned n)
31195 +#ifdef CONFIG_PAX_MEMORY_UDEREF
31196 +void __set_fs(mm_segment_t x)
31197 {
31198 - if (access_ok(VERIFY_WRITE, to, n))
31199 - n = __copy_to_user(to, from, n);
31200 - return n;
31201 + switch (x.seg) {
31202 + case 0:
31203 + loadsegment(gs, 0);
31204 + break;
31205 + case TASK_SIZE_MAX:
31206 + loadsegment(gs, __USER_DS);
31207 + break;
31208 + case -1UL:
31209 + loadsegment(gs, __KERNEL_DS);
31210 + break;
31211 + default:
31212 + BUG();
31213 + }
31214 }
31215 -EXPORT_SYMBOL(_copy_to_user);
31216 +EXPORT_SYMBOL(__set_fs);
31217
31218 -/**
31219 - * copy_from_user: - Copy a block of data from user space.
31220 - * @to: Destination address, in kernel space.
31221 - * @from: Source address, in user space.
31222 - * @n: Number of bytes to copy.
31223 - *
31224 - * Context: User context only. This function may sleep.
31225 - *
31226 - * Copy data from user space to kernel space.
31227 - *
31228 - * Returns number of bytes that could not be copied.
31229 - * On success, this will be zero.
31230 - *
31231 - * If some data could not be copied, this function will pad the copied
31232 - * data to the requested size using zero bytes.
31233 - */
31234 -unsigned long _copy_from_user(void *to, const void __user *from, unsigned n)
31235 +void set_fs(mm_segment_t x)
31236 {
31237 - if (access_ok(VERIFY_READ, from, n))
31238 - n = __copy_from_user(to, from, n);
31239 - else
31240 - memset(to, 0, n);
31241 - return n;
31242 + current_thread_info()->addr_limit = x;
31243 + __set_fs(x);
31244 }
31245 -EXPORT_SYMBOL(_copy_from_user);
31246 +EXPORT_SYMBOL(set_fs);
31247 +#endif
31248 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
31249 index c905e89..01ab928 100644
31250 --- a/arch/x86/lib/usercopy_64.c
31251 +++ b/arch/x86/lib/usercopy_64.c
31252 @@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31253 might_fault();
31254 /* no memory constraint because it doesn't change any memory gcc knows
31255 about */
31256 + pax_open_userland();
31257 stac();
31258 asm volatile(
31259 " testq %[size8],%[size8]\n"
31260 @@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
31261 _ASM_EXTABLE(0b,3b)
31262 _ASM_EXTABLE(1b,2b)
31263 : [size8] "=&c"(size), [dst] "=&D" (__d0)
31264 - : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
31265 + : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
31266 [zero] "r" (0UL), [eight] "r" (8UL));
31267 clac();
31268 + pax_close_userland();
31269 return size;
31270 }
31271 EXPORT_SYMBOL(__clear_user);
31272 @@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
31273 }
31274 EXPORT_SYMBOL(clear_user);
31275
31276 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
31277 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
31278 {
31279 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
31280 - return copy_user_generic((__force void *)to, (__force void *)from, len);
31281 - }
31282 - return len;
31283 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
31284 + return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
31285 + return len;
31286 }
31287 EXPORT_SYMBOL(copy_in_user);
31288
31289 @@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
31290 * it is not necessary to optimize tail handling.
31291 */
31292 __visible unsigned long
31293 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31294 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
31295 {
31296 char c;
31297 unsigned zero_len;
31298
31299 + clac();
31300 + pax_close_userland();
31301 for (; len; --len, to++) {
31302 if (__get_user_nocheck(c, from++, sizeof(char)))
31303 break;
31304 @@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
31305 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
31306 if (__put_user_nocheck(c, to++, sizeof(char)))
31307 break;
31308 - clac();
31309 return len;
31310 }
31311 diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
31312 index 6a19ad9..1c48f9a 100644
31313 --- a/arch/x86/mm/Makefile
31314 +++ b/arch/x86/mm/Makefile
31315 @@ -30,3 +30,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
31316 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
31317
31318 obj-$(CONFIG_MEMTEST) += memtest.o
31319 +
31320 +quote:="
31321 +obj-$(CONFIG_X86_64) += uderef_64.o
31322 +CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
31323 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
31324 index 903ec1e..c4166b2 100644
31325 --- a/arch/x86/mm/extable.c
31326 +++ b/arch/x86/mm/extable.c
31327 @@ -6,12 +6,24 @@
31328 static inline unsigned long
31329 ex_insn_addr(const struct exception_table_entry *x)
31330 {
31331 - return (unsigned long)&x->insn + x->insn;
31332 + unsigned long reloc = 0;
31333 +
31334 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31335 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31336 +#endif
31337 +
31338 + return (unsigned long)&x->insn + x->insn + reloc;
31339 }
31340 static inline unsigned long
31341 ex_fixup_addr(const struct exception_table_entry *x)
31342 {
31343 - return (unsigned long)&x->fixup + x->fixup;
31344 + unsigned long reloc = 0;
31345 +
31346 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31347 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31348 +#endif
31349 +
31350 + return (unsigned long)&x->fixup + x->fixup + reloc;
31351 }
31352
31353 int fixup_exception(struct pt_regs *regs)
31354 @@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
31355 unsigned long new_ip;
31356
31357 #ifdef CONFIG_PNPBIOS
31358 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
31359 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
31360 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
31361 extern u32 pnp_bios_is_utter_crap;
31362 pnp_bios_is_utter_crap = 1;
31363 @@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
31364 i += 4;
31365 p->fixup -= i;
31366 i += 4;
31367 +
31368 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
31369 + BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
31370 + p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31371 + p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
31372 +#endif
31373 +
31374 }
31375 }
31376
31377 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
31378 index 8e57229..31cce89 100644
31379 --- a/arch/x86/mm/fault.c
31380 +++ b/arch/x86/mm/fault.c
31381 @@ -14,11 +14,18 @@
31382 #include <linux/hugetlb.h> /* hstate_index_to_shift */
31383 #include <linux/prefetch.h> /* prefetchw */
31384 #include <linux/context_tracking.h> /* exception_enter(), ... */
31385 +#include <linux/unistd.h>
31386 +#include <linux/compiler.h>
31387
31388 #include <asm/traps.h> /* dotraplinkage, ... */
31389 #include <asm/pgalloc.h> /* pgd_*(), ... */
31390 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
31391 #include <asm/fixmap.h> /* VSYSCALL_START */
31392 +#include <asm/tlbflush.h>
31393 +
31394 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31395 +#include <asm/stacktrace.h>
31396 +#endif
31397
31398 #define CREATE_TRACE_POINTS
31399 #include <asm/trace/exceptions.h>
31400 @@ -59,7 +66,7 @@ static inline int __kprobes kprobes_fault(struct pt_regs *regs)
31401 int ret = 0;
31402
31403 /* kprobe_running() needs smp_processor_id() */
31404 - if (kprobes_built_in() && !user_mode_vm(regs)) {
31405 + if (kprobes_built_in() && !user_mode(regs)) {
31406 preempt_disable();
31407 if (kprobe_running() && kprobe_fault_handler(regs, 14))
31408 ret = 1;
31409 @@ -120,7 +127,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
31410 return !instr_lo || (instr_lo>>1) == 1;
31411 case 0x00:
31412 /* Prefetch instruction is 0x0F0D or 0x0F18 */
31413 - if (probe_kernel_address(instr, opcode))
31414 + if (user_mode(regs)) {
31415 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31416 + return 0;
31417 + } else if (probe_kernel_address(instr, opcode))
31418 return 0;
31419
31420 *prefetch = (instr_lo == 0xF) &&
31421 @@ -154,7 +164,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
31422 while (instr < max_instr) {
31423 unsigned char opcode;
31424
31425 - if (probe_kernel_address(instr, opcode))
31426 + if (user_mode(regs)) {
31427 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
31428 + break;
31429 + } else if (probe_kernel_address(instr, opcode))
31430 break;
31431
31432 instr++;
31433 @@ -185,6 +198,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
31434 force_sig_info(si_signo, &info, tsk);
31435 }
31436
31437 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31438 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
31439 +#endif
31440 +
31441 +#ifdef CONFIG_PAX_EMUTRAMP
31442 +static int pax_handle_fetch_fault(struct pt_regs *regs);
31443 +#endif
31444 +
31445 +#ifdef CONFIG_PAX_PAGEEXEC
31446 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
31447 +{
31448 + pgd_t *pgd;
31449 + pud_t *pud;
31450 + pmd_t *pmd;
31451 +
31452 + pgd = pgd_offset(mm, address);
31453 + if (!pgd_present(*pgd))
31454 + return NULL;
31455 + pud = pud_offset(pgd, address);
31456 + if (!pud_present(*pud))
31457 + return NULL;
31458 + pmd = pmd_offset(pud, address);
31459 + if (!pmd_present(*pmd))
31460 + return NULL;
31461 + return pmd;
31462 +}
31463 +#endif
31464 +
31465 DEFINE_SPINLOCK(pgd_lock);
31466 LIST_HEAD(pgd_list);
31467
31468 @@ -235,10 +276,27 @@ void vmalloc_sync_all(void)
31469 for (address = VMALLOC_START & PMD_MASK;
31470 address >= TASK_SIZE && address < FIXADDR_TOP;
31471 address += PMD_SIZE) {
31472 +
31473 +#ifdef CONFIG_PAX_PER_CPU_PGD
31474 + unsigned long cpu;
31475 +#else
31476 struct page *page;
31477 +#endif
31478
31479 spin_lock(&pgd_lock);
31480 +
31481 +#ifdef CONFIG_PAX_PER_CPU_PGD
31482 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
31483 + pgd_t *pgd = get_cpu_pgd(cpu, user);
31484 + pmd_t *ret;
31485 +
31486 + ret = vmalloc_sync_one(pgd, address);
31487 + if (!ret)
31488 + break;
31489 + pgd = get_cpu_pgd(cpu, kernel);
31490 +#else
31491 list_for_each_entry(page, &pgd_list, lru) {
31492 + pgd_t *pgd;
31493 spinlock_t *pgt_lock;
31494 pmd_t *ret;
31495
31496 @@ -246,8 +304,14 @@ void vmalloc_sync_all(void)
31497 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
31498
31499 spin_lock(pgt_lock);
31500 - ret = vmalloc_sync_one(page_address(page), address);
31501 + pgd = page_address(page);
31502 +#endif
31503 +
31504 + ret = vmalloc_sync_one(pgd, address);
31505 +
31506 +#ifndef CONFIG_PAX_PER_CPU_PGD
31507 spin_unlock(pgt_lock);
31508 +#endif
31509
31510 if (!ret)
31511 break;
31512 @@ -281,6 +345,12 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
31513 * an interrupt in the middle of a task switch..
31514 */
31515 pgd_paddr = read_cr3();
31516 +
31517 +#ifdef CONFIG_PAX_PER_CPU_PGD
31518 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
31519 + vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
31520 +#endif
31521 +
31522 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
31523 if (!pmd_k)
31524 return -1;
31525 @@ -376,11 +446,25 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
31526 * happen within a race in page table update. In the later
31527 * case just flush:
31528 */
31529 - pgd = pgd_offset(current->active_mm, address);
31530 +
31531 pgd_ref = pgd_offset_k(address);
31532 if (pgd_none(*pgd_ref))
31533 return -1;
31534
31535 +#ifdef CONFIG_PAX_PER_CPU_PGD
31536 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
31537 + pgd = pgd_offset_cpu(smp_processor_id(), user, address);
31538 + if (pgd_none(*pgd)) {
31539 + set_pgd(pgd, *pgd_ref);
31540 + arch_flush_lazy_mmu_mode();
31541 + } else {
31542 + BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
31543 + }
31544 + pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
31545 +#else
31546 + pgd = pgd_offset(current->active_mm, address);
31547 +#endif
31548 +
31549 if (pgd_none(*pgd)) {
31550 set_pgd(pgd, *pgd_ref);
31551 arch_flush_lazy_mmu_mode();
31552 @@ -546,7 +630,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
31553 static int is_errata100(struct pt_regs *regs, unsigned long address)
31554 {
31555 #ifdef CONFIG_X86_64
31556 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
31557 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
31558 return 1;
31559 #endif
31560 return 0;
31561 @@ -573,7 +657,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
31562 }
31563
31564 static const char nx_warning[] = KERN_CRIT
31565 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
31566 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
31567
31568 static void
31569 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31570 @@ -582,7 +666,7 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31571 if (!oops_may_print())
31572 return;
31573
31574 - if (error_code & PF_INSTR) {
31575 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
31576 unsigned int level;
31577 pgd_t *pgd;
31578 pte_t *pte;
31579 @@ -593,9 +677,21 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
31580 pte = lookup_address_in_pgd(pgd, address, &level);
31581
31582 if (pte && pte_present(*pte) && !pte_exec(*pte))
31583 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
31584 + printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
31585 }
31586
31587 +#ifdef CONFIG_PAX_KERNEXEC
31588 + if (init_mm.start_code <= address && address < init_mm.end_code) {
31589 + if (current->signal->curr_ip)
31590 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
31591 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
31592 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31593 + else
31594 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
31595 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
31596 + }
31597 +#endif
31598 +
31599 printk(KERN_ALERT "BUG: unable to handle kernel ");
31600 if (address < PAGE_SIZE)
31601 printk(KERN_CONT "NULL pointer dereference");
31602 @@ -776,6 +872,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
31603 return;
31604 }
31605 #endif
31606 +
31607 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31608 + if (pax_is_fetch_fault(regs, error_code, address)) {
31609 +
31610 +#ifdef CONFIG_PAX_EMUTRAMP
31611 + switch (pax_handle_fetch_fault(regs)) {
31612 + case 2:
31613 + return;
31614 + }
31615 +#endif
31616 +
31617 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
31618 + do_group_exit(SIGKILL);
31619 + }
31620 +#endif
31621 +
31622 /* Kernel addresses are always protection faults: */
31623 if (address >= TASK_SIZE)
31624 error_code |= PF_PROT;
31625 @@ -861,7 +973,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
31626 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
31627 printk(KERN_ERR
31628 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
31629 - tsk->comm, tsk->pid, address);
31630 + tsk->comm, task_pid_nr(tsk), address);
31631 code = BUS_MCEERR_AR;
31632 }
31633 #endif
31634 @@ -915,6 +1027,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
31635 return 1;
31636 }
31637
31638 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
31639 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
31640 +{
31641 + pte_t *pte;
31642 + pmd_t *pmd;
31643 + spinlock_t *ptl;
31644 + unsigned char pte_mask;
31645 +
31646 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
31647 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
31648 + return 0;
31649 +
31650 + /* PaX: it's our fault, let's handle it if we can */
31651 +
31652 + /* PaX: take a look at read faults before acquiring any locks */
31653 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
31654 + /* instruction fetch attempt from a protected page in user mode */
31655 + up_read(&mm->mmap_sem);
31656 +
31657 +#ifdef CONFIG_PAX_EMUTRAMP
31658 + switch (pax_handle_fetch_fault(regs)) {
31659 + case 2:
31660 + return 1;
31661 + }
31662 +#endif
31663 +
31664 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
31665 + do_group_exit(SIGKILL);
31666 + }
31667 +
31668 + pmd = pax_get_pmd(mm, address);
31669 + if (unlikely(!pmd))
31670 + return 0;
31671 +
31672 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
31673 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
31674 + pte_unmap_unlock(pte, ptl);
31675 + return 0;
31676 + }
31677 +
31678 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
31679 + /* write attempt to a protected page in user mode */
31680 + pte_unmap_unlock(pte, ptl);
31681 + return 0;
31682 + }
31683 +
31684 +#ifdef CONFIG_SMP
31685 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
31686 +#else
31687 + if (likely(address > get_limit(regs->cs)))
31688 +#endif
31689 + {
31690 + set_pte(pte, pte_mkread(*pte));
31691 + __flush_tlb_one(address);
31692 + pte_unmap_unlock(pte, ptl);
31693 + up_read(&mm->mmap_sem);
31694 + return 1;
31695 + }
31696 +
31697 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
31698 +
31699 + /*
31700 + * PaX: fill DTLB with user rights and retry
31701 + */
31702 + __asm__ __volatile__ (
31703 + "orb %2,(%1)\n"
31704 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
31705 +/*
31706 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
31707 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
31708 + * page fault when examined during a TLB load attempt. this is true not only
31709 + * for PTEs holding a non-present entry but also present entries that will
31710 + * raise a page fault (such as those set up by PaX, or the copy-on-write
31711 + * mechanism). in effect it means that we do *not* need to flush the TLBs
31712 + * for our target pages since their PTEs are simply not in the TLBs at all.
31713 +
31714 + * the best thing in omitting it is that we gain around 15-20% speed in the
31715 + * fast path of the page fault handler and can get rid of tracing since we
31716 + * can no longer flush unintended entries.
31717 + */
31718 + "invlpg (%0)\n"
31719 +#endif
31720 + __copyuser_seg"testb $0,(%0)\n"
31721 + "xorb %3,(%1)\n"
31722 + :
31723 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
31724 + : "memory", "cc");
31725 + pte_unmap_unlock(pte, ptl);
31726 + up_read(&mm->mmap_sem);
31727 + return 1;
31728 +}
31729 +#endif
31730 +
31731 /*
31732 * Handle a spurious fault caused by a stale TLB entry.
31733 *
31734 @@ -981,6 +1186,9 @@ int show_unhandled_signals = 1;
31735 static inline int
31736 access_error(unsigned long error_code, struct vm_area_struct *vma)
31737 {
31738 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
31739 + return 1;
31740 +
31741 if (error_code & PF_WRITE) {
31742 /* write, present and write, not present: */
31743 if (unlikely(!(vma->vm_flags & VM_WRITE)))
31744 @@ -1015,7 +1223,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
31745 if (error_code & PF_USER)
31746 return false;
31747
31748 - if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
31749 + if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
31750 return false;
31751
31752 return true;
31753 @@ -1043,6 +1251,22 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
31754 tsk = current;
31755 mm = tsk->mm;
31756
31757 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31758 + if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
31759 + if (!search_exception_tables(regs->ip)) {
31760 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
31761 + bad_area_nosemaphore(regs, error_code, address);
31762 + return;
31763 + }
31764 + if (address < pax_user_shadow_base) {
31765 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
31766 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
31767 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
31768 + } else
31769 + address -= pax_user_shadow_base;
31770 + }
31771 +#endif
31772 +
31773 /*
31774 * Detect and handle instructions that would cause a page fault for
31775 * both a tracked kernel page and a userspace page.
31776 @@ -1120,7 +1344,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code,
31777 * User-mode registers count as a user access even for any
31778 * potential system fault or CPU buglet:
31779 */
31780 - if (user_mode_vm(regs)) {
31781 + if (user_mode(regs)) {
31782 local_irq_enable();
31783 error_code |= PF_USER;
31784 flags |= FAULT_FLAG_USER;
31785 @@ -1167,6 +1391,11 @@ retry:
31786 might_sleep();
31787 }
31788
31789 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
31790 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
31791 + return;
31792 +#endif
31793 +
31794 vma = find_vma(mm, address);
31795 if (unlikely(!vma)) {
31796 bad_area(regs, error_code, address);
31797 @@ -1178,18 +1407,24 @@ retry:
31798 bad_area(regs, error_code, address);
31799 return;
31800 }
31801 - if (error_code & PF_USER) {
31802 - /*
31803 - * Accessing the stack below %sp is always a bug.
31804 - * The large cushion allows instructions like enter
31805 - * and pusha to work. ("enter $65535, $31" pushes
31806 - * 32 pointers and then decrements %sp by 65535.)
31807 - */
31808 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
31809 - bad_area(regs, error_code, address);
31810 - return;
31811 - }
31812 + /*
31813 + * Accessing the stack below %sp is always a bug.
31814 + * The large cushion allows instructions like enter
31815 + * and pusha to work. ("enter $65535, $31" pushes
31816 + * 32 pointers and then decrements %sp by 65535.)
31817 + */
31818 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
31819 + bad_area(regs, error_code, address);
31820 + return;
31821 }
31822 +
31823 +#ifdef CONFIG_PAX_SEGMEXEC
31824 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
31825 + bad_area(regs, error_code, address);
31826 + return;
31827 + }
31828 +#endif
31829 +
31830 if (unlikely(expand_stack(vma, address))) {
31831 bad_area(regs, error_code, address);
31832 return;
31833 @@ -1301,3 +1536,292 @@ trace_do_page_fault(struct pt_regs *regs, unsigned long error_code)
31834 exception_exit(prev_state);
31835 }
31836 #endif /* CONFIG_TRACING */
31837 +
31838 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31839 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
31840 +{
31841 + struct mm_struct *mm = current->mm;
31842 + unsigned long ip = regs->ip;
31843 +
31844 + if (v8086_mode(regs))
31845 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
31846 +
31847 +#ifdef CONFIG_PAX_PAGEEXEC
31848 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
31849 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
31850 + return true;
31851 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
31852 + return true;
31853 + return false;
31854 + }
31855 +#endif
31856 +
31857 +#ifdef CONFIG_PAX_SEGMEXEC
31858 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
31859 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
31860 + return true;
31861 + return false;
31862 + }
31863 +#endif
31864 +
31865 + return false;
31866 +}
31867 +#endif
31868 +
31869 +#ifdef CONFIG_PAX_EMUTRAMP
31870 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
31871 +{
31872 + int err;
31873 +
31874 + do { /* PaX: libffi trampoline emulation */
31875 + unsigned char mov, jmp;
31876 + unsigned int addr1, addr2;
31877 +
31878 +#ifdef CONFIG_X86_64
31879 + if ((regs->ip + 9) >> 32)
31880 + break;
31881 +#endif
31882 +
31883 + err = get_user(mov, (unsigned char __user *)regs->ip);
31884 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31885 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
31886 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31887 +
31888 + if (err)
31889 + break;
31890 +
31891 + if (mov == 0xB8 && jmp == 0xE9) {
31892 + regs->ax = addr1;
31893 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
31894 + return 2;
31895 + }
31896 + } while (0);
31897 +
31898 + do { /* PaX: gcc trampoline emulation #1 */
31899 + unsigned char mov1, mov2;
31900 + unsigned short jmp;
31901 + unsigned int addr1, addr2;
31902 +
31903 +#ifdef CONFIG_X86_64
31904 + if ((regs->ip + 11) >> 32)
31905 + break;
31906 +#endif
31907 +
31908 + err = get_user(mov1, (unsigned char __user *)regs->ip);
31909 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31910 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
31911 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31912 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
31913 +
31914 + if (err)
31915 + break;
31916 +
31917 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
31918 + regs->cx = addr1;
31919 + regs->ax = addr2;
31920 + regs->ip = addr2;
31921 + return 2;
31922 + }
31923 + } while (0);
31924 +
31925 + do { /* PaX: gcc trampoline emulation #2 */
31926 + unsigned char mov, jmp;
31927 + unsigned int addr1, addr2;
31928 +
31929 +#ifdef CONFIG_X86_64
31930 + if ((regs->ip + 9) >> 32)
31931 + break;
31932 +#endif
31933 +
31934 + err = get_user(mov, (unsigned char __user *)regs->ip);
31935 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31936 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
31937 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31938 +
31939 + if (err)
31940 + break;
31941 +
31942 + if (mov == 0xB9 && jmp == 0xE9) {
31943 + regs->cx = addr1;
31944 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
31945 + return 2;
31946 + }
31947 + } while (0);
31948 +
31949 + return 1; /* PaX in action */
31950 +}
31951 +
31952 +#ifdef CONFIG_X86_64
31953 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
31954 +{
31955 + int err;
31956 +
31957 + do { /* PaX: libffi trampoline emulation */
31958 + unsigned short mov1, mov2, jmp1;
31959 + unsigned char stcclc, jmp2;
31960 + unsigned long addr1, addr2;
31961 +
31962 + err = get_user(mov1, (unsigned short __user *)regs->ip);
31963 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
31964 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
31965 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
31966 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
31967 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
31968 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
31969 +
31970 + if (err)
31971 + break;
31972 +
31973 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31974 + regs->r11 = addr1;
31975 + regs->r10 = addr2;
31976 + if (stcclc == 0xF8)
31977 + regs->flags &= ~X86_EFLAGS_CF;
31978 + else
31979 + regs->flags |= X86_EFLAGS_CF;
31980 + regs->ip = addr1;
31981 + return 2;
31982 + }
31983 + } while (0);
31984 +
31985 + do { /* PaX: gcc trampoline emulation #1 */
31986 + unsigned short mov1, mov2, jmp1;
31987 + unsigned char jmp2;
31988 + unsigned int addr1;
31989 + unsigned long addr2;
31990 +
31991 + err = get_user(mov1, (unsigned short __user *)regs->ip);
31992 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
31993 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
31994 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
31995 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
31996 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
31997 +
31998 + if (err)
31999 + break;
32000 +
32001 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32002 + regs->r11 = addr1;
32003 + regs->r10 = addr2;
32004 + regs->ip = addr1;
32005 + return 2;
32006 + }
32007 + } while (0);
32008 +
32009 + do { /* PaX: gcc trampoline emulation #2 */
32010 + unsigned short mov1, mov2, jmp1;
32011 + unsigned char jmp2;
32012 + unsigned long addr1, addr2;
32013 +
32014 + err = get_user(mov1, (unsigned short __user *)regs->ip);
32015 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
32016 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
32017 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
32018 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
32019 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
32020 +
32021 + if (err)
32022 + break;
32023 +
32024 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
32025 + regs->r11 = addr1;
32026 + regs->r10 = addr2;
32027 + regs->ip = addr1;
32028 + return 2;
32029 + }
32030 + } while (0);
32031 +
32032 + return 1; /* PaX in action */
32033 +}
32034 +#endif
32035 +
32036 +/*
32037 + * PaX: decide what to do with offenders (regs->ip = fault address)
32038 + *
32039 + * returns 1 when task should be killed
32040 + * 2 when gcc trampoline was detected
32041 + */
32042 +static int pax_handle_fetch_fault(struct pt_regs *regs)
32043 +{
32044 + if (v8086_mode(regs))
32045 + return 1;
32046 +
32047 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
32048 + return 1;
32049 +
32050 +#ifdef CONFIG_X86_32
32051 + return pax_handle_fetch_fault_32(regs);
32052 +#else
32053 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
32054 + return pax_handle_fetch_fault_32(regs);
32055 + else
32056 + return pax_handle_fetch_fault_64(regs);
32057 +#endif
32058 +}
32059 +#endif
32060 +
32061 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32062 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
32063 +{
32064 + long i;
32065 +
32066 + printk(KERN_ERR "PAX: bytes at PC: ");
32067 + for (i = 0; i < 20; i++) {
32068 + unsigned char c;
32069 + if (get_user(c, (unsigned char __force_user *)pc+i))
32070 + printk(KERN_CONT "?? ");
32071 + else
32072 + printk(KERN_CONT "%02x ", c);
32073 + }
32074 + printk("\n");
32075 +
32076 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
32077 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
32078 + unsigned long c;
32079 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
32080 +#ifdef CONFIG_X86_32
32081 + printk(KERN_CONT "???????? ");
32082 +#else
32083 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
32084 + printk(KERN_CONT "???????? ???????? ");
32085 + else
32086 + printk(KERN_CONT "???????????????? ");
32087 +#endif
32088 + } else {
32089 +#ifdef CONFIG_X86_64
32090 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
32091 + printk(KERN_CONT "%08x ", (unsigned int)c);
32092 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
32093 + } else
32094 +#endif
32095 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
32096 + }
32097 + }
32098 + printk("\n");
32099 +}
32100 +#endif
32101 +
32102 +/**
32103 + * probe_kernel_write(): safely attempt to write to a location
32104 + * @dst: address to write to
32105 + * @src: pointer to the data that shall be written
32106 + * @size: size of the data chunk
32107 + *
32108 + * Safely write to address @dst from the buffer at @src. If a kernel fault
32109 + * happens, handle that and return -EFAULT.
32110 + */
32111 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
32112 +{
32113 + long ret;
32114 + mm_segment_t old_fs = get_fs();
32115 +
32116 + set_fs(KERNEL_DS);
32117 + pagefault_disable();
32118 + pax_open_kernel();
32119 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
32120 + pax_close_kernel();
32121 + pagefault_enable();
32122 + set_fs(old_fs);
32123 +
32124 + return ret ? -EFAULT : 0;
32125 +}
32126 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
32127 index 207d9aef..69030980 100644
32128 --- a/arch/x86/mm/gup.c
32129 +++ b/arch/x86/mm/gup.c
32130 @@ -268,7 +268,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
32131 addr = start;
32132 len = (unsigned long) nr_pages << PAGE_SHIFT;
32133 end = start + len;
32134 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
32135 + if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
32136 (void __user *)start, len)))
32137 return 0;
32138
32139 @@ -344,6 +344,10 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
32140 goto slow_irqon;
32141 #endif
32142
32143 + if (unlikely(!access_ok_noprefault(write ? VERIFY_WRITE : VERIFY_READ,
32144 + (void __user *)start, len)))
32145 + return 0;
32146 +
32147 /*
32148 * XXX: batch / limit 'nr', to avoid large irq off latency
32149 * needs some instrumenting to determine the common sizes used by
32150 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
32151 index 4500142..53a363c 100644
32152 --- a/arch/x86/mm/highmem_32.c
32153 +++ b/arch/x86/mm/highmem_32.c
32154 @@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
32155 idx = type + KM_TYPE_NR*smp_processor_id();
32156 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
32157 BUG_ON(!pte_none(*(kmap_pte-idx)));
32158 +
32159 + pax_open_kernel();
32160 set_pte(kmap_pte-idx, mk_pte(page, prot));
32161 + pax_close_kernel();
32162 +
32163 arch_flush_lazy_mmu_mode();
32164
32165 return (void *)vaddr;
32166 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
32167 index 8b977eb..4732c33 100644
32168 --- a/arch/x86/mm/hugetlbpage.c
32169 +++ b/arch/x86/mm/hugetlbpage.c
32170 @@ -80,23 +80,24 @@ int pud_huge(pud_t pud)
32171 #ifdef CONFIG_HUGETLB_PAGE
32172 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
32173 unsigned long addr, unsigned long len,
32174 - unsigned long pgoff, unsigned long flags)
32175 + unsigned long pgoff, unsigned long flags, unsigned long offset)
32176 {
32177 struct hstate *h = hstate_file(file);
32178 struct vm_unmapped_area_info info;
32179 -
32180 +
32181 info.flags = 0;
32182 info.length = len;
32183 info.low_limit = current->mm->mmap_legacy_base;
32184 info.high_limit = TASK_SIZE;
32185 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32186 info.align_offset = 0;
32187 + info.threadstack_offset = offset;
32188 return vm_unmapped_area(&info);
32189 }
32190
32191 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32192 unsigned long addr0, unsigned long len,
32193 - unsigned long pgoff, unsigned long flags)
32194 + unsigned long pgoff, unsigned long flags, unsigned long offset)
32195 {
32196 struct hstate *h = hstate_file(file);
32197 struct vm_unmapped_area_info info;
32198 @@ -108,6 +109,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32199 info.high_limit = current->mm->mmap_base;
32200 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
32201 info.align_offset = 0;
32202 + info.threadstack_offset = offset;
32203 addr = vm_unmapped_area(&info);
32204
32205 /*
32206 @@ -120,6 +122,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
32207 VM_BUG_ON(addr != -ENOMEM);
32208 info.flags = 0;
32209 info.low_limit = TASK_UNMAPPED_BASE;
32210 +
32211 +#ifdef CONFIG_PAX_RANDMMAP
32212 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
32213 + info.low_limit += current->mm->delta_mmap;
32214 +#endif
32215 +
32216 info.high_limit = TASK_SIZE;
32217 addr = vm_unmapped_area(&info);
32218 }
32219 @@ -134,10 +142,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32220 struct hstate *h = hstate_file(file);
32221 struct mm_struct *mm = current->mm;
32222 struct vm_area_struct *vma;
32223 + unsigned long pax_task_size = TASK_SIZE;
32224 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
32225
32226 if (len & ~huge_page_mask(h))
32227 return -EINVAL;
32228 - if (len > TASK_SIZE)
32229 +
32230 +#ifdef CONFIG_PAX_SEGMEXEC
32231 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
32232 + pax_task_size = SEGMEXEC_TASK_SIZE;
32233 +#endif
32234 +
32235 + pax_task_size -= PAGE_SIZE;
32236 +
32237 + if (len > pax_task_size)
32238 return -ENOMEM;
32239
32240 if (flags & MAP_FIXED) {
32241 @@ -146,19 +164,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
32242 return addr;
32243 }
32244
32245 +#ifdef CONFIG_PAX_RANDMMAP
32246 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
32247 +#endif
32248 +
32249 if (addr) {
32250 addr = ALIGN(addr, huge_page_size(h));
32251 vma = find_vma(mm, addr);
32252 - if (TASK_SIZE - len >= addr &&
32253 - (!vma || addr + len <= vma->vm_start))
32254 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
32255 return addr;
32256 }
32257 if (mm->get_unmapped_area == arch_get_unmapped_area)
32258 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
32259 - pgoff, flags);
32260 + pgoff, flags, offset);
32261 else
32262 return hugetlb_get_unmapped_area_topdown(file, addr, len,
32263 - pgoff, flags);
32264 + pgoff, flags, offset);
32265 }
32266 #endif /* CONFIG_HUGETLB_PAGE */
32267
32268 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
32269 index f971306..e83e0f6 100644
32270 --- a/arch/x86/mm/init.c
32271 +++ b/arch/x86/mm/init.c
32272 @@ -4,6 +4,7 @@
32273 #include <linux/swap.h>
32274 #include <linux/memblock.h>
32275 #include <linux/bootmem.h> /* for max_low_pfn */
32276 +#include <linux/tboot.h>
32277
32278 #include <asm/cacheflush.h>
32279 #include <asm/e820.h>
32280 @@ -17,6 +18,8 @@
32281 #include <asm/proto.h>
32282 #include <asm/dma.h> /* for MAX_DMA_PFN */
32283 #include <asm/microcode.h>
32284 +#include <asm/desc.h>
32285 +#include <asm/bios_ebda.h>
32286
32287 #include "mm_internal.h"
32288
32289 @@ -563,7 +566,18 @@ void __init init_mem_mapping(void)
32290 early_ioremap_page_table_range_init();
32291 #endif
32292
32293 +#ifdef CONFIG_PAX_PER_CPU_PGD
32294 + clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
32295 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32296 + KERNEL_PGD_PTRS);
32297 + clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
32298 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
32299 + KERNEL_PGD_PTRS);
32300 + load_cr3(get_cpu_pgd(0, kernel));
32301 +#else
32302 load_cr3(swapper_pg_dir);
32303 +#endif
32304 +
32305 __flush_tlb_all();
32306
32307 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
32308 @@ -579,10 +593,40 @@ void __init init_mem_mapping(void)
32309 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
32310 * mmio resources as well as potential bios/acpi data regions.
32311 */
32312 +
32313 +#ifdef CONFIG_GRKERNSEC_KMEM
32314 +static unsigned int ebda_start __read_only;
32315 +static unsigned int ebda_end __read_only;
32316 +#endif
32317 +
32318 int devmem_is_allowed(unsigned long pagenr)
32319 {
32320 - if (pagenr < 256)
32321 +#ifdef CONFIG_GRKERNSEC_KMEM
32322 + /* allow BDA */
32323 + if (!pagenr)
32324 return 1;
32325 + /* allow EBDA */
32326 + if (pagenr >= ebda_start && pagenr < ebda_end)
32327 + return 1;
32328 + /* if tboot is in use, allow access to its hardcoded serial log range */
32329 + if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
32330 + return 1;
32331 +#else
32332 + if (!pagenr)
32333 + return 1;
32334 +#ifdef CONFIG_VM86
32335 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
32336 + return 1;
32337 +#endif
32338 +#endif
32339 +
32340 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
32341 + return 1;
32342 +#ifdef CONFIG_GRKERNSEC_KMEM
32343 + /* throw out everything else below 1MB */
32344 + if (pagenr <= 256)
32345 + return 0;
32346 +#endif
32347 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
32348 return 0;
32349 if (!page_is_ram(pagenr))
32350 @@ -628,8 +672,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
32351 #endif
32352 }
32353
32354 +#ifdef CONFIG_GRKERNSEC_KMEM
32355 +static inline void gr_init_ebda(void)
32356 +{
32357 + unsigned int ebda_addr;
32358 + unsigned int ebda_size = 0;
32359 +
32360 + ebda_addr = get_bios_ebda();
32361 + if (ebda_addr) {
32362 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
32363 + ebda_size <<= 10;
32364 + }
32365 + if (ebda_addr && ebda_size) {
32366 + ebda_start = ebda_addr >> PAGE_SHIFT;
32367 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
32368 + } else {
32369 + ebda_start = 0x9f000 >> PAGE_SHIFT;
32370 + ebda_end = 0xa0000 >> PAGE_SHIFT;
32371 + }
32372 +}
32373 +#else
32374 +static inline void gr_init_ebda(void) { }
32375 +#endif
32376 +
32377 void free_initmem(void)
32378 {
32379 +#ifdef CONFIG_PAX_KERNEXEC
32380 +#ifdef CONFIG_X86_32
32381 + /* PaX: limit KERNEL_CS to actual size */
32382 + unsigned long addr, limit;
32383 + struct desc_struct d;
32384 + int cpu;
32385 +#else
32386 + pgd_t *pgd;
32387 + pud_t *pud;
32388 + pmd_t *pmd;
32389 + unsigned long addr, end;
32390 +#endif
32391 +#endif
32392 +
32393 + gr_init_ebda();
32394 +
32395 +#ifdef CONFIG_PAX_KERNEXEC
32396 +#ifdef CONFIG_X86_32
32397 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
32398 + limit = (limit - 1UL) >> PAGE_SHIFT;
32399 +
32400 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
32401 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
32402 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
32403 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
32404 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
32405 + }
32406 +
32407 + /* PaX: make KERNEL_CS read-only */
32408 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
32409 + if (!paravirt_enabled())
32410 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
32411 +/*
32412 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
32413 + pgd = pgd_offset_k(addr);
32414 + pud = pud_offset(pgd, addr);
32415 + pmd = pmd_offset(pud, addr);
32416 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32417 + }
32418 +*/
32419 +#ifdef CONFIG_X86_PAE
32420 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
32421 +/*
32422 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
32423 + pgd = pgd_offset_k(addr);
32424 + pud = pud_offset(pgd, addr);
32425 + pmd = pmd_offset(pud, addr);
32426 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32427 + }
32428 +*/
32429 +#endif
32430 +
32431 +#ifdef CONFIG_MODULES
32432 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
32433 +#endif
32434 +
32435 +#else
32436 + /* PaX: make kernel code/rodata read-only, rest non-executable */
32437 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
32438 + pgd = pgd_offset_k(addr);
32439 + pud = pud_offset(pgd, addr);
32440 + pmd = pmd_offset(pud, addr);
32441 + if (!pmd_present(*pmd))
32442 + continue;
32443 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
32444 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32445 + else
32446 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
32447 + }
32448 +
32449 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
32450 + end = addr + KERNEL_IMAGE_SIZE;
32451 + for (; addr < end; addr += PMD_SIZE) {
32452 + pgd = pgd_offset_k(addr);
32453 + pud = pud_offset(pgd, addr);
32454 + pmd = pmd_offset(pud, addr);
32455 + if (!pmd_present(*pmd))
32456 + continue;
32457 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
32458 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
32459 + }
32460 +#endif
32461 +
32462 + flush_tlb_all();
32463 +#endif
32464 +
32465 free_init_pages("unused kernel",
32466 (unsigned long)(&__init_begin),
32467 (unsigned long)(&__init_end));
32468 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
32469 index e395048..cd38278 100644
32470 --- a/arch/x86/mm/init_32.c
32471 +++ b/arch/x86/mm/init_32.c
32472 @@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
32473 bool __read_mostly __vmalloc_start_set = false;
32474
32475 /*
32476 - * Creates a middle page table and puts a pointer to it in the
32477 - * given global directory entry. This only returns the gd entry
32478 - * in non-PAE compilation mode, since the middle layer is folded.
32479 - */
32480 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
32481 -{
32482 - pud_t *pud;
32483 - pmd_t *pmd_table;
32484 -
32485 -#ifdef CONFIG_X86_PAE
32486 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
32487 - pmd_table = (pmd_t *)alloc_low_page();
32488 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
32489 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
32490 - pud = pud_offset(pgd, 0);
32491 - BUG_ON(pmd_table != pmd_offset(pud, 0));
32492 -
32493 - return pmd_table;
32494 - }
32495 -#endif
32496 - pud = pud_offset(pgd, 0);
32497 - pmd_table = pmd_offset(pud, 0);
32498 -
32499 - return pmd_table;
32500 -}
32501 -
32502 -/*
32503 * Create a page table and place a pointer to it in a middle page
32504 * directory entry:
32505 */
32506 @@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
32507 pte_t *page_table = (pte_t *)alloc_low_page();
32508
32509 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
32510 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
32511 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
32512 +#else
32513 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
32514 +#endif
32515 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
32516 }
32517
32518 return pte_offset_kernel(pmd, 0);
32519 }
32520
32521 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
32522 +{
32523 + pud_t *pud;
32524 + pmd_t *pmd_table;
32525 +
32526 + pud = pud_offset(pgd, 0);
32527 + pmd_table = pmd_offset(pud, 0);
32528 +
32529 + return pmd_table;
32530 +}
32531 +
32532 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
32533 {
32534 int pgd_idx = pgd_index(vaddr);
32535 @@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32536 int pgd_idx, pmd_idx;
32537 unsigned long vaddr;
32538 pgd_t *pgd;
32539 + pud_t *pud;
32540 pmd_t *pmd;
32541 pte_t *pte = NULL;
32542 unsigned long count = page_table_range_init_count(start, end);
32543 @@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32544 pgd = pgd_base + pgd_idx;
32545
32546 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
32547 - pmd = one_md_table_init(pgd);
32548 - pmd = pmd + pmd_index(vaddr);
32549 + pud = pud_offset(pgd, vaddr);
32550 + pmd = pmd_offset(pud, vaddr);
32551 +
32552 +#ifdef CONFIG_X86_PAE
32553 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32554 +#endif
32555 +
32556 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
32557 pmd++, pmd_idx++) {
32558 pte = page_table_kmap_check(one_page_table_init(pmd),
32559 @@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
32560 }
32561 }
32562
32563 -static inline int is_kernel_text(unsigned long addr)
32564 +static inline int is_kernel_text(unsigned long start, unsigned long end)
32565 {
32566 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
32567 - return 1;
32568 - return 0;
32569 + if ((start >= ktla_ktva((unsigned long)_etext) ||
32570 + end <= ktla_ktva((unsigned long)_stext)) &&
32571 + (start >= ktla_ktva((unsigned long)_einittext) ||
32572 + end <= ktla_ktva((unsigned long)_sinittext)) &&
32573 +
32574 +#ifdef CONFIG_ACPI_SLEEP
32575 + (start >= (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
32576 +#endif
32577 +
32578 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
32579 + return 0;
32580 + return 1;
32581 }
32582
32583 /*
32584 @@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
32585 unsigned long last_map_addr = end;
32586 unsigned long start_pfn, end_pfn;
32587 pgd_t *pgd_base = swapper_pg_dir;
32588 - int pgd_idx, pmd_idx, pte_ofs;
32589 + unsigned int pgd_idx, pmd_idx, pte_ofs;
32590 unsigned long pfn;
32591 pgd_t *pgd;
32592 + pud_t *pud;
32593 pmd_t *pmd;
32594 pte_t *pte;
32595 unsigned pages_2m, pages_4k;
32596 @@ -291,8 +295,13 @@ repeat:
32597 pfn = start_pfn;
32598 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
32599 pgd = pgd_base + pgd_idx;
32600 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
32601 - pmd = one_md_table_init(pgd);
32602 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
32603 + pud = pud_offset(pgd, 0);
32604 + pmd = pmd_offset(pud, 0);
32605 +
32606 +#ifdef CONFIG_X86_PAE
32607 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
32608 +#endif
32609
32610 if (pfn >= end_pfn)
32611 continue;
32612 @@ -304,14 +313,13 @@ repeat:
32613 #endif
32614 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
32615 pmd++, pmd_idx++) {
32616 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
32617 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
32618
32619 /*
32620 * Map with big pages if possible, otherwise
32621 * create normal page tables:
32622 */
32623 if (use_pse) {
32624 - unsigned int addr2;
32625 pgprot_t prot = PAGE_KERNEL_LARGE;
32626 /*
32627 * first pass will use the same initial
32628 @@ -322,11 +330,7 @@ repeat:
32629 _PAGE_PSE);
32630
32631 pfn &= PMD_MASK >> PAGE_SHIFT;
32632 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
32633 - PAGE_OFFSET + PAGE_SIZE-1;
32634 -
32635 - if (is_kernel_text(addr) ||
32636 - is_kernel_text(addr2))
32637 + if (is_kernel_text(address, address + PMD_SIZE))
32638 prot = PAGE_KERNEL_LARGE_EXEC;
32639
32640 pages_2m++;
32641 @@ -343,7 +347,7 @@ repeat:
32642 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
32643 pte += pte_ofs;
32644 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
32645 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
32646 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
32647 pgprot_t prot = PAGE_KERNEL;
32648 /*
32649 * first pass will use the same initial
32650 @@ -351,7 +355,7 @@ repeat:
32651 */
32652 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
32653
32654 - if (is_kernel_text(addr))
32655 + if (is_kernel_text(address, address + PAGE_SIZE))
32656 prot = PAGE_KERNEL_EXEC;
32657
32658 pages_4k++;
32659 @@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
32660
32661 pud = pud_offset(pgd, va);
32662 pmd = pmd_offset(pud, va);
32663 - if (!pmd_present(*pmd))
32664 + if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
32665 break;
32666
32667 /* should not be large page here */
32668 @@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
32669
32670 static void __init pagetable_init(void)
32671 {
32672 - pgd_t *pgd_base = swapper_pg_dir;
32673 -
32674 - permanent_kmaps_init(pgd_base);
32675 + permanent_kmaps_init(swapper_pg_dir);
32676 }
32677
32678 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
32679 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
32680 EXPORT_SYMBOL_GPL(__supported_pte_mask);
32681
32682 /* user-defined highmem size */
32683 @@ -787,10 +789,10 @@ void __init mem_init(void)
32684 ((unsigned long)&__init_end -
32685 (unsigned long)&__init_begin) >> 10,
32686
32687 - (unsigned long)&_etext, (unsigned long)&_edata,
32688 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
32689 + (unsigned long)&_sdata, (unsigned long)&_edata,
32690 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
32691
32692 - (unsigned long)&_text, (unsigned long)&_etext,
32693 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
32694 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
32695
32696 /*
32697 @@ -883,6 +885,7 @@ void set_kernel_text_rw(void)
32698 if (!kernel_set_to_readonly)
32699 return;
32700
32701 + start = ktla_ktva(start);
32702 pr_debug("Set kernel text: %lx - %lx for read write\n",
32703 start, start+size);
32704
32705 @@ -897,6 +900,7 @@ void set_kernel_text_ro(void)
32706 if (!kernel_set_to_readonly)
32707 return;
32708
32709 + start = ktla_ktva(start);
32710 pr_debug("Set kernel text: %lx - %lx for read only\n",
32711 start, start+size);
32712
32713 @@ -925,6 +929,7 @@ void mark_rodata_ro(void)
32714 unsigned long start = PFN_ALIGN(_text);
32715 unsigned long size = PFN_ALIGN(_etext) - start;
32716
32717 + start = ktla_ktva(start);
32718 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
32719 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
32720 size >> 10);
32721 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
32722 index f35c66c..84b95ef 100644
32723 --- a/arch/x86/mm/init_64.c
32724 +++ b/arch/x86/mm/init_64.c
32725 @@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
32726 * around without checking the pgd every time.
32727 */
32728
32729 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
32730 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
32731 EXPORT_SYMBOL_GPL(__supported_pte_mask);
32732
32733 int force_personality32;
32734 @@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32735
32736 for (address = start; address <= end; address += PGDIR_SIZE) {
32737 const pgd_t *pgd_ref = pgd_offset_k(address);
32738 +
32739 +#ifdef CONFIG_PAX_PER_CPU_PGD
32740 + unsigned long cpu;
32741 +#else
32742 struct page *page;
32743 +#endif
32744
32745 if (pgd_none(*pgd_ref))
32746 continue;
32747
32748 spin_lock(&pgd_lock);
32749 +
32750 +#ifdef CONFIG_PAX_PER_CPU_PGD
32751 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
32752 + pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
32753 +
32754 + if (pgd_none(*pgd))
32755 + set_pgd(pgd, *pgd_ref);
32756 + else
32757 + BUG_ON(pgd_page_vaddr(*pgd)
32758 + != pgd_page_vaddr(*pgd_ref));
32759 + pgd = pgd_offset_cpu(cpu, kernel, address);
32760 +#else
32761 list_for_each_entry(page, &pgd_list, lru) {
32762 pgd_t *pgd;
32763 spinlock_t *pgt_lock;
32764 @@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32765 /* the pgt_lock only for Xen */
32766 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
32767 spin_lock(pgt_lock);
32768 +#endif
32769
32770 if (pgd_none(*pgd))
32771 set_pgd(pgd, *pgd_ref);
32772 @@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32773 BUG_ON(pgd_page_vaddr(*pgd)
32774 != pgd_page_vaddr(*pgd_ref));
32775
32776 +#ifndef CONFIG_PAX_PER_CPU_PGD
32777 spin_unlock(pgt_lock);
32778 +#endif
32779 +
32780 }
32781 spin_unlock(&pgd_lock);
32782 }
32783 @@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
32784 {
32785 if (pgd_none(*pgd)) {
32786 pud_t *pud = (pud_t *)spp_getpage();
32787 - pgd_populate(&init_mm, pgd, pud);
32788 + pgd_populate_kernel(&init_mm, pgd, pud);
32789 if (pud != pud_offset(pgd, 0))
32790 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
32791 pud, pud_offset(pgd, 0));
32792 @@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
32793 {
32794 if (pud_none(*pud)) {
32795 pmd_t *pmd = (pmd_t *) spp_getpage();
32796 - pud_populate(&init_mm, pud, pmd);
32797 + pud_populate_kernel(&init_mm, pud, pmd);
32798 if (pmd != pmd_offset(pud, 0))
32799 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
32800 pmd, pmd_offset(pud, 0));
32801 @@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
32802 pmd = fill_pmd(pud, vaddr);
32803 pte = fill_pte(pmd, vaddr);
32804
32805 + pax_open_kernel();
32806 set_pte(pte, new_pte);
32807 + pax_close_kernel();
32808
32809 /*
32810 * It's enough to flush this one mapping.
32811 @@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
32812 pgd = pgd_offset_k((unsigned long)__va(phys));
32813 if (pgd_none(*pgd)) {
32814 pud = (pud_t *) spp_getpage();
32815 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
32816 - _PAGE_USER));
32817 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
32818 }
32819 pud = pud_offset(pgd, (unsigned long)__va(phys));
32820 if (pud_none(*pud)) {
32821 pmd = (pmd_t *) spp_getpage();
32822 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
32823 - _PAGE_USER));
32824 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
32825 }
32826 pmd = pmd_offset(pud, phys);
32827 BUG_ON(!pmd_none(*pmd));
32828 @@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
32829 prot);
32830
32831 spin_lock(&init_mm.page_table_lock);
32832 - pud_populate(&init_mm, pud, pmd);
32833 + pud_populate_kernel(&init_mm, pud, pmd);
32834 spin_unlock(&init_mm.page_table_lock);
32835 }
32836 __flush_tlb_all();
32837 @@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
32838 page_size_mask);
32839
32840 spin_lock(&init_mm.page_table_lock);
32841 - pgd_populate(&init_mm, pgd, pud);
32842 + pgd_populate_kernel(&init_mm, pgd, pud);
32843 spin_unlock(&init_mm.page_table_lock);
32844 pgd_changed = true;
32845 }
32846 @@ -1188,8 +1209,8 @@ int kern_addr_valid(unsigned long addr)
32847 static struct vm_area_struct gate_vma = {
32848 .vm_start = VSYSCALL_START,
32849 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
32850 - .vm_page_prot = PAGE_READONLY_EXEC,
32851 - .vm_flags = VM_READ | VM_EXEC
32852 + .vm_page_prot = PAGE_READONLY,
32853 + .vm_flags = VM_READ
32854 };
32855
32856 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
32857 @@ -1223,7 +1244,7 @@ int in_gate_area_no_mm(unsigned long addr)
32858
32859 const char *arch_vma_name(struct vm_area_struct *vma)
32860 {
32861 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
32862 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
32863 return "[vdso]";
32864 if (vma == &gate_vma)
32865 return "[vsyscall]";
32866 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
32867 index 7b179b4..6bd17777 100644
32868 --- a/arch/x86/mm/iomap_32.c
32869 +++ b/arch/x86/mm/iomap_32.c
32870 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
32871 type = kmap_atomic_idx_push();
32872 idx = type + KM_TYPE_NR * smp_processor_id();
32873 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
32874 +
32875 + pax_open_kernel();
32876 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
32877 + pax_close_kernel();
32878 +
32879 arch_flush_lazy_mmu_mode();
32880
32881 return (void *)vaddr;
32882 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
32883 index 597ac15..49841be 100644
32884 --- a/arch/x86/mm/ioremap.c
32885 +++ b/arch/x86/mm/ioremap.c
32886 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
32887 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
32888 int is_ram = page_is_ram(pfn);
32889
32890 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
32891 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
32892 return NULL;
32893 WARN_ON_ONCE(is_ram);
32894 }
32895 @@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
32896 *
32897 * Caller must ensure there is only one unmapping for the same pointer.
32898 */
32899 -void iounmap(volatile void __iomem *addr)
32900 +void iounmap(const volatile void __iomem *addr)
32901 {
32902 struct vm_struct *p, *o;
32903
32904 @@ -310,6 +310,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
32905
32906 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
32907 if (page_is_ram(start >> PAGE_SHIFT))
32908 +#ifdef CONFIG_HIGHMEM
32909 + if ((start >> PAGE_SHIFT) < max_low_pfn)
32910 +#endif
32911 return __va(phys);
32912
32913 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
32914 @@ -322,13 +325,16 @@ void *xlate_dev_mem_ptr(unsigned long phys)
32915 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
32916 {
32917 if (page_is_ram(phys >> PAGE_SHIFT))
32918 +#ifdef CONFIG_HIGHMEM
32919 + if ((phys >> PAGE_SHIFT) < max_low_pfn)
32920 +#endif
32921 return;
32922
32923 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
32924 return;
32925 }
32926
32927 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
32928 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
32929
32930 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
32931 {
32932 @@ -358,8 +364,7 @@ void __init early_ioremap_init(void)
32933 early_ioremap_setup();
32934
32935 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
32936 - memset(bm_pte, 0, sizeof(bm_pte));
32937 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
32938 + pmd_populate_user(&init_mm, pmd, bm_pte);
32939
32940 /*
32941 * The boot-ioremap range spans multiple pmds, for which
32942 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
32943 index dd89a13..d77bdcc 100644
32944 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
32945 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
32946 @@ -628,9 +628,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
32947 * memory (e.g. tracked pages)? For now, we need this to avoid
32948 * invoking kmemcheck for PnP BIOS calls.
32949 */
32950 - if (regs->flags & X86_VM_MASK)
32951 + if (v8086_mode(regs))
32952 return false;
32953 - if (regs->cs != __KERNEL_CS)
32954 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
32955 return false;
32956
32957 pte = kmemcheck_pte_lookup(address);
32958 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
32959 index 25e7e13..1964579 100644
32960 --- a/arch/x86/mm/mmap.c
32961 +++ b/arch/x86/mm/mmap.c
32962 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
32963 * Leave an at least ~128 MB hole with possible stack randomization.
32964 */
32965 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
32966 -#define MAX_GAP (TASK_SIZE/6*5)
32967 +#define MAX_GAP (pax_task_size/6*5)
32968
32969 static int mmap_is_legacy(void)
32970 {
32971 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
32972 return rnd << PAGE_SHIFT;
32973 }
32974
32975 -static unsigned long mmap_base(void)
32976 +static unsigned long mmap_base(struct mm_struct *mm)
32977 {
32978 unsigned long gap = rlimit(RLIMIT_STACK);
32979 + unsigned long pax_task_size = TASK_SIZE;
32980 +
32981 +#ifdef CONFIG_PAX_SEGMEXEC
32982 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
32983 + pax_task_size = SEGMEXEC_TASK_SIZE;
32984 +#endif
32985
32986 if (gap < MIN_GAP)
32987 gap = MIN_GAP;
32988 else if (gap > MAX_GAP)
32989 gap = MAX_GAP;
32990
32991 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
32992 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
32993 }
32994
32995 /*
32996 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
32997 * does, but not when emulating X86_32
32998 */
32999 -static unsigned long mmap_legacy_base(void)
33000 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
33001 {
33002 - if (mmap_is_ia32())
33003 + if (mmap_is_ia32()) {
33004 +
33005 +#ifdef CONFIG_PAX_SEGMEXEC
33006 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
33007 + return SEGMEXEC_TASK_UNMAPPED_BASE;
33008 + else
33009 +#endif
33010 +
33011 return TASK_UNMAPPED_BASE;
33012 - else
33013 + } else
33014 return TASK_UNMAPPED_BASE + mmap_rnd();
33015 }
33016
33017 @@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
33018 */
33019 void arch_pick_mmap_layout(struct mm_struct *mm)
33020 {
33021 - mm->mmap_legacy_base = mmap_legacy_base();
33022 - mm->mmap_base = mmap_base();
33023 + mm->mmap_legacy_base = mmap_legacy_base(mm);
33024 + mm->mmap_base = mmap_base(mm);
33025 +
33026 +#ifdef CONFIG_PAX_RANDMMAP
33027 + if (mm->pax_flags & MF_PAX_RANDMMAP) {
33028 + mm->mmap_legacy_base += mm->delta_mmap;
33029 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
33030 + }
33031 +#endif
33032
33033 if (mmap_is_legacy()) {
33034 mm->mmap_base = mm->mmap_legacy_base;
33035 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
33036 index 0057a7a..95c7edd 100644
33037 --- a/arch/x86/mm/mmio-mod.c
33038 +++ b/arch/x86/mm/mmio-mod.c
33039 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
33040 break;
33041 default:
33042 {
33043 - unsigned char *ip = (unsigned char *)instptr;
33044 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
33045 my_trace->opcode = MMIO_UNKNOWN_OP;
33046 my_trace->width = 0;
33047 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
33048 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
33049 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
33050 void __iomem *addr)
33051 {
33052 - static atomic_t next_id;
33053 + static atomic_unchecked_t next_id;
33054 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
33055 /* These are page-unaligned. */
33056 struct mmiotrace_map map = {
33057 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
33058 .private = trace
33059 },
33060 .phys = offset,
33061 - .id = atomic_inc_return(&next_id)
33062 + .id = atomic_inc_return_unchecked(&next_id)
33063 };
33064 map.map_id = trace->id;
33065
33066 @@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
33067 ioremap_trace_core(offset, size, addr);
33068 }
33069
33070 -static void iounmap_trace_core(volatile void __iomem *addr)
33071 +static void iounmap_trace_core(const volatile void __iomem *addr)
33072 {
33073 struct mmiotrace_map map = {
33074 .phys = 0,
33075 @@ -328,7 +328,7 @@ not_enabled:
33076 }
33077 }
33078
33079 -void mmiotrace_iounmap(volatile void __iomem *addr)
33080 +void mmiotrace_iounmap(const volatile void __iomem *addr)
33081 {
33082 might_sleep();
33083 if (is_enabled()) /* recheck and proper locking in *_core() */
33084 diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
33085 index 1d045f9..3a00249 100644
33086 --- a/arch/x86/mm/numa.c
33087 +++ b/arch/x86/mm/numa.c
33088 @@ -478,7 +478,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
33089 return true;
33090 }
33091
33092 -static int __init numa_register_memblks(struct numa_meminfo *mi)
33093 +static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
33094 {
33095 unsigned long uninitialized_var(pfn_align);
33096 int i, nid;
33097 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
33098 index 461bc82..4e091a3 100644
33099 --- a/arch/x86/mm/pageattr-test.c
33100 +++ b/arch/x86/mm/pageattr-test.c
33101 @@ -35,7 +35,7 @@ enum {
33102
33103 static int pte_testbit(pte_t pte)
33104 {
33105 - return pte_flags(pte) & _PAGE_UNUSED1;
33106 + return pte_flags(pte) & _PAGE_CPA_TEST;
33107 }
33108
33109 struct split_state {
33110 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
33111 index ae242a7..1c7998f 100644
33112 --- a/arch/x86/mm/pageattr.c
33113 +++ b/arch/x86/mm/pageattr.c
33114 @@ -262,7 +262,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33115 */
33116 #ifdef CONFIG_PCI_BIOS
33117 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
33118 - pgprot_val(forbidden) |= _PAGE_NX;
33119 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33120 #endif
33121
33122 /*
33123 @@ -270,9 +270,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33124 * Does not cover __inittext since that is gone later on. On
33125 * 64bit we do not enforce !NX on the low mapping
33126 */
33127 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
33128 - pgprot_val(forbidden) |= _PAGE_NX;
33129 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
33130 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33131
33132 +#ifdef CONFIG_DEBUG_RODATA
33133 /*
33134 * The .rodata section needs to be read-only. Using the pfn
33135 * catches all aliases.
33136 @@ -280,6 +281,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33137 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
33138 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
33139 pgprot_val(forbidden) |= _PAGE_RW;
33140 +#endif
33141
33142 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
33143 /*
33144 @@ -318,6 +320,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
33145 }
33146 #endif
33147
33148 +#ifdef CONFIG_PAX_KERNEXEC
33149 + if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
33150 + pgprot_val(forbidden) |= _PAGE_RW;
33151 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
33152 + }
33153 +#endif
33154 +
33155 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
33156
33157 return prot;
33158 @@ -420,23 +429,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
33159 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
33160 {
33161 /* change init_mm */
33162 + pax_open_kernel();
33163 set_pte_atomic(kpte, pte);
33164 +
33165 #ifdef CONFIG_X86_32
33166 if (!SHARED_KERNEL_PMD) {
33167 +
33168 +#ifdef CONFIG_PAX_PER_CPU_PGD
33169 + unsigned long cpu;
33170 +#else
33171 struct page *page;
33172 +#endif
33173
33174 +#ifdef CONFIG_PAX_PER_CPU_PGD
33175 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
33176 + pgd_t *pgd = get_cpu_pgd(cpu, kernel);
33177 +#else
33178 list_for_each_entry(page, &pgd_list, lru) {
33179 - pgd_t *pgd;
33180 + pgd_t *pgd = (pgd_t *)page_address(page);
33181 +#endif
33182 +
33183 pud_t *pud;
33184 pmd_t *pmd;
33185
33186 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
33187 + pgd += pgd_index(address);
33188 pud = pud_offset(pgd, address);
33189 pmd = pmd_offset(pud, address);
33190 set_pte_atomic((pte_t *)pmd, pte);
33191 }
33192 }
33193 #endif
33194 + pax_close_kernel();
33195 }
33196
33197 static int
33198 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
33199 index 6574388..87e9bef 100644
33200 --- a/arch/x86/mm/pat.c
33201 +++ b/arch/x86/mm/pat.c
33202 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
33203
33204 if (!entry) {
33205 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
33206 - current->comm, current->pid, start, end - 1);
33207 + current->comm, task_pid_nr(current), start, end - 1);
33208 return -EINVAL;
33209 }
33210
33211 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
33212
33213 while (cursor < to) {
33214 if (!devmem_is_allowed(pfn)) {
33215 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
33216 - current->comm, from, to - 1);
33217 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
33218 + current->comm, from, to - 1, cursor);
33219 return 0;
33220 }
33221 cursor += PAGE_SIZE;
33222 @@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
33223 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
33224 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
33225 "for [mem %#010Lx-%#010Lx]\n",
33226 - current->comm, current->pid,
33227 + current->comm, task_pid_nr(current),
33228 cattr_name(flags),
33229 base, (unsigned long long)(base + size-1));
33230 return -EINVAL;
33231 @@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33232 flags = lookup_memtype(paddr);
33233 if (want_flags != flags) {
33234 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
33235 - current->comm, current->pid,
33236 + current->comm, task_pid_nr(current),
33237 cattr_name(want_flags),
33238 (unsigned long long)paddr,
33239 (unsigned long long)(paddr + size - 1),
33240 @@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
33241 free_memtype(paddr, paddr + size);
33242 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
33243 " for [mem %#010Lx-%#010Lx], got %s\n",
33244 - current->comm, current->pid,
33245 + current->comm, task_pid_nr(current),
33246 cattr_name(want_flags),
33247 (unsigned long long)paddr,
33248 (unsigned long long)(paddr + size - 1),
33249 diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
33250 index 415f6c4..d319983 100644
33251 --- a/arch/x86/mm/pat_rbtree.c
33252 +++ b/arch/x86/mm/pat_rbtree.c
33253 @@ -160,7 +160,7 @@ success:
33254
33255 failure:
33256 printk(KERN_INFO "%s:%d conflicting memory types "
33257 - "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
33258 + "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
33259 end, cattr_name(found_type), cattr_name(match->type));
33260 return -EBUSY;
33261 }
33262 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
33263 index 9f0614d..92ae64a 100644
33264 --- a/arch/x86/mm/pf_in.c
33265 +++ b/arch/x86/mm/pf_in.c
33266 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
33267 int i;
33268 enum reason_type rv = OTHERS;
33269
33270 - p = (unsigned char *)ins_addr;
33271 + p = (unsigned char *)ktla_ktva(ins_addr);
33272 p += skip_prefix(p, &prf);
33273 p += get_opcode(p, &opcode);
33274
33275 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
33276 struct prefix_bits prf;
33277 int i;
33278
33279 - p = (unsigned char *)ins_addr;
33280 + p = (unsigned char *)ktla_ktva(ins_addr);
33281 p += skip_prefix(p, &prf);
33282 p += get_opcode(p, &opcode);
33283
33284 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
33285 struct prefix_bits prf;
33286 int i;
33287
33288 - p = (unsigned char *)ins_addr;
33289 + p = (unsigned char *)ktla_ktva(ins_addr);
33290 p += skip_prefix(p, &prf);
33291 p += get_opcode(p, &opcode);
33292
33293 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
33294 struct prefix_bits prf;
33295 int i;
33296
33297 - p = (unsigned char *)ins_addr;
33298 + p = (unsigned char *)ktla_ktva(ins_addr);
33299 p += skip_prefix(p, &prf);
33300 p += get_opcode(p, &opcode);
33301 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
33302 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
33303 struct prefix_bits prf;
33304 int i;
33305
33306 - p = (unsigned char *)ins_addr;
33307 + p = (unsigned char *)ktla_ktva(ins_addr);
33308 p += skip_prefix(p, &prf);
33309 p += get_opcode(p, &opcode);
33310 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
33311 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
33312 index c96314a..433b127 100644
33313 --- a/arch/x86/mm/pgtable.c
33314 +++ b/arch/x86/mm/pgtable.c
33315 @@ -97,10 +97,71 @@ static inline void pgd_list_del(pgd_t *pgd)
33316 list_del(&page->lru);
33317 }
33318
33319 -#define UNSHARED_PTRS_PER_PGD \
33320 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33321 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33322 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
33323
33324 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
33325 +{
33326 + unsigned int count = USER_PGD_PTRS;
33327
33328 + if (!pax_user_shadow_base)
33329 + return;
33330 +
33331 + while (count--)
33332 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
33333 +}
33334 +#endif
33335 +
33336 +#ifdef CONFIG_PAX_PER_CPU_PGD
33337 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
33338 +{
33339 + unsigned int count = USER_PGD_PTRS;
33340 +
33341 + while (count--) {
33342 + pgd_t pgd;
33343 +
33344 +#ifdef CONFIG_X86_64
33345 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
33346 +#else
33347 + pgd = *src++;
33348 +#endif
33349 +
33350 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
33351 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
33352 +#endif
33353 +
33354 + *dst++ = pgd;
33355 + }
33356 +
33357 +}
33358 +#endif
33359 +
33360 +#ifdef CONFIG_X86_64
33361 +#define pxd_t pud_t
33362 +#define pyd_t pgd_t
33363 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
33364 +#define pgtable_pxd_page_ctor(page) true
33365 +#define pgtable_pxd_page_dtor(page)
33366 +#define pxd_free(mm, pud) pud_free((mm), (pud))
33367 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
33368 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
33369 +#define PYD_SIZE PGDIR_SIZE
33370 +#else
33371 +#define pxd_t pmd_t
33372 +#define pyd_t pud_t
33373 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
33374 +#define pgtable_pxd_page_ctor(page) pgtable_pmd_page_ctor(page)
33375 +#define pgtable_pxd_page_dtor(page) pgtable_pmd_page_dtor(page)
33376 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
33377 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
33378 +#define pyd_offset(mm, address) pud_offset((mm), (address))
33379 +#define PYD_SIZE PUD_SIZE
33380 +#endif
33381 +
33382 +#ifdef CONFIG_PAX_PER_CPU_PGD
33383 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
33384 +static inline void pgd_dtor(pgd_t *pgd) {}
33385 +#else
33386 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
33387 {
33388 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
33389 @@ -141,6 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
33390 pgd_list_del(pgd);
33391 spin_unlock(&pgd_lock);
33392 }
33393 +#endif
33394
33395 /*
33396 * List of all pgd's needed for non-PAE so it can invalidate entries
33397 @@ -153,7 +215,7 @@ static void pgd_dtor(pgd_t *pgd)
33398 * -- nyc
33399 */
33400
33401 -#ifdef CONFIG_X86_PAE
33402 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
33403 /*
33404 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
33405 * updating the top-level pagetable entries to guarantee the
33406 @@ -165,7 +227,7 @@ static void pgd_dtor(pgd_t *pgd)
33407 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
33408 * and initialize the kernel pmds here.
33409 */
33410 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
33411 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
33412
33413 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33414 {
33415 @@ -183,43 +245,45 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
33416 */
33417 flush_tlb_mm(mm);
33418 }
33419 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
33420 +#define PREALLOCATED_PXDS USER_PGD_PTRS
33421 #else /* !CONFIG_X86_PAE */
33422
33423 /* No need to prepopulate any pagetable entries in non-PAE modes. */
33424 -#define PREALLOCATED_PMDS 0
33425 +#define PREALLOCATED_PXDS 0
33426
33427 #endif /* CONFIG_X86_PAE */
33428
33429 -static void free_pmds(pmd_t *pmds[])
33430 +static void free_pxds(pxd_t *pxds[])
33431 {
33432 int i;
33433
33434 - for(i = 0; i < PREALLOCATED_PMDS; i++)
33435 - if (pmds[i]) {
33436 - pgtable_pmd_page_dtor(virt_to_page(pmds[i]));
33437 - free_page((unsigned long)pmds[i]);
33438 + for(i = 0; i < PREALLOCATED_PXDS; i++)
33439 + if (pxds[i]) {
33440 + pgtable_pxd_page_dtor(virt_to_page(pxds[i]));
33441 + free_page((unsigned long)pxds[i]);
33442 }
33443 }
33444
33445 -static int preallocate_pmds(pmd_t *pmds[])
33446 +static int preallocate_pxds(pxd_t *pxds[])
33447 {
33448 int i;
33449 bool failed = false;
33450
33451 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
33452 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
33453 - if (!pmd)
33454 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
33455 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
33456 + if (!pxd)
33457 failed = true;
33458 - if (pmd && !pgtable_pmd_page_ctor(virt_to_page(pmd))) {
33459 - free_page((unsigned long)pmd);
33460 - pmd = NULL;
33461 + if (pxd && !pgtable_pxd_page_ctor(virt_to_page(pxd))) {
33462 + free_page((unsigned long)pxd);
33463 + pxd = NULL;
33464 failed = true;
33465 }
33466 - pmds[i] = pmd;
33467 + pxds[i] = pxd;
33468 }
33469
33470 if (failed) {
33471 - free_pmds(pmds);
33472 + free_pxds(pxds);
33473 return -ENOMEM;
33474 }
33475
33476 @@ -232,49 +296,52 @@ static int preallocate_pmds(pmd_t *pmds[])
33477 * preallocate which never got a corresponding vma will need to be
33478 * freed manually.
33479 */
33480 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
33481 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
33482 {
33483 int i;
33484
33485 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
33486 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
33487 pgd_t pgd = pgdp[i];
33488
33489 if (pgd_val(pgd) != 0) {
33490 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
33491 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
33492
33493 - pgdp[i] = native_make_pgd(0);
33494 + set_pgd(pgdp + i, native_make_pgd(0));
33495
33496 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
33497 - pmd_free(mm, pmd);
33498 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
33499 + pxd_free(mm, pxd);
33500 }
33501 }
33502 }
33503
33504 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
33505 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
33506 {
33507 - pud_t *pud;
33508 + pyd_t *pyd;
33509 int i;
33510
33511 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
33512 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
33513 return;
33514
33515 - pud = pud_offset(pgd, 0);
33516 -
33517 - for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
33518 - pmd_t *pmd = pmds[i];
33519 +#ifdef CONFIG_X86_64
33520 + pyd = pyd_offset(mm, 0L);
33521 +#else
33522 + pyd = pyd_offset(pgd, 0L);
33523 +#endif
33524
33525 + for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
33526 + pxd_t *pxd = pxds[i];
33527 if (i >= KERNEL_PGD_BOUNDARY)
33528 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33529 - sizeof(pmd_t) * PTRS_PER_PMD);
33530 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
33531 + sizeof(pxd_t) * PTRS_PER_PMD);
33532
33533 - pud_populate(mm, pud, pmd);
33534 + pyd_populate(mm, pyd, pxd);
33535 }
33536 }
33537
33538 pgd_t *pgd_alloc(struct mm_struct *mm)
33539 {
33540 pgd_t *pgd;
33541 - pmd_t *pmds[PREALLOCATED_PMDS];
33542 + pxd_t *pxds[PREALLOCATED_PXDS];
33543
33544 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
33545
33546 @@ -283,11 +350,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33547
33548 mm->pgd = pgd;
33549
33550 - if (preallocate_pmds(pmds) != 0)
33551 + if (preallocate_pxds(pxds) != 0)
33552 goto out_free_pgd;
33553
33554 if (paravirt_pgd_alloc(mm) != 0)
33555 - goto out_free_pmds;
33556 + goto out_free_pxds;
33557
33558 /*
33559 * Make sure that pre-populating the pmds is atomic with
33560 @@ -297,14 +364,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
33561 spin_lock(&pgd_lock);
33562
33563 pgd_ctor(mm, pgd);
33564 - pgd_prepopulate_pmd(mm, pgd, pmds);
33565 + pgd_prepopulate_pxd(mm, pgd, pxds);
33566
33567 spin_unlock(&pgd_lock);
33568
33569 return pgd;
33570
33571 -out_free_pmds:
33572 - free_pmds(pmds);
33573 +out_free_pxds:
33574 + free_pxds(pxds);
33575 out_free_pgd:
33576 free_page((unsigned long)pgd);
33577 out:
33578 @@ -313,7 +380,7 @@ out:
33579
33580 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
33581 {
33582 - pgd_mop_up_pmds(mm, pgd);
33583 + pgd_mop_up_pxds(mm, pgd);
33584 pgd_dtor(pgd);
33585 paravirt_pgd_free(mm, pgd);
33586 free_page((unsigned long)pgd);
33587 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
33588 index 4dd8cf6..f9d143e 100644
33589 --- a/arch/x86/mm/pgtable_32.c
33590 +++ b/arch/x86/mm/pgtable_32.c
33591 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
33592 return;
33593 }
33594 pte = pte_offset_kernel(pmd, vaddr);
33595 +
33596 + pax_open_kernel();
33597 if (pte_val(pteval))
33598 set_pte_at(&init_mm, vaddr, pte, pteval);
33599 else
33600 pte_clear(&init_mm, vaddr, pte);
33601 + pax_close_kernel();
33602
33603 /*
33604 * It's enough to flush this one mapping.
33605 diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
33606 index e666cbb..61788c45 100644
33607 --- a/arch/x86/mm/physaddr.c
33608 +++ b/arch/x86/mm/physaddr.c
33609 @@ -10,7 +10,7 @@
33610 #ifdef CONFIG_X86_64
33611
33612 #ifdef CONFIG_DEBUG_VIRTUAL
33613 -unsigned long __phys_addr(unsigned long x)
33614 +unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
33615 {
33616 unsigned long y = x - __START_KERNEL_map;
33617
33618 @@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
33619 #else
33620
33621 #ifdef CONFIG_DEBUG_VIRTUAL
33622 -unsigned long __phys_addr(unsigned long x)
33623 +unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
33624 {
33625 unsigned long phys_addr = x - PAGE_OFFSET;
33626 /* VMALLOC_* aren't constants */
33627 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
33628 index 90555bf..f5f1828 100644
33629 --- a/arch/x86/mm/setup_nx.c
33630 +++ b/arch/x86/mm/setup_nx.c
33631 @@ -5,8 +5,10 @@
33632 #include <asm/pgtable.h>
33633 #include <asm/proto.h>
33634
33635 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
33636 static int disable_nx;
33637
33638 +#ifndef CONFIG_PAX_PAGEEXEC
33639 /*
33640 * noexec = on|off
33641 *
33642 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
33643 return 0;
33644 }
33645 early_param("noexec", noexec_setup);
33646 +#endif
33647 +
33648 +#endif
33649
33650 void x86_configure_nx(void)
33651 {
33652 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
33653 if (cpu_has_nx && !disable_nx)
33654 __supported_pte_mask |= _PAGE_NX;
33655 else
33656 +#endif
33657 __supported_pte_mask &= ~_PAGE_NX;
33658 }
33659
33660 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
33661 index dd8dda1..9e9b0f6 100644
33662 --- a/arch/x86/mm/tlb.c
33663 +++ b/arch/x86/mm/tlb.c
33664 @@ -48,7 +48,11 @@ void leave_mm(int cpu)
33665 BUG();
33666 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
33667 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
33668 +
33669 +#ifndef CONFIG_PAX_PER_CPU_PGD
33670 load_cr3(swapper_pg_dir);
33671 +#endif
33672 +
33673 }
33674 }
33675 EXPORT_SYMBOL_GPL(leave_mm);
33676 diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
33677 new file mode 100644
33678 index 0000000..dace51c
33679 --- /dev/null
33680 +++ b/arch/x86/mm/uderef_64.c
33681 @@ -0,0 +1,37 @@
33682 +#include <linux/mm.h>
33683 +#include <asm/pgtable.h>
33684 +#include <asm/uaccess.h>
33685 +
33686 +#ifdef CONFIG_PAX_MEMORY_UDEREF
33687 +/* PaX: due to the special call convention these functions must
33688 + * - remain leaf functions under all configurations,
33689 + * - never be called directly, only dereferenced from the wrappers.
33690 + */
33691 +void __pax_open_userland(void)
33692 +{
33693 + unsigned int cpu;
33694 +
33695 + if (unlikely(!segment_eq(get_fs(), USER_DS)))
33696 + return;
33697 +
33698 + cpu = raw_get_cpu();
33699 + BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
33700 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
33701 + raw_put_cpu_no_resched();
33702 +}
33703 +EXPORT_SYMBOL(__pax_open_userland);
33704 +
33705 +void __pax_close_userland(void)
33706 +{
33707 + unsigned int cpu;
33708 +
33709 + if (unlikely(!segment_eq(get_fs(), USER_DS)))
33710 + return;
33711 +
33712 + cpu = raw_get_cpu();
33713 + BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
33714 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
33715 + raw_put_cpu_no_resched();
33716 +}
33717 +EXPORT_SYMBOL(__pax_close_userland);
33718 +#endif
33719 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
33720 index 0149575..f746de8 100644
33721 --- a/arch/x86/net/bpf_jit.S
33722 +++ b/arch/x86/net/bpf_jit.S
33723 @@ -9,6 +9,7 @@
33724 */
33725 #include <linux/linkage.h>
33726 #include <asm/dwarf2.h>
33727 +#include <asm/alternative-asm.h>
33728
33729 /*
33730 * Calling convention :
33731 @@ -35,6 +36,7 @@ sk_load_word_positive_offset:
33732 jle bpf_slow_path_word
33733 mov (SKBDATA,%rsi),%eax
33734 bswap %eax /* ntohl() */
33735 + pax_force_retaddr
33736 ret
33737
33738 sk_load_half:
33739 @@ -52,6 +54,7 @@ sk_load_half_positive_offset:
33740 jle bpf_slow_path_half
33741 movzwl (SKBDATA,%rsi),%eax
33742 rol $8,%ax # ntohs()
33743 + pax_force_retaddr
33744 ret
33745
33746 sk_load_byte:
33747 @@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
33748 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
33749 jle bpf_slow_path_byte
33750 movzbl (SKBDATA,%rsi),%eax
33751 + pax_force_retaddr
33752 ret
33753
33754 /**
33755 @@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
33756 movzbl (SKBDATA,%rsi),%ebx
33757 and $15,%bl
33758 shl $2,%bl
33759 + pax_force_retaddr
33760 ret
33761
33762 /* rsi contains offset and can be scratched */
33763 @@ -109,6 +114,7 @@ bpf_slow_path_word:
33764 js bpf_error
33765 mov -12(%rbp),%eax
33766 bswap %eax
33767 + pax_force_retaddr
33768 ret
33769
33770 bpf_slow_path_half:
33771 @@ -117,12 +123,14 @@ bpf_slow_path_half:
33772 mov -12(%rbp),%ax
33773 rol $8,%ax
33774 movzwl %ax,%eax
33775 + pax_force_retaddr
33776 ret
33777
33778 bpf_slow_path_byte:
33779 bpf_slow_path_common(1)
33780 js bpf_error
33781 movzbl -12(%rbp),%eax
33782 + pax_force_retaddr
33783 ret
33784
33785 bpf_slow_path_byte_msh:
33786 @@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
33787 and $15,%al
33788 shl $2,%al
33789 xchg %eax,%ebx
33790 + pax_force_retaddr
33791 ret
33792
33793 #define sk_negative_common(SIZE) \
33794 @@ -157,6 +166,7 @@ sk_load_word_negative_offset:
33795 sk_negative_common(4)
33796 mov (%rax), %eax
33797 bswap %eax
33798 + pax_force_retaddr
33799 ret
33800
33801 bpf_slow_path_half_neg:
33802 @@ -168,6 +178,7 @@ sk_load_half_negative_offset:
33803 mov (%rax),%ax
33804 rol $8,%ax
33805 movzwl %ax,%eax
33806 + pax_force_retaddr
33807 ret
33808
33809 bpf_slow_path_byte_neg:
33810 @@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
33811 .globl sk_load_byte_negative_offset
33812 sk_negative_common(1)
33813 movzbl (%rax), %eax
33814 + pax_force_retaddr
33815 ret
33816
33817 bpf_slow_path_byte_msh_neg:
33818 @@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
33819 and $15,%al
33820 shl $2,%al
33821 xchg %eax,%ebx
33822 + pax_force_retaddr
33823 ret
33824
33825 bpf_error:
33826 @@ -197,4 +210,5 @@ bpf_error:
33827 xor %eax,%eax
33828 mov -8(%rbp),%rbx
33829 leaveq
33830 + pax_force_retaddr
33831 ret
33832 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
33833 index 6d5663a..f1ec380 100644
33834 --- a/arch/x86/net/bpf_jit_comp.c
33835 +++ b/arch/x86/net/bpf_jit_comp.c
33836 @@ -50,13 +50,90 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
33837 return ptr + len;
33838 }
33839
33840 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33841 +#define MAX_INSTR_CODE_SIZE 96
33842 +#else
33843 +#define MAX_INSTR_CODE_SIZE 64
33844 +#endif
33845 +
33846 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
33847
33848 #define EMIT1(b1) EMIT(b1, 1)
33849 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
33850 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
33851 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
33852 +
33853 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33854 +/* original constant will appear in ecx */
33855 +#define DILUTE_CONST_SEQUENCE(_off, _key) \
33856 +do { \
33857 + /* mov ecx, randkey */ \
33858 + EMIT1(0xb9); \
33859 + EMIT(_key, 4); \
33860 + /* xor ecx, randkey ^ off */ \
33861 + EMIT2(0x81, 0xf1); \
33862 + EMIT((_key) ^ (_off), 4); \
33863 +} while (0)
33864 +
33865 +#define EMIT1_off32(b1, _off) \
33866 +do { \
33867 + switch (b1) { \
33868 + case 0x05: /* add eax, imm32 */ \
33869 + case 0x2d: /* sub eax, imm32 */ \
33870 + case 0x25: /* and eax, imm32 */ \
33871 + case 0x0d: /* or eax, imm32 */ \
33872 + case 0xb8: /* mov eax, imm32 */ \
33873 + case 0x35: /* xor eax, imm32 */ \
33874 + case 0x3d: /* cmp eax, imm32 */ \
33875 + case 0xa9: /* test eax, imm32 */ \
33876 + DILUTE_CONST_SEQUENCE(_off, randkey); \
33877 + EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
33878 + break; \
33879 + case 0xbb: /* mov ebx, imm32 */ \
33880 + DILUTE_CONST_SEQUENCE(_off, randkey); \
33881 + /* mov ebx, ecx */ \
33882 + EMIT2(0x89, 0xcb); \
33883 + break; \
33884 + case 0xbe: /* mov esi, imm32 */ \
33885 + DILUTE_CONST_SEQUENCE(_off, randkey); \
33886 + /* mov esi, ecx */ \
33887 + EMIT2(0x89, 0xce); \
33888 + break; \
33889 + case 0xe8: /* call rel imm32, always to known funcs */ \
33890 + EMIT1(b1); \
33891 + EMIT(_off, 4); \
33892 + break; \
33893 + case 0xe9: /* jmp rel imm32 */ \
33894 + EMIT1(b1); \
33895 + EMIT(_off, 4); \
33896 + /* prevent fall-through, we're not called if off = 0 */ \
33897 + EMIT(0xcccccccc, 4); \
33898 + EMIT(0xcccccccc, 4); \
33899 + break; \
33900 + default: \
33901 + BUILD_BUG(); \
33902 + } \
33903 +} while (0)
33904 +
33905 +#define EMIT2_off32(b1, b2, _off) \
33906 +do { \
33907 + if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
33908 + EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
33909 + EMIT(randkey, 4); \
33910 + EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
33911 + EMIT((_off) - randkey, 4); \
33912 + } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
33913 + DILUTE_CONST_SEQUENCE(_off, randkey); \
33914 + /* imul eax, ecx */ \
33915 + EMIT3(0x0f, 0xaf, 0xc1); \
33916 + } else { \
33917 + BUILD_BUG(); \
33918 + } \
33919 +} while (0)
33920 +#else
33921 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
33922 +#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
33923 +#endif
33924
33925 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
33926 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
33927 @@ -91,6 +168,24 @@ do { \
33928 #define X86_JBE 0x76
33929 #define X86_JA 0x77
33930
33931 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33932 +#define APPEND_FLOW_VERIFY() \
33933 +do { \
33934 + /* mov ecx, randkey */ \
33935 + EMIT1(0xb9); \
33936 + EMIT(randkey, 4); \
33937 + /* cmp ecx, randkey */ \
33938 + EMIT2(0x81, 0xf9); \
33939 + EMIT(randkey, 4); \
33940 + /* jz after 8 int 3s */ \
33941 + EMIT2(0x74, 0x08); \
33942 + EMIT(0xcccccccc, 4); \
33943 + EMIT(0xcccccccc, 4); \
33944 +} while (0)
33945 +#else
33946 +#define APPEND_FLOW_VERIFY() do { } while (0)
33947 +#endif
33948 +
33949 #define EMIT_COND_JMP(op, offset) \
33950 do { \
33951 if (is_near(offset)) \
33952 @@ -98,6 +193,7 @@ do { \
33953 else { \
33954 EMIT2(0x0f, op + 0x10); \
33955 EMIT(offset, 4); /* jxx .+off32 */ \
33956 + APPEND_FLOW_VERIFY(); \
33957 } \
33958 } while (0)
33959
33960 @@ -145,55 +241,54 @@ static int pkt_type_offset(void)
33961 return -1;
33962 }
33963
33964 -struct bpf_binary_header {
33965 - unsigned int pages;
33966 - /* Note : for security reasons, bpf code will follow a randomly
33967 - * sized amount of int3 instructions
33968 - */
33969 - u8 image[];
33970 -};
33971 -
33972 -static struct bpf_binary_header *bpf_alloc_binary(unsigned int proglen,
33973 +/* Note : for security reasons, bpf code will follow a randomly
33974 + * sized amount of int3 instructions
33975 + */
33976 +static u8 *bpf_alloc_binary(unsigned int proglen,
33977 u8 **image_ptr)
33978 {
33979 unsigned int sz, hole;
33980 - struct bpf_binary_header *header;
33981 + u8 *header;
33982
33983 /* Most of BPF filters are really small,
33984 * but if some of them fill a page, allow at least
33985 * 128 extra bytes to insert a random section of int3
33986 */
33987 - sz = round_up(proglen + sizeof(*header) + 128, PAGE_SIZE);
33988 - header = module_alloc(sz);
33989 + sz = round_up(proglen + 128, PAGE_SIZE);
33990 + header = module_alloc_exec(sz);
33991 if (!header)
33992 return NULL;
33993
33994 + pax_open_kernel();
33995 memset(header, 0xcc, sz); /* fill whole space with int3 instructions */
33996 + pax_close_kernel();
33997
33998 - header->pages = sz / PAGE_SIZE;
33999 - hole = min(sz - (proglen + sizeof(*header)), PAGE_SIZE - sizeof(*header));
34000 + hole = PAGE_SIZE - (proglen & ~PAGE_MASK);
34001
34002 /* insert a random number of int3 instructions before BPF code */
34003 - *image_ptr = &header->image[prandom_u32() % hole];
34004 + *image_ptr = &header[prandom_u32() % hole];
34005 return header;
34006 }
34007
34008 void bpf_jit_compile(struct sk_filter *fp)
34009 {
34010 - u8 temp[64];
34011 + u8 temp[MAX_INSTR_CODE_SIZE];
34012 u8 *prog;
34013 unsigned int proglen, oldproglen = 0;
34014 int ilen, i;
34015 int t_offset, f_offset;
34016 u8 t_op, f_op, seen = 0, pass;
34017 u8 *image = NULL;
34018 - struct bpf_binary_header *header = NULL;
34019 + u8 *header = NULL;
34020 u8 *func;
34021 int pc_ret0 = -1; /* bpf index of first RET #0 instruction (if any) */
34022 unsigned int cleanup_addr; /* epilogue code offset */
34023 unsigned int *addrs;
34024 const struct sock_filter *filter = fp->insns;
34025 int flen = fp->len;
34026 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34027 + unsigned int randkey;
34028 +#endif
34029
34030 if (!bpf_jit_enable)
34031 return;
34032 @@ -203,10 +298,10 @@ void bpf_jit_compile(struct sk_filter *fp)
34033 return;
34034
34035 /* Before first pass, make a rough estimation of addrs[]
34036 - * each bpf instruction is translated to less than 64 bytes
34037 + * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
34038 */
34039 for (proglen = 0, i = 0; i < flen; i++) {
34040 - proglen += 64;
34041 + proglen += MAX_INSTR_CODE_SIZE;
34042 addrs[i] = proglen;
34043 }
34044 cleanup_addr = proglen; /* epilogue address */
34045 @@ -285,6 +380,10 @@ void bpf_jit_compile(struct sk_filter *fp)
34046 for (i = 0; i < flen; i++) {
34047 unsigned int K = filter[i].k;
34048
34049 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34050 + randkey = prandom_u32();
34051 +#endif
34052 +
34053 switch (filter[i].code) {
34054 case BPF_S_ALU_ADD_X: /* A += X; */
34055 seen |= SEEN_XREG;
34056 @@ -317,10 +416,8 @@ void bpf_jit_compile(struct sk_filter *fp)
34057 case BPF_S_ALU_MUL_K: /* A *= K */
34058 if (is_imm8(K))
34059 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
34060 - else {
34061 - EMIT2(0x69, 0xc0); /* imul imm32,%eax */
34062 - EMIT(K, 4);
34063 - }
34064 + else
34065 + EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
34066 break;
34067 case BPF_S_ALU_DIV_X: /* A /= X; */
34068 seen |= SEEN_XREG;
34069 @@ -364,7 +461,11 @@ void bpf_jit_compile(struct sk_filter *fp)
34070 break;
34071 }
34072 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
34073 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34074 + DILUTE_CONST_SEQUENCE(K, randkey);
34075 +#else
34076 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
34077 +#endif
34078 EMIT2(0xf7, 0xf1); /* div %ecx */
34079 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
34080 break;
34081 @@ -372,7 +473,11 @@ void bpf_jit_compile(struct sk_filter *fp)
34082 if (K == 1)
34083 break;
34084 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
34085 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
34086 + DILUTE_CONST_SEQUENCE(K, randkey);
34087 +#else
34088 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
34089 +#endif
34090 EMIT2(0xf7, 0xf1); /* div %ecx */
34091 break;
34092 case BPF_S_ALU_AND_X:
34093 @@ -643,8 +748,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
34094 if (is_imm8(K)) {
34095 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
34096 } else {
34097 - EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
34098 - EMIT(K, 4);
34099 + EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
34100 }
34101 } else {
34102 EMIT2(0x89,0xde); /* mov %ebx,%esi */
34103 @@ -734,10 +838,12 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
34104 if (unlikely(proglen + ilen > oldproglen)) {
34105 pr_err("bpb_jit_compile fatal error\n");
34106 kfree(addrs);
34107 - module_free(NULL, header);
34108 + module_free_exec(NULL, image);
34109 return;
34110 }
34111 + pax_open_kernel();
34112 memcpy(image + proglen, temp, ilen);
34113 + pax_close_kernel();
34114 }
34115 proglen += ilen;
34116 addrs[i] = proglen;
34117 @@ -770,7 +876,6 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
34118
34119 if (image) {
34120 bpf_flush_icache(header, image + proglen);
34121 - set_memory_ro((unsigned long)header, header->pages);
34122 fp->bpf_func = (void *)image;
34123 fp->jited = 1;
34124 }
34125 @@ -783,10 +888,9 @@ static void bpf_jit_free_deferred(struct work_struct *work)
34126 {
34127 struct sk_filter *fp = container_of(work, struct sk_filter, work);
34128 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
34129 - struct bpf_binary_header *header = (void *)addr;
34130
34131 - set_memory_rw(addr, header->pages);
34132 - module_free(NULL, header);
34133 + set_memory_rw(addr, 1);
34134 + module_free_exec(NULL, (void *)addr);
34135 kfree(fp);
34136 }
34137
34138 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
34139 index 5d04be5..2beeaa2 100644
34140 --- a/arch/x86/oprofile/backtrace.c
34141 +++ b/arch/x86/oprofile/backtrace.c
34142 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
34143 struct stack_frame_ia32 *fp;
34144 unsigned long bytes;
34145
34146 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
34147 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
34148 if (bytes != 0)
34149 return NULL;
34150
34151 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
34152 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
34153
34154 oprofile_add_trace(bufhead[0].return_address);
34155
34156 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
34157 struct stack_frame bufhead[2];
34158 unsigned long bytes;
34159
34160 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
34161 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
34162 if (bytes != 0)
34163 return NULL;
34164
34165 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
34166 {
34167 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
34168
34169 - if (!user_mode_vm(regs)) {
34170 + if (!user_mode(regs)) {
34171 unsigned long stack = kernel_stack_pointer(regs);
34172 if (depth)
34173 dump_trace(NULL, regs, (unsigned long *)stack, 0,
34174 diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
34175 index 379e8bd..6386e09 100644
34176 --- a/arch/x86/oprofile/nmi_int.c
34177 +++ b/arch/x86/oprofile/nmi_int.c
34178 @@ -23,6 +23,7 @@
34179 #include <asm/nmi.h>
34180 #include <asm/msr.h>
34181 #include <asm/apic.h>
34182 +#include <asm/pgtable.h>
34183
34184 #include "op_counter.h"
34185 #include "op_x86_model.h"
34186 @@ -785,8 +786,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
34187 if (ret)
34188 return ret;
34189
34190 - if (!model->num_virt_counters)
34191 - model->num_virt_counters = model->num_counters;
34192 + if (!model->num_virt_counters) {
34193 + pax_open_kernel();
34194 + *(unsigned int *)&model->num_virt_counters = model->num_counters;
34195 + pax_close_kernel();
34196 + }
34197
34198 mux_init(ops);
34199
34200 diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
34201 index 50d86c0..7985318 100644
34202 --- a/arch/x86/oprofile/op_model_amd.c
34203 +++ b/arch/x86/oprofile/op_model_amd.c
34204 @@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
34205 num_counters = AMD64_NUM_COUNTERS;
34206 }
34207
34208 - op_amd_spec.num_counters = num_counters;
34209 - op_amd_spec.num_controls = num_counters;
34210 - op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34211 + pax_open_kernel();
34212 + *(unsigned int *)&op_amd_spec.num_counters = num_counters;
34213 + *(unsigned int *)&op_amd_spec.num_controls = num_counters;
34214 + *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
34215 + pax_close_kernel();
34216
34217 return 0;
34218 }
34219 diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
34220 index d90528e..0127e2b 100644
34221 --- a/arch/x86/oprofile/op_model_ppro.c
34222 +++ b/arch/x86/oprofile/op_model_ppro.c
34223 @@ -19,6 +19,7 @@
34224 #include <asm/msr.h>
34225 #include <asm/apic.h>
34226 #include <asm/nmi.h>
34227 +#include <asm/pgtable.h>
34228
34229 #include "op_x86_model.h"
34230 #include "op_counter.h"
34231 @@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
34232
34233 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
34234
34235 - op_arch_perfmon_spec.num_counters = num_counters;
34236 - op_arch_perfmon_spec.num_controls = num_counters;
34237 + pax_open_kernel();
34238 + *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
34239 + *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
34240 + pax_close_kernel();
34241 }
34242
34243 static int arch_perfmon_init(struct oprofile_operations *ignore)
34244 diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
34245 index 71e8a67..6a313bb 100644
34246 --- a/arch/x86/oprofile/op_x86_model.h
34247 +++ b/arch/x86/oprofile/op_x86_model.h
34248 @@ -52,7 +52,7 @@ struct op_x86_model_spec {
34249 void (*switch_ctrl)(struct op_x86_model_spec const *model,
34250 struct op_msrs const * const msrs);
34251 #endif
34252 -};
34253 +} __do_const;
34254
34255 struct op_counter_config;
34256
34257 diff --git a/arch/x86/pci/intel_mid_pci.c b/arch/x86/pci/intel_mid_pci.c
34258 index 84b9d67..260e5ff 100644
34259 --- a/arch/x86/pci/intel_mid_pci.c
34260 +++ b/arch/x86/pci/intel_mid_pci.c
34261 @@ -245,7 +245,7 @@ int __init intel_mid_pci_init(void)
34262 pr_info("Intel MID platform detected, using MID PCI ops\n");
34263 pci_mmcfg_late_init();
34264 pcibios_enable_irq = intel_mid_pci_irq_enable;
34265 - pci_root_ops = intel_mid_pci_ops;
34266 + memcpy((void *)&pci_root_ops, &intel_mid_pci_ops, sizeof pci_root_ops);
34267 pci_soc_mode = 1;
34268 /* Continue with standard init */
34269 return 1;
34270 diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
34271 index 84112f5..6334d60 100644
34272 --- a/arch/x86/pci/irq.c
34273 +++ b/arch/x86/pci/irq.c
34274 @@ -50,7 +50,7 @@ struct irq_router {
34275 struct irq_router_handler {
34276 u16 vendor;
34277 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
34278 -};
34279 +} __do_const;
34280
34281 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
34282 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
34283 @@ -790,7 +790,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
34284 return 0;
34285 }
34286
34287 -static __initdata struct irq_router_handler pirq_routers[] = {
34288 +static __initconst const struct irq_router_handler pirq_routers[] = {
34289 { PCI_VENDOR_ID_INTEL, intel_router_probe },
34290 { PCI_VENDOR_ID_AL, ali_router_probe },
34291 { PCI_VENDOR_ID_ITE, ite_router_probe },
34292 @@ -817,7 +817,7 @@ static struct pci_dev *pirq_router_dev;
34293 static void __init pirq_find_router(struct irq_router *r)
34294 {
34295 struct irq_routing_table *rt = pirq_table;
34296 - struct irq_router_handler *h;
34297 + const struct irq_router_handler *h;
34298
34299 #ifdef CONFIG_PCI_BIOS
34300 if (!rt->signature) {
34301 @@ -1090,7 +1090,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
34302 return 0;
34303 }
34304
34305 -static struct dmi_system_id __initdata pciirq_dmi_table[] = {
34306 +static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
34307 {
34308 .callback = fix_broken_hp_bios_irq9,
34309 .ident = "HP Pavilion N5400 Series Laptop",
34310 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
34311 index c77b24a..c979855 100644
34312 --- a/arch/x86/pci/pcbios.c
34313 +++ b/arch/x86/pci/pcbios.c
34314 @@ -79,7 +79,7 @@ union bios32 {
34315 static struct {
34316 unsigned long address;
34317 unsigned short segment;
34318 -} bios32_indirect = { 0, __KERNEL_CS };
34319 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
34320
34321 /*
34322 * Returns the entry point for the given service, NULL on error
34323 @@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
34324 unsigned long length; /* %ecx */
34325 unsigned long entry; /* %edx */
34326 unsigned long flags;
34327 + struct desc_struct d, *gdt;
34328
34329 local_irq_save(flags);
34330 - __asm__("lcall *(%%edi); cld"
34331 +
34332 + gdt = get_cpu_gdt_table(smp_processor_id());
34333 +
34334 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
34335 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34336 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
34337 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34338 +
34339 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
34340 : "=a" (return_code),
34341 "=b" (address),
34342 "=c" (length),
34343 "=d" (entry)
34344 : "0" (service),
34345 "1" (0),
34346 - "D" (&bios32_indirect));
34347 + "D" (&bios32_indirect),
34348 + "r"(__PCIBIOS_DS)
34349 + : "memory");
34350 +
34351 + pax_open_kernel();
34352 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
34353 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
34354 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
34355 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
34356 + pax_close_kernel();
34357 +
34358 local_irq_restore(flags);
34359
34360 switch (return_code) {
34361 - case 0:
34362 - return address + entry;
34363 - case 0x80: /* Not present */
34364 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34365 - return 0;
34366 - default: /* Shouldn't happen */
34367 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34368 - service, return_code);
34369 + case 0: {
34370 + int cpu;
34371 + unsigned char flags;
34372 +
34373 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
34374 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
34375 + printk(KERN_WARNING "bios32_service: not valid\n");
34376 return 0;
34377 + }
34378 + address = address + PAGE_OFFSET;
34379 + length += 16UL; /* some BIOSs underreport this... */
34380 + flags = 4;
34381 + if (length >= 64*1024*1024) {
34382 + length >>= PAGE_SHIFT;
34383 + flags |= 8;
34384 + }
34385 +
34386 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
34387 + gdt = get_cpu_gdt_table(cpu);
34388 + pack_descriptor(&d, address, length, 0x9b, flags);
34389 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
34390 + pack_descriptor(&d, address, length, 0x93, flags);
34391 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
34392 + }
34393 + return entry;
34394 + }
34395 + case 0x80: /* Not present */
34396 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
34397 + return 0;
34398 + default: /* Shouldn't happen */
34399 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
34400 + service, return_code);
34401 + return 0;
34402 }
34403 }
34404
34405 static struct {
34406 unsigned long address;
34407 unsigned short segment;
34408 -} pci_indirect = { 0, __KERNEL_CS };
34409 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
34410
34411 -static int pci_bios_present;
34412 +static int pci_bios_present __read_only;
34413
34414 static int check_pcibios(void)
34415 {
34416 @@ -131,11 +174,13 @@ static int check_pcibios(void)
34417 unsigned long flags, pcibios_entry;
34418
34419 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
34420 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
34421 + pci_indirect.address = pcibios_entry;
34422
34423 local_irq_save(flags);
34424 - __asm__(
34425 - "lcall *(%%edi); cld\n\t"
34426 + __asm__("movw %w6, %%ds\n\t"
34427 + "lcall *%%ss:(%%edi); cld\n\t"
34428 + "push %%ss\n\t"
34429 + "pop %%ds\n\t"
34430 "jc 1f\n\t"
34431 "xor %%ah, %%ah\n"
34432 "1:"
34433 @@ -144,7 +189,8 @@ static int check_pcibios(void)
34434 "=b" (ebx),
34435 "=c" (ecx)
34436 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
34437 - "D" (&pci_indirect)
34438 + "D" (&pci_indirect),
34439 + "r" (__PCIBIOS_DS)
34440 : "memory");
34441 local_irq_restore(flags);
34442
34443 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34444
34445 switch (len) {
34446 case 1:
34447 - __asm__("lcall *(%%esi); cld\n\t"
34448 + __asm__("movw %w6, %%ds\n\t"
34449 + "lcall *%%ss:(%%esi); cld\n\t"
34450 + "push %%ss\n\t"
34451 + "pop %%ds\n\t"
34452 "jc 1f\n\t"
34453 "xor %%ah, %%ah\n"
34454 "1:"
34455 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34456 : "1" (PCIBIOS_READ_CONFIG_BYTE),
34457 "b" (bx),
34458 "D" ((long)reg),
34459 - "S" (&pci_indirect));
34460 + "S" (&pci_indirect),
34461 + "r" (__PCIBIOS_DS));
34462 /*
34463 * Zero-extend the result beyond 8 bits, do not trust the
34464 * BIOS having done it:
34465 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34466 *value &= 0xff;
34467 break;
34468 case 2:
34469 - __asm__("lcall *(%%esi); cld\n\t"
34470 + __asm__("movw %w6, %%ds\n\t"
34471 + "lcall *%%ss:(%%esi); cld\n\t"
34472 + "push %%ss\n\t"
34473 + "pop %%ds\n\t"
34474 "jc 1f\n\t"
34475 "xor %%ah, %%ah\n"
34476 "1:"
34477 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34478 : "1" (PCIBIOS_READ_CONFIG_WORD),
34479 "b" (bx),
34480 "D" ((long)reg),
34481 - "S" (&pci_indirect));
34482 + "S" (&pci_indirect),
34483 + "r" (__PCIBIOS_DS));
34484 /*
34485 * Zero-extend the result beyond 16 bits, do not trust the
34486 * BIOS having done it:
34487 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34488 *value &= 0xffff;
34489 break;
34490 case 4:
34491 - __asm__("lcall *(%%esi); cld\n\t"
34492 + __asm__("movw %w6, %%ds\n\t"
34493 + "lcall *%%ss:(%%esi); cld\n\t"
34494 + "push %%ss\n\t"
34495 + "pop %%ds\n\t"
34496 "jc 1f\n\t"
34497 "xor %%ah, %%ah\n"
34498 "1:"
34499 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
34500 : "1" (PCIBIOS_READ_CONFIG_DWORD),
34501 "b" (bx),
34502 "D" ((long)reg),
34503 - "S" (&pci_indirect));
34504 + "S" (&pci_indirect),
34505 + "r" (__PCIBIOS_DS));
34506 break;
34507 }
34508
34509 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34510
34511 switch (len) {
34512 case 1:
34513 - __asm__("lcall *(%%esi); cld\n\t"
34514 + __asm__("movw %w6, %%ds\n\t"
34515 + "lcall *%%ss:(%%esi); cld\n\t"
34516 + "push %%ss\n\t"
34517 + "pop %%ds\n\t"
34518 "jc 1f\n\t"
34519 "xor %%ah, %%ah\n"
34520 "1:"
34521 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34522 "c" (value),
34523 "b" (bx),
34524 "D" ((long)reg),
34525 - "S" (&pci_indirect));
34526 + "S" (&pci_indirect),
34527 + "r" (__PCIBIOS_DS));
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 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34539 "c" (value),
34540 "b" (bx),
34541 "D" ((long)reg),
34542 - "S" (&pci_indirect));
34543 + "S" (&pci_indirect),
34544 + "r" (__PCIBIOS_DS));
34545 break;
34546 case 4:
34547 - __asm__("lcall *(%%esi); cld\n\t"
34548 + __asm__("movw %w6, %%ds\n\t"
34549 + "lcall *%%ss:(%%esi); cld\n\t"
34550 + "push %%ss\n\t"
34551 + "pop %%ds\n\t"
34552 "jc 1f\n\t"
34553 "xor %%ah, %%ah\n"
34554 "1:"
34555 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
34556 "c" (value),
34557 "b" (bx),
34558 "D" ((long)reg),
34559 - "S" (&pci_indirect));
34560 + "S" (&pci_indirect),
34561 + "r" (__PCIBIOS_DS));
34562 break;
34563 }
34564
34565 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34566
34567 DBG("PCI: Fetching IRQ routing table... ");
34568 __asm__("push %%es\n\t"
34569 + "movw %w8, %%ds\n\t"
34570 "push %%ds\n\t"
34571 "pop %%es\n\t"
34572 - "lcall *(%%esi); cld\n\t"
34573 + "lcall *%%ss:(%%esi); cld\n\t"
34574 "pop %%es\n\t"
34575 + "push %%ss\n\t"
34576 + "pop %%ds\n"
34577 "jc 1f\n\t"
34578 "xor %%ah, %%ah\n"
34579 "1:"
34580 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
34581 "1" (0),
34582 "D" ((long) &opt),
34583 "S" (&pci_indirect),
34584 - "m" (opt)
34585 + "m" (opt),
34586 + "r" (__PCIBIOS_DS)
34587 : "memory");
34588 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
34589 if (ret & 0xff00)
34590 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34591 {
34592 int ret;
34593
34594 - __asm__("lcall *(%%esi); cld\n\t"
34595 + __asm__("movw %w5, %%ds\n\t"
34596 + "lcall *%%ss:(%%esi); cld\n\t"
34597 + "push %%ss\n\t"
34598 + "pop %%ds\n"
34599 "jc 1f\n\t"
34600 "xor %%ah, %%ah\n"
34601 "1:"
34602 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
34603 : "0" (PCIBIOS_SET_PCI_HW_INT),
34604 "b" ((dev->bus->number << 8) | dev->devfn),
34605 "c" ((irq << 8) | (pin + 10)),
34606 - "S" (&pci_indirect));
34607 + "S" (&pci_indirect),
34608 + "r" (__PCIBIOS_DS));
34609 return !(ret & 0xff00);
34610 }
34611 EXPORT_SYMBOL(pcibios_set_irq_routing);
34612 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
34613 index 9ee3491..872192f 100644
34614 --- a/arch/x86/platform/efi/efi_32.c
34615 +++ b/arch/x86/platform/efi/efi_32.c
34616 @@ -59,11 +59,22 @@ void efi_call_phys_prelog(void)
34617 {
34618 struct desc_ptr gdt_descr;
34619
34620 +#ifdef CONFIG_PAX_KERNEXEC
34621 + struct desc_struct d;
34622 +#endif
34623 +
34624 local_irq_save(efi_rt_eflags);
34625
34626 load_cr3(initial_page_table);
34627 __flush_tlb_all();
34628
34629 +#ifdef CONFIG_PAX_KERNEXEC
34630 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
34631 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34632 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
34633 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34634 +#endif
34635 +
34636 gdt_descr.address = __pa(get_cpu_gdt_table(0));
34637 gdt_descr.size = GDT_SIZE - 1;
34638 load_gdt(&gdt_descr);
34639 @@ -73,11 +84,24 @@ void efi_call_phys_epilog(void)
34640 {
34641 struct desc_ptr gdt_descr;
34642
34643 +#ifdef CONFIG_PAX_KERNEXEC
34644 + struct desc_struct d;
34645 +
34646 + memset(&d, 0, sizeof d);
34647 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
34648 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
34649 +#endif
34650 +
34651 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
34652 gdt_descr.size = GDT_SIZE - 1;
34653 load_gdt(&gdt_descr);
34654
34655 +#ifdef CONFIG_PAX_PER_CPU_PGD
34656 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34657 +#else
34658 load_cr3(swapper_pg_dir);
34659 +#endif
34660 +
34661 __flush_tlb_all();
34662
34663 local_irq_restore(efi_rt_eflags);
34664 diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
34665 index 290d397..3906bcd 100644
34666 --- a/arch/x86/platform/efi/efi_64.c
34667 +++ b/arch/x86/platform/efi/efi_64.c
34668 @@ -99,6 +99,11 @@ void __init efi_call_phys_prelog(void)
34669 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
34670 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
34671 }
34672 +
34673 +#ifdef CONFIG_PAX_PER_CPU_PGD
34674 + load_cr3(swapper_pg_dir);
34675 +#endif
34676 +
34677 __flush_tlb_all();
34678 }
34679
34680 @@ -116,6 +121,11 @@ void __init efi_call_phys_epilog(void)
34681 for (pgd = 0; pgd < n_pgds; pgd++)
34682 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
34683 kfree(save_pgd);
34684 +
34685 +#ifdef CONFIG_PAX_PER_CPU_PGD
34686 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34687 +#endif
34688 +
34689 __flush_tlb_all();
34690 local_irq_restore(efi_flags);
34691 early_code_mapping_set_exec(0);
34692 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
34693 index fbe66e6..eae5e38 100644
34694 --- a/arch/x86/platform/efi/efi_stub_32.S
34695 +++ b/arch/x86/platform/efi/efi_stub_32.S
34696 @@ -6,7 +6,9 @@
34697 */
34698
34699 #include <linux/linkage.h>
34700 +#include <linux/init.h>
34701 #include <asm/page_types.h>
34702 +#include <asm/segment.h>
34703
34704 /*
34705 * efi_call_phys(void *, ...) is a function with variable parameters.
34706 @@ -20,7 +22,7 @@
34707 * service functions will comply with gcc calling convention, too.
34708 */
34709
34710 -.text
34711 +__INIT
34712 ENTRY(efi_call_phys)
34713 /*
34714 * 0. The function can only be called in Linux kernel. So CS has been
34715 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
34716 * The mapping of lower virtual memory has been created in prelog and
34717 * epilog.
34718 */
34719 - movl $1f, %edx
34720 - subl $__PAGE_OFFSET, %edx
34721 - jmp *%edx
34722 +#ifdef CONFIG_PAX_KERNEXEC
34723 + movl $(__KERNEXEC_EFI_DS), %edx
34724 + mov %edx, %ds
34725 + mov %edx, %es
34726 + mov %edx, %ss
34727 + addl $2f,(1f)
34728 + ljmp *(1f)
34729 +
34730 +__INITDATA
34731 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
34732 +.previous
34733 +
34734 +2:
34735 + subl $2b,(1b)
34736 +#else
34737 + jmp 1f-__PAGE_OFFSET
34738 1:
34739 +#endif
34740
34741 /*
34742 * 2. Now on the top of stack is the return
34743 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
34744 * parameter 2, ..., param n. To make things easy, we save the return
34745 * address of efi_call_phys in a global variable.
34746 */
34747 - popl %edx
34748 - movl %edx, saved_return_addr
34749 - /* get the function pointer into ECX*/
34750 - popl %ecx
34751 - movl %ecx, efi_rt_function_ptr
34752 - movl $2f, %edx
34753 - subl $__PAGE_OFFSET, %edx
34754 - pushl %edx
34755 + popl (saved_return_addr)
34756 + popl (efi_rt_function_ptr)
34757
34758 /*
34759 * 3. Clear PG bit in %CR0.
34760 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
34761 /*
34762 * 5. Call the physical function.
34763 */
34764 - jmp *%ecx
34765 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
34766
34767 -2:
34768 /*
34769 * 6. After EFI runtime service returns, control will return to
34770 * following instruction. We'd better readjust stack pointer first.
34771 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
34772 movl %cr0, %edx
34773 orl $0x80000000, %edx
34774 movl %edx, %cr0
34775 - jmp 1f
34776 -1:
34777 +
34778 /*
34779 * 8. Now restore the virtual mode from flat mode by
34780 * adding EIP with PAGE_OFFSET.
34781 */
34782 - movl $1f, %edx
34783 - jmp *%edx
34784 +#ifdef CONFIG_PAX_KERNEXEC
34785 + movl $(__KERNEL_DS), %edx
34786 + mov %edx, %ds
34787 + mov %edx, %es
34788 + mov %edx, %ss
34789 + ljmp $(__KERNEL_CS),$1f
34790 +#else
34791 + jmp 1f+__PAGE_OFFSET
34792 +#endif
34793 1:
34794
34795 /*
34796 * 9. Balance the stack. And because EAX contain the return value,
34797 * we'd better not clobber it.
34798 */
34799 - leal efi_rt_function_ptr, %edx
34800 - movl (%edx), %ecx
34801 - pushl %ecx
34802 + pushl (efi_rt_function_ptr)
34803
34804 /*
34805 - * 10. Push the saved return address onto the stack and return.
34806 + * 10. Return to the saved return address.
34807 */
34808 - leal saved_return_addr, %edx
34809 - movl (%edx), %ecx
34810 - pushl %ecx
34811 - ret
34812 + jmpl *(saved_return_addr)
34813 ENDPROC(efi_call_phys)
34814 .previous
34815
34816 -.data
34817 +__INITDATA
34818 saved_return_addr:
34819 .long 0
34820 efi_rt_function_ptr:
34821 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
34822 index e0984ef..a062dac 100644
34823 --- a/arch/x86/platform/efi/efi_stub_64.S
34824 +++ b/arch/x86/platform/efi/efi_stub_64.S
34825 @@ -11,6 +11,7 @@
34826 #include <asm/msr.h>
34827 #include <asm/processor-flags.h>
34828 #include <asm/page_types.h>
34829 +#include <asm/alternative-asm.h>
34830
34831 #define SAVE_XMM \
34832 mov %rsp, %rax; \
34833 @@ -81,6 +82,7 @@ ENTRY(efi_call0)
34834 RESTORE_PGT
34835 addq $32, %rsp
34836 RESTORE_XMM
34837 + pax_force_retaddr 0, 1
34838 ret
34839 ENDPROC(efi_call0)
34840
34841 @@ -93,6 +95,7 @@ ENTRY(efi_call1)
34842 RESTORE_PGT
34843 addq $32, %rsp
34844 RESTORE_XMM
34845 + pax_force_retaddr 0, 1
34846 ret
34847 ENDPROC(efi_call1)
34848
34849 @@ -105,6 +108,7 @@ ENTRY(efi_call2)
34850 RESTORE_PGT
34851 addq $32, %rsp
34852 RESTORE_XMM
34853 + pax_force_retaddr 0, 1
34854 ret
34855 ENDPROC(efi_call2)
34856
34857 @@ -118,6 +122,7 @@ ENTRY(efi_call3)
34858 RESTORE_PGT
34859 addq $32, %rsp
34860 RESTORE_XMM
34861 + pax_force_retaddr 0, 1
34862 ret
34863 ENDPROC(efi_call3)
34864
34865 @@ -132,6 +137,7 @@ ENTRY(efi_call4)
34866 RESTORE_PGT
34867 addq $32, %rsp
34868 RESTORE_XMM
34869 + pax_force_retaddr 0, 1
34870 ret
34871 ENDPROC(efi_call4)
34872
34873 @@ -147,6 +153,7 @@ ENTRY(efi_call5)
34874 RESTORE_PGT
34875 addq $48, %rsp
34876 RESTORE_XMM
34877 + pax_force_retaddr 0, 1
34878 ret
34879 ENDPROC(efi_call5)
34880
34881 @@ -165,6 +172,7 @@ ENTRY(efi_call6)
34882 RESTORE_PGT
34883 addq $48, %rsp
34884 RESTORE_XMM
34885 + pax_force_retaddr 0, 1
34886 ret
34887 ENDPROC(efi_call6)
34888
34889 diff --git a/arch/x86/platform/intel-mid/intel-mid.c b/arch/x86/platform/intel-mid/intel-mid.c
34890 index 1bbedc4..eb795b5 100644
34891 --- a/arch/x86/platform/intel-mid/intel-mid.c
34892 +++ b/arch/x86/platform/intel-mid/intel-mid.c
34893 @@ -71,9 +71,10 @@ static void intel_mid_power_off(void)
34894 {
34895 };
34896
34897 -static void intel_mid_reboot(void)
34898 +static void __noreturn intel_mid_reboot(void)
34899 {
34900 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
34901 + BUG();
34902 }
34903
34904 static unsigned long __init intel_mid_calibrate_tsc(void)
34905 diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
34906 index d6ee929..3637cb5 100644
34907 --- a/arch/x86/platform/olpc/olpc_dt.c
34908 +++ b/arch/x86/platform/olpc/olpc_dt.c
34909 @@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
34910 return res;
34911 }
34912
34913 -static struct of_pdt_ops prom_olpc_ops __initdata = {
34914 +static struct of_pdt_ops prom_olpc_ops __initconst = {
34915 .nextprop = olpc_dt_nextprop,
34916 .getproplen = olpc_dt_getproplen,
34917 .getproperty = olpc_dt_getproperty,
34918 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
34919 index 424f4c9..f2a2988 100644
34920 --- a/arch/x86/power/cpu.c
34921 +++ b/arch/x86/power/cpu.c
34922 @@ -137,11 +137,8 @@ static void do_fpu_end(void)
34923 static void fix_processor_context(void)
34924 {
34925 int cpu = smp_processor_id();
34926 - struct tss_struct *t = &per_cpu(init_tss, cpu);
34927 -#ifdef CONFIG_X86_64
34928 - struct desc_struct *desc = get_cpu_gdt_table(cpu);
34929 - tss_desc tss;
34930 -#endif
34931 + struct tss_struct *t = init_tss + cpu;
34932 +
34933 set_tss_desc(cpu, t); /*
34934 * This just modifies memory; should not be
34935 * necessary. But... This is necessary, because
34936 @@ -150,10 +147,6 @@ static void fix_processor_context(void)
34937 */
34938
34939 #ifdef CONFIG_X86_64
34940 - memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
34941 - tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
34942 - write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
34943 -
34944 syscall_init(); /* This sets MSR_*STAR and related */
34945 #endif
34946 load_TR_desc(); /* This does ltr */
34947 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
34948 index bad628a..a102610 100644
34949 --- a/arch/x86/realmode/init.c
34950 +++ b/arch/x86/realmode/init.c
34951 @@ -68,7 +68,13 @@ void __init setup_real_mode(void)
34952 __va(real_mode_header->trampoline_header);
34953
34954 #ifdef CONFIG_X86_32
34955 - trampoline_header->start = __pa_symbol(startup_32_smp);
34956 + trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
34957 +
34958 +#ifdef CONFIG_PAX_KERNEXEC
34959 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
34960 +#endif
34961 +
34962 + trampoline_header->boot_cs = __BOOT_CS;
34963 trampoline_header->gdt_limit = __BOOT_DS + 7;
34964 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
34965 #else
34966 @@ -84,7 +90,7 @@ void __init setup_real_mode(void)
34967 *trampoline_cr4_features = read_cr4();
34968
34969 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
34970 - trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
34971 + trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
34972 trampoline_pgd[511] = init_level4_pgt[511].pgd;
34973 #endif
34974 }
34975 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
34976 index 3497f14..cc73b92 100644
34977 --- a/arch/x86/realmode/rm/Makefile
34978 +++ b/arch/x86/realmode/rm/Makefile
34979 @@ -66,5 +66,8 @@ $(obj)/realmode.relocs: $(obj)/realmode.elf FORCE
34980
34981 KBUILD_CFLAGS := $(LINUXINCLUDE) $(REALMODE_CFLAGS) -D_SETUP -D_WAKEUP \
34982 -I$(srctree)/arch/x86/boot
34983 +ifdef CONSTIFY_PLUGIN
34984 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
34985 +endif
34986 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
34987 GCOV_PROFILE := n
34988 diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
34989 index a28221d..93c40f1 100644
34990 --- a/arch/x86/realmode/rm/header.S
34991 +++ b/arch/x86/realmode/rm/header.S
34992 @@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
34993 #endif
34994 /* APM/BIOS reboot */
34995 .long pa_machine_real_restart_asm
34996 -#ifdef CONFIG_X86_64
34997 +#ifdef CONFIG_X86_32
34998 + .long __KERNEL_CS
34999 +#else
35000 .long __KERNEL32_CS
35001 #endif
35002 END(real_mode_header)
35003 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
35004 index 48ddd76..c26749f 100644
35005 --- a/arch/x86/realmode/rm/trampoline_32.S
35006 +++ b/arch/x86/realmode/rm/trampoline_32.S
35007 @@ -24,6 +24,12 @@
35008 #include <asm/page_types.h>
35009 #include "realmode.h"
35010
35011 +#ifdef CONFIG_PAX_KERNEXEC
35012 +#define ta(X) (X)
35013 +#else
35014 +#define ta(X) (pa_ ## X)
35015 +#endif
35016 +
35017 .text
35018 .code16
35019
35020 @@ -38,8 +44,6 @@ ENTRY(trampoline_start)
35021
35022 cli # We should be safe anyway
35023
35024 - movl tr_start, %eax # where we need to go
35025 -
35026 movl $0xA5A5A5A5, trampoline_status
35027 # write marker for master knows we're running
35028
35029 @@ -55,7 +59,7 @@ ENTRY(trampoline_start)
35030 movw $1, %dx # protected mode (PE) bit
35031 lmsw %dx # into protected mode
35032
35033 - ljmpl $__BOOT_CS, $pa_startup_32
35034 + ljmpl *(trampoline_header)
35035
35036 .section ".text32","ax"
35037 .code32
35038 @@ -66,7 +70,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
35039 .balign 8
35040 GLOBAL(trampoline_header)
35041 tr_start: .space 4
35042 - tr_gdt_pad: .space 2
35043 + tr_boot_cs: .space 2
35044 tr_gdt: .space 6
35045 END(trampoline_header)
35046
35047 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
35048 index dac7b20..72dbaca 100644
35049 --- a/arch/x86/realmode/rm/trampoline_64.S
35050 +++ b/arch/x86/realmode/rm/trampoline_64.S
35051 @@ -93,6 +93,7 @@ ENTRY(startup_32)
35052 movl %edx, %gs
35053
35054 movl pa_tr_cr4, %eax
35055 + andl $~X86_CR4_PCIDE, %eax
35056 movl %eax, %cr4 # Enable PAE mode
35057
35058 # Setup trampoline 4 level pagetables
35059 @@ -106,7 +107,7 @@ ENTRY(startup_32)
35060 wrmsr
35061
35062 # Enable paging and in turn activate Long Mode
35063 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
35064 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
35065 movl %eax, %cr0
35066
35067 /*
35068 diff --git a/arch/x86/realmode/rm/wakeup_asm.S b/arch/x86/realmode/rm/wakeup_asm.S
35069 index 9e7e147..25a4158 100644
35070 --- a/arch/x86/realmode/rm/wakeup_asm.S
35071 +++ b/arch/x86/realmode/rm/wakeup_asm.S
35072 @@ -126,11 +126,10 @@ ENTRY(wakeup_start)
35073 lgdtl pmode_gdt
35074
35075 /* This really couldn't... */
35076 - movl pmode_entry, %eax
35077 movl pmode_cr0, %ecx
35078 movl %ecx, %cr0
35079 - ljmpl $__KERNEL_CS, $pa_startup_32
35080 - /* -> jmp *%eax in trampoline_32.S */
35081 +
35082 + ljmpl *pmode_entry
35083 #else
35084 jmp trampoline_start
35085 #endif
35086 diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
35087 index 604a37e..e49702a 100644
35088 --- a/arch/x86/tools/Makefile
35089 +++ b/arch/x86/tools/Makefile
35090 @@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
35091
35092 $(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
35093
35094 -HOST_EXTRACFLAGS += -I$(srctree)/tools/include
35095 +HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
35096 hostprogs-y += relocs
35097 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
35098 PHONY += relocs
35099 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
35100 index bbb1d22..e505211 100644
35101 --- a/arch/x86/tools/relocs.c
35102 +++ b/arch/x86/tools/relocs.c
35103 @@ -1,5 +1,7 @@
35104 /* This is included from relocs_32/64.c */
35105
35106 +#include "../../../include/generated/autoconf.h"
35107 +
35108 #define ElfW(type) _ElfW(ELF_BITS, type)
35109 #define _ElfW(bits, type) __ElfW(bits, type)
35110 #define __ElfW(bits, type) Elf##bits##_##type
35111 @@ -11,6 +13,7 @@
35112 #define Elf_Sym ElfW(Sym)
35113
35114 static Elf_Ehdr ehdr;
35115 +static Elf_Phdr *phdr;
35116
35117 struct relocs {
35118 uint32_t *offset;
35119 @@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
35120 }
35121 }
35122
35123 +static void read_phdrs(FILE *fp)
35124 +{
35125 + unsigned int i;
35126 +
35127 + phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
35128 + if (!phdr) {
35129 + die("Unable to allocate %d program headers\n",
35130 + ehdr.e_phnum);
35131 + }
35132 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
35133 + die("Seek to %d failed: %s\n",
35134 + ehdr.e_phoff, strerror(errno));
35135 + }
35136 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
35137 + die("Cannot read ELF program headers: %s\n",
35138 + strerror(errno));
35139 + }
35140 + for(i = 0; i < ehdr.e_phnum; i++) {
35141 + phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
35142 + phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
35143 + phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
35144 + phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
35145 + phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
35146 + phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
35147 + phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
35148 + phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
35149 + }
35150 +
35151 +}
35152 +
35153 static void read_shdrs(FILE *fp)
35154 {
35155 - int i;
35156 + unsigned int i;
35157 Elf_Shdr shdr;
35158
35159 secs = calloc(ehdr.e_shnum, sizeof(struct section));
35160 @@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
35161
35162 static void read_strtabs(FILE *fp)
35163 {
35164 - int i;
35165 + unsigned int i;
35166 for (i = 0; i < ehdr.e_shnum; i++) {
35167 struct section *sec = &secs[i];
35168 if (sec->shdr.sh_type != SHT_STRTAB) {
35169 @@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
35170
35171 static void read_symtabs(FILE *fp)
35172 {
35173 - int i,j;
35174 + unsigned int i,j;
35175 for (i = 0; i < ehdr.e_shnum; i++) {
35176 struct section *sec = &secs[i];
35177 if (sec->shdr.sh_type != SHT_SYMTAB) {
35178 @@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
35179 }
35180
35181
35182 -static void read_relocs(FILE *fp)
35183 +static void read_relocs(FILE *fp, int use_real_mode)
35184 {
35185 - int i,j;
35186 + unsigned int i,j;
35187 + uint32_t base;
35188 +
35189 for (i = 0; i < ehdr.e_shnum; i++) {
35190 struct section *sec = &secs[i];
35191 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35192 @@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
35193 die("Cannot read symbol table: %s\n",
35194 strerror(errno));
35195 }
35196 + base = 0;
35197 +
35198 +#ifdef CONFIG_X86_32
35199 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
35200 + if (phdr[j].p_type != PT_LOAD )
35201 + continue;
35202 + 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)
35203 + continue;
35204 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
35205 + break;
35206 + }
35207 +#endif
35208 +
35209 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
35210 Elf_Rel *rel = &sec->reltab[j];
35211 - rel->r_offset = elf_addr_to_cpu(rel->r_offset);
35212 + rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
35213 rel->r_info = elf_xword_to_cpu(rel->r_info);
35214 #if (SHT_REL_TYPE == SHT_RELA)
35215 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
35216 @@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
35217
35218 static void print_absolute_symbols(void)
35219 {
35220 - int i;
35221 + unsigned int i;
35222 const char *format;
35223
35224 if (ELF_BITS == 64)
35225 @@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
35226 for (i = 0; i < ehdr.e_shnum; i++) {
35227 struct section *sec = &secs[i];
35228 char *sym_strtab;
35229 - int j;
35230 + unsigned int j;
35231
35232 if (sec->shdr.sh_type != SHT_SYMTAB) {
35233 continue;
35234 @@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
35235
35236 static void print_absolute_relocs(void)
35237 {
35238 - int i, printed = 0;
35239 + unsigned int i, printed = 0;
35240 const char *format;
35241
35242 if (ELF_BITS == 64)
35243 @@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
35244 struct section *sec_applies, *sec_symtab;
35245 char *sym_strtab;
35246 Elf_Sym *sh_symtab;
35247 - int j;
35248 + unsigned int j;
35249 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35250 continue;
35251 }
35252 @@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
35253 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
35254 Elf_Sym *sym, const char *symname))
35255 {
35256 - int i;
35257 + unsigned int i;
35258 /* Walk through the relocations */
35259 for (i = 0; i < ehdr.e_shnum; i++) {
35260 char *sym_strtab;
35261 Elf_Sym *sh_symtab;
35262 struct section *sec_applies, *sec_symtab;
35263 - int j;
35264 + unsigned int j;
35265 struct section *sec = &secs[i];
35266
35267 if (sec->shdr.sh_type != SHT_REL_TYPE) {
35268 @@ -822,6 +870,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35269 {
35270 unsigned r_type = ELF32_R_TYPE(rel->r_info);
35271 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
35272 + char *sym_strtab = sec->link->link->strtab;
35273 +
35274 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
35275 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
35276 + return 0;
35277 +
35278 +#ifdef CONFIG_PAX_KERNEXEC
35279 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
35280 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
35281 + return 0;
35282 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
35283 + return 0;
35284 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
35285 + return 0;
35286 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
35287 + return 0;
35288 +#endif
35289
35290 switch (r_type) {
35291 case R_386_NONE:
35292 @@ -960,7 +1025,7 @@ static int write32_as_text(uint32_t v, FILE *f)
35293
35294 static void emit_relocs(int as_text, int use_real_mode)
35295 {
35296 - int i;
35297 + unsigned int i;
35298 int (*write_reloc)(uint32_t, FILE *) = write32;
35299 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
35300 const char *symname);
35301 @@ -1060,10 +1125,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
35302 {
35303 regex_init(use_real_mode);
35304 read_ehdr(fp);
35305 + read_phdrs(fp);
35306 read_shdrs(fp);
35307 read_strtabs(fp);
35308 read_symtabs(fp);
35309 - read_relocs(fp);
35310 + read_relocs(fp, use_real_mode);
35311 if (ELF_BITS == 64)
35312 percpu_init();
35313 if (show_absolute_syms) {
35314 diff --git a/arch/x86/um/mem_32.c b/arch/x86/um/mem_32.c
35315 index f40281e..92728c9 100644
35316 --- a/arch/x86/um/mem_32.c
35317 +++ b/arch/x86/um/mem_32.c
35318 @@ -21,7 +21,7 @@ static int __init gate_vma_init(void)
35319 gate_vma.vm_start = FIXADDR_USER_START;
35320 gate_vma.vm_end = FIXADDR_USER_END;
35321 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
35322 - gate_vma.vm_page_prot = __P101;
35323 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
35324
35325 return 0;
35326 }
35327 diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
35328 index 80ffa5b..a33bd15 100644
35329 --- a/arch/x86/um/tls_32.c
35330 +++ b/arch/x86/um/tls_32.c
35331 @@ -260,7 +260,7 @@ out:
35332 if (unlikely(task == current &&
35333 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
35334 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
35335 - "without flushed TLS.", current->pid);
35336 + "without flushed TLS.", task_pid_nr(current));
35337 }
35338
35339 return 0;
35340 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
35341 index c580d12..0a0ba35 100644
35342 --- a/arch/x86/vdso/Makefile
35343 +++ b/arch/x86/vdso/Makefile
35344 @@ -196,7 +196,7 @@ quiet_cmd_vdso = VDSO $@
35345 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
35346 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
35347
35348 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
35349 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) \
35350 $(LTO_CFLAGS)
35351 GCOV_PROFILE := n
35352
35353 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
35354 index 310c5f0..766d0a7 100644
35355 --- a/arch/x86/vdso/vdso32-setup.c
35356 +++ b/arch/x86/vdso/vdso32-setup.c
35357 @@ -29,6 +29,7 @@
35358 #include <asm/fixmap.h>
35359 #include <asm/hpet.h>
35360 #include <asm/vvar.h>
35361 +#include <asm/mman.h>
35362
35363 #ifdef CONFIG_COMPAT_VDSO
35364 #define VDSO_DEFAULT 0
35365 @@ -99,7 +100,7 @@ void syscall32_cpu_init(void)
35366 void enable_sep_cpu(void)
35367 {
35368 int cpu = get_cpu();
35369 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
35370 + struct tss_struct *tss = init_tss + cpu;
35371
35372 if (!boot_cpu_has(X86_FEATURE_SEP)) {
35373 put_cpu();
35374 @@ -167,7 +168,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35375
35376 down_write(&mm->mmap_sem);
35377
35378 - addr = get_unmapped_area(NULL, 0, vdso32_size + VDSO_OFFSET(VDSO_PREV_PAGES), 0, 0);
35379 + addr = get_unmapped_area(NULL, 0, vdso32_size + VDSO_OFFSET(VDSO_PREV_PAGES), 0, MAP_EXECUTABLE);
35380 if (IS_ERR_VALUE(addr)) {
35381 ret = addr;
35382 goto up_fail;
35383 @@ -175,7 +176,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35384
35385 addr += VDSO_OFFSET(VDSO_PREV_PAGES);
35386
35387 - current->mm->context.vdso = (void *)addr;
35388 + current->mm->context.vdso = addr;
35389
35390 /*
35391 * MAYWRITE to allow gdb to COW and set breakpoints
35392 @@ -224,11 +225,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35393 #endif
35394
35395 current_thread_info()->sysenter_return =
35396 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
35397 + (void __force_user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
35398
35399 up_fail:
35400 if (ret)
35401 - current->mm->context.vdso = NULL;
35402 + current->mm->context.vdso = 0;
35403
35404 up_write(&mm->mmap_sem);
35405
35406 @@ -282,8 +283,14 @@ __initcall(ia32_binfmt_init);
35407
35408 const char *arch_vma_name(struct vm_area_struct *vma)
35409 {
35410 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
35411 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
35412 return "[vdso]";
35413 +
35414 +#ifdef CONFIG_PAX_SEGMEXEC
35415 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
35416 + return "[vdso]";
35417 +#endif
35418 +
35419 return NULL;
35420 }
35421
35422 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
35423 index 1ad1026..1a08abe 100644
35424 --- a/arch/x86/vdso/vma.c
35425 +++ b/arch/x86/vdso/vma.c
35426 @@ -17,8 +17,6 @@
35427 #include <asm/page.h>
35428
35429 #if defined(CONFIG_X86_64)
35430 -unsigned int __read_mostly vdso_enabled = 1;
35431 -
35432 DECLARE_VDSO_IMAGE(vdso);
35433 extern unsigned short vdso_sync_cpuid;
35434 static unsigned vdso_size;
35435 @@ -144,7 +142,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
35436 * unaligned here as a result of stack start randomization.
35437 */
35438 addr = PAGE_ALIGN(addr);
35439 - addr = align_vdso_addr(addr);
35440
35441 return addr;
35442 }
35443 @@ -157,30 +154,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
35444 unsigned size)
35445 {
35446 struct mm_struct *mm = current->mm;
35447 - unsigned long addr;
35448 + unsigned long addr = 0;
35449 int ret;
35450
35451 - if (!vdso_enabled)
35452 - return 0;
35453 -
35454 down_write(&mm->mmap_sem);
35455 +
35456 +#ifdef CONFIG_PAX_RANDMMAP
35457 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
35458 +#endif
35459 +
35460 addr = vdso_addr(mm->start_stack, size);
35461 + addr = align_vdso_addr(addr);
35462 addr = get_unmapped_area(NULL, addr, size, 0, 0);
35463 if (IS_ERR_VALUE(addr)) {
35464 ret = addr;
35465 goto up_fail;
35466 }
35467
35468 - current->mm->context.vdso = (void *)addr;
35469 + mm->context.vdso = addr;
35470
35471 ret = install_special_mapping(mm, addr, size,
35472 VM_READ|VM_EXEC|
35473 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
35474 pages);
35475 - if (ret) {
35476 - current->mm->context.vdso = NULL;
35477 - goto up_fail;
35478 - }
35479 + if (ret)
35480 + mm->context.vdso = 0;
35481
35482 up_fail:
35483 up_write(&mm->mmap_sem);
35484 @@ -200,11 +198,4 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
35485 vdsox32_size);
35486 }
35487 #endif
35488 -
35489 -static __init int vdso_setup(char *s)
35490 -{
35491 - vdso_enabled = simple_strtoul(s, NULL, 0);
35492 - return 0;
35493 -}
35494 -__setup("vdso=", vdso_setup);
35495 #endif
35496 diff --git a/arch/x86/xen/Kconfig b/arch/x86/xen/Kconfig
35497 index e88fda8..76ce7ce 100644
35498 --- a/arch/x86/xen/Kconfig
35499 +++ b/arch/x86/xen/Kconfig
35500 @@ -9,6 +9,7 @@ config XEN
35501 select XEN_HAVE_PVMMU
35502 depends on X86_64 || (X86_32 && X86_PAE)
35503 depends on X86_TSC
35504 + depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_XEN
35505 help
35506 This is the Linux Xen port. Enabling this will allow the
35507 kernel to boot in a paravirtualized environment under the
35508 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
35509 index c34bfc4..e599673 100644
35510 --- a/arch/x86/xen/enlighten.c
35511 +++ b/arch/x86/xen/enlighten.c
35512 @@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
35513
35514 struct shared_info xen_dummy_shared_info;
35515
35516 -void *xen_initial_gdt;
35517 -
35518 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
35519 __read_mostly int xen_have_vector_callback;
35520 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
35521 @@ -542,8 +540,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
35522 {
35523 unsigned long va = dtr->address;
35524 unsigned int size = dtr->size + 1;
35525 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35526 - unsigned long frames[pages];
35527 + unsigned long frames[65536 / PAGE_SIZE];
35528 int f;
35529
35530 /*
35531 @@ -591,8 +588,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35532 {
35533 unsigned long va = dtr->address;
35534 unsigned int size = dtr->size + 1;
35535 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
35536 - unsigned long frames[pages];
35537 + unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
35538 int f;
35539
35540 /*
35541 @@ -600,7 +596,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
35542 * 8-byte entries, or 16 4k pages..
35543 */
35544
35545 - BUG_ON(size > 65536);
35546 + BUG_ON(size > GDT_SIZE);
35547 BUG_ON(va & ~PAGE_MASK);
35548
35549 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
35550 @@ -989,7 +985,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
35551 return 0;
35552 }
35553
35554 -static void set_xen_basic_apic_ops(void)
35555 +static void __init set_xen_basic_apic_ops(void)
35556 {
35557 apic->read = xen_apic_read;
35558 apic->write = xen_apic_write;
35559 @@ -1295,30 +1291,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
35560 #endif
35561 };
35562
35563 -static void xen_reboot(int reason)
35564 +static __noreturn void xen_reboot(int reason)
35565 {
35566 struct sched_shutdown r = { .reason = reason };
35567
35568 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
35569 - BUG();
35570 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
35571 + BUG();
35572 }
35573
35574 -static void xen_restart(char *msg)
35575 +static __noreturn void xen_restart(char *msg)
35576 {
35577 xen_reboot(SHUTDOWN_reboot);
35578 }
35579
35580 -static void xen_emergency_restart(void)
35581 +static __noreturn void xen_emergency_restart(void)
35582 {
35583 xen_reboot(SHUTDOWN_reboot);
35584 }
35585
35586 -static void xen_machine_halt(void)
35587 +static __noreturn void xen_machine_halt(void)
35588 {
35589 xen_reboot(SHUTDOWN_poweroff);
35590 }
35591
35592 -static void xen_machine_power_off(void)
35593 +static __noreturn void xen_machine_power_off(void)
35594 {
35595 if (pm_power_off)
35596 pm_power_off();
35597 @@ -1564,7 +1560,17 @@ asmlinkage __visible void __init xen_start_kernel(void)
35598 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
35599
35600 /* Work out if we support NX */
35601 - x86_configure_nx();
35602 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
35603 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
35604 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
35605 + unsigned l, h;
35606 +
35607 + __supported_pte_mask |= _PAGE_NX;
35608 + rdmsr(MSR_EFER, l, h);
35609 + l |= EFER_NX;
35610 + wrmsr(MSR_EFER, l, h);
35611 + }
35612 +#endif
35613
35614 /* Get mfn list */
35615 xen_build_dynamic_phys_to_machine();
35616 @@ -1592,13 +1598,6 @@ asmlinkage __visible void __init xen_start_kernel(void)
35617
35618 machine_ops = xen_machine_ops;
35619
35620 - /*
35621 - * The only reliable way to retain the initial address of the
35622 - * percpu gdt_page is to remember it here, so we can go and
35623 - * mark it RW later, when the initial percpu area is freed.
35624 - */
35625 - xen_initial_gdt = &per_cpu(gdt_page, 0);
35626 -
35627 xen_smp_init();
35628
35629 #ifdef CONFIG_ACPI_NUMA
35630 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
35631 index 86e02ea..e3705ca 100644
35632 --- a/arch/x86/xen/mmu.c
35633 +++ b/arch/x86/xen/mmu.c
35634 @@ -379,7 +379,7 @@ static pteval_t pte_mfn_to_pfn(pteval_t val)
35635 return val;
35636 }
35637
35638 -static pteval_t pte_pfn_to_mfn(pteval_t val)
35639 +static pteval_t __intentional_overflow(-1) pte_pfn_to_mfn(pteval_t val)
35640 {
35641 if (val & _PAGE_PRESENT) {
35642 unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
35643 @@ -1904,6 +1904,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35644 /* L3_k[510] -> level2_kernel_pgt
35645 * L3_i[511] -> level2_fixmap_pgt */
35646 convert_pfn_mfn(level3_kernel_pgt);
35647 + convert_pfn_mfn(level3_vmalloc_start_pgt);
35648 + convert_pfn_mfn(level3_vmalloc_end_pgt);
35649 + convert_pfn_mfn(level3_vmemmap_pgt);
35650 }
35651 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
35652 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
35653 @@ -1933,8 +1936,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
35654 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
35655 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
35656 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
35657 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
35658 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
35659 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
35660 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
35661 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
35662 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
35663 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
35664 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
35665
35666 @@ -2122,6 +2129,7 @@ static void __init xen_post_allocator_init(void)
35667 pv_mmu_ops.set_pud = xen_set_pud;
35668 #if PAGETABLE_LEVELS == 4
35669 pv_mmu_ops.set_pgd = xen_set_pgd;
35670 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
35671 #endif
35672
35673 /* This will work as long as patching hasn't happened yet
35674 @@ -2200,6 +2208,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
35675 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
35676 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
35677 .set_pgd = xen_set_pgd_hyper,
35678 + .set_pgd_batched = xen_set_pgd_hyper,
35679
35680 .alloc_pud = xen_alloc_pmd_init,
35681 .release_pud = xen_release_pmd_init,
35682 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
35683 index 7005974..54fb05f 100644
35684 --- a/arch/x86/xen/smp.c
35685 +++ b/arch/x86/xen/smp.c
35686 @@ -283,17 +283,13 @@ static void __init xen_smp_prepare_boot_cpu(void)
35687
35688 if (xen_pv_domain()) {
35689 if (!xen_feature(XENFEAT_writable_page_tables))
35690 - /* We've switched to the "real" per-cpu gdt, so make
35691 - * sure the old memory can be recycled. */
35692 - make_lowmem_page_readwrite(xen_initial_gdt);
35693 -
35694 #ifdef CONFIG_X86_32
35695 /*
35696 * Xen starts us with XEN_FLAT_RING1_DS, but linux code
35697 * expects __USER_DS
35698 */
35699 - loadsegment(ds, __USER_DS);
35700 - loadsegment(es, __USER_DS);
35701 + loadsegment(ds, __KERNEL_DS);
35702 + loadsegment(es, __KERNEL_DS);
35703 #endif
35704
35705 xen_filter_cpu_maps();
35706 @@ -372,7 +368,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35707 #ifdef CONFIG_X86_32
35708 /* Note: PVH is not yet supported on x86_32. */
35709 ctxt->user_regs.fs = __KERNEL_PERCPU;
35710 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
35711 + savesegment(gs, ctxt->user_regs.gs);
35712 #endif
35713 ctxt->user_regs.eip = (unsigned long)cpu_bringup_and_idle;
35714
35715 @@ -381,8 +377,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35716 if (!xen_feature(XENFEAT_auto_translated_physmap)) {
35717 ctxt->flags = VGCF_IN_KERNEL;
35718 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
35719 - ctxt->user_regs.ds = __USER_DS;
35720 - ctxt->user_regs.es = __USER_DS;
35721 + ctxt->user_regs.ds = __KERNEL_DS;
35722 + ctxt->user_regs.es = __KERNEL_DS;
35723 ctxt->user_regs.ss = __KERNEL_DS;
35724
35725 xen_copy_trap_info(ctxt->trap_ctxt);
35726 @@ -437,14 +433,13 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
35727 int rc;
35728
35729 per_cpu(current_task, cpu) = idle;
35730 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
35731 #ifdef CONFIG_X86_32
35732 irq_ctx_init(cpu);
35733 #else
35734 clear_tsk_thread_flag(idle, TIF_FORK);
35735 #endif
35736 - per_cpu(kernel_stack, cpu) =
35737 - (unsigned long)task_stack_page(idle) -
35738 - KERNEL_STACK_OFFSET + THREAD_SIZE;
35739 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
35740
35741 xen_setup_runstate_info(cpu);
35742 xen_setup_timer(cpu);
35743 @@ -720,7 +715,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
35744
35745 void __init xen_smp_init(void)
35746 {
35747 - smp_ops = xen_smp_ops;
35748 + memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
35749 xen_fill_possible_map();
35750 }
35751
35752 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
35753 index fd92a64..1f72641 100644
35754 --- a/arch/x86/xen/xen-asm_32.S
35755 +++ b/arch/x86/xen/xen-asm_32.S
35756 @@ -99,7 +99,7 @@ ENTRY(xen_iret)
35757 pushw %fs
35758 movl $(__KERNEL_PERCPU), %eax
35759 movl %eax, %fs
35760 - movl %fs:xen_vcpu, %eax
35761 + mov PER_CPU_VAR(xen_vcpu), %eax
35762 POP_FS
35763 #else
35764 movl %ss:xen_vcpu, %eax
35765 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
35766 index 485b695..fda3e7c 100644
35767 --- a/arch/x86/xen/xen-head.S
35768 +++ b/arch/x86/xen/xen-head.S
35769 @@ -39,6 +39,17 @@ ENTRY(startup_xen)
35770 #ifdef CONFIG_X86_32
35771 mov %esi,xen_start_info
35772 mov $init_thread_union+THREAD_SIZE,%esp
35773 +#ifdef CONFIG_SMP
35774 + movl $cpu_gdt_table,%edi
35775 + movl $__per_cpu_load,%eax
35776 + movw %ax,__KERNEL_PERCPU + 2(%edi)
35777 + rorl $16,%eax
35778 + movb %al,__KERNEL_PERCPU + 4(%edi)
35779 + movb %ah,__KERNEL_PERCPU + 7(%edi)
35780 + movl $__per_cpu_end - 1,%eax
35781 + subl $__per_cpu_start,%eax
35782 + movw %ax,__KERNEL_PERCPU + 0(%edi)
35783 +#endif
35784 #else
35785 mov %rsi,xen_start_info
35786 mov $init_thread_union+THREAD_SIZE,%rsp
35787 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
35788 index 1cb6f4c..9981524 100644
35789 --- a/arch/x86/xen/xen-ops.h
35790 +++ b/arch/x86/xen/xen-ops.h
35791 @@ -10,8 +10,6 @@
35792 extern const char xen_hypervisor_callback[];
35793 extern const char xen_failsafe_callback[];
35794
35795 -extern void *xen_initial_gdt;
35796 -
35797 struct trap_info;
35798 void xen_copy_trap_info(struct trap_info *traps);
35799
35800 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
35801 index 525bd3d..ef888b1 100644
35802 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
35803 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
35804 @@ -119,9 +119,9 @@
35805 ----------------------------------------------------------------------*/
35806
35807 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
35808 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
35809 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
35810 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
35811 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35812
35813 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
35814 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
35815 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
35816 index 2f33760..835e50a 100644
35817 --- a/arch/xtensa/variants/fsf/include/variant/core.h
35818 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
35819 @@ -11,6 +11,7 @@
35820 #ifndef _XTENSA_CORE_H
35821 #define _XTENSA_CORE_H
35822
35823 +#include <linux/const.h>
35824
35825 /****************************************************************************
35826 Parameters Useful for Any Code, USER or PRIVILEGED
35827 @@ -112,9 +113,9 @@
35828 ----------------------------------------------------------------------*/
35829
35830 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35831 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35832 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35833 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35834 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35835
35836 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
35837 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
35838 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
35839 index af00795..2bb8105 100644
35840 --- a/arch/xtensa/variants/s6000/include/variant/core.h
35841 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
35842 @@ -11,6 +11,7 @@
35843 #ifndef _XTENSA_CORE_CONFIGURATION_H
35844 #define _XTENSA_CORE_CONFIGURATION_H
35845
35846 +#include <linux/const.h>
35847
35848 /****************************************************************************
35849 Parameters Useful for Any Code, USER or PRIVILEGED
35850 @@ -118,9 +119,9 @@
35851 ----------------------------------------------------------------------*/
35852
35853 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35854 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35855 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35856 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35857 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35858
35859 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
35860 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
35861 diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
35862 index 95ee425..c9c7237 100644
35863 --- a/block/blk-cgroup.c
35864 +++ b/block/blk-cgroup.c
35865 @@ -822,7 +822,7 @@ static void blkcg_css_free(struct cgroup_subsys_state *css)
35866 static struct cgroup_subsys_state *
35867 blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
35868 {
35869 - static atomic64_t id_seq = ATOMIC64_INIT(0);
35870 + static atomic64_unchecked_t id_seq = ATOMIC64_INIT(0);
35871 struct blkcg *blkcg;
35872
35873 if (!parent_css) {
35874 @@ -836,7 +836,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
35875
35876 blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
35877 blkcg->cfq_leaf_weight = CFQ_WEIGHT_DEFAULT;
35878 - blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
35879 + blkcg->id = atomic64_inc_return_unchecked(&id_seq); /* root is 0, start from 1 */
35880 done:
35881 spin_lock_init(&blkcg->lock);
35882 INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
35883 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
35884 index c11d24e..e915d24 100644
35885 --- a/block/blk-iopoll.c
35886 +++ b/block/blk-iopoll.c
35887 @@ -74,7 +74,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
35888 }
35889 EXPORT_SYMBOL(blk_iopoll_complete);
35890
35891 -static void blk_iopoll_softirq(struct softirq_action *h)
35892 +static __latent_entropy void blk_iopoll_softirq(void)
35893 {
35894 struct list_head *list = this_cpu_ptr(&blk_cpu_iopoll);
35895 int rearm = 0, budget = blk_iopoll_budget;
35896 diff --git a/block/blk-map.c b/block/blk-map.c
35897 index f7b22bc..ec2ddf4 100644
35898 --- a/block/blk-map.c
35899 +++ b/block/blk-map.c
35900 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
35901 if (!len || !kbuf)
35902 return -EINVAL;
35903
35904 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
35905 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
35906 if (do_copy)
35907 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
35908 else
35909 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
35910 index 53b1737..08177d2e 100644
35911 --- a/block/blk-softirq.c
35912 +++ b/block/blk-softirq.c
35913 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
35914 * Softirq action handler - move entries to local list and loop over them
35915 * while passing them to the queue registered handler.
35916 */
35917 -static void blk_done_softirq(struct softirq_action *h)
35918 +static __latent_entropy void blk_done_softirq(void)
35919 {
35920 struct list_head *cpu_list, local_list;
35921
35922 diff --git a/block/bsg.c b/block/bsg.c
35923 index 420a5a9..23834aa 100644
35924 --- a/block/bsg.c
35925 +++ b/block/bsg.c
35926 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
35927 struct sg_io_v4 *hdr, struct bsg_device *bd,
35928 fmode_t has_write_perm)
35929 {
35930 + unsigned char tmpcmd[sizeof(rq->__cmd)];
35931 + unsigned char *cmdptr;
35932 +
35933 if (hdr->request_len > BLK_MAX_CDB) {
35934 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
35935 if (!rq->cmd)
35936 return -ENOMEM;
35937 - }
35938 + cmdptr = rq->cmd;
35939 + } else
35940 + cmdptr = tmpcmd;
35941
35942 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
35943 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
35944 hdr->request_len))
35945 return -EFAULT;
35946
35947 + if (cmdptr != rq->cmd)
35948 + memcpy(rq->cmd, cmdptr, hdr->request_len);
35949 +
35950 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
35951 if (blk_verify_command(rq->cmd, has_write_perm))
35952 return -EPERM;
35953 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
35954 index fbd5a67..f24fd95 100644
35955 --- a/block/compat_ioctl.c
35956 +++ b/block/compat_ioctl.c
35957 @@ -156,7 +156,7 @@ static int compat_cdrom_generic_command(struct block_device *bdev, fmode_t mode,
35958 cgc = compat_alloc_user_space(sizeof(*cgc));
35959 cgc32 = compat_ptr(arg);
35960
35961 - if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
35962 + if (copy_in_user(cgc->cmd, cgc32->cmd, sizeof(cgc->cmd)) ||
35963 get_user(data, &cgc32->buffer) ||
35964 put_user(compat_ptr(data), &cgc->buffer) ||
35965 copy_in_user(&cgc->buflen, &cgc32->buflen,
35966 @@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
35967 err |= __get_user(f->spec1, &uf->spec1);
35968 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
35969 err |= __get_user(name, &uf->name);
35970 - f->name = compat_ptr(name);
35971 + f->name = (void __force_kernel *)compat_ptr(name);
35972 if (err) {
35973 err = -EFAULT;
35974 goto out;
35975 diff --git a/block/genhd.c b/block/genhd.c
35976 index 791f419..89f21c4 100644
35977 --- a/block/genhd.c
35978 +++ b/block/genhd.c
35979 @@ -467,21 +467,24 @@ static char *bdevt_str(dev_t devt, char *buf)
35980
35981 /*
35982 * Register device numbers dev..(dev+range-1)
35983 - * range must be nonzero
35984 + * Noop if @range is zero.
35985 * The hash chain is sorted on range, so that subranges can override.
35986 */
35987 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
35988 struct kobject *(*probe)(dev_t, int *, void *),
35989 int (*lock)(dev_t, void *), void *data)
35990 {
35991 - kobj_map(bdev_map, devt, range, module, probe, lock, data);
35992 + if (range)
35993 + kobj_map(bdev_map, devt, range, module, probe, lock, data);
35994 }
35995
35996 EXPORT_SYMBOL(blk_register_region);
35997
35998 +/* undo blk_register_region(), noop if @range is zero */
35999 void blk_unregister_region(dev_t devt, unsigned long range)
36000 {
36001 - kobj_unmap(bdev_map, devt, range);
36002 + if (range)
36003 + kobj_unmap(bdev_map, devt, range);
36004 }
36005
36006 EXPORT_SYMBOL(blk_unregister_region);
36007 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
36008 index dc51f46..d5446a8 100644
36009 --- a/block/partitions/efi.c
36010 +++ b/block/partitions/efi.c
36011 @@ -293,14 +293,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
36012 if (!gpt)
36013 return NULL;
36014
36015 + if (!le32_to_cpu(gpt->num_partition_entries))
36016 + return NULL;
36017 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
36018 + if (!pte)
36019 + return NULL;
36020 +
36021 count = le32_to_cpu(gpt->num_partition_entries) *
36022 le32_to_cpu(gpt->sizeof_partition_entry);
36023 - if (!count)
36024 - return NULL;
36025 - pte = kmalloc(count, GFP_KERNEL);
36026 - if (!pte)
36027 - return NULL;
36028 -
36029 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
36030 (u8 *) pte, count) < count) {
36031 kfree(pte);
36032 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
36033 index 2648797..92ed21f 100644
36034 --- a/block/scsi_ioctl.c
36035 +++ b/block/scsi_ioctl.c
36036 @@ -67,7 +67,7 @@ static int scsi_get_bus(struct request_queue *q, int __user *p)
36037 return put_user(0, p);
36038 }
36039
36040 -static int sg_get_timeout(struct request_queue *q)
36041 +static int __intentional_overflow(-1) sg_get_timeout(struct request_queue *q)
36042 {
36043 return jiffies_to_clock_t(q->sg_timeout);
36044 }
36045 @@ -224,8 +224,20 @@ EXPORT_SYMBOL(blk_verify_command);
36046 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
36047 struct sg_io_hdr *hdr, fmode_t mode)
36048 {
36049 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
36050 + unsigned char tmpcmd[sizeof(rq->__cmd)];
36051 + unsigned char *cmdptr;
36052 +
36053 + if (rq->cmd != rq->__cmd)
36054 + cmdptr = rq->cmd;
36055 + else
36056 + cmdptr = tmpcmd;
36057 +
36058 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
36059 return -EFAULT;
36060 +
36061 + if (cmdptr != rq->cmd)
36062 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
36063 +
36064 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
36065 return -EPERM;
36066
36067 @@ -417,6 +429,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
36068 int err;
36069 unsigned int in_len, out_len, bytes, opcode, cmdlen;
36070 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
36071 + unsigned char tmpcmd[sizeof(rq->__cmd)];
36072 + unsigned char *cmdptr;
36073
36074 if (!sic)
36075 return -EINVAL;
36076 @@ -450,9 +464,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
36077 */
36078 err = -EFAULT;
36079 rq->cmd_len = cmdlen;
36080 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
36081 +
36082 + if (rq->cmd != rq->__cmd)
36083 + cmdptr = rq->cmd;
36084 + else
36085 + cmdptr = tmpcmd;
36086 +
36087 + if (copy_from_user(cmdptr, sic->data, cmdlen))
36088 goto error;
36089
36090 + if (rq->cmd != cmdptr)
36091 + memcpy(rq->cmd, cmdptr, cmdlen);
36092 +
36093 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
36094 goto error;
36095
36096 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
36097 index 7bdd61b..afec999 100644
36098 --- a/crypto/cryptd.c
36099 +++ b/crypto/cryptd.c
36100 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
36101
36102 struct cryptd_blkcipher_request_ctx {
36103 crypto_completion_t complete;
36104 -};
36105 +} __no_const;
36106
36107 struct cryptd_hash_ctx {
36108 struct crypto_shash *child;
36109 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
36110
36111 struct cryptd_aead_request_ctx {
36112 crypto_completion_t complete;
36113 -};
36114 +} __no_const;
36115
36116 static void cryptd_queue_worker(struct work_struct *work);
36117
36118 diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
36119 index 309d345..1632720 100644
36120 --- a/crypto/pcrypt.c
36121 +++ b/crypto/pcrypt.c
36122 @@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
36123 int ret;
36124
36125 pinst->kobj.kset = pcrypt_kset;
36126 - ret = kobject_add(&pinst->kobj, NULL, name);
36127 + ret = kobject_add(&pinst->kobj, NULL, "%s", name);
36128 if (!ret)
36129 kobject_uevent(&pinst->kobj, KOBJ_ADD);
36130
36131 diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c
36132 index 6921c7f..78e1af7 100644
36133 --- a/drivers/acpi/acpica/hwxfsleep.c
36134 +++ b/drivers/acpi/acpica/hwxfsleep.c
36135 @@ -63,11 +63,12 @@ static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id);
36136 /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
36137
36138 static struct acpi_sleep_functions acpi_sleep_dispatch[] = {
36139 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
36140 - acpi_hw_extended_sleep},
36141 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
36142 - acpi_hw_extended_wake_prep},
36143 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake), acpi_hw_extended_wake}
36144 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
36145 + .extended_function = acpi_hw_extended_sleep},
36146 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
36147 + .extended_function = acpi_hw_extended_wake_prep},
36148 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake),
36149 + .extended_function = acpi_hw_extended_wake}
36150 };
36151
36152 /*
36153 diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
36154 index e5bcd91..74f050d 100644
36155 --- a/drivers/acpi/apei/apei-internal.h
36156 +++ b/drivers/acpi/apei/apei-internal.h
36157 @@ -19,7 +19,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
36158 struct apei_exec_ins_type {
36159 u32 flags;
36160 apei_exec_ins_func_t run;
36161 -};
36162 +} __do_const;
36163
36164 struct apei_exec_context {
36165 u32 ip;
36166 diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
36167 index dab7cb7..f0d2994 100644
36168 --- a/drivers/acpi/apei/ghes.c
36169 +++ b/drivers/acpi/apei/ghes.c
36170 @@ -500,7 +500,7 @@ static void __ghes_print_estatus(const char *pfx,
36171 const struct acpi_hest_generic *generic,
36172 const struct acpi_generic_status *estatus)
36173 {
36174 - static atomic_t seqno;
36175 + static atomic_unchecked_t seqno;
36176 unsigned int curr_seqno;
36177 char pfx_seq[64];
36178
36179 @@ -511,7 +511,7 @@ static void __ghes_print_estatus(const char *pfx,
36180 else
36181 pfx = KERN_ERR;
36182 }
36183 - curr_seqno = atomic_inc_return(&seqno);
36184 + curr_seqno = atomic_inc_return_unchecked(&seqno);
36185 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
36186 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
36187 pfx_seq, generic->header.source_id);
36188 diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
36189 index a83e3c6..c3d617f 100644
36190 --- a/drivers/acpi/bgrt.c
36191 +++ b/drivers/acpi/bgrt.c
36192 @@ -86,8 +86,10 @@ static int __init bgrt_init(void)
36193 if (!bgrt_image)
36194 return -ENODEV;
36195
36196 - bin_attr_image.private = bgrt_image;
36197 - bin_attr_image.size = bgrt_image_size;
36198 + pax_open_kernel();
36199 + *(void **)&bin_attr_image.private = bgrt_image;
36200 + *(size_t *)&bin_attr_image.size = bgrt_image_size;
36201 + pax_close_kernel();
36202
36203 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
36204 if (!bgrt_kobj)
36205 diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
36206 index 3d8413d..95f638c 100644
36207 --- a/drivers/acpi/blacklist.c
36208 +++ b/drivers/acpi/blacklist.c
36209 @@ -51,7 +51,7 @@ struct acpi_blacklist_item {
36210 u32 is_critical_error;
36211 };
36212
36213 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
36214 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
36215
36216 /*
36217 * POLICY: If *anything* doesn't work, put it on the blacklist.
36218 @@ -163,7 +163,7 @@ static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
36219 return 0;
36220 }
36221
36222 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
36223 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
36224 {
36225 .callback = dmi_disable_osi_vista,
36226 .ident = "Fujitsu Siemens",
36227 diff --git a/drivers/acpi/custom_method.c b/drivers/acpi/custom_method.c
36228 index c68e724..e863008 100644
36229 --- a/drivers/acpi/custom_method.c
36230 +++ b/drivers/acpi/custom_method.c
36231 @@ -29,6 +29,10 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf,
36232 struct acpi_table_header table;
36233 acpi_status status;
36234
36235 +#ifdef CONFIG_GRKERNSEC_KMEM
36236 + return -EPERM;
36237 +#endif
36238 +
36239 if (!(*ppos)) {
36240 /* parse the table header to get the table length */
36241 if (count <= sizeof(struct acpi_table_header))
36242 diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
36243 index 3dca36d..abaf070 100644
36244 --- a/drivers/acpi/processor_idle.c
36245 +++ b/drivers/acpi/processor_idle.c
36246 @@ -952,7 +952,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
36247 {
36248 int i, count = CPUIDLE_DRIVER_STATE_START;
36249 struct acpi_processor_cx *cx;
36250 - struct cpuidle_state *state;
36251 + cpuidle_state_no_const *state;
36252 struct cpuidle_driver *drv = &acpi_idle_driver;
36253
36254 if (!pr->flags.power_setup_done)
36255 diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
36256 index 38cb978..352c761 100644
36257 --- a/drivers/acpi/sysfs.c
36258 +++ b/drivers/acpi/sysfs.c
36259 @@ -423,11 +423,11 @@ static u32 num_counters;
36260 static struct attribute **all_attrs;
36261 static u32 acpi_gpe_count;
36262
36263 -static struct attribute_group interrupt_stats_attr_group = {
36264 +static attribute_group_no_const interrupt_stats_attr_group = {
36265 .name = "interrupts",
36266 };
36267
36268 -static struct kobj_attribute *counter_attrs;
36269 +static kobj_attribute_no_const *counter_attrs;
36270
36271 static void delete_gpe_attr_array(void)
36272 {
36273 diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
36274 index b986145..82bddb8 100644
36275 --- a/drivers/ata/libahci.c
36276 +++ b/drivers/ata/libahci.c
36277 @@ -1252,7 +1252,7 @@ int ahci_kick_engine(struct ata_port *ap)
36278 }
36279 EXPORT_SYMBOL_GPL(ahci_kick_engine);
36280
36281 -static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36282 +static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
36283 struct ata_taskfile *tf, int is_cmd, u16 flags,
36284 unsigned long timeout_msec)
36285 {
36286 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
36287 index 18d97d5..be690af 100644
36288 --- a/drivers/ata/libata-core.c
36289 +++ b/drivers/ata/libata-core.c
36290 @@ -98,7 +98,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
36291 static void ata_dev_xfermask(struct ata_device *dev);
36292 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
36293
36294 -atomic_t ata_print_id = ATOMIC_INIT(0);
36295 +atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
36296
36297 struct ata_force_param {
36298 const char *name;
36299 @@ -4858,7 +4858,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
36300 struct ata_port *ap;
36301 unsigned int tag;
36302
36303 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36304 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36305 ap = qc->ap;
36306
36307 qc->flags = 0;
36308 @@ -4874,7 +4874,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
36309 struct ata_port *ap;
36310 struct ata_link *link;
36311
36312 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36313 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
36314 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
36315 ap = qc->ap;
36316 link = qc->dev->link;
36317 @@ -5978,6 +5978,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36318 return;
36319
36320 spin_lock(&lock);
36321 + pax_open_kernel();
36322
36323 for (cur = ops->inherits; cur; cur = cur->inherits) {
36324 void **inherit = (void **)cur;
36325 @@ -5991,8 +5992,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
36326 if (IS_ERR(*pp))
36327 *pp = NULL;
36328
36329 - ops->inherits = NULL;
36330 + *(struct ata_port_operations **)&ops->inherits = NULL;
36331
36332 + pax_close_kernel();
36333 spin_unlock(&lock);
36334 }
36335
36336 @@ -6185,7 +6187,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
36337
36338 /* give ports names and add SCSI hosts */
36339 for (i = 0; i < host->n_ports; i++) {
36340 - host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
36341 + host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
36342 host->ports[i]->local_port_no = i + 1;
36343 }
36344
36345 diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
36346 index ef8567d..8bdbd03 100644
36347 --- a/drivers/ata/libata-scsi.c
36348 +++ b/drivers/ata/libata-scsi.c
36349 @@ -4147,7 +4147,7 @@ int ata_sas_port_init(struct ata_port *ap)
36350
36351 if (rc)
36352 return rc;
36353 - ap->print_id = atomic_inc_return(&ata_print_id);
36354 + ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
36355 return 0;
36356 }
36357 EXPORT_SYMBOL_GPL(ata_sas_port_init);
36358 diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
36359 index 45b5ab3..98446b8 100644
36360 --- a/drivers/ata/libata.h
36361 +++ b/drivers/ata/libata.h
36362 @@ -53,7 +53,7 @@ enum {
36363 ATA_DNXFER_QUIET = (1 << 31),
36364 };
36365
36366 -extern atomic_t ata_print_id;
36367 +extern atomic_unchecked_t ata_print_id;
36368 extern int atapi_passthru16;
36369 extern int libata_fua;
36370 extern int libata_noacpi;
36371 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
36372 index 4edb1a8..84e1658 100644
36373 --- a/drivers/ata/pata_arasan_cf.c
36374 +++ b/drivers/ata/pata_arasan_cf.c
36375 @@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
36376 /* Handle platform specific quirks */
36377 if (quirk) {
36378 if (quirk & CF_BROKEN_PIO) {
36379 - ap->ops->set_piomode = NULL;
36380 + pax_open_kernel();
36381 + *(void **)&ap->ops->set_piomode = NULL;
36382 + pax_close_kernel();
36383 ap->pio_mask = 0;
36384 }
36385 if (quirk & CF_BROKEN_MWDMA)
36386 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
36387 index f9b983a..887b9d8 100644
36388 --- a/drivers/atm/adummy.c
36389 +++ b/drivers/atm/adummy.c
36390 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
36391 vcc->pop(vcc, skb);
36392 else
36393 dev_kfree_skb_any(skb);
36394 - atomic_inc(&vcc->stats->tx);
36395 + atomic_inc_unchecked(&vcc->stats->tx);
36396
36397 return 0;
36398 }
36399 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
36400 index f1a9198..f466a4a 100644
36401 --- a/drivers/atm/ambassador.c
36402 +++ b/drivers/atm/ambassador.c
36403 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
36404 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
36405
36406 // VC layer stats
36407 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36408 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36409
36410 // free the descriptor
36411 kfree (tx_descr);
36412 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36413 dump_skb ("<<<", vc, skb);
36414
36415 // VC layer stats
36416 - atomic_inc(&atm_vcc->stats->rx);
36417 + atomic_inc_unchecked(&atm_vcc->stats->rx);
36418 __net_timestamp(skb);
36419 // end of our responsibility
36420 atm_vcc->push (atm_vcc, skb);
36421 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
36422 } else {
36423 PRINTK (KERN_INFO, "dropped over-size frame");
36424 // should we count this?
36425 - atomic_inc(&atm_vcc->stats->rx_drop);
36426 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36427 }
36428
36429 } else {
36430 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
36431 }
36432
36433 if (check_area (skb->data, skb->len)) {
36434 - atomic_inc(&atm_vcc->stats->tx_err);
36435 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
36436 return -ENOMEM; // ?
36437 }
36438
36439 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
36440 index 0e3f8f9..765a7a5 100644
36441 --- a/drivers/atm/atmtcp.c
36442 +++ b/drivers/atm/atmtcp.c
36443 @@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36444 if (vcc->pop) vcc->pop(vcc,skb);
36445 else dev_kfree_skb(skb);
36446 if (dev_data) return 0;
36447 - atomic_inc(&vcc->stats->tx_err);
36448 + atomic_inc_unchecked(&vcc->stats->tx_err);
36449 return -ENOLINK;
36450 }
36451 size = skb->len+sizeof(struct atmtcp_hdr);
36452 @@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36453 if (!new_skb) {
36454 if (vcc->pop) vcc->pop(vcc,skb);
36455 else dev_kfree_skb(skb);
36456 - atomic_inc(&vcc->stats->tx_err);
36457 + atomic_inc_unchecked(&vcc->stats->tx_err);
36458 return -ENOBUFS;
36459 }
36460 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
36461 @@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
36462 if (vcc->pop) vcc->pop(vcc,skb);
36463 else dev_kfree_skb(skb);
36464 out_vcc->push(out_vcc,new_skb);
36465 - atomic_inc(&vcc->stats->tx);
36466 - atomic_inc(&out_vcc->stats->rx);
36467 + atomic_inc_unchecked(&vcc->stats->tx);
36468 + atomic_inc_unchecked(&out_vcc->stats->rx);
36469 return 0;
36470 }
36471
36472 @@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36473 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
36474 read_unlock(&vcc_sklist_lock);
36475 if (!out_vcc) {
36476 - atomic_inc(&vcc->stats->tx_err);
36477 + atomic_inc_unchecked(&vcc->stats->tx_err);
36478 goto done;
36479 }
36480 skb_pull(skb,sizeof(struct atmtcp_hdr));
36481 @@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
36482 __net_timestamp(new_skb);
36483 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
36484 out_vcc->push(out_vcc,new_skb);
36485 - atomic_inc(&vcc->stats->tx);
36486 - atomic_inc(&out_vcc->stats->rx);
36487 + atomic_inc_unchecked(&vcc->stats->tx);
36488 + atomic_inc_unchecked(&out_vcc->stats->rx);
36489 done:
36490 if (vcc->pop) vcc->pop(vcc,skb);
36491 else dev_kfree_skb(skb);
36492 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
36493 index b1955ba..b179940 100644
36494 --- a/drivers/atm/eni.c
36495 +++ b/drivers/atm/eni.c
36496 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
36497 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
36498 vcc->dev->number);
36499 length = 0;
36500 - atomic_inc(&vcc->stats->rx_err);
36501 + atomic_inc_unchecked(&vcc->stats->rx_err);
36502 }
36503 else {
36504 length = ATM_CELL_SIZE-1; /* no HEC */
36505 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36506 size);
36507 }
36508 eff = length = 0;
36509 - atomic_inc(&vcc->stats->rx_err);
36510 + atomic_inc_unchecked(&vcc->stats->rx_err);
36511 }
36512 else {
36513 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
36514 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
36515 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
36516 vcc->dev->number,vcc->vci,length,size << 2,descr);
36517 length = eff = 0;
36518 - atomic_inc(&vcc->stats->rx_err);
36519 + atomic_inc_unchecked(&vcc->stats->rx_err);
36520 }
36521 }
36522 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
36523 @@ -767,7 +767,7 @@ rx_dequeued++;
36524 vcc->push(vcc,skb);
36525 pushed++;
36526 }
36527 - atomic_inc(&vcc->stats->rx);
36528 + atomic_inc_unchecked(&vcc->stats->rx);
36529 }
36530 wake_up(&eni_dev->rx_wait);
36531 }
36532 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
36533 PCI_DMA_TODEVICE);
36534 if (vcc->pop) vcc->pop(vcc,skb);
36535 else dev_kfree_skb_irq(skb);
36536 - atomic_inc(&vcc->stats->tx);
36537 + atomic_inc_unchecked(&vcc->stats->tx);
36538 wake_up(&eni_dev->tx_wait);
36539 dma_complete++;
36540 }
36541 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
36542 index 82f2ae0..f205c02 100644
36543 --- a/drivers/atm/firestream.c
36544 +++ b/drivers/atm/firestream.c
36545 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
36546 }
36547 }
36548
36549 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36550 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36551
36552 fs_dprintk (FS_DEBUG_TXMEM, "i");
36553 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
36554 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36555 #endif
36556 skb_put (skb, qe->p1 & 0xffff);
36557 ATM_SKB(skb)->vcc = atm_vcc;
36558 - atomic_inc(&atm_vcc->stats->rx);
36559 + atomic_inc_unchecked(&atm_vcc->stats->rx);
36560 __net_timestamp(skb);
36561 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
36562 atm_vcc->push (atm_vcc, skb);
36563 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
36564 kfree (pe);
36565 }
36566 if (atm_vcc)
36567 - atomic_inc(&atm_vcc->stats->rx_drop);
36568 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36569 break;
36570 case 0x1f: /* Reassembly abort: no buffers. */
36571 /* Silently increment error counter. */
36572 if (atm_vcc)
36573 - atomic_inc(&atm_vcc->stats->rx_drop);
36574 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
36575 break;
36576 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
36577 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
36578 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
36579 index 204814e..cede831 100644
36580 --- a/drivers/atm/fore200e.c
36581 +++ b/drivers/atm/fore200e.c
36582 @@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
36583 #endif
36584 /* check error condition */
36585 if (*entry->status & STATUS_ERROR)
36586 - atomic_inc(&vcc->stats->tx_err);
36587 + atomic_inc_unchecked(&vcc->stats->tx_err);
36588 else
36589 - atomic_inc(&vcc->stats->tx);
36590 + atomic_inc_unchecked(&vcc->stats->tx);
36591 }
36592 }
36593
36594 @@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36595 if (skb == NULL) {
36596 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
36597
36598 - atomic_inc(&vcc->stats->rx_drop);
36599 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36600 return -ENOMEM;
36601 }
36602
36603 @@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
36604
36605 dev_kfree_skb_any(skb);
36606
36607 - atomic_inc(&vcc->stats->rx_drop);
36608 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36609 return -ENOMEM;
36610 }
36611
36612 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36613
36614 vcc->push(vcc, skb);
36615 - atomic_inc(&vcc->stats->rx);
36616 + atomic_inc_unchecked(&vcc->stats->rx);
36617
36618 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
36619
36620 @@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
36621 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
36622 fore200e->atm_dev->number,
36623 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
36624 - atomic_inc(&vcc->stats->rx_err);
36625 + atomic_inc_unchecked(&vcc->stats->rx_err);
36626 }
36627 }
36628
36629 @@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
36630 goto retry_here;
36631 }
36632
36633 - atomic_inc(&vcc->stats->tx_err);
36634 + atomic_inc_unchecked(&vcc->stats->tx_err);
36635
36636 fore200e->tx_sat++;
36637 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
36638 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
36639 index aa6be26..f70a785 100644
36640 --- a/drivers/atm/he.c
36641 +++ b/drivers/atm/he.c
36642 @@ -1690,7 +1690,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36643
36644 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
36645 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
36646 - atomic_inc(&vcc->stats->rx_drop);
36647 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36648 goto return_host_buffers;
36649 }
36650
36651 @@ -1717,7 +1717,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36652 RBRQ_LEN_ERR(he_dev->rbrq_head)
36653 ? "LEN_ERR" : "",
36654 vcc->vpi, vcc->vci);
36655 - atomic_inc(&vcc->stats->rx_err);
36656 + atomic_inc_unchecked(&vcc->stats->rx_err);
36657 goto return_host_buffers;
36658 }
36659
36660 @@ -1769,7 +1769,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
36661 vcc->push(vcc, skb);
36662 spin_lock(&he_dev->global_lock);
36663
36664 - atomic_inc(&vcc->stats->rx);
36665 + atomic_inc_unchecked(&vcc->stats->rx);
36666
36667 return_host_buffers:
36668 ++pdus_assembled;
36669 @@ -2095,7 +2095,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
36670 tpd->vcc->pop(tpd->vcc, tpd->skb);
36671 else
36672 dev_kfree_skb_any(tpd->skb);
36673 - atomic_inc(&tpd->vcc->stats->tx_err);
36674 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
36675 }
36676 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
36677 return;
36678 @@ -2507,7 +2507,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36679 vcc->pop(vcc, skb);
36680 else
36681 dev_kfree_skb_any(skb);
36682 - atomic_inc(&vcc->stats->tx_err);
36683 + atomic_inc_unchecked(&vcc->stats->tx_err);
36684 return -EINVAL;
36685 }
36686
36687 @@ -2518,7 +2518,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36688 vcc->pop(vcc, skb);
36689 else
36690 dev_kfree_skb_any(skb);
36691 - atomic_inc(&vcc->stats->tx_err);
36692 + atomic_inc_unchecked(&vcc->stats->tx_err);
36693 return -EINVAL;
36694 }
36695 #endif
36696 @@ -2530,7 +2530,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36697 vcc->pop(vcc, skb);
36698 else
36699 dev_kfree_skb_any(skb);
36700 - atomic_inc(&vcc->stats->tx_err);
36701 + atomic_inc_unchecked(&vcc->stats->tx_err);
36702 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36703 return -ENOMEM;
36704 }
36705 @@ -2572,7 +2572,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36706 vcc->pop(vcc, skb);
36707 else
36708 dev_kfree_skb_any(skb);
36709 - atomic_inc(&vcc->stats->tx_err);
36710 + atomic_inc_unchecked(&vcc->stats->tx_err);
36711 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36712 return -ENOMEM;
36713 }
36714 @@ -2603,7 +2603,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36715 __enqueue_tpd(he_dev, tpd, cid);
36716 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36717
36718 - atomic_inc(&vcc->stats->tx);
36719 + atomic_inc_unchecked(&vcc->stats->tx);
36720
36721 return 0;
36722 }
36723 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
36724 index 1dc0519..1aadaf7 100644
36725 --- a/drivers/atm/horizon.c
36726 +++ b/drivers/atm/horizon.c
36727 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
36728 {
36729 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
36730 // VC layer stats
36731 - atomic_inc(&vcc->stats->rx);
36732 + atomic_inc_unchecked(&vcc->stats->rx);
36733 __net_timestamp(skb);
36734 // end of our responsibility
36735 vcc->push (vcc, skb);
36736 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
36737 dev->tx_iovec = NULL;
36738
36739 // VC layer stats
36740 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36741 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36742
36743 // free the skb
36744 hrz_kfree_skb (skb);
36745 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
36746 index 1bdf104..9dc44b1 100644
36747 --- a/drivers/atm/idt77252.c
36748 +++ b/drivers/atm/idt77252.c
36749 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
36750 else
36751 dev_kfree_skb(skb);
36752
36753 - atomic_inc(&vcc->stats->tx);
36754 + atomic_inc_unchecked(&vcc->stats->tx);
36755 }
36756
36757 atomic_dec(&scq->used);
36758 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36759 if ((sb = dev_alloc_skb(64)) == NULL) {
36760 printk("%s: Can't allocate buffers for aal0.\n",
36761 card->name);
36762 - atomic_add(i, &vcc->stats->rx_drop);
36763 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
36764 break;
36765 }
36766 if (!atm_charge(vcc, sb->truesize)) {
36767 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
36768 card->name);
36769 - atomic_add(i - 1, &vcc->stats->rx_drop);
36770 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
36771 dev_kfree_skb(sb);
36772 break;
36773 }
36774 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36775 ATM_SKB(sb)->vcc = vcc;
36776 __net_timestamp(sb);
36777 vcc->push(vcc, sb);
36778 - atomic_inc(&vcc->stats->rx);
36779 + atomic_inc_unchecked(&vcc->stats->rx);
36780
36781 cell += ATM_CELL_PAYLOAD;
36782 }
36783 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36784 "(CDC: %08x)\n",
36785 card->name, len, rpp->len, readl(SAR_REG_CDC));
36786 recycle_rx_pool_skb(card, rpp);
36787 - atomic_inc(&vcc->stats->rx_err);
36788 + atomic_inc_unchecked(&vcc->stats->rx_err);
36789 return;
36790 }
36791 if (stat & SAR_RSQE_CRC) {
36792 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
36793 recycle_rx_pool_skb(card, rpp);
36794 - atomic_inc(&vcc->stats->rx_err);
36795 + atomic_inc_unchecked(&vcc->stats->rx_err);
36796 return;
36797 }
36798 if (skb_queue_len(&rpp->queue) > 1) {
36799 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36800 RXPRINTK("%s: Can't alloc RX skb.\n",
36801 card->name);
36802 recycle_rx_pool_skb(card, rpp);
36803 - atomic_inc(&vcc->stats->rx_err);
36804 + atomic_inc_unchecked(&vcc->stats->rx_err);
36805 return;
36806 }
36807 if (!atm_charge(vcc, skb->truesize)) {
36808 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36809 __net_timestamp(skb);
36810
36811 vcc->push(vcc, skb);
36812 - atomic_inc(&vcc->stats->rx);
36813 + atomic_inc_unchecked(&vcc->stats->rx);
36814
36815 return;
36816 }
36817 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36818 __net_timestamp(skb);
36819
36820 vcc->push(vcc, skb);
36821 - atomic_inc(&vcc->stats->rx);
36822 + atomic_inc_unchecked(&vcc->stats->rx);
36823
36824 if (skb->truesize > SAR_FB_SIZE_3)
36825 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
36826 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
36827 if (vcc->qos.aal != ATM_AAL0) {
36828 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
36829 card->name, vpi, vci);
36830 - atomic_inc(&vcc->stats->rx_drop);
36831 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36832 goto drop;
36833 }
36834
36835 if ((sb = dev_alloc_skb(64)) == NULL) {
36836 printk("%s: Can't allocate buffers for AAL0.\n",
36837 card->name);
36838 - atomic_inc(&vcc->stats->rx_err);
36839 + atomic_inc_unchecked(&vcc->stats->rx_err);
36840 goto drop;
36841 }
36842
36843 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
36844 ATM_SKB(sb)->vcc = vcc;
36845 __net_timestamp(sb);
36846 vcc->push(vcc, sb);
36847 - atomic_inc(&vcc->stats->rx);
36848 + atomic_inc_unchecked(&vcc->stats->rx);
36849
36850 drop:
36851 skb_pull(queue, 64);
36852 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36853
36854 if (vc == NULL) {
36855 printk("%s: NULL connection in send().\n", card->name);
36856 - atomic_inc(&vcc->stats->tx_err);
36857 + atomic_inc_unchecked(&vcc->stats->tx_err);
36858 dev_kfree_skb(skb);
36859 return -EINVAL;
36860 }
36861 if (!test_bit(VCF_TX, &vc->flags)) {
36862 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
36863 - atomic_inc(&vcc->stats->tx_err);
36864 + atomic_inc_unchecked(&vcc->stats->tx_err);
36865 dev_kfree_skb(skb);
36866 return -EINVAL;
36867 }
36868 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36869 break;
36870 default:
36871 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
36872 - atomic_inc(&vcc->stats->tx_err);
36873 + atomic_inc_unchecked(&vcc->stats->tx_err);
36874 dev_kfree_skb(skb);
36875 return -EINVAL;
36876 }
36877
36878 if (skb_shinfo(skb)->nr_frags != 0) {
36879 printk("%s: No scatter-gather yet.\n", card->name);
36880 - atomic_inc(&vcc->stats->tx_err);
36881 + atomic_inc_unchecked(&vcc->stats->tx_err);
36882 dev_kfree_skb(skb);
36883 return -EINVAL;
36884 }
36885 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36886
36887 err = queue_skb(card, vc, skb, oam);
36888 if (err) {
36889 - atomic_inc(&vcc->stats->tx_err);
36890 + atomic_inc_unchecked(&vcc->stats->tx_err);
36891 dev_kfree_skb(skb);
36892 return err;
36893 }
36894 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
36895 skb = dev_alloc_skb(64);
36896 if (!skb) {
36897 printk("%s: Out of memory in send_oam().\n", card->name);
36898 - atomic_inc(&vcc->stats->tx_err);
36899 + atomic_inc_unchecked(&vcc->stats->tx_err);
36900 return -ENOMEM;
36901 }
36902 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
36903 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
36904 index 4217f29..88f547a 100644
36905 --- a/drivers/atm/iphase.c
36906 +++ b/drivers/atm/iphase.c
36907 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
36908 status = (u_short) (buf_desc_ptr->desc_mode);
36909 if (status & (RX_CER | RX_PTE | RX_OFL))
36910 {
36911 - atomic_inc(&vcc->stats->rx_err);
36912 + atomic_inc_unchecked(&vcc->stats->rx_err);
36913 IF_ERR(printk("IA: bad packet, dropping it");)
36914 if (status & RX_CER) {
36915 IF_ERR(printk(" cause: packet CRC error\n");)
36916 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
36917 len = dma_addr - buf_addr;
36918 if (len > iadev->rx_buf_sz) {
36919 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
36920 - atomic_inc(&vcc->stats->rx_err);
36921 + atomic_inc_unchecked(&vcc->stats->rx_err);
36922 goto out_free_desc;
36923 }
36924
36925 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36926 ia_vcc = INPH_IA_VCC(vcc);
36927 if (ia_vcc == NULL)
36928 {
36929 - atomic_inc(&vcc->stats->rx_err);
36930 + atomic_inc_unchecked(&vcc->stats->rx_err);
36931 atm_return(vcc, skb->truesize);
36932 dev_kfree_skb_any(skb);
36933 goto INCR_DLE;
36934 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36935 if ((length > iadev->rx_buf_sz) || (length >
36936 (skb->len - sizeof(struct cpcs_trailer))))
36937 {
36938 - atomic_inc(&vcc->stats->rx_err);
36939 + atomic_inc_unchecked(&vcc->stats->rx_err);
36940 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
36941 length, skb->len);)
36942 atm_return(vcc, skb->truesize);
36943 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36944
36945 IF_RX(printk("rx_dle_intr: skb push");)
36946 vcc->push(vcc,skb);
36947 - atomic_inc(&vcc->stats->rx);
36948 + atomic_inc_unchecked(&vcc->stats->rx);
36949 iadev->rx_pkt_cnt++;
36950 }
36951 INCR_DLE:
36952 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
36953 {
36954 struct k_sonet_stats *stats;
36955 stats = &PRIV(_ia_dev[board])->sonet_stats;
36956 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
36957 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
36958 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
36959 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
36960 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
36961 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
36962 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
36963 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
36964 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
36965 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
36966 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
36967 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
36968 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
36969 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
36970 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
36971 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
36972 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
36973 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
36974 }
36975 ia_cmds.status = 0;
36976 break;
36977 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
36978 if ((desc == 0) || (desc > iadev->num_tx_desc))
36979 {
36980 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
36981 - atomic_inc(&vcc->stats->tx);
36982 + atomic_inc_unchecked(&vcc->stats->tx);
36983 if (vcc->pop)
36984 vcc->pop(vcc, skb);
36985 else
36986 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
36987 ATM_DESC(skb) = vcc->vci;
36988 skb_queue_tail(&iadev->tx_dma_q, skb);
36989
36990 - atomic_inc(&vcc->stats->tx);
36991 + atomic_inc_unchecked(&vcc->stats->tx);
36992 iadev->tx_pkt_cnt++;
36993 /* Increment transaction counter */
36994 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
36995
36996 #if 0
36997 /* add flow control logic */
36998 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
36999 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
37000 if (iavcc->vc_desc_cnt > 10) {
37001 vcc->tx_quota = vcc->tx_quota * 3 / 4;
37002 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
37003 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
37004 index fa7d701..1e404c7 100644
37005 --- a/drivers/atm/lanai.c
37006 +++ b/drivers/atm/lanai.c
37007 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
37008 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
37009 lanai_endtx(lanai, lvcc);
37010 lanai_free_skb(lvcc->tx.atmvcc, skb);
37011 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
37012 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
37013 }
37014
37015 /* Try to fill the buffer - don't call unless there is backlog */
37016 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
37017 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
37018 __net_timestamp(skb);
37019 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
37020 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
37021 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
37022 out:
37023 lvcc->rx.buf.ptr = end;
37024 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
37025 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37026 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
37027 "vcc %d\n", lanai->number, (unsigned int) s, vci);
37028 lanai->stats.service_rxnotaal5++;
37029 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37030 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37031 return 0;
37032 }
37033 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
37034 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37035 int bytes;
37036 read_unlock(&vcc_sklist_lock);
37037 DPRINTK("got trashed rx pdu on vci %d\n", vci);
37038 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37039 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37040 lvcc->stats.x.aal5.service_trash++;
37041 bytes = (SERVICE_GET_END(s) * 16) -
37042 (((unsigned long) lvcc->rx.buf.ptr) -
37043 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37044 }
37045 if (s & SERVICE_STREAM) {
37046 read_unlock(&vcc_sklist_lock);
37047 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37048 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37049 lvcc->stats.x.aal5.service_stream++;
37050 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
37051 "PDU on VCI %d!\n", lanai->number, vci);
37052 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
37053 return 0;
37054 }
37055 DPRINTK("got rx crc error on vci %d\n", vci);
37056 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
37057 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
37058 lvcc->stats.x.aal5.service_rxcrc++;
37059 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
37060 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
37061 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
37062 index 9988ac9..7c52585 100644
37063 --- a/drivers/atm/nicstar.c
37064 +++ b/drivers/atm/nicstar.c
37065 @@ -1640,7 +1640,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37066 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
37067 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
37068 card->index);
37069 - atomic_inc(&vcc->stats->tx_err);
37070 + atomic_inc_unchecked(&vcc->stats->tx_err);
37071 dev_kfree_skb_any(skb);
37072 return -EINVAL;
37073 }
37074 @@ -1648,7 +1648,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37075 if (!vc->tx) {
37076 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
37077 card->index);
37078 - atomic_inc(&vcc->stats->tx_err);
37079 + atomic_inc_unchecked(&vcc->stats->tx_err);
37080 dev_kfree_skb_any(skb);
37081 return -EINVAL;
37082 }
37083 @@ -1656,14 +1656,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37084 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
37085 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
37086 card->index);
37087 - atomic_inc(&vcc->stats->tx_err);
37088 + atomic_inc_unchecked(&vcc->stats->tx_err);
37089 dev_kfree_skb_any(skb);
37090 return -EINVAL;
37091 }
37092
37093 if (skb_shinfo(skb)->nr_frags != 0) {
37094 printk("nicstar%d: No scatter-gather yet.\n", card->index);
37095 - atomic_inc(&vcc->stats->tx_err);
37096 + atomic_inc_unchecked(&vcc->stats->tx_err);
37097 dev_kfree_skb_any(skb);
37098 return -EINVAL;
37099 }
37100 @@ -1711,11 +1711,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
37101 }
37102
37103 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
37104 - atomic_inc(&vcc->stats->tx_err);
37105 + atomic_inc_unchecked(&vcc->stats->tx_err);
37106 dev_kfree_skb_any(skb);
37107 return -EIO;
37108 }
37109 - atomic_inc(&vcc->stats->tx);
37110 + atomic_inc_unchecked(&vcc->stats->tx);
37111
37112 return 0;
37113 }
37114 @@ -2032,14 +2032,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37115 printk
37116 ("nicstar%d: Can't allocate buffers for aal0.\n",
37117 card->index);
37118 - atomic_add(i, &vcc->stats->rx_drop);
37119 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
37120 break;
37121 }
37122 if (!atm_charge(vcc, sb->truesize)) {
37123 RXPRINTK
37124 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
37125 card->index);
37126 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
37127 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
37128 dev_kfree_skb_any(sb);
37129 break;
37130 }
37131 @@ -2054,7 +2054,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37132 ATM_SKB(sb)->vcc = vcc;
37133 __net_timestamp(sb);
37134 vcc->push(vcc, sb);
37135 - atomic_inc(&vcc->stats->rx);
37136 + atomic_inc_unchecked(&vcc->stats->rx);
37137 cell += ATM_CELL_PAYLOAD;
37138 }
37139
37140 @@ -2071,7 +2071,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37141 if (iovb == NULL) {
37142 printk("nicstar%d: Out of iovec buffers.\n",
37143 card->index);
37144 - atomic_inc(&vcc->stats->rx_drop);
37145 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37146 recycle_rx_buf(card, skb);
37147 return;
37148 }
37149 @@ -2095,7 +2095,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37150 small or large buffer itself. */
37151 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
37152 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
37153 - atomic_inc(&vcc->stats->rx_err);
37154 + atomic_inc_unchecked(&vcc->stats->rx_err);
37155 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37156 NS_MAX_IOVECS);
37157 NS_PRV_IOVCNT(iovb) = 0;
37158 @@ -2115,7 +2115,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37159 ("nicstar%d: Expected a small buffer, and this is not one.\n",
37160 card->index);
37161 which_list(card, skb);
37162 - atomic_inc(&vcc->stats->rx_err);
37163 + atomic_inc_unchecked(&vcc->stats->rx_err);
37164 recycle_rx_buf(card, skb);
37165 vc->rx_iov = NULL;
37166 recycle_iov_buf(card, iovb);
37167 @@ -2128,7 +2128,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37168 ("nicstar%d: Expected a large buffer, and this is not one.\n",
37169 card->index);
37170 which_list(card, skb);
37171 - atomic_inc(&vcc->stats->rx_err);
37172 + atomic_inc_unchecked(&vcc->stats->rx_err);
37173 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37174 NS_PRV_IOVCNT(iovb));
37175 vc->rx_iov = NULL;
37176 @@ -2151,7 +2151,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37177 printk(" - PDU size mismatch.\n");
37178 else
37179 printk(".\n");
37180 - atomic_inc(&vcc->stats->rx_err);
37181 + atomic_inc_unchecked(&vcc->stats->rx_err);
37182 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
37183 NS_PRV_IOVCNT(iovb));
37184 vc->rx_iov = NULL;
37185 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37186 /* skb points to a small buffer */
37187 if (!atm_charge(vcc, skb->truesize)) {
37188 push_rxbufs(card, skb);
37189 - atomic_inc(&vcc->stats->rx_drop);
37190 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37191 } else {
37192 skb_put(skb, len);
37193 dequeue_sm_buf(card, skb);
37194 @@ -2175,7 +2175,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37195 ATM_SKB(skb)->vcc = vcc;
37196 __net_timestamp(skb);
37197 vcc->push(vcc, skb);
37198 - atomic_inc(&vcc->stats->rx);
37199 + atomic_inc_unchecked(&vcc->stats->rx);
37200 }
37201 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
37202 struct sk_buff *sb;
37203 @@ -2186,7 +2186,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37204 if (len <= NS_SMBUFSIZE) {
37205 if (!atm_charge(vcc, sb->truesize)) {
37206 push_rxbufs(card, sb);
37207 - atomic_inc(&vcc->stats->rx_drop);
37208 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37209 } else {
37210 skb_put(sb, len);
37211 dequeue_sm_buf(card, sb);
37212 @@ -2196,7 +2196,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37213 ATM_SKB(sb)->vcc = vcc;
37214 __net_timestamp(sb);
37215 vcc->push(vcc, sb);
37216 - atomic_inc(&vcc->stats->rx);
37217 + atomic_inc_unchecked(&vcc->stats->rx);
37218 }
37219
37220 push_rxbufs(card, skb);
37221 @@ -2205,7 +2205,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37222
37223 if (!atm_charge(vcc, skb->truesize)) {
37224 push_rxbufs(card, skb);
37225 - atomic_inc(&vcc->stats->rx_drop);
37226 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37227 } else {
37228 dequeue_lg_buf(card, skb);
37229 #ifdef NS_USE_DESTRUCTORS
37230 @@ -2218,7 +2218,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37231 ATM_SKB(skb)->vcc = vcc;
37232 __net_timestamp(skb);
37233 vcc->push(vcc, skb);
37234 - atomic_inc(&vcc->stats->rx);
37235 + atomic_inc_unchecked(&vcc->stats->rx);
37236 }
37237
37238 push_rxbufs(card, sb);
37239 @@ -2239,7 +2239,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37240 printk
37241 ("nicstar%d: Out of huge buffers.\n",
37242 card->index);
37243 - atomic_inc(&vcc->stats->rx_drop);
37244 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37245 recycle_iovec_rx_bufs(card,
37246 (struct iovec *)
37247 iovb->data,
37248 @@ -2290,7 +2290,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37249 card->hbpool.count++;
37250 } else
37251 dev_kfree_skb_any(hb);
37252 - atomic_inc(&vcc->stats->rx_drop);
37253 + atomic_inc_unchecked(&vcc->stats->rx_drop);
37254 } else {
37255 /* Copy the small buffer to the huge buffer */
37256 sb = (struct sk_buff *)iov->iov_base;
37257 @@ -2327,7 +2327,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
37258 #endif /* NS_USE_DESTRUCTORS */
37259 __net_timestamp(hb);
37260 vcc->push(vcc, hb);
37261 - atomic_inc(&vcc->stats->rx);
37262 + atomic_inc_unchecked(&vcc->stats->rx);
37263 }
37264 }
37265
37266 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
37267 index 943cf0d..37d15d5 100644
37268 --- a/drivers/atm/solos-pci.c
37269 +++ b/drivers/atm/solos-pci.c
37270 @@ -838,7 +838,7 @@ static void solos_bh(unsigned long card_arg)
37271 }
37272 atm_charge(vcc, skb->truesize);
37273 vcc->push(vcc, skb);
37274 - atomic_inc(&vcc->stats->rx);
37275 + atomic_inc_unchecked(&vcc->stats->rx);
37276 break;
37277
37278 case PKT_STATUS:
37279 @@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
37280 vcc = SKB_CB(oldskb)->vcc;
37281
37282 if (vcc) {
37283 - atomic_inc(&vcc->stats->tx);
37284 + atomic_inc_unchecked(&vcc->stats->tx);
37285 solos_pop(vcc, oldskb);
37286 } else {
37287 dev_kfree_skb_irq(oldskb);
37288 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
37289 index 0215934..ce9f5b1 100644
37290 --- a/drivers/atm/suni.c
37291 +++ b/drivers/atm/suni.c
37292 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
37293
37294
37295 #define ADD_LIMITED(s,v) \
37296 - atomic_add((v),&stats->s); \
37297 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
37298 + atomic_add_unchecked((v),&stats->s); \
37299 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
37300
37301
37302 static void suni_hz(unsigned long from_timer)
37303 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
37304 index 5120a96..e2572bd 100644
37305 --- a/drivers/atm/uPD98402.c
37306 +++ b/drivers/atm/uPD98402.c
37307 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
37308 struct sonet_stats tmp;
37309 int error = 0;
37310
37311 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37312 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
37313 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
37314 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
37315 if (zero && !error) {
37316 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
37317
37318
37319 #define ADD_LIMITED(s,v) \
37320 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
37321 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
37322 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37323 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
37324 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
37325 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
37326
37327
37328 static void stat_event(struct atm_dev *dev)
37329 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
37330 if (reason & uPD98402_INT_PFM) stat_event(dev);
37331 if (reason & uPD98402_INT_PCO) {
37332 (void) GET(PCOCR); /* clear interrupt cause */
37333 - atomic_add(GET(HECCT),
37334 + atomic_add_unchecked(GET(HECCT),
37335 &PRIV(dev)->sonet_stats.uncorr_hcs);
37336 }
37337 if ((reason & uPD98402_INT_RFO) &&
37338 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
37339 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
37340 uPD98402_INT_LOS),PIMR); /* enable them */
37341 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
37342 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37343 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
37344 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
37345 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
37346 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
37347 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
37348 return 0;
37349 }
37350
37351 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
37352 index 969c3c2..9b72956 100644
37353 --- a/drivers/atm/zatm.c
37354 +++ b/drivers/atm/zatm.c
37355 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37356 }
37357 if (!size) {
37358 dev_kfree_skb_irq(skb);
37359 - if (vcc) atomic_inc(&vcc->stats->rx_err);
37360 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
37361 continue;
37362 }
37363 if (!atm_charge(vcc,skb->truesize)) {
37364 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
37365 skb->len = size;
37366 ATM_SKB(skb)->vcc = vcc;
37367 vcc->push(vcc,skb);
37368 - atomic_inc(&vcc->stats->rx);
37369 + atomic_inc_unchecked(&vcc->stats->rx);
37370 }
37371 zout(pos & 0xffff,MTA(mbx));
37372 #if 0 /* probably a stupid idea */
37373 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
37374 skb_queue_head(&zatm_vcc->backlog,skb);
37375 break;
37376 }
37377 - atomic_inc(&vcc->stats->tx);
37378 + atomic_inc_unchecked(&vcc->stats->tx);
37379 wake_up(&zatm_vcc->tx_wait);
37380 }
37381
37382 diff --git a/drivers/base/bus.c b/drivers/base/bus.c
37383 index 83e910a..b224a73 100644
37384 --- a/drivers/base/bus.c
37385 +++ b/drivers/base/bus.c
37386 @@ -1124,7 +1124,7 @@ int subsys_interface_register(struct subsys_interface *sif)
37387 return -EINVAL;
37388
37389 mutex_lock(&subsys->p->mutex);
37390 - list_add_tail(&sif->node, &subsys->p->interfaces);
37391 + pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
37392 if (sif->add_dev) {
37393 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37394 while ((dev = subsys_dev_iter_next(&iter)))
37395 @@ -1149,7 +1149,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
37396 subsys = sif->subsys;
37397
37398 mutex_lock(&subsys->p->mutex);
37399 - list_del_init(&sif->node);
37400 + pax_list_del_init((struct list_head *)&sif->node);
37401 if (sif->remove_dev) {
37402 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
37403 while ((dev = subsys_dev_iter_next(&iter)))
37404 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
37405 index 25798db..15f130e 100644
37406 --- a/drivers/base/devtmpfs.c
37407 +++ b/drivers/base/devtmpfs.c
37408 @@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
37409 if (!thread)
37410 return 0;
37411
37412 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
37413 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
37414 if (err)
37415 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
37416 else
37417 @@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
37418 *err = sys_unshare(CLONE_NEWNS);
37419 if (*err)
37420 goto out;
37421 - *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
37422 + *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
37423 if (*err)
37424 goto out;
37425 - sys_chdir("/.."); /* will traverse into overmounted root */
37426 - sys_chroot(".");
37427 + sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
37428 + sys_chroot((char __force_user *)".");
37429 complete(&setup_done);
37430 while (1) {
37431 spin_lock(&req_lock);
37432 diff --git a/drivers/base/node.c b/drivers/base/node.c
37433 index 8f7ed99..700dd0c 100644
37434 --- a/drivers/base/node.c
37435 +++ b/drivers/base/node.c
37436 @@ -624,7 +624,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
37437 struct node_attr {
37438 struct device_attribute attr;
37439 enum node_states state;
37440 -};
37441 +} __do_const;
37442
37443 static ssize_t show_node_state(struct device *dev,
37444 struct device_attribute *attr, char *buf)
37445 diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
37446 index ae098a2..0999830 100644
37447 --- a/drivers/base/power/domain.c
37448 +++ b/drivers/base/power/domain.c
37449 @@ -1821,9 +1821,9 @@ int __pm_genpd_remove_callbacks(struct device *dev, bool clear_td)
37450
37451 if (dev->power.subsys_data->domain_data) {
37452 gpd_data = to_gpd_data(dev->power.subsys_data->domain_data);
37453 - gpd_data->ops = (struct gpd_dev_ops){ NULL };
37454 + memset(&gpd_data->ops, 0, sizeof(gpd_data->ops));
37455 if (clear_td)
37456 - gpd_data->td = (struct gpd_timing_data){ 0 };
37457 + memset(&gpd_data->td, 0, sizeof(gpd_data->td));
37458
37459 if (--gpd_data->refcount == 0) {
37460 dev->power.subsys_data->domain_data = NULL;
37461 @@ -1862,7 +1862,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
37462 {
37463 struct cpuidle_driver *cpuidle_drv;
37464 struct gpd_cpu_data *cpu_data;
37465 - struct cpuidle_state *idle_state;
37466 + cpuidle_state_no_const *idle_state;
37467 int ret = 0;
37468
37469 if (IS_ERR_OR_NULL(genpd) || state < 0)
37470 @@ -1930,7 +1930,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
37471 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
37472 {
37473 struct gpd_cpu_data *cpu_data;
37474 - struct cpuidle_state *idle_state;
37475 + cpuidle_state_no_const *idle_state;
37476 int ret = 0;
37477
37478 if (IS_ERR_OR_NULL(genpd))
37479 diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
37480 index 95b181d1..c4f0e19 100644
37481 --- a/drivers/base/power/sysfs.c
37482 +++ b/drivers/base/power/sysfs.c
37483 @@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
37484 return -EIO;
37485 }
37486 }
37487 - return sprintf(buf, p);
37488 + return sprintf(buf, "%s", p);
37489 }
37490
37491 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
37492 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
37493 index 2d56f41..8830f19 100644
37494 --- a/drivers/base/power/wakeup.c
37495 +++ b/drivers/base/power/wakeup.c
37496 @@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
37497 * They need to be modified together atomically, so it's better to use one
37498 * atomic variable to hold them both.
37499 */
37500 -static atomic_t combined_event_count = ATOMIC_INIT(0);
37501 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
37502
37503 #define IN_PROGRESS_BITS (sizeof(int) * 4)
37504 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
37505
37506 static void split_counters(unsigned int *cnt, unsigned int *inpr)
37507 {
37508 - unsigned int comb = atomic_read(&combined_event_count);
37509 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
37510
37511 *cnt = (comb >> IN_PROGRESS_BITS);
37512 *inpr = comb & MAX_IN_PROGRESS;
37513 @@ -395,7 +395,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
37514 ws->start_prevent_time = ws->last_time;
37515
37516 /* Increment the counter of events in progress. */
37517 - cec = atomic_inc_return(&combined_event_count);
37518 + cec = atomic_inc_return_unchecked(&combined_event_count);
37519
37520 trace_wakeup_source_activate(ws->name, cec);
37521 }
37522 @@ -521,7 +521,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
37523 * Increment the counter of registered wakeup events and decrement the
37524 * couter of wakeup events in progress simultaneously.
37525 */
37526 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
37527 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
37528 trace_wakeup_source_deactivate(ws->name, cec);
37529
37530 split_counters(&cnt, &inpr);
37531 diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
37532 index e8d11b6..7b1b36f 100644
37533 --- a/drivers/base/syscore.c
37534 +++ b/drivers/base/syscore.c
37535 @@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
37536 void register_syscore_ops(struct syscore_ops *ops)
37537 {
37538 mutex_lock(&syscore_ops_lock);
37539 - list_add_tail(&ops->node, &syscore_ops_list);
37540 + pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
37541 mutex_unlock(&syscore_ops_lock);
37542 }
37543 EXPORT_SYMBOL_GPL(register_syscore_ops);
37544 @@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
37545 void unregister_syscore_ops(struct syscore_ops *ops)
37546 {
37547 mutex_lock(&syscore_ops_lock);
37548 - list_del(&ops->node);
37549 + pax_list_del((struct list_head *)&ops->node);
37550 mutex_unlock(&syscore_ops_lock);
37551 }
37552 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
37553 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
37554 index 73894ca..69f64ef 100644
37555 --- a/drivers/block/cciss.c
37556 +++ b/drivers/block/cciss.c
37557 @@ -3011,7 +3011,7 @@ static void start_io(ctlr_info_t *h)
37558 while (!list_empty(&h->reqQ)) {
37559 c = list_entry(h->reqQ.next, CommandList_struct, list);
37560 /* can't do anything if fifo is full */
37561 - if ((h->access.fifo_full(h))) {
37562 + if ((h->access->fifo_full(h))) {
37563 dev_warn(&h->pdev->dev, "fifo full\n");
37564 break;
37565 }
37566 @@ -3021,7 +3021,7 @@ static void start_io(ctlr_info_t *h)
37567 h->Qdepth--;
37568
37569 /* Tell the controller execute command */
37570 - h->access.submit_command(h, c);
37571 + h->access->submit_command(h, c);
37572
37573 /* Put job onto the completed Q */
37574 addQ(&h->cmpQ, c);
37575 @@ -3447,17 +3447,17 @@ startio:
37576
37577 static inline unsigned long get_next_completion(ctlr_info_t *h)
37578 {
37579 - return h->access.command_completed(h);
37580 + return h->access->command_completed(h);
37581 }
37582
37583 static inline int interrupt_pending(ctlr_info_t *h)
37584 {
37585 - return h->access.intr_pending(h);
37586 + return h->access->intr_pending(h);
37587 }
37588
37589 static inline long interrupt_not_for_us(ctlr_info_t *h)
37590 {
37591 - return ((h->access.intr_pending(h) == 0) ||
37592 + return ((h->access->intr_pending(h) == 0) ||
37593 (h->interrupts_enabled == 0));
37594 }
37595
37596 @@ -3490,7 +3490,7 @@ static inline u32 next_command(ctlr_info_t *h)
37597 u32 a;
37598
37599 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
37600 - return h->access.command_completed(h);
37601 + return h->access->command_completed(h);
37602
37603 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
37604 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
37605 @@ -4047,7 +4047,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
37606 trans_support & CFGTBL_Trans_use_short_tags);
37607
37608 /* Change the access methods to the performant access methods */
37609 - h->access = SA5_performant_access;
37610 + h->access = &SA5_performant_access;
37611 h->transMethod = CFGTBL_Trans_Performant;
37612
37613 return;
37614 @@ -4325,7 +4325,7 @@ static int cciss_pci_init(ctlr_info_t *h)
37615 if (prod_index < 0)
37616 return -ENODEV;
37617 h->product_name = products[prod_index].product_name;
37618 - h->access = *(products[prod_index].access);
37619 + h->access = products[prod_index].access;
37620
37621 if (cciss_board_disabled(h)) {
37622 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
37623 @@ -5057,7 +5057,7 @@ reinit_after_soft_reset:
37624 }
37625
37626 /* make sure the board interrupts are off */
37627 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37628 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37629 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
37630 if (rc)
37631 goto clean2;
37632 @@ -5107,7 +5107,7 @@ reinit_after_soft_reset:
37633 * fake ones to scoop up any residual completions.
37634 */
37635 spin_lock_irqsave(&h->lock, flags);
37636 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37637 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37638 spin_unlock_irqrestore(&h->lock, flags);
37639 free_irq(h->intr[h->intr_mode], h);
37640 rc = cciss_request_irq(h, cciss_msix_discard_completions,
37641 @@ -5127,9 +5127,9 @@ reinit_after_soft_reset:
37642 dev_info(&h->pdev->dev, "Board READY.\n");
37643 dev_info(&h->pdev->dev,
37644 "Waiting for stale completions to drain.\n");
37645 - h->access.set_intr_mask(h, CCISS_INTR_ON);
37646 + h->access->set_intr_mask(h, CCISS_INTR_ON);
37647 msleep(10000);
37648 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37649 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37650
37651 rc = controller_reset_failed(h->cfgtable);
37652 if (rc)
37653 @@ -5152,7 +5152,7 @@ reinit_after_soft_reset:
37654 cciss_scsi_setup(h);
37655
37656 /* Turn the interrupts on so we can service requests */
37657 - h->access.set_intr_mask(h, CCISS_INTR_ON);
37658 + h->access->set_intr_mask(h, CCISS_INTR_ON);
37659
37660 /* Get the firmware version */
37661 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
37662 @@ -5224,7 +5224,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
37663 kfree(flush_buf);
37664 if (return_code != IO_OK)
37665 dev_warn(&h->pdev->dev, "Error flushing cache\n");
37666 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
37667 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
37668 free_irq(h->intr[h->intr_mode], h);
37669 }
37670
37671 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
37672 index 7fda30e..2f27946 100644
37673 --- a/drivers/block/cciss.h
37674 +++ b/drivers/block/cciss.h
37675 @@ -101,7 +101,7 @@ struct ctlr_info
37676 /* information about each logical volume */
37677 drive_info_struct *drv[CISS_MAX_LUN];
37678
37679 - struct access_method access;
37680 + struct access_method *access;
37681
37682 /* queue and queue Info */
37683 struct list_head reqQ;
37684 @@ -402,27 +402,27 @@ static bool SA5_performant_intr_pending(ctlr_info_t *h)
37685 }
37686
37687 static struct access_method SA5_access = {
37688 - SA5_submit_command,
37689 - SA5_intr_mask,
37690 - SA5_fifo_full,
37691 - SA5_intr_pending,
37692 - SA5_completed,
37693 + .submit_command = SA5_submit_command,
37694 + .set_intr_mask = SA5_intr_mask,
37695 + .fifo_full = SA5_fifo_full,
37696 + .intr_pending = SA5_intr_pending,
37697 + .command_completed = SA5_completed,
37698 };
37699
37700 static struct access_method SA5B_access = {
37701 - SA5_submit_command,
37702 - SA5B_intr_mask,
37703 - SA5_fifo_full,
37704 - SA5B_intr_pending,
37705 - SA5_completed,
37706 + .submit_command = SA5_submit_command,
37707 + .set_intr_mask = SA5B_intr_mask,
37708 + .fifo_full = SA5_fifo_full,
37709 + .intr_pending = SA5B_intr_pending,
37710 + .command_completed = SA5_completed,
37711 };
37712
37713 static struct access_method SA5_performant_access = {
37714 - SA5_submit_command,
37715 - SA5_performant_intr_mask,
37716 - SA5_fifo_full,
37717 - SA5_performant_intr_pending,
37718 - SA5_performant_completed,
37719 + .submit_command = SA5_submit_command,
37720 + .set_intr_mask = SA5_performant_intr_mask,
37721 + .fifo_full = SA5_fifo_full,
37722 + .intr_pending = SA5_performant_intr_pending,
37723 + .command_completed = SA5_performant_completed,
37724 };
37725
37726 struct board_type {
37727 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
37728 index 2b94403..fd6ad1f 100644
37729 --- a/drivers/block/cpqarray.c
37730 +++ b/drivers/block/cpqarray.c
37731 @@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37732 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
37733 goto Enomem4;
37734 }
37735 - hba[i]->access.set_intr_mask(hba[i], 0);
37736 + hba[i]->access->set_intr_mask(hba[i], 0);
37737 if (request_irq(hba[i]->intr, do_ida_intr,
37738 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
37739 {
37740 @@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37741 add_timer(&hba[i]->timer);
37742
37743 /* Enable IRQ now that spinlock and rate limit timer are set up */
37744 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37745 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37746
37747 for(j=0; j<NWD; j++) {
37748 struct gendisk *disk = ida_gendisk[i][j];
37749 @@ -694,7 +694,7 @@ DBGINFO(
37750 for(i=0; i<NR_PRODUCTS; i++) {
37751 if (board_id == products[i].board_id) {
37752 c->product_name = products[i].product_name;
37753 - c->access = *(products[i].access);
37754 + c->access = products[i].access;
37755 break;
37756 }
37757 }
37758 @@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
37759 hba[ctlr]->intr = intr;
37760 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
37761 hba[ctlr]->product_name = products[j].product_name;
37762 - hba[ctlr]->access = *(products[j].access);
37763 + hba[ctlr]->access = products[j].access;
37764 hba[ctlr]->ctlr = ctlr;
37765 hba[ctlr]->board_id = board_id;
37766 hba[ctlr]->pci_dev = NULL; /* not PCI */
37767 @@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
37768
37769 while((c = h->reqQ) != NULL) {
37770 /* Can't do anything if we're busy */
37771 - if (h->access.fifo_full(h) == 0)
37772 + if (h->access->fifo_full(h) == 0)
37773 return;
37774
37775 /* Get the first entry from the request Q */
37776 @@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
37777 h->Qdepth--;
37778
37779 /* Tell the controller to do our bidding */
37780 - h->access.submit_command(h, c);
37781 + h->access->submit_command(h, c);
37782
37783 /* Get onto the completion Q */
37784 addQ(&h->cmpQ, c);
37785 @@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37786 unsigned long flags;
37787 __u32 a,a1;
37788
37789 - istat = h->access.intr_pending(h);
37790 + istat = h->access->intr_pending(h);
37791 /* Is this interrupt for us? */
37792 if (istat == 0)
37793 return IRQ_NONE;
37794 @@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37795 */
37796 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
37797 if (istat & FIFO_NOT_EMPTY) {
37798 - while((a = h->access.command_completed(h))) {
37799 + while((a = h->access->command_completed(h))) {
37800 a1 = a; a &= ~3;
37801 if ((c = h->cmpQ) == NULL)
37802 {
37803 @@ -1448,11 +1448,11 @@ static int sendcmd(
37804 /*
37805 * Disable interrupt
37806 */
37807 - info_p->access.set_intr_mask(info_p, 0);
37808 + info_p->access->set_intr_mask(info_p, 0);
37809 /* Make sure there is room in the command FIFO */
37810 /* Actually it should be completely empty at this time. */
37811 for (i = 200000; i > 0; i--) {
37812 - temp = info_p->access.fifo_full(info_p);
37813 + temp = info_p->access->fifo_full(info_p);
37814 if (temp != 0) {
37815 break;
37816 }
37817 @@ -1465,7 +1465,7 @@ DBG(
37818 /*
37819 * Send the cmd
37820 */
37821 - info_p->access.submit_command(info_p, c);
37822 + info_p->access->submit_command(info_p, c);
37823 complete = pollcomplete(ctlr);
37824
37825 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
37826 @@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
37827 * we check the new geometry. Then turn interrupts back on when
37828 * we're done.
37829 */
37830 - host->access.set_intr_mask(host, 0);
37831 + host->access->set_intr_mask(host, 0);
37832 getgeometry(ctlr);
37833 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
37834 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
37835
37836 for(i=0; i<NWD; i++) {
37837 struct gendisk *disk = ida_gendisk[ctlr][i];
37838 @@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
37839 /* Wait (up to 2 seconds) for a command to complete */
37840
37841 for (i = 200000; i > 0; i--) {
37842 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
37843 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
37844 if (done == 0) {
37845 udelay(10); /* a short fixed delay */
37846 } else
37847 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
37848 index be73e9d..7fbf140 100644
37849 --- a/drivers/block/cpqarray.h
37850 +++ b/drivers/block/cpqarray.h
37851 @@ -99,7 +99,7 @@ struct ctlr_info {
37852 drv_info_t drv[NWD];
37853 struct proc_dir_entry *proc;
37854
37855 - struct access_method access;
37856 + struct access_method *access;
37857
37858 cmdlist_t *reqQ;
37859 cmdlist_t *cmpQ;
37860 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
37861 index e7093d4..b364085 100644
37862 --- a/drivers/block/drbd/drbd_int.h
37863 +++ b/drivers/block/drbd/drbd_int.h
37864 @@ -331,7 +331,7 @@ struct drbd_epoch {
37865 struct drbd_connection *connection;
37866 struct list_head list;
37867 unsigned int barrier_nr;
37868 - atomic_t epoch_size; /* increased on every request added. */
37869 + atomic_unchecked_t epoch_size; /* increased on every request added. */
37870 atomic_t active; /* increased on every req. added, and dec on every finished. */
37871 unsigned long flags;
37872 };
37873 @@ -787,7 +787,7 @@ struct drbd_device {
37874 unsigned int al_tr_number;
37875 int al_tr_cycle;
37876 wait_queue_head_t seq_wait;
37877 - atomic_t packet_seq;
37878 + atomic_unchecked_t packet_seq;
37879 unsigned int peer_seq;
37880 spinlock_t peer_seq_lock;
37881 unsigned int minor;
37882 @@ -1361,7 +1361,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
37883 char __user *uoptval;
37884 int err;
37885
37886 - uoptval = (char __user __force *)optval;
37887 + uoptval = (char __force_user *)optval;
37888
37889 set_fs(KERNEL_DS);
37890 if (level == SOL_SOCKET)
37891 diff --git a/drivers/block/drbd/drbd_interval.c b/drivers/block/drbd/drbd_interval.c
37892 index 89c497c..9c736ae 100644
37893 --- a/drivers/block/drbd/drbd_interval.c
37894 +++ b/drivers/block/drbd/drbd_interval.c
37895 @@ -67,9 +67,9 @@ static void augment_rotate(struct rb_node *rb_old, struct rb_node *rb_new)
37896 }
37897
37898 static const struct rb_augment_callbacks augment_callbacks = {
37899 - augment_propagate,
37900 - augment_copy,
37901 - augment_rotate,
37902 + .propagate = augment_propagate,
37903 + .copy = augment_copy,
37904 + .rotate = augment_rotate,
37905 };
37906
37907 /**
37908 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
37909 index 331e5cc..6d657bce 100644
37910 --- a/drivers/block/drbd/drbd_main.c
37911 +++ b/drivers/block/drbd/drbd_main.c
37912 @@ -1322,7 +1322,7 @@ static int _drbd_send_ack(struct drbd_peer_device *peer_device, enum drbd_packet
37913 p->sector = sector;
37914 p->block_id = block_id;
37915 p->blksize = blksize;
37916 - p->seq_num = cpu_to_be32(atomic_inc_return(&peer_device->device->packet_seq));
37917 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&peer_device->device->packet_seq));
37918 return drbd_send_command(peer_device, sock, cmd, sizeof(*p), NULL, 0);
37919 }
37920
37921 @@ -1628,7 +1628,7 @@ int drbd_send_dblock(struct drbd_peer_device *peer_device, struct drbd_request *
37922 return -EIO;
37923 p->sector = cpu_to_be64(req->i.sector);
37924 p->block_id = (unsigned long)req;
37925 - p->seq_num = cpu_to_be32(atomic_inc_return(&device->packet_seq));
37926 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&device->packet_seq));
37927 dp_flags = bio_flags_to_wire(peer_device->connection, req->master_bio->bi_rw);
37928 if (device->state.conn >= C_SYNC_SOURCE &&
37929 device->state.conn <= C_PAUSED_SYNC_T)
37930 @@ -2658,8 +2658,8 @@ void drbd_destroy_connection(struct kref *kref)
37931 struct drbd_connection *connection = container_of(kref, struct drbd_connection, kref);
37932 struct drbd_resource *resource = connection->resource;
37933
37934 - if (atomic_read(&connection->current_epoch->epoch_size) != 0)
37935 - drbd_err(connection, "epoch_size:%d\n", atomic_read(&connection->current_epoch->epoch_size));
37936 + if (atomic_read_unchecked(&connection->current_epoch->epoch_size) != 0)
37937 + drbd_err(connection, "epoch_size:%d\n", atomic_read_unchecked(&connection->current_epoch->epoch_size));
37938 kfree(connection->current_epoch);
37939
37940 idr_destroy(&connection->peer_devices);
37941 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
37942 index 526414b..4eb8184 100644
37943 --- a/drivers/block/drbd/drbd_nl.c
37944 +++ b/drivers/block/drbd/drbd_nl.c
37945 @@ -3505,7 +3505,7 @@ out:
37946
37947 void drbd_bcast_event(struct drbd_device *device, const struct sib_info *sib)
37948 {
37949 - static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
37950 + static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
37951 struct sk_buff *msg;
37952 struct drbd_genlmsghdr *d_out;
37953 unsigned seq;
37954 @@ -3518,7 +3518,7 @@ void drbd_bcast_event(struct drbd_device *device, const struct sib_info *sib)
37955 return;
37956 }
37957
37958 - seq = atomic_inc_return(&drbd_genl_seq);
37959 + seq = atomic_inc_return_unchecked(&drbd_genl_seq);
37960 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
37961 if (!msg)
37962 goto failed;
37963 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
37964 index 68e3992..1aca24a 100644
37965 --- a/drivers/block/drbd/drbd_receiver.c
37966 +++ b/drivers/block/drbd/drbd_receiver.c
37967 @@ -826,7 +826,7 @@ int drbd_connected(struct drbd_peer_device *peer_device)
37968 struct drbd_device *device = peer_device->device;
37969 int err;
37970
37971 - atomic_set(&device->packet_seq, 0);
37972 + atomic_set_unchecked(&device->packet_seq, 0);
37973 device->peer_seq = 0;
37974
37975 device->state_mutex = peer_device->connection->agreed_pro_version < 100 ?
37976 @@ -1188,7 +1188,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connectio
37977 do {
37978 next_epoch = NULL;
37979
37980 - epoch_size = atomic_read(&epoch->epoch_size);
37981 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
37982
37983 switch (ev & ~EV_CLEANUP) {
37984 case EV_PUT:
37985 @@ -1228,7 +1228,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_connection *connectio
37986 rv = FE_DESTROYED;
37987 } else {
37988 epoch->flags = 0;
37989 - atomic_set(&epoch->epoch_size, 0);
37990 + atomic_set_unchecked(&epoch->epoch_size, 0);
37991 /* atomic_set(&epoch->active, 0); is already zero */
37992 if (rv == FE_STILL_LIVE)
37993 rv = FE_RECYCLED;
37994 @@ -1456,7 +1456,7 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf
37995 conn_wait_active_ee_empty(connection);
37996 drbd_flush(connection);
37997
37998 - if (atomic_read(&connection->current_epoch->epoch_size)) {
37999 + if (atomic_read_unchecked(&connection->current_epoch->epoch_size)) {
38000 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
38001 if (epoch)
38002 break;
38003 @@ -1469,11 +1469,11 @@ static int receive_Barrier(struct drbd_connection *connection, struct packet_inf
38004 }
38005
38006 epoch->flags = 0;
38007 - atomic_set(&epoch->epoch_size, 0);
38008 + atomic_set_unchecked(&epoch->epoch_size, 0);
38009 atomic_set(&epoch->active, 0);
38010
38011 spin_lock(&connection->epoch_lock);
38012 - if (atomic_read(&connection->current_epoch->epoch_size)) {
38013 + if (atomic_read_unchecked(&connection->current_epoch->epoch_size)) {
38014 list_add(&epoch->list, &connection->current_epoch->list);
38015 connection->current_epoch = epoch;
38016 connection->epochs++;
38017 @@ -2182,7 +2182,7 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info *
38018
38019 err = wait_for_and_update_peer_seq(peer_device, peer_seq);
38020 drbd_send_ack_dp(peer_device, P_NEG_ACK, p, pi->size);
38021 - atomic_inc(&connection->current_epoch->epoch_size);
38022 + atomic_inc_unchecked(&connection->current_epoch->epoch_size);
38023 err2 = drbd_drain_block(peer_device, pi->size);
38024 if (!err)
38025 err = err2;
38026 @@ -2216,7 +2216,7 @@ static int receive_Data(struct drbd_connection *connection, struct packet_info *
38027
38028 spin_lock(&connection->epoch_lock);
38029 peer_req->epoch = connection->current_epoch;
38030 - atomic_inc(&peer_req->epoch->epoch_size);
38031 + atomic_inc_unchecked(&peer_req->epoch->epoch_size);
38032 atomic_inc(&peer_req->epoch->active);
38033 spin_unlock(&connection->epoch_lock);
38034
38035 @@ -4396,7 +4396,7 @@ struct data_cmd {
38036 int expect_payload;
38037 size_t pkt_size;
38038 int (*fn)(struct drbd_connection *, struct packet_info *);
38039 -};
38040 +} __do_const;
38041
38042 static struct data_cmd drbd_cmd_handler[] = {
38043 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
38044 @@ -4506,7 +4506,7 @@ static void conn_disconnect(struct drbd_connection *connection)
38045 if (!list_empty(&connection->current_epoch->list))
38046 drbd_err(connection, "ASSERTION FAILED: connection->current_epoch->list not empty\n");
38047 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
38048 - atomic_set(&connection->current_epoch->epoch_size, 0);
38049 + atomic_set_unchecked(&connection->current_epoch->epoch_size, 0);
38050 connection->send.seen_any_write_yet = false;
38051
38052 drbd_info(connection, "Connection closed\n");
38053 @@ -5281,7 +5281,7 @@ static int connection_finish_peer_reqs(struct drbd_connection *connection)
38054 struct asender_cmd {
38055 size_t pkt_size;
38056 int (*fn)(struct drbd_connection *connection, struct packet_info *);
38057 -};
38058 +} __do_const;
38059
38060 static struct asender_cmd asender_tbl[] = {
38061 [P_PING] = { 0, got_Ping },
38062 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
38063 index f70a230..9dc90d5 100644
38064 --- a/drivers/block/loop.c
38065 +++ b/drivers/block/loop.c
38066 @@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
38067
38068 file_start_write(file);
38069 set_fs(get_ds());
38070 - bw = file->f_op->write(file, buf, len, &pos);
38071 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
38072 set_fs(old_fs);
38073 file_end_write(file);
38074 if (likely(bw == len))
38075 diff --git a/drivers/block/null_blk.c b/drivers/block/null_blk.c
38076 index 091b9ea..f5428f8 100644
38077 --- a/drivers/block/null_blk.c
38078 +++ b/drivers/block/null_blk.c
38079 @@ -382,15 +382,25 @@ static int null_init_hctx(struct blk_mq_hw_ctx *hctx, void *data,
38080 return 0;
38081 }
38082
38083 -static struct blk_mq_ops null_mq_ops = {
38084 - .queue_rq = null_queue_rq,
38085 - .map_queue = blk_mq_map_queue,
38086 +static struct blk_mq_ops null_mq_single_ops = {
38087 + .queue_rq = null_queue_rq,
38088 + .map_queue = blk_mq_map_queue,
38089 .init_hctx = null_init_hctx,
38090 .complete = null_softirq_done_fn,
38091 + .alloc_hctx = blk_mq_alloc_single_hw_queue,
38092 + .free_hctx = blk_mq_free_single_hw_queue,
38093 +};
38094 +
38095 +static struct blk_mq_ops null_mq_per_node_ops = {
38096 + .queue_rq = null_queue_rq,
38097 + .map_queue = blk_mq_map_queue,
38098 + .init_hctx = null_init_hctx,
38099 + .alloc_hctx = null_alloc_hctx,
38100 + .free_hctx = null_free_hctx,
38101 };
38102
38103 static struct blk_mq_reg null_mq_reg = {
38104 - .ops = &null_mq_ops,
38105 + .ops = &null_mq_single_ops,
38106 .queue_depth = 64,
38107 .cmd_size = sizeof(struct nullb_cmd),
38108 .flags = BLK_MQ_F_SHOULD_MERGE,
38109 @@ -521,13 +531,8 @@ static int null_add_dev(void)
38110 null_mq_reg.queue_depth = hw_queue_depth;
38111 null_mq_reg.nr_hw_queues = submit_queues;
38112
38113 - if (use_per_node_hctx) {
38114 - null_mq_reg.ops->alloc_hctx = null_alloc_hctx;
38115 - null_mq_reg.ops->free_hctx = null_free_hctx;
38116 - } else {
38117 - null_mq_reg.ops->alloc_hctx = blk_mq_alloc_single_hw_queue;
38118 - null_mq_reg.ops->free_hctx = blk_mq_free_single_hw_queue;
38119 - }
38120 + if (use_per_node_hctx)
38121 + null_mq_reg.ops = &null_mq_per_node_ops;
38122
38123 nullb->q = blk_mq_init_queue(&null_mq_reg, nullb);
38124 } else if (queue_mode == NULL_Q_BIO) {
38125 diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
38126 index a2af73d..c0b8f61 100644
38127 --- a/drivers/block/pktcdvd.c
38128 +++ b/drivers/block/pktcdvd.c
38129 @@ -108,7 +108,7 @@ static int pkt_seq_show(struct seq_file *m, void *p);
38130
38131 static sector_t get_zone(sector_t sector, struct pktcdvd_device *pd)
38132 {
38133 - return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1);
38134 + return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1UL);
38135 }
38136
38137 /*
38138 @@ -1888,7 +1888,7 @@ static noinline_for_stack int pkt_probe_settings(struct pktcdvd_device *pd)
38139 return -EROFS;
38140 }
38141 pd->settings.fp = ti.fp;
38142 - pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1);
38143 + pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1UL);
38144
38145 if (ti.nwa_v) {
38146 pd->nwa = be32_to_cpu(ti.next_writable);
38147 diff --git a/drivers/block/smart1,2.h b/drivers/block/smart1,2.h
38148 index e5565fb..71be10b4 100644
38149 --- a/drivers/block/smart1,2.h
38150 +++ b/drivers/block/smart1,2.h
38151 @@ -108,11 +108,11 @@ static unsigned long smart4_intr_pending(ctlr_info_t *h)
38152 }
38153
38154 static struct access_method smart4_access = {
38155 - smart4_submit_command,
38156 - smart4_intr_mask,
38157 - smart4_fifo_full,
38158 - smart4_intr_pending,
38159 - smart4_completed,
38160 + .submit_command = smart4_submit_command,
38161 + .set_intr_mask = smart4_intr_mask,
38162 + .fifo_full = smart4_fifo_full,
38163 + .intr_pending = smart4_intr_pending,
38164 + .command_completed = smart4_completed,
38165 };
38166
38167 /*
38168 @@ -144,11 +144,11 @@ static unsigned long smart2_intr_pending(ctlr_info_t *h)
38169 }
38170
38171 static struct access_method smart2_access = {
38172 - smart2_submit_command,
38173 - smart2_intr_mask,
38174 - smart2_fifo_full,
38175 - smart2_intr_pending,
38176 - smart2_completed,
38177 + .submit_command = smart2_submit_command,
38178 + .set_intr_mask = smart2_intr_mask,
38179 + .fifo_full = smart2_fifo_full,
38180 + .intr_pending = smart2_intr_pending,
38181 + .command_completed = smart2_completed,
38182 };
38183
38184 /*
38185 @@ -180,11 +180,11 @@ static unsigned long smart2e_intr_pending(ctlr_info_t *h)
38186 }
38187
38188 static struct access_method smart2e_access = {
38189 - smart2e_submit_command,
38190 - smart2e_intr_mask,
38191 - smart2e_fifo_full,
38192 - smart2e_intr_pending,
38193 - smart2e_completed,
38194 + .submit_command = smart2e_submit_command,
38195 + .set_intr_mask = smart2e_intr_mask,
38196 + .fifo_full = smart2e_fifo_full,
38197 + .intr_pending = smart2e_intr_pending,
38198 + .command_completed = smart2e_completed,
38199 };
38200
38201 /*
38202 @@ -270,9 +270,9 @@ static unsigned long smart1_intr_pending(ctlr_info_t *h)
38203 }
38204
38205 static struct access_method smart1_access = {
38206 - smart1_submit_command,
38207 - smart1_intr_mask,
38208 - smart1_fifo_full,
38209 - smart1_intr_pending,
38210 - smart1_completed,
38211 + .submit_command = smart1_submit_command,
38212 + .set_intr_mask = smart1_intr_mask,
38213 + .fifo_full = smart1_fifo_full,
38214 + .intr_pending = smart1_intr_pending,
38215 + .command_completed = smart1_completed,
38216 };
38217 diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
38218 index f038dba..bb74c08 100644
38219 --- a/drivers/bluetooth/btwilink.c
38220 +++ b/drivers/bluetooth/btwilink.c
38221 @@ -288,7 +288,7 @@ static int ti_st_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
38222
38223 static int bt_ti_probe(struct platform_device *pdev)
38224 {
38225 - static struct ti_st *hst;
38226 + struct ti_st *hst;
38227 struct hci_dev *hdev;
38228 int err;
38229
38230 diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
38231 index 8a3aff7..d7538c2 100644
38232 --- a/drivers/cdrom/cdrom.c
38233 +++ b/drivers/cdrom/cdrom.c
38234 @@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
38235 ENSURE(reset, CDC_RESET);
38236 ENSURE(generic_packet, CDC_GENERIC_PACKET);
38237 cdi->mc_flags = 0;
38238 - cdo->n_minors = 0;
38239 cdi->options = CDO_USE_FFLAGS;
38240
38241 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
38242 @@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
38243 else
38244 cdi->cdda_method = CDDA_OLD;
38245
38246 - if (!cdo->generic_packet)
38247 - cdo->generic_packet = cdrom_dummy_generic_packet;
38248 + if (!cdo->generic_packet) {
38249 + pax_open_kernel();
38250 + *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
38251 + pax_close_kernel();
38252 + }
38253
38254 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
38255 mutex_lock(&cdrom_mutex);
38256 @@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
38257 if (cdi->exit)
38258 cdi->exit(cdi);
38259
38260 - cdi->ops->n_minors--;
38261 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
38262 }
38263
38264 @@ -2107,7 +2108,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
38265 */
38266 nr = nframes;
38267 do {
38268 - cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38269 + cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
38270 if (cgc.buffer)
38271 break;
38272
38273 @@ -3429,7 +3430,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
38274 struct cdrom_device_info *cdi;
38275 int ret;
38276
38277 - ret = scnprintf(info + *pos, max_size - *pos, header);
38278 + ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
38279 if (!ret)
38280 return 1;
38281
38282 diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
38283 index 51e75ad..39c4c76 100644
38284 --- a/drivers/cdrom/gdrom.c
38285 +++ b/drivers/cdrom/gdrom.c
38286 @@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
38287 .audio_ioctl = gdrom_audio_ioctl,
38288 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
38289 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
38290 - .n_minors = 1,
38291 };
38292
38293 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
38294 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
38295 index 6e9f74a..50c7cea 100644
38296 --- a/drivers/char/Kconfig
38297 +++ b/drivers/char/Kconfig
38298 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
38299
38300 config DEVKMEM
38301 bool "/dev/kmem virtual device support"
38302 - default y
38303 + default n
38304 + depends on !GRKERNSEC_KMEM
38305 help
38306 Say Y here if you want to support the /dev/kmem device. The
38307 /dev/kmem device is rarely used, but can be used for certain
38308 @@ -577,6 +578,7 @@ config DEVPORT
38309 bool
38310 depends on !M68K
38311 depends on ISA || PCI
38312 + depends on !GRKERNSEC_KMEM
38313 default y
38314
38315 source "drivers/s390/char/Kconfig"
38316 diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
38317 index a48e05b..6bac831 100644
38318 --- a/drivers/char/agp/compat_ioctl.c
38319 +++ b/drivers/char/agp/compat_ioctl.c
38320 @@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
38321 return -ENOMEM;
38322 }
38323
38324 - if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
38325 + if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
38326 sizeof(*usegment) * ureserve.seg_count)) {
38327 kfree(usegment);
38328 kfree(ksegment);
38329 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
38330 index b297033..fa217ca 100644
38331 --- a/drivers/char/agp/frontend.c
38332 +++ b/drivers/char/agp/frontend.c
38333 @@ -819,7 +819,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38334 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
38335 return -EFAULT;
38336
38337 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
38338 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
38339 return -EFAULT;
38340
38341 client = agp_find_client_by_pid(reserve.pid);
38342 @@ -849,7 +849,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
38343 if (segment == NULL)
38344 return -ENOMEM;
38345
38346 - if (copy_from_user(segment, (void __user *) reserve.seg_list,
38347 + if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
38348 sizeof(struct agp_segment) * reserve.seg_count)) {
38349 kfree(segment);
38350 return -EFAULT;
38351 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
38352 index 4f94375..413694e 100644
38353 --- a/drivers/char/genrtc.c
38354 +++ b/drivers/char/genrtc.c
38355 @@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
38356 switch (cmd) {
38357
38358 case RTC_PLL_GET:
38359 + memset(&pll, 0, sizeof(pll));
38360 if (get_rtc_pll(&pll))
38361 return -EINVAL;
38362 else
38363 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
38364 index d5d4cd8..22d561d 100644
38365 --- a/drivers/char/hpet.c
38366 +++ b/drivers/char/hpet.c
38367 @@ -575,7 +575,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
38368 }
38369
38370 static int
38371 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
38372 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
38373 struct hpet_info *info)
38374 {
38375 struct hpet_timer __iomem *timer;
38376 diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
38377 index 86fe45c..c0ea948 100644
38378 --- a/drivers/char/hw_random/intel-rng.c
38379 +++ b/drivers/char/hw_random/intel-rng.c
38380 @@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
38381
38382 if (no_fwh_detect)
38383 return -ENODEV;
38384 - printk(warning);
38385 + printk("%s", warning);
38386 return -EBUSY;
38387 }
38388
38389 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
38390 index e6db938..835e3a2 100644
38391 --- a/drivers/char/ipmi/ipmi_msghandler.c
38392 +++ b/drivers/char/ipmi/ipmi_msghandler.c
38393 @@ -438,7 +438,7 @@ struct ipmi_smi {
38394 struct proc_dir_entry *proc_dir;
38395 char proc_dir_name[10];
38396
38397 - atomic_t stats[IPMI_NUM_STATS];
38398 + atomic_unchecked_t stats[IPMI_NUM_STATS];
38399
38400 /*
38401 * run_to_completion duplicate of smb_info, smi_info
38402 @@ -470,9 +470,9 @@ static LIST_HEAD(smi_watchers);
38403 static DEFINE_MUTEX(smi_watchers_mutex);
38404
38405 #define ipmi_inc_stat(intf, stat) \
38406 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
38407 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
38408 #define ipmi_get_stat(intf, stat) \
38409 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
38410 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
38411
38412 static int is_lan_addr(struct ipmi_addr *addr)
38413 {
38414 @@ -2926,7 +2926,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
38415 INIT_LIST_HEAD(&intf->cmd_rcvrs);
38416 init_waitqueue_head(&intf->waitq);
38417 for (i = 0; i < IPMI_NUM_STATS; i++)
38418 - atomic_set(&intf->stats[i], 0);
38419 + atomic_set_unchecked(&intf->stats[i], 0);
38420
38421 intf->proc_dir = NULL;
38422
38423 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
38424 index 1c4bb4f..719e873 100644
38425 --- a/drivers/char/ipmi/ipmi_si_intf.c
38426 +++ b/drivers/char/ipmi/ipmi_si_intf.c
38427 @@ -285,7 +285,7 @@ struct smi_info {
38428 unsigned char slave_addr;
38429
38430 /* Counters and things for the proc filesystem. */
38431 - atomic_t stats[SI_NUM_STATS];
38432 + atomic_unchecked_t stats[SI_NUM_STATS];
38433
38434 struct task_struct *thread;
38435
38436 @@ -294,9 +294,9 @@ struct smi_info {
38437 };
38438
38439 #define smi_inc_stat(smi, stat) \
38440 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
38441 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
38442 #define smi_get_stat(smi, stat) \
38443 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
38444 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
38445
38446 #define SI_MAX_PARMS 4
38447
38448 @@ -3374,7 +3374,7 @@ static int try_smi_init(struct smi_info *new_smi)
38449 atomic_set(&new_smi->req_events, 0);
38450 new_smi->run_to_completion = false;
38451 for (i = 0; i < SI_NUM_STATS; i++)
38452 - atomic_set(&new_smi->stats[i], 0);
38453 + atomic_set_unchecked(&new_smi->stats[i], 0);
38454
38455 new_smi->interrupt_disabled = true;
38456 atomic_set(&new_smi->stop_operation, 0);
38457 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
38458 index 917403f..dddd899 100644
38459 --- a/drivers/char/mem.c
38460 +++ b/drivers/char/mem.c
38461 @@ -18,6 +18,7 @@
38462 #include <linux/raw.h>
38463 #include <linux/tty.h>
38464 #include <linux/capability.h>
38465 +#include <linux/security.h>
38466 #include <linux/ptrace.h>
38467 #include <linux/device.h>
38468 #include <linux/highmem.h>
38469 @@ -36,6 +37,10 @@
38470
38471 #define DEVPORT_MINOR 4
38472
38473 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38474 +extern const struct file_operations grsec_fops;
38475 +#endif
38476 +
38477 static inline unsigned long size_inside_page(unsigned long start,
38478 unsigned long size)
38479 {
38480 @@ -67,9 +72,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38481
38482 while (cursor < to) {
38483 if (!devmem_is_allowed(pfn)) {
38484 +#ifdef CONFIG_GRKERNSEC_KMEM
38485 + gr_handle_mem_readwrite(from, to);
38486 +#else
38487 printk(KERN_INFO
38488 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
38489 current->comm, from, to);
38490 +#endif
38491 return 0;
38492 }
38493 cursor += PAGE_SIZE;
38494 @@ -77,6 +86,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38495 }
38496 return 1;
38497 }
38498 +#elif defined(CONFIG_GRKERNSEC_KMEM)
38499 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38500 +{
38501 + return 0;
38502 +}
38503 #else
38504 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
38505 {
38506 @@ -122,6 +136,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38507
38508 while (count > 0) {
38509 unsigned long remaining;
38510 + char *temp;
38511
38512 sz = size_inside_page(p, count);
38513
38514 @@ -137,7 +152,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
38515 if (!ptr)
38516 return -EFAULT;
38517
38518 - remaining = copy_to_user(buf, ptr, sz);
38519 +#ifdef CONFIG_PAX_USERCOPY
38520 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38521 + if (!temp) {
38522 + unxlate_dev_mem_ptr(p, ptr);
38523 + return -ENOMEM;
38524 + }
38525 + memcpy(temp, ptr, sz);
38526 +#else
38527 + temp = ptr;
38528 +#endif
38529 +
38530 + remaining = copy_to_user(buf, temp, sz);
38531 +
38532 +#ifdef CONFIG_PAX_USERCOPY
38533 + kfree(temp);
38534 +#endif
38535 +
38536 unxlate_dev_mem_ptr(p, ptr);
38537 if (remaining)
38538 return -EFAULT;
38539 @@ -369,9 +400,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38540 size_t count, loff_t *ppos)
38541 {
38542 unsigned long p = *ppos;
38543 - ssize_t low_count, read, sz;
38544 + ssize_t low_count, read, sz, err = 0;
38545 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
38546 - int err = 0;
38547
38548 read = 0;
38549 if (p < (unsigned long) high_memory) {
38550 @@ -393,6 +423,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38551 }
38552 #endif
38553 while (low_count > 0) {
38554 + char *temp;
38555 +
38556 sz = size_inside_page(p, low_count);
38557
38558 /*
38559 @@ -402,7 +434,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
38560 */
38561 kbuf = xlate_dev_kmem_ptr((char *)p);
38562
38563 - if (copy_to_user(buf, kbuf, sz))
38564 +#ifdef CONFIG_PAX_USERCOPY
38565 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
38566 + if (!temp)
38567 + return -ENOMEM;
38568 + memcpy(temp, kbuf, sz);
38569 +#else
38570 + temp = kbuf;
38571 +#endif
38572 +
38573 + err = copy_to_user(buf, temp, sz);
38574 +
38575 +#ifdef CONFIG_PAX_USERCOPY
38576 + kfree(temp);
38577 +#endif
38578 +
38579 + if (err)
38580 return -EFAULT;
38581 buf += sz;
38582 p += sz;
38583 @@ -827,6 +874,9 @@ static const struct memdev {
38584 #ifdef CONFIG_PRINTK
38585 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
38586 #endif
38587 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
38588 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
38589 +#endif
38590 };
38591
38592 static int memory_open(struct inode *inode, struct file *filp)
38593 @@ -898,7 +948,7 @@ static int __init chr_dev_init(void)
38594 continue;
38595
38596 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
38597 - NULL, devlist[minor].name);
38598 + NULL, "%s", devlist[minor].name);
38599 }
38600
38601 return tty_init();
38602 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
38603 index 9df78e2..01ba9ae 100644
38604 --- a/drivers/char/nvram.c
38605 +++ b/drivers/char/nvram.c
38606 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
38607
38608 spin_unlock_irq(&rtc_lock);
38609
38610 - if (copy_to_user(buf, contents, tmp - contents))
38611 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
38612 return -EFAULT;
38613
38614 *ppos = i;
38615 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
38616 index 8320abd..ec48108 100644
38617 --- a/drivers/char/pcmcia/synclink_cs.c
38618 +++ b/drivers/char/pcmcia/synclink_cs.c
38619 @@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38620
38621 if (debug_level >= DEBUG_LEVEL_INFO)
38622 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
38623 - __FILE__, __LINE__, info->device_name, port->count);
38624 + __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
38625
38626 - WARN_ON(!port->count);
38627 + WARN_ON(!atomic_read(&port->count));
38628
38629 if (tty_port_close_start(port, tty, filp) == 0)
38630 goto cleanup;
38631 @@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
38632 cleanup:
38633 if (debug_level >= DEBUG_LEVEL_INFO)
38634 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
38635 - tty->driver->name, port->count);
38636 + tty->driver->name, atomic_read(&port->count));
38637 }
38638
38639 /* Wait until the transmitter is empty.
38640 @@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38641
38642 if (debug_level >= DEBUG_LEVEL_INFO)
38643 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
38644 - __FILE__, __LINE__, tty->driver->name, port->count);
38645 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
38646
38647 /* If port is closing, signal caller to try again */
38648 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
38649 @@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
38650 goto cleanup;
38651 }
38652 spin_lock(&port->lock);
38653 - port->count++;
38654 + atomic_inc(&port->count);
38655 spin_unlock(&port->lock);
38656 spin_unlock_irqrestore(&info->netlock, flags);
38657
38658 - if (port->count == 1) {
38659 + if (atomic_read(&port->count) == 1) {
38660 /* 1st open on this device, init hardware */
38661 retval = startup(info, tty);
38662 if (retval < 0)
38663 @@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38664 unsigned short new_crctype;
38665
38666 /* return error if TTY interface open */
38667 - if (info->port.count)
38668 + if (atomic_read(&info->port.count))
38669 return -EBUSY;
38670
38671 switch (encoding)
38672 @@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
38673
38674 /* arbitrate between network and tty opens */
38675 spin_lock_irqsave(&info->netlock, flags);
38676 - if (info->port.count != 0 || info->netcount != 0) {
38677 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38678 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38679 spin_unlock_irqrestore(&info->netlock, flags);
38680 return -EBUSY;
38681 @@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38682 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
38683
38684 /* return error if TTY interface open */
38685 - if (info->port.count)
38686 + if (atomic_read(&info->port.count))
38687 return -EBUSY;
38688
38689 if (cmd != SIOCWANDEV)
38690 diff --git a/drivers/char/random.c b/drivers/char/random.c
38691 index 2b6e4cd..43d7ae1 100644
38692 --- a/drivers/char/random.c
38693 +++ b/drivers/char/random.c
38694 @@ -270,10 +270,17 @@
38695 /*
38696 * Configuration information
38697 */
38698 +#ifdef CONFIG_GRKERNSEC_RANDNET
38699 +#define INPUT_POOL_SHIFT 14
38700 +#define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
38701 +#define OUTPUT_POOL_SHIFT 12
38702 +#define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
38703 +#else
38704 #define INPUT_POOL_SHIFT 12
38705 #define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
38706 #define OUTPUT_POOL_SHIFT 10
38707 #define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
38708 +#endif
38709 #define SEC_XFER_SIZE 512
38710 #define EXTRACT_SIZE 10
38711
38712 @@ -284,9 +291,6 @@
38713 /*
38714 * To allow fractional bits to be tracked, the entropy_count field is
38715 * denominated in units of 1/8th bits.
38716 - *
38717 - * 2*(ENTROPY_SHIFT + log2(poolbits)) must <= 31, or the multiply in
38718 - * credit_entropy_bits() needs to be 64 bits wide.
38719 */
38720 #define ENTROPY_SHIFT 3
38721 #define ENTROPY_BITS(r) ((r)->entropy_count >> ENTROPY_SHIFT)
38722 @@ -361,12 +365,19 @@ static struct poolinfo {
38723 #define S(x) ilog2(x)+5, (x), (x)*4, (x)*32, (x) << (ENTROPY_SHIFT+5)
38724 int tap1, tap2, tap3, tap4, tap5;
38725 } poolinfo_table[] = {
38726 +#ifdef CONFIG_GRKERNSEC_RANDNET
38727 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
38728 + { S(512), 411, 308, 208, 104, 1 },
38729 + /* x^128 + x^104 + x^76 + x^51 + x^25 + x + 1 -- 105 */
38730 + { S(128), 104, 76, 51, 25, 1 },
38731 +#else
38732 /* was: x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 */
38733 /* x^128 + x^104 + x^76 + x^51 +x^25 + x + 1 */
38734 { S(128), 104, 76, 51, 25, 1 },
38735 /* was: x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 */
38736 /* x^32 + x^26 + x^19 + x^14 + x^7 + x + 1 */
38737 { S(32), 26, 19, 14, 7, 1 },
38738 +#endif
38739 #if 0
38740 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
38741 { S(2048), 1638, 1231, 819, 411, 1 },
38742 @@ -433,9 +444,9 @@ struct entropy_store {
38743 };
38744
38745 static void push_to_pool(struct work_struct *work);
38746 -static __u32 input_pool_data[INPUT_POOL_WORDS];
38747 -static __u32 blocking_pool_data[OUTPUT_POOL_WORDS];
38748 -static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS];
38749 +static __u32 input_pool_data[INPUT_POOL_WORDS] __latent_entropy;
38750 +static __u32 blocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
38751 +static __u32 nonblocking_pool_data[OUTPUT_POOL_WORDS] __latent_entropy;
38752
38753 static struct entropy_store input_pool = {
38754 .poolinfo = &poolinfo_table[0],
38755 @@ -524,8 +535,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
38756 input_rotate = (input_rotate + (i ? 7 : 14)) & 31;
38757 }
38758
38759 - ACCESS_ONCE(r->input_rotate) = input_rotate;
38760 - ACCESS_ONCE(r->add_ptr) = i;
38761 + ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
38762 + ACCESS_ONCE_RW(r->add_ptr) = i;
38763 smp_wmb();
38764
38765 if (out)
38766 @@ -632,7 +643,7 @@ retry:
38767 /* The +2 corresponds to the /4 in the denominator */
38768
38769 do {
38770 - unsigned int anfrac = min(pnfrac, pool_size/2);
38771 + u64 anfrac = min(pnfrac, pool_size/2);
38772 unsigned int add =
38773 ((pool_size - entropy_count)*anfrac*3) >> s;
38774
38775 @@ -1166,7 +1177,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
38776
38777 extract_buf(r, tmp);
38778 i = min_t(int, nbytes, EXTRACT_SIZE);
38779 - if (copy_to_user(buf, tmp, i)) {
38780 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
38781 ret = -EFAULT;
38782 break;
38783 }
38784 @@ -1555,7 +1566,7 @@ static char sysctl_bootid[16];
38785 static int proc_do_uuid(struct ctl_table *table, int write,
38786 void __user *buffer, size_t *lenp, loff_t *ppos)
38787 {
38788 - struct ctl_table fake_table;
38789 + ctl_table_no_const fake_table;
38790 unsigned char buf[64], tmp_uuid[16], *uuid;
38791
38792 uuid = table->data;
38793 @@ -1585,7 +1596,7 @@ static int proc_do_uuid(struct ctl_table *table, int write,
38794 static int proc_do_entropy(ctl_table *table, int write,
38795 void __user *buffer, size_t *lenp, loff_t *ppos)
38796 {
38797 - ctl_table fake_table;
38798 + ctl_table_no_const fake_table;
38799 int entropy_count;
38800
38801 entropy_count = *(int *)table->data >> ENTROPY_SHIFT;
38802 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
38803 index 7cc1fe22..b602d6b 100644
38804 --- a/drivers/char/sonypi.c
38805 +++ b/drivers/char/sonypi.c
38806 @@ -54,6 +54,7 @@
38807
38808 #include <asm/uaccess.h>
38809 #include <asm/io.h>
38810 +#include <asm/local.h>
38811
38812 #include <linux/sonypi.h>
38813
38814 @@ -490,7 +491,7 @@ static struct sonypi_device {
38815 spinlock_t fifo_lock;
38816 wait_queue_head_t fifo_proc_list;
38817 struct fasync_struct *fifo_async;
38818 - int open_count;
38819 + local_t open_count;
38820 int model;
38821 struct input_dev *input_jog_dev;
38822 struct input_dev *input_key_dev;
38823 @@ -892,7 +893,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
38824 static int sonypi_misc_release(struct inode *inode, struct file *file)
38825 {
38826 mutex_lock(&sonypi_device.lock);
38827 - sonypi_device.open_count--;
38828 + local_dec(&sonypi_device.open_count);
38829 mutex_unlock(&sonypi_device.lock);
38830 return 0;
38831 }
38832 @@ -901,9 +902,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
38833 {
38834 mutex_lock(&sonypi_device.lock);
38835 /* Flush input queue on first open */
38836 - if (!sonypi_device.open_count)
38837 + if (!local_read(&sonypi_device.open_count))
38838 kfifo_reset(&sonypi_device.fifo);
38839 - sonypi_device.open_count++;
38840 + local_inc(&sonypi_device.open_count);
38841 mutex_unlock(&sonypi_device.lock);
38842
38843 return 0;
38844 diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
38845 index b9a57fa..5bb9e38 100644
38846 --- a/drivers/char/tpm/tpm_acpi.c
38847 +++ b/drivers/char/tpm/tpm_acpi.c
38848 @@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
38849 virt = acpi_os_map_memory(start, len);
38850 if (!virt) {
38851 kfree(log->bios_event_log);
38852 + log->bios_event_log = NULL;
38853 printk("%s: ERROR - Unable to map memory\n", __func__);
38854 return -EIO;
38855 }
38856
38857 - memcpy_fromio(log->bios_event_log, virt, len);
38858 + memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
38859
38860 acpi_os_unmap_memory(virt, len);
38861 return 0;
38862 diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
38863 index 59f7cb2..bac8b6d 100644
38864 --- a/drivers/char/tpm/tpm_eventlog.c
38865 +++ b/drivers/char/tpm/tpm_eventlog.c
38866 @@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
38867 event = addr;
38868
38869 if ((event->event_type == 0 && event->event_size == 0) ||
38870 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
38871 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
38872 return NULL;
38873
38874 return addr;
38875 @@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
38876 return NULL;
38877
38878 if ((event->event_type == 0 && event->event_size == 0) ||
38879 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
38880 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
38881 return NULL;
38882
38883 (*pos)++;
38884 @@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
38885 int i;
38886
38887 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
38888 - seq_putc(m, data[i]);
38889 + if (!seq_putc(m, data[i]))
38890 + return -EFAULT;
38891
38892 return 0;
38893 }
38894 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
38895 index 60aafb8..10c08e0 100644
38896 --- a/drivers/char/virtio_console.c
38897 +++ b/drivers/char/virtio_console.c
38898 @@ -684,7 +684,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
38899 if (to_user) {
38900 ssize_t ret;
38901
38902 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
38903 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
38904 if (ret)
38905 return -EFAULT;
38906 } else {
38907 @@ -787,7 +787,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
38908 if (!port_has_data(port) && !port->host_connected)
38909 return 0;
38910
38911 - return fill_readbuf(port, ubuf, count, true);
38912 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
38913 }
38914
38915 static int wait_port_writable(struct port *port, bool nonblock)
38916 diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
38917 index 57a078e..c17cde8 100644
38918 --- a/drivers/clk/clk-composite.c
38919 +++ b/drivers/clk/clk-composite.c
38920 @@ -146,7 +146,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
38921 struct clk *clk;
38922 struct clk_init_data init;
38923 struct clk_composite *composite;
38924 - struct clk_ops *clk_composite_ops;
38925 + clk_ops_no_const *clk_composite_ops;
38926
38927 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
38928 if (!composite) {
38929 diff --git a/drivers/clk/socfpga/clk-gate.c b/drivers/clk/socfpga/clk-gate.c
38930 index 501d513..fb0ecf9 100644
38931 --- a/drivers/clk/socfpga/clk-gate.c
38932 +++ b/drivers/clk/socfpga/clk-gate.c
38933 @@ -22,6 +22,7 @@
38934 #include <linux/mfd/syscon.h>
38935 #include <linux/of.h>
38936 #include <linux/regmap.h>
38937 +#include <asm/pgtable.h>
38938
38939 #include "clk.h"
38940
38941 @@ -175,7 +176,7 @@ static int socfpga_clk_prepare(struct clk_hw *hwclk)
38942 return 0;
38943 }
38944
38945 -static struct clk_ops gateclk_ops = {
38946 +static clk_ops_no_const gateclk_ops __read_only = {
38947 .prepare = socfpga_clk_prepare,
38948 .recalc_rate = socfpga_clk_recalc_rate,
38949 .get_parent = socfpga_clk_get_parent,
38950 @@ -209,8 +210,10 @@ static void __init __socfpga_gate_init(struct device_node *node,
38951 socfpga_clk->hw.reg = clk_mgr_base_addr + clk_gate[0];
38952 socfpga_clk->hw.bit_idx = clk_gate[1];
38953
38954 - gateclk_ops.enable = clk_gate_ops.enable;
38955 - gateclk_ops.disable = clk_gate_ops.disable;
38956 + pax_open_kernel();
38957 + *(void **)&gateclk_ops.enable = clk_gate_ops.enable;
38958 + *(void **)&gateclk_ops.disable = clk_gate_ops.disable;
38959 + pax_close_kernel();
38960 }
38961
38962 rc = of_property_read_u32(node, "fixed-divider", &fixed_div);
38963 diff --git a/drivers/clk/socfpga/clk-pll.c b/drivers/clk/socfpga/clk-pll.c
38964 index de6da95..a2e72c0 100644
38965 --- a/drivers/clk/socfpga/clk-pll.c
38966 +++ b/drivers/clk/socfpga/clk-pll.c
38967 @@ -21,6 +21,7 @@
38968 #include <linux/io.h>
38969 #include <linux/of.h>
38970 #include <linux/of_address.h>
38971 +#include <asm/pgtable.h>
38972
38973 #include "clk.h"
38974
38975 @@ -76,7 +77,7 @@ static u8 clk_pll_get_parent(struct clk_hw *hwclk)
38976 CLK_MGR_PLL_CLK_SRC_MASK;
38977 }
38978
38979 -static struct clk_ops clk_pll_ops = {
38980 +static struct clk_ops_no_const clk_pll_ops __read_only = {
38981 .recalc_rate = clk_pll_recalc_rate,
38982 .get_parent = clk_pll_get_parent,
38983 };
38984 @@ -120,8 +121,10 @@ static __init struct clk *__socfpga_pll_init(struct device_node *node,
38985 pll_clk->hw.hw.init = &init;
38986
38987 pll_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
38988 - clk_pll_ops.enable = clk_gate_ops.enable;
38989 - clk_pll_ops.disable = clk_gate_ops.disable;
38990 + pax_open_kernel();
38991 + *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
38992 + *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
38993 + pax_close_kernel();
38994
38995 clk = clk_register(NULL, &pll_clk->hw.hw);
38996 if (WARN_ON(IS_ERR(clk))) {
38997 diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
38998 index 000e4e0..4770351 100644
38999 --- a/drivers/cpufreq/acpi-cpufreq.c
39000 +++ b/drivers/cpufreq/acpi-cpufreq.c
39001 @@ -676,8 +676,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
39002 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
39003 per_cpu(acfreq_data, cpu) = data;
39004
39005 - if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
39006 - acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
39007 + if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
39008 + pax_open_kernel();
39009 + *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
39010 + pax_close_kernel();
39011 + }
39012
39013 result = acpi_processor_register_performance(data->acpi_data, cpu);
39014 if (result)
39015 @@ -810,7 +813,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
39016 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
39017 break;
39018 case ACPI_ADR_SPACE_FIXED_HARDWARE:
39019 - acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
39020 + pax_open_kernel();
39021 + *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
39022 + pax_close_kernel();
39023 break;
39024 default:
39025 break;
39026 @@ -904,8 +909,10 @@ static void __init acpi_cpufreq_boost_init(void)
39027 if (!msrs)
39028 return;
39029
39030 - acpi_cpufreq_driver.boost_supported = true;
39031 - acpi_cpufreq_driver.boost_enabled = boost_state(0);
39032 + pax_open_kernel();
39033 + *(bool *)&acpi_cpufreq_driver.boost_supported = true;
39034 + *(bool *)&acpi_cpufreq_driver.boost_enabled = boost_state(0);
39035 + pax_close_kernel();
39036
39037 cpu_notifier_register_begin();
39038
39039 diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
39040 index 558224c..55e3b57 100644
39041 --- a/drivers/cpufreq/cpufreq.c
39042 +++ b/drivers/cpufreq/cpufreq.c
39043 @@ -2022,7 +2022,7 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
39044 }
39045
39046 mutex_lock(&cpufreq_governor_mutex);
39047 - list_del(&governor->governor_list);
39048 + pax_list_del(&governor->governor_list);
39049 mutex_unlock(&cpufreq_governor_mutex);
39050 return;
39051 }
39052 @@ -2238,7 +2238,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
39053 return NOTIFY_OK;
39054 }
39055
39056 -static struct notifier_block __refdata cpufreq_cpu_notifier = {
39057 +static struct notifier_block cpufreq_cpu_notifier = {
39058 .notifier_call = cpufreq_cpu_callback,
39059 };
39060
39061 @@ -2278,13 +2278,17 @@ int cpufreq_boost_trigger_state(int state)
39062 return 0;
39063
39064 write_lock_irqsave(&cpufreq_driver_lock, flags);
39065 - cpufreq_driver->boost_enabled = state;
39066 + pax_open_kernel();
39067 + *(bool *)&cpufreq_driver->boost_enabled = state;
39068 + pax_close_kernel();
39069 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
39070
39071 ret = cpufreq_driver->set_boost(state);
39072 if (ret) {
39073 write_lock_irqsave(&cpufreq_driver_lock, flags);
39074 - cpufreq_driver->boost_enabled = !state;
39075 + pax_open_kernel();
39076 + *(bool *)&cpufreq_driver->boost_enabled = !state;
39077 + pax_close_kernel();
39078 write_unlock_irqrestore(&cpufreq_driver_lock, flags);
39079
39080 pr_err("%s: Cannot %s BOOST\n",
39081 @@ -2340,8 +2344,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
39082
39083 pr_debug("trying to register driver %s\n", driver_data->name);
39084
39085 - if (driver_data->setpolicy)
39086 - driver_data->flags |= CPUFREQ_CONST_LOOPS;
39087 + if (driver_data->setpolicy) {
39088 + pax_open_kernel();
39089 + *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
39090 + pax_close_kernel();
39091 + }
39092
39093 write_lock_irqsave(&cpufreq_driver_lock, flags);
39094 if (cpufreq_driver) {
39095 @@ -2356,8 +2363,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
39096 * Check if driver provides function to enable boost -
39097 * if not, use cpufreq_boost_set_sw as default
39098 */
39099 - if (!cpufreq_driver->set_boost)
39100 - cpufreq_driver->set_boost = cpufreq_boost_set_sw;
39101 + if (!cpufreq_driver->set_boost) {
39102 + pax_open_kernel();
39103 + *(void **)&cpufreq_driver->set_boost = cpufreq_boost_set_sw;
39104 + pax_close_kernel();
39105 + }
39106
39107 ret = cpufreq_sysfs_create_file(&boost.attr);
39108 if (ret) {
39109 diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
39110 index e1c6433..31203ae 100644
39111 --- a/drivers/cpufreq/cpufreq_governor.c
39112 +++ b/drivers/cpufreq/cpufreq_governor.c
39113 @@ -191,7 +191,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39114 struct dbs_data *dbs_data;
39115 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
39116 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
39117 - struct od_ops *od_ops = NULL;
39118 + const struct od_ops *od_ops = NULL;
39119 struct od_dbs_tuners *od_tuners = NULL;
39120 struct cs_dbs_tuners *cs_tuners = NULL;
39121 struct cpu_dbs_common_info *cpu_cdbs;
39122 @@ -257,7 +257,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39123
39124 if ((cdata->governor == GOV_CONSERVATIVE) &&
39125 (!policy->governor->initialized)) {
39126 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39127 + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39128
39129 cpufreq_register_notifier(cs_ops->notifier_block,
39130 CPUFREQ_TRANSITION_NOTIFIER);
39131 @@ -277,7 +277,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
39132
39133 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
39134 (policy->governor->initialized == 1)) {
39135 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39136 + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
39137
39138 cpufreq_unregister_notifier(cs_ops->notifier_block,
39139 CPUFREQ_TRANSITION_NOTIFIER);
39140 diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
39141 index bfb9ae1..e1d3a7e 100644
39142 --- a/drivers/cpufreq/cpufreq_governor.h
39143 +++ b/drivers/cpufreq/cpufreq_governor.h
39144 @@ -205,7 +205,7 @@ struct common_dbs_data {
39145 void (*exit)(struct dbs_data *dbs_data);
39146
39147 /* Governor specific ops, see below */
39148 - void *gov_ops;
39149 + const void *gov_ops;
39150 };
39151
39152 /* Governor Per policy data */
39153 @@ -225,7 +225,7 @@ struct od_ops {
39154 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
39155 unsigned int freq_next, unsigned int relation);
39156 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
39157 -};
39158 +} __no_const;
39159
39160 struct cs_ops {
39161 struct notifier_block *notifier_block;
39162 diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
39163 index 18d4091..434be15 100644
39164 --- a/drivers/cpufreq/cpufreq_ondemand.c
39165 +++ b/drivers/cpufreq/cpufreq_ondemand.c
39166 @@ -521,7 +521,7 @@ static void od_exit(struct dbs_data *dbs_data)
39167
39168 define_get_cpu_dbs_routines(od_cpu_dbs_info);
39169
39170 -static struct od_ops od_ops = {
39171 +static struct od_ops od_ops __read_only = {
39172 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
39173 .powersave_bias_target = generic_powersave_bias_target,
39174 .freq_increase = dbs_freq_increase,
39175 @@ -576,14 +576,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
39176 (struct cpufreq_policy *, unsigned int, unsigned int),
39177 unsigned int powersave_bias)
39178 {
39179 - od_ops.powersave_bias_target = f;
39180 + pax_open_kernel();
39181 + *(void **)&od_ops.powersave_bias_target = f;
39182 + pax_close_kernel();
39183 od_set_powersave_bias(powersave_bias);
39184 }
39185 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
39186
39187 void od_unregister_powersave_bias_handler(void)
39188 {
39189 - od_ops.powersave_bias_target = generic_powersave_bias_target;
39190 + pax_open_kernel();
39191 + *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
39192 + pax_close_kernel();
39193 od_set_powersave_bias(0);
39194 }
39195 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
39196 diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
39197 index fcd0c92..7b736c2 100644
39198 --- a/drivers/cpufreq/intel_pstate.c
39199 +++ b/drivers/cpufreq/intel_pstate.c
39200 @@ -125,10 +125,10 @@ struct pstate_funcs {
39201 struct cpu_defaults {
39202 struct pstate_adjust_policy pid_policy;
39203 struct pstate_funcs funcs;
39204 -};
39205 +} __do_const;
39206
39207 static struct pstate_adjust_policy pid_params;
39208 -static struct pstate_funcs pstate_funcs;
39209 +static struct pstate_funcs *pstate_funcs;
39210
39211 struct perf_limits {
39212 int no_turbo;
39213 @@ -526,7 +526,7 @@ static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
39214
39215 cpu->pstate.current_pstate = pstate;
39216
39217 - pstate_funcs.set(cpu, pstate);
39218 + pstate_funcs->set(cpu, pstate);
39219 }
39220
39221 static inline void intel_pstate_pstate_increase(struct cpudata *cpu, int steps)
39222 @@ -548,12 +548,12 @@ static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
39223 {
39224 sprintf(cpu->name, "Intel 2nd generation core");
39225
39226 - cpu->pstate.min_pstate = pstate_funcs.get_min();
39227 - cpu->pstate.max_pstate = pstate_funcs.get_max();
39228 - cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
39229 + cpu->pstate.min_pstate = pstate_funcs->get_min();
39230 + cpu->pstate.max_pstate = pstate_funcs->get_max();
39231 + cpu->pstate.turbo_pstate = pstate_funcs->get_turbo();
39232
39233 - if (pstate_funcs.get_vid)
39234 - pstate_funcs.get_vid(cpu);
39235 + if (pstate_funcs->get_vid)
39236 + pstate_funcs->get_vid(cpu);
39237 intel_pstate_set_pstate(cpu, cpu->pstate.min_pstate);
39238 }
39239
39240 @@ -838,9 +838,9 @@ static int intel_pstate_msrs_not_valid(void)
39241 rdmsrl(MSR_IA32_APERF, aperf);
39242 rdmsrl(MSR_IA32_MPERF, mperf);
39243
39244 - if (!pstate_funcs.get_max() ||
39245 - !pstate_funcs.get_min() ||
39246 - !pstate_funcs.get_turbo())
39247 + if (!pstate_funcs->get_max() ||
39248 + !pstate_funcs->get_min() ||
39249 + !pstate_funcs->get_turbo())
39250 return -ENODEV;
39251
39252 rdmsrl(MSR_IA32_APERF, tmp);
39253 @@ -854,7 +854,7 @@ static int intel_pstate_msrs_not_valid(void)
39254 return 0;
39255 }
39256
39257 -static void copy_pid_params(struct pstate_adjust_policy *policy)
39258 +static void copy_pid_params(const struct pstate_adjust_policy *policy)
39259 {
39260 pid_params.sample_rate_ms = policy->sample_rate_ms;
39261 pid_params.p_gain_pct = policy->p_gain_pct;
39262 @@ -866,11 +866,7 @@ static void copy_pid_params(struct pstate_adjust_policy *policy)
39263
39264 static void copy_cpu_funcs(struct pstate_funcs *funcs)
39265 {
39266 - pstate_funcs.get_max = funcs->get_max;
39267 - pstate_funcs.get_min = funcs->get_min;
39268 - pstate_funcs.get_turbo = funcs->get_turbo;
39269 - pstate_funcs.set = funcs->set;
39270 - pstate_funcs.get_vid = funcs->get_vid;
39271 + pstate_funcs = funcs;
39272 }
39273
39274 #if IS_ENABLED(CONFIG_ACPI)
39275 diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
39276 index 529cfd9..0e28fff 100644
39277 --- a/drivers/cpufreq/p4-clockmod.c
39278 +++ b/drivers/cpufreq/p4-clockmod.c
39279 @@ -134,10 +134,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39280 case 0x0F: /* Core Duo */
39281 case 0x16: /* Celeron Core */
39282 case 0x1C: /* Atom */
39283 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39284 + pax_open_kernel();
39285 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39286 + pax_close_kernel();
39287 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
39288 case 0x0D: /* Pentium M (Dothan) */
39289 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39290 + pax_open_kernel();
39291 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39292 + pax_close_kernel();
39293 /* fall through */
39294 case 0x09: /* Pentium M (Banias) */
39295 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
39296 @@ -149,7 +153,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
39297
39298 /* on P-4s, the TSC runs with constant frequency independent whether
39299 * throttling is active or not. */
39300 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39301 + pax_open_kernel();
39302 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
39303 + pax_close_kernel();
39304
39305 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
39306 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
39307 diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
39308 index 9bb42ba..b01b4a2 100644
39309 --- a/drivers/cpufreq/sparc-us3-cpufreq.c
39310 +++ b/drivers/cpufreq/sparc-us3-cpufreq.c
39311 @@ -18,14 +18,12 @@
39312 #include <asm/head.h>
39313 #include <asm/timer.h>
39314
39315 -static struct cpufreq_driver *cpufreq_us3_driver;
39316 -
39317 struct us3_freq_percpu_info {
39318 struct cpufreq_frequency_table table[4];
39319 };
39320
39321 /* Indexed by cpu number. */
39322 -static struct us3_freq_percpu_info *us3_freq_table;
39323 +static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
39324
39325 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
39326 * in the Safari config register.
39327 @@ -156,16 +154,27 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
39328
39329 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
39330 {
39331 - if (cpufreq_us3_driver)
39332 - us3_freq_target(policy, 0);
39333 + us3_freq_target(policy, 0);
39334
39335 return 0;
39336 }
39337
39338 +static int __init us3_freq_init(void);
39339 +static void __exit us3_freq_exit(void);
39340 +
39341 +static struct cpufreq_driver cpufreq_us3_driver = {
39342 + .init = us3_freq_cpu_init,
39343 + .verify = cpufreq_generic_frequency_table_verify,
39344 + .target_index = us3_freq_target,
39345 + .get = us3_freq_get,
39346 + .exit = us3_freq_cpu_exit,
39347 + .name = "UltraSPARC-III",
39348 +
39349 +};
39350 +
39351 static int __init us3_freq_init(void)
39352 {
39353 unsigned long manuf, impl, ver;
39354 - int ret;
39355
39356 if (tlb_type != cheetah && tlb_type != cheetah_plus)
39357 return -ENODEV;
39358 @@ -178,55 +187,15 @@ static int __init us3_freq_init(void)
39359 (impl == CHEETAH_IMPL ||
39360 impl == CHEETAH_PLUS_IMPL ||
39361 impl == JAGUAR_IMPL ||
39362 - impl == PANTHER_IMPL)) {
39363 - struct cpufreq_driver *driver;
39364 -
39365 - ret = -ENOMEM;
39366 - driver = kzalloc(sizeof(*driver), GFP_KERNEL);
39367 - if (!driver)
39368 - goto err_out;
39369 -
39370 - us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
39371 - GFP_KERNEL);
39372 - if (!us3_freq_table)
39373 - goto err_out;
39374 -
39375 - driver->init = us3_freq_cpu_init;
39376 - driver->verify = cpufreq_generic_frequency_table_verify;
39377 - driver->target_index = us3_freq_target;
39378 - driver->get = us3_freq_get;
39379 - driver->exit = us3_freq_cpu_exit;
39380 - strcpy(driver->name, "UltraSPARC-III");
39381 -
39382 - cpufreq_us3_driver = driver;
39383 - ret = cpufreq_register_driver(driver);
39384 - if (ret)
39385 - goto err_out;
39386 -
39387 - return 0;
39388 -
39389 -err_out:
39390 - if (driver) {
39391 - kfree(driver);
39392 - cpufreq_us3_driver = NULL;
39393 - }
39394 - kfree(us3_freq_table);
39395 - us3_freq_table = NULL;
39396 - return ret;
39397 - }
39398 + impl == PANTHER_IMPL))
39399 + return cpufreq_register_driver(&cpufreq_us3_driver);
39400
39401 return -ENODEV;
39402 }
39403
39404 static void __exit us3_freq_exit(void)
39405 {
39406 - if (cpufreq_us3_driver) {
39407 - cpufreq_unregister_driver(cpufreq_us3_driver);
39408 - kfree(cpufreq_us3_driver);
39409 - cpufreq_us3_driver = NULL;
39410 - kfree(us3_freq_table);
39411 - us3_freq_table = NULL;
39412 - }
39413 + cpufreq_unregister_driver(&cpufreq_us3_driver);
39414 }
39415
39416 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
39417 diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
39418 index 6723f03..3465190 100644
39419 --- a/drivers/cpufreq/speedstep-centrino.c
39420 +++ b/drivers/cpufreq/speedstep-centrino.c
39421 @@ -351,8 +351,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
39422 !cpu_has(cpu, X86_FEATURE_EST))
39423 return -ENODEV;
39424
39425 - if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
39426 - centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39427 + if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
39428 + pax_open_kernel();
39429 + *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
39430 + pax_close_kernel();
39431 + }
39432
39433 if (policy->cpu != 0)
39434 return -ENODEV;
39435 diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
39436 index 136d6a2..06e373d 100644
39437 --- a/drivers/cpuidle/driver.c
39438 +++ b/drivers/cpuidle/driver.c
39439 @@ -202,7 +202,7 @@ static int poll_idle(struct cpuidle_device *dev,
39440
39441 static void poll_idle_init(struct cpuidle_driver *drv)
39442 {
39443 - struct cpuidle_state *state = &drv->states[0];
39444 + cpuidle_state_no_const *state = &drv->states[0];
39445
39446 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
39447 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
39448 diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
39449 index ca89412..a7b9c49 100644
39450 --- a/drivers/cpuidle/governor.c
39451 +++ b/drivers/cpuidle/governor.c
39452 @@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
39453 mutex_lock(&cpuidle_lock);
39454 if (__cpuidle_find_governor(gov->name) == NULL) {
39455 ret = 0;
39456 - list_add_tail(&gov->governor_list, &cpuidle_governors);
39457 + pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
39458 if (!cpuidle_curr_governor ||
39459 cpuidle_curr_governor->rating < gov->rating)
39460 cpuidle_switch_governor(gov);
39461 diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
39462 index efe2f17..b8124f9 100644
39463 --- a/drivers/cpuidle/sysfs.c
39464 +++ b/drivers/cpuidle/sysfs.c
39465 @@ -135,7 +135,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
39466 NULL
39467 };
39468
39469 -static struct attribute_group cpuidle_attr_group = {
39470 +static attribute_group_no_const cpuidle_attr_group = {
39471 .attrs = cpuidle_default_attrs,
39472 .name = "cpuidle",
39473 };
39474 diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
39475 index 12fea3e..1e28f47 100644
39476 --- a/drivers/crypto/hifn_795x.c
39477 +++ b/drivers/crypto/hifn_795x.c
39478 @@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
39479 MODULE_PARM_DESC(hifn_pll_ref,
39480 "PLL reference clock (pci[freq] or ext[freq], default ext)");
39481
39482 -static atomic_t hifn_dev_number;
39483 +static atomic_unchecked_t hifn_dev_number;
39484
39485 #define ACRYPTO_OP_DECRYPT 0
39486 #define ACRYPTO_OP_ENCRYPT 1
39487 @@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
39488 goto err_out_disable_pci_device;
39489
39490 snprintf(name, sizeof(name), "hifn%d",
39491 - atomic_inc_return(&hifn_dev_number)-1);
39492 + atomic_inc_return_unchecked(&hifn_dev_number)-1);
39493
39494 err = pci_request_regions(pdev, name);
39495 if (err)
39496 diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
39497 index 2042ec3..a9ce67f 100644
39498 --- a/drivers/devfreq/devfreq.c
39499 +++ b/drivers/devfreq/devfreq.c
39500 @@ -616,7 +616,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
39501 goto err_out;
39502 }
39503
39504 - list_add(&governor->node, &devfreq_governor_list);
39505 + pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
39506
39507 list_for_each_entry(devfreq, &devfreq_list, node) {
39508 int ret = 0;
39509 @@ -704,7 +704,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
39510 }
39511 }
39512
39513 - list_del(&governor->node);
39514 + pax_list_del((struct list_head *)&governor->node);
39515 err_out:
39516 mutex_unlock(&devfreq_list_lock);
39517
39518 diff --git a/drivers/dma/sh/shdma-base.c b/drivers/dma/sh/shdma-base.c
39519 index 5239677..1cb71a8 100644
39520 --- a/drivers/dma/sh/shdma-base.c
39521 +++ b/drivers/dma/sh/shdma-base.c
39522 @@ -267,8 +267,8 @@ static int shdma_alloc_chan_resources(struct dma_chan *chan)
39523 schan->slave_id = -EINVAL;
39524 }
39525
39526 - schan->desc = kcalloc(NR_DESCS_PER_CHANNEL,
39527 - sdev->desc_size, GFP_KERNEL);
39528 + schan->desc = kcalloc(sdev->desc_size,
39529 + NR_DESCS_PER_CHANNEL, GFP_KERNEL);
39530 if (!schan->desc) {
39531 ret = -ENOMEM;
39532 goto edescalloc;
39533 diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c
39534 index dda7e75..0a4c867 100644
39535 --- a/drivers/dma/sh/shdmac.c
39536 +++ b/drivers/dma/sh/shdmac.c
39537 @@ -513,7 +513,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
39538 return ret;
39539 }
39540
39541 -static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
39542 +static struct notifier_block sh_dmae_nmi_notifier = {
39543 .notifier_call = sh_dmae_nmi_handler,
39544
39545 /* Run before NMI debug handler and KGDB */
39546 diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
39547 index 592af5f..bb1d583 100644
39548 --- a/drivers/edac/edac_device.c
39549 +++ b/drivers/edac/edac_device.c
39550 @@ -477,9 +477,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
39551 */
39552 int edac_device_alloc_index(void)
39553 {
39554 - static atomic_t device_indexes = ATOMIC_INIT(0);
39555 + static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
39556
39557 - return atomic_inc_return(&device_indexes) - 1;
39558 + return atomic_inc_return_unchecked(&device_indexes) - 1;
39559 }
39560 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
39561
39562 diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
39563 index 01fae82..1dd8289 100644
39564 --- a/drivers/edac/edac_mc_sysfs.c
39565 +++ b/drivers/edac/edac_mc_sysfs.c
39566 @@ -152,7 +152,7 @@ static const char * const edac_caps[] = {
39567 struct dev_ch_attribute {
39568 struct device_attribute attr;
39569 int channel;
39570 -};
39571 +} __do_const;
39572
39573 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
39574 struct dev_ch_attribute dev_attr_legacy_##_name = \
39575 @@ -1009,14 +1009,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
39576 }
39577
39578 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
39579 + pax_open_kernel();
39580 if (mci->get_sdram_scrub_rate) {
39581 - dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39582 - dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39583 + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
39584 + *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
39585 }
39586 if (mci->set_sdram_scrub_rate) {
39587 - dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39588 - dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39589 + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
39590 + *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
39591 }
39592 + pax_close_kernel();
39593 err = device_create_file(&mci->dev,
39594 &dev_attr_sdram_scrub_rate);
39595 if (err) {
39596 diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
39597 index 2cf44b4d..6dd2dc7 100644
39598 --- a/drivers/edac/edac_pci.c
39599 +++ b/drivers/edac/edac_pci.c
39600 @@ -29,7 +29,7 @@
39601
39602 static DEFINE_MUTEX(edac_pci_ctls_mutex);
39603 static LIST_HEAD(edac_pci_list);
39604 -static atomic_t pci_indexes = ATOMIC_INIT(0);
39605 +static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
39606
39607 /*
39608 * edac_pci_alloc_ctl_info
39609 @@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
39610 */
39611 int edac_pci_alloc_index(void)
39612 {
39613 - return atomic_inc_return(&pci_indexes) - 1;
39614 + return atomic_inc_return_unchecked(&pci_indexes) - 1;
39615 }
39616 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
39617
39618 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
39619 index e8658e4..22746d6 100644
39620 --- a/drivers/edac/edac_pci_sysfs.c
39621 +++ b/drivers/edac/edac_pci_sysfs.c
39622 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
39623 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
39624 static int edac_pci_poll_msec = 1000; /* one second workq period */
39625
39626 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
39627 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
39628 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
39629 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
39630
39631 static struct kobject *edac_pci_top_main_kobj;
39632 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
39633 @@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
39634 void *value;
39635 ssize_t(*show) (void *, char *);
39636 ssize_t(*store) (void *, const char *, size_t);
39637 -};
39638 +} __do_const;
39639
39640 /* Set of show/store abstract level functions for PCI Parity object */
39641 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
39642 @@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39643 edac_printk(KERN_CRIT, EDAC_PCI,
39644 "Signaled System Error on %s\n",
39645 pci_name(dev));
39646 - atomic_inc(&pci_nonparity_count);
39647 + atomic_inc_unchecked(&pci_nonparity_count);
39648 }
39649
39650 if (status & (PCI_STATUS_PARITY)) {
39651 @@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39652 "Master Data Parity Error on %s\n",
39653 pci_name(dev));
39654
39655 - atomic_inc(&pci_parity_count);
39656 + atomic_inc_unchecked(&pci_parity_count);
39657 }
39658
39659 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39660 @@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39661 "Detected Parity Error on %s\n",
39662 pci_name(dev));
39663
39664 - atomic_inc(&pci_parity_count);
39665 + atomic_inc_unchecked(&pci_parity_count);
39666 }
39667 }
39668
39669 @@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39670 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
39671 "Signaled System Error on %s\n",
39672 pci_name(dev));
39673 - atomic_inc(&pci_nonparity_count);
39674 + atomic_inc_unchecked(&pci_nonparity_count);
39675 }
39676
39677 if (status & (PCI_STATUS_PARITY)) {
39678 @@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39679 "Master Data Parity Error on "
39680 "%s\n", pci_name(dev));
39681
39682 - atomic_inc(&pci_parity_count);
39683 + atomic_inc_unchecked(&pci_parity_count);
39684 }
39685
39686 if (status & (PCI_STATUS_DETECTED_PARITY)) {
39687 @@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
39688 "Detected Parity Error on %s\n",
39689 pci_name(dev));
39690
39691 - atomic_inc(&pci_parity_count);
39692 + atomic_inc_unchecked(&pci_parity_count);
39693 }
39694 }
39695 }
39696 @@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
39697 if (!check_pci_errors)
39698 return;
39699
39700 - before_count = atomic_read(&pci_parity_count);
39701 + before_count = atomic_read_unchecked(&pci_parity_count);
39702
39703 /* scan all PCI devices looking for a Parity Error on devices and
39704 * bridges.
39705 @@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
39706 /* Only if operator has selected panic on PCI Error */
39707 if (edac_pci_get_panic_on_pe()) {
39708 /* If the count is different 'after' from 'before' */
39709 - if (before_count != atomic_read(&pci_parity_count))
39710 + if (before_count != atomic_read_unchecked(&pci_parity_count))
39711 panic("EDAC: PCI Parity Error");
39712 }
39713 }
39714 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
39715 index 51b7e3a..aa8a3e8 100644
39716 --- a/drivers/edac/mce_amd.h
39717 +++ b/drivers/edac/mce_amd.h
39718 @@ -77,7 +77,7 @@ struct amd_decoder_ops {
39719 bool (*mc0_mce)(u16, u8);
39720 bool (*mc1_mce)(u16, u8);
39721 bool (*mc2_mce)(u16, u8);
39722 -};
39723 +} __no_const;
39724
39725 void amd_report_gart_errors(bool);
39726 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
39727 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
39728 index 57ea7f4..af06b76 100644
39729 --- a/drivers/firewire/core-card.c
39730 +++ b/drivers/firewire/core-card.c
39731 @@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
39732 const struct fw_card_driver *driver,
39733 struct device *device)
39734 {
39735 - static atomic_t index = ATOMIC_INIT(-1);
39736 + static atomic_unchecked_t index = ATOMIC_INIT(-1);
39737
39738 - card->index = atomic_inc_return(&index);
39739 + card->index = atomic_inc_return_unchecked(&index);
39740 card->driver = driver;
39741 card->device = device;
39742 card->current_tlabel = 0;
39743 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
39744
39745 void fw_core_remove_card(struct fw_card *card)
39746 {
39747 - struct fw_card_driver dummy_driver = dummy_driver_template;
39748 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
39749
39750 card->driver->update_phy_reg(card, 4,
39751 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
39752 diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
39753 index 2c6d5e1..a2cca6b 100644
39754 --- a/drivers/firewire/core-device.c
39755 +++ b/drivers/firewire/core-device.c
39756 @@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
39757 struct config_rom_attribute {
39758 struct device_attribute attr;
39759 u32 key;
39760 -};
39761 +} __do_const;
39762
39763 static ssize_t show_immediate(struct device *dev,
39764 struct device_attribute *dattr, char *buf)
39765 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
39766 index eb6935c..3cc2bfa 100644
39767 --- a/drivers/firewire/core-transaction.c
39768 +++ b/drivers/firewire/core-transaction.c
39769 @@ -38,6 +38,7 @@
39770 #include <linux/timer.h>
39771 #include <linux/types.h>
39772 #include <linux/workqueue.h>
39773 +#include <linux/sched.h>
39774
39775 #include <asm/byteorder.h>
39776
39777 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
39778 index f477308..2795f24 100644
39779 --- a/drivers/firewire/core.h
39780 +++ b/drivers/firewire/core.h
39781 @@ -111,6 +111,7 @@ struct fw_card_driver {
39782
39783 int (*stop_iso)(struct fw_iso_context *ctx);
39784 };
39785 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
39786
39787 void fw_card_initialize(struct fw_card *card,
39788 const struct fw_card_driver *driver, struct device *device);
39789 diff --git a/drivers/firewire/ohci.c b/drivers/firewire/ohci.c
39790 index 586f2f7..3545ad2 100644
39791 --- a/drivers/firewire/ohci.c
39792 +++ b/drivers/firewire/ohci.c
39793 @@ -2049,10 +2049,12 @@ static void bus_reset_work(struct work_struct *work)
39794 be32_to_cpu(ohci->next_header));
39795 }
39796
39797 +#ifndef CONFIG_GRKERNSEC
39798 if (param_remote_dma) {
39799 reg_write(ohci, OHCI1394_PhyReqFilterHiSet, ~0);
39800 reg_write(ohci, OHCI1394_PhyReqFilterLoSet, ~0);
39801 }
39802 +#endif
39803
39804 spin_unlock_irq(&ohci->lock);
39805
39806 @@ -2584,8 +2586,10 @@ static int ohci_enable_phys_dma(struct fw_card *card,
39807 unsigned long flags;
39808 int n, ret = 0;
39809
39810 +#ifndef CONFIG_GRKERNSEC
39811 if (param_remote_dma)
39812 return 0;
39813 +#endif
39814
39815 /*
39816 * FIXME: Make sure this bitmask is cleared when we clear the busReset
39817 diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
39818 index 94a58a0..f5eba42 100644
39819 --- a/drivers/firmware/dmi-id.c
39820 +++ b/drivers/firmware/dmi-id.c
39821 @@ -16,7 +16,7 @@
39822 struct dmi_device_attribute{
39823 struct device_attribute dev_attr;
39824 int field;
39825 -};
39826 +} __do_const;
39827 #define to_dmi_dev_attr(_dev_attr) \
39828 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
39829
39830 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
39831 index 17afc51..0ef90cd 100644
39832 --- a/drivers/firmware/dmi_scan.c
39833 +++ b/drivers/firmware/dmi_scan.c
39834 @@ -835,7 +835,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
39835 if (buf == NULL)
39836 return -1;
39837
39838 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
39839 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
39840
39841 dmi_unmap(buf);
39842 return 0;
39843 diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
39844 index 1491dd4..aa910db 100644
39845 --- a/drivers/firmware/efi/cper.c
39846 +++ b/drivers/firmware/efi/cper.c
39847 @@ -41,12 +41,12 @@
39848 */
39849 u64 cper_next_record_id(void)
39850 {
39851 - static atomic64_t seq;
39852 + static atomic64_unchecked_t seq;
39853
39854 - if (!atomic64_read(&seq))
39855 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
39856 + if (!atomic64_read_unchecked(&seq))
39857 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
39858
39859 - return atomic64_inc_return(&seq);
39860 + return atomic64_inc_return_unchecked(&seq);
39861 }
39862 EXPORT_SYMBOL_GPL(cper_next_record_id);
39863
39864 diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
39865 index af20f17..4e4e545 100644
39866 --- a/drivers/firmware/efi/efi.c
39867 +++ b/drivers/firmware/efi/efi.c
39868 @@ -120,14 +120,16 @@ static struct attribute_group efi_subsys_attr_group = {
39869 };
39870
39871 static struct efivars generic_efivars;
39872 -static struct efivar_operations generic_ops;
39873 +static efivar_operations_no_const generic_ops __read_only;
39874
39875 static int generic_ops_register(void)
39876 {
39877 - generic_ops.get_variable = efi.get_variable;
39878 - generic_ops.set_variable = efi.set_variable;
39879 - generic_ops.get_next_variable = efi.get_next_variable;
39880 - generic_ops.query_variable_store = efi_query_variable_store;
39881 + pax_open_kernel();
39882 + *(void **)&generic_ops.get_variable = efi.get_variable;
39883 + *(void **)&generic_ops.set_variable = efi.set_variable;
39884 + *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
39885 + *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
39886 + pax_close_kernel();
39887
39888 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
39889 }
39890 diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
39891 index 50ea412..caccd6e9 100644
39892 --- a/drivers/firmware/efi/efivars.c
39893 +++ b/drivers/firmware/efi/efivars.c
39894 @@ -456,7 +456,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
39895 static int
39896 create_efivars_bin_attributes(void)
39897 {
39898 - struct bin_attribute *attr;
39899 + bin_attribute_no_const *attr;
39900 int error;
39901
39902 /* new_var */
39903 diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
39904 index 2f569aa..c95f4fb 100644
39905 --- a/drivers/firmware/google/memconsole.c
39906 +++ b/drivers/firmware/google/memconsole.c
39907 @@ -155,7 +155,10 @@ static int __init memconsole_init(void)
39908 if (!found_memconsole())
39909 return -ENODEV;
39910
39911 - memconsole_bin_attr.size = memconsole_length;
39912 + pax_open_kernel();
39913 + *(size_t *)&memconsole_bin_attr.size = memconsole_length;
39914 + pax_close_kernel();
39915 +
39916 return sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
39917 }
39918
39919 diff --git a/drivers/gpio/gpio-em.c b/drivers/gpio/gpio-em.c
39920 index 8765bd6..2e5b147 100644
39921 --- a/drivers/gpio/gpio-em.c
39922 +++ b/drivers/gpio/gpio-em.c
39923 @@ -278,7 +278,7 @@ static int em_gio_probe(struct platform_device *pdev)
39924 struct em_gio_priv *p;
39925 struct resource *io[2], *irq[2];
39926 struct gpio_chip *gpio_chip;
39927 - struct irq_chip *irq_chip;
39928 + irq_chip_no_const *irq_chip;
39929 const char *name = dev_name(&pdev->dev);
39930 int ret;
39931
39932 diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
39933 index 7030422..42a3fe9 100644
39934 --- a/drivers/gpio/gpio-ich.c
39935 +++ b/drivers/gpio/gpio-ich.c
39936 @@ -94,7 +94,7 @@ struct ichx_desc {
39937 * this option allows driver caching written output values
39938 */
39939 bool use_outlvl_cache;
39940 -};
39941 +} __do_const;
39942
39943 static struct {
39944 spinlock_t lock;
39945 diff --git a/drivers/gpio/gpio-rcar.c b/drivers/gpio/gpio-rcar.c
39946 index 03c9148..c66e753 100644
39947 --- a/drivers/gpio/gpio-rcar.c
39948 +++ b/drivers/gpio/gpio-rcar.c
39949 @@ -355,7 +355,7 @@ static int gpio_rcar_probe(struct platform_device *pdev)
39950 struct gpio_rcar_priv *p;
39951 struct resource *io, *irq;
39952 struct gpio_chip *gpio_chip;
39953 - struct irq_chip *irq_chip;
39954 + irq_chip_no_const *irq_chip;
39955 struct device *dev = &pdev->dev;
39956 const char *name = dev_name(dev);
39957 int ret;
39958 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
39959 index 66cbcc1..0c5e622 100644
39960 --- a/drivers/gpio/gpio-vr41xx.c
39961 +++ b/drivers/gpio/gpio-vr41xx.c
39962 @@ -224,7 +224,7 @@ static int giu_get_irq(unsigned int irq)
39963 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
39964 maskl, pendl, maskh, pendh);
39965
39966 - atomic_inc(&irq_err_count);
39967 + atomic_inc_unchecked(&irq_err_count);
39968
39969 return -EINVAL;
39970 }
39971 diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
39972 index d8b7099..8a314a5 100644
39973 --- a/drivers/gpu/drm/drm_crtc.c
39974 +++ b/drivers/gpu/drm/drm_crtc.c
39975 @@ -3500,7 +3500,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
39976 goto done;
39977 }
39978
39979 - if (copy_to_user(&enum_ptr[copied].name,
39980 + if (copy_to_user(enum_ptr[copied].name,
39981 &prop_enum->name, DRM_PROP_NAME_LEN)) {
39982 ret = -EFAULT;
39983 goto done;
39984 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
39985 old mode 100644
39986 new mode 100755
39987 index 8218078..9960928a
39988 --- a/drivers/gpu/drm/drm_drv.c
39989 +++ b/drivers/gpu/drm/drm_drv.c
39990 @@ -233,7 +233,7 @@ module_exit(drm_core_exit);
39991 /**
39992 * Copy and IOCTL return string to user space
39993 */
39994 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
39995 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
39996 {
39997 int len;
39998
39999 @@ -342,7 +342,7 @@ long drm_ioctl(struct file *filp,
40000 struct drm_file *file_priv = filp->private_data;
40001 struct drm_device *dev;
40002 const struct drm_ioctl_desc *ioctl = NULL;
40003 - drm_ioctl_t *func;
40004 + drm_ioctl_no_const_t func;
40005 unsigned int nr = DRM_IOCTL_NR(cmd);
40006 int retcode = -EINVAL;
40007 char stack_kdata[128];
40008 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
40009 index e1eba0b..98f69f9 100644
40010 --- a/drivers/gpu/drm/drm_fops.c
40011 +++ b/drivers/gpu/drm/drm_fops.c
40012 @@ -89,7 +89,7 @@ int drm_open(struct inode *inode, struct file *filp)
40013 return PTR_ERR(minor);
40014
40015 dev = minor->dev;
40016 - if (!dev->open_count++)
40017 + if (local_inc_return(&dev->open_count) == 1)
40018 need_setup = 1;
40019
40020 /* share address_space across all char-devs of a single device */
40021 @@ -106,7 +106,7 @@ int drm_open(struct inode *inode, struct file *filp)
40022 return 0;
40023
40024 err_undo:
40025 - dev->open_count--;
40026 + local_dec(&dev->open_count);
40027 drm_minor_release(minor);
40028 return retcode;
40029 }
40030 @@ -430,7 +430,7 @@ int drm_release(struct inode *inode, struct file *filp)
40031
40032 mutex_lock(&drm_global_mutex);
40033
40034 - DRM_DEBUG("open_count = %d\n", dev->open_count);
40035 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
40036
40037 if (dev->driver->preclose)
40038 dev->driver->preclose(dev, file_priv);
40039 @@ -439,10 +439,10 @@ int drm_release(struct inode *inode, struct file *filp)
40040 * Begin inline drm_release
40041 */
40042
40043 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
40044 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
40045 task_pid_nr(current),
40046 (long)old_encode_dev(file_priv->minor->kdev->devt),
40047 - dev->open_count);
40048 + local_read(&dev->open_count));
40049
40050 /* Release any auth tokens that might point to this file_priv,
40051 (do that under the drm_global_mutex) */
40052 @@ -543,7 +543,7 @@ int drm_release(struct inode *inode, struct file *filp)
40053 * End inline drm_release
40054 */
40055
40056 - if (!--dev->open_count) {
40057 + if (local_dec_and_test(&dev->open_count)) {
40058 retcode = drm_lastclose(dev);
40059 if (drm_device_is_unplugged(dev))
40060 drm_put_dev(dev);
40061 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
40062 index 3d2e91c..d31c4c9 100644
40063 --- a/drivers/gpu/drm/drm_global.c
40064 +++ b/drivers/gpu/drm/drm_global.c
40065 @@ -36,7 +36,7 @@
40066 struct drm_global_item {
40067 struct mutex mutex;
40068 void *object;
40069 - int refcount;
40070 + atomic_t refcount;
40071 };
40072
40073 static struct drm_global_item glob[DRM_GLOBAL_NUM];
40074 @@ -49,7 +49,7 @@ void drm_global_init(void)
40075 struct drm_global_item *item = &glob[i];
40076 mutex_init(&item->mutex);
40077 item->object = NULL;
40078 - item->refcount = 0;
40079 + atomic_set(&item->refcount, 0);
40080 }
40081 }
40082
40083 @@ -59,7 +59,7 @@ void drm_global_release(void)
40084 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
40085 struct drm_global_item *item = &glob[i];
40086 BUG_ON(item->object != NULL);
40087 - BUG_ON(item->refcount != 0);
40088 + BUG_ON(atomic_read(&item->refcount) != 0);
40089 }
40090 }
40091
40092 @@ -69,7 +69,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
40093 struct drm_global_item *item = &glob[ref->global_type];
40094
40095 mutex_lock(&item->mutex);
40096 - if (item->refcount == 0) {
40097 + if (atomic_read(&item->refcount) == 0) {
40098 item->object = kzalloc(ref->size, GFP_KERNEL);
40099 if (unlikely(item->object == NULL)) {
40100 ret = -ENOMEM;
40101 @@ -82,7 +82,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
40102 goto out_err;
40103
40104 }
40105 - ++item->refcount;
40106 + atomic_inc(&item->refcount);
40107 ref->object = item->object;
40108 mutex_unlock(&item->mutex);
40109 return 0;
40110 @@ -98,9 +98,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
40111 struct drm_global_item *item = &glob[ref->global_type];
40112
40113 mutex_lock(&item->mutex);
40114 - BUG_ON(item->refcount == 0);
40115 + BUG_ON(atomic_read(&item->refcount) == 0);
40116 BUG_ON(ref->object != item->object);
40117 - if (--item->refcount == 0) {
40118 + if (atomic_dec_and_test(&item->refcount)) {
40119 ref->release(ref);
40120 item->object = NULL;
40121 }
40122 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
40123 index 7473035..a48b9c5 100644
40124 --- a/drivers/gpu/drm/drm_info.c
40125 +++ b/drivers/gpu/drm/drm_info.c
40126 @@ -75,10 +75,13 @@ int drm_vm_info(struct seq_file *m, void *data)
40127 struct drm_local_map *map;
40128 struct drm_map_list *r_list;
40129
40130 - /* Hardcoded from _DRM_FRAME_BUFFER,
40131 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
40132 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
40133 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
40134 + static const char * const types[] = {
40135 + [_DRM_FRAME_BUFFER] = "FB",
40136 + [_DRM_REGISTERS] = "REG",
40137 + [_DRM_SHM] = "SHM",
40138 + [_DRM_AGP] = "AGP",
40139 + [_DRM_SCATTER_GATHER] = "SG",
40140 + [_DRM_CONSISTENT] = "PCI"};
40141 const char *type;
40142 int i;
40143
40144 @@ -89,7 +92,7 @@ int drm_vm_info(struct seq_file *m, void *data)
40145 map = r_list->map;
40146 if (!map)
40147 continue;
40148 - if (map->type < 0 || map->type > 5)
40149 + if (map->type >= ARRAY_SIZE(types))
40150 type = "??";
40151 else
40152 type = types[map->type];
40153 @@ -261,7 +264,11 @@ int drm_vma_info(struct seq_file *m, void *data)
40154 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
40155 vma->vm_flags & VM_LOCKED ? 'l' : '-',
40156 vma->vm_flags & VM_IO ? 'i' : '-',
40157 +#ifdef CONFIG_GRKERNSEC_HIDESYM
40158 + 0);
40159 +#else
40160 vma->vm_pgoff);
40161 +#endif
40162
40163 #if defined(__i386__)
40164 pgprot = pgprot_val(vma->vm_page_prot);
40165 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
40166 index 2f4c4343..dd12cd2 100644
40167 --- a/drivers/gpu/drm/drm_ioc32.c
40168 +++ b/drivers/gpu/drm/drm_ioc32.c
40169 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
40170 request = compat_alloc_user_space(nbytes);
40171 if (!access_ok(VERIFY_WRITE, request, nbytes))
40172 return -EFAULT;
40173 - list = (struct drm_buf_desc *) (request + 1);
40174 + list = (struct drm_buf_desc __user *) (request + 1);
40175
40176 if (__put_user(count, &request->count)
40177 || __put_user(list, &request->list))
40178 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
40179 request = compat_alloc_user_space(nbytes);
40180 if (!access_ok(VERIFY_WRITE, request, nbytes))
40181 return -EFAULT;
40182 - list = (struct drm_buf_pub *) (request + 1);
40183 + list = (struct drm_buf_pub __user *) (request + 1);
40184
40185 if (__put_user(count, &request->count)
40186 || __put_user(list, &request->list))
40187 @@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
40188 return 0;
40189 }
40190
40191 -drm_ioctl_compat_t *drm_compat_ioctls[] = {
40192 +drm_ioctl_compat_t drm_compat_ioctls[] = {
40193 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
40194 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
40195 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
40196 @@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
40197 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40198 {
40199 unsigned int nr = DRM_IOCTL_NR(cmd);
40200 - drm_ioctl_compat_t *fn;
40201 int ret;
40202
40203 /* Assume that ioctls without an explicit compat routine will just
40204 @@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40205 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
40206 return drm_ioctl(filp, cmd, arg);
40207
40208 - fn = drm_compat_ioctls[nr];
40209 -
40210 - if (fn != NULL)
40211 - ret = (*fn) (filp, cmd, arg);
40212 + if (drm_compat_ioctls[nr] != NULL)
40213 + ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
40214 else
40215 ret = drm_ioctl(filp, cmd, arg);
40216
40217 diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
40218 index 4c24c3a..c903cab 100644
40219 --- a/drivers/gpu/drm/drm_stub.c
40220 +++ b/drivers/gpu/drm/drm_stub.c
40221 @@ -455,7 +455,7 @@ void drm_unplug_dev(struct drm_device *dev)
40222
40223 drm_device_set_unplugged(dev);
40224
40225 - if (dev->open_count == 0) {
40226 + if (local_read(&dev->open_count) == 0) {
40227 drm_put_dev(dev);
40228 }
40229 mutex_unlock(&drm_global_mutex);
40230 diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
40231 index c22c309..ae758c3 100644
40232 --- a/drivers/gpu/drm/drm_sysfs.c
40233 +++ b/drivers/gpu/drm/drm_sysfs.c
40234 @@ -505,7 +505,7 @@ static void drm_sysfs_release(struct device *dev)
40235 */
40236 int drm_sysfs_device_add(struct drm_minor *minor)
40237 {
40238 - char *minor_str;
40239 + const char *minor_str;
40240 int r;
40241
40242 if (minor->type == DRM_MINOR_CONTROL)
40243 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
40244 index d4d16ed..8fb0b51 100644
40245 --- a/drivers/gpu/drm/i810/i810_drv.h
40246 +++ b/drivers/gpu/drm/i810/i810_drv.h
40247 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
40248 int page_flipping;
40249
40250 wait_queue_head_t irq_queue;
40251 - atomic_t irq_received;
40252 - atomic_t irq_emitted;
40253 + atomic_unchecked_t irq_received;
40254 + atomic_unchecked_t irq_emitted;
40255
40256 int front_offset;
40257 } drm_i810_private_t;
40258 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
40259 index eedb023..25076a4 100644
40260 --- a/drivers/gpu/drm/i915/i915_dma.c
40261 +++ b/drivers/gpu/drm/i915/i915_dma.c
40262 @@ -1280,7 +1280,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
40263 bool can_switch;
40264
40265 spin_lock(&dev->count_lock);
40266 - can_switch = (dev->open_count == 0);
40267 + can_switch = (local_read(&dev->open_count) == 0);
40268 spin_unlock(&dev->count_lock);
40269 return can_switch;
40270 }
40271 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40272 index 20fef6c..76c78fb 100644
40273 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40274 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
40275 @@ -886,9 +886,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
40276
40277 static int
40278 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
40279 - int count)
40280 + unsigned int count)
40281 {
40282 - int i;
40283 + unsigned int i;
40284 unsigned relocs_total = 0;
40285 unsigned relocs_max = UINT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
40286
40287 diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
40288 index 3c59584..500f2e9 100644
40289 --- a/drivers/gpu/drm/i915/i915_ioc32.c
40290 +++ b/drivers/gpu/drm/i915/i915_ioc32.c
40291 @@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
40292 (unsigned long)request);
40293 }
40294
40295 -static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40296 +static drm_ioctl_compat_t i915_compat_ioctls[] = {
40297 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
40298 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
40299 [DRM_I915_GETPARAM] = compat_i915_getparam,
40300 @@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
40301 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40302 {
40303 unsigned int nr = DRM_IOCTL_NR(cmd);
40304 - drm_ioctl_compat_t *fn = NULL;
40305 int ret;
40306
40307 if (nr < DRM_COMMAND_BASE)
40308 return drm_compat_ioctl(filp, cmd, arg);
40309
40310 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
40311 - fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40312 -
40313 - if (fn != NULL)
40314 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
40315 + drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
40316 ret = (*fn) (filp, cmd, arg);
40317 - else
40318 + } else
40319 ret = drm_ioctl(filp, cmd, arg);
40320
40321 return ret;
40322 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
40323 index 5b60e25..eac1625 100644
40324 --- a/drivers/gpu/drm/i915/intel_display.c
40325 +++ b/drivers/gpu/drm/i915/intel_display.c
40326 @@ -11171,13 +11171,13 @@ struct intel_quirk {
40327 int subsystem_vendor;
40328 int subsystem_device;
40329 void (*hook)(struct drm_device *dev);
40330 -};
40331 +} __do_const;
40332
40333 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
40334 struct intel_dmi_quirk {
40335 void (*hook)(struct drm_device *dev);
40336 const struct dmi_system_id (*dmi_id_list)[];
40337 -};
40338 +} __do_const;
40339
40340 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40341 {
40342 @@ -11185,18 +11185,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
40343 return 1;
40344 }
40345
40346 -static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40347 +static const struct dmi_system_id intel_dmi_quirks_table[] = {
40348 {
40349 - .dmi_id_list = &(const struct dmi_system_id[]) {
40350 - {
40351 - .callback = intel_dmi_reverse_brightness,
40352 - .ident = "NCR Corporation",
40353 - .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40354 - DMI_MATCH(DMI_PRODUCT_NAME, ""),
40355 - },
40356 - },
40357 - { } /* terminating entry */
40358 + .callback = intel_dmi_reverse_brightness,
40359 + .ident = "NCR Corporation",
40360 + .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
40361 + DMI_MATCH(DMI_PRODUCT_NAME, ""),
40362 },
40363 + },
40364 + { } /* terminating entry */
40365 +};
40366 +
40367 +static const struct intel_dmi_quirk intel_dmi_quirks[] = {
40368 + {
40369 + .dmi_id_list = &intel_dmi_quirks_table,
40370 .hook = quirk_invert_brightness,
40371 },
40372 };
40373 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
40374 index fe45321..836fdca 100644
40375 --- a/drivers/gpu/drm/mga/mga_drv.h
40376 +++ b/drivers/gpu/drm/mga/mga_drv.h
40377 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
40378 u32 clear_cmd;
40379 u32 maccess;
40380
40381 - atomic_t vbl_received; /**< Number of vblanks received. */
40382 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
40383 wait_queue_head_t fence_queue;
40384 - atomic_t last_fence_retired;
40385 + atomic_unchecked_t last_fence_retired;
40386 u32 next_fence_to_post;
40387
40388 unsigned int fb_cpp;
40389 diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
40390 index 86b4bb8..ae237ad 100644
40391 --- a/drivers/gpu/drm/mga/mga_ioc32.c
40392 +++ b/drivers/gpu/drm/mga/mga_ioc32.c
40393 @@ -190,7 +190,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
40394 return 0;
40395 }
40396
40397 -drm_ioctl_compat_t *mga_compat_ioctls[] = {
40398 +drm_ioctl_compat_t mga_compat_ioctls[] = {
40399 [DRM_MGA_INIT] = compat_mga_init,
40400 [DRM_MGA_GETPARAM] = compat_mga_getparam,
40401 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
40402 @@ -208,18 +208,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
40403 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40404 {
40405 unsigned int nr = DRM_IOCTL_NR(cmd);
40406 - drm_ioctl_compat_t *fn = NULL;
40407 int ret;
40408
40409 if (nr < DRM_COMMAND_BASE)
40410 return drm_compat_ioctl(filp, cmd, arg);
40411
40412 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
40413 - fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40414 -
40415 - if (fn != NULL)
40416 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
40417 + drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
40418 ret = (*fn) (filp, cmd, arg);
40419 - else
40420 + } else
40421 ret = drm_ioctl(filp, cmd, arg);
40422
40423 return ret;
40424 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
40425 index 1b071b8..de8601a 100644
40426 --- a/drivers/gpu/drm/mga/mga_irq.c
40427 +++ b/drivers/gpu/drm/mga/mga_irq.c
40428 @@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
40429 if (crtc != 0)
40430 return 0;
40431
40432 - return atomic_read(&dev_priv->vbl_received);
40433 + return atomic_read_unchecked(&dev_priv->vbl_received);
40434 }
40435
40436
40437 @@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40438 /* VBLANK interrupt */
40439 if (status & MGA_VLINEPEN) {
40440 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
40441 - atomic_inc(&dev_priv->vbl_received);
40442 + atomic_inc_unchecked(&dev_priv->vbl_received);
40443 drm_handle_vblank(dev, 0);
40444 handled = 1;
40445 }
40446 @@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(int irq, void *arg)
40447 if ((prim_start & ~0x03) != (prim_end & ~0x03))
40448 MGA_WRITE(MGA_PRIMEND, prim_end);
40449
40450 - atomic_inc(&dev_priv->last_fence_retired);
40451 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
40452 wake_up(&dev_priv->fence_queue);
40453 handled = 1;
40454 }
40455 @@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
40456 * using fences.
40457 */
40458 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * HZ,
40459 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
40460 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
40461 - *sequence) <= (1 << 23)));
40462
40463 *sequence = cur_fence;
40464 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
40465 index 8268a4c..5105708 100644
40466 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
40467 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
40468 @@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
40469 struct bit_table {
40470 const char id;
40471 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
40472 -};
40473 +} __no_const;
40474
40475 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
40476
40477 diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
40478 index 7efbafa..19f8087 100644
40479 --- a/drivers/gpu/drm/nouveau/nouveau_drm.h
40480 +++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
40481 @@ -97,7 +97,6 @@ struct nouveau_drm {
40482 struct drm_global_reference mem_global_ref;
40483 struct ttm_bo_global_ref bo_global_ref;
40484 struct ttm_bo_device bdev;
40485 - atomic_t validate_sequence;
40486 int (*move)(struct nouveau_channel *,
40487 struct ttm_buffer_object *,
40488 struct ttm_mem_reg *, struct ttm_mem_reg *);
40489 diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40490 index c1a7e5a..38b8539 100644
40491 --- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40492 +++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
40493 @@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
40494 unsigned long arg)
40495 {
40496 unsigned int nr = DRM_IOCTL_NR(cmd);
40497 - drm_ioctl_compat_t *fn = NULL;
40498 + drm_ioctl_compat_t fn = NULL;
40499 int ret;
40500
40501 if (nr < DRM_COMMAND_BASE)
40502 diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40503 index ab0228f..20b756b 100644
40504 --- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
40505 +++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
40506 @@ -130,11 +130,11 @@ nouveau_vram_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40507 }
40508
40509 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
40510 - nouveau_vram_manager_init,
40511 - nouveau_vram_manager_fini,
40512 - nouveau_vram_manager_new,
40513 - nouveau_vram_manager_del,
40514 - nouveau_vram_manager_debug
40515 + .init = nouveau_vram_manager_init,
40516 + .takedown = nouveau_vram_manager_fini,
40517 + .get_node = nouveau_vram_manager_new,
40518 + .put_node = nouveau_vram_manager_del,
40519 + .debug = nouveau_vram_manager_debug
40520 };
40521
40522 static int
40523 @@ -199,11 +199,11 @@ nouveau_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40524 }
40525
40526 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
40527 - nouveau_gart_manager_init,
40528 - nouveau_gart_manager_fini,
40529 - nouveau_gart_manager_new,
40530 - nouveau_gart_manager_del,
40531 - nouveau_gart_manager_debug
40532 + .init = nouveau_gart_manager_init,
40533 + .takedown = nouveau_gart_manager_fini,
40534 + .get_node = nouveau_gart_manager_new,
40535 + .put_node = nouveau_gart_manager_del,
40536 + .debug = nouveau_gart_manager_debug
40537 };
40538
40539 #include <core/subdev/vm/nv04.h>
40540 @@ -271,11 +271,11 @@ nv04_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
40541 }
40542
40543 const struct ttm_mem_type_manager_func nv04_gart_manager = {
40544 - nv04_gart_manager_init,
40545 - nv04_gart_manager_fini,
40546 - nv04_gart_manager_new,
40547 - nv04_gart_manager_del,
40548 - nv04_gart_manager_debug
40549 + .init = nv04_gart_manager_init,
40550 + .takedown = nv04_gart_manager_fini,
40551 + .get_node = nv04_gart_manager_new,
40552 + .put_node = nv04_gart_manager_del,
40553 + .debug = nv04_gart_manager_debug
40554 };
40555
40556 int
40557 diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
40558 index fb84da3..d7ee463 100644
40559 --- a/drivers/gpu/drm/nouveau/nouveau_vga.c
40560 +++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
40561 @@ -67,7 +67,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
40562 bool can_switch;
40563
40564 spin_lock(&dev->count_lock);
40565 - can_switch = (dev->open_count == 0);
40566 + can_switch = (local_read(&dev->open_count) == 0);
40567 spin_unlock(&dev->count_lock);
40568 return can_switch;
40569 }
40570 diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
40571 index eb89653..613cf71 100644
40572 --- a/drivers/gpu/drm/qxl/qxl_cmd.c
40573 +++ b/drivers/gpu/drm/qxl/qxl_cmd.c
40574 @@ -285,27 +285,27 @@ static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port,
40575 int ret;
40576
40577 mutex_lock(&qdev->async_io_mutex);
40578 - irq_num = atomic_read(&qdev->irq_received_io_cmd);
40579 + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40580 if (qdev->last_sent_io_cmd > irq_num) {
40581 if (intr)
40582 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40583 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40584 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40585 else
40586 ret = wait_event_timeout(qdev->io_cmd_event,
40587 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40588 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40589 /* 0 is timeout, just bail the "hw" has gone away */
40590 if (ret <= 0)
40591 goto out;
40592 - irq_num = atomic_read(&qdev->irq_received_io_cmd);
40593 + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
40594 }
40595 outb(val, addr);
40596 qdev->last_sent_io_cmd = irq_num + 1;
40597 if (intr)
40598 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
40599 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40600 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40601 else
40602 ret = wait_event_timeout(qdev->io_cmd_event,
40603 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40604 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
40605 out:
40606 if (ret > 0)
40607 ret = 0;
40608 diff --git a/drivers/gpu/drm/qxl/qxl_debugfs.c b/drivers/gpu/drm/qxl/qxl_debugfs.c
40609 index c3c2bbd..bc3c0fb 100644
40610 --- a/drivers/gpu/drm/qxl/qxl_debugfs.c
40611 +++ b/drivers/gpu/drm/qxl/qxl_debugfs.c
40612 @@ -42,10 +42,10 @@ qxl_debugfs_irq_received(struct seq_file *m, void *data)
40613 struct drm_info_node *node = (struct drm_info_node *) m->private;
40614 struct qxl_device *qdev = node->minor->dev->dev_private;
40615
40616 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
40617 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
40618 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
40619 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
40620 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received));
40621 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_display));
40622 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_cursor));
40623 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_io_cmd));
40624 seq_printf(m, "%d\n", qdev->irq_received_error);
40625 return 0;
40626 }
40627 diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
40628 index 36ed40b..0397633 100644
40629 --- a/drivers/gpu/drm/qxl/qxl_drv.h
40630 +++ b/drivers/gpu/drm/qxl/qxl_drv.h
40631 @@ -290,10 +290,10 @@ struct qxl_device {
40632 unsigned int last_sent_io_cmd;
40633
40634 /* interrupt handling */
40635 - atomic_t irq_received;
40636 - atomic_t irq_received_display;
40637 - atomic_t irq_received_cursor;
40638 - atomic_t irq_received_io_cmd;
40639 + atomic_unchecked_t irq_received;
40640 + atomic_unchecked_t irq_received_display;
40641 + atomic_unchecked_t irq_received_cursor;
40642 + atomic_unchecked_t irq_received_io_cmd;
40643 unsigned irq_received_error;
40644 wait_queue_head_t display_event;
40645 wait_queue_head_t cursor_event;
40646 diff --git a/drivers/gpu/drm/qxl/qxl_ioctl.c b/drivers/gpu/drm/qxl/qxl_ioctl.c
40647 index 0bb86e6..d41416d 100644
40648 --- a/drivers/gpu/drm/qxl/qxl_ioctl.c
40649 +++ b/drivers/gpu/drm/qxl/qxl_ioctl.c
40650 @@ -181,7 +181,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40651
40652 /* TODO copy slow path code from i915 */
40653 fb_cmd = qxl_bo_kmap_atomic_page(qdev, cmd_bo, (release->release_offset & PAGE_SIZE));
40654 - 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);
40655 + 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);
40656
40657 {
40658 struct qxl_drawable *draw = fb_cmd;
40659 @@ -201,7 +201,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40660 struct drm_qxl_reloc reloc;
40661
40662 if (copy_from_user(&reloc,
40663 - &((struct drm_qxl_reloc *)(uintptr_t)cmd->relocs)[i],
40664 + &((struct drm_qxl_reloc __force_user *)(uintptr_t)cmd->relocs)[i],
40665 sizeof(reloc))) {
40666 ret = -EFAULT;
40667 goto out_free_bos;
40668 @@ -294,10 +294,10 @@ static int qxl_execbuffer_ioctl(struct drm_device *dev, void *data,
40669
40670 for (cmd_num = 0; cmd_num < execbuffer->commands_num; ++cmd_num) {
40671
40672 - struct drm_qxl_command *commands =
40673 - (struct drm_qxl_command *)(uintptr_t)execbuffer->commands;
40674 + struct drm_qxl_command __user *commands =
40675 + (struct drm_qxl_command __user *)(uintptr_t)execbuffer->commands;
40676
40677 - if (copy_from_user(&user_cmd, &commands[cmd_num],
40678 + if (copy_from_user(&user_cmd, (struct drm_qxl_command __force_user *)&commands[cmd_num],
40679 sizeof(user_cmd)))
40680 return -EFAULT;
40681
40682 diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c
40683 index 28f84b4..fb3e224 100644
40684 --- a/drivers/gpu/drm/qxl/qxl_irq.c
40685 +++ b/drivers/gpu/drm/qxl/qxl_irq.c
40686 @@ -33,19 +33,19 @@ irqreturn_t qxl_irq_handler(int irq, void *arg)
40687
40688 pending = xchg(&qdev->ram_header->int_pending, 0);
40689
40690 - atomic_inc(&qdev->irq_received);
40691 + atomic_inc_unchecked(&qdev->irq_received);
40692
40693 if (pending & QXL_INTERRUPT_DISPLAY) {
40694 - atomic_inc(&qdev->irq_received_display);
40695 + atomic_inc_unchecked(&qdev->irq_received_display);
40696 wake_up_all(&qdev->display_event);
40697 qxl_queue_garbage_collect(qdev, false);
40698 }
40699 if (pending & QXL_INTERRUPT_CURSOR) {
40700 - atomic_inc(&qdev->irq_received_cursor);
40701 + atomic_inc_unchecked(&qdev->irq_received_cursor);
40702 wake_up_all(&qdev->cursor_event);
40703 }
40704 if (pending & QXL_INTERRUPT_IO_CMD) {
40705 - atomic_inc(&qdev->irq_received_io_cmd);
40706 + atomic_inc_unchecked(&qdev->irq_received_io_cmd);
40707 wake_up_all(&qdev->io_cmd_event);
40708 }
40709 if (pending & QXL_INTERRUPT_ERROR) {
40710 @@ -82,10 +82,10 @@ int qxl_irq_init(struct qxl_device *qdev)
40711 init_waitqueue_head(&qdev->io_cmd_event);
40712 INIT_WORK(&qdev->client_monitors_config_work,
40713 qxl_client_monitors_config_work_func);
40714 - atomic_set(&qdev->irq_received, 0);
40715 - atomic_set(&qdev->irq_received_display, 0);
40716 - atomic_set(&qdev->irq_received_cursor, 0);
40717 - atomic_set(&qdev->irq_received_io_cmd, 0);
40718 + atomic_set_unchecked(&qdev->irq_received, 0);
40719 + atomic_set_unchecked(&qdev->irq_received_display, 0);
40720 + atomic_set_unchecked(&qdev->irq_received_cursor, 0);
40721 + atomic_set_unchecked(&qdev->irq_received_io_cmd, 0);
40722 qdev->irq_received_error = 0;
40723 ret = drm_irq_install(qdev->ddev);
40724 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
40725 diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
40726 index d52c275..4e6b43d 100644
40727 --- a/drivers/gpu/drm/qxl/qxl_ttm.c
40728 +++ b/drivers/gpu/drm/qxl/qxl_ttm.c
40729 @@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
40730 }
40731 }
40732
40733 -static struct vm_operations_struct qxl_ttm_vm_ops;
40734 +static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
40735 static const struct vm_operations_struct *ttm_vm_ops;
40736
40737 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
40738 @@ -147,8 +147,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
40739 return r;
40740 if (unlikely(ttm_vm_ops == NULL)) {
40741 ttm_vm_ops = vma->vm_ops;
40742 + pax_open_kernel();
40743 qxl_ttm_vm_ops = *ttm_vm_ops;
40744 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
40745 + pax_close_kernel();
40746 }
40747 vma->vm_ops = &qxl_ttm_vm_ops;
40748 return 0;
40749 @@ -561,25 +563,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
40750 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
40751 {
40752 #if defined(CONFIG_DEBUG_FS)
40753 - static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
40754 - static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
40755 - unsigned i;
40756 + static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
40757 + {
40758 + .name = "qxl_mem_mm",
40759 + .show = &qxl_mm_dump_table,
40760 + },
40761 + {
40762 + .name = "qxl_surf_mm",
40763 + .show = &qxl_mm_dump_table,
40764 + }
40765 + };
40766
40767 - for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
40768 - if (i == 0)
40769 - sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
40770 - else
40771 - sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
40772 - qxl_mem_types_list[i].name = qxl_mem_types_names[i];
40773 - qxl_mem_types_list[i].show = &qxl_mm_dump_table;
40774 - qxl_mem_types_list[i].driver_features = 0;
40775 - if (i == 0)
40776 - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
40777 - else
40778 - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
40779 + pax_open_kernel();
40780 + *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
40781 + *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
40782 + pax_close_kernel();
40783
40784 - }
40785 - return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
40786 + return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
40787 #else
40788 return 0;
40789 #endif
40790 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
40791 index 59459fe..be26b31 100644
40792 --- a/drivers/gpu/drm/r128/r128_cce.c
40793 +++ b/drivers/gpu/drm/r128/r128_cce.c
40794 @@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
40795
40796 /* GH: Simple idle check.
40797 */
40798 - atomic_set(&dev_priv->idle_count, 0);
40799 + atomic_set_unchecked(&dev_priv->idle_count, 0);
40800
40801 /* We don't support anything other than bus-mastering ring mode,
40802 * but the ring can be in either AGP or PCI space for the ring
40803 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
40804 index 5bf3f5f..7000661 100644
40805 --- a/drivers/gpu/drm/r128/r128_drv.h
40806 +++ b/drivers/gpu/drm/r128/r128_drv.h
40807 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
40808 int is_pci;
40809 unsigned long cce_buffers_offset;
40810
40811 - atomic_t idle_count;
40812 + atomic_unchecked_t idle_count;
40813
40814 int page_flipping;
40815 int current_page;
40816 u32 crtc_offset;
40817 u32 crtc_offset_cntl;
40818
40819 - atomic_t vbl_received;
40820 + atomic_unchecked_t vbl_received;
40821
40822 u32 color_fmt;
40823 unsigned int front_offset;
40824 diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
40825 index b0d0fd3..a6fbbe4 100644
40826 --- a/drivers/gpu/drm/r128/r128_ioc32.c
40827 +++ b/drivers/gpu/drm/r128/r128_ioc32.c
40828 @@ -178,7 +178,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
40829 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
40830 }
40831
40832 -drm_ioctl_compat_t *r128_compat_ioctls[] = {
40833 +drm_ioctl_compat_t r128_compat_ioctls[] = {
40834 [DRM_R128_INIT] = compat_r128_init,
40835 [DRM_R128_DEPTH] = compat_r128_depth,
40836 [DRM_R128_STIPPLE] = compat_r128_stipple,
40837 @@ -197,18 +197,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
40838 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40839 {
40840 unsigned int nr = DRM_IOCTL_NR(cmd);
40841 - drm_ioctl_compat_t *fn = NULL;
40842 int ret;
40843
40844 if (nr < DRM_COMMAND_BASE)
40845 return drm_compat_ioctl(filp, cmd, arg);
40846
40847 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
40848 - fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
40849 -
40850 - if (fn != NULL)
40851 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
40852 + drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
40853 ret = (*fn) (filp, cmd, arg);
40854 - else
40855 + } else
40856 ret = drm_ioctl(filp, cmd, arg);
40857
40858 return ret;
40859 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
40860 index c2ae496..30b5993 100644
40861 --- a/drivers/gpu/drm/r128/r128_irq.c
40862 +++ b/drivers/gpu/drm/r128/r128_irq.c
40863 @@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
40864 if (crtc != 0)
40865 return 0;
40866
40867 - return atomic_read(&dev_priv->vbl_received);
40868 + return atomic_read_unchecked(&dev_priv->vbl_received);
40869 }
40870
40871 irqreturn_t r128_driver_irq_handler(int irq, void *arg)
40872 @@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(int irq, void *arg)
40873 /* VBLANK interrupt */
40874 if (status & R128_CRTC_VBLANK_INT) {
40875 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
40876 - atomic_inc(&dev_priv->vbl_received);
40877 + atomic_inc_unchecked(&dev_priv->vbl_received);
40878 drm_handle_vblank(dev, 0);
40879 return IRQ_HANDLED;
40880 }
40881 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
40882 index e806dac..f81d32f 100644
40883 --- a/drivers/gpu/drm/r128/r128_state.c
40884 +++ b/drivers/gpu/drm/r128/r128_state.c
40885 @@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
40886
40887 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
40888 {
40889 - if (atomic_read(&dev_priv->idle_count) == 0)
40890 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
40891 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
40892 else
40893 - atomic_set(&dev_priv->idle_count, 0);
40894 + atomic_set_unchecked(&dev_priv->idle_count, 0);
40895 }
40896
40897 #endif
40898 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
40899 index 4a85bb6..aaea819 100644
40900 --- a/drivers/gpu/drm/radeon/mkregtable.c
40901 +++ b/drivers/gpu/drm/radeon/mkregtable.c
40902 @@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
40903 regex_t mask_rex;
40904 regmatch_t match[4];
40905 char buf[1024];
40906 - size_t end;
40907 + long end;
40908 int len;
40909 int done = 0;
40910 int r;
40911 unsigned o;
40912 struct offset *offset;
40913 char last_reg_s[10];
40914 - int last_reg;
40915 + unsigned long last_reg;
40916
40917 if (regcomp
40918 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
40919 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
40920 index 2cd144c..a01c95a 100644
40921 --- a/drivers/gpu/drm/radeon/radeon_device.c
40922 +++ b/drivers/gpu/drm/radeon/radeon_device.c
40923 @@ -1129,7 +1129,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
40924 bool can_switch;
40925
40926 spin_lock(&dev->count_lock);
40927 - can_switch = (dev->open_count == 0);
40928 + can_switch = (local_read(&dev->open_count) == 0);
40929 spin_unlock(&dev->count_lock);
40930 return can_switch;
40931 }
40932 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
40933 index dafd812..1bf20c7 100644
40934 --- a/drivers/gpu/drm/radeon/radeon_drv.h
40935 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
40936 @@ -262,7 +262,7 @@ typedef struct drm_radeon_private {
40937
40938 /* SW interrupt */
40939 wait_queue_head_t swi_queue;
40940 - atomic_t swi_emitted;
40941 + atomic_unchecked_t swi_emitted;
40942 int vblank_crtc;
40943 uint32_t irq_enable_reg;
40944 uint32_t r500_disp_irq_reg;
40945 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
40946 index bdb0f93..5ff558f 100644
40947 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
40948 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
40949 @@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
40950 request = compat_alloc_user_space(sizeof(*request));
40951 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
40952 || __put_user(req32.param, &request->param)
40953 - || __put_user((void __user *)(unsigned long)req32.value,
40954 + || __put_user((unsigned long)req32.value,
40955 &request->value))
40956 return -EFAULT;
40957
40958 @@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
40959 #define compat_radeon_cp_setparam NULL
40960 #endif /* X86_64 || IA64 */
40961
40962 -static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
40963 +static drm_ioctl_compat_t radeon_compat_ioctls[] = {
40964 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
40965 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
40966 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
40967 @@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
40968 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40969 {
40970 unsigned int nr = DRM_IOCTL_NR(cmd);
40971 - drm_ioctl_compat_t *fn = NULL;
40972 int ret;
40973
40974 if (nr < DRM_COMMAND_BASE)
40975 return drm_compat_ioctl(filp, cmd, arg);
40976
40977 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
40978 - fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
40979 -
40980 - if (fn != NULL)
40981 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
40982 + drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
40983 ret = (*fn) (filp, cmd, arg);
40984 - else
40985 + } else
40986 ret = drm_ioctl(filp, cmd, arg);
40987
40988 return ret;
40989 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
40990 index 244b19b..c19226d 100644
40991 --- a/drivers/gpu/drm/radeon/radeon_irq.c
40992 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
40993 @@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
40994 unsigned int ret;
40995 RING_LOCALS;
40996
40997 - atomic_inc(&dev_priv->swi_emitted);
40998 - ret = atomic_read(&dev_priv->swi_emitted);
40999 + atomic_inc_unchecked(&dev_priv->swi_emitted);
41000 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
41001
41002 BEGIN_RING(4);
41003 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
41004 @@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
41005 drm_radeon_private_t *dev_priv =
41006 (drm_radeon_private_t *) dev->dev_private;
41007
41008 - atomic_set(&dev_priv->swi_emitted, 0);
41009 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
41010 init_waitqueue_head(&dev_priv->swi_queue);
41011
41012 dev->max_vblank_count = 0x001fffff;
41013 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
41014 index 956ab7f..fbd36d8 100644
41015 --- a/drivers/gpu/drm/radeon/radeon_state.c
41016 +++ b/drivers/gpu/drm/radeon/radeon_state.c
41017 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
41018 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
41019 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
41020
41021 - if (copy_from_user(&depth_boxes, clear->depth_boxes,
41022 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || copy_from_user(&depth_boxes, clear->depth_boxes,
41023 sarea_priv->nbox * sizeof(depth_boxes[0])))
41024 return -EFAULT;
41025
41026 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
41027 {
41028 drm_radeon_private_t *dev_priv = dev->dev_private;
41029 drm_radeon_getparam_t *param = data;
41030 - int value;
41031 + int value = 0;
41032
41033 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
41034
41035 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
41036 index c8a8a51..219dacc 100644
41037 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
41038 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
41039 @@ -797,7 +797,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
41040 man->size = size >> PAGE_SHIFT;
41041 }
41042
41043 -static struct vm_operations_struct radeon_ttm_vm_ops;
41044 +static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
41045 static const struct vm_operations_struct *ttm_vm_ops = NULL;
41046
41047 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
41048 @@ -838,8 +838,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
41049 }
41050 if (unlikely(ttm_vm_ops == NULL)) {
41051 ttm_vm_ops = vma->vm_ops;
41052 + pax_open_kernel();
41053 radeon_ttm_vm_ops = *ttm_vm_ops;
41054 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
41055 + pax_close_kernel();
41056 }
41057 vma->vm_ops = &radeon_ttm_vm_ops;
41058 return 0;
41059 diff --git a/drivers/gpu/drm/radeon/radeon_vm.c b/drivers/gpu/drm/radeon/radeon_vm.c
41060 index c11b71d..c8c48aa 100644
41061 --- a/drivers/gpu/drm/radeon/radeon_vm.c
41062 +++ b/drivers/gpu/drm/radeon/radeon_vm.c
41063 @@ -493,7 +493,7 @@ int radeon_vm_bo_set_addr(struct radeon_device *rdev,
41064 mutex_unlock(&vm->mutex);
41065
41066 r = radeon_bo_create(rdev, RADEON_VM_PTE_COUNT * 8,
41067 - RADEON_GPU_PAGE_SIZE, false,
41068 + RADEON_GPU_PAGE_SIZE, true,
41069 RADEON_GEM_DOMAIN_VRAM, NULL, &pt);
41070 if (r)
41071 return r;
41072 @@ -913,7 +913,7 @@ int radeon_vm_init(struct radeon_device *rdev, struct radeon_vm *vm)
41073 return -ENOMEM;
41074 }
41075
41076 - r = radeon_bo_create(rdev, pd_size, RADEON_VM_PTB_ALIGN_SIZE, false,
41077 + r = radeon_bo_create(rdev, pd_size, RADEON_VM_PTB_ALIGN_SIZE, true,
41078 RADEON_GEM_DOMAIN_VRAM, NULL,
41079 &vm->page_directory);
41080 if (r)
41081 diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
41082 index edb871d..a275c6ed 100644
41083 --- a/drivers/gpu/drm/tegra/dc.c
41084 +++ b/drivers/gpu/drm/tegra/dc.c
41085 @@ -1057,7 +1057,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
41086 }
41087
41088 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
41089 - dc->debugfs_files[i].data = dc;
41090 + *(void **)&dc->debugfs_files[i].data = dc;
41091
41092 err = drm_debugfs_create_files(dc->debugfs_files,
41093 ARRAY_SIZE(debugfs_files),
41094 diff --git a/drivers/gpu/drm/tegra/dsi.c b/drivers/gpu/drm/tegra/dsi.c
41095 index 0e599f0..c9ea7c7 100644
41096 --- a/drivers/gpu/drm/tegra/dsi.c
41097 +++ b/drivers/gpu/drm/tegra/dsi.c
41098 @@ -39,7 +39,7 @@ struct tegra_dsi {
41099 struct clk *clk_lp;
41100 struct clk *clk;
41101
41102 - struct drm_info_list *debugfs_files;
41103 + drm_info_list_no_const *debugfs_files;
41104 struct drm_minor *minor;
41105 struct dentry *debugfs;
41106
41107 diff --git a/drivers/gpu/drm/tegra/hdmi.c b/drivers/gpu/drm/tegra/hdmi.c
41108 index 6928015..c9853e7 100644
41109 --- a/drivers/gpu/drm/tegra/hdmi.c
41110 +++ b/drivers/gpu/drm/tegra/hdmi.c
41111 @@ -59,7 +59,7 @@ struct tegra_hdmi {
41112 bool stereo;
41113 bool dvi;
41114
41115 - struct drm_info_list *debugfs_files;
41116 + drm_info_list_no_const *debugfs_files;
41117 struct drm_minor *minor;
41118 struct dentry *debugfs;
41119 };
41120 diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41121 index bd850c9..d9f3573 100644
41122 --- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
41123 +++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
41124 @@ -146,10 +146,10 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
41125 }
41126
41127 const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
41128 - ttm_bo_man_init,
41129 - ttm_bo_man_takedown,
41130 - ttm_bo_man_get_node,
41131 - ttm_bo_man_put_node,
41132 - ttm_bo_man_debug
41133 + .init = ttm_bo_man_init,
41134 + .takedown = ttm_bo_man_takedown,
41135 + .get_node = ttm_bo_man_get_node,
41136 + .put_node = ttm_bo_man_put_node,
41137 + .debug = ttm_bo_man_debug
41138 };
41139 EXPORT_SYMBOL(ttm_bo_manager_func);
41140 diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
41141 index dbc2def..0a9f710 100644
41142 --- a/drivers/gpu/drm/ttm/ttm_memory.c
41143 +++ b/drivers/gpu/drm/ttm/ttm_memory.c
41144 @@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
41145 zone->glob = glob;
41146 glob->zone_kernel = zone;
41147 ret = kobject_init_and_add(
41148 - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41149 + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41150 if (unlikely(ret != 0)) {
41151 kobject_put(&zone->kobj);
41152 return ret;
41153 @@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
41154 zone->glob = glob;
41155 glob->zone_dma32 = zone;
41156 ret = kobject_init_and_add(
41157 - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
41158 + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
41159 if (unlikely(ret != 0)) {
41160 kobject_put(&zone->kobj);
41161 return ret;
41162 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41163 index 863bef9..cba15cf 100644
41164 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
41165 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
41166 @@ -391,9 +391,9 @@ out:
41167 static unsigned long
41168 ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
41169 {
41170 - static atomic_t start_pool = ATOMIC_INIT(0);
41171 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
41172 unsigned i;
41173 - unsigned pool_offset = atomic_add_return(1, &start_pool);
41174 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
41175 struct ttm_page_pool *pool;
41176 int shrink_pages = sc->nr_to_scan;
41177 unsigned long freed = 0;
41178 diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
41179 index 3771763..883f206 100644
41180 --- a/drivers/gpu/drm/udl/udl_fb.c
41181 +++ b/drivers/gpu/drm/udl/udl_fb.c
41182 @@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
41183 fb_deferred_io_cleanup(info);
41184 kfree(info->fbdefio);
41185 info->fbdefio = NULL;
41186 - info->fbops->fb_mmap = udl_fb_mmap;
41187 }
41188
41189 pr_warn("released /dev/fb%d user=%d count=%d\n",
41190 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
41191 index ad02732..144f5ed 100644
41192 --- a/drivers/gpu/drm/via/via_drv.h
41193 +++ b/drivers/gpu/drm/via/via_drv.h
41194 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
41195 typedef uint32_t maskarray_t[5];
41196
41197 typedef struct drm_via_irq {
41198 - atomic_t irq_received;
41199 + atomic_unchecked_t irq_received;
41200 uint32_t pending_mask;
41201 uint32_t enable_mask;
41202 wait_queue_head_t irq_queue;
41203 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
41204 struct timeval last_vblank;
41205 int last_vblank_valid;
41206 unsigned usec_per_vblank;
41207 - atomic_t vbl_received;
41208 + atomic_unchecked_t vbl_received;
41209 drm_via_state_t hc_state;
41210 char pci_buf[VIA_PCI_BUF_SIZE];
41211 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
41212 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
41213 index 1319433..a993b0c 100644
41214 --- a/drivers/gpu/drm/via/via_irq.c
41215 +++ b/drivers/gpu/drm/via/via_irq.c
41216 @@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
41217 if (crtc != 0)
41218 return 0;
41219
41220 - return atomic_read(&dev_priv->vbl_received);
41221 + return atomic_read_unchecked(&dev_priv->vbl_received);
41222 }
41223
41224 irqreturn_t via_driver_irq_handler(int irq, void *arg)
41225 @@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41226
41227 status = VIA_READ(VIA_REG_INTERRUPT);
41228 if (status & VIA_IRQ_VBLANK_PENDING) {
41229 - atomic_inc(&dev_priv->vbl_received);
41230 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
41231 + atomic_inc_unchecked(&dev_priv->vbl_received);
41232 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
41233 do_gettimeofday(&cur_vblank);
41234 if (dev_priv->last_vblank_valid) {
41235 dev_priv->usec_per_vblank =
41236 @@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41237 dev_priv->last_vblank = cur_vblank;
41238 dev_priv->last_vblank_valid = 1;
41239 }
41240 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
41241 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
41242 DRM_DEBUG("US per vblank is: %u\n",
41243 dev_priv->usec_per_vblank);
41244 }
41245 @@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(int irq, void *arg)
41246
41247 for (i = 0; i < dev_priv->num_irqs; ++i) {
41248 if (status & cur_irq->pending_mask) {
41249 - atomic_inc(&cur_irq->irq_received);
41250 + atomic_inc_unchecked(&cur_irq->irq_received);
41251 wake_up(&cur_irq->irq_queue);
41252 handled = 1;
41253 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
41254 @@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
41255 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41256 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
41257 masks[irq][4]));
41258 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
41259 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
41260 } else {
41261 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * HZ,
41262 (((cur_irq_sequence =
41263 - atomic_read(&cur_irq->irq_received)) -
41264 + atomic_read_unchecked(&cur_irq->irq_received)) -
41265 *sequence) <= (1 << 23)));
41266 }
41267 *sequence = cur_irq_sequence;
41268 @@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
41269 }
41270
41271 for (i = 0; i < dev_priv->num_irqs; ++i) {
41272 - atomic_set(&cur_irq->irq_received, 0);
41273 + atomic_set_unchecked(&cur_irq->irq_received, 0);
41274 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
41275 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
41276 init_waitqueue_head(&cur_irq->irq_queue);
41277 @@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
41278 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
41279 case VIA_IRQ_RELATIVE:
41280 irqwait->request.sequence +=
41281 - atomic_read(&cur_irq->irq_received);
41282 + atomic_read_unchecked(&cur_irq->irq_received);
41283 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
41284 case VIA_IRQ_ABSOLUTE:
41285 break;
41286 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41287 index 6b252a8..5975dfe 100644
41288 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41289 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
41290 @@ -437,7 +437,7 @@ struct vmw_private {
41291 * Fencing and IRQs.
41292 */
41293
41294 - atomic_t marker_seq;
41295 + atomic_unchecked_t marker_seq;
41296 wait_queue_head_t fence_queue;
41297 wait_queue_head_t fifo_queue;
41298 int fence_queue_waiters; /* Protected by hw_mutex */
41299 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41300 index 6ccd993..618d592 100644
41301 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41302 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
41303 @@ -154,7 +154,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
41304 (unsigned int) min,
41305 (unsigned int) fifo->capabilities);
41306
41307 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41308 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
41309 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
41310 vmw_marker_queue_init(&fifo->marker_queue);
41311 return vmw_fifo_send_fence(dev_priv, &dummy);
41312 @@ -372,7 +372,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
41313 if (reserveable)
41314 iowrite32(bytes, fifo_mem +
41315 SVGA_FIFO_RESERVED);
41316 - return fifo_mem + (next_cmd >> 2);
41317 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
41318 } else {
41319 need_bounce = true;
41320 }
41321 @@ -492,7 +492,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41322
41323 fm = vmw_fifo_reserve(dev_priv, bytes);
41324 if (unlikely(fm == NULL)) {
41325 - *seqno = atomic_read(&dev_priv->marker_seq);
41326 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41327 ret = -ENOMEM;
41328 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
41329 false, 3*HZ);
41330 @@ -500,7 +500,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
41331 }
41332
41333 do {
41334 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
41335 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
41336 } while (*seqno == 0);
41337
41338 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
41339 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41340 index b1273e8..9c274fd 100644
41341 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41342 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
41343 @@ -164,9 +164,9 @@ static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
41344 }
41345
41346 const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
41347 - vmw_gmrid_man_init,
41348 - vmw_gmrid_man_takedown,
41349 - vmw_gmrid_man_get_node,
41350 - vmw_gmrid_man_put_node,
41351 - vmw_gmrid_man_debug
41352 + .init = vmw_gmrid_man_init,
41353 + .takedown = vmw_gmrid_man_takedown,
41354 + .get_node = vmw_gmrid_man_get_node,
41355 + .put_node = vmw_gmrid_man_put_node,
41356 + .debug = vmw_gmrid_man_debug
41357 };
41358 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41359 index 37881ec..319065d 100644
41360 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41361 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
41362 @@ -235,7 +235,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
41363 int ret;
41364
41365 num_clips = arg->num_clips;
41366 - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41367 + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41368
41369 if (unlikely(num_clips == 0))
41370 return 0;
41371 @@ -318,7 +318,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
41372 int ret;
41373
41374 num_clips = arg->num_clips;
41375 - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
41376 + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
41377
41378 if (unlikely(num_clips == 0))
41379 return 0;
41380 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41381 index 0c42376..6febe77 100644
41382 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41383 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
41384 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
41385 * emitted. Then the fence is stale and signaled.
41386 */
41387
41388 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
41389 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
41390 > VMW_FENCE_WRAP);
41391
41392 return ret;
41393 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
41394
41395 if (fifo_idle)
41396 down_read(&fifo_state->rwsem);
41397 - signal_seq = atomic_read(&dev_priv->marker_seq);
41398 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
41399 ret = 0;
41400
41401 for (;;) {
41402 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41403 index 8a8725c2..afed796 100644
41404 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41405 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
41406 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
41407 while (!vmw_lag_lt(queue, us)) {
41408 spin_lock(&queue->lock);
41409 if (list_empty(&queue->head))
41410 - seqno = atomic_read(&dev_priv->marker_seq);
41411 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
41412 else {
41413 marker = list_first_entry(&queue->head,
41414 struct vmw_marker, head);
41415 diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
41416 index 6866448..2ad2b34 100644
41417 --- a/drivers/gpu/vga/vga_switcheroo.c
41418 +++ b/drivers/gpu/vga/vga_switcheroo.c
41419 @@ -644,7 +644,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
41420
41421 /* this version is for the case where the power switch is separate
41422 to the device being powered down. */
41423 -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
41424 +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain)
41425 {
41426 /* copy over all the bus versions */
41427 if (dev->bus && dev->bus->pm) {
41428 @@ -689,7 +689,7 @@ static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
41429 return ret;
41430 }
41431
41432 -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
41433 +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain)
41434 {
41435 /* copy over all the bus versions */
41436 if (dev->bus && dev->bus->pm) {
41437 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
41438 index a5c7927..025a2b4 100644
41439 --- a/drivers/hid/hid-core.c
41440 +++ b/drivers/hid/hid-core.c
41441 @@ -2476,7 +2476,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
41442
41443 int hid_add_device(struct hid_device *hdev)
41444 {
41445 - static atomic_t id = ATOMIC_INIT(0);
41446 + static atomic_unchecked_t id = ATOMIC_INIT(0);
41447 int ret;
41448
41449 if (WARN_ON(hdev->status & HID_STAT_ADDED))
41450 @@ -2518,7 +2518,7 @@ int hid_add_device(struct hid_device *hdev)
41451 /* XXX hack, any other cleaner solution after the driver core
41452 * is converted to allow more than 20 bytes as the device name? */
41453 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
41454 - hdev->vendor, hdev->product, atomic_inc_return(&id));
41455 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
41456
41457 hid_debug_register(hdev, dev_name(&hdev->dev));
41458 ret = device_add(&hdev->dev);
41459 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
41460 index c13fb5b..55a3802 100644
41461 --- a/drivers/hid/hid-wiimote-debug.c
41462 +++ b/drivers/hid/hid-wiimote-debug.c
41463 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
41464 else if (size == 0)
41465 return -EIO;
41466
41467 - if (copy_to_user(u, buf, size))
41468 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
41469 return -EFAULT;
41470
41471 *off += size;
41472 diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
41473 index 0d078c3..cd0962c 100644
41474 --- a/drivers/hid/uhid.c
41475 +++ b/drivers/hid/uhid.c
41476 @@ -47,7 +47,7 @@ struct uhid_device {
41477 struct mutex report_lock;
41478 wait_queue_head_t report_wait;
41479 atomic_t report_done;
41480 - atomic_t report_id;
41481 + atomic_unchecked_t report_id;
41482 struct uhid_event report_buf;
41483 };
41484
41485 @@ -163,7 +163,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
41486
41487 spin_lock_irqsave(&uhid->qlock, flags);
41488 ev->type = UHID_FEATURE;
41489 - ev->u.feature.id = atomic_inc_return(&uhid->report_id);
41490 + ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
41491 ev->u.feature.rnum = rnum;
41492 ev->u.feature.rtype = report_type;
41493
41494 @@ -539,7 +539,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
41495 spin_lock_irqsave(&uhid->qlock, flags);
41496
41497 /* id for old report; drop it silently */
41498 - if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
41499 + if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
41500 goto unlock;
41501 if (atomic_read(&uhid->report_done))
41502 goto unlock;
41503 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
41504 index 602ca86..10a6573 100644
41505 --- a/drivers/hv/channel.c
41506 +++ b/drivers/hv/channel.c
41507 @@ -365,8 +365,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
41508 int ret = 0;
41509 int t;
41510
41511 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
41512 - atomic_inc(&vmbus_connection.next_gpadl_handle);
41513 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
41514 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
41515
41516 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
41517 if (ret)
41518 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
41519 index bcb4950..61dba6c 100644
41520 --- a/drivers/hv/hv.c
41521 +++ b/drivers/hv/hv.c
41522 @@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
41523 u64 output_address = (output) ? virt_to_phys(output) : 0;
41524 u32 output_address_hi = output_address >> 32;
41525 u32 output_address_lo = output_address & 0xFFFFFFFF;
41526 - void *hypercall_page = hv_context.hypercall_page;
41527 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
41528
41529 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
41530 "=a"(hv_status_lo) : "d" (control_hi),
41531 @@ -154,7 +154,7 @@ int hv_init(void)
41532 /* See if the hypercall page is already set */
41533 rdmsrl(HV_X64_MSR_HYPERCALL, hypercall_msr.as_uint64);
41534
41535 - virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_EXEC);
41536 + virtaddr = __vmalloc(PAGE_SIZE, GFP_KERNEL, PAGE_KERNEL_RX);
41537
41538 if (!virtaddr)
41539 goto cleanup;
41540 diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
41541 index 5e90c5d..d8fcefb 100644
41542 --- a/drivers/hv/hv_balloon.c
41543 +++ b/drivers/hv/hv_balloon.c
41544 @@ -470,7 +470,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
41545
41546 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
41547 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
41548 -static atomic_t trans_id = ATOMIC_INIT(0);
41549 +static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
41550
41551 static int dm_ring_size = (5 * PAGE_SIZE);
41552
41553 @@ -893,7 +893,7 @@ static void hot_add_req(struct work_struct *dummy)
41554 pr_info("Memory hot add failed\n");
41555
41556 dm->state = DM_INITIALIZED;
41557 - resp.hdr.trans_id = atomic_inc_return(&trans_id);
41558 + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41559 vmbus_sendpacket(dm->dev->channel, &resp,
41560 sizeof(struct dm_hot_add_response),
41561 (unsigned long)NULL,
41562 @@ -973,7 +973,7 @@ static void post_status(struct hv_dynmem_device *dm)
41563 memset(&status, 0, sizeof(struct dm_status));
41564 status.hdr.type = DM_STATUS_REPORT;
41565 status.hdr.size = sizeof(struct dm_status);
41566 - status.hdr.trans_id = atomic_inc_return(&trans_id);
41567 + status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41568
41569 /*
41570 * The host expects the guest to report free memory.
41571 @@ -993,7 +993,7 @@ static void post_status(struct hv_dynmem_device *dm)
41572 * send the status. This can happen if we were interrupted
41573 * after we picked our transaction ID.
41574 */
41575 - if (status.hdr.trans_id != atomic_read(&trans_id))
41576 + if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
41577 return;
41578
41579 /*
41580 @@ -1129,7 +1129,7 @@ static void balloon_up(struct work_struct *dummy)
41581 */
41582
41583 do {
41584 - bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
41585 + bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41586 ret = vmbus_sendpacket(dm_device.dev->channel,
41587 bl_resp,
41588 bl_resp->hdr.size,
41589 @@ -1175,7 +1175,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
41590
41591 memset(&resp, 0, sizeof(struct dm_unballoon_response));
41592 resp.hdr.type = DM_UNBALLOON_RESPONSE;
41593 - resp.hdr.trans_id = atomic_inc_return(&trans_id);
41594 + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41595 resp.hdr.size = sizeof(struct dm_unballoon_response);
41596
41597 vmbus_sendpacket(dm_device.dev->channel, &resp,
41598 @@ -1239,7 +1239,7 @@ static void version_resp(struct hv_dynmem_device *dm,
41599 memset(&version_req, 0, sizeof(struct dm_version_request));
41600 version_req.hdr.type = DM_VERSION_REQUEST;
41601 version_req.hdr.size = sizeof(struct dm_version_request);
41602 - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
41603 + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41604 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
41605 version_req.is_last_attempt = 1;
41606
41607 @@ -1409,7 +1409,7 @@ static int balloon_probe(struct hv_device *dev,
41608 memset(&version_req, 0, sizeof(struct dm_version_request));
41609 version_req.hdr.type = DM_VERSION_REQUEST;
41610 version_req.hdr.size = sizeof(struct dm_version_request);
41611 - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
41612 + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41613 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
41614 version_req.is_last_attempt = 0;
41615
41616 @@ -1440,7 +1440,7 @@ static int balloon_probe(struct hv_device *dev,
41617 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
41618 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
41619 cap_msg.hdr.size = sizeof(struct dm_capabilities);
41620 - cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
41621 + cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
41622
41623 cap_msg.caps.cap_bits.balloon = 1;
41624 cap_msg.caps.cap_bits.hot_add = 1;
41625 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
41626 index 860134d..ea3a79a 100644
41627 --- a/drivers/hv/hyperv_vmbus.h
41628 +++ b/drivers/hv/hyperv_vmbus.h
41629 @@ -602,7 +602,7 @@ enum vmbus_connect_state {
41630 struct vmbus_connection {
41631 enum vmbus_connect_state conn_state;
41632
41633 - atomic_t next_gpadl_handle;
41634 + atomic_unchecked_t next_gpadl_handle;
41635
41636 /*
41637 * Represents channel interrupts. Each bit position represents a
41638 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
41639 index 8e53a3c..7a64e44 100644
41640 --- a/drivers/hv/vmbus_drv.c
41641 +++ b/drivers/hv/vmbus_drv.c
41642 @@ -807,10 +807,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
41643 {
41644 int ret = 0;
41645
41646 - static atomic_t device_num = ATOMIC_INIT(0);
41647 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
41648
41649 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
41650 - atomic_inc_return(&device_num));
41651 + atomic_inc_return_unchecked(&device_num));
41652
41653 child_device_obj->device.bus = &hv_bus;
41654 child_device_obj->device.parent = &hv_acpi_dev->dev;
41655 diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
41656 index 579bdf9..75118b5 100644
41657 --- a/drivers/hwmon/acpi_power_meter.c
41658 +++ b/drivers/hwmon/acpi_power_meter.c
41659 @@ -116,7 +116,7 @@ struct sensor_template {
41660 struct device_attribute *devattr,
41661 const char *buf, size_t count);
41662 int index;
41663 -};
41664 +} __do_const;
41665
41666 /* Averaging interval */
41667 static int update_avg_interval(struct acpi_power_meter_resource *resource)
41668 @@ -631,7 +631,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
41669 struct sensor_template *attrs)
41670 {
41671 struct device *dev = &resource->acpi_dev->dev;
41672 - struct sensor_device_attribute *sensors =
41673 + sensor_device_attribute_no_const *sensors =
41674 &resource->sensors[resource->num_sensors];
41675 int res = 0;
41676
41677 diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
41678 index 3288f13..71cfb4e 100644
41679 --- a/drivers/hwmon/applesmc.c
41680 +++ b/drivers/hwmon/applesmc.c
41681 @@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
41682 {
41683 struct applesmc_node_group *grp;
41684 struct applesmc_dev_attr *node;
41685 - struct attribute *attr;
41686 + attribute_no_const *attr;
41687 int ret, i;
41688
41689 for (grp = groups; grp->format; grp++) {
41690 diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
41691 index ae208f6..48b6c5b 100644
41692 --- a/drivers/hwmon/asus_atk0110.c
41693 +++ b/drivers/hwmon/asus_atk0110.c
41694 @@ -147,10 +147,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
41695 struct atk_sensor_data {
41696 struct list_head list;
41697 struct atk_data *data;
41698 - struct device_attribute label_attr;
41699 - struct device_attribute input_attr;
41700 - struct device_attribute limit1_attr;
41701 - struct device_attribute limit2_attr;
41702 + device_attribute_no_const label_attr;
41703 + device_attribute_no_const input_attr;
41704 + device_attribute_no_const limit1_attr;
41705 + device_attribute_no_const limit2_attr;
41706 char label_attr_name[ATTR_NAME_SIZE];
41707 char input_attr_name[ATTR_NAME_SIZE];
41708 char limit1_attr_name[ATTR_NAME_SIZE];
41709 @@ -270,7 +270,7 @@ static ssize_t atk_name_show(struct device *dev,
41710 static struct device_attribute atk_name_attr =
41711 __ATTR(name, 0444, atk_name_show, NULL);
41712
41713 -static void atk_init_attribute(struct device_attribute *attr, char *name,
41714 +static void atk_init_attribute(device_attribute_no_const *attr, char *name,
41715 sysfs_show_func show)
41716 {
41717 sysfs_attr_init(&attr->attr);
41718 diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
41719 index d76f0b7..55ae976 100644
41720 --- a/drivers/hwmon/coretemp.c
41721 +++ b/drivers/hwmon/coretemp.c
41722 @@ -784,7 +784,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
41723 return NOTIFY_OK;
41724 }
41725
41726 -static struct notifier_block coretemp_cpu_notifier __refdata = {
41727 +static struct notifier_block coretemp_cpu_notifier = {
41728 .notifier_call = coretemp_cpu_callback,
41729 };
41730
41731 diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
41732 index 632f1dc..57e6a58 100644
41733 --- a/drivers/hwmon/ibmaem.c
41734 +++ b/drivers/hwmon/ibmaem.c
41735 @@ -926,7 +926,7 @@ static int aem_register_sensors(struct aem_data *data,
41736 struct aem_rw_sensor_template *rw)
41737 {
41738 struct device *dev = &data->pdev->dev;
41739 - struct sensor_device_attribute *sensors = data->sensors;
41740 + sensor_device_attribute_no_const *sensors = data->sensors;
41741 int err;
41742
41743 /* Set up read-only sensors */
41744 diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
41745 index 9fbb1b1..efbaa3e 100644
41746 --- a/drivers/hwmon/iio_hwmon.c
41747 +++ b/drivers/hwmon/iio_hwmon.c
41748 @@ -61,7 +61,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
41749 {
41750 struct device *dev = &pdev->dev;
41751 struct iio_hwmon_state *st;
41752 - struct sensor_device_attribute *a;
41753 + sensor_device_attribute_no_const *a;
41754 int ret, i;
41755 int in_i = 1, temp_i = 1, curr_i = 1;
41756 enum iio_chan_type type;
41757 diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
41758 index 38d5a63..cf2c2ea 100644
41759 --- a/drivers/hwmon/nct6775.c
41760 +++ b/drivers/hwmon/nct6775.c
41761 @@ -944,10 +944,10 @@ static struct attribute_group *
41762 nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
41763 int repeat)
41764 {
41765 - struct attribute_group *group;
41766 + attribute_group_no_const *group;
41767 struct sensor_device_attr_u *su;
41768 - struct sensor_device_attribute *a;
41769 - struct sensor_device_attribute_2 *a2;
41770 + sensor_device_attribute_no_const *a;
41771 + sensor_device_attribute_2_no_const *a2;
41772 struct attribute **attrs;
41773 struct sensor_device_template **t;
41774 int i, count;
41775 diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
41776 index 291d11f..3f0dbbd 100644
41777 --- a/drivers/hwmon/pmbus/pmbus_core.c
41778 +++ b/drivers/hwmon/pmbus/pmbus_core.c
41779 @@ -783,7 +783,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
41780 return 0;
41781 }
41782
41783 -static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
41784 +static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
41785 const char *name,
41786 umode_t mode,
41787 ssize_t (*show)(struct device *dev,
41788 @@ -800,7 +800,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
41789 dev_attr->store = store;
41790 }
41791
41792 -static void pmbus_attr_init(struct sensor_device_attribute *a,
41793 +static void pmbus_attr_init(sensor_device_attribute_no_const *a,
41794 const char *name,
41795 umode_t mode,
41796 ssize_t (*show)(struct device *dev,
41797 @@ -822,7 +822,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
41798 u16 reg, u8 mask)
41799 {
41800 struct pmbus_boolean *boolean;
41801 - struct sensor_device_attribute *a;
41802 + sensor_device_attribute_no_const *a;
41803
41804 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
41805 if (!boolean)
41806 @@ -847,7 +847,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
41807 bool update, bool readonly)
41808 {
41809 struct pmbus_sensor *sensor;
41810 - struct device_attribute *a;
41811 + device_attribute_no_const *a;
41812
41813 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
41814 if (!sensor)
41815 @@ -878,7 +878,7 @@ static int pmbus_add_label(struct pmbus_data *data,
41816 const char *lstring, int index)
41817 {
41818 struct pmbus_label *label;
41819 - struct device_attribute *a;
41820 + device_attribute_no_const *a;
41821
41822 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
41823 if (!label)
41824 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
41825 index 97cd45a..ac54d8b 100644
41826 --- a/drivers/hwmon/sht15.c
41827 +++ b/drivers/hwmon/sht15.c
41828 @@ -169,7 +169,7 @@ struct sht15_data {
41829 int supply_uv;
41830 bool supply_uv_valid;
41831 struct work_struct update_supply_work;
41832 - atomic_t interrupt_handled;
41833 + atomic_unchecked_t interrupt_handled;
41834 };
41835
41836 /**
41837 @@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
41838 ret = gpio_direction_input(data->pdata->gpio_data);
41839 if (ret)
41840 return ret;
41841 - atomic_set(&data->interrupt_handled, 0);
41842 + atomic_set_unchecked(&data->interrupt_handled, 0);
41843
41844 enable_irq(gpio_to_irq(data->pdata->gpio_data));
41845 if (gpio_get_value(data->pdata->gpio_data) == 0) {
41846 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
41847 /* Only relevant if the interrupt hasn't occurred. */
41848 - if (!atomic_read(&data->interrupt_handled))
41849 + if (!atomic_read_unchecked(&data->interrupt_handled))
41850 schedule_work(&data->read_work);
41851 }
41852 ret = wait_event_timeout(data->wait_queue,
41853 @@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
41854
41855 /* First disable the interrupt */
41856 disable_irq_nosync(irq);
41857 - atomic_inc(&data->interrupt_handled);
41858 + atomic_inc_unchecked(&data->interrupt_handled);
41859 /* Then schedule a reading work struct */
41860 if (data->state != SHT15_READING_NOTHING)
41861 schedule_work(&data->read_work);
41862 @@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
41863 * If not, then start the interrupt again - care here as could
41864 * have gone low in meantime so verify it hasn't!
41865 */
41866 - atomic_set(&data->interrupt_handled, 0);
41867 + atomic_set_unchecked(&data->interrupt_handled, 0);
41868 enable_irq(gpio_to_irq(data->pdata->gpio_data));
41869 /* If still not occurred or another handler was scheduled */
41870 if (gpio_get_value(data->pdata->gpio_data)
41871 - || atomic_read(&data->interrupt_handled))
41872 + || atomic_read_unchecked(&data->interrupt_handled))
41873 return;
41874 }
41875
41876 diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
41877 index 8df43c5..b07b91d 100644
41878 --- a/drivers/hwmon/via-cputemp.c
41879 +++ b/drivers/hwmon/via-cputemp.c
41880 @@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
41881 return NOTIFY_OK;
41882 }
41883
41884 -static struct notifier_block via_cputemp_cpu_notifier __refdata = {
41885 +static struct notifier_block via_cputemp_cpu_notifier = {
41886 .notifier_call = via_cputemp_cpu_callback,
41887 };
41888
41889 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
41890 index 41fc683..a39cfea 100644
41891 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
41892 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
41893 @@ -43,7 +43,7 @@
41894 extern struct i2c_adapter amd756_smbus;
41895
41896 static struct i2c_adapter *s4882_adapter;
41897 -static struct i2c_algorithm *s4882_algo;
41898 +static i2c_algorithm_no_const *s4882_algo;
41899
41900 /* Wrapper access functions for multiplexed SMBus */
41901 static DEFINE_MUTEX(amd756_lock);
41902 diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
41903 index 721f7eb..0fd2a09 100644
41904 --- a/drivers/i2c/busses/i2c-diolan-u2c.c
41905 +++ b/drivers/i2c/busses/i2c-diolan-u2c.c
41906 @@ -98,7 +98,7 @@ MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
41907 /* usb layer */
41908
41909 /* Send command to device, and get response. */
41910 -static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
41911 +static int __intentional_overflow(-1) diolan_usb_transfer(struct i2c_diolan_u2c *dev)
41912 {
41913 int ret = 0;
41914 int actual;
41915 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
41916 index b170bdf..3c76427 100644
41917 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
41918 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
41919 @@ -41,7 +41,7 @@
41920 extern struct i2c_adapter *nforce2_smbus;
41921
41922 static struct i2c_adapter *s4985_adapter;
41923 -static struct i2c_algorithm *s4985_algo;
41924 +static i2c_algorithm_no_const *s4985_algo;
41925
41926 /* Wrapper access functions for multiplexed SMBus */
41927 static DEFINE_MUTEX(nforce2_lock);
41928 diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
41929 index 80b47e8..1a6040d9 100644
41930 --- a/drivers/i2c/i2c-dev.c
41931 +++ b/drivers/i2c/i2c-dev.c
41932 @@ -277,7 +277,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
41933 break;
41934 }
41935
41936 - data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
41937 + data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
41938 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
41939 if (IS_ERR(rdwr_pa[i].buf)) {
41940 res = PTR_ERR(rdwr_pa[i].buf);
41941 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
41942 index 0b510ba..4fbb5085 100644
41943 --- a/drivers/ide/ide-cd.c
41944 +++ b/drivers/ide/ide-cd.c
41945 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
41946 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
41947 if ((unsigned long)buf & alignment
41948 || blk_rq_bytes(rq) & q->dma_pad_mask
41949 - || object_is_on_stack(buf))
41950 + || object_starts_on_stack(buf))
41951 drive->dma = 0;
41952 }
41953 }
41954 diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
41955 index ede16aec..e423e8a 100644
41956 --- a/drivers/iio/industrialio-core.c
41957 +++ b/drivers/iio/industrialio-core.c
41958 @@ -527,7 +527,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
41959 }
41960
41961 static
41962 -int __iio_device_attr_init(struct device_attribute *dev_attr,
41963 +int __iio_device_attr_init(device_attribute_no_const *dev_attr,
41964 const char *postfix,
41965 struct iio_chan_spec const *chan,
41966 ssize_t (*readfunc)(struct device *dev,
41967 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
41968 index c323917..6ddea8b 100644
41969 --- a/drivers/infiniband/core/cm.c
41970 +++ b/drivers/infiniband/core/cm.c
41971 @@ -115,7 +115,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
41972
41973 struct cm_counter_group {
41974 struct kobject obj;
41975 - atomic_long_t counter[CM_ATTR_COUNT];
41976 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
41977 };
41978
41979 struct cm_counter_attribute {
41980 @@ -1398,7 +1398,7 @@ static void cm_dup_req_handler(struct cm_work *work,
41981 struct ib_mad_send_buf *msg = NULL;
41982 int ret;
41983
41984 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41985 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41986 counter[CM_REQ_COUNTER]);
41987
41988 /* Quick state check to discard duplicate REQs. */
41989 @@ -1785,7 +1785,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
41990 if (!cm_id_priv)
41991 return;
41992
41993 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41994 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41995 counter[CM_REP_COUNTER]);
41996 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
41997 if (ret)
41998 @@ -1952,7 +1952,7 @@ static int cm_rtu_handler(struct cm_work *work)
41999 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
42000 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
42001 spin_unlock_irq(&cm_id_priv->lock);
42002 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42003 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42004 counter[CM_RTU_COUNTER]);
42005 goto out;
42006 }
42007 @@ -2135,7 +2135,7 @@ static int cm_dreq_handler(struct cm_work *work)
42008 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
42009 dreq_msg->local_comm_id);
42010 if (!cm_id_priv) {
42011 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42012 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42013 counter[CM_DREQ_COUNTER]);
42014 cm_issue_drep(work->port, work->mad_recv_wc);
42015 return -EINVAL;
42016 @@ -2160,7 +2160,7 @@ static int cm_dreq_handler(struct cm_work *work)
42017 case IB_CM_MRA_REP_RCVD:
42018 break;
42019 case IB_CM_TIMEWAIT:
42020 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42021 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42022 counter[CM_DREQ_COUNTER]);
42023 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
42024 goto unlock;
42025 @@ -2174,7 +2174,7 @@ static int cm_dreq_handler(struct cm_work *work)
42026 cm_free_msg(msg);
42027 goto deref;
42028 case IB_CM_DREQ_RCVD:
42029 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42030 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42031 counter[CM_DREQ_COUNTER]);
42032 goto unlock;
42033 default:
42034 @@ -2541,7 +2541,7 @@ static int cm_mra_handler(struct cm_work *work)
42035 ib_modify_mad(cm_id_priv->av.port->mad_agent,
42036 cm_id_priv->msg, timeout)) {
42037 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
42038 - atomic_long_inc(&work->port->
42039 + atomic_long_inc_unchecked(&work->port->
42040 counter_group[CM_RECV_DUPLICATES].
42041 counter[CM_MRA_COUNTER]);
42042 goto out;
42043 @@ -2550,7 +2550,7 @@ static int cm_mra_handler(struct cm_work *work)
42044 break;
42045 case IB_CM_MRA_REQ_RCVD:
42046 case IB_CM_MRA_REP_RCVD:
42047 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42048 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42049 counter[CM_MRA_COUNTER]);
42050 /* fall through */
42051 default:
42052 @@ -2712,7 +2712,7 @@ static int cm_lap_handler(struct cm_work *work)
42053 case IB_CM_LAP_IDLE:
42054 break;
42055 case IB_CM_MRA_LAP_SENT:
42056 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42057 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42058 counter[CM_LAP_COUNTER]);
42059 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
42060 goto unlock;
42061 @@ -2728,7 +2728,7 @@ static int cm_lap_handler(struct cm_work *work)
42062 cm_free_msg(msg);
42063 goto deref;
42064 case IB_CM_LAP_RCVD:
42065 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42066 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42067 counter[CM_LAP_COUNTER]);
42068 goto unlock;
42069 default:
42070 @@ -3012,7 +3012,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
42071 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
42072 if (cur_cm_id_priv) {
42073 spin_unlock_irq(&cm.lock);
42074 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
42075 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
42076 counter[CM_SIDR_REQ_COUNTER]);
42077 goto out; /* Duplicate message. */
42078 }
42079 @@ -3224,10 +3224,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
42080 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
42081 msg->retries = 1;
42082
42083 - atomic_long_add(1 + msg->retries,
42084 + atomic_long_add_unchecked(1 + msg->retries,
42085 &port->counter_group[CM_XMIT].counter[attr_index]);
42086 if (msg->retries)
42087 - atomic_long_add(msg->retries,
42088 + atomic_long_add_unchecked(msg->retries,
42089 &port->counter_group[CM_XMIT_RETRIES].
42090 counter[attr_index]);
42091
42092 @@ -3437,7 +3437,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
42093 }
42094
42095 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
42096 - atomic_long_inc(&port->counter_group[CM_RECV].
42097 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
42098 counter[attr_id - CM_ATTR_ID_OFFSET]);
42099
42100 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
42101 @@ -3668,7 +3668,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
42102 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
42103
42104 return sprintf(buf, "%ld\n",
42105 - atomic_long_read(&group->counter[cm_attr->index]));
42106 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
42107 }
42108
42109 static const struct sysfs_ops cm_counter_ops = {
42110 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
42111 index 9f5ad7c..588cd84 100644
42112 --- a/drivers/infiniband/core/fmr_pool.c
42113 +++ b/drivers/infiniband/core/fmr_pool.c
42114 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
42115
42116 struct task_struct *thread;
42117
42118 - atomic_t req_ser;
42119 - atomic_t flush_ser;
42120 + atomic_unchecked_t req_ser;
42121 + atomic_unchecked_t flush_ser;
42122
42123 wait_queue_head_t force_wait;
42124 };
42125 @@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42126 struct ib_fmr_pool *pool = pool_ptr;
42127
42128 do {
42129 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
42130 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
42131 ib_fmr_batch_release(pool);
42132
42133 - atomic_inc(&pool->flush_ser);
42134 + atomic_inc_unchecked(&pool->flush_ser);
42135 wake_up_interruptible(&pool->force_wait);
42136
42137 if (pool->flush_function)
42138 @@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
42139 }
42140
42141 set_current_state(TASK_INTERRUPTIBLE);
42142 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
42143 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
42144 !kthread_should_stop())
42145 schedule();
42146 __set_current_state(TASK_RUNNING);
42147 @@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
42148 pool->dirty_watermark = params->dirty_watermark;
42149 pool->dirty_len = 0;
42150 spin_lock_init(&pool->pool_lock);
42151 - atomic_set(&pool->req_ser, 0);
42152 - atomic_set(&pool->flush_ser, 0);
42153 + atomic_set_unchecked(&pool->req_ser, 0);
42154 + atomic_set_unchecked(&pool->flush_ser, 0);
42155 init_waitqueue_head(&pool->force_wait);
42156
42157 pool->thread = kthread_run(ib_fmr_cleanup_thread,
42158 @@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
42159 }
42160 spin_unlock_irq(&pool->pool_lock);
42161
42162 - serial = atomic_inc_return(&pool->req_ser);
42163 + serial = atomic_inc_return_unchecked(&pool->req_ser);
42164 wake_up_process(pool->thread);
42165
42166 if (wait_event_interruptible(pool->force_wait,
42167 - atomic_read(&pool->flush_ser) - serial >= 0))
42168 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
42169 return -EINTR;
42170
42171 return 0;
42172 @@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
42173 } else {
42174 list_add_tail(&fmr->list, &pool->dirty_list);
42175 if (++pool->dirty_len >= pool->dirty_watermark) {
42176 - atomic_inc(&pool->req_ser);
42177 + atomic_inc_unchecked(&pool->req_ser);
42178 wake_up_process(pool->thread);
42179 }
42180 }
42181 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
42182 index ec7a298..8742e59 100644
42183 --- a/drivers/infiniband/hw/cxgb4/mem.c
42184 +++ b/drivers/infiniband/hw/cxgb4/mem.c
42185 @@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42186 int err;
42187 struct fw_ri_tpte tpt;
42188 u32 stag_idx;
42189 - static atomic_t key;
42190 + static atomic_unchecked_t key;
42191
42192 if (c4iw_fatal_error(rdev))
42193 return -EIO;
42194 @@ -270,7 +270,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
42195 if (rdev->stats.stag.cur > rdev->stats.stag.max)
42196 rdev->stats.stag.max = rdev->stats.stag.cur;
42197 mutex_unlock(&rdev->stats.lock);
42198 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
42199 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
42200 }
42201 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
42202 __func__, stag_state, type, pdid, stag_idx);
42203 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
42204 index 79b3dbc..96e5fcc 100644
42205 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
42206 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
42207 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42208 struct ib_atomic_eth *ateth;
42209 struct ipath_ack_entry *e;
42210 u64 vaddr;
42211 - atomic64_t *maddr;
42212 + atomic64_unchecked_t *maddr;
42213 u64 sdata;
42214 u32 rkey;
42215 u8 next;
42216 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
42217 IB_ACCESS_REMOTE_ATOMIC)))
42218 goto nack_acc_unlck;
42219 /* Perform atomic OP and save result. */
42220 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42221 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42222 sdata = be64_to_cpu(ateth->swap_data);
42223 e = &qp->s_ack_queue[qp->r_head_ack_queue];
42224 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
42225 - (u64) atomic64_add_return(sdata, maddr) - sdata :
42226 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42227 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42228 be64_to_cpu(ateth->compare_data),
42229 sdata);
42230 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
42231 index 1f95bba..9530f87 100644
42232 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
42233 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
42234 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
42235 unsigned long flags;
42236 struct ib_wc wc;
42237 u64 sdata;
42238 - atomic64_t *maddr;
42239 + atomic64_unchecked_t *maddr;
42240 enum ib_wc_status send_status;
42241
42242 /*
42243 @@ -382,11 +382,11 @@ again:
42244 IB_ACCESS_REMOTE_ATOMIC)))
42245 goto acc_err;
42246 /* Perform atomic OP and save result. */
42247 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
42248 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
42249 sdata = wqe->wr.wr.atomic.compare_add;
42250 *(u64 *) sqp->s_sge.sge.vaddr =
42251 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
42252 - (u64) atomic64_add_return(sdata, maddr) - sdata :
42253 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
42254 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
42255 sdata, wqe->wr.wr.atomic.swap);
42256 goto send_comp;
42257 diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
42258 index fd36ec6..a6a082f 100644
42259 --- a/drivers/infiniband/hw/mlx4/mad.c
42260 +++ b/drivers/infiniband/hw/mlx4/mad.c
42261 @@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
42262
42263 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
42264 {
42265 - return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
42266 + return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
42267 cpu_to_be64(0xff00000000000000LL);
42268 }
42269
42270 diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
42271 index ed327e6..ca1739e0 100644
42272 --- a/drivers/infiniband/hw/mlx4/mcg.c
42273 +++ b/drivers/infiniband/hw/mlx4/mcg.c
42274 @@ -1041,7 +1041,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
42275 {
42276 char name[20];
42277
42278 - atomic_set(&ctx->tid, 0);
42279 + atomic_set_unchecked(&ctx->tid, 0);
42280 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
42281 ctx->mcg_wq = create_singlethread_workqueue(name);
42282 if (!ctx->mcg_wq)
42283 diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42284 index 66b0b7d..f14836a 100644
42285 --- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
42286 +++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
42287 @@ -425,7 +425,7 @@ struct mlx4_ib_demux_ctx {
42288 struct list_head mcg_mgid0_list;
42289 struct workqueue_struct *mcg_wq;
42290 struct mlx4_ib_demux_pv_ctx **tun;
42291 - atomic_t tid;
42292 + atomic_unchecked_t tid;
42293 int flushing; /* flushing the work queue */
42294 };
42295
42296 diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
42297 index 9d3e5c1..6f166df 100644
42298 --- a/drivers/infiniband/hw/mthca/mthca_cmd.c
42299 +++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
42300 @@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
42301 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
42302 }
42303
42304 -int mthca_QUERY_FW(struct mthca_dev *dev)
42305 +int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
42306 {
42307 struct mthca_mailbox *mailbox;
42308 u32 *outbox;
42309 @@ -1612,7 +1612,7 @@ int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42310 CMD_TIME_CLASS_B);
42311 }
42312
42313 -int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42314 +int __intentional_overflow(-1) mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42315 int num_mtt)
42316 {
42317 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
42318 @@ -1634,7 +1634,7 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
42319 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
42320 }
42321
42322 -int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42323 +int __intentional_overflow(-1) mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
42324 int eq_num)
42325 {
42326 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
42327 @@ -1857,7 +1857,7 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
42328 CMD_TIME_CLASS_B);
42329 }
42330
42331 -int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42332 +int __intentional_overflow(-1) mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
42333 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
42334 void *in_mad, void *response_mad)
42335 {
42336 diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
42337 index ded76c1..0cf0a08 100644
42338 --- a/drivers/infiniband/hw/mthca/mthca_main.c
42339 +++ b/drivers/infiniband/hw/mthca/mthca_main.c
42340 @@ -692,7 +692,7 @@ err_close:
42341 return err;
42342 }
42343
42344 -static int mthca_setup_hca(struct mthca_dev *dev)
42345 +static int __intentional_overflow(-1) mthca_setup_hca(struct mthca_dev *dev)
42346 {
42347 int err;
42348
42349 diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
42350 index ed9a989..6aa5dc2 100644
42351 --- a/drivers/infiniband/hw/mthca/mthca_mr.c
42352 +++ b/drivers/infiniband/hw/mthca/mthca_mr.c
42353 @@ -81,7 +81,7 @@ struct mthca_mpt_entry {
42354 * through the bitmaps)
42355 */
42356
42357 -static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42358 +static u32 __intentional_overflow(-1) mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
42359 {
42360 int o;
42361 int m;
42362 @@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
42363 return key;
42364 }
42365
42366 -int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42367 +int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
42368 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
42369 {
42370 struct mthca_mailbox *mailbox;
42371 @@ -516,7 +516,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
42372 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
42373 }
42374
42375 -int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42376 +int __intentional_overflow(-1) mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
42377 u64 *buffer_list, int buffer_size_shift,
42378 int list_len, u64 iova, u64 total_size,
42379 u32 access, struct mthca_mr *mr)
42380 diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
42381 index 415f8e1..e34214e 100644
42382 --- a/drivers/infiniband/hw/mthca/mthca_provider.c
42383 +++ b/drivers/infiniband/hw/mthca/mthca_provider.c
42384 @@ -764,7 +764,7 @@ unlock:
42385 return 0;
42386 }
42387
42388 -static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42389 +static int __intentional_overflow(-1) mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
42390 {
42391 struct mthca_dev *dev = to_mdev(ibcq->device);
42392 struct mthca_cq *cq = to_mcq(ibcq);
42393 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
42394 index 353c7b0..c6ce921 100644
42395 --- a/drivers/infiniband/hw/nes/nes.c
42396 +++ b/drivers/infiniband/hw/nes/nes.c
42397 @@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
42398 LIST_HEAD(nes_adapter_list);
42399 static LIST_HEAD(nes_dev_list);
42400
42401 -atomic_t qps_destroyed;
42402 +atomic_unchecked_t qps_destroyed;
42403
42404 static unsigned int ee_flsh_adapter;
42405 static unsigned int sysfs_nonidx_addr;
42406 @@ -269,7 +269,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
42407 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
42408 struct nes_adapter *nesadapter = nesdev->nesadapter;
42409
42410 - atomic_inc(&qps_destroyed);
42411 + atomic_inc_unchecked(&qps_destroyed);
42412
42413 /* Free the control structures */
42414
42415 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
42416 index 33cc589..3bd6538 100644
42417 --- a/drivers/infiniband/hw/nes/nes.h
42418 +++ b/drivers/infiniband/hw/nes/nes.h
42419 @@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
42420 extern unsigned int wqm_quanta;
42421 extern struct list_head nes_adapter_list;
42422
42423 -extern atomic_t cm_connects;
42424 -extern atomic_t cm_accepts;
42425 -extern atomic_t cm_disconnects;
42426 -extern atomic_t cm_closes;
42427 -extern atomic_t cm_connecteds;
42428 -extern atomic_t cm_connect_reqs;
42429 -extern atomic_t cm_rejects;
42430 -extern atomic_t mod_qp_timouts;
42431 -extern atomic_t qps_created;
42432 -extern atomic_t qps_destroyed;
42433 -extern atomic_t sw_qps_destroyed;
42434 +extern atomic_unchecked_t cm_connects;
42435 +extern atomic_unchecked_t cm_accepts;
42436 +extern atomic_unchecked_t cm_disconnects;
42437 +extern atomic_unchecked_t cm_closes;
42438 +extern atomic_unchecked_t cm_connecteds;
42439 +extern atomic_unchecked_t cm_connect_reqs;
42440 +extern atomic_unchecked_t cm_rejects;
42441 +extern atomic_unchecked_t mod_qp_timouts;
42442 +extern atomic_unchecked_t qps_created;
42443 +extern atomic_unchecked_t qps_destroyed;
42444 +extern atomic_unchecked_t sw_qps_destroyed;
42445 extern u32 mh_detected;
42446 extern u32 mh_pauses_sent;
42447 extern u32 cm_packets_sent;
42448 @@ -196,16 +196,16 @@ extern u32 cm_packets_created;
42449 extern u32 cm_packets_received;
42450 extern u32 cm_packets_dropped;
42451 extern u32 cm_packets_retrans;
42452 -extern atomic_t cm_listens_created;
42453 -extern atomic_t cm_listens_destroyed;
42454 +extern atomic_unchecked_t cm_listens_created;
42455 +extern atomic_unchecked_t cm_listens_destroyed;
42456 extern u32 cm_backlog_drops;
42457 -extern atomic_t cm_loopbacks;
42458 -extern atomic_t cm_nodes_created;
42459 -extern atomic_t cm_nodes_destroyed;
42460 -extern atomic_t cm_accel_dropped_pkts;
42461 -extern atomic_t cm_resets_recvd;
42462 -extern atomic_t pau_qps_created;
42463 -extern atomic_t pau_qps_destroyed;
42464 +extern atomic_unchecked_t cm_loopbacks;
42465 +extern atomic_unchecked_t cm_nodes_created;
42466 +extern atomic_unchecked_t cm_nodes_destroyed;
42467 +extern atomic_unchecked_t cm_accel_dropped_pkts;
42468 +extern atomic_unchecked_t cm_resets_recvd;
42469 +extern atomic_unchecked_t pau_qps_created;
42470 +extern atomic_unchecked_t pau_qps_destroyed;
42471
42472 extern u32 int_mod_timer_init;
42473 extern u32 int_mod_cq_depth_256;
42474 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
42475 index dfa9df4..6bf7221 100644
42476 --- a/drivers/infiniband/hw/nes/nes_cm.c
42477 +++ b/drivers/infiniband/hw/nes/nes_cm.c
42478 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
42479 u32 cm_packets_retrans;
42480 u32 cm_packets_created;
42481 u32 cm_packets_received;
42482 -atomic_t cm_listens_created;
42483 -atomic_t cm_listens_destroyed;
42484 +atomic_unchecked_t cm_listens_created;
42485 +atomic_unchecked_t cm_listens_destroyed;
42486 u32 cm_backlog_drops;
42487 -atomic_t cm_loopbacks;
42488 -atomic_t cm_nodes_created;
42489 -atomic_t cm_nodes_destroyed;
42490 -atomic_t cm_accel_dropped_pkts;
42491 -atomic_t cm_resets_recvd;
42492 +atomic_unchecked_t cm_loopbacks;
42493 +atomic_unchecked_t cm_nodes_created;
42494 +atomic_unchecked_t cm_nodes_destroyed;
42495 +atomic_unchecked_t cm_accel_dropped_pkts;
42496 +atomic_unchecked_t cm_resets_recvd;
42497
42498 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
42499 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
42500 @@ -134,28 +134,28 @@ static void record_ird_ord(struct nes_cm_node *, u16, u16);
42501 /* instance of function pointers for client API */
42502 /* set address of this instance to cm_core->cm_ops at cm_core alloc */
42503 static struct nes_cm_ops nes_cm_api = {
42504 - mini_cm_accelerated,
42505 - mini_cm_listen,
42506 - mini_cm_del_listen,
42507 - mini_cm_connect,
42508 - mini_cm_close,
42509 - mini_cm_accept,
42510 - mini_cm_reject,
42511 - mini_cm_recv_pkt,
42512 - mini_cm_dealloc_core,
42513 - mini_cm_get,
42514 - mini_cm_set
42515 + .accelerated = mini_cm_accelerated,
42516 + .listen = mini_cm_listen,
42517 + .stop_listener = mini_cm_del_listen,
42518 + .connect = mini_cm_connect,
42519 + .close = mini_cm_close,
42520 + .accept = mini_cm_accept,
42521 + .reject = mini_cm_reject,
42522 + .recv_pkt = mini_cm_recv_pkt,
42523 + .destroy_cm_core = mini_cm_dealloc_core,
42524 + .get = mini_cm_get,
42525 + .set = mini_cm_set
42526 };
42527
42528 static struct nes_cm_core *g_cm_core;
42529
42530 -atomic_t cm_connects;
42531 -atomic_t cm_accepts;
42532 -atomic_t cm_disconnects;
42533 -atomic_t cm_closes;
42534 -atomic_t cm_connecteds;
42535 -atomic_t cm_connect_reqs;
42536 -atomic_t cm_rejects;
42537 +atomic_unchecked_t cm_connects;
42538 +atomic_unchecked_t cm_accepts;
42539 +atomic_unchecked_t cm_disconnects;
42540 +atomic_unchecked_t cm_closes;
42541 +atomic_unchecked_t cm_connecteds;
42542 +atomic_unchecked_t cm_connect_reqs;
42543 +atomic_unchecked_t cm_rejects;
42544
42545 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
42546 {
42547 @@ -1319,7 +1319,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
42548 kfree(listener);
42549 listener = NULL;
42550 ret = 0;
42551 - atomic_inc(&cm_listens_destroyed);
42552 + atomic_inc_unchecked(&cm_listens_destroyed);
42553 } else {
42554 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
42555 }
42556 @@ -1513,7 +1513,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
42557 cm_node->rem_mac);
42558
42559 add_hte_node(cm_core, cm_node);
42560 - atomic_inc(&cm_nodes_created);
42561 + atomic_inc_unchecked(&cm_nodes_created);
42562
42563 return cm_node;
42564 }
42565 @@ -1571,7 +1571,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
42566 }
42567
42568 atomic_dec(&cm_core->node_cnt);
42569 - atomic_inc(&cm_nodes_destroyed);
42570 + atomic_inc_unchecked(&cm_nodes_destroyed);
42571 nesqp = cm_node->nesqp;
42572 if (nesqp) {
42573 nesqp->cm_node = NULL;
42574 @@ -1635,7 +1635,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
42575
42576 static void drop_packet(struct sk_buff *skb)
42577 {
42578 - atomic_inc(&cm_accel_dropped_pkts);
42579 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
42580 dev_kfree_skb_any(skb);
42581 }
42582
42583 @@ -1698,7 +1698,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
42584 {
42585
42586 int reset = 0; /* whether to send reset in case of err.. */
42587 - atomic_inc(&cm_resets_recvd);
42588 + atomic_inc_unchecked(&cm_resets_recvd);
42589 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
42590 " refcnt=%d\n", cm_node, cm_node->state,
42591 atomic_read(&cm_node->ref_count));
42592 @@ -2339,7 +2339,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
42593 rem_ref_cm_node(cm_node->cm_core, cm_node);
42594 return NULL;
42595 }
42596 - atomic_inc(&cm_loopbacks);
42597 + atomic_inc_unchecked(&cm_loopbacks);
42598 loopbackremotenode->loopbackpartner = cm_node;
42599 loopbackremotenode->tcp_cntxt.rcv_wscale =
42600 NES_CM_DEFAULT_RCV_WND_SCALE;
42601 @@ -2614,7 +2614,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
42602 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
42603 else {
42604 rem_ref_cm_node(cm_core, cm_node);
42605 - atomic_inc(&cm_accel_dropped_pkts);
42606 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
42607 dev_kfree_skb_any(skb);
42608 }
42609 break;
42610 @@ -2922,7 +2922,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
42611
42612 if ((cm_id) && (cm_id->event_handler)) {
42613 if (issue_disconn) {
42614 - atomic_inc(&cm_disconnects);
42615 + atomic_inc_unchecked(&cm_disconnects);
42616 cm_event.event = IW_CM_EVENT_DISCONNECT;
42617 cm_event.status = disconn_status;
42618 cm_event.local_addr = cm_id->local_addr;
42619 @@ -2944,7 +2944,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
42620 }
42621
42622 if (issue_close) {
42623 - atomic_inc(&cm_closes);
42624 + atomic_inc_unchecked(&cm_closes);
42625 nes_disconnect(nesqp, 1);
42626
42627 cm_id->provider_data = nesqp;
42628 @@ -3082,7 +3082,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
42629
42630 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
42631 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
42632 - atomic_inc(&cm_accepts);
42633 + atomic_inc_unchecked(&cm_accepts);
42634
42635 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
42636 netdev_refcnt_read(nesvnic->netdev));
42637 @@ -3278,7 +3278,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
42638 struct nes_cm_core *cm_core;
42639 u8 *start_buff;
42640
42641 - atomic_inc(&cm_rejects);
42642 + atomic_inc_unchecked(&cm_rejects);
42643 cm_node = (struct nes_cm_node *)cm_id->provider_data;
42644 loopback = cm_node->loopbackpartner;
42645 cm_core = cm_node->cm_core;
42646 @@ -3340,7 +3340,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
42647 ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
42648 ntohs(laddr->sin_port));
42649
42650 - atomic_inc(&cm_connects);
42651 + atomic_inc_unchecked(&cm_connects);
42652 nesqp->active_conn = 1;
42653
42654 /* cache the cm_id in the qp */
42655 @@ -3451,7 +3451,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
42656 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
42657 return err;
42658 }
42659 - atomic_inc(&cm_listens_created);
42660 + atomic_inc_unchecked(&cm_listens_created);
42661 }
42662
42663 cm_id->add_ref(cm_id);
42664 @@ -3558,7 +3558,7 @@ static void cm_event_connected(struct nes_cm_event *event)
42665
42666 if (nesqp->destroyed)
42667 return;
42668 - atomic_inc(&cm_connecteds);
42669 + atomic_inc_unchecked(&cm_connecteds);
42670 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
42671 " local port 0x%04X. jiffies = %lu.\n",
42672 nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
42673 @@ -3741,7 +3741,7 @@ static void cm_event_reset(struct nes_cm_event *event)
42674
42675 cm_id->add_ref(cm_id);
42676 ret = cm_id->event_handler(cm_id, &cm_event);
42677 - atomic_inc(&cm_closes);
42678 + atomic_inc_unchecked(&cm_closes);
42679 cm_event.event = IW_CM_EVENT_CLOSE;
42680 cm_event.status = 0;
42681 cm_event.provider_data = cm_id->provider_data;
42682 @@ -3781,7 +3781,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
42683 return;
42684 cm_id = cm_node->cm_id;
42685
42686 - atomic_inc(&cm_connect_reqs);
42687 + atomic_inc_unchecked(&cm_connect_reqs);
42688 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
42689 cm_node, cm_id, jiffies);
42690
42691 @@ -3830,7 +3830,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
42692 return;
42693 cm_id = cm_node->cm_id;
42694
42695 - atomic_inc(&cm_connect_reqs);
42696 + atomic_inc_unchecked(&cm_connect_reqs);
42697 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
42698 cm_node, cm_id, jiffies);
42699
42700 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
42701 index 4166452..fc952c3 100644
42702 --- a/drivers/infiniband/hw/nes/nes_mgt.c
42703 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
42704 @@ -40,8 +40,8 @@
42705 #include "nes.h"
42706 #include "nes_mgt.h"
42707
42708 -atomic_t pau_qps_created;
42709 -atomic_t pau_qps_destroyed;
42710 +atomic_unchecked_t pau_qps_created;
42711 +atomic_unchecked_t pau_qps_destroyed;
42712
42713 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
42714 {
42715 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
42716 {
42717 struct sk_buff *skb;
42718 unsigned long flags;
42719 - atomic_inc(&pau_qps_destroyed);
42720 + atomic_inc_unchecked(&pau_qps_destroyed);
42721
42722 /* Free packets that have not yet been forwarded */
42723 /* Lock is acquired by skb_dequeue when removing the skb */
42724 @@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
42725 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
42726 skb_queue_head_init(&nesqp->pau_list);
42727 spin_lock_init(&nesqp->pau_lock);
42728 - atomic_inc(&pau_qps_created);
42729 + atomic_inc_unchecked(&pau_qps_created);
42730 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
42731 }
42732
42733 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
42734 index 49eb511..a774366 100644
42735 --- a/drivers/infiniband/hw/nes/nes_nic.c
42736 +++ b/drivers/infiniband/hw/nes/nes_nic.c
42737 @@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
42738 target_stat_values[++index] = mh_detected;
42739 target_stat_values[++index] = mh_pauses_sent;
42740 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
42741 - target_stat_values[++index] = atomic_read(&cm_connects);
42742 - target_stat_values[++index] = atomic_read(&cm_accepts);
42743 - target_stat_values[++index] = atomic_read(&cm_disconnects);
42744 - target_stat_values[++index] = atomic_read(&cm_connecteds);
42745 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
42746 - target_stat_values[++index] = atomic_read(&cm_rejects);
42747 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
42748 - target_stat_values[++index] = atomic_read(&qps_created);
42749 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
42750 - target_stat_values[++index] = atomic_read(&qps_destroyed);
42751 - target_stat_values[++index] = atomic_read(&cm_closes);
42752 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
42753 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
42754 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
42755 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
42756 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
42757 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
42758 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
42759 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
42760 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
42761 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
42762 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
42763 target_stat_values[++index] = cm_packets_sent;
42764 target_stat_values[++index] = cm_packets_bounced;
42765 target_stat_values[++index] = cm_packets_created;
42766 target_stat_values[++index] = cm_packets_received;
42767 target_stat_values[++index] = cm_packets_dropped;
42768 target_stat_values[++index] = cm_packets_retrans;
42769 - target_stat_values[++index] = atomic_read(&cm_listens_created);
42770 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
42771 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
42772 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
42773 target_stat_values[++index] = cm_backlog_drops;
42774 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
42775 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
42776 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
42777 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
42778 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
42779 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
42780 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
42781 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
42782 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
42783 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
42784 target_stat_values[++index] = nesadapter->free_4kpbl;
42785 target_stat_values[++index] = nesadapter->free_256pbl;
42786 target_stat_values[++index] = int_mod_timer_init;
42787 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
42788 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
42789 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
42790 - target_stat_values[++index] = atomic_read(&pau_qps_created);
42791 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
42792 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
42793 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
42794 }
42795
42796 /**
42797 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
42798 index 218dd35..97ce31d 100644
42799 --- a/drivers/infiniband/hw/nes/nes_verbs.c
42800 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
42801 @@ -46,9 +46,9 @@
42802
42803 #include <rdma/ib_umem.h>
42804
42805 -atomic_t mod_qp_timouts;
42806 -atomic_t qps_created;
42807 -atomic_t sw_qps_destroyed;
42808 +atomic_unchecked_t mod_qp_timouts;
42809 +atomic_unchecked_t qps_created;
42810 +atomic_unchecked_t sw_qps_destroyed;
42811
42812 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
42813
42814 @@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
42815 if (init_attr->create_flags)
42816 return ERR_PTR(-EINVAL);
42817
42818 - atomic_inc(&qps_created);
42819 + atomic_inc_unchecked(&qps_created);
42820 switch (init_attr->qp_type) {
42821 case IB_QPT_RC:
42822 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
42823 @@ -1468,7 +1468,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
42824 struct iw_cm_event cm_event;
42825 int ret = 0;
42826
42827 - atomic_inc(&sw_qps_destroyed);
42828 + atomic_inc_unchecked(&sw_qps_destroyed);
42829 nesqp->destroyed = 1;
42830
42831 /* Blow away the connection if it exists. */
42832 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
42833 index c00ae09..04e91be 100644
42834 --- a/drivers/infiniband/hw/qib/qib.h
42835 +++ b/drivers/infiniband/hw/qib/qib.h
42836 @@ -52,6 +52,7 @@
42837 #include <linux/kref.h>
42838 #include <linux/sched.h>
42839 #include <linux/kthread.h>
42840 +#include <linux/slab.h>
42841
42842 #include "qib_common.h"
42843 #include "qib_verbs.h"
42844 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
42845 index 24c41ba..102d71f 100644
42846 --- a/drivers/input/gameport/gameport.c
42847 +++ b/drivers/input/gameport/gameport.c
42848 @@ -490,14 +490,14 @@ EXPORT_SYMBOL(gameport_set_phys);
42849 */
42850 static void gameport_init_port(struct gameport *gameport)
42851 {
42852 - static atomic_t gameport_no = ATOMIC_INIT(0);
42853 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
42854
42855 __module_get(THIS_MODULE);
42856
42857 mutex_init(&gameport->drv_mutex);
42858 device_initialize(&gameport->dev);
42859 dev_set_name(&gameport->dev, "gameport%lu",
42860 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
42861 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
42862 gameport->dev.bus = &gameport_bus;
42863 gameport->dev.release = gameport_release_port;
42864 if (gameport->parent)
42865 diff --git a/drivers/input/input.c b/drivers/input/input.c
42866 index 1c4c0db..6f7abe3 100644
42867 --- a/drivers/input/input.c
42868 +++ b/drivers/input/input.c
42869 @@ -1772,7 +1772,7 @@ EXPORT_SYMBOL_GPL(input_class);
42870 */
42871 struct input_dev *input_allocate_device(void)
42872 {
42873 - static atomic_t input_no = ATOMIC_INIT(0);
42874 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
42875 struct input_dev *dev;
42876
42877 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
42878 @@ -1787,7 +1787,7 @@ struct input_dev *input_allocate_device(void)
42879 INIT_LIST_HEAD(&dev->node);
42880
42881 dev_set_name(&dev->dev, "input%ld",
42882 - (unsigned long) atomic_inc_return(&input_no) - 1);
42883 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
42884
42885 __module_get(THIS_MODULE);
42886 }
42887 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
42888 index 4a95b22..874c182 100644
42889 --- a/drivers/input/joystick/sidewinder.c
42890 +++ b/drivers/input/joystick/sidewinder.c
42891 @@ -30,6 +30,7 @@
42892 #include <linux/kernel.h>
42893 #include <linux/module.h>
42894 #include <linux/slab.h>
42895 +#include <linux/sched.h>
42896 #include <linux/input.h>
42897 #include <linux/gameport.h>
42898 #include <linux/jiffies.h>
42899 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
42900 index 603fe0d..f63decc 100644
42901 --- a/drivers/input/joystick/xpad.c
42902 +++ b/drivers/input/joystick/xpad.c
42903 @@ -737,7 +737,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
42904
42905 static int xpad_led_probe(struct usb_xpad *xpad)
42906 {
42907 - static atomic_t led_seq = ATOMIC_INIT(0);
42908 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
42909 long led_no;
42910 struct xpad_led *led;
42911 struct led_classdev *led_cdev;
42912 @@ -750,7 +750,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
42913 if (!led)
42914 return -ENOMEM;
42915
42916 - led_no = (long)atomic_inc_return(&led_seq) - 1;
42917 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
42918
42919 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
42920 led->xpad = xpad;
42921 diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
42922 index 5a73639..d586683 100644
42923 --- a/drivers/input/misc/ims-pcu.c
42924 +++ b/drivers/input/misc/ims-pcu.c
42925 @@ -1850,7 +1850,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
42926
42927 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
42928 {
42929 - static atomic_t device_no = ATOMIC_INIT(0);
42930 + static atomic_unchecked_t device_no = ATOMIC_INIT(0);
42931
42932 const struct ims_pcu_device_info *info;
42933 int error;
42934 @@ -1881,7 +1881,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
42935 }
42936
42937 /* Device appears to be operable, complete initialization */
42938 - pcu->device_no = atomic_inc_return(&device_no) - 1;
42939 + pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
42940
42941 /*
42942 * PCU-B devices, both GEN_1 and GEN_2 do not have OFN sensor
42943 diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
42944 index 2f0b39d..7370f13 100644
42945 --- a/drivers/input/mouse/psmouse.h
42946 +++ b/drivers/input/mouse/psmouse.h
42947 @@ -116,7 +116,7 @@ struct psmouse_attribute {
42948 ssize_t (*set)(struct psmouse *psmouse, void *data,
42949 const char *buf, size_t count);
42950 bool protect;
42951 -};
42952 +} __do_const;
42953 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
42954
42955 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
42956 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
42957 index b604564..3f14ae4 100644
42958 --- a/drivers/input/mousedev.c
42959 +++ b/drivers/input/mousedev.c
42960 @@ -744,7 +744,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
42961
42962 spin_unlock_irq(&client->packet_lock);
42963
42964 - if (copy_to_user(buffer, data, count))
42965 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
42966 return -EFAULT;
42967
42968 return count;
42969 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
42970 index b29134d..394deb0 100644
42971 --- a/drivers/input/serio/serio.c
42972 +++ b/drivers/input/serio/serio.c
42973 @@ -514,7 +514,7 @@ static void serio_release_port(struct device *dev)
42974 */
42975 static void serio_init_port(struct serio *serio)
42976 {
42977 - static atomic_t serio_no = ATOMIC_INIT(0);
42978 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
42979
42980 __module_get(THIS_MODULE);
42981
42982 @@ -525,7 +525,7 @@ static void serio_init_port(struct serio *serio)
42983 mutex_init(&serio->drv_mutex);
42984 device_initialize(&serio->dev);
42985 dev_set_name(&serio->dev, "serio%ld",
42986 - (long)atomic_inc_return(&serio_no) - 1);
42987 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
42988 serio->dev.bus = &serio_bus;
42989 serio->dev.release = serio_release_port;
42990 serio->dev.groups = serio_device_attr_groups;
42991 diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
42992 index c9a02fe..0debc75 100644
42993 --- a/drivers/input/serio/serio_raw.c
42994 +++ b/drivers/input/serio/serio_raw.c
42995 @@ -292,7 +292,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
42996
42997 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
42998 {
42999 - static atomic_t serio_raw_no = ATOMIC_INIT(0);
43000 + static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
43001 struct serio_raw *serio_raw;
43002 int err;
43003
43004 @@ -303,7 +303,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
43005 }
43006
43007 snprintf(serio_raw->name, sizeof(serio_raw->name),
43008 - "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
43009 + "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
43010 kref_init(&serio_raw->kref);
43011 INIT_LIST_HEAD(&serio_raw->client_list);
43012 init_waitqueue_head(&serio_raw->wait);
43013 diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
43014 index e5555fc..937986d 100644
43015 --- a/drivers/iommu/iommu.c
43016 +++ b/drivers/iommu/iommu.c
43017 @@ -588,7 +588,7 @@ static struct notifier_block iommu_bus_nb = {
43018 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
43019 {
43020 bus_register_notifier(bus, &iommu_bus_nb);
43021 - bus_for_each_dev(bus, NULL, ops, add_iommu_group);
43022 + bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
43023 }
43024
43025 /**
43026 diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
43027 index 228632c9..edfe331 100644
43028 --- a/drivers/iommu/irq_remapping.c
43029 +++ b/drivers/iommu/irq_remapping.c
43030 @@ -356,7 +356,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
43031 void panic_if_irq_remap(const char *msg)
43032 {
43033 if (irq_remapping_enabled)
43034 - panic(msg);
43035 + panic("%s", msg);
43036 }
43037
43038 static void ir_ack_apic_edge(struct irq_data *data)
43039 @@ -377,10 +377,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
43040
43041 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
43042 {
43043 - chip->irq_print_chip = ir_print_prefix;
43044 - chip->irq_ack = ir_ack_apic_edge;
43045 - chip->irq_eoi = ir_ack_apic_level;
43046 - chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43047 + pax_open_kernel();
43048 + *(void **)&chip->irq_print_chip = ir_print_prefix;
43049 + *(void **)&chip->irq_ack = ir_ack_apic_edge;
43050 + *(void **)&chip->irq_eoi = ir_ack_apic_level;
43051 + *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
43052 + pax_close_kernel();
43053 }
43054
43055 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
43056 diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
43057 index 57d165e..611997e 100644
43058 --- a/drivers/irqchip/irq-gic.c
43059 +++ b/drivers/irqchip/irq-gic.c
43060 @@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
43061 * Supported arch specific GIC irq extension.
43062 * Default make them NULL.
43063 */
43064 -struct irq_chip gic_arch_extn = {
43065 +irq_chip_no_const gic_arch_extn = {
43066 .irq_eoi = NULL,
43067 .irq_mask = NULL,
43068 .irq_unmask = NULL,
43069 @@ -336,7 +336,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
43070 chained_irq_exit(chip, desc);
43071 }
43072
43073 -static struct irq_chip gic_chip = {
43074 +static irq_chip_no_const gic_chip __read_only = {
43075 .name = "GIC",
43076 .irq_mask = gic_mask_irq,
43077 .irq_unmask = gic_unmask_irq,
43078 diff --git a/drivers/irqchip/irq-renesas-irqc.c b/drivers/irqchip/irq-renesas-irqc.c
43079 index 8777065..a4a9967 100644
43080 --- a/drivers/irqchip/irq-renesas-irqc.c
43081 +++ b/drivers/irqchip/irq-renesas-irqc.c
43082 @@ -151,7 +151,7 @@ static int irqc_probe(struct platform_device *pdev)
43083 struct irqc_priv *p;
43084 struct resource *io;
43085 struct resource *irq;
43086 - struct irq_chip *irq_chip;
43087 + irq_chip_no_const *irq_chip;
43088 const char *name = dev_name(&pdev->dev);
43089 int ret;
43090 int k;
43091 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
43092 index ac6f72b..81150f2 100644
43093 --- a/drivers/isdn/capi/capi.c
43094 +++ b/drivers/isdn/capi/capi.c
43095 @@ -81,8 +81,8 @@ struct capiminor {
43096
43097 struct capi20_appl *ap;
43098 u32 ncci;
43099 - atomic_t datahandle;
43100 - atomic_t msgid;
43101 + atomic_unchecked_t datahandle;
43102 + atomic_unchecked_t msgid;
43103
43104 struct tty_port port;
43105 int ttyinstop;
43106 @@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
43107 capimsg_setu16(s, 2, mp->ap->applid);
43108 capimsg_setu8 (s, 4, CAPI_DATA_B3);
43109 capimsg_setu8 (s, 5, CAPI_RESP);
43110 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
43111 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
43112 capimsg_setu32(s, 8, mp->ncci);
43113 capimsg_setu16(s, 12, datahandle);
43114 }
43115 @@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
43116 mp->outbytes -= len;
43117 spin_unlock_bh(&mp->outlock);
43118
43119 - datahandle = atomic_inc_return(&mp->datahandle);
43120 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
43121 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
43122 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43123 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
43124 capimsg_setu16(skb->data, 2, mp->ap->applid);
43125 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
43126 capimsg_setu8 (skb->data, 5, CAPI_REQ);
43127 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
43128 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
43129 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
43130 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
43131 capimsg_setu16(skb->data, 16, len); /* Data length */
43132 diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
43133 index c44950d..10ac276 100644
43134 --- a/drivers/isdn/gigaset/bas-gigaset.c
43135 +++ b/drivers/isdn/gigaset/bas-gigaset.c
43136 @@ -2564,22 +2564,22 @@ static int gigaset_post_reset(struct usb_interface *intf)
43137
43138
43139 static const struct gigaset_ops gigops = {
43140 - gigaset_write_cmd,
43141 - gigaset_write_room,
43142 - gigaset_chars_in_buffer,
43143 - gigaset_brkchars,
43144 - gigaset_init_bchannel,
43145 - gigaset_close_bchannel,
43146 - gigaset_initbcshw,
43147 - gigaset_freebcshw,
43148 - gigaset_reinitbcshw,
43149 - gigaset_initcshw,
43150 - gigaset_freecshw,
43151 - gigaset_set_modem_ctrl,
43152 - gigaset_baud_rate,
43153 - gigaset_set_line_ctrl,
43154 - gigaset_isoc_send_skb,
43155 - gigaset_isoc_input,
43156 + .write_cmd = gigaset_write_cmd,
43157 + .write_room = gigaset_write_room,
43158 + .chars_in_buffer = gigaset_chars_in_buffer,
43159 + .brkchars = gigaset_brkchars,
43160 + .init_bchannel = gigaset_init_bchannel,
43161 + .close_bchannel = gigaset_close_bchannel,
43162 + .initbcshw = gigaset_initbcshw,
43163 + .freebcshw = gigaset_freebcshw,
43164 + .reinitbcshw = gigaset_reinitbcshw,
43165 + .initcshw = gigaset_initcshw,
43166 + .freecshw = gigaset_freecshw,
43167 + .set_modem_ctrl = gigaset_set_modem_ctrl,
43168 + .baud_rate = gigaset_baud_rate,
43169 + .set_line_ctrl = gigaset_set_line_ctrl,
43170 + .send_skb = gigaset_isoc_send_skb,
43171 + .handle_input = gigaset_isoc_input,
43172 };
43173
43174 /* bas_gigaset_init
43175 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
43176 index 600c79b..3752bab 100644
43177 --- a/drivers/isdn/gigaset/interface.c
43178 +++ b/drivers/isdn/gigaset/interface.c
43179 @@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
43180 }
43181 tty->driver_data = cs;
43182
43183 - ++cs->port.count;
43184 + atomic_inc(&cs->port.count);
43185
43186 - if (cs->port.count == 1) {
43187 + if (atomic_read(&cs->port.count) == 1) {
43188 tty_port_tty_set(&cs->port, tty);
43189 cs->port.low_latency = 1;
43190 }
43191 @@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
43192
43193 if (!cs->connected)
43194 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
43195 - else if (!cs->port.count)
43196 + else if (!atomic_read(&cs->port.count))
43197 dev_warn(cs->dev, "%s: device not opened\n", __func__);
43198 - else if (!--cs->port.count)
43199 + else if (!atomic_dec_return(&cs->port.count))
43200 tty_port_tty_set(&cs->port, NULL);
43201
43202 mutex_unlock(&cs->mutex);
43203 diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
43204 index 8c91fd5..14f13ce 100644
43205 --- a/drivers/isdn/gigaset/ser-gigaset.c
43206 +++ b/drivers/isdn/gigaset/ser-gigaset.c
43207 @@ -453,22 +453,22 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
43208 }
43209
43210 static const struct gigaset_ops ops = {
43211 - gigaset_write_cmd,
43212 - gigaset_write_room,
43213 - gigaset_chars_in_buffer,
43214 - gigaset_brkchars,
43215 - gigaset_init_bchannel,
43216 - gigaset_close_bchannel,
43217 - gigaset_initbcshw,
43218 - gigaset_freebcshw,
43219 - gigaset_reinitbcshw,
43220 - gigaset_initcshw,
43221 - gigaset_freecshw,
43222 - gigaset_set_modem_ctrl,
43223 - gigaset_baud_rate,
43224 - gigaset_set_line_ctrl,
43225 - gigaset_m10x_send_skb, /* asyncdata.c */
43226 - gigaset_m10x_input, /* asyncdata.c */
43227 + .write_cmd = gigaset_write_cmd,
43228 + .write_room = gigaset_write_room,
43229 + .chars_in_buffer = gigaset_chars_in_buffer,
43230 + .brkchars = gigaset_brkchars,
43231 + .init_bchannel = gigaset_init_bchannel,
43232 + .close_bchannel = gigaset_close_bchannel,
43233 + .initbcshw = gigaset_initbcshw,
43234 + .freebcshw = gigaset_freebcshw,
43235 + .reinitbcshw = gigaset_reinitbcshw,
43236 + .initcshw = gigaset_initcshw,
43237 + .freecshw = gigaset_freecshw,
43238 + .set_modem_ctrl = gigaset_set_modem_ctrl,
43239 + .baud_rate = gigaset_baud_rate,
43240 + .set_line_ctrl = gigaset_set_line_ctrl,
43241 + .send_skb = gigaset_m10x_send_skb, /* asyncdata.c */
43242 + .handle_input = gigaset_m10x_input, /* asyncdata.c */
43243 };
43244
43245
43246 diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
43247 index d0a41cb..b953e50 100644
43248 --- a/drivers/isdn/gigaset/usb-gigaset.c
43249 +++ b/drivers/isdn/gigaset/usb-gigaset.c
43250 @@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
43251 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
43252 memcpy(cs->hw.usb->bchars, buf, 6);
43253 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
43254 - 0, 0, &buf, 6, 2000);
43255 + 0, 0, buf, 6, 2000);
43256 }
43257
43258 static void gigaset_freebcshw(struct bc_state *bcs)
43259 @@ -869,22 +869,22 @@ static int gigaset_pre_reset(struct usb_interface *intf)
43260 }
43261
43262 static const struct gigaset_ops ops = {
43263 - gigaset_write_cmd,
43264 - gigaset_write_room,
43265 - gigaset_chars_in_buffer,
43266 - gigaset_brkchars,
43267 - gigaset_init_bchannel,
43268 - gigaset_close_bchannel,
43269 - gigaset_initbcshw,
43270 - gigaset_freebcshw,
43271 - gigaset_reinitbcshw,
43272 - gigaset_initcshw,
43273 - gigaset_freecshw,
43274 - gigaset_set_modem_ctrl,
43275 - gigaset_baud_rate,
43276 - gigaset_set_line_ctrl,
43277 - gigaset_m10x_send_skb,
43278 - gigaset_m10x_input,
43279 + .write_cmd = gigaset_write_cmd,
43280 + .write_room = gigaset_write_room,
43281 + .chars_in_buffer = gigaset_chars_in_buffer,
43282 + .brkchars = gigaset_brkchars,
43283 + .init_bchannel = gigaset_init_bchannel,
43284 + .close_bchannel = gigaset_close_bchannel,
43285 + .initbcshw = gigaset_initbcshw,
43286 + .freebcshw = gigaset_freebcshw,
43287 + .reinitbcshw = gigaset_reinitbcshw,
43288 + .initcshw = gigaset_initcshw,
43289 + .freecshw = gigaset_freecshw,
43290 + .set_modem_ctrl = gigaset_set_modem_ctrl,
43291 + .baud_rate = gigaset_baud_rate,
43292 + .set_line_ctrl = gigaset_set_line_ctrl,
43293 + .send_skb = gigaset_m10x_send_skb,
43294 + .handle_input = gigaset_m10x_input,
43295 };
43296
43297 /*
43298 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
43299 index 4d9b195..455075c 100644
43300 --- a/drivers/isdn/hardware/avm/b1.c
43301 +++ b/drivers/isdn/hardware/avm/b1.c
43302 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
43303 }
43304 if (left) {
43305 if (t4file->user) {
43306 - if (copy_from_user(buf, dp, left))
43307 + if (left > sizeof buf || copy_from_user(buf, dp, left))
43308 return -EFAULT;
43309 } else {
43310 memcpy(buf, dp, left);
43311 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
43312 }
43313 if (left) {
43314 if (config->user) {
43315 - if (copy_from_user(buf, dp, left))
43316 + if (left > sizeof buf || copy_from_user(buf, dp, left))
43317 return -EFAULT;
43318 } else {
43319 memcpy(buf, dp, left);
43320 diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
43321 index 9b856e1..fa03c92 100644
43322 --- a/drivers/isdn/i4l/isdn_common.c
43323 +++ b/drivers/isdn/i4l/isdn_common.c
43324 @@ -1654,6 +1654,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
43325 } else
43326 return -EINVAL;
43327 case IIOCDBGVAR:
43328 + if (!capable(CAP_SYS_RAWIO))
43329 + return -EPERM;
43330 if (arg) {
43331 if (copy_to_user(argp, &dev, sizeof(ulong)))
43332 return -EFAULT;
43333 diff --git a/drivers/isdn/i4l/isdn_concap.c b/drivers/isdn/i4l/isdn_concap.c
43334 index 91d5730..336523e 100644
43335 --- a/drivers/isdn/i4l/isdn_concap.c
43336 +++ b/drivers/isdn/i4l/isdn_concap.c
43337 @@ -80,9 +80,9 @@ static int isdn_concap_dl_disconn_req(struct concap_proto *concap)
43338 }
43339
43340 struct concap_device_ops isdn_concap_reliable_dl_dops = {
43341 - &isdn_concap_dl_data_req,
43342 - &isdn_concap_dl_connect_req,
43343 - &isdn_concap_dl_disconn_req
43344 + .data_req = &isdn_concap_dl_data_req,
43345 + .connect_req = &isdn_concap_dl_connect_req,
43346 + .disconn_req = &isdn_concap_dl_disconn_req
43347 };
43348
43349 /* The following should better go into a dedicated source file such that
43350 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
43351 index 3c5f249..5fac4d0 100644
43352 --- a/drivers/isdn/i4l/isdn_tty.c
43353 +++ b/drivers/isdn/i4l/isdn_tty.c
43354 @@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
43355
43356 #ifdef ISDN_DEBUG_MODEM_OPEN
43357 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
43358 - port->count);
43359 + atomic_read(&port->count));
43360 #endif
43361 - port->count++;
43362 + atomic_inc(&port->count);
43363 port->tty = tty;
43364 /*
43365 * Start up serial port
43366 @@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
43367 #endif
43368 return;
43369 }
43370 - if ((tty->count == 1) && (port->count != 1)) {
43371 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
43372 /*
43373 * Uh, oh. tty->count is 1, which means that the tty
43374 * structure will be freed. Info->count should always
43375 @@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
43376 * serial port won't be shutdown.
43377 */
43378 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
43379 - "info->count is %d\n", port->count);
43380 - port->count = 1;
43381 + "info->count is %d\n", atomic_read(&port->count));
43382 + atomic_set(&port->count, 1);
43383 }
43384 - if (--port->count < 0) {
43385 + if (atomic_dec_return(&port->count) < 0) {
43386 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
43387 - info->line, port->count);
43388 - port->count = 0;
43389 + info->line, atomic_read(&port->count));
43390 + atomic_set(&port->count, 0);
43391 }
43392 - if (port->count) {
43393 + if (atomic_read(&port->count)) {
43394 #ifdef ISDN_DEBUG_MODEM_OPEN
43395 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
43396 #endif
43397 @@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
43398 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
43399 return;
43400 isdn_tty_shutdown(info);
43401 - port->count = 0;
43402 + atomic_set(&port->count, 0);
43403 port->flags &= ~ASYNC_NORMAL_ACTIVE;
43404 port->tty = NULL;
43405 wake_up_interruptible(&port->open_wait);
43406 @@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
43407 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
43408 modem_info *info = &dev->mdm.info[i];
43409
43410 - if (info->port.count == 0)
43411 + if (atomic_read(&info->port.count) == 0)
43412 continue;
43413 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
43414 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
43415 diff --git a/drivers/isdn/i4l/isdn_x25iface.c b/drivers/isdn/i4l/isdn_x25iface.c
43416 index e2d4e58..40cd045 100644
43417 --- a/drivers/isdn/i4l/isdn_x25iface.c
43418 +++ b/drivers/isdn/i4l/isdn_x25iface.c
43419 @@ -53,14 +53,14 @@ static int isdn_x25iface_disconn_ind(struct concap_proto *);
43420
43421
43422 static struct concap_proto_ops ix25_pops = {
43423 - &isdn_x25iface_proto_new,
43424 - &isdn_x25iface_proto_del,
43425 - &isdn_x25iface_proto_restart,
43426 - &isdn_x25iface_proto_close,
43427 - &isdn_x25iface_xmit,
43428 - &isdn_x25iface_receive,
43429 - &isdn_x25iface_connect_ind,
43430 - &isdn_x25iface_disconn_ind
43431 + .proto_new = &isdn_x25iface_proto_new,
43432 + .proto_del = &isdn_x25iface_proto_del,
43433 + .restart = &isdn_x25iface_proto_restart,
43434 + .close = &isdn_x25iface_proto_close,
43435 + .encap_and_xmit = &isdn_x25iface_xmit,
43436 + .data_ind = &isdn_x25iface_receive,
43437 + .connect_ind = &isdn_x25iface_connect_ind,
43438 + .disconn_ind = &isdn_x25iface_disconn_ind
43439 };
43440
43441 /* error message helper function */
43442 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
43443 index 6a7447c..cae33fe 100644
43444 --- a/drivers/isdn/icn/icn.c
43445 +++ b/drivers/isdn/icn/icn.c
43446 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
43447 if (count > len)
43448 count = len;
43449 if (user) {
43450 - if (copy_from_user(msg, buf, count))
43451 + if (count > sizeof msg || copy_from_user(msg, buf, count))
43452 return -EFAULT;
43453 } else
43454 memcpy(msg, buf, count);
43455 diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
43456 index a4f05c5..1433bc5 100644
43457 --- a/drivers/isdn/mISDN/dsp_cmx.c
43458 +++ b/drivers/isdn/mISDN/dsp_cmx.c
43459 @@ -1628,7 +1628,7 @@ unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
43460 static u16 dsp_count; /* last sample count */
43461 static int dsp_count_valid; /* if we have last sample count */
43462
43463 -void
43464 +void __intentional_overflow(-1)
43465 dsp_cmx_send(void *arg)
43466 {
43467 struct dsp_conf *conf;
43468 diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
43469 index f58a354..fbae176 100644
43470 --- a/drivers/leds/leds-clevo-mail.c
43471 +++ b/drivers/leds/leds-clevo-mail.c
43472 @@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
43473 * detected as working, but in reality it is not) as low as
43474 * possible.
43475 */
43476 -static struct dmi_system_id clevo_mail_led_dmi_table[] __initdata = {
43477 +static struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
43478 {
43479 .callback = clevo_mail_led_dmi_callback,
43480 .ident = "Clevo D410J",
43481 diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
43482 index 2eb3ef6..295891f 100644
43483 --- a/drivers/leds/leds-ss4200.c
43484 +++ b/drivers/leds/leds-ss4200.c
43485 @@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
43486 * detected as working, but in reality it is not) as low as
43487 * possible.
43488 */
43489 -static struct dmi_system_id nas_led_whitelist[] __initdata = {
43490 +static struct dmi_system_id nas_led_whitelist[] __initconst = {
43491 {
43492 .callback = ss4200_led_dmi_callback,
43493 .ident = "Intel SS4200-E",
43494 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
43495 index 0bf1e4e..b4bf44e 100644
43496 --- a/drivers/lguest/core.c
43497 +++ b/drivers/lguest/core.c
43498 @@ -97,9 +97,17 @@ static __init int map_switcher(void)
43499 * The end address needs +1 because __get_vm_area allocates an
43500 * extra guard page, so we need space for that.
43501 */
43502 +
43503 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
43504 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
43505 + VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
43506 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
43507 +#else
43508 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
43509 VM_ALLOC, switcher_addr, switcher_addr
43510 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
43511 +#endif
43512 +
43513 if (!switcher_vma) {
43514 err = -ENOMEM;
43515 printk("lguest: could not map switcher pages high\n");
43516 @@ -124,7 +132,7 @@ static __init int map_switcher(void)
43517 * Now the Switcher is mapped at the right address, we can't fail!
43518 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
43519 */
43520 - memcpy(switcher_vma->addr, start_switcher_text,
43521 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
43522 end_switcher_text - start_switcher_text);
43523
43524 printk(KERN_INFO "lguest: mapped switcher at %p\n",
43525 diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
43526 index e8b55c3..3514c37 100644
43527 --- a/drivers/lguest/page_tables.c
43528 +++ b/drivers/lguest/page_tables.c
43529 @@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
43530 /*:*/
43531
43532 #ifdef CONFIG_X86_PAE
43533 -static void release_pmd(pmd_t *spmd)
43534 +static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
43535 {
43536 /* If the entry's not present, there's nothing to release. */
43537 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
43538 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
43539 index 922a1ac..9dd0c2a 100644
43540 --- a/drivers/lguest/x86/core.c
43541 +++ b/drivers/lguest/x86/core.c
43542 @@ -59,7 +59,7 @@ static struct {
43543 /* Offset from where switcher.S was compiled to where we've copied it */
43544 static unsigned long switcher_offset(void)
43545 {
43546 - return switcher_addr - (unsigned long)start_switcher_text;
43547 + return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
43548 }
43549
43550 /* This cpu's struct lguest_pages (after the Switcher text page) */
43551 @@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
43552 * These copies are pretty cheap, so we do them unconditionally: */
43553 /* Save the current Host top-level page directory.
43554 */
43555 +
43556 +#ifdef CONFIG_PAX_PER_CPU_PGD
43557 + pages->state.host_cr3 = read_cr3();
43558 +#else
43559 pages->state.host_cr3 = __pa(current->mm->pgd);
43560 +#endif
43561 +
43562 /*
43563 * Set up the Guest's page tables to see this CPU's pages (and no
43564 * other CPU's pages).
43565 @@ -477,7 +483,7 @@ void __init lguest_arch_host_init(void)
43566 * compiled-in switcher code and the high-mapped copy we just made.
43567 */
43568 for (i = 0; i < IDT_ENTRIES; i++)
43569 - default_idt_entries[i] += switcher_offset();
43570 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
43571
43572 /*
43573 * Set up the Switcher's per-cpu areas.
43574 @@ -560,7 +566,7 @@ void __init lguest_arch_host_init(void)
43575 * it will be undisturbed when we switch. To change %cs and jump we
43576 * need this structure to feed to Intel's "lcall" instruction.
43577 */
43578 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
43579 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
43580 lguest_entry.segment = LGUEST_CS;
43581
43582 /*
43583 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
43584 index 40634b0..4f5855e 100644
43585 --- a/drivers/lguest/x86/switcher_32.S
43586 +++ b/drivers/lguest/x86/switcher_32.S
43587 @@ -87,6 +87,7 @@
43588 #include <asm/page.h>
43589 #include <asm/segment.h>
43590 #include <asm/lguest.h>
43591 +#include <asm/processor-flags.h>
43592
43593 // We mark the start of the code to copy
43594 // It's placed in .text tho it's never run here
43595 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
43596 // Changes type when we load it: damn Intel!
43597 // For after we switch over our page tables
43598 // That entry will be read-only: we'd crash.
43599 +
43600 +#ifdef CONFIG_PAX_KERNEXEC
43601 + mov %cr0, %edx
43602 + xor $X86_CR0_WP, %edx
43603 + mov %edx, %cr0
43604 +#endif
43605 +
43606 movl $(GDT_ENTRY_TSS*8), %edx
43607 ltr %dx
43608
43609 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
43610 // Let's clear it again for our return.
43611 // The GDT descriptor of the Host
43612 // Points to the table after two "size" bytes
43613 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
43614 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
43615 // Clear "used" from type field (byte 5, bit 2)
43616 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
43617 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
43618 +
43619 +#ifdef CONFIG_PAX_KERNEXEC
43620 + mov %cr0, %eax
43621 + xor $X86_CR0_WP, %eax
43622 + mov %eax, %cr0
43623 +#endif
43624
43625 // Once our page table's switched, the Guest is live!
43626 // The Host fades as we run this final step.
43627 @@ -295,13 +309,12 @@ deliver_to_host:
43628 // I consulted gcc, and it gave
43629 // These instructions, which I gladly credit:
43630 leal (%edx,%ebx,8), %eax
43631 - movzwl (%eax),%edx
43632 - movl 4(%eax), %eax
43633 - xorw %ax, %ax
43634 - orl %eax, %edx
43635 + movl 4(%eax), %edx
43636 + movw (%eax), %dx
43637 // Now the address of the handler's in %edx
43638 // We call it now: its "iret" drops us home.
43639 - jmp *%edx
43640 + ljmp $__KERNEL_CS, $1f
43641 +1: jmp *%edx
43642
43643 // Every interrupt can come to us here
43644 // But we must truly tell each apart.
43645 diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
43646 index 7ef7461..5a09dac 100644
43647 --- a/drivers/md/bcache/closure.h
43648 +++ b/drivers/md/bcache/closure.h
43649 @@ -238,7 +238,7 @@ static inline void closure_set_stopped(struct closure *cl)
43650 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
43651 struct workqueue_struct *wq)
43652 {
43653 - BUG_ON(object_is_on_stack(cl));
43654 + BUG_ON(object_starts_on_stack(cl));
43655 closure_set_ip(cl);
43656 cl->fn = fn;
43657 cl->wq = wq;
43658 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
43659 index 9a8e66a..10cc762 100644
43660 --- a/drivers/md/bitmap.c
43661 +++ b/drivers/md/bitmap.c
43662 @@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
43663 chunk_kb ? "KB" : "B");
43664 if (bitmap->storage.file) {
43665 seq_printf(seq, ", file: ");
43666 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
43667 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
43668 }
43669
43670 seq_printf(seq, "\n");
43671 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
43672 index 5152142..623d141 100644
43673 --- a/drivers/md/dm-ioctl.c
43674 +++ b/drivers/md/dm-ioctl.c
43675 @@ -1769,7 +1769,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
43676 cmd == DM_LIST_VERSIONS_CMD)
43677 return 0;
43678
43679 - if ((cmd == DM_DEV_CREATE_CMD)) {
43680 + if (cmd == DM_DEV_CREATE_CMD) {
43681 if (!*param->name) {
43682 DMWARN("name not supplied when creating device");
43683 return -EINVAL;
43684 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
43685 index 7dfdb5c..4caada6 100644
43686 --- a/drivers/md/dm-raid1.c
43687 +++ b/drivers/md/dm-raid1.c
43688 @@ -40,7 +40,7 @@ enum dm_raid1_error {
43689
43690 struct mirror {
43691 struct mirror_set *ms;
43692 - atomic_t error_count;
43693 + atomic_unchecked_t error_count;
43694 unsigned long error_type;
43695 struct dm_dev *dev;
43696 sector_t offset;
43697 @@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
43698 struct mirror *m;
43699
43700 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
43701 - if (!atomic_read(&m->error_count))
43702 + if (!atomic_read_unchecked(&m->error_count))
43703 return m;
43704
43705 return NULL;
43706 @@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
43707 * simple way to tell if a device has encountered
43708 * errors.
43709 */
43710 - atomic_inc(&m->error_count);
43711 + atomic_inc_unchecked(&m->error_count);
43712
43713 if (test_and_set_bit(error_type, &m->error_type))
43714 return;
43715 @@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
43716 struct mirror *m = get_default_mirror(ms);
43717
43718 do {
43719 - if (likely(!atomic_read(&m->error_count)))
43720 + if (likely(!atomic_read_unchecked(&m->error_count)))
43721 return m;
43722
43723 if (m-- == ms->mirror)
43724 @@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
43725 {
43726 struct mirror *default_mirror = get_default_mirror(m->ms);
43727
43728 - return !atomic_read(&default_mirror->error_count);
43729 + return !atomic_read_unchecked(&default_mirror->error_count);
43730 }
43731
43732 static int mirror_available(struct mirror_set *ms, struct bio *bio)
43733 @@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
43734 */
43735 if (likely(region_in_sync(ms, region, 1)))
43736 m = choose_mirror(ms, bio->bi_iter.bi_sector);
43737 - else if (m && atomic_read(&m->error_count))
43738 + else if (m && atomic_read_unchecked(&m->error_count))
43739 m = NULL;
43740
43741 if (likely(m))
43742 @@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
43743 }
43744
43745 ms->mirror[mirror].ms = ms;
43746 - atomic_set(&(ms->mirror[mirror].error_count), 0);
43747 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
43748 ms->mirror[mirror].error_type = 0;
43749 ms->mirror[mirror].offset = offset;
43750
43751 @@ -1342,7 +1342,7 @@ static void mirror_resume(struct dm_target *ti)
43752 */
43753 static char device_status_char(struct mirror *m)
43754 {
43755 - if (!atomic_read(&(m->error_count)))
43756 + if (!atomic_read_unchecked(&(m->error_count)))
43757 return 'A';
43758
43759 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
43760 diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
43761 index 28a9012..9c0f6a5 100644
43762 --- a/drivers/md/dm-stats.c
43763 +++ b/drivers/md/dm-stats.c
43764 @@ -382,7 +382,7 @@ do_sync_free:
43765 synchronize_rcu_expedited();
43766 dm_stat_free(&s->rcu_head);
43767 } else {
43768 - ACCESS_ONCE(dm_stat_need_rcu_barrier) = 1;
43769 + ACCESS_ONCE_RW(dm_stat_need_rcu_barrier) = 1;
43770 call_rcu(&s->rcu_head, dm_stat_free);
43771 }
43772 return 0;
43773 @@ -554,8 +554,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
43774 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
43775 (ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
43776 ));
43777 - ACCESS_ONCE(last->last_sector) = end_sector;
43778 - ACCESS_ONCE(last->last_rw) = bi_rw;
43779 + ACCESS_ONCE_RW(last->last_sector) = end_sector;
43780 + ACCESS_ONCE_RW(last->last_rw) = bi_rw;
43781 }
43782
43783 rcu_read_lock();
43784 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
43785 index d1600d2..4c3af3a 100644
43786 --- a/drivers/md/dm-stripe.c
43787 +++ b/drivers/md/dm-stripe.c
43788 @@ -21,7 +21,7 @@ struct stripe {
43789 struct dm_dev *dev;
43790 sector_t physical_start;
43791
43792 - atomic_t error_count;
43793 + atomic_unchecked_t error_count;
43794 };
43795
43796 struct stripe_c {
43797 @@ -186,7 +186,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
43798 kfree(sc);
43799 return r;
43800 }
43801 - atomic_set(&(sc->stripe[i].error_count), 0);
43802 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
43803 }
43804
43805 ti->private = sc;
43806 @@ -330,7 +330,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
43807 DMEMIT("%d ", sc->stripes);
43808 for (i = 0; i < sc->stripes; i++) {
43809 DMEMIT("%s ", sc->stripe[i].dev->name);
43810 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
43811 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
43812 'D' : 'A';
43813 }
43814 buffer[i] = '\0';
43815 @@ -375,8 +375,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
43816 */
43817 for (i = 0; i < sc->stripes; i++)
43818 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
43819 - atomic_inc(&(sc->stripe[i].error_count));
43820 - if (atomic_read(&(sc->stripe[i].error_count)) <
43821 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
43822 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
43823 DM_IO_ERROR_THRESHOLD)
43824 schedule_work(&sc->trigger_event);
43825 }
43826 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
43827 index 50601ec..6d3b9dc 100644
43828 --- a/drivers/md/dm-table.c
43829 +++ b/drivers/md/dm-table.c
43830 @@ -274,7 +274,7 @@ static struct dm_dev_internal *find_device(struct list_head *l, dev_t dev)
43831 static int open_dev(struct dm_dev_internal *d, dev_t dev,
43832 struct mapped_device *md)
43833 {
43834 - static char *_claim_ptr = "I belong to device-mapper";
43835 + static char _claim_ptr[] = "I belong to device-mapper";
43836 struct block_device *bdev;
43837
43838 int r;
43839 @@ -342,7 +342,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
43840 if (!dev_size)
43841 return 0;
43842
43843 - if ((start >= dev_size) || (start + len > dev_size)) {
43844 + if ((start >= dev_size) || (len > dev_size - start)) {
43845 DMWARN("%s: %s too small for target: "
43846 "start=%llu, len=%llu, dev_size=%llu",
43847 dm_device_name(ti->table->md), bdevname(bdev, b),
43848 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
43849 index b086a94..74cb67e 100644
43850 --- a/drivers/md/dm-thin-metadata.c
43851 +++ b/drivers/md/dm-thin-metadata.c
43852 @@ -404,7 +404,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
43853 {
43854 pmd->info.tm = pmd->tm;
43855 pmd->info.levels = 2;
43856 - pmd->info.value_type.context = pmd->data_sm;
43857 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
43858 pmd->info.value_type.size = sizeof(__le64);
43859 pmd->info.value_type.inc = data_block_inc;
43860 pmd->info.value_type.dec = data_block_dec;
43861 @@ -423,7 +423,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
43862
43863 pmd->bl_info.tm = pmd->tm;
43864 pmd->bl_info.levels = 1;
43865 - pmd->bl_info.value_type.context = pmd->data_sm;
43866 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
43867 pmd->bl_info.value_type.size = sizeof(__le64);
43868 pmd->bl_info.value_type.inc = data_block_inc;
43869 pmd->bl_info.value_type.dec = data_block_dec;
43870 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
43871 index 455e649..1f214be 100644
43872 --- a/drivers/md/dm.c
43873 +++ b/drivers/md/dm.c
43874 @@ -178,9 +178,9 @@ struct mapped_device {
43875 /*
43876 * Event handling.
43877 */
43878 - atomic_t event_nr;
43879 + atomic_unchecked_t event_nr;
43880 wait_queue_head_t eventq;
43881 - atomic_t uevent_seq;
43882 + atomic_unchecked_t uevent_seq;
43883 struct list_head uevent_list;
43884 spinlock_t uevent_lock; /* Protect access to uevent_list */
43885
43886 @@ -1884,8 +1884,8 @@ static struct mapped_device *alloc_dev(int minor)
43887 spin_lock_init(&md->deferred_lock);
43888 atomic_set(&md->holders, 1);
43889 atomic_set(&md->open_count, 0);
43890 - atomic_set(&md->event_nr, 0);
43891 - atomic_set(&md->uevent_seq, 0);
43892 + atomic_set_unchecked(&md->event_nr, 0);
43893 + atomic_set_unchecked(&md->uevent_seq, 0);
43894 INIT_LIST_HEAD(&md->uevent_list);
43895 spin_lock_init(&md->uevent_lock);
43896
43897 @@ -2039,7 +2039,7 @@ static void event_callback(void *context)
43898
43899 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
43900
43901 - atomic_inc(&md->event_nr);
43902 + atomic_inc_unchecked(&md->event_nr);
43903 wake_up(&md->eventq);
43904 }
43905
43906 @@ -2732,18 +2732,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
43907
43908 uint32_t dm_next_uevent_seq(struct mapped_device *md)
43909 {
43910 - return atomic_add_return(1, &md->uevent_seq);
43911 + return atomic_add_return_unchecked(1, &md->uevent_seq);
43912 }
43913
43914 uint32_t dm_get_event_nr(struct mapped_device *md)
43915 {
43916 - return atomic_read(&md->event_nr);
43917 + return atomic_read_unchecked(&md->event_nr);
43918 }
43919
43920 int dm_wait_event(struct mapped_device *md, int event_nr)
43921 {
43922 return wait_event_interruptible(md->eventq,
43923 - (event_nr != atomic_read(&md->event_nr)));
43924 + (event_nr != atomic_read_unchecked(&md->event_nr)));
43925 }
43926
43927 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
43928 diff --git a/drivers/md/md.c b/drivers/md/md.c
43929 index 9a18209..ec4d3ec 100644
43930 --- a/drivers/md/md.c
43931 +++ b/drivers/md/md.c
43932 @@ -194,10 +194,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
43933 * start build, activate spare
43934 */
43935 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
43936 -static atomic_t md_event_count;
43937 +static atomic_unchecked_t md_event_count;
43938 void md_new_event(struct mddev *mddev)
43939 {
43940 - atomic_inc(&md_event_count);
43941 + atomic_inc_unchecked(&md_event_count);
43942 wake_up(&md_event_waiters);
43943 }
43944 EXPORT_SYMBOL_GPL(md_new_event);
43945 @@ -207,7 +207,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
43946 */
43947 static void md_new_event_inintr(struct mddev *mddev)
43948 {
43949 - atomic_inc(&md_event_count);
43950 + atomic_inc_unchecked(&md_event_count);
43951 wake_up(&md_event_waiters);
43952 }
43953
43954 @@ -1462,7 +1462,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
43955 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
43956 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
43957 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
43958 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
43959 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
43960
43961 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
43962 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
43963 @@ -1713,7 +1713,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
43964 else
43965 sb->resync_offset = cpu_to_le64(0);
43966
43967 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
43968 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
43969
43970 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
43971 sb->size = cpu_to_le64(mddev->dev_sectors);
43972 @@ -2725,7 +2725,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
43973 static ssize_t
43974 errors_show(struct md_rdev *rdev, char *page)
43975 {
43976 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
43977 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
43978 }
43979
43980 static ssize_t
43981 @@ -2734,7 +2734,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
43982 char *e;
43983 unsigned long n = simple_strtoul(buf, &e, 10);
43984 if (*buf && (*e == 0 || *e == '\n')) {
43985 - atomic_set(&rdev->corrected_errors, n);
43986 + atomic_set_unchecked(&rdev->corrected_errors, n);
43987 return len;
43988 }
43989 return -EINVAL;
43990 @@ -3183,8 +3183,8 @@ int md_rdev_init(struct md_rdev *rdev)
43991 rdev->sb_loaded = 0;
43992 rdev->bb_page = NULL;
43993 atomic_set(&rdev->nr_pending, 0);
43994 - atomic_set(&rdev->read_errors, 0);
43995 - atomic_set(&rdev->corrected_errors, 0);
43996 + atomic_set_unchecked(&rdev->read_errors, 0);
43997 + atomic_set_unchecked(&rdev->corrected_errors, 0);
43998
43999 INIT_LIST_HEAD(&rdev->same_set);
44000 init_waitqueue_head(&rdev->blocked_wait);
44001 @@ -7058,7 +7058,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
44002
44003 spin_unlock(&pers_lock);
44004 seq_printf(seq, "\n");
44005 - seq->poll_event = atomic_read(&md_event_count);
44006 + seq->poll_event = atomic_read_unchecked(&md_event_count);
44007 return 0;
44008 }
44009 if (v == (void*)2) {
44010 @@ -7161,7 +7161,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
44011 return error;
44012
44013 seq = file->private_data;
44014 - seq->poll_event = atomic_read(&md_event_count);
44015 + seq->poll_event = atomic_read_unchecked(&md_event_count);
44016 return error;
44017 }
44018
44019 @@ -7178,7 +7178,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
44020 /* always allow read */
44021 mask = POLLIN | POLLRDNORM;
44022
44023 - if (seq->poll_event != atomic_read(&md_event_count))
44024 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
44025 mask |= POLLERR | POLLPRI;
44026 return mask;
44027 }
44028 @@ -7222,7 +7222,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
44029 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
44030 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
44031 (int)part_stat_read(&disk->part0, sectors[1]) -
44032 - atomic_read(&disk->sync_io);
44033 + atomic_read_unchecked(&disk->sync_io);
44034 /* sync IO will cause sync_io to increase before the disk_stats
44035 * as sync_io is counted when a request starts, and
44036 * disk_stats is counted when it completes.
44037 diff --git a/drivers/md/md.h b/drivers/md/md.h
44038 index a49d991..3582bb7 100644
44039 --- a/drivers/md/md.h
44040 +++ b/drivers/md/md.h
44041 @@ -94,13 +94,13 @@ struct md_rdev {
44042 * only maintained for arrays that
44043 * support hot removal
44044 */
44045 - atomic_t read_errors; /* number of consecutive read errors that
44046 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
44047 * we have tried to ignore.
44048 */
44049 struct timespec last_read_error; /* monotonic time since our
44050 * last read error
44051 */
44052 - atomic_t corrected_errors; /* number of corrected read errors,
44053 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
44054 * for reporting to userspace and storing
44055 * in superblock.
44056 */
44057 @@ -449,7 +449,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
44058
44059 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
44060 {
44061 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44062 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
44063 }
44064
44065 struct md_personality
44066 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
44067 index 786b689..ea8c956 100644
44068 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
44069 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
44070 @@ -679,7 +679,7 @@ static int sm_metadata_extend(struct dm_space_map *sm, dm_block_t extra_blocks)
44071 * Flick into a mode where all blocks get allocated in the new area.
44072 */
44073 smm->begin = old_len;
44074 - memcpy(sm, &bootstrap_ops, sizeof(*sm));
44075 + memcpy((void *)sm, &bootstrap_ops, sizeof(*sm));
44076
44077 /*
44078 * Extend.
44079 @@ -710,7 +710,7 @@ out:
44080 /*
44081 * Switch back to normal behaviour.
44082 */
44083 - memcpy(sm, &ops, sizeof(*sm));
44084 + memcpy((void *)sm, &ops, sizeof(*sm));
44085 return r;
44086 }
44087
44088 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
44089 index 3e6d115..ffecdeb 100644
44090 --- a/drivers/md/persistent-data/dm-space-map.h
44091 +++ b/drivers/md/persistent-data/dm-space-map.h
44092 @@ -71,6 +71,7 @@ struct dm_space_map {
44093 dm_sm_threshold_fn fn,
44094 void *context);
44095 };
44096 +typedef struct dm_space_map __no_const dm_space_map_no_const;
44097
44098 /*----------------------------------------------------------------*/
44099
44100 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
44101 index 56e24c0..e1c8e1f 100644
44102 --- a/drivers/md/raid1.c
44103 +++ b/drivers/md/raid1.c
44104 @@ -1931,7 +1931,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
44105 if (r1_sync_page_io(rdev, sect, s,
44106 bio->bi_io_vec[idx].bv_page,
44107 READ) != 0)
44108 - atomic_add(s, &rdev->corrected_errors);
44109 + atomic_add_unchecked(s, &rdev->corrected_errors);
44110 }
44111 sectors -= s;
44112 sect += s;
44113 @@ -2165,7 +2165,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
44114 test_bit(In_sync, &rdev->flags)) {
44115 if (r1_sync_page_io(rdev, sect, s,
44116 conf->tmppage, READ)) {
44117 - atomic_add(s, &rdev->corrected_errors);
44118 + atomic_add_unchecked(s, &rdev->corrected_errors);
44119 printk(KERN_INFO
44120 "md/raid1:%s: read error corrected "
44121 "(%d sectors at %llu on %s)\n",
44122 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
44123 index cb882aa..9bd076e 100644
44124 --- a/drivers/md/raid10.c
44125 +++ b/drivers/md/raid10.c
44126 @@ -1949,7 +1949,7 @@ static void end_sync_read(struct bio *bio, int error)
44127 /* The write handler will notice the lack of
44128 * R10BIO_Uptodate and record any errors etc
44129 */
44130 - atomic_add(r10_bio->sectors,
44131 + atomic_add_unchecked(r10_bio->sectors,
44132 &conf->mirrors[d].rdev->corrected_errors);
44133
44134 /* for reconstruct, we always reschedule after a read.
44135 @@ -2307,7 +2307,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44136 {
44137 struct timespec cur_time_mon;
44138 unsigned long hours_since_last;
44139 - unsigned int read_errors = atomic_read(&rdev->read_errors);
44140 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
44141
44142 ktime_get_ts(&cur_time_mon);
44143
44144 @@ -2329,9 +2329,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
44145 * overflowing the shift of read_errors by hours_since_last.
44146 */
44147 if (hours_since_last >= 8 * sizeof(read_errors))
44148 - atomic_set(&rdev->read_errors, 0);
44149 + atomic_set_unchecked(&rdev->read_errors, 0);
44150 else
44151 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
44152 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
44153 }
44154
44155 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
44156 @@ -2385,8 +2385,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44157 return;
44158
44159 check_decay_read_errors(mddev, rdev);
44160 - atomic_inc(&rdev->read_errors);
44161 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
44162 + atomic_inc_unchecked(&rdev->read_errors);
44163 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
44164 char b[BDEVNAME_SIZE];
44165 bdevname(rdev->bdev, b);
44166
44167 @@ -2394,7 +2394,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44168 "md/raid10:%s: %s: Raid device exceeded "
44169 "read_error threshold [cur %d:max %d]\n",
44170 mdname(mddev), b,
44171 - atomic_read(&rdev->read_errors), max_read_errors);
44172 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
44173 printk(KERN_NOTICE
44174 "md/raid10:%s: %s: Failing raid device\n",
44175 mdname(mddev), b);
44176 @@ -2549,7 +2549,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
44177 sect +
44178 choose_data_offset(r10_bio, rdev)),
44179 bdevname(rdev->bdev, b));
44180 - atomic_add(s, &rdev->corrected_errors);
44181 + atomic_add_unchecked(s, &rdev->corrected_errors);
44182 }
44183
44184 rdev_dec_pending(rdev, mddev);
44185 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
44186 index ad1b9be..b417412 100644
44187 --- a/drivers/md/raid5.c
44188 +++ b/drivers/md/raid5.c
44189 @@ -1702,6 +1702,10 @@ static int grow_one_stripe(struct r5conf *conf, int hash)
44190 return 1;
44191 }
44192
44193 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44194 +static atomic_unchecked_t raid5_cache_id = ATOMIC_INIT(0);
44195 +#endif
44196 +
44197 static int grow_stripes(struct r5conf *conf, int num)
44198 {
44199 struct kmem_cache *sc;
44200 @@ -1713,7 +1717,11 @@ static int grow_stripes(struct r5conf *conf, int num)
44201 "raid%d-%s", conf->level, mdname(conf->mddev));
44202 else
44203 sprintf(conf->cache_name[0],
44204 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44205 + "raid%d-%08lx", conf->level, atomic_inc_return_unchecked(&raid5_cache_id));
44206 +#else
44207 "raid%d-%p", conf->level, conf->mddev);
44208 +#endif
44209 sprintf(conf->cache_name[1], "%s-alt", conf->cache_name[0]);
44210
44211 conf->active_name = 0;
44212 @@ -1986,21 +1994,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
44213 mdname(conf->mddev), STRIPE_SECTORS,
44214 (unsigned long long)s,
44215 bdevname(rdev->bdev, b));
44216 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
44217 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
44218 clear_bit(R5_ReadError, &sh->dev[i].flags);
44219 clear_bit(R5_ReWrite, &sh->dev[i].flags);
44220 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
44221 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
44222
44223 - if (atomic_read(&rdev->read_errors))
44224 - atomic_set(&rdev->read_errors, 0);
44225 + if (atomic_read_unchecked(&rdev->read_errors))
44226 + atomic_set_unchecked(&rdev->read_errors, 0);
44227 } else {
44228 const char *bdn = bdevname(rdev->bdev, b);
44229 int retry = 0;
44230 int set_bad = 0;
44231
44232 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
44233 - atomic_inc(&rdev->read_errors);
44234 + atomic_inc_unchecked(&rdev->read_errors);
44235 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
44236 printk_ratelimited(
44237 KERN_WARNING
44238 @@ -2028,7 +2036,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
44239 mdname(conf->mddev),
44240 (unsigned long long)s,
44241 bdn);
44242 - } else if (atomic_read(&rdev->read_errors)
44243 + } else if (atomic_read_unchecked(&rdev->read_errors)
44244 > conf->max_nr_stripes)
44245 printk(KERN_WARNING
44246 "md/raid:%s: Too many read errors, failing device %s.\n",
44247 diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
44248 index 983db75..ef9248c 100644
44249 --- a/drivers/media/dvb-core/dvbdev.c
44250 +++ b/drivers/media/dvb-core/dvbdev.c
44251 @@ -185,7 +185,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
44252 const struct dvb_device *template, void *priv, int type)
44253 {
44254 struct dvb_device *dvbdev;
44255 - struct file_operations *dvbdevfops;
44256 + file_operations_no_const *dvbdevfops;
44257 struct device *clsdev;
44258 int minor;
44259 int id;
44260 diff --git a/drivers/media/dvb-frontends/af9033.h b/drivers/media/dvb-frontends/af9033.h
44261 index 539f4db..cdd403b 100644
44262 --- a/drivers/media/dvb-frontends/af9033.h
44263 +++ b/drivers/media/dvb-frontends/af9033.h
44264 @@ -82,7 +82,7 @@ struct af9033_ops {
44265 int (*pid_filter_ctrl)(struct dvb_frontend *fe, int onoff);
44266 int (*pid_filter)(struct dvb_frontend *fe, int index, u16 pid,
44267 int onoff);
44268 -};
44269 +} __no_const;
44270
44271
44272 #if IS_ENABLED(CONFIG_DVB_AF9033)
44273 diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
44274 index 9b6c3bb..baeb5c7 100644
44275 --- a/drivers/media/dvb-frontends/dib3000.h
44276 +++ b/drivers/media/dvb-frontends/dib3000.h
44277 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
44278 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
44279 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
44280 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
44281 -};
44282 +} __no_const;
44283
44284 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
44285 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
44286 diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
44287 index ed8cb90..5ef7f79 100644
44288 --- a/drivers/media/pci/cx88/cx88-video.c
44289 +++ b/drivers/media/pci/cx88/cx88-video.c
44290 @@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
44291
44292 /* ------------------------------------------------------------------ */
44293
44294 -static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44295 -static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44296 -static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44297 +static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44298 +static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44299 +static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
44300
44301 module_param_array(video_nr, int, NULL, 0444);
44302 module_param_array(vbi_nr, int, NULL, 0444);
44303 diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
44304 index 802642d..5534900 100644
44305 --- a/drivers/media/pci/ivtv/ivtv-driver.c
44306 +++ b/drivers/media/pci/ivtv/ivtv-driver.c
44307 @@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
44308 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
44309
44310 /* ivtv instance counter */
44311 -static atomic_t ivtv_instance = ATOMIC_INIT(0);
44312 +static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
44313
44314 /* Parameter declarations */
44315 static int cardtype[IVTV_MAX_CARDS];
44316 diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
44317 index 9a726ea..f5e9b52 100644
44318 --- a/drivers/media/platform/omap/omap_vout.c
44319 +++ b/drivers/media/platform/omap/omap_vout.c
44320 @@ -63,7 +63,6 @@ enum omap_vout_channels {
44321 OMAP_VIDEO2,
44322 };
44323
44324 -static struct videobuf_queue_ops video_vbq_ops;
44325 /* Variables configurable through module params*/
44326 static u32 video1_numbuffers = 3;
44327 static u32 video2_numbuffers = 3;
44328 @@ -1015,6 +1014,12 @@ static int omap_vout_open(struct file *file)
44329 {
44330 struct videobuf_queue *q;
44331 struct omap_vout_device *vout = NULL;
44332 + static struct videobuf_queue_ops video_vbq_ops = {
44333 + .buf_setup = omap_vout_buffer_setup,
44334 + .buf_prepare = omap_vout_buffer_prepare,
44335 + .buf_release = omap_vout_buffer_release,
44336 + .buf_queue = omap_vout_buffer_queue,
44337 + };
44338
44339 vout = video_drvdata(file);
44340 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
44341 @@ -1032,10 +1037,6 @@ static int omap_vout_open(struct file *file)
44342 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
44343
44344 q = &vout->vbq;
44345 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
44346 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
44347 - video_vbq_ops.buf_release = omap_vout_buffer_release;
44348 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
44349 spin_lock_init(&vout->vbq_lock);
44350
44351 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
44352 diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
44353 index fb2acc5..a2fcbdc4 100644
44354 --- a/drivers/media/platform/s5p-tv/mixer.h
44355 +++ b/drivers/media/platform/s5p-tv/mixer.h
44356 @@ -156,7 +156,7 @@ struct mxr_layer {
44357 /** layer index (unique identifier) */
44358 int idx;
44359 /** callbacks for layer methods */
44360 - struct mxr_layer_ops ops;
44361 + struct mxr_layer_ops *ops;
44362 /** format array */
44363 const struct mxr_format **fmt_array;
44364 /** size of format array */
44365 diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44366 index 74344c7..a39e70e 100644
44367 --- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44368 +++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
44369 @@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
44370 {
44371 struct mxr_layer *layer;
44372 int ret;
44373 - struct mxr_layer_ops ops = {
44374 + static struct mxr_layer_ops ops = {
44375 .release = mxr_graph_layer_release,
44376 .buffer_set = mxr_graph_buffer_set,
44377 .stream_set = mxr_graph_stream_set,
44378 diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
44379 index b713403..53cb5ad 100644
44380 --- a/drivers/media/platform/s5p-tv/mixer_reg.c
44381 +++ b/drivers/media/platform/s5p-tv/mixer_reg.c
44382 @@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
44383 layer->update_buf = next;
44384 }
44385
44386 - layer->ops.buffer_set(layer, layer->update_buf);
44387 + layer->ops->buffer_set(layer, layer->update_buf);
44388
44389 if (done && done != layer->shadow_buf)
44390 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
44391 diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
44392 index a1ce55f..4a3c4d9 100644
44393 --- a/drivers/media/platform/s5p-tv/mixer_video.c
44394 +++ b/drivers/media/platform/s5p-tv/mixer_video.c
44395 @@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
44396 layer->geo.src.height = layer->geo.src.full_height;
44397
44398 mxr_geometry_dump(mdev, &layer->geo);
44399 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44400 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44401 mxr_geometry_dump(mdev, &layer->geo);
44402 }
44403
44404 @@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
44405 layer->geo.dst.full_width = mbus_fmt.width;
44406 layer->geo.dst.full_height = mbus_fmt.height;
44407 layer->geo.dst.field = mbus_fmt.field;
44408 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44409 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
44410
44411 mxr_geometry_dump(mdev, &layer->geo);
44412 }
44413 @@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
44414 /* set source size to highest accepted value */
44415 geo->src.full_width = max(geo->dst.full_width, pix->width);
44416 geo->src.full_height = max(geo->dst.full_height, pix->height);
44417 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44418 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44419 mxr_geometry_dump(mdev, &layer->geo);
44420 /* set cropping to total visible screen */
44421 geo->src.width = pix->width;
44422 @@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
44423 geo->src.x_offset = 0;
44424 geo->src.y_offset = 0;
44425 /* assure consistency of geometry */
44426 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
44427 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
44428 mxr_geometry_dump(mdev, &layer->geo);
44429 /* set full size to lowest possible value */
44430 geo->src.full_width = 0;
44431 geo->src.full_height = 0;
44432 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44433 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
44434 mxr_geometry_dump(mdev, &layer->geo);
44435
44436 /* returning results */
44437 @@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
44438 target->width = s->r.width;
44439 target->height = s->r.height;
44440
44441 - layer->ops.fix_geometry(layer, stage, s->flags);
44442 + layer->ops->fix_geometry(layer, stage, s->flags);
44443
44444 /* retrieve update selection rectangle */
44445 res.left = target->x_offset;
44446 @@ -950,13 +950,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
44447 mxr_output_get(mdev);
44448
44449 mxr_layer_update_output(layer);
44450 - layer->ops.format_set(layer);
44451 + layer->ops->format_set(layer);
44452 /* enabling layer in hardware */
44453 spin_lock_irqsave(&layer->enq_slock, flags);
44454 layer->state = MXR_LAYER_STREAMING;
44455 spin_unlock_irqrestore(&layer->enq_slock, flags);
44456
44457 - layer->ops.stream_set(layer, MXR_ENABLE);
44458 + layer->ops->stream_set(layer, MXR_ENABLE);
44459 mxr_streamer_get(mdev);
44460
44461 return 0;
44462 @@ -1026,7 +1026,7 @@ static int stop_streaming(struct vb2_queue *vq)
44463 spin_unlock_irqrestore(&layer->enq_slock, flags);
44464
44465 /* disabling layer in hardware */
44466 - layer->ops.stream_set(layer, MXR_DISABLE);
44467 + layer->ops->stream_set(layer, MXR_DISABLE);
44468 /* remove one streamer */
44469 mxr_streamer_put(mdev);
44470 /* allow changes in output configuration */
44471 @@ -1065,8 +1065,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
44472
44473 void mxr_layer_release(struct mxr_layer *layer)
44474 {
44475 - if (layer->ops.release)
44476 - layer->ops.release(layer);
44477 + if (layer->ops->release)
44478 + layer->ops->release(layer);
44479 }
44480
44481 void mxr_base_layer_release(struct mxr_layer *layer)
44482 @@ -1092,7 +1092,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
44483
44484 layer->mdev = mdev;
44485 layer->idx = idx;
44486 - layer->ops = *ops;
44487 + layer->ops = ops;
44488
44489 spin_lock_init(&layer->enq_slock);
44490 INIT_LIST_HEAD(&layer->enq_list);
44491 diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44492 index c9388c4..ce71ece 100644
44493 --- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44494 +++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
44495 @@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
44496 {
44497 struct mxr_layer *layer;
44498 int ret;
44499 - struct mxr_layer_ops ops = {
44500 + static struct mxr_layer_ops ops = {
44501 .release = mxr_vp_layer_release,
44502 .buffer_set = mxr_vp_buffer_set,
44503 .stream_set = mxr_vp_stream_set,
44504 diff --git a/drivers/media/platform/vivi.c b/drivers/media/platform/vivi.c
44505 index 3890f4f..b5c7511 100644
44506 --- a/drivers/media/platform/vivi.c
44507 +++ b/drivers/media/platform/vivi.c
44508 @@ -58,8 +58,8 @@ MODULE_AUTHOR("Mauro Carvalho Chehab, Ted Walther and John Sokol");
44509 MODULE_LICENSE("Dual BSD/GPL");
44510 MODULE_VERSION(VIVI_VERSION);
44511
44512 -static unsigned video_nr = -1;
44513 -module_param(video_nr, uint, 0644);
44514 +static int video_nr = -1;
44515 +module_param(video_nr, int, 0644);
44516 MODULE_PARM_DESC(video_nr, "videoX start number, -1 is autodetect");
44517
44518 static unsigned n_devs = 1;
44519 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
44520 index d719e59..63f3470 100644
44521 --- a/drivers/media/radio/radio-cadet.c
44522 +++ b/drivers/media/radio/radio-cadet.c
44523 @@ -333,6 +333,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
44524 unsigned char readbuf[RDS_BUFFER];
44525 int i = 0;
44526
44527 + if (count > RDS_BUFFER)
44528 + return -EFAULT;
44529 mutex_lock(&dev->lock);
44530 if (dev->rdsstat == 0)
44531 cadet_start_rds(dev);
44532 @@ -349,8 +351,9 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
44533 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
44534 mutex_unlock(&dev->lock);
44535
44536 - if (i && copy_to_user(data, readbuf, i))
44537 - return -EFAULT;
44538 + if (i > sizeof(readbuf) || (i && copy_to_user(data, readbuf, i)))
44539 + i = -EFAULT;
44540 +
44541 return i;
44542 }
44543
44544 diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
44545 index 5236035..c622c74 100644
44546 --- a/drivers/media/radio/radio-maxiradio.c
44547 +++ b/drivers/media/radio/radio-maxiradio.c
44548 @@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
44549 /* TEA5757 pin mappings */
44550 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
44551
44552 -static atomic_t maxiradio_instance = ATOMIC_INIT(0);
44553 +static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
44554
44555 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
44556 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
44557 diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
44558 index 050b3bb..79f62b9 100644
44559 --- a/drivers/media/radio/radio-shark.c
44560 +++ b/drivers/media/radio/radio-shark.c
44561 @@ -79,7 +79,7 @@ struct shark_device {
44562 u32 last_val;
44563 };
44564
44565 -static atomic_t shark_instance = ATOMIC_INIT(0);
44566 +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
44567
44568 static void shark_write_val(struct snd_tea575x *tea, u32 val)
44569 {
44570 diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
44571 index 8654e0d..0608a64 100644
44572 --- a/drivers/media/radio/radio-shark2.c
44573 +++ b/drivers/media/radio/radio-shark2.c
44574 @@ -74,7 +74,7 @@ struct shark_device {
44575 u8 *transfer_buffer;
44576 };
44577
44578 -static atomic_t shark_instance = ATOMIC_INIT(0);
44579 +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
44580
44581 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
44582 {
44583 diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
44584 index 2fd9009..278cc1e 100644
44585 --- a/drivers/media/radio/radio-si476x.c
44586 +++ b/drivers/media/radio/radio-si476x.c
44587 @@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
44588 struct si476x_radio *radio;
44589 struct v4l2_ctrl *ctrl;
44590
44591 - static atomic_t instance = ATOMIC_INIT(0);
44592 + static atomic_unchecked_t instance = ATOMIC_INIT(0);
44593
44594 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
44595 if (!radio)
44596 diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
44597 index a1c641e..3007da9 100644
44598 --- a/drivers/media/usb/dvb-usb/cxusb.c
44599 +++ b/drivers/media/usb/dvb-usb/cxusb.c
44600 @@ -1112,7 +1112,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
44601
44602 struct dib0700_adapter_state {
44603 int (*set_param_save) (struct dvb_frontend *);
44604 -};
44605 +} __no_const;
44606
44607 static int dib7070_set_param_override(struct dvb_frontend *fe)
44608 {
44609 diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
44610 index ae0f56a..ec71784 100644
44611 --- a/drivers/media/usb/dvb-usb/dw2102.c
44612 +++ b/drivers/media/usb/dvb-usb/dw2102.c
44613 @@ -118,7 +118,7 @@ struct su3000_state {
44614
44615 struct s6x0_state {
44616 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
44617 -};
44618 +} __no_const;
44619
44620 /* debug */
44621 static int dvb_usb_dw2102_debug;
44622 diff --git a/drivers/media/usb/dvb-usb/technisat-usb2.c b/drivers/media/usb/dvb-usb/technisat-usb2.c
44623 index 98d24ae..33a8050 100644
44624 --- a/drivers/media/usb/dvb-usb/technisat-usb2.c
44625 +++ b/drivers/media/usb/dvb-usb/technisat-usb2.c
44626 @@ -224,14 +224,16 @@ static int technisat_usb2_set_led(struct dvb_usb_device *d, int red, enum techni
44627 {
44628 int ret;
44629
44630 - u8 led[8] = {
44631 - red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST,
44632 - 0
44633 - };
44634 + u8 *led = kzalloc(8, GFP_KERNEL);
44635 +
44636 + if (led == NULL)
44637 + return -ENOMEM;
44638
44639 if (disable_led_control && state != LED_OFF)
44640 return 0;
44641
44642 + led[0] = red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST;
44643 +
44644 switch (state) {
44645 case LED_ON:
44646 led[1] = 0x82;
44647 @@ -263,16 +265,22 @@ static int technisat_usb2_set_led(struct dvb_usb_device *d, int red, enum techni
44648 red ? SET_RED_LED_VENDOR_REQUEST : SET_GREEN_LED_VENDOR_REQUEST,
44649 USB_TYPE_VENDOR | USB_DIR_OUT,
44650 0, 0,
44651 - led, sizeof(led), 500);
44652 + led, 8, 500);
44653
44654 mutex_unlock(&d->i2c_mutex);
44655 +
44656 + kfree(led);
44657 +
44658 return ret;
44659 }
44660
44661 static int technisat_usb2_set_led_timer(struct dvb_usb_device *d, u8 red, u8 green)
44662 {
44663 int ret;
44664 - u8 b = 0;
44665 + u8 *b = kzalloc(1, GFP_KERNEL);
44666 +
44667 + if (b == NULL)
44668 + return -ENOMEM;
44669
44670 if (mutex_lock_interruptible(&d->i2c_mutex) < 0)
44671 return -EAGAIN;
44672 @@ -281,10 +289,12 @@ static int technisat_usb2_set_led_timer(struct dvb_usb_device *d, u8 red, u8 gre
44673 SET_LED_TIMER_DIVIDER_VENDOR_REQUEST,
44674 USB_TYPE_VENDOR | USB_DIR_OUT,
44675 (red << 8) | green, 0,
44676 - &b, 1, 500);
44677 + b, 1, 500);
44678
44679 mutex_unlock(&d->i2c_mutex);
44680
44681 + kfree(b);
44682 +
44683 return ret;
44684 }
44685
44686 @@ -328,7 +338,7 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
44687 struct dvb_usb_device_description **desc, int *cold)
44688 {
44689 int ret;
44690 - u8 version[3];
44691 + u8 *version = kmalloc(3, GFP_KERNEL);
44692
44693 /* first select the interface */
44694 if (usb_set_interface(udev, 0, 1) != 0)
44695 @@ -338,11 +348,14 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
44696
44697 *cold = 0; /* by default do not download a firmware - just in case something is wrong */
44698
44699 + if (version == NULL)
44700 + return 0;
44701 +
44702 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
44703 GET_VERSION_INFO_VENDOR_REQUEST,
44704 USB_TYPE_VENDOR | USB_DIR_IN,
44705 0, 0,
44706 - version, sizeof(version), 500);
44707 + version, 3, 500);
44708
44709 if (ret < 0)
44710 *cold = 1;
44711 @@ -351,6 +364,8 @@ static int technisat_usb2_identify_state(struct usb_device *udev,
44712 *cold = 0;
44713 }
44714
44715 + kfree(version);
44716 +
44717 return 0;
44718 }
44719
44720 @@ -591,10 +606,15 @@ static int technisat_usb2_frontend_attach(struct dvb_usb_adapter *a)
44721
44722 static int technisat_usb2_get_ir(struct dvb_usb_device *d)
44723 {
44724 - u8 buf[62], *b;
44725 + u8 *buf, *b;
44726 int ret;
44727 struct ir_raw_event ev;
44728
44729 + buf = kmalloc(62, GFP_KERNEL);
44730 +
44731 + if (buf == NULL)
44732 + return -ENOMEM;
44733 +
44734 buf[0] = GET_IR_DATA_VENDOR_REQUEST;
44735 buf[1] = 0x08;
44736 buf[2] = 0x8f;
44737 @@ -617,16 +637,20 @@ static int technisat_usb2_get_ir(struct dvb_usb_device *d)
44738 GET_IR_DATA_VENDOR_REQUEST,
44739 USB_TYPE_VENDOR | USB_DIR_IN,
44740 0x8080, 0,
44741 - buf, sizeof(buf), 500);
44742 + buf, 62, 500);
44743
44744 unlock:
44745 mutex_unlock(&d->i2c_mutex);
44746
44747 - if (ret < 0)
44748 + if (ret < 0) {
44749 + kfree(buf);
44750 return ret;
44751 + }
44752
44753 - if (ret == 1)
44754 + if (ret == 1) {
44755 + kfree(buf);
44756 return 0; /* no key pressed */
44757 + }
44758
44759 /* decoding */
44760 b = buf+1;
44761 @@ -653,6 +677,8 @@ unlock:
44762
44763 ir_raw_event_handle(d->rc_dev);
44764
44765 + kfree(buf);
44766 +
44767 return 1;
44768 }
44769
44770 diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
44771 index 7e2411c..cef73ca 100644
44772 --- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
44773 +++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
44774 @@ -328,7 +328,7 @@ struct v4l2_buffer32 {
44775 __u32 reserved;
44776 };
44777
44778 -static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
44779 +static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
44780 enum v4l2_memory memory)
44781 {
44782 void __user *up_pln;
44783 @@ -357,7 +357,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
44784 return 0;
44785 }
44786
44787 -static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
44788 +static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
44789 enum v4l2_memory memory)
44790 {
44791 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
44792 @@ -427,7 +427,7 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
44793 * by passing a very big num_planes value */
44794 uplane = compat_alloc_user_space(num_planes *
44795 sizeof(struct v4l2_plane));
44796 - kp->m.planes = uplane;
44797 + kp->m.planes = (struct v4l2_plane __force_kernel *)uplane;
44798
44799 while (--num_planes >= 0) {
44800 ret = get_v4l2_plane32(uplane, uplane32, kp->memory);
44801 @@ -498,7 +498,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
44802 if (num_planes == 0)
44803 return 0;
44804
44805 - uplane = kp->m.planes;
44806 + uplane = (struct v4l2_plane __force_user *)kp->m.planes;
44807 if (get_user(p, &up->m.planes))
44808 return -EFAULT;
44809 uplane32 = compat_ptr(p);
44810 @@ -552,7 +552,7 @@ static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_frame
44811 get_user(kp->capability, &up->capability) ||
44812 get_user(kp->flags, &up->flags))
44813 return -EFAULT;
44814 - kp->base = compat_ptr(tmp);
44815 + kp->base = (void __force_kernel *)compat_ptr(tmp);
44816 get_v4l2_pix_format(&kp->fmt, &up->fmt);
44817 return 0;
44818 }
44819 @@ -658,7 +658,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
44820 n * sizeof(struct v4l2_ext_control32)))
44821 return -EFAULT;
44822 kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control));
44823 - kp->controls = kcontrols;
44824 + kp->controls = (struct v4l2_ext_control __force_kernel *)kcontrols;
44825 while (--n >= 0) {
44826 if (copy_in_user(kcontrols, ucontrols, sizeof(*ucontrols)))
44827 return -EFAULT;
44828 @@ -680,7 +680,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
44829 static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up)
44830 {
44831 struct v4l2_ext_control32 __user *ucontrols;
44832 - struct v4l2_ext_control __user *kcontrols = kp->controls;
44833 + struct v4l2_ext_control __user *kcontrols = (struct v4l2_ext_control __force_user *)kp->controls;
44834 int n = kp->count;
44835 compat_caddr_t p;
44836
44837 @@ -774,7 +774,7 @@ static int put_v4l2_edid32(struct v4l2_edid *kp, struct v4l2_edid32 __user *up)
44838 put_user(kp->start_block, &up->start_block) ||
44839 put_user(kp->blocks, &up->blocks) ||
44840 put_user(tmp, &up->edid) ||
44841 - copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
44842 + copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
44843 return -EFAULT;
44844 return 0;
44845 }
44846 diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c
44847 index 55c6832..a91c7a6 100644
44848 --- a/drivers/media/v4l2-core/v4l2-ctrls.c
44849 +++ b/drivers/media/v4l2-core/v4l2-ctrls.c
44850 @@ -1431,8 +1431,8 @@ static int validate_new(const struct v4l2_ctrl *ctrl,
44851 return 0;
44852
44853 case V4L2_CTRL_TYPE_STRING:
44854 - len = strlen(c->string);
44855 - if (len < ctrl->minimum)
44856 + len = strlen_user(c->string);
44857 + if (!len || len < ctrl->minimum)
44858 return -ERANGE;
44859 if ((len - ctrl->minimum) % ctrl->step)
44860 return -ERANGE;
44861 diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
44862 index 02d1b63..5fd6b16 100644
44863 --- a/drivers/media/v4l2-core/v4l2-device.c
44864 +++ b/drivers/media/v4l2-core/v4l2-device.c
44865 @@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
44866 EXPORT_SYMBOL_GPL(v4l2_device_put);
44867
44868 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
44869 - atomic_t *instance)
44870 + atomic_unchecked_t *instance)
44871 {
44872 - int num = atomic_inc_return(instance) - 1;
44873 + int num = atomic_inc_return_unchecked(instance) - 1;
44874 int len = strlen(basename);
44875
44876 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
44877 diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
44878 index d9113cc..7de6ccc 100644
44879 --- a/drivers/media/v4l2-core/v4l2-ioctl.c
44880 +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
44881 @@ -2003,7 +2003,8 @@ struct v4l2_ioctl_info {
44882 struct file *file, void *fh, void *p);
44883 } u;
44884 void (*debug)(const void *arg, bool write_only);
44885 -};
44886 +} __do_const;
44887 +typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
44888
44889 /* This control needs a priority check */
44890 #define INFO_FL_PRIO (1 << 0)
44891 @@ -2186,7 +2187,7 @@ static long __video_do_ioctl(struct file *file,
44892 struct video_device *vfd = video_devdata(file);
44893 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
44894 bool write_only = false;
44895 - struct v4l2_ioctl_info default_info;
44896 + v4l2_ioctl_info_no_const default_info;
44897 const struct v4l2_ioctl_info *info;
44898 void *fh = file->private_data;
44899 struct v4l2_fh *vfh = NULL;
44900 @@ -2260,7 +2261,7 @@ done:
44901 }
44902
44903 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44904 - void * __user *user_ptr, void ***kernel_ptr)
44905 + void __user **user_ptr, void ***kernel_ptr)
44906 {
44907 int ret = 0;
44908
44909 @@ -2276,7 +2277,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44910 ret = -EINVAL;
44911 break;
44912 }
44913 - *user_ptr = (void __user *)buf->m.planes;
44914 + *user_ptr = (void __force_user *)buf->m.planes;
44915 *kernel_ptr = (void *)&buf->m.planes;
44916 *array_size = sizeof(struct v4l2_plane) * buf->length;
44917 ret = 1;
44918 @@ -2311,7 +2312,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44919 ret = -EINVAL;
44920 break;
44921 }
44922 - *user_ptr = (void __user *)ctrls->controls;
44923 + *user_ptr = (void __force_user *)ctrls->controls;
44924 *kernel_ptr = (void *)&ctrls->controls;
44925 *array_size = sizeof(struct v4l2_ext_control)
44926 * ctrls->count;
44927 @@ -2412,7 +2413,7 @@ video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
44928 }
44929
44930 if (has_array_args) {
44931 - *kernel_ptr = user_ptr;
44932 + *kernel_ptr = (void __force_kernel *)user_ptr;
44933 if (copy_to_user(user_ptr, mbuf, array_size))
44934 err = -EFAULT;
44935 goto out_array_args;
44936 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
44937 index 570b18a..f880314 100644
44938 --- a/drivers/message/fusion/mptbase.c
44939 +++ b/drivers/message/fusion/mptbase.c
44940 @@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
44941 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
44942 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
44943
44944 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44945 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
44946 +#else
44947 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
44948 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
44949 +#endif
44950 +
44951 /*
44952 * Rounding UP to nearest 4-kB boundary here...
44953 */
44954 @@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
44955 ioc->facts.GlobalCredits);
44956
44957 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
44958 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44959 + NULL, NULL);
44960 +#else
44961 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
44962 +#endif
44963 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
44964 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
44965 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
44966 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
44967 index 00d339c..2ea899d 100644
44968 --- a/drivers/message/fusion/mptsas.c
44969 +++ b/drivers/message/fusion/mptsas.c
44970 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
44971 return 0;
44972 }
44973
44974 +static inline void
44975 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
44976 +{
44977 + if (phy_info->port_details) {
44978 + phy_info->port_details->rphy = rphy;
44979 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
44980 + ioc->name, rphy));
44981 + }
44982 +
44983 + if (rphy) {
44984 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
44985 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
44986 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
44987 + ioc->name, rphy, rphy->dev.release));
44988 + }
44989 +}
44990 +
44991 /* no mutex */
44992 static void
44993 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
44994 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
44995 return NULL;
44996 }
44997
44998 -static inline void
44999 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
45000 -{
45001 - if (phy_info->port_details) {
45002 - phy_info->port_details->rphy = rphy;
45003 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
45004 - ioc->name, rphy));
45005 - }
45006 -
45007 - if (rphy) {
45008 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
45009 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
45010 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
45011 - ioc->name, rphy, rphy->dev.release));
45012 - }
45013 -}
45014 -
45015 static inline struct sas_port *
45016 mptsas_get_port(struct mptsas_phyinfo *phy_info)
45017 {
45018 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
45019 index 727819c..ad74694 100644
45020 --- a/drivers/message/fusion/mptscsih.c
45021 +++ b/drivers/message/fusion/mptscsih.c
45022 @@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
45023
45024 h = shost_priv(SChost);
45025
45026 - if (h) {
45027 - if (h->info_kbuf == NULL)
45028 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
45029 - return h->info_kbuf;
45030 - h->info_kbuf[0] = '\0';
45031 + if (!h)
45032 + return NULL;
45033
45034 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
45035 - h->info_kbuf[size-1] = '\0';
45036 - }
45037 + if (h->info_kbuf == NULL)
45038 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
45039 + return h->info_kbuf;
45040 + h->info_kbuf[0] = '\0';
45041 +
45042 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
45043 + h->info_kbuf[size-1] = '\0';
45044
45045 return h->info_kbuf;
45046 }
45047 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
45048 index b7d87cd..3fb36da 100644
45049 --- a/drivers/message/i2o/i2o_proc.c
45050 +++ b/drivers/message/i2o/i2o_proc.c
45051 @@ -255,12 +255,6 @@ static char *scsi_devices[] = {
45052 "Array Controller Device"
45053 };
45054
45055 -static char *chtostr(char *tmp, u8 *chars, int n)
45056 -{
45057 - tmp[0] = 0;
45058 - return strncat(tmp, (char *)chars, n);
45059 -}
45060 -
45061 static int i2o_report_query_status(struct seq_file *seq, int block_status,
45062 char *group)
45063 {
45064 @@ -707,9 +701,9 @@ static int i2o_seq_show_status(struct seq_file *seq, void *v)
45065 static int i2o_seq_show_hw(struct seq_file *seq, void *v)
45066 {
45067 struct i2o_controller *c = (struct i2o_controller *)seq->private;
45068 - static u32 work32[5];
45069 - static u8 *work8 = (u8 *) work32;
45070 - static u16 *work16 = (u16 *) work32;
45071 + u32 work32[5];
45072 + u8 *work8 = (u8 *) work32;
45073 + u16 *work16 = (u16 *) work32;
45074 int token;
45075 u32 hwcap;
45076
45077 @@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
45078 } *result;
45079
45080 i2o_exec_execute_ddm_table ddm_table;
45081 - char tmp[28 + 1];
45082
45083 result = kmalloc(sizeof(*result), GFP_KERNEL);
45084 if (!result)
45085 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
45086
45087 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
45088 seq_printf(seq, "%-#8x", ddm_table.module_id);
45089 - seq_printf(seq, "%-29s",
45090 - chtostr(tmp, ddm_table.module_name_version, 28));
45091 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
45092 seq_printf(seq, "%9d ", ddm_table.data_size);
45093 seq_printf(seq, "%8d", ddm_table.code_size);
45094
45095 @@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
45096
45097 i2o_driver_result_table *result;
45098 i2o_driver_store_table *dst;
45099 - char tmp[28 + 1];
45100
45101 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
45102 if (result == NULL)
45103 @@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
45104
45105 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
45106 seq_printf(seq, "%-#8x", dst->module_id);
45107 - seq_printf(seq, "%-29s",
45108 - chtostr(tmp, dst->module_name_version, 28));
45109 - seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
45110 + seq_printf(seq, "%-.28s", dst->module_name_version);
45111 + seq_printf(seq, "%-.8s", dst->date);
45112 seq_printf(seq, "%8d ", dst->module_size);
45113 seq_printf(seq, "%8d ", dst->mpb_size);
45114 seq_printf(seq, "0x%04x", dst->module_flags);
45115 @@ -1246,11 +1236,10 @@ static int i2o_seq_show_authorized_users(struct seq_file *seq, void *v)
45116 static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
45117 {
45118 struct i2o_device *d = (struct i2o_device *)seq->private;
45119 - static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
45120 + u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
45121 // == (allow) 512d bytes (max)
45122 - static u16 *work16 = (u16 *) work32;
45123 + u16 *work16 = (u16 *) work32;
45124 int token;
45125 - char tmp[16 + 1];
45126
45127 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
45128
45129 @@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
45130 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
45131 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
45132 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
45133 - seq_printf(seq, "Vendor info : %s\n",
45134 - chtostr(tmp, (u8 *) (work32 + 2), 16));
45135 - seq_printf(seq, "Product info : %s\n",
45136 - chtostr(tmp, (u8 *) (work32 + 6), 16));
45137 - seq_printf(seq, "Description : %s\n",
45138 - chtostr(tmp, (u8 *) (work32 + 10), 16));
45139 - seq_printf(seq, "Product rev. : %s\n",
45140 - chtostr(tmp, (u8 *) (work32 + 14), 8));
45141 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
45142 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
45143 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
45144 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
45145
45146 seq_printf(seq, "Serial number : ");
45147 print_serial_number(seq, (u8 *) (work32 + 16),
45148 @@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
45149 u8 pad[256]; // allow up to 256 byte (max) serial number
45150 } result;
45151
45152 - char tmp[24 + 1];
45153 -
45154 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
45155
45156 if (token < 0) {
45157 @@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
45158 }
45159
45160 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
45161 - seq_printf(seq, "Module name : %s\n",
45162 - chtostr(tmp, result.module_name, 24));
45163 - seq_printf(seq, "Module revision : %s\n",
45164 - chtostr(tmp, result.module_rev, 8));
45165 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
45166 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
45167
45168 seq_printf(seq, "Serial number : ");
45169 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
45170 @@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
45171 u8 instance_number[4];
45172 } result;
45173
45174 - char tmp[64 + 1];
45175 -
45176 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
45177
45178 if (token < 0) {
45179 @@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
45180 return 0;
45181 }
45182
45183 - seq_printf(seq, "Device name : %s\n",
45184 - chtostr(tmp, result.device_name, 64));
45185 - seq_printf(seq, "Service name : %s\n",
45186 - chtostr(tmp, result.service_name, 64));
45187 - seq_printf(seq, "Physical name : %s\n",
45188 - chtostr(tmp, result.physical_location, 64));
45189 - seq_printf(seq, "Instance number : %s\n",
45190 - chtostr(tmp, result.instance_number, 4));
45191 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
45192 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
45193 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
45194 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
45195
45196 return 0;
45197 }
45198 @@ -1368,9 +1343,9 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
45199 static int i2o_seq_show_sgl_limits(struct seq_file *seq, void *v)
45200 {
45201 struct i2o_device *d = (struct i2o_device *)seq->private;
45202 - static u32 work32[12];
45203 - static u16 *work16 = (u16 *) work32;
45204 - static u8 *work8 = (u8 *) work32;
45205 + u32 work32[12];
45206 + u16 *work16 = (u16 *) work32;
45207 + u8 *work8 = (u8 *) work32;
45208 int token;
45209
45210 token = i2o_parm_field_get(d, 0xF103, -1, &work32, sizeof(work32));
45211 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
45212 index 92752fb..a7494f6 100644
45213 --- a/drivers/message/i2o/iop.c
45214 +++ b/drivers/message/i2o/iop.c
45215 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
45216
45217 spin_lock_irqsave(&c->context_list_lock, flags);
45218
45219 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
45220 - atomic_inc(&c->context_list_counter);
45221 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
45222 + atomic_inc_unchecked(&c->context_list_counter);
45223
45224 - entry->context = atomic_read(&c->context_list_counter);
45225 + entry->context = atomic_read_unchecked(&c->context_list_counter);
45226
45227 list_add(&entry->list, &c->context_list);
45228
45229 @@ -1076,7 +1076,7 @@ struct i2o_controller *i2o_iop_alloc(void)
45230
45231 #if BITS_PER_LONG == 64
45232 spin_lock_init(&c->context_list_lock);
45233 - atomic_set(&c->context_list_counter, 0);
45234 + atomic_set_unchecked(&c->context_list_counter, 0);
45235 INIT_LIST_HEAD(&c->context_list);
45236 #endif
45237
45238 diff --git a/drivers/mfd/ab8500-debugfs.c b/drivers/mfd/ab8500-debugfs.c
45239 index d1a22aa..d0f7bf7 100644
45240 --- a/drivers/mfd/ab8500-debugfs.c
45241 +++ b/drivers/mfd/ab8500-debugfs.c
45242 @@ -100,7 +100,7 @@ static int irq_last;
45243 static u32 *irq_count;
45244 static int num_irqs;
45245
45246 -static struct device_attribute **dev_attr;
45247 +static device_attribute_no_const **dev_attr;
45248 static char **event_name;
45249
45250 static u8 avg_sample = SAMPLE_16;
45251 diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
45252 index a83eed5..62a58a9 100644
45253 --- a/drivers/mfd/max8925-i2c.c
45254 +++ b/drivers/mfd/max8925-i2c.c
45255 @@ -152,7 +152,7 @@ static int max8925_probe(struct i2c_client *client,
45256 const struct i2c_device_id *id)
45257 {
45258 struct max8925_platform_data *pdata = dev_get_platdata(&client->dev);
45259 - static struct max8925_chip *chip;
45260 + struct max8925_chip *chip;
45261 struct device_node *node = client->dev.of_node;
45262
45263 if (node && !pdata) {
45264 diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
45265 index 460a014..21d3061 100644
45266 --- a/drivers/mfd/tps65910.c
45267 +++ b/drivers/mfd/tps65910.c
45268 @@ -230,7 +230,7 @@ static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
45269 struct tps65910_platform_data *pdata)
45270 {
45271 int ret = 0;
45272 - static struct regmap_irq_chip *tps6591x_irqs_chip;
45273 + struct regmap_irq_chip *tps6591x_irqs_chip;
45274
45275 if (!irq) {
45276 dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
45277 diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
45278 index 596b1f6..5b6ab74 100644
45279 --- a/drivers/mfd/twl4030-irq.c
45280 +++ b/drivers/mfd/twl4030-irq.c
45281 @@ -34,6 +34,7 @@
45282 #include <linux/of.h>
45283 #include <linux/irqdomain.h>
45284 #include <linux/i2c/twl.h>
45285 +#include <asm/pgtable.h>
45286
45287 #include "twl-core.h"
45288
45289 @@ -725,10 +726,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
45290 * Install an irq handler for each of the SIH modules;
45291 * clone dummy irq_chip since PIH can't *do* anything
45292 */
45293 - twl4030_irq_chip = dummy_irq_chip;
45294 - twl4030_irq_chip.name = "twl4030";
45295 + pax_open_kernel();
45296 + memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
45297 + *(const char **)&twl4030_irq_chip.name = "twl4030";
45298
45299 - twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
45300 + *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
45301 + pax_close_kernel();
45302
45303 for (i = irq_base; i < irq_end; i++) {
45304 irq_set_chip_and_handler(i, &twl4030_irq_chip,
45305 diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
45306 index 464419b..64bae8d 100644
45307 --- a/drivers/misc/c2port/core.c
45308 +++ b/drivers/misc/c2port/core.c
45309 @@ -922,7 +922,9 @@ struct c2port_device *c2port_device_register(char *name,
45310 goto error_idr_alloc;
45311 c2dev->id = ret;
45312
45313 - bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
45314 + pax_open_kernel();
45315 + *(size_t *)&bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
45316 + pax_close_kernel();
45317
45318 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
45319 "c2port%d", c2dev->id);
45320 diff --git a/drivers/misc/eeprom/sunxi_sid.c b/drivers/misc/eeprom/sunxi_sid.c
45321 index 3f2b625..945e179 100644
45322 --- a/drivers/misc/eeprom/sunxi_sid.c
45323 +++ b/drivers/misc/eeprom/sunxi_sid.c
45324 @@ -126,7 +126,9 @@ static int sunxi_sid_probe(struct platform_device *pdev)
45325
45326 platform_set_drvdata(pdev, sid_data);
45327
45328 - sid_bin_attr.size = sid_data->keysize;
45329 + pax_open_kernel();
45330 + *(size_t *)&sid_bin_attr.size = sid_data->keysize;
45331 + pax_close_kernel();
45332 if (device_create_bin_file(&pdev->dev, &sid_bin_attr))
45333 return -ENODEV;
45334
45335 diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
45336 index 36f5d52..32311c3 100644
45337 --- a/drivers/misc/kgdbts.c
45338 +++ b/drivers/misc/kgdbts.c
45339 @@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
45340 char before[BREAK_INSTR_SIZE];
45341 char after[BREAK_INSTR_SIZE];
45342
45343 - probe_kernel_read(before, (char *)kgdbts_break_test,
45344 + probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
45345 BREAK_INSTR_SIZE);
45346 init_simple_test();
45347 ts.tst = plant_and_detach_test;
45348 @@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
45349 /* Activate test with initial breakpoint */
45350 if (!is_early)
45351 kgdb_breakpoint();
45352 - probe_kernel_read(after, (char *)kgdbts_break_test,
45353 + probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
45354 BREAK_INSTR_SIZE);
45355 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
45356 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
45357 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
45358 index 3ef4627..8d00486 100644
45359 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
45360 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
45361 @@ -497,7 +497,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
45362 * the lid is closed. This leads to interrupts as soon as a little move
45363 * is done.
45364 */
45365 - atomic_inc(&lis3->count);
45366 + atomic_inc_unchecked(&lis3->count);
45367
45368 wake_up_interruptible(&lis3->misc_wait);
45369 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
45370 @@ -583,7 +583,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
45371 if (lis3->pm_dev)
45372 pm_runtime_get_sync(lis3->pm_dev);
45373
45374 - atomic_set(&lis3->count, 0);
45375 + atomic_set_unchecked(&lis3->count, 0);
45376 return 0;
45377 }
45378
45379 @@ -615,7 +615,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
45380 add_wait_queue(&lis3->misc_wait, &wait);
45381 while (true) {
45382 set_current_state(TASK_INTERRUPTIBLE);
45383 - data = atomic_xchg(&lis3->count, 0);
45384 + data = atomic_xchg_unchecked(&lis3->count, 0);
45385 if (data)
45386 break;
45387
45388 @@ -656,7 +656,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
45389 struct lis3lv02d, miscdev);
45390
45391 poll_wait(file, &lis3->misc_wait, wait);
45392 - if (atomic_read(&lis3->count))
45393 + if (atomic_read_unchecked(&lis3->count))
45394 return POLLIN | POLLRDNORM;
45395 return 0;
45396 }
45397 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
45398 index c439c82..1f20f57 100644
45399 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
45400 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
45401 @@ -297,7 +297,7 @@ struct lis3lv02d {
45402 struct input_polled_dev *idev; /* input device */
45403 struct platform_device *pdev; /* platform device */
45404 struct regulator_bulk_data regulators[2];
45405 - atomic_t count; /* interrupt count after last read */
45406 + atomic_unchecked_t count; /* interrupt count after last read */
45407 union axis_conversion ac; /* hw -> logical axis */
45408 int mapped_btns[3];
45409
45410 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
45411 index 2f30bad..c4c13d0 100644
45412 --- a/drivers/misc/sgi-gru/gruhandles.c
45413 +++ b/drivers/misc/sgi-gru/gruhandles.c
45414 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
45415 unsigned long nsec;
45416
45417 nsec = CLKS2NSEC(clks);
45418 - atomic_long_inc(&mcs_op_statistics[op].count);
45419 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
45420 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
45421 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
45422 if (mcs_op_statistics[op].max < nsec)
45423 mcs_op_statistics[op].max = nsec;
45424 }
45425 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
45426 index 4f76359..cdfcb2e 100644
45427 --- a/drivers/misc/sgi-gru/gruprocfs.c
45428 +++ b/drivers/misc/sgi-gru/gruprocfs.c
45429 @@ -32,9 +32,9 @@
45430
45431 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
45432
45433 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
45434 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
45435 {
45436 - unsigned long val = atomic_long_read(v);
45437 + unsigned long val = atomic_long_read_unchecked(v);
45438
45439 seq_printf(s, "%16lu %s\n", val, id);
45440 }
45441 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
45442
45443 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
45444 for (op = 0; op < mcsop_last; op++) {
45445 - count = atomic_long_read(&mcs_op_statistics[op].count);
45446 - total = atomic_long_read(&mcs_op_statistics[op].total);
45447 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
45448 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
45449 max = mcs_op_statistics[op].max;
45450 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
45451 count ? total / count : 0, max);
45452 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
45453 index 5c3ce24..4915ccb 100644
45454 --- a/drivers/misc/sgi-gru/grutables.h
45455 +++ b/drivers/misc/sgi-gru/grutables.h
45456 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
45457 * GRU statistics.
45458 */
45459 struct gru_stats_s {
45460 - atomic_long_t vdata_alloc;
45461 - atomic_long_t vdata_free;
45462 - atomic_long_t gts_alloc;
45463 - atomic_long_t gts_free;
45464 - atomic_long_t gms_alloc;
45465 - atomic_long_t gms_free;
45466 - atomic_long_t gts_double_allocate;
45467 - atomic_long_t assign_context;
45468 - atomic_long_t assign_context_failed;
45469 - atomic_long_t free_context;
45470 - atomic_long_t load_user_context;
45471 - atomic_long_t load_kernel_context;
45472 - atomic_long_t lock_kernel_context;
45473 - atomic_long_t unlock_kernel_context;
45474 - atomic_long_t steal_user_context;
45475 - atomic_long_t steal_kernel_context;
45476 - atomic_long_t steal_context_failed;
45477 - atomic_long_t nopfn;
45478 - atomic_long_t asid_new;
45479 - atomic_long_t asid_next;
45480 - atomic_long_t asid_wrap;
45481 - atomic_long_t asid_reuse;
45482 - atomic_long_t intr;
45483 - atomic_long_t intr_cbr;
45484 - atomic_long_t intr_tfh;
45485 - atomic_long_t intr_spurious;
45486 - atomic_long_t intr_mm_lock_failed;
45487 - atomic_long_t call_os;
45488 - atomic_long_t call_os_wait_queue;
45489 - atomic_long_t user_flush_tlb;
45490 - atomic_long_t user_unload_context;
45491 - atomic_long_t user_exception;
45492 - atomic_long_t set_context_option;
45493 - atomic_long_t check_context_retarget_intr;
45494 - atomic_long_t check_context_unload;
45495 - atomic_long_t tlb_dropin;
45496 - atomic_long_t tlb_preload_page;
45497 - atomic_long_t tlb_dropin_fail_no_asid;
45498 - atomic_long_t tlb_dropin_fail_upm;
45499 - atomic_long_t tlb_dropin_fail_invalid;
45500 - atomic_long_t tlb_dropin_fail_range_active;
45501 - atomic_long_t tlb_dropin_fail_idle;
45502 - atomic_long_t tlb_dropin_fail_fmm;
45503 - atomic_long_t tlb_dropin_fail_no_exception;
45504 - atomic_long_t tfh_stale_on_fault;
45505 - atomic_long_t mmu_invalidate_range;
45506 - atomic_long_t mmu_invalidate_page;
45507 - atomic_long_t flush_tlb;
45508 - atomic_long_t flush_tlb_gru;
45509 - atomic_long_t flush_tlb_gru_tgh;
45510 - atomic_long_t flush_tlb_gru_zero_asid;
45511 + atomic_long_unchecked_t vdata_alloc;
45512 + atomic_long_unchecked_t vdata_free;
45513 + atomic_long_unchecked_t gts_alloc;
45514 + atomic_long_unchecked_t gts_free;
45515 + atomic_long_unchecked_t gms_alloc;
45516 + atomic_long_unchecked_t gms_free;
45517 + atomic_long_unchecked_t gts_double_allocate;
45518 + atomic_long_unchecked_t assign_context;
45519 + atomic_long_unchecked_t assign_context_failed;
45520 + atomic_long_unchecked_t free_context;
45521 + atomic_long_unchecked_t load_user_context;
45522 + atomic_long_unchecked_t load_kernel_context;
45523 + atomic_long_unchecked_t lock_kernel_context;
45524 + atomic_long_unchecked_t unlock_kernel_context;
45525 + atomic_long_unchecked_t steal_user_context;
45526 + atomic_long_unchecked_t steal_kernel_context;
45527 + atomic_long_unchecked_t steal_context_failed;
45528 + atomic_long_unchecked_t nopfn;
45529 + atomic_long_unchecked_t asid_new;
45530 + atomic_long_unchecked_t asid_next;
45531 + atomic_long_unchecked_t asid_wrap;
45532 + atomic_long_unchecked_t asid_reuse;
45533 + atomic_long_unchecked_t intr;
45534 + atomic_long_unchecked_t intr_cbr;
45535 + atomic_long_unchecked_t intr_tfh;
45536 + atomic_long_unchecked_t intr_spurious;
45537 + atomic_long_unchecked_t intr_mm_lock_failed;
45538 + atomic_long_unchecked_t call_os;
45539 + atomic_long_unchecked_t call_os_wait_queue;
45540 + atomic_long_unchecked_t user_flush_tlb;
45541 + atomic_long_unchecked_t user_unload_context;
45542 + atomic_long_unchecked_t user_exception;
45543 + atomic_long_unchecked_t set_context_option;
45544 + atomic_long_unchecked_t check_context_retarget_intr;
45545 + atomic_long_unchecked_t check_context_unload;
45546 + atomic_long_unchecked_t tlb_dropin;
45547 + atomic_long_unchecked_t tlb_preload_page;
45548 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
45549 + atomic_long_unchecked_t tlb_dropin_fail_upm;
45550 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
45551 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
45552 + atomic_long_unchecked_t tlb_dropin_fail_idle;
45553 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
45554 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
45555 + atomic_long_unchecked_t tfh_stale_on_fault;
45556 + atomic_long_unchecked_t mmu_invalidate_range;
45557 + atomic_long_unchecked_t mmu_invalidate_page;
45558 + atomic_long_unchecked_t flush_tlb;
45559 + atomic_long_unchecked_t flush_tlb_gru;
45560 + atomic_long_unchecked_t flush_tlb_gru_tgh;
45561 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
45562
45563 - atomic_long_t copy_gpa;
45564 - atomic_long_t read_gpa;
45565 + atomic_long_unchecked_t copy_gpa;
45566 + atomic_long_unchecked_t read_gpa;
45567
45568 - atomic_long_t mesq_receive;
45569 - atomic_long_t mesq_receive_none;
45570 - atomic_long_t mesq_send;
45571 - atomic_long_t mesq_send_failed;
45572 - atomic_long_t mesq_noop;
45573 - atomic_long_t mesq_send_unexpected_error;
45574 - atomic_long_t mesq_send_lb_overflow;
45575 - atomic_long_t mesq_send_qlimit_reached;
45576 - atomic_long_t mesq_send_amo_nacked;
45577 - atomic_long_t mesq_send_put_nacked;
45578 - atomic_long_t mesq_page_overflow;
45579 - atomic_long_t mesq_qf_locked;
45580 - atomic_long_t mesq_qf_noop_not_full;
45581 - atomic_long_t mesq_qf_switch_head_failed;
45582 - atomic_long_t mesq_qf_unexpected_error;
45583 - atomic_long_t mesq_noop_unexpected_error;
45584 - atomic_long_t mesq_noop_lb_overflow;
45585 - atomic_long_t mesq_noop_qlimit_reached;
45586 - atomic_long_t mesq_noop_amo_nacked;
45587 - atomic_long_t mesq_noop_put_nacked;
45588 - atomic_long_t mesq_noop_page_overflow;
45589 + atomic_long_unchecked_t mesq_receive;
45590 + atomic_long_unchecked_t mesq_receive_none;
45591 + atomic_long_unchecked_t mesq_send;
45592 + atomic_long_unchecked_t mesq_send_failed;
45593 + atomic_long_unchecked_t mesq_noop;
45594 + atomic_long_unchecked_t mesq_send_unexpected_error;
45595 + atomic_long_unchecked_t mesq_send_lb_overflow;
45596 + atomic_long_unchecked_t mesq_send_qlimit_reached;
45597 + atomic_long_unchecked_t mesq_send_amo_nacked;
45598 + atomic_long_unchecked_t mesq_send_put_nacked;
45599 + atomic_long_unchecked_t mesq_page_overflow;
45600 + atomic_long_unchecked_t mesq_qf_locked;
45601 + atomic_long_unchecked_t mesq_qf_noop_not_full;
45602 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
45603 + atomic_long_unchecked_t mesq_qf_unexpected_error;
45604 + atomic_long_unchecked_t mesq_noop_unexpected_error;
45605 + atomic_long_unchecked_t mesq_noop_lb_overflow;
45606 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
45607 + atomic_long_unchecked_t mesq_noop_amo_nacked;
45608 + atomic_long_unchecked_t mesq_noop_put_nacked;
45609 + atomic_long_unchecked_t mesq_noop_page_overflow;
45610
45611 };
45612
45613 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
45614 tghop_invalidate, mcsop_last};
45615
45616 struct mcs_op_statistic {
45617 - atomic_long_t count;
45618 - atomic_long_t total;
45619 + atomic_long_unchecked_t count;
45620 + atomic_long_unchecked_t total;
45621 unsigned long max;
45622 };
45623
45624 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
45625
45626 #define STAT(id) do { \
45627 if (gru_options & OPT_STATS) \
45628 - atomic_long_inc(&gru_stats.id); \
45629 + atomic_long_inc_unchecked(&gru_stats.id); \
45630 } while (0)
45631
45632 #ifdef CONFIG_SGI_GRU_DEBUG
45633 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
45634 index c862cd4..0d176fe 100644
45635 --- a/drivers/misc/sgi-xp/xp.h
45636 +++ b/drivers/misc/sgi-xp/xp.h
45637 @@ -288,7 +288,7 @@ struct xpc_interface {
45638 xpc_notify_func, void *);
45639 void (*received) (short, int, void *);
45640 enum xp_retval (*partid_to_nasids) (short, void *);
45641 -};
45642 +} __no_const;
45643
45644 extern struct xpc_interface xpc_interface;
45645
45646 diff --git a/drivers/misc/sgi-xp/xp_main.c b/drivers/misc/sgi-xp/xp_main.c
45647 index 01be66d..e3a0c7e 100644
45648 --- a/drivers/misc/sgi-xp/xp_main.c
45649 +++ b/drivers/misc/sgi-xp/xp_main.c
45650 @@ -78,13 +78,13 @@ xpc_notloaded(void)
45651 }
45652
45653 struct xpc_interface xpc_interface = {
45654 - (void (*)(int))xpc_notloaded,
45655 - (void (*)(int))xpc_notloaded,
45656 - (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
45657 - (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
45658 + .connect = (void (*)(int))xpc_notloaded,
45659 + .disconnect = (void (*)(int))xpc_notloaded,
45660 + .send = (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
45661 + .send_notify = (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
45662 void *))xpc_notloaded,
45663 - (void (*)(short, int, void *))xpc_notloaded,
45664 - (enum xp_retval(*)(short, void *))xpc_notloaded
45665 + .received = (void (*)(short, int, void *))xpc_notloaded,
45666 + .partid_to_nasids = (enum xp_retval(*)(short, void *))xpc_notloaded
45667 };
45668 EXPORT_SYMBOL_GPL(xpc_interface);
45669
45670 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
45671 index b94d5f7..7f494c5 100644
45672 --- a/drivers/misc/sgi-xp/xpc.h
45673 +++ b/drivers/misc/sgi-xp/xpc.h
45674 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
45675 void (*received_payload) (struct xpc_channel *, void *);
45676 void (*notify_senders_of_disconnect) (struct xpc_channel *);
45677 };
45678 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
45679
45680 /* struct xpc_partition act_state values (for XPC HB) */
45681
45682 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
45683 /* found in xpc_main.c */
45684 extern struct device *xpc_part;
45685 extern struct device *xpc_chan;
45686 -extern struct xpc_arch_operations xpc_arch_ops;
45687 +extern xpc_arch_operations_no_const xpc_arch_ops;
45688 extern int xpc_disengage_timelimit;
45689 extern int xpc_disengage_timedout;
45690 extern int xpc_activate_IRQ_rcvd;
45691 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
45692 index 82dc574..8539ab2 100644
45693 --- a/drivers/misc/sgi-xp/xpc_main.c
45694 +++ b/drivers/misc/sgi-xp/xpc_main.c
45695 @@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
45696 .notifier_call = xpc_system_die,
45697 };
45698
45699 -struct xpc_arch_operations xpc_arch_ops;
45700 +xpc_arch_operations_no_const xpc_arch_ops;
45701
45702 /*
45703 * Timer function to enforce the timelimit on the partition disengage.
45704 @@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
45705
45706 if (((die_args->trapnr == X86_TRAP_MF) ||
45707 (die_args->trapnr == X86_TRAP_XF)) &&
45708 - !user_mode_vm(die_args->regs))
45709 + !user_mode(die_args->regs))
45710 xpc_die_deactivate();
45711
45712 break;
45713 diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
45714 index 452782b..0c10e40 100644
45715 --- a/drivers/mmc/card/block.c
45716 +++ b/drivers/mmc/card/block.c
45717 @@ -574,7 +574,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
45718 if (idata->ic.postsleep_min_us)
45719 usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us);
45720
45721 - if (copy_to_user(&(ic_ptr->response), cmd.resp, sizeof(cmd.resp))) {
45722 + if (copy_to_user(ic_ptr->response, cmd.resp, sizeof(cmd.resp))) {
45723 err = -EFAULT;
45724 goto cmd_rel_host;
45725 }
45726 diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
45727 index f51b5ba..86614a7 100644
45728 --- a/drivers/mmc/core/mmc_ops.c
45729 +++ b/drivers/mmc/core/mmc_ops.c
45730 @@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
45731 void *data_buf;
45732 int is_on_stack;
45733
45734 - is_on_stack = object_is_on_stack(buf);
45735 + is_on_stack = object_starts_on_stack(buf);
45736 if (is_on_stack) {
45737 /*
45738 * dma onto stack is unsafe/nonportable, but callers to this
45739 diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
45740 index 6834977..824ee1b 100644
45741 --- a/drivers/mmc/host/dw_mmc.h
45742 +++ b/drivers/mmc/host/dw_mmc.h
45743 @@ -259,5 +259,5 @@ struct dw_mci_drv_data {
45744 int (*parse_dt)(struct dw_mci *host);
45745 int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode,
45746 struct dw_mci_tuning_data *tuning_data);
45747 -};
45748 +} __do_const;
45749 #endif /* _DW_MMC_H_ */
45750 diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
45751 index 771c60a..12cb615 100644
45752 --- a/drivers/mmc/host/mmci.c
45753 +++ b/drivers/mmc/host/mmci.c
45754 @@ -1570,7 +1570,9 @@ static int mmci_probe(struct amba_device *dev,
45755 mmc->caps2 = plat->capabilities2;
45756
45757 if (variant->busy_detect) {
45758 - mmci_ops.card_busy = mmci_card_busy;
45759 + pax_open_kernel();
45760 + *(void **)&mmci_ops.card_busy = mmci_card_busy;
45761 + pax_close_kernel();
45762 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
45763 mmc->caps |= MMC_CAP_WAIT_WHILE_BUSY;
45764 mmc->max_busy_timeout = 0;
45765 diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
45766 index b841bb7..d82712f5 100644
45767 --- a/drivers/mmc/host/sdhci-esdhc-imx.c
45768 +++ b/drivers/mmc/host/sdhci-esdhc-imx.c
45769 @@ -1031,9 +1031,12 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
45770 host->mmc->caps |= MMC_CAP_1_8V_DDR;
45771 }
45772
45773 - if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING)
45774 - sdhci_esdhc_ops.platform_execute_tuning =
45775 + if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) {
45776 + pax_open_kernel();
45777 + *(void **)&sdhci_esdhc_ops.platform_execute_tuning =
45778 esdhc_executing_tuning;
45779 + pax_close_kernel();
45780 + }
45781
45782 if (imx_data->socdata->flags & ESDHC_FLAG_STD_TUNING)
45783 writel(readl(host->ioaddr + ESDHC_TUNING_CTRL) |
45784 diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
45785 index d61eb5a..88c0f5d 100644
45786 --- a/drivers/mmc/host/sdhci-s3c.c
45787 +++ b/drivers/mmc/host/sdhci-s3c.c
45788 @@ -657,9 +657,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
45789 * we can use overriding functions instead of default.
45790 */
45791 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
45792 - sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
45793 - sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
45794 - sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
45795 + pax_open_kernel();
45796 + *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
45797 + *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
45798 + *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
45799 + pax_close_kernel();
45800 }
45801
45802 /* It supports additional host capabilities if needed */
45803 diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
45804 index 6293855..3415551 100644
45805 --- a/drivers/mtd/chips/cfi_cmdset_0020.c
45806 +++ b/drivers/mtd/chips/cfi_cmdset_0020.c
45807 @@ -666,7 +666,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
45808 size_t totlen = 0, thislen;
45809 int ret = 0;
45810 size_t buflen = 0;
45811 - static char *buffer;
45812 + char *buffer;
45813
45814 if (!ECCBUF_SIZE) {
45815 /* We should fall back to a general writev implementation.
45816 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
45817 index c07cd57..61c4fbd 100644
45818 --- a/drivers/mtd/nand/denali.c
45819 +++ b/drivers/mtd/nand/denali.c
45820 @@ -24,6 +24,7 @@
45821 #include <linux/slab.h>
45822 #include <linux/mtd/mtd.h>
45823 #include <linux/module.h>
45824 +#include <linux/slab.h>
45825
45826 #include "denali.h"
45827
45828 diff --git a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
45829 index bb77f75..47539b1 100644
45830 --- a/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
45831 +++ b/drivers/mtd/nand/gpmi-nand/gpmi-nand.c
45832 @@ -370,7 +370,7 @@ void prepare_data_dma(struct gpmi_nand_data *this, enum dma_data_direction dr)
45833
45834 /* first try to map the upper buffer directly */
45835 if (virt_addr_valid(this->upper_buf) &&
45836 - !object_is_on_stack(this->upper_buf)) {
45837 + !object_starts_on_stack(this->upper_buf)) {
45838 sg_init_one(sgl, this->upper_buf, this->upper_len);
45839 ret = dma_map_sg(this->dev, sgl, 1, dr);
45840 if (ret == 0)
45841 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
45842 index 51b9d6a..52af9a7 100644
45843 --- a/drivers/mtd/nftlmount.c
45844 +++ b/drivers/mtd/nftlmount.c
45845 @@ -24,6 +24,7 @@
45846 #include <asm/errno.h>
45847 #include <linux/delay.h>
45848 #include <linux/slab.h>
45849 +#include <linux/sched.h>
45850 #include <linux/mtd/mtd.h>
45851 #include <linux/mtd/nand.h>
45852 #include <linux/mtd/nftl.h>
45853 diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
45854 index cf49c22..971b133 100644
45855 --- a/drivers/mtd/sm_ftl.c
45856 +++ b/drivers/mtd/sm_ftl.c
45857 @@ -56,7 +56,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
45858 #define SM_CIS_VENDOR_OFFSET 0x59
45859 static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
45860 {
45861 - struct attribute_group *attr_group;
45862 + attribute_group_no_const *attr_group;
45863 struct attribute **attributes;
45864 struct sm_sysfs_attribute *vendor_attribute;
45865 char *vendor;
45866 diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
45867 index f847e16..fc8dbe9 100644
45868 --- a/drivers/net/bonding/bond_netlink.c
45869 +++ b/drivers/net/bonding/bond_netlink.c
45870 @@ -542,7 +542,7 @@ nla_put_failure:
45871 return -EMSGSIZE;
45872 }
45873
45874 -struct rtnl_link_ops bond_link_ops __read_mostly = {
45875 +struct rtnl_link_ops bond_link_ops = {
45876 .kind = "bond",
45877 .priv_size = sizeof(struct bonding),
45878 .setup = bond_setup,
45879 diff --git a/drivers/net/can/Kconfig b/drivers/net/can/Kconfig
45880 index 9e7d95d..d447b88 100644
45881 --- a/drivers/net/can/Kconfig
45882 +++ b/drivers/net/can/Kconfig
45883 @@ -104,7 +104,7 @@ config CAN_JANZ_ICAN3
45884
45885 config CAN_FLEXCAN
45886 tristate "Support for Freescale FLEXCAN based chips"
45887 - depends on ARM || PPC
45888 + depends on (ARM && CPU_LITTLE_ENDIAN) || PPC
45889 ---help---
45890 Say Y here if you want to support for Freescale FlexCAN.
45891
45892 diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
45893 index 455d4c3..3353ee7 100644
45894 --- a/drivers/net/ethernet/8390/ax88796.c
45895 +++ b/drivers/net/ethernet/8390/ax88796.c
45896 @@ -889,9 +889,11 @@ static int ax_probe(struct platform_device *pdev)
45897 if (ax->plat->reg_offsets)
45898 ei_local->reg_offset = ax->plat->reg_offsets;
45899 else {
45900 + resource_size_t _mem_size = mem_size;
45901 + do_div(_mem_size, 0x18);
45902 ei_local->reg_offset = ax->reg_offsets;
45903 for (ret = 0; ret < 0x18; ret++)
45904 - ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
45905 + ax->reg_offsets[ret] = _mem_size * ret;
45906 }
45907
45908 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
45909 diff --git a/drivers/net/ethernet/altera/altera_tse_main.c b/drivers/net/ethernet/altera/altera_tse_main.c
45910 index 7330681..7e9e463 100644
45911 --- a/drivers/net/ethernet/altera/altera_tse_main.c
45912 +++ b/drivers/net/ethernet/altera/altera_tse_main.c
45913 @@ -1182,7 +1182,7 @@ static int tse_shutdown(struct net_device *dev)
45914 return 0;
45915 }
45916
45917 -static struct net_device_ops altera_tse_netdev_ops = {
45918 +static net_device_ops_no_const altera_tse_netdev_ops __read_only = {
45919 .ndo_open = tse_open,
45920 .ndo_stop = tse_shutdown,
45921 .ndo_start_xmit = tse_start_xmit,
45922 @@ -1439,11 +1439,13 @@ static int altera_tse_probe(struct platform_device *pdev)
45923 ndev->netdev_ops = &altera_tse_netdev_ops;
45924 altera_tse_set_ethtool_ops(ndev);
45925
45926 + pax_open_kernel();
45927 altera_tse_netdev_ops.ndo_set_rx_mode = tse_set_rx_mode;
45928
45929 if (priv->hash_filter)
45930 altera_tse_netdev_ops.ndo_set_rx_mode =
45931 tse_set_rx_mode_hashfilter;
45932 + pax_close_kernel();
45933
45934 /* Scatter/gather IO is not supported,
45935 * so it is turned off
45936 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45937 index 3448cc0..67b2dc4 100644
45938 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45939 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45940 @@ -1058,7 +1058,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
45941 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
45942 {
45943 /* RX_MODE controlling object */
45944 - bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
45945 + bnx2x_init_rx_mode_obj(bp);
45946
45947 /* multicast configuration controlling object */
45948 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
45949 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45950 index 31297266..944cf6e 100644
45951 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45952 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45953 @@ -2329,15 +2329,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
45954 return rc;
45955 }
45956
45957 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
45958 - struct bnx2x_rx_mode_obj *o)
45959 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
45960 {
45961 if (CHIP_IS_E1x(bp)) {
45962 - o->wait_comp = bnx2x_empty_rx_mode_wait;
45963 - o->config_rx_mode = bnx2x_set_rx_mode_e1x;
45964 + bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
45965 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
45966 } else {
45967 - o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
45968 - o->config_rx_mode = bnx2x_set_rx_mode_e2;
45969 + bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
45970 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
45971 }
45972 }
45973
45974 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45975 index 80f6c79..fb7d12d 100644
45976 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45977 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45978 @@ -1340,8 +1340,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
45979
45980 /********************* RX MODE ****************/
45981
45982 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
45983 - struct bnx2x_rx_mode_obj *o);
45984 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
45985
45986 /**
45987 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
45988 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
45989 index 04321e5..b51cdc4 100644
45990 --- a/drivers/net/ethernet/broadcom/tg3.h
45991 +++ b/drivers/net/ethernet/broadcom/tg3.h
45992 @@ -150,6 +150,7 @@
45993 #define CHIPREV_ID_5750_A0 0x4000
45994 #define CHIPREV_ID_5750_A1 0x4001
45995 #define CHIPREV_ID_5750_A3 0x4003
45996 +#define CHIPREV_ID_5750_C1 0x4201
45997 #define CHIPREV_ID_5750_C2 0x4202
45998 #define CHIPREV_ID_5752_A0_HW 0x5000
45999 #define CHIPREV_ID_5752_A0 0x6000
46000 diff --git a/drivers/net/ethernet/brocade/bna/bna_enet.c b/drivers/net/ethernet/brocade/bna/bna_enet.c
46001 index 13f9636..228040f 100644
46002 --- a/drivers/net/ethernet/brocade/bna/bna_enet.c
46003 +++ b/drivers/net/ethernet/brocade/bna/bna_enet.c
46004 @@ -1690,10 +1690,10 @@ bna_cb_ioceth_reset(void *arg)
46005 }
46006
46007 static struct bfa_ioc_cbfn bna_ioceth_cbfn = {
46008 - bna_cb_ioceth_enable,
46009 - bna_cb_ioceth_disable,
46010 - bna_cb_ioceth_hbfail,
46011 - bna_cb_ioceth_reset
46012 + .enable_cbfn = bna_cb_ioceth_enable,
46013 + .disable_cbfn = bna_cb_ioceth_disable,
46014 + .hbfail_cbfn = bna_cb_ioceth_hbfail,
46015 + .reset_cbfn = bna_cb_ioceth_reset
46016 };
46017
46018 static void bna_attr_init(struct bna_ioceth *ioceth)
46019 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
46020 index 8cffcdf..aadf043 100644
46021 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
46022 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
46023 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
46024 */
46025 struct l2t_skb_cb {
46026 arp_failure_handler_func arp_failure_handler;
46027 -};
46028 +} __no_const;
46029
46030 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
46031
46032 diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
46033 index 24e16e3..bfe6ef2 100644
46034 --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
46035 +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
46036 @@ -2139,7 +2139,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
46037
46038 int i;
46039 struct adapter *ap = netdev2adap(dev);
46040 - static const unsigned int *reg_ranges;
46041 + const unsigned int *reg_ranges;
46042 int arr_size = 0, buf_size = 0;
46043
46044 if (is_t4(ap->params.chip)) {
46045 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
46046 index c05b66d..ed69872 100644
46047 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
46048 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
46049 @@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
46050 for (i=0; i<ETH_ALEN; i++) {
46051 tmp.addr[i] = dev->dev_addr[i];
46052 }
46053 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
46054 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
46055 break;
46056
46057 case DE4X5_SET_HWADDR: /* Set the hardware address */
46058 @@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
46059 spin_lock_irqsave(&lp->lock, flags);
46060 memcpy(&statbuf, &lp->pktStats, ioc->len);
46061 spin_unlock_irqrestore(&lp->lock, flags);
46062 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
46063 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
46064 return -EFAULT;
46065 break;
46066 }
46067 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
46068 index dc19bc5..f2d4548 100644
46069 --- a/drivers/net/ethernet/emulex/benet/be_main.c
46070 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
46071 @@ -535,7 +535,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
46072
46073 if (wrapped)
46074 newacc += 65536;
46075 - ACCESS_ONCE(*acc) = newacc;
46076 + ACCESS_ONCE_RW(*acc) = newacc;
46077 }
46078
46079 static void populate_erx_stats(struct be_adapter *adapter,
46080 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
46081 index 68069ea..c4484f6 100644
46082 --- a/drivers/net/ethernet/faraday/ftgmac100.c
46083 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
46084 @@ -30,6 +30,8 @@
46085 #include <linux/netdevice.h>
46086 #include <linux/phy.h>
46087 #include <linux/platform_device.h>
46088 +#include <linux/interrupt.h>
46089 +#include <linux/irqreturn.h>
46090 #include <net/ip.h>
46091
46092 #include "ftgmac100.h"
46093 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
46094 index 8be5b40..081bc1b 100644
46095 --- a/drivers/net/ethernet/faraday/ftmac100.c
46096 +++ b/drivers/net/ethernet/faraday/ftmac100.c
46097 @@ -31,6 +31,8 @@
46098 #include <linux/module.h>
46099 #include <linux/netdevice.h>
46100 #include <linux/platform_device.h>
46101 +#include <linux/interrupt.h>
46102 +#include <linux/irqreturn.h>
46103
46104 #include "ftmac100.h"
46105
46106 diff --git a/drivers/net/ethernet/intel/i40e/i40e_ptp.c b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
46107 index e61e637..9117795 100644
46108 --- a/drivers/net/ethernet/intel/i40e/i40e_ptp.c
46109 +++ b/drivers/net/ethernet/intel/i40e/i40e_ptp.c
46110 @@ -436,7 +436,7 @@ void i40e_ptp_set_increment(struct i40e_pf *pf)
46111 wr32(hw, I40E_PRTTSYN_INC_H, incval >> 32);
46112
46113 /* Update the base adjustement value. */
46114 - ACCESS_ONCE(pf->ptp_base_adj) = incval;
46115 + ACCESS_ONCE_RW(pf->ptp_base_adj) = incval;
46116 smp_mb(); /* Force the above update. */
46117 }
46118
46119 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
46120 index 8902ae6..e7bcdce 100644
46121 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
46122 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
46123 @@ -771,7 +771,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
46124 }
46125
46126 /* update the base incval used to calculate frequency adjustment */
46127 - ACCESS_ONCE(adapter->base_incval) = incval;
46128 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
46129 smp_mb();
46130
46131 /* need lock to prevent incorrect read while modifying cyclecounter */
46132 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
46133 index 089b713..28d87ae 100644
46134 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
46135 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
46136 @@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
46137 struct __vxge_hw_fifo *fifo;
46138 struct vxge_hw_fifo_config *config;
46139 u32 txdl_size, txdl_per_memblock;
46140 - struct vxge_hw_mempool_cbs fifo_mp_callback;
46141 + static struct vxge_hw_mempool_cbs fifo_mp_callback = {
46142 + .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
46143 + };
46144 +
46145 struct __vxge_hw_virtualpath *vpath;
46146
46147 if ((vp == NULL) || (attr == NULL)) {
46148 @@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
46149 goto exit;
46150 }
46151
46152 - fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
46153 -
46154 fifo->mempool =
46155 __vxge_hw_mempool_create(vpath->hldev,
46156 fifo->config->memblock_size,
46157 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
46158 index ba20c72..f30c0fe 100644
46159 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
46160 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
46161 @@ -2176,7 +2176,9 @@ int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
46162 max_tx_rings = QLCNIC_MAX_VNIC_TX_RINGS;
46163 } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
46164 ahw->nic_mode = QLCNIC_DEFAULT_MODE;
46165 - adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
46166 + pax_open_kernel();
46167 + *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
46168 + pax_close_kernel();
46169 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
46170 max_sds_rings = QLCNIC_MAX_SDS_RINGS;
46171 max_tx_rings = QLCNIC_MAX_TX_RINGS;
46172 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
46173 index be7d7a6..a8983f8 100644
46174 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
46175 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
46176 @@ -207,17 +207,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
46177 case QLCNIC_NON_PRIV_FUNC:
46178 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
46179 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
46180 - nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
46181 + pax_open_kernel();
46182 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
46183 + pax_close_kernel();
46184 break;
46185 case QLCNIC_PRIV_FUNC:
46186 ahw->op_mode = QLCNIC_PRIV_FUNC;
46187 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
46188 - nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
46189 + pax_open_kernel();
46190 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
46191 + pax_close_kernel();
46192 break;
46193 case QLCNIC_MGMT_FUNC:
46194 ahw->op_mode = QLCNIC_MGMT_FUNC;
46195 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
46196 - nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
46197 + pax_open_kernel();
46198 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
46199 + pax_close_kernel();
46200 break;
46201 default:
46202 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
46203 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
46204 index 37b979b..50f5b95 100644
46205 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
46206 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
46207 @@ -1217,7 +1217,7 @@ flash_temp:
46208 int qlcnic_dump_fw(struct qlcnic_adapter *adapter)
46209 {
46210 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
46211 - static const struct qlcnic_dump_operations *fw_dump_ops;
46212 + const struct qlcnic_dump_operations *fw_dump_ops;
46213 struct qlcnic_83xx_dump_template_hdr *hdr_83xx;
46214 u32 entry_offset, dump, no_entries, buf_offset = 0;
46215 int i, k, ops_cnt, ops_index, dump_size = 0;
46216 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
46217 index aa1c079..2b1a3e8 100644
46218 --- a/drivers/net/ethernet/realtek/r8169.c
46219 +++ b/drivers/net/ethernet/realtek/r8169.c
46220 @@ -758,22 +758,22 @@ struct rtl8169_private {
46221 struct mdio_ops {
46222 void (*write)(struct rtl8169_private *, int, int);
46223 int (*read)(struct rtl8169_private *, int);
46224 - } mdio_ops;
46225 + } __no_const mdio_ops;
46226
46227 struct pll_power_ops {
46228 void (*down)(struct rtl8169_private *);
46229 void (*up)(struct rtl8169_private *);
46230 - } pll_power_ops;
46231 + } __no_const pll_power_ops;
46232
46233 struct jumbo_ops {
46234 void (*enable)(struct rtl8169_private *);
46235 void (*disable)(struct rtl8169_private *);
46236 - } jumbo_ops;
46237 + } __no_const jumbo_ops;
46238
46239 struct csi_ops {
46240 void (*write)(struct rtl8169_private *, int, int);
46241 u32 (*read)(struct rtl8169_private *, int);
46242 - } csi_ops;
46243 + } __no_const csi_ops;
46244
46245 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
46246 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
46247 diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
46248 index 6b861e3..204ac86 100644
46249 --- a/drivers/net/ethernet/sfc/ptp.c
46250 +++ b/drivers/net/ethernet/sfc/ptp.c
46251 @@ -822,7 +822,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
46252 ptp->start.dma_addr);
46253
46254 /* Clear flag that signals MC ready */
46255 - ACCESS_ONCE(*start) = 0;
46256 + ACCESS_ONCE_RW(*start) = 0;
46257 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
46258 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
46259 EFX_BUG_ON_PARANOID(rc);
46260 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46261 index 50617c5..b13724c 100644
46262 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46263 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
46264 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
46265
46266 writel(value, ioaddr + MMC_CNTRL);
46267
46268 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
46269 - MMC_CNTRL, value);
46270 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
46271 +// MMC_CNTRL, value);
46272 }
46273
46274 /* To mask all all interrupts.*/
46275 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
46276 index d18f711d..5755800 100644
46277 --- a/drivers/net/hyperv/hyperv_net.h
46278 +++ b/drivers/net/hyperv/hyperv_net.h
46279 @@ -101,7 +101,7 @@ struct rndis_device {
46280
46281 enum rndis_device_state state;
46282 bool link_state;
46283 - atomic_t new_req_id;
46284 + atomic_unchecked_t new_req_id;
46285
46286 spinlock_t request_lock;
46287 struct list_head req_list;
46288 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
46289 index 143a98c..d54fbaa 100644
46290 --- a/drivers/net/hyperv/rndis_filter.c
46291 +++ b/drivers/net/hyperv/rndis_filter.c
46292 @@ -100,7 +100,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
46293 * template
46294 */
46295 set = &rndis_msg->msg.set_req;
46296 - set->req_id = atomic_inc_return(&dev->new_req_id);
46297 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
46298
46299 /* Add to the request list */
46300 spin_lock_irqsave(&dev->request_lock, flags);
46301 @@ -834,7 +834,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
46302
46303 /* Setup the rndis set */
46304 halt = &request->request_msg.msg.halt_req;
46305 - halt->req_id = atomic_inc_return(&dev->new_req_id);
46306 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
46307
46308 /* Ignore return since this msg is optional. */
46309 rndis_filter_send_request(dev, request);
46310 diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
46311 index 78f18be..1d19c62 100644
46312 --- a/drivers/net/ieee802154/fakehard.c
46313 +++ b/drivers/net/ieee802154/fakehard.c
46314 @@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
46315 phy->transmit_power = 0xbf;
46316
46317 dev->netdev_ops = &fake_ops;
46318 - dev->ml_priv = &fake_mlme;
46319 + dev->ml_priv = (void *)&fake_mlme;
46320
46321 priv = netdev_priv(dev);
46322 priv->phy = phy;
46323 diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
46324 index 7eec598..90b8428 100644
46325 --- a/drivers/net/macvlan.c
46326 +++ b/drivers/net/macvlan.c
46327 @@ -984,13 +984,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
46328 int macvlan_link_register(struct rtnl_link_ops *ops)
46329 {
46330 /* common fields */
46331 - ops->priv_size = sizeof(struct macvlan_dev);
46332 - ops->validate = macvlan_validate;
46333 - ops->maxtype = IFLA_MACVLAN_MAX;
46334 - ops->policy = macvlan_policy;
46335 - ops->changelink = macvlan_changelink;
46336 - ops->get_size = macvlan_get_size;
46337 - ops->fill_info = macvlan_fill_info;
46338 + pax_open_kernel();
46339 + *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
46340 + *(void **)&ops->validate = macvlan_validate;
46341 + *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
46342 + *(const void **)&ops->policy = macvlan_policy;
46343 + *(void **)&ops->changelink = macvlan_changelink;
46344 + *(void **)&ops->get_size = macvlan_get_size;
46345 + *(void **)&ops->fill_info = macvlan_fill_info;
46346 + pax_close_kernel();
46347
46348 return rtnl_link_register(ops);
46349 };
46350 @@ -1044,7 +1046,7 @@ static int macvlan_device_event(struct notifier_block *unused,
46351 return NOTIFY_DONE;
46352 }
46353
46354 -static struct notifier_block macvlan_notifier_block __read_mostly = {
46355 +static struct notifier_block macvlan_notifier_block = {
46356 .notifier_call = macvlan_device_event,
46357 };
46358
46359 diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
46360 index 3381c4f..dea5fd5 100644
46361 --- a/drivers/net/macvtap.c
46362 +++ b/drivers/net/macvtap.c
46363 @@ -1020,7 +1020,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
46364 }
46365
46366 ret = 0;
46367 - if (copy_to_user(&ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
46368 + if (copy_to_user(ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
46369 put_user(q->flags, &ifr->ifr_flags))
46370 ret = -EFAULT;
46371 macvtap_put_vlan(vlan);
46372 @@ -1190,7 +1190,7 @@ static int macvtap_device_event(struct notifier_block *unused,
46373 return NOTIFY_DONE;
46374 }
46375
46376 -static struct notifier_block macvtap_notifier_block __read_mostly = {
46377 +static struct notifier_block macvtap_notifier_block = {
46378 .notifier_call = macvtap_device_event,
46379 };
46380
46381 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
46382 index e3923eb..2a0373b 100644
46383 --- a/drivers/net/ppp/ppp_generic.c
46384 +++ b/drivers/net/ppp/ppp_generic.c
46385 @@ -1012,7 +1012,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
46386 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
46387 struct ppp_stats stats;
46388 struct ppp_comp_stats cstats;
46389 - char *vers;
46390
46391 switch (cmd) {
46392 case SIOCGPPPSTATS:
46393 @@ -1034,8 +1033,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
46394 break;
46395
46396 case SIOCGPPPVER:
46397 - vers = PPP_VERSION;
46398 - if (copy_to_user(addr, vers, strlen(vers) + 1))
46399 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
46400 break;
46401 err = 0;
46402 break;
46403 diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
46404 index 1252d9c..80e660b 100644
46405 --- a/drivers/net/slip/slhc.c
46406 +++ b/drivers/net/slip/slhc.c
46407 @@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
46408 register struct tcphdr *thp;
46409 register struct iphdr *ip;
46410 register struct cstate *cs;
46411 - int len, hdrlen;
46412 + long len, hdrlen;
46413 unsigned char *cp = icp;
46414
46415 /* We've got a compressed packet; read the change byte */
46416 diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
46417 index ce4989b..b40b328 100644
46418 --- a/drivers/net/team/team.c
46419 +++ b/drivers/net/team/team.c
46420 @@ -2868,7 +2868,7 @@ static int team_device_event(struct notifier_block *unused,
46421 return NOTIFY_DONE;
46422 }
46423
46424 -static struct notifier_block team_notifier_block __read_mostly = {
46425 +static struct notifier_block team_notifier_block = {
46426 .notifier_call = team_device_event,
46427 };
46428
46429 diff --git a/drivers/net/tun.c b/drivers/net/tun.c
46430 index ee328ba..c4a0041 100644
46431 --- a/drivers/net/tun.c
46432 +++ b/drivers/net/tun.c
46433 @@ -1876,7 +1876,7 @@ unlock:
46434 }
46435
46436 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
46437 - unsigned long arg, int ifreq_len)
46438 + unsigned long arg, size_t ifreq_len)
46439 {
46440 struct tun_file *tfile = file->private_data;
46441 struct tun_struct *tun;
46442 @@ -1889,6 +1889,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
46443 unsigned int ifindex;
46444 int ret;
46445
46446 + if (ifreq_len > sizeof ifr)
46447 + return -EFAULT;
46448 +
46449 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
46450 if (copy_from_user(&ifr, argp, ifreq_len))
46451 return -EFAULT;
46452 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
46453 index 660bd5e..ac59452 100644
46454 --- a/drivers/net/usb/hso.c
46455 +++ b/drivers/net/usb/hso.c
46456 @@ -71,7 +71,7 @@
46457 #include <asm/byteorder.h>
46458 #include <linux/serial_core.h>
46459 #include <linux/serial.h>
46460 -
46461 +#include <asm/local.h>
46462
46463 #define MOD_AUTHOR "Option Wireless"
46464 #define MOD_DESCRIPTION "USB High Speed Option driver"
46465 @@ -1179,7 +1179,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
46466 struct urb *urb;
46467
46468 urb = serial->rx_urb[0];
46469 - if (serial->port.count > 0) {
46470 + if (atomic_read(&serial->port.count) > 0) {
46471 count = put_rxbuf_data(urb, serial);
46472 if (count == -1)
46473 return;
46474 @@ -1217,7 +1217,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
46475 DUMP1(urb->transfer_buffer, urb->actual_length);
46476
46477 /* Anyone listening? */
46478 - if (serial->port.count == 0)
46479 + if (atomic_read(&serial->port.count) == 0)
46480 return;
46481
46482 if (serial->parent->port_spec & HSO_INFO_CRC_BUG)
46483 @@ -1287,8 +1287,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
46484 tty_port_tty_set(&serial->port, tty);
46485
46486 /* check for port already opened, if not set the termios */
46487 - serial->port.count++;
46488 - if (serial->port.count == 1) {
46489 + if (atomic_inc_return(&serial->port.count) == 1) {
46490 serial->rx_state = RX_IDLE;
46491 /* Force default termio settings */
46492 _hso_serial_set_termios(tty, NULL);
46493 @@ -1300,7 +1299,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
46494 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
46495 if (result) {
46496 hso_stop_serial_device(serial->parent);
46497 - serial->port.count--;
46498 + atomic_dec(&serial->port.count);
46499 kref_put(&serial->parent->ref, hso_serial_ref_free);
46500 }
46501 } else {
46502 @@ -1337,10 +1336,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
46503
46504 /* reset the rts and dtr */
46505 /* do the actual close */
46506 - serial->port.count--;
46507 + atomic_dec(&serial->port.count);
46508
46509 - if (serial->port.count <= 0) {
46510 - serial->port.count = 0;
46511 + if (atomic_read(&serial->port.count) <= 0) {
46512 + atomic_set(&serial->port.count, 0);
46513 tty_port_tty_set(&serial->port, NULL);
46514 if (!usb_gone)
46515 hso_stop_serial_device(serial->parent);
46516 @@ -1416,7 +1415,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
46517
46518 /* the actual setup */
46519 spin_lock_irqsave(&serial->serial_lock, flags);
46520 - if (serial->port.count)
46521 + if (atomic_read(&serial->port.count))
46522 _hso_serial_set_termios(tty, old);
46523 else
46524 tty->termios = *old;
46525 @@ -1885,7 +1884,7 @@ static void intr_callback(struct urb *urb)
46526 D1("Pending read interrupt on port %d\n", i);
46527 spin_lock(&serial->serial_lock);
46528 if (serial->rx_state == RX_IDLE &&
46529 - serial->port.count > 0) {
46530 + atomic_read(&serial->port.count) > 0) {
46531 /* Setup and send a ctrl req read on
46532 * port i */
46533 if (!serial->rx_urb_filled[0]) {
46534 @@ -3061,7 +3060,7 @@ static int hso_resume(struct usb_interface *iface)
46535 /* Start all serial ports */
46536 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
46537 if (serial_table[i] && (serial_table[i]->interface == iface)) {
46538 - if (dev2ser(serial_table[i])->port.count) {
46539 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
46540 result =
46541 hso_start_serial_device(serial_table[i], GFP_NOIO);
46542 hso_kick_transmit(dev2ser(serial_table[i]));
46543 diff --git a/drivers/net/usb/r8152.c b/drivers/net/usb/r8152.c
46544 index 3fbfb08..2c16265 100644
46545 --- a/drivers/net/usb/r8152.c
46546 +++ b/drivers/net/usb/r8152.c
46547 @@ -567,7 +567,7 @@ struct r8152 {
46548 void (*up)(struct r8152 *);
46549 void (*down)(struct r8152 *);
46550 void (*unload)(struct r8152 *);
46551 - } rtl_ops;
46552 + } __no_const rtl_ops;
46553
46554 int intr_interval;
46555 u32 saved_wolopts;
46556 diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
46557 index a2515887..6d13233 100644
46558 --- a/drivers/net/usb/sierra_net.c
46559 +++ b/drivers/net/usb/sierra_net.c
46560 @@ -51,7 +51,7 @@ static const char driver_name[] = "sierra_net";
46561 /* atomic counter partially included in MAC address to make sure 2 devices
46562 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
46563 */
46564 -static atomic_t iface_counter = ATOMIC_INIT(0);
46565 +static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
46566
46567 /*
46568 * SYNC Timer Delay definition used to set the expiry time
46569 @@ -697,7 +697,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
46570 dev->net->netdev_ops = &sierra_net_device_ops;
46571
46572 /* change MAC addr to include, ifacenum, and to be unique */
46573 - dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
46574 + dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
46575 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
46576
46577 /* we will have to manufacture ethernet headers, prepare template */
46578 diff --git a/drivers/net/virtio_net.c b/drivers/net/virtio_net.c
46579 index 8a852b5..668a4b6 100644
46580 --- a/drivers/net/virtio_net.c
46581 +++ b/drivers/net/virtio_net.c
46582 @@ -47,7 +47,7 @@ module_param(gso, bool, 0444);
46583 #define RECEIVE_AVG_WEIGHT 64
46584
46585 /* Minimum alignment for mergeable packet buffers. */
46586 -#define MERGEABLE_BUFFER_ALIGN max(L1_CACHE_BYTES, 256)
46587 +#define MERGEABLE_BUFFER_ALIGN max(L1_CACHE_BYTES, 256UL)
46588
46589 #define VIRTNET_DRIVER_VERSION "1.0.0"
46590
46591 diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
46592 index 77dcf92..549924a 100644
46593 --- a/drivers/net/vxlan.c
46594 +++ b/drivers/net/vxlan.c
46595 @@ -2839,7 +2839,7 @@ nla_put_failure:
46596 return -EMSGSIZE;
46597 }
46598
46599 -static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
46600 +static struct rtnl_link_ops vxlan_link_ops = {
46601 .kind = "vxlan",
46602 .maxtype = IFLA_VXLAN_MAX,
46603 .policy = vxlan_policy,
46604 @@ -2886,7 +2886,7 @@ static int vxlan_lowerdev_event(struct notifier_block *unused,
46605 return NOTIFY_DONE;
46606 }
46607
46608 -static struct notifier_block vxlan_notifier_block __read_mostly = {
46609 +static struct notifier_block vxlan_notifier_block = {
46610 .notifier_call = vxlan_lowerdev_event,
46611 };
46612
46613 diff --git a/drivers/net/wan/lmc/lmc_media.c b/drivers/net/wan/lmc/lmc_media.c
46614 index 5920c99..ff2e4a5 100644
46615 --- a/drivers/net/wan/lmc/lmc_media.c
46616 +++ b/drivers/net/wan/lmc/lmc_media.c
46617 @@ -95,62 +95,63 @@ static inline void write_av9110_bit (lmc_softc_t *, int);
46618 static void write_av9110(lmc_softc_t *, u32, u32, u32, u32, u32);
46619
46620 lmc_media_t lmc_ds3_media = {
46621 - lmc_ds3_init, /* special media init stuff */
46622 - lmc_ds3_default, /* reset to default state */
46623 - lmc_ds3_set_status, /* reset status to state provided */
46624 - lmc_dummy_set_1, /* set clock source */
46625 - lmc_dummy_set2_1, /* set line speed */
46626 - lmc_ds3_set_100ft, /* set cable length */
46627 - lmc_ds3_set_scram, /* set scrambler */
46628 - lmc_ds3_get_link_status, /* get link status */
46629 - lmc_dummy_set_1, /* set link status */
46630 - lmc_ds3_set_crc_length, /* set CRC length */
46631 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
46632 - lmc_ds3_watchdog
46633 + .init = lmc_ds3_init, /* special media init stuff */
46634 + .defaults = lmc_ds3_default, /* reset to default state */
46635 + .set_status = lmc_ds3_set_status, /* reset status to state provided */
46636 + .set_clock_source = lmc_dummy_set_1, /* set clock source */
46637 + .set_speed = lmc_dummy_set2_1, /* set line speed */
46638 + .set_cable_length = lmc_ds3_set_100ft, /* set cable length */
46639 + .set_scrambler = lmc_ds3_set_scram, /* set scrambler */
46640 + .get_link_status = lmc_ds3_get_link_status, /* get link status */
46641 + .set_link_status = lmc_dummy_set_1, /* set link status */
46642 + .set_crc_length = lmc_ds3_set_crc_length, /* set CRC length */
46643 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46644 + .watchdog = lmc_ds3_watchdog
46645 };
46646
46647 lmc_media_t lmc_hssi_media = {
46648 - lmc_hssi_init, /* special media init stuff */
46649 - lmc_hssi_default, /* reset to default state */
46650 - lmc_hssi_set_status, /* reset status to state provided */
46651 - lmc_hssi_set_clock, /* set clock source */
46652 - lmc_dummy_set2_1, /* set line speed */
46653 - lmc_dummy_set_1, /* set cable length */
46654 - lmc_dummy_set_1, /* set scrambler */
46655 - lmc_hssi_get_link_status, /* get link status */
46656 - lmc_hssi_set_link_status, /* set link status */
46657 - lmc_hssi_set_crc_length, /* set CRC length */
46658 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
46659 - lmc_hssi_watchdog
46660 + .init = lmc_hssi_init, /* special media init stuff */
46661 + .defaults = lmc_hssi_default, /* reset to default state */
46662 + .set_status = lmc_hssi_set_status, /* reset status to state provided */
46663 + .set_clock_source = lmc_hssi_set_clock, /* set clock source */
46664 + .set_speed = lmc_dummy_set2_1, /* set line speed */
46665 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
46666 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46667 + .get_link_status = lmc_hssi_get_link_status, /* get link status */
46668 + .set_link_status = lmc_hssi_set_link_status, /* set link status */
46669 + .set_crc_length = lmc_hssi_set_crc_length, /* set CRC length */
46670 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46671 + .watchdog = lmc_hssi_watchdog
46672 };
46673
46674 -lmc_media_t lmc_ssi_media = { lmc_ssi_init, /* special media init stuff */
46675 - lmc_ssi_default, /* reset to default state */
46676 - lmc_ssi_set_status, /* reset status to state provided */
46677 - lmc_ssi_set_clock, /* set clock source */
46678 - lmc_ssi_set_speed, /* set line speed */
46679 - lmc_dummy_set_1, /* set cable length */
46680 - lmc_dummy_set_1, /* set scrambler */
46681 - lmc_ssi_get_link_status, /* get link status */
46682 - lmc_ssi_set_link_status, /* set link status */
46683 - lmc_ssi_set_crc_length, /* set CRC length */
46684 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
46685 - lmc_ssi_watchdog
46686 +lmc_media_t lmc_ssi_media = {
46687 + .init = lmc_ssi_init, /* special media init stuff */
46688 + .defaults = lmc_ssi_default, /* reset to default state */
46689 + .set_status = lmc_ssi_set_status, /* reset status to state provided */
46690 + .set_clock_source = lmc_ssi_set_clock, /* set clock source */
46691 + .set_speed = lmc_ssi_set_speed, /* set line speed */
46692 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
46693 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46694 + .get_link_status = lmc_ssi_get_link_status, /* get link status */
46695 + .set_link_status = lmc_ssi_set_link_status, /* set link status */
46696 + .set_crc_length = lmc_ssi_set_crc_length, /* set CRC length */
46697 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
46698 + .watchdog = lmc_ssi_watchdog
46699 };
46700
46701 lmc_media_t lmc_t1_media = {
46702 - lmc_t1_init, /* special media init stuff */
46703 - lmc_t1_default, /* reset to default state */
46704 - lmc_t1_set_status, /* reset status to state provided */
46705 - lmc_t1_set_clock, /* set clock source */
46706 - lmc_dummy_set2_1, /* set line speed */
46707 - lmc_dummy_set_1, /* set cable length */
46708 - lmc_dummy_set_1, /* set scrambler */
46709 - lmc_t1_get_link_status, /* get link status */
46710 - lmc_dummy_set_1, /* set link status */
46711 - lmc_t1_set_crc_length, /* set CRC length */
46712 - lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
46713 - lmc_t1_watchdog
46714 + .init = lmc_t1_init, /* special media init stuff */
46715 + .defaults = lmc_t1_default, /* reset to default state */
46716 + .set_status = lmc_t1_set_status, /* reset status to state provided */
46717 + .set_clock_source = lmc_t1_set_clock, /* set clock source */
46718 + .set_speed = lmc_dummy_set2_1, /* set line speed */
46719 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
46720 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
46721 + .get_link_status = lmc_t1_get_link_status, /* get link status */
46722 + .set_link_status = lmc_dummy_set_1, /* set link status */
46723 + .set_crc_length = lmc_t1_set_crc_length, /* set CRC length */
46724 + .set_circuit_type = lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
46725 + .watchdog = lmc_t1_watchdog
46726 };
46727
46728 static void
46729 diff --git a/drivers/net/wan/z85230.c b/drivers/net/wan/z85230.c
46730 index feacc3b..5bac0de 100644
46731 --- a/drivers/net/wan/z85230.c
46732 +++ b/drivers/net/wan/z85230.c
46733 @@ -485,9 +485,9 @@ static void z8530_status(struct z8530_channel *chan)
46734
46735 struct z8530_irqhandler z8530_sync =
46736 {
46737 - z8530_rx,
46738 - z8530_tx,
46739 - z8530_status
46740 + .rx = z8530_rx,
46741 + .tx = z8530_tx,
46742 + .status = z8530_status
46743 };
46744
46745 EXPORT_SYMBOL(z8530_sync);
46746 @@ -605,15 +605,15 @@ static void z8530_dma_status(struct z8530_channel *chan)
46747 }
46748
46749 static struct z8530_irqhandler z8530_dma_sync = {
46750 - z8530_dma_rx,
46751 - z8530_dma_tx,
46752 - z8530_dma_status
46753 + .rx = z8530_dma_rx,
46754 + .tx = z8530_dma_tx,
46755 + .status = z8530_dma_status
46756 };
46757
46758 static struct z8530_irqhandler z8530_txdma_sync = {
46759 - z8530_rx,
46760 - z8530_dma_tx,
46761 - z8530_dma_status
46762 + .rx = z8530_rx,
46763 + .tx = z8530_dma_tx,
46764 + .status = z8530_dma_status
46765 };
46766
46767 /**
46768 @@ -680,9 +680,9 @@ static void z8530_status_clear(struct z8530_channel *chan)
46769
46770 struct z8530_irqhandler z8530_nop=
46771 {
46772 - z8530_rx_clear,
46773 - z8530_tx_clear,
46774 - z8530_status_clear
46775 + .rx = z8530_rx_clear,
46776 + .tx = z8530_tx_clear,
46777 + .status = z8530_status_clear
46778 };
46779
46780
46781 diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
46782 index 0b60295..b8bfa5b 100644
46783 --- a/drivers/net/wimax/i2400m/rx.c
46784 +++ b/drivers/net/wimax/i2400m/rx.c
46785 @@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
46786 if (i2400m->rx_roq == NULL)
46787 goto error_roq_alloc;
46788
46789 - rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
46790 + rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
46791 GFP_KERNEL);
46792 if (rd == NULL) {
46793 result = -ENOMEM;
46794 diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
46795 index 64747d4..17c4cf3 100644
46796 --- a/drivers/net/wireless/airo.c
46797 +++ b/drivers/net/wireless/airo.c
46798 @@ -7846,7 +7846,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
46799 struct airo_info *ai = dev->ml_priv;
46800 int ridcode;
46801 int enabled;
46802 - static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
46803 + int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
46804 unsigned char *iobuf;
46805
46806 /* Only super-user can write RIDs */
46807 diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
46808 index 99b3bfa..9559372 100644
46809 --- a/drivers/net/wireless/at76c50x-usb.c
46810 +++ b/drivers/net/wireless/at76c50x-usb.c
46811 @@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
46812 }
46813
46814 /* Convert timeout from the DFU status to jiffies */
46815 -static inline unsigned long at76_get_timeout(struct dfu_status *s)
46816 +static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
46817 {
46818 return msecs_to_jiffies((s->poll_timeout[2] << 16)
46819 | (s->poll_timeout[1] << 8)
46820 diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
46821 index 7f1bccd..ca2ffca 100644
46822 --- a/drivers/net/wireless/ath/ath10k/htc.c
46823 +++ b/drivers/net/wireless/ath/ath10k/htc.c
46824 @@ -840,7 +840,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
46825 /* registered target arrival callback from the HIF layer */
46826 int ath10k_htc_init(struct ath10k *ar)
46827 {
46828 - struct ath10k_hif_cb htc_callbacks;
46829 + static struct ath10k_hif_cb htc_callbacks = {
46830 + .rx_completion = ath10k_htc_rx_completion_handler,
46831 + .tx_completion = ath10k_htc_tx_completion_handler,
46832 + };
46833 struct ath10k_htc_ep *ep = NULL;
46834 struct ath10k_htc *htc = &ar->htc;
46835
46836 @@ -850,8 +853,6 @@ int ath10k_htc_init(struct ath10k *ar)
46837 ath10k_htc_reset_endpoint_states(htc);
46838
46839 /* setup HIF layer callbacks */
46840 - htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
46841 - htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
46842 htc->ar = ar;
46843
46844 /* Get HIF default pipe for HTC message exchange */
46845 diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
46846 index 4716d33..a688310 100644
46847 --- a/drivers/net/wireless/ath/ath10k/htc.h
46848 +++ b/drivers/net/wireless/ath/ath10k/htc.h
46849 @@ -271,13 +271,13 @@ enum ath10k_htc_ep_id {
46850
46851 struct ath10k_htc_ops {
46852 void (*target_send_suspend_complete)(struct ath10k *ar);
46853 -};
46854 +} __no_const;
46855
46856 struct ath10k_htc_ep_ops {
46857 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
46858 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
46859 void (*ep_tx_credits)(struct ath10k *);
46860 -};
46861 +} __no_const;
46862
46863 /* service connection information */
46864 struct ath10k_htc_svc_conn_req {
46865 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
46866 index 741b38d..b7ae41b 100644
46867 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
46868 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
46869 @@ -220,8 +220,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46870 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
46871 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
46872
46873 - ACCESS_ONCE(ads->ds_link) = i->link;
46874 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
46875 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
46876 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
46877
46878 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
46879 ctl6 = SM(i->keytype, AR_EncrType);
46880 @@ -235,26 +235,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46881
46882 if ((i->is_first || i->is_last) &&
46883 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
46884 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
46885 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
46886 | set11nTries(i->rates, 1)
46887 | set11nTries(i->rates, 2)
46888 | set11nTries(i->rates, 3)
46889 | (i->dur_update ? AR_DurUpdateEna : 0)
46890 | SM(0, AR_BurstDur);
46891
46892 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
46893 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
46894 | set11nRate(i->rates, 1)
46895 | set11nRate(i->rates, 2)
46896 | set11nRate(i->rates, 3);
46897 } else {
46898 - ACCESS_ONCE(ads->ds_ctl2) = 0;
46899 - ACCESS_ONCE(ads->ds_ctl3) = 0;
46900 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
46901 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
46902 }
46903
46904 if (!i->is_first) {
46905 - ACCESS_ONCE(ads->ds_ctl0) = 0;
46906 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
46907 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
46908 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
46909 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
46910 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
46911 return;
46912 }
46913
46914 @@ -279,7 +279,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46915 break;
46916 }
46917
46918 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
46919 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
46920 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
46921 | SM(i->txpower, AR_XmitPower)
46922 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
46923 @@ -289,19 +289,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46924 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
46925 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
46926
46927 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
46928 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
46929 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
46930 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
46931
46932 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
46933 return;
46934
46935 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
46936 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
46937 | set11nPktDurRTSCTS(i->rates, 1);
46938
46939 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
46940 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
46941 | set11nPktDurRTSCTS(i->rates, 3);
46942
46943 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
46944 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
46945 | set11nRateFlags(i->rates, 1)
46946 | set11nRateFlags(i->rates, 2)
46947 | set11nRateFlags(i->rates, 3)
46948 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46949 index 729ffbf..49f50e3 100644
46950 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46951 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46952 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46953 (i->qcu << AR_TxQcuNum_S) | desc_len;
46954
46955 checksum += val;
46956 - ACCESS_ONCE(ads->info) = val;
46957 + ACCESS_ONCE_RW(ads->info) = val;
46958
46959 checksum += i->link;
46960 - ACCESS_ONCE(ads->link) = i->link;
46961 + ACCESS_ONCE_RW(ads->link) = i->link;
46962
46963 checksum += i->buf_addr[0];
46964 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
46965 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
46966 checksum += i->buf_addr[1];
46967 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
46968 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
46969 checksum += i->buf_addr[2];
46970 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
46971 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
46972 checksum += i->buf_addr[3];
46973 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
46974 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
46975
46976 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
46977 - ACCESS_ONCE(ads->ctl3) = val;
46978 + ACCESS_ONCE_RW(ads->ctl3) = val;
46979 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
46980 - ACCESS_ONCE(ads->ctl5) = val;
46981 + ACCESS_ONCE_RW(ads->ctl5) = val;
46982 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
46983 - ACCESS_ONCE(ads->ctl7) = val;
46984 + ACCESS_ONCE_RW(ads->ctl7) = val;
46985 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
46986 - ACCESS_ONCE(ads->ctl9) = val;
46987 + ACCESS_ONCE_RW(ads->ctl9) = val;
46988
46989 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
46990 - ACCESS_ONCE(ads->ctl10) = checksum;
46991 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
46992
46993 if (i->is_first || i->is_last) {
46994 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
46995 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
46996 | set11nTries(i->rates, 1)
46997 | set11nTries(i->rates, 2)
46998 | set11nTries(i->rates, 3)
46999 | (i->dur_update ? AR_DurUpdateEna : 0)
47000 | SM(0, AR_BurstDur);
47001
47002 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
47003 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
47004 | set11nRate(i->rates, 1)
47005 | set11nRate(i->rates, 2)
47006 | set11nRate(i->rates, 3);
47007 } else {
47008 - ACCESS_ONCE(ads->ctl13) = 0;
47009 - ACCESS_ONCE(ads->ctl14) = 0;
47010 + ACCESS_ONCE_RW(ads->ctl13) = 0;
47011 + ACCESS_ONCE_RW(ads->ctl14) = 0;
47012 }
47013
47014 ads->ctl20 = 0;
47015 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47016
47017 ctl17 = SM(i->keytype, AR_EncrType);
47018 if (!i->is_first) {
47019 - ACCESS_ONCE(ads->ctl11) = 0;
47020 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
47021 - ACCESS_ONCE(ads->ctl15) = 0;
47022 - ACCESS_ONCE(ads->ctl16) = 0;
47023 - ACCESS_ONCE(ads->ctl17) = ctl17;
47024 - ACCESS_ONCE(ads->ctl18) = 0;
47025 - ACCESS_ONCE(ads->ctl19) = 0;
47026 + ACCESS_ONCE_RW(ads->ctl11) = 0;
47027 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
47028 + ACCESS_ONCE_RW(ads->ctl15) = 0;
47029 + ACCESS_ONCE_RW(ads->ctl16) = 0;
47030 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
47031 + ACCESS_ONCE_RW(ads->ctl18) = 0;
47032 + ACCESS_ONCE_RW(ads->ctl19) = 0;
47033 return;
47034 }
47035
47036 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
47037 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
47038 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
47039 | SM(i->txpower, AR_XmitPower)
47040 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
47041 @@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
47042 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
47043 ctl12 |= SM(val, AR_PAPRDChainMask);
47044
47045 - ACCESS_ONCE(ads->ctl12) = ctl12;
47046 - ACCESS_ONCE(ads->ctl17) = ctl17;
47047 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
47048 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
47049
47050 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
47051 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
47052 | set11nPktDurRTSCTS(i->rates, 1);
47053
47054 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
47055 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
47056 | set11nPktDurRTSCTS(i->rates, 3);
47057
47058 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
47059 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
47060 | set11nRateFlags(i->rates, 1)
47061 | set11nRateFlags(i->rates, 2)
47062 | set11nRateFlags(i->rates, 3)
47063 | SM(i->rtscts_rate, AR_RTSCTSRate);
47064
47065 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
47066 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
47067 }
47068
47069 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
47070 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
47071 index 0acd4b5..0591c91 100644
47072 --- a/drivers/net/wireless/ath/ath9k/hw.h
47073 +++ b/drivers/net/wireless/ath/ath9k/hw.h
47074 @@ -629,7 +629,7 @@ struct ath_hw_private_ops {
47075
47076 /* ANI */
47077 void (*ani_cache_ini_regs)(struct ath_hw *ah);
47078 -};
47079 +} __no_const;
47080
47081 /**
47082 * struct ath_spec_scan - parameters for Atheros spectral scan
47083 @@ -706,7 +706,7 @@ struct ath_hw_ops {
47084 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
47085 void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
47086 #endif
47087 -};
47088 +} __no_const;
47089
47090 struct ath_nf_limits {
47091 s16 max;
47092 diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
47093 index 92190da..f3a4c4c 100644
47094 --- a/drivers/net/wireless/b43/phy_lp.c
47095 +++ b/drivers/net/wireless/b43/phy_lp.c
47096 @@ -2514,7 +2514,7 @@ static int lpphy_b2063_tune(struct b43_wldev *dev,
47097 {
47098 struct ssb_bus *bus = dev->dev->sdev->bus;
47099
47100 - static const struct b206x_channel *chandata = NULL;
47101 + const struct b206x_channel *chandata = NULL;
47102 u32 crystal_freq = bus->chipco.pmu.crystalfreq * 1000;
47103 u32 freqref, vco_freq, val1, val2, val3, timeout, timeoutref, count;
47104 u16 old_comm15, scale;
47105 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
47106 index dc1d20c..f7a4f06 100644
47107 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
47108 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
47109 @@ -3633,7 +3633,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
47110 */
47111 if (il3945_mod_params.disable_hw_scan) {
47112 D_INFO("Disabling hw_scan\n");
47113 - il3945_mac_ops.hw_scan = NULL;
47114 + pax_open_kernel();
47115 + *(void **)&il3945_mac_ops.hw_scan = NULL;
47116 + pax_close_kernel();
47117 }
47118
47119 D_INFO("*** LOAD DRIVER ***\n");
47120 diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
47121 index d2fe259..0c4c682 100644
47122 --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
47123 +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
47124 @@ -188,7 +188,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
47125 {
47126 struct iwl_priv *priv = file->private_data;
47127 char buf[64];
47128 - int buf_size;
47129 + size_t buf_size;
47130 u32 offset, len;
47131
47132 memset(buf, 0, sizeof(buf));
47133 @@ -458,7 +458,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
47134 struct iwl_priv *priv = file->private_data;
47135
47136 char buf[8];
47137 - int buf_size;
47138 + size_t buf_size;
47139 u32 reset_flag;
47140
47141 memset(buf, 0, sizeof(buf));
47142 @@ -539,7 +539,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
47143 {
47144 struct iwl_priv *priv = file->private_data;
47145 char buf[8];
47146 - int buf_size;
47147 + size_t buf_size;
47148 int ht40;
47149
47150 memset(buf, 0, sizeof(buf));
47151 @@ -591,7 +591,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
47152 {
47153 struct iwl_priv *priv = file->private_data;
47154 char buf[8];
47155 - int buf_size;
47156 + size_t buf_size;
47157 int value;
47158
47159 memset(buf, 0, sizeof(buf));
47160 @@ -683,10 +683,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
47161 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
47162 DEBUGFS_READ_FILE_OPS(current_sleep_command);
47163
47164 -static const char *fmt_value = " %-30s %10u\n";
47165 -static const char *fmt_hex = " %-30s 0x%02X\n";
47166 -static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
47167 -static const char *fmt_header =
47168 +static const char fmt_value[] = " %-30s %10u\n";
47169 +static const char fmt_hex[] = " %-30s 0x%02X\n";
47170 +static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
47171 +static const char fmt_header[] =
47172 "%-32s current cumulative delta max\n";
47173
47174 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
47175 @@ -1856,7 +1856,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
47176 {
47177 struct iwl_priv *priv = file->private_data;
47178 char buf[8];
47179 - int buf_size;
47180 + size_t buf_size;
47181 int clear;
47182
47183 memset(buf, 0, sizeof(buf));
47184 @@ -1901,7 +1901,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
47185 {
47186 struct iwl_priv *priv = file->private_data;
47187 char buf[8];
47188 - int buf_size;
47189 + size_t buf_size;
47190 int trace;
47191
47192 memset(buf, 0, sizeof(buf));
47193 @@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
47194 {
47195 struct iwl_priv *priv = file->private_data;
47196 char buf[8];
47197 - int buf_size;
47198 + size_t buf_size;
47199 int missed;
47200
47201 memset(buf, 0, sizeof(buf));
47202 @@ -2013,7 +2013,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
47203
47204 struct iwl_priv *priv = file->private_data;
47205 char buf[8];
47206 - int buf_size;
47207 + size_t buf_size;
47208 int plcp;
47209
47210 memset(buf, 0, sizeof(buf));
47211 @@ -2073,7 +2073,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
47212
47213 struct iwl_priv *priv = file->private_data;
47214 char buf[8];
47215 - int buf_size;
47216 + size_t buf_size;
47217 int flush;
47218
47219 memset(buf, 0, sizeof(buf));
47220 @@ -2163,7 +2163,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
47221
47222 struct iwl_priv *priv = file->private_data;
47223 char buf[8];
47224 - int buf_size;
47225 + size_t buf_size;
47226 int rts;
47227
47228 if (!priv->cfg->ht_params)
47229 @@ -2205,7 +2205,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
47230 {
47231 struct iwl_priv *priv = file->private_data;
47232 char buf[8];
47233 - int buf_size;
47234 + size_t buf_size;
47235
47236 memset(buf, 0, sizeof(buf));
47237 buf_size = min(count, sizeof(buf) - 1);
47238 @@ -2239,7 +2239,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
47239 struct iwl_priv *priv = file->private_data;
47240 u32 event_log_flag;
47241 char buf[8];
47242 - int buf_size;
47243 + size_t buf_size;
47244
47245 /* check that the interface is up */
47246 if (!iwl_is_ready(priv))
47247 @@ -2293,7 +2293,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
47248 struct iwl_priv *priv = file->private_data;
47249 char buf[8];
47250 u32 calib_disabled;
47251 - int buf_size;
47252 + size_t buf_size;
47253
47254 memset(buf, 0, sizeof(buf));
47255 buf_size = min(count, sizeof(buf) - 1);
47256 diff --git a/drivers/net/wireless/iwlwifi/dvm/main.c b/drivers/net/wireless/iwlwifi/dvm/main.c
47257 index 6a6df71..eb5c93a 100644
47258 --- a/drivers/net/wireless/iwlwifi/dvm/main.c
47259 +++ b/drivers/net/wireless/iwlwifi/dvm/main.c
47260 @@ -1127,7 +1127,7 @@ static void iwl_option_config(struct iwl_priv *priv)
47261 static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
47262 {
47263 struct iwl_nvm_data *data = priv->nvm_data;
47264 - char *debug_msg;
47265 + static const char debug_msg[] = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
47266
47267 if (data->sku_cap_11n_enable &&
47268 !priv->cfg->ht_params) {
47269 @@ -1141,7 +1141,6 @@ static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
47270 return -EINVAL;
47271 }
47272
47273 - debug_msg = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
47274 IWL_DEBUG_INFO(priv, debug_msg,
47275 data->sku_cap_band_24GHz_enable ? "" : "NOT", "enabled",
47276 data->sku_cap_band_52GHz_enable ? "" : "NOT", "enabled",
47277 diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
47278 index 295b24c..cb4f823 100644
47279 --- a/drivers/net/wireless/iwlwifi/pcie/trans.c
47280 +++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
47281 @@ -1558,7 +1558,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
47282 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
47283
47284 char buf[8];
47285 - int buf_size;
47286 + size_t buf_size;
47287 u32 reset_flag;
47288
47289 memset(buf, 0, sizeof(buf));
47290 @@ -1579,7 +1579,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
47291 {
47292 struct iwl_trans *trans = file->private_data;
47293 char buf[8];
47294 - int buf_size;
47295 + size_t buf_size;
47296 int csr;
47297
47298 memset(buf, 0, sizeof(buf));
47299 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
47300 index 9d7a52f..2729a99 100644
47301 --- a/drivers/net/wireless/mac80211_hwsim.c
47302 +++ b/drivers/net/wireless/mac80211_hwsim.c
47303 @@ -2570,20 +2570,20 @@ static int __init init_mac80211_hwsim(void)
47304 if (channels < 1)
47305 return -EINVAL;
47306
47307 - mac80211_hwsim_mchan_ops = mac80211_hwsim_ops;
47308 - mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
47309 - mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
47310 - mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
47311 - mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
47312 - mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
47313 - mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
47314 - mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
47315 - mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
47316 - mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
47317 - mac80211_hwsim_mchan_ops.assign_vif_chanctx =
47318 - mac80211_hwsim_assign_vif_chanctx;
47319 - mac80211_hwsim_mchan_ops.unassign_vif_chanctx =
47320 - mac80211_hwsim_unassign_vif_chanctx;
47321 + pax_open_kernel();
47322 + memcpy((void *)&mac80211_hwsim_mchan_ops, &mac80211_hwsim_ops, sizeof mac80211_hwsim_mchan_ops);
47323 + *(void **)&mac80211_hwsim_mchan_ops.hw_scan = mac80211_hwsim_hw_scan;
47324 + *(void **)&mac80211_hwsim_mchan_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
47325 + *(void **)&mac80211_hwsim_mchan_ops.sw_scan_start = NULL;
47326 + *(void **)&mac80211_hwsim_mchan_ops.sw_scan_complete = NULL;
47327 + *(void **)&mac80211_hwsim_mchan_ops.remain_on_channel = mac80211_hwsim_roc;
47328 + *(void **)&mac80211_hwsim_mchan_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
47329 + *(void **)&mac80211_hwsim_mchan_ops.add_chanctx = mac80211_hwsim_add_chanctx;
47330 + *(void **)&mac80211_hwsim_mchan_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
47331 + *(void **)&mac80211_hwsim_mchan_ops.change_chanctx = mac80211_hwsim_change_chanctx;
47332 + *(void **)&mac80211_hwsim_mchan_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
47333 + *(void **)&mac80211_hwsim_mchan_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
47334 + pax_close_kernel();
47335
47336 spin_lock_init(&hwsim_radio_lock);
47337 INIT_LIST_HEAD(&hwsim_radios);
47338 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
47339 index 39d22a1..4ec8612 100644
47340 --- a/drivers/net/wireless/rndis_wlan.c
47341 +++ b/drivers/net/wireless/rndis_wlan.c
47342 @@ -1236,7 +1236,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
47343
47344 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
47345
47346 - if (rts_threshold < 0 || rts_threshold > 2347)
47347 + if (rts_threshold > 2347)
47348 rts_threshold = 2347;
47349
47350 tmp = cpu_to_le32(rts_threshold);
47351 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
47352 index 5d45a1a..6f5f041 100644
47353 --- a/drivers/net/wireless/rt2x00/rt2x00.h
47354 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
47355 @@ -375,7 +375,7 @@ struct rt2x00_intf {
47356 * for hardware which doesn't support hardware
47357 * sequence counting.
47358 */
47359 - atomic_t seqno;
47360 + atomic_unchecked_t seqno;
47361 };
47362
47363 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
47364 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
47365 index 5642ccc..01f03eb 100644
47366 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
47367 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
47368 @@ -250,9 +250,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
47369 * sequence counter given by mac80211.
47370 */
47371 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
47372 - seqno = atomic_add_return(0x10, &intf->seqno);
47373 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
47374 else
47375 - seqno = atomic_read(&intf->seqno);
47376 + seqno = atomic_read_unchecked(&intf->seqno);
47377
47378 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
47379 hdr->seq_ctrl |= cpu_to_le16(seqno);
47380 diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
47381 index b661f896..ddf7d2b 100644
47382 --- a/drivers/net/wireless/ti/wl1251/sdio.c
47383 +++ b/drivers/net/wireless/ti/wl1251/sdio.c
47384 @@ -282,13 +282,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
47385
47386 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
47387
47388 - wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
47389 - wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
47390 + pax_open_kernel();
47391 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
47392 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
47393 + pax_close_kernel();
47394
47395 wl1251_info("using dedicated interrupt line");
47396 } else {
47397 - wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
47398 - wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
47399 + pax_open_kernel();
47400 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
47401 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
47402 + pax_close_kernel();
47403
47404 wl1251_info("using SDIO interrupt");
47405 }
47406 diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
47407 index d50dfac..0a6f5be3 100644
47408 --- a/drivers/net/wireless/ti/wl12xx/main.c
47409 +++ b/drivers/net/wireless/ti/wl12xx/main.c
47410 @@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
47411 sizeof(wl->conf.mem));
47412
47413 /* read data preparation is only needed by wl127x */
47414 - wl->ops->prepare_read = wl127x_prepare_read;
47415 + pax_open_kernel();
47416 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
47417 + pax_close_kernel();
47418
47419 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
47420 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
47421 @@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
47422 sizeof(wl->conf.mem));
47423
47424 /* read data preparation is only needed by wl127x */
47425 - wl->ops->prepare_read = wl127x_prepare_read;
47426 + pax_open_kernel();
47427 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
47428 + pax_close_kernel();
47429
47430 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
47431 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
47432 diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
47433 index de5b4fa..7996ec6 100644
47434 --- a/drivers/net/wireless/ti/wl18xx/main.c
47435 +++ b/drivers/net/wireless/ti/wl18xx/main.c
47436 @@ -1900,8 +1900,10 @@ static int wl18xx_setup(struct wl1271 *wl)
47437 }
47438
47439 if (!checksum_param) {
47440 - wl18xx_ops.set_rx_csum = NULL;
47441 - wl18xx_ops.init_vif = NULL;
47442 + pax_open_kernel();
47443 + *(void **)&wl18xx_ops.set_rx_csum = NULL;
47444 + *(void **)&wl18xx_ops.init_vif = NULL;
47445 + pax_close_kernel();
47446 }
47447
47448 /* Enable 11a Band only if we have 5G antennas */
47449 diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
47450 index a912dc0..a8225ba 100644
47451 --- a/drivers/net/wireless/zd1211rw/zd_usb.c
47452 +++ b/drivers/net/wireless/zd1211rw/zd_usb.c
47453 @@ -385,7 +385,7 @@ static inline void handle_regs_int(struct urb *urb)
47454 {
47455 struct zd_usb *usb = urb->context;
47456 struct zd_usb_interrupt *intr = &usb->intr;
47457 - int len;
47458 + unsigned int len;
47459 u16 int_num;
47460
47461 ZD_ASSERT(in_interrupt());
47462 diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
47463 index 683671a..4519fc2 100644
47464 --- a/drivers/nfc/nfcwilink.c
47465 +++ b/drivers/nfc/nfcwilink.c
47466 @@ -497,7 +497,7 @@ static struct nci_ops nfcwilink_ops = {
47467
47468 static int nfcwilink_probe(struct platform_device *pdev)
47469 {
47470 - static struct nfcwilink *drv;
47471 + struct nfcwilink *drv;
47472 int rc;
47473 __u32 protocols;
47474
47475 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
47476 index d93b2b6..ae50401 100644
47477 --- a/drivers/oprofile/buffer_sync.c
47478 +++ b/drivers/oprofile/buffer_sync.c
47479 @@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
47480 if (cookie == NO_COOKIE)
47481 offset = pc;
47482 if (cookie == INVALID_COOKIE) {
47483 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
47484 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
47485 offset = pc;
47486 }
47487 if (cookie != last_cookie) {
47488 @@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
47489 /* add userspace sample */
47490
47491 if (!mm) {
47492 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
47493 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
47494 return 0;
47495 }
47496
47497 cookie = lookup_dcookie(mm, s->eip, &offset);
47498
47499 if (cookie == INVALID_COOKIE) {
47500 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
47501 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
47502 return 0;
47503 }
47504
47505 @@ -552,7 +552,7 @@ void sync_buffer(int cpu)
47506 /* ignore backtraces if failed to add a sample */
47507 if (state == sb_bt_start) {
47508 state = sb_bt_ignore;
47509 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
47510 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
47511 }
47512 }
47513 release_mm(mm);
47514 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
47515 index c0cc4e7..44d4e54 100644
47516 --- a/drivers/oprofile/event_buffer.c
47517 +++ b/drivers/oprofile/event_buffer.c
47518 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
47519 }
47520
47521 if (buffer_pos == buffer_size) {
47522 - atomic_inc(&oprofile_stats.event_lost_overflow);
47523 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
47524 return;
47525 }
47526
47527 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
47528 index ed2c3ec..deda85a 100644
47529 --- a/drivers/oprofile/oprof.c
47530 +++ b/drivers/oprofile/oprof.c
47531 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
47532 if (oprofile_ops.switch_events())
47533 return;
47534
47535 - atomic_inc(&oprofile_stats.multiplex_counter);
47536 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
47537 start_switch_worker();
47538 }
47539
47540 diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
47541 index ee2cfce..7f8f699 100644
47542 --- a/drivers/oprofile/oprofile_files.c
47543 +++ b/drivers/oprofile/oprofile_files.c
47544 @@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
47545
47546 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
47547
47548 -static ssize_t timeout_read(struct file *file, char __user *buf,
47549 +static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
47550 size_t count, loff_t *offset)
47551 {
47552 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
47553 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
47554 index 59659ce..6c860a0 100644
47555 --- a/drivers/oprofile/oprofile_stats.c
47556 +++ b/drivers/oprofile/oprofile_stats.c
47557 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
47558 cpu_buf->sample_invalid_eip = 0;
47559 }
47560
47561 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
47562 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
47563 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
47564 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
47565 - atomic_set(&oprofile_stats.multiplex_counter, 0);
47566 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
47567 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
47568 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
47569 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
47570 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
47571 }
47572
47573
47574 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
47575 index 1fc622b..8c48fc3 100644
47576 --- a/drivers/oprofile/oprofile_stats.h
47577 +++ b/drivers/oprofile/oprofile_stats.h
47578 @@ -13,11 +13,11 @@
47579 #include <linux/atomic.h>
47580
47581 struct oprofile_stat_struct {
47582 - atomic_t sample_lost_no_mm;
47583 - atomic_t sample_lost_no_mapping;
47584 - atomic_t bt_lost_no_mapping;
47585 - atomic_t event_lost_overflow;
47586 - atomic_t multiplex_counter;
47587 + atomic_unchecked_t sample_lost_no_mm;
47588 + atomic_unchecked_t sample_lost_no_mapping;
47589 + atomic_unchecked_t bt_lost_no_mapping;
47590 + atomic_unchecked_t event_lost_overflow;
47591 + atomic_unchecked_t multiplex_counter;
47592 };
47593
47594 extern struct oprofile_stat_struct oprofile_stats;
47595 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
47596 index 3f49345..c750d0b 100644
47597 --- a/drivers/oprofile/oprofilefs.c
47598 +++ b/drivers/oprofile/oprofilefs.c
47599 @@ -176,8 +176,8 @@ int oprofilefs_create_ro_ulong(struct dentry *root,
47600
47601 static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
47602 {
47603 - atomic_t *val = file->private_data;
47604 - return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
47605 + atomic_unchecked_t *val = file->private_data;
47606 + return oprofilefs_ulong_to_user(atomic_read_unchecked(val), buf, count, offset);
47607 }
47608
47609
47610 @@ -189,7 +189,7 @@ static const struct file_operations atomic_ro_fops = {
47611
47612
47613 int oprofilefs_create_ro_atomic(struct dentry *root,
47614 - char const *name, atomic_t *val)
47615 + char const *name, atomic_unchecked_t *val)
47616 {
47617 return __oprofilefs_create_file(root, name,
47618 &atomic_ro_fops, 0444, val);
47619 diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
47620 index 61be1d9..dec05d7 100644
47621 --- a/drivers/oprofile/timer_int.c
47622 +++ b/drivers/oprofile/timer_int.c
47623 @@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
47624 return NOTIFY_OK;
47625 }
47626
47627 -static struct notifier_block __refdata oprofile_cpu_notifier = {
47628 +static struct notifier_block oprofile_cpu_notifier = {
47629 .notifier_call = oprofile_cpu_notify,
47630 };
47631
47632 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
47633 index 92ed045..62d39bd7 100644
47634 --- a/drivers/parport/procfs.c
47635 +++ b/drivers/parport/procfs.c
47636 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
47637
47638 *ppos += len;
47639
47640 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
47641 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
47642 }
47643
47644 #ifdef CONFIG_PARPORT_1284
47645 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
47646
47647 *ppos += len;
47648
47649 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
47650 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
47651 }
47652 #endif /* IEEE1284.3 support. */
47653
47654 diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
47655 index 8dcccff..35d701d 100644
47656 --- a/drivers/pci/hotplug/acpiphp_ibm.c
47657 +++ b/drivers/pci/hotplug/acpiphp_ibm.c
47658 @@ -452,7 +452,9 @@ static int __init ibm_acpiphp_init(void)
47659 goto init_cleanup;
47660 }
47661
47662 - ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
47663 + pax_open_kernel();
47664 + *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
47665 + pax_close_kernel();
47666 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
47667
47668 return retval;
47669 diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
47670 index 7536eef..52dc8fa 100644
47671 --- a/drivers/pci/hotplug/cpcihp_generic.c
47672 +++ b/drivers/pci/hotplug/cpcihp_generic.c
47673 @@ -73,7 +73,6 @@ static u16 port;
47674 static unsigned int enum_bit;
47675 static u8 enum_mask;
47676
47677 -static struct cpci_hp_controller_ops generic_hpc_ops;
47678 static struct cpci_hp_controller generic_hpc;
47679
47680 static int __init validate_parameters(void)
47681 @@ -139,6 +138,10 @@ static int query_enum(void)
47682 return ((value & enum_mask) == enum_mask);
47683 }
47684
47685 +static struct cpci_hp_controller_ops generic_hpc_ops = {
47686 + .query_enum = query_enum,
47687 +};
47688 +
47689 static int __init cpcihp_generic_init(void)
47690 {
47691 int status;
47692 @@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
47693 pci_dev_put(dev);
47694
47695 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
47696 - generic_hpc_ops.query_enum = query_enum;
47697 generic_hpc.ops = &generic_hpc_ops;
47698
47699 status = cpci_hp_register_controller(&generic_hpc);
47700 diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
47701 index e8c4a7c..7046f5c 100644
47702 --- a/drivers/pci/hotplug/cpcihp_zt5550.c
47703 +++ b/drivers/pci/hotplug/cpcihp_zt5550.c
47704 @@ -59,7 +59,6 @@
47705 /* local variables */
47706 static bool debug;
47707 static bool poll;
47708 -static struct cpci_hp_controller_ops zt5550_hpc_ops;
47709 static struct cpci_hp_controller zt5550_hpc;
47710
47711 /* Primary cPCI bus bridge device */
47712 @@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
47713 return 0;
47714 }
47715
47716 +static struct cpci_hp_controller_ops zt5550_hpc_ops = {
47717 + .query_enum = zt5550_hc_query_enum,
47718 +};
47719 +
47720 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
47721 {
47722 int status;
47723 @@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
47724 dbg("returned from zt5550_hc_config");
47725
47726 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
47727 - zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
47728 zt5550_hpc.ops = &zt5550_hpc_ops;
47729 if(!poll) {
47730 zt5550_hpc.irq = hc_dev->irq;
47731 zt5550_hpc.irq_flags = IRQF_SHARED;
47732 zt5550_hpc.dev_id = hc_dev;
47733
47734 - zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
47735 - zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
47736 - zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
47737 + pax_open_kernel();
47738 + *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
47739 + *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
47740 + *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
47741 + pax_open_kernel();
47742 } else {
47743 info("using ENUM# polling mode");
47744 }
47745 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
47746 index 76ba8a1..20ca857 100644
47747 --- a/drivers/pci/hotplug/cpqphp_nvram.c
47748 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
47749 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
47750
47751 void compaq_nvram_init (void __iomem *rom_start)
47752 {
47753 +
47754 +#ifndef CONFIG_PAX_KERNEXEC
47755 if (rom_start) {
47756 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
47757 }
47758 +#endif
47759 +
47760 dbg("int15 entry = %p\n", compaq_int15_entry_point);
47761
47762 /* initialize our int15 lock */
47763 diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
47764 index cfa92a9..29539c5 100644
47765 --- a/drivers/pci/hotplug/pci_hotplug_core.c
47766 +++ b/drivers/pci/hotplug/pci_hotplug_core.c
47767 @@ -441,8 +441,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
47768 return -EINVAL;
47769 }
47770
47771 - slot->ops->owner = owner;
47772 - slot->ops->mod_name = mod_name;
47773 + pax_open_kernel();
47774 + *(struct module **)&slot->ops->owner = owner;
47775 + *(const char **)&slot->ops->mod_name = mod_name;
47776 + pax_close_kernel();
47777
47778 mutex_lock(&pci_hp_mutex);
47779 /*
47780 diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
47781 index 0e0a2ff..29dff57 100644
47782 --- a/drivers/pci/hotplug/pciehp_core.c
47783 +++ b/drivers/pci/hotplug/pciehp_core.c
47784 @@ -92,7 +92,7 @@ static int init_slot(struct controller *ctrl)
47785 struct slot *slot = ctrl->slot;
47786 struct hotplug_slot *hotplug = NULL;
47787 struct hotplug_slot_info *info = NULL;
47788 - struct hotplug_slot_ops *ops = NULL;
47789 + hotplug_slot_ops_no_const *ops = NULL;
47790 char name[SLOT_NAME_SIZE];
47791 int retval = -ENOMEM;
47792
47793 diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c
47794 index fb02fc2..83dc2c3 100644
47795 --- a/drivers/pci/msi.c
47796 +++ b/drivers/pci/msi.c
47797 @@ -524,8 +524,8 @@ static int populate_msi_sysfs(struct pci_dev *pdev)
47798 {
47799 struct attribute **msi_attrs;
47800 struct attribute *msi_attr;
47801 - struct device_attribute *msi_dev_attr;
47802 - struct attribute_group *msi_irq_group;
47803 + device_attribute_no_const *msi_dev_attr;
47804 + attribute_group_no_const *msi_irq_group;
47805 const struct attribute_group **msi_irq_groups;
47806 struct msi_desc *entry;
47807 int ret = -ENOMEM;
47808 @@ -589,7 +589,7 @@ error_attrs:
47809 count = 0;
47810 msi_attr = msi_attrs[count];
47811 while (msi_attr) {
47812 - msi_dev_attr = container_of(msi_attr, struct device_attribute, attr);
47813 + msi_dev_attr = container_of(msi_attr, device_attribute_no_const, attr);
47814 kfree(msi_attr->name);
47815 kfree(msi_dev_attr);
47816 ++count;
47817 diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
47818 index 4e0acef..bd98e31 100644
47819 --- a/drivers/pci/pci-sysfs.c
47820 +++ b/drivers/pci/pci-sysfs.c
47821 @@ -1101,7 +1101,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
47822 {
47823 /* allocate attribute structure, piggyback attribute name */
47824 int name_len = write_combine ? 13 : 10;
47825 - struct bin_attribute *res_attr;
47826 + bin_attribute_no_const *res_attr;
47827 int retval;
47828
47829 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
47830 @@ -1286,7 +1286,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
47831 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
47832 {
47833 int retval;
47834 - struct bin_attribute *attr;
47835 + bin_attribute_no_const *attr;
47836
47837 /* If the device has VPD, try to expose it in sysfs. */
47838 if (dev->vpd) {
47839 @@ -1333,7 +1333,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
47840 {
47841 int retval;
47842 int rom_size = 0;
47843 - struct bin_attribute *attr;
47844 + bin_attribute_no_const *attr;
47845
47846 if (!sysfs_initialized)
47847 return -EACCES;
47848 diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
47849 index 6bd0822..35bc2b3 100644
47850 --- a/drivers/pci/pci.h
47851 +++ b/drivers/pci/pci.h
47852 @@ -91,7 +91,7 @@ struct pci_vpd_ops {
47853 struct pci_vpd {
47854 unsigned int len;
47855 const struct pci_vpd_ops *ops;
47856 - struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
47857 + bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
47858 };
47859
47860 int pci_vpd_pci22_init(struct pci_dev *dev);
47861 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
47862 index e1e7026..d28dd33 100644
47863 --- a/drivers/pci/pcie/aspm.c
47864 +++ b/drivers/pci/pcie/aspm.c
47865 @@ -27,9 +27,9 @@
47866 #define MODULE_PARAM_PREFIX "pcie_aspm."
47867
47868 /* Note: those are not register definitions */
47869 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
47870 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
47871 -#define ASPM_STATE_L1 (4) /* L1 state */
47872 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
47873 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
47874 +#define ASPM_STATE_L1 (4U) /* L1 state */
47875 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
47876 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
47877
47878 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
47879 index ef09f5f..49ac62f 100644
47880 --- a/drivers/pci/probe.c
47881 +++ b/drivers/pci/probe.c
47882 @@ -175,7 +175,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
47883 struct pci_bus_region region, inverted_region;
47884 bool bar_too_big = false, bar_disabled = false;
47885
47886 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
47887 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
47888
47889 /* No printks while decoding is disabled! */
47890 if (!dev->mmio_always_on) {
47891 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
47892 index 46d1378..30e452b 100644
47893 --- a/drivers/pci/proc.c
47894 +++ b/drivers/pci/proc.c
47895 @@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
47896 static int __init pci_proc_init(void)
47897 {
47898 struct pci_dev *dev = NULL;
47899 +
47900 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
47901 +#ifdef CONFIG_GRKERNSEC_PROC_USER
47902 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
47903 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47904 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
47905 +#endif
47906 +#else
47907 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
47908 +#endif
47909 proc_create("devices", 0, proc_bus_pci_dir,
47910 &proc_bus_pci_dev_operations);
47911 proc_initialized = 1;
47912 diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c
47913 index 7f3aad0..7d604bb 100644
47914 --- a/drivers/platform/chrome/chromeos_laptop.c
47915 +++ b/drivers/platform/chrome/chromeos_laptop.c
47916 @@ -406,7 +406,7 @@ static struct chromeos_laptop cr48 = {
47917 .callback = chromeos_laptop_dmi_matched, \
47918 .driver_data = (void *)&board_
47919
47920 -static struct dmi_system_id chromeos_laptop_dmi_table[] __initdata = {
47921 +static struct dmi_system_id chromeos_laptop_dmi_table[] __initconst = {
47922 {
47923 .ident = "Samsung Series 5 550",
47924 .matches = {
47925 diff --git a/drivers/platform/x86/alienware-wmi.c b/drivers/platform/x86/alienware-wmi.c
47926 index 541f951..4dfd598 100644
47927 --- a/drivers/platform/x86/alienware-wmi.c
47928 +++ b/drivers/platform/x86/alienware-wmi.c
47929 @@ -132,7 +132,7 @@ struct wmax_led_args {
47930 } __packed;
47931
47932 static struct platform_device *platform_device;
47933 -static struct device_attribute *zone_dev_attrs;
47934 +static device_attribute_no_const *zone_dev_attrs;
47935 static struct attribute **zone_attrs;
47936 static struct platform_zone *zone_data;
47937
47938 @@ -143,7 +143,7 @@ static struct platform_driver platform_driver = {
47939 }
47940 };
47941
47942 -static struct attribute_group zone_attribute_group = {
47943 +static attribute_group_no_const zone_attribute_group = {
47944 .name = "rgb_zones",
47945 };
47946
47947 diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
47948 index c5e082f..d6307a0 100644
47949 --- a/drivers/platform/x86/asus-wmi.c
47950 +++ b/drivers/platform/x86/asus-wmi.c
47951 @@ -1595,6 +1595,10 @@ static int show_dsts(struct seq_file *m, void *data)
47952 int err;
47953 u32 retval = -1;
47954
47955 +#ifdef CONFIG_GRKERNSEC_KMEM
47956 + return -EPERM;
47957 +#endif
47958 +
47959 err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval);
47960
47961 if (err < 0)
47962 @@ -1611,6 +1615,10 @@ static int show_devs(struct seq_file *m, void *data)
47963 int err;
47964 u32 retval = -1;
47965
47966 +#ifdef CONFIG_GRKERNSEC_KMEM
47967 + return -EPERM;
47968 +#endif
47969 +
47970 err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param,
47971 &retval);
47972
47973 @@ -1635,6 +1643,10 @@ static int show_call(struct seq_file *m, void *data)
47974 union acpi_object *obj;
47975 acpi_status status;
47976
47977 +#ifdef CONFIG_GRKERNSEC_KMEM
47978 + return -EPERM;
47979 +#endif
47980 +
47981 status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
47982 1, asus->debug.method_id,
47983 &input, &output);
47984 diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
47985 index 62f8030..c7f2a45 100644
47986 --- a/drivers/platform/x86/msi-laptop.c
47987 +++ b/drivers/platform/x86/msi-laptop.c
47988 @@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
47989
47990 if (!quirks->ec_read_only) {
47991 /* allow userland write sysfs file */
47992 - dev_attr_bluetooth.store = store_bluetooth;
47993 - dev_attr_wlan.store = store_wlan;
47994 - dev_attr_threeg.store = store_threeg;
47995 - dev_attr_bluetooth.attr.mode |= S_IWUSR;
47996 - dev_attr_wlan.attr.mode |= S_IWUSR;
47997 - dev_attr_threeg.attr.mode |= S_IWUSR;
47998 + pax_open_kernel();
47999 + *(void **)&dev_attr_bluetooth.store = store_bluetooth;
48000 + *(void **)&dev_attr_wlan.store = store_wlan;
48001 + *(void **)&dev_attr_threeg.store = store_threeg;
48002 + *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
48003 + *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
48004 + *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
48005 + pax_close_kernel();
48006 }
48007
48008 /* disable hardware control by fn key */
48009 diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
48010 index 70222f2..8c8ce66 100644
48011 --- a/drivers/platform/x86/msi-wmi.c
48012 +++ b/drivers/platform/x86/msi-wmi.c
48013 @@ -183,7 +183,7 @@ static const struct backlight_ops msi_backlight_ops = {
48014 static void msi_wmi_notify(u32 value, void *context)
48015 {
48016 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
48017 - static struct key_entry *key;
48018 + struct key_entry *key;
48019 union acpi_object *obj;
48020 acpi_status status;
48021
48022 diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
48023 index 9c5a074..06c976a 100644
48024 --- a/drivers/platform/x86/sony-laptop.c
48025 +++ b/drivers/platform/x86/sony-laptop.c
48026 @@ -2527,7 +2527,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
48027 }
48028
48029 /* High speed charging function */
48030 -static struct device_attribute *hsc_handle;
48031 +static device_attribute_no_const *hsc_handle;
48032
48033 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
48034 struct device_attribute *attr,
48035 @@ -2601,7 +2601,7 @@ static void sony_nc_highspeed_charging_cleanup(struct platform_device *pd)
48036 }
48037
48038 /* low battery function */
48039 -static struct device_attribute *lowbatt_handle;
48040 +static device_attribute_no_const *lowbatt_handle;
48041
48042 static ssize_t sony_nc_lowbatt_store(struct device *dev,
48043 struct device_attribute *attr,
48044 @@ -2667,7 +2667,7 @@ static void sony_nc_lowbatt_cleanup(struct platform_device *pd)
48045 }
48046
48047 /* fan speed function */
48048 -static struct device_attribute *fan_handle, *hsf_handle;
48049 +static device_attribute_no_const *fan_handle, *hsf_handle;
48050
48051 static ssize_t sony_nc_hsfan_store(struct device *dev,
48052 struct device_attribute *attr,
48053 @@ -2774,7 +2774,7 @@ static void sony_nc_fanspeed_cleanup(struct platform_device *pd)
48054 }
48055
48056 /* USB charge function */
48057 -static struct device_attribute *uc_handle;
48058 +static device_attribute_no_const *uc_handle;
48059
48060 static ssize_t sony_nc_usb_charge_store(struct device *dev,
48061 struct device_attribute *attr,
48062 @@ -2848,7 +2848,7 @@ static void sony_nc_usb_charge_cleanup(struct platform_device *pd)
48063 }
48064
48065 /* Panel ID function */
48066 -static struct device_attribute *panel_handle;
48067 +static device_attribute_no_const *panel_handle;
48068
48069 static ssize_t sony_nc_panelid_show(struct device *dev,
48070 struct device_attribute *attr, char *buffer)
48071 @@ -2895,7 +2895,7 @@ static void sony_nc_panelid_cleanup(struct platform_device *pd)
48072 }
48073
48074 /* smart connect function */
48075 -static struct device_attribute *sc_handle;
48076 +static device_attribute_no_const *sc_handle;
48077
48078 static ssize_t sony_nc_smart_conn_store(struct device *dev,
48079 struct device_attribute *attr,
48080 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
48081 index 15e61c1..40a39c7 100644
48082 --- a/drivers/platform/x86/thinkpad_acpi.c
48083 +++ b/drivers/platform/x86/thinkpad_acpi.c
48084 @@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
48085 return 0;
48086 }
48087
48088 -void static hotkey_mask_warn_incomplete_mask(void)
48089 +static void hotkey_mask_warn_incomplete_mask(void)
48090 {
48091 /* log only what the user can fix... */
48092 const u32 wantedmask = hotkey_driver_mask &
48093 @@ -2438,10 +2438,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
48094 && !tp_features.bright_unkfw)
48095 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
48096 }
48097 +}
48098
48099 #undef TPACPI_COMPARE_KEY
48100 #undef TPACPI_MAY_SEND_KEY
48101 -}
48102
48103 /*
48104 * Polling driver
48105 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
48106 index 438d4c7..ca8a2fb 100644
48107 --- a/drivers/pnp/pnpbios/bioscalls.c
48108 +++ b/drivers/pnp/pnpbios/bioscalls.c
48109 @@ -59,7 +59,7 @@ do { \
48110 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
48111 } while(0)
48112
48113 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
48114 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
48115 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
48116
48117 /*
48118 @@ -96,7 +96,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
48119
48120 cpu = get_cpu();
48121 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
48122 +
48123 + pax_open_kernel();
48124 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
48125 + pax_close_kernel();
48126
48127 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
48128 spin_lock_irqsave(&pnp_bios_lock, flags);
48129 @@ -134,7 +137,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
48130 :"memory");
48131 spin_unlock_irqrestore(&pnp_bios_lock, flags);
48132
48133 + pax_open_kernel();
48134 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
48135 + pax_close_kernel();
48136 +
48137 put_cpu();
48138
48139 /* If we get here and this is set then the PnP BIOS faulted on us. */
48140 @@ -468,7 +474,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
48141 return status;
48142 }
48143
48144 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
48145 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
48146 {
48147 int i;
48148
48149 @@ -476,6 +482,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
48150 pnp_bios_callpoint.offset = header->fields.pm16offset;
48151 pnp_bios_callpoint.segment = PNP_CS16;
48152
48153 + pax_open_kernel();
48154 +
48155 for_each_possible_cpu(i) {
48156 struct desc_struct *gdt = get_cpu_gdt_table(i);
48157 if (!gdt)
48158 @@ -487,4 +495,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
48159 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
48160 (unsigned long)__va(header->fields.pm16dseg));
48161 }
48162 +
48163 + pax_close_kernel();
48164 }
48165 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
48166 index 01712cb..782e822 100644
48167 --- a/drivers/pnp/resource.c
48168 +++ b/drivers/pnp/resource.c
48169 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
48170 return 1;
48171
48172 /* check if the resource is valid */
48173 - if (*irq < 0 || *irq > 15)
48174 + if (*irq > 15)
48175 return 0;
48176
48177 /* check if the resource is reserved */
48178 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
48179 return 1;
48180
48181 /* check if the resource is valid */
48182 - if (*dma < 0 || *dma == 4 || *dma > 7)
48183 + if (*dma == 4 || *dma > 7)
48184 return 0;
48185
48186 /* check if the resource is reserved */
48187 diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
48188 index 0c52e2a..3421ab7 100644
48189 --- a/drivers/power/pda_power.c
48190 +++ b/drivers/power/pda_power.c
48191 @@ -37,7 +37,11 @@ static int polling;
48192
48193 #if IS_ENABLED(CONFIG_USB_PHY)
48194 static struct usb_phy *transceiver;
48195 -static struct notifier_block otg_nb;
48196 +static int otg_handle_notification(struct notifier_block *nb,
48197 + unsigned long event, void *unused);
48198 +static struct notifier_block otg_nb = {
48199 + .notifier_call = otg_handle_notification
48200 +};
48201 #endif
48202
48203 static struct regulator *ac_draw;
48204 @@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
48205
48206 #if IS_ENABLED(CONFIG_USB_PHY)
48207 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
48208 - otg_nb.notifier_call = otg_handle_notification;
48209 ret = usb_register_notifier(transceiver, &otg_nb);
48210 if (ret) {
48211 dev_err(dev, "failure to register otg notifier\n");
48212 diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
48213 index cc439fd..8fa30df 100644
48214 --- a/drivers/power/power_supply.h
48215 +++ b/drivers/power/power_supply.h
48216 @@ -16,12 +16,12 @@ struct power_supply;
48217
48218 #ifdef CONFIG_SYSFS
48219
48220 -extern void power_supply_init_attrs(struct device_type *dev_type);
48221 +extern void power_supply_init_attrs(void);
48222 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
48223
48224 #else
48225
48226 -static inline void power_supply_init_attrs(struct device_type *dev_type) {}
48227 +static inline void power_supply_init_attrs(void) {}
48228 #define power_supply_uevent NULL
48229
48230 #endif /* CONFIG_SYSFS */
48231 diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
48232 index 2660664..75fcb04 100644
48233 --- a/drivers/power/power_supply_core.c
48234 +++ b/drivers/power/power_supply_core.c
48235 @@ -28,7 +28,10 @@ EXPORT_SYMBOL_GPL(power_supply_class);
48236 ATOMIC_NOTIFIER_HEAD(power_supply_notifier);
48237 EXPORT_SYMBOL_GPL(power_supply_notifier);
48238
48239 -static struct device_type power_supply_dev_type;
48240 +extern const struct attribute_group *power_supply_attr_groups[];
48241 +static struct device_type power_supply_dev_type = {
48242 + .groups = power_supply_attr_groups,
48243 +};
48244
48245 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
48246 struct power_supply *supply)
48247 @@ -628,7 +631,7 @@ static int __init power_supply_class_init(void)
48248 return PTR_ERR(power_supply_class);
48249
48250 power_supply_class->dev_uevent = power_supply_uevent;
48251 - power_supply_init_attrs(&power_supply_dev_type);
48252 + power_supply_init_attrs();
48253
48254 return 0;
48255 }
48256 diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
48257 index 44420d1..967126e 100644
48258 --- a/drivers/power/power_supply_sysfs.c
48259 +++ b/drivers/power/power_supply_sysfs.c
48260 @@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
48261 .is_visible = power_supply_attr_is_visible,
48262 };
48263
48264 -static const struct attribute_group *power_supply_attr_groups[] = {
48265 +const struct attribute_group *power_supply_attr_groups[] = {
48266 &power_supply_attr_group,
48267 NULL,
48268 };
48269
48270 -void power_supply_init_attrs(struct device_type *dev_type)
48271 +void power_supply_init_attrs(void)
48272 {
48273 int i;
48274
48275 - dev_type->groups = power_supply_attr_groups;
48276 -
48277 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
48278 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
48279 }
48280 diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c
48281 index 84419af..268ede8 100644
48282 --- a/drivers/powercap/powercap_sys.c
48283 +++ b/drivers/powercap/powercap_sys.c
48284 @@ -154,8 +154,77 @@ struct powercap_constraint_attr {
48285 struct device_attribute name_attr;
48286 };
48287
48288 +static ssize_t show_constraint_name(struct device *dev,
48289 + struct device_attribute *dev_attr,
48290 + char *buf);
48291 +
48292 static struct powercap_constraint_attr
48293 - constraint_attrs[MAX_CONSTRAINTS_PER_ZONE];
48294 + constraint_attrs[MAX_CONSTRAINTS_PER_ZONE] = {
48295 + [0 ... MAX_CONSTRAINTS_PER_ZONE - 1] = {
48296 + .power_limit_attr = {
48297 + .attr = {
48298 + .name = NULL,
48299 + .mode = S_IWUSR | S_IRUGO
48300 + },
48301 + .show = show_constraint_power_limit_uw,
48302 + .store = store_constraint_power_limit_uw
48303 + },
48304 +
48305 + .time_window_attr = {
48306 + .attr = {
48307 + .name = NULL,
48308 + .mode = S_IWUSR | S_IRUGO
48309 + },
48310 + .show = show_constraint_time_window_us,
48311 + .store = store_constraint_time_window_us
48312 + },
48313 +
48314 + .max_power_attr = {
48315 + .attr = {
48316 + .name = NULL,
48317 + .mode = S_IRUGO
48318 + },
48319 + .show = show_constraint_max_power_uw,
48320 + .store = NULL
48321 + },
48322 +
48323 + .min_power_attr = {
48324 + .attr = {
48325 + .name = NULL,
48326 + .mode = S_IRUGO
48327 + },
48328 + .show = show_constraint_min_power_uw,
48329 + .store = NULL
48330 + },
48331 +
48332 + .max_time_window_attr = {
48333 + .attr = {
48334 + .name = NULL,
48335 + .mode = S_IRUGO
48336 + },
48337 + .show = show_constraint_max_time_window_us,
48338 + .store = NULL
48339 + },
48340 +
48341 + .min_time_window_attr = {
48342 + .attr = {
48343 + .name = NULL,
48344 + .mode = S_IRUGO
48345 + },
48346 + .show = show_constraint_min_time_window_us,
48347 + .store = NULL
48348 + },
48349 +
48350 + .name_attr = {
48351 + .attr = {
48352 + .name = NULL,
48353 + .mode = S_IRUGO
48354 + },
48355 + .show = show_constraint_name,
48356 + .store = NULL
48357 + }
48358 + }
48359 +};
48360
48361 /* A list of powercap control_types */
48362 static LIST_HEAD(powercap_cntrl_list);
48363 @@ -193,23 +262,16 @@ static ssize_t show_constraint_name(struct device *dev,
48364 }
48365
48366 static int create_constraint_attribute(int id, const char *name,
48367 - int mode,
48368 - struct device_attribute *dev_attr,
48369 - ssize_t (*show)(struct device *,
48370 - struct device_attribute *, char *),
48371 - ssize_t (*store)(struct device *,
48372 - struct device_attribute *,
48373 - const char *, size_t)
48374 - )
48375 + struct device_attribute *dev_attr)
48376 {
48377 + name = kasprintf(GFP_KERNEL, "constraint_%d_%s", id, name);
48378
48379 - dev_attr->attr.name = kasprintf(GFP_KERNEL, "constraint_%d_%s",
48380 - id, name);
48381 - if (!dev_attr->attr.name)
48382 + if (!name)
48383 return -ENOMEM;
48384 - dev_attr->attr.mode = mode;
48385 - dev_attr->show = show;
48386 - dev_attr->store = store;
48387 +
48388 + pax_open_kernel();
48389 + *(const char **)&dev_attr->attr.name = name;
48390 + pax_close_kernel();
48391
48392 return 0;
48393 }
48394 @@ -236,49 +298,31 @@ static int seed_constraint_attributes(void)
48395
48396 for (i = 0; i < MAX_CONSTRAINTS_PER_ZONE; ++i) {
48397 ret = create_constraint_attribute(i, "power_limit_uw",
48398 - S_IWUSR | S_IRUGO,
48399 - &constraint_attrs[i].power_limit_attr,
48400 - show_constraint_power_limit_uw,
48401 - store_constraint_power_limit_uw);
48402 + &constraint_attrs[i].power_limit_attr);
48403 if (ret)
48404 goto err_alloc;
48405 ret = create_constraint_attribute(i, "time_window_us",
48406 - S_IWUSR | S_IRUGO,
48407 - &constraint_attrs[i].time_window_attr,
48408 - show_constraint_time_window_us,
48409 - store_constraint_time_window_us);
48410 + &constraint_attrs[i].time_window_attr);
48411 if (ret)
48412 goto err_alloc;
48413 - ret = create_constraint_attribute(i, "name", S_IRUGO,
48414 - &constraint_attrs[i].name_attr,
48415 - show_constraint_name,
48416 - NULL);
48417 + ret = create_constraint_attribute(i, "name",
48418 + &constraint_attrs[i].name_attr);
48419 if (ret)
48420 goto err_alloc;
48421 - ret = create_constraint_attribute(i, "max_power_uw", S_IRUGO,
48422 - &constraint_attrs[i].max_power_attr,
48423 - show_constraint_max_power_uw,
48424 - NULL);
48425 + ret = create_constraint_attribute(i, "max_power_uw",
48426 + &constraint_attrs[i].max_power_attr);
48427 if (ret)
48428 goto err_alloc;
48429 - ret = create_constraint_attribute(i, "min_power_uw", S_IRUGO,
48430 - &constraint_attrs[i].min_power_attr,
48431 - show_constraint_min_power_uw,
48432 - NULL);
48433 + ret = create_constraint_attribute(i, "min_power_uw",
48434 + &constraint_attrs[i].min_power_attr);
48435 if (ret)
48436 goto err_alloc;
48437 ret = create_constraint_attribute(i, "max_time_window_us",
48438 - S_IRUGO,
48439 - &constraint_attrs[i].max_time_window_attr,
48440 - show_constraint_max_time_window_us,
48441 - NULL);
48442 + &constraint_attrs[i].max_time_window_attr);
48443 if (ret)
48444 goto err_alloc;
48445 ret = create_constraint_attribute(i, "min_time_window_us",
48446 - S_IRUGO,
48447 - &constraint_attrs[i].min_time_window_attr,
48448 - show_constraint_min_time_window_us,
48449 - NULL);
48450 + &constraint_attrs[i].min_time_window_attr);
48451 if (ret)
48452 goto err_alloc;
48453
48454 @@ -378,10 +422,12 @@ static void create_power_zone_common_attributes(
48455 power_zone->zone_dev_attrs[count++] =
48456 &dev_attr_max_energy_range_uj.attr;
48457 if (power_zone->ops->get_energy_uj) {
48458 + pax_open_kernel();
48459 if (power_zone->ops->reset_energy_uj)
48460 - dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
48461 + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
48462 else
48463 - dev_attr_energy_uj.attr.mode = S_IRUGO;
48464 + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IRUGO;
48465 + pax_close_kernel();
48466 power_zone->zone_dev_attrs[count++] =
48467 &dev_attr_energy_uj.attr;
48468 }
48469 diff --git a/drivers/ptp/ptp_private.h b/drivers/ptp/ptp_private.h
48470 index 9c5d414..c7900ce 100644
48471 --- a/drivers/ptp/ptp_private.h
48472 +++ b/drivers/ptp/ptp_private.h
48473 @@ -51,7 +51,7 @@ struct ptp_clock {
48474 struct mutex pincfg_mux; /* protect concurrent info->pin_config access */
48475 wait_queue_head_t tsev_wq;
48476 int defunct; /* tells readers to go away when clock is being removed */
48477 - struct device_attribute *pin_dev_attr;
48478 + device_attribute_no_const *pin_dev_attr;
48479 struct attribute **pin_attr;
48480 struct attribute_group pin_attr_group;
48481 };
48482 diff --git a/drivers/ptp/ptp_sysfs.c b/drivers/ptp/ptp_sysfs.c
48483 index 302e626..12579af 100644
48484 --- a/drivers/ptp/ptp_sysfs.c
48485 +++ b/drivers/ptp/ptp_sysfs.c
48486 @@ -280,7 +280,7 @@ static int ptp_populate_pins(struct ptp_clock *ptp)
48487 goto no_pin_attr;
48488
48489 for (i = 0; i < n_pins; i++) {
48490 - struct device_attribute *da = &ptp->pin_dev_attr[i];
48491 + device_attribute_no_const *da = &ptp->pin_dev_attr[i];
48492 sysfs_attr_init(&da->attr);
48493 da->attr.name = info->pin_config[i].name;
48494 da->attr.mode = 0644;
48495 diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
48496 index 9a09f3c..450b523 100644
48497 --- a/drivers/regulator/core.c
48498 +++ b/drivers/regulator/core.c
48499 @@ -3380,7 +3380,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
48500 {
48501 const struct regulation_constraints *constraints = NULL;
48502 const struct regulator_init_data *init_data;
48503 - static atomic_t regulator_no = ATOMIC_INIT(0);
48504 + static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
48505 struct regulator_dev *rdev;
48506 struct device *dev;
48507 int ret, i;
48508 @@ -3450,7 +3450,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
48509 rdev->dev.of_node = config->of_node;
48510 rdev->dev.parent = dev;
48511 dev_set_name(&rdev->dev, "regulator.%d",
48512 - atomic_inc_return(&regulator_no) - 1);
48513 + atomic_inc_return_unchecked(&regulator_no) - 1);
48514 ret = device_register(&rdev->dev);
48515 if (ret != 0) {
48516 put_device(&rdev->dev);
48517 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
48518 index 2fc4111..6aa88ca 100644
48519 --- a/drivers/regulator/max8660.c
48520 +++ b/drivers/regulator/max8660.c
48521 @@ -424,8 +424,10 @@ static int max8660_probe(struct i2c_client *client,
48522 max8660->shadow_regs[MAX8660_OVER1] = 5;
48523 } else {
48524 /* Otherwise devices can be toggled via software */
48525 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
48526 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
48527 + pax_open_kernel();
48528 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
48529 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
48530 + pax_close_kernel();
48531 }
48532
48533 /*
48534 diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
48535 index dbedf17..18ff6b7 100644
48536 --- a/drivers/regulator/max8973-regulator.c
48537 +++ b/drivers/regulator/max8973-regulator.c
48538 @@ -403,9 +403,11 @@ static int max8973_probe(struct i2c_client *client,
48539 if (!pdata || !pdata->enable_ext_control) {
48540 max->desc.enable_reg = MAX8973_VOUT;
48541 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
48542 - max->ops.enable = regulator_enable_regmap;
48543 - max->ops.disable = regulator_disable_regmap;
48544 - max->ops.is_enabled = regulator_is_enabled_regmap;
48545 + pax_open_kernel();
48546 + *(void **)&max->ops.enable = regulator_enable_regmap;
48547 + *(void **)&max->ops.disable = regulator_disable_regmap;
48548 + *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
48549 + pax_close_kernel();
48550 }
48551
48552 if (pdata) {
48553 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
48554 index f374fa5..26f0683 100644
48555 --- a/drivers/regulator/mc13892-regulator.c
48556 +++ b/drivers/regulator/mc13892-regulator.c
48557 @@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
48558 }
48559 mc13xxx_unlock(mc13892);
48560
48561 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
48562 + pax_open_kernel();
48563 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
48564 = mc13892_vcam_set_mode;
48565 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
48566 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
48567 = mc13892_vcam_get_mode;
48568 + pax_close_kernel();
48569
48570 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
48571 ARRAY_SIZE(mc13892_regulators));
48572 diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
48573 index 0963c93..ea29cce 100644
48574 --- a/drivers/rtc/rtc-cmos.c
48575 +++ b/drivers/rtc/rtc-cmos.c
48576 @@ -777,7 +777,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
48577 hpet_rtc_timer_init();
48578
48579 /* export at least the first block of NVRAM */
48580 - nvram.size = address_space - NVRAM_OFFSET;
48581 + pax_open_kernel();
48582 + *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
48583 + pax_close_kernel();
48584 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
48585 if (retval < 0) {
48586 dev_dbg(dev, "can't create nvram file? %d\n", retval);
48587 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
48588 index d049393..bb20be0 100644
48589 --- a/drivers/rtc/rtc-dev.c
48590 +++ b/drivers/rtc/rtc-dev.c
48591 @@ -16,6 +16,7 @@
48592 #include <linux/module.h>
48593 #include <linux/rtc.h>
48594 #include <linux/sched.h>
48595 +#include <linux/grsecurity.h>
48596 #include "rtc-core.h"
48597
48598 static dev_t rtc_devt;
48599 @@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
48600 if (copy_from_user(&tm, uarg, sizeof(tm)))
48601 return -EFAULT;
48602
48603 + gr_log_timechange();
48604 +
48605 return rtc_set_time(rtc, &tm);
48606
48607 case RTC_PIE_ON:
48608 diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
48609 index f03d5ba..8325bf6 100644
48610 --- a/drivers/rtc/rtc-ds1307.c
48611 +++ b/drivers/rtc/rtc-ds1307.c
48612 @@ -107,7 +107,7 @@ struct ds1307 {
48613 u8 offset; /* register's offset */
48614 u8 regs[11];
48615 u16 nvram_offset;
48616 - struct bin_attribute *nvram;
48617 + bin_attribute_no_const *nvram;
48618 enum ds_type type;
48619 unsigned long flags;
48620 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
48621 diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
48622 index 11880c1..b823aa4 100644
48623 --- a/drivers/rtc/rtc-m48t59.c
48624 +++ b/drivers/rtc/rtc-m48t59.c
48625 @@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
48626 if (IS_ERR(m48t59->rtc))
48627 return PTR_ERR(m48t59->rtc);
48628
48629 - m48t59_nvram_attr.size = pdata->offset;
48630 + pax_open_kernel();
48631 + *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
48632 + pax_close_kernel();
48633
48634 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
48635 if (ret)
48636 diff --git a/drivers/scsi/aic7xxx/aic79xx_pci.c b/drivers/scsi/aic7xxx/aic79xx_pci.c
48637 index 14b5f8d..cc9bd26 100644
48638 --- a/drivers/scsi/aic7xxx/aic79xx_pci.c
48639 +++ b/drivers/scsi/aic7xxx/aic79xx_pci.c
48640 @@ -827,7 +827,7 @@ ahd_pci_intr(struct ahd_softc *ahd)
48641 for (bit = 0; bit < 8; bit++) {
48642
48643 if ((pci_status[i] & (0x1 << bit)) != 0) {
48644 - static const char *s;
48645 + const char *s;
48646
48647 s = pci_status_strings[bit];
48648 if (i == 7/*TARG*/ && bit == 3)
48649 @@ -887,23 +887,15 @@ ahd_pci_split_intr(struct ahd_softc *ahd, u_int intstat)
48650
48651 for (bit = 0; bit < 8; bit++) {
48652
48653 - if ((split_status[i] & (0x1 << bit)) != 0) {
48654 - static const char *s;
48655 -
48656 - s = split_status_strings[bit];
48657 - printk(s, ahd_name(ahd),
48658 + if ((split_status[i] & (0x1 << bit)) != 0)
48659 + printk(split_status_strings[bit], ahd_name(ahd),
48660 split_status_source[i]);
48661 - }
48662
48663 if (i > 1)
48664 continue;
48665
48666 - if ((sg_split_status[i] & (0x1 << bit)) != 0) {
48667 - static const char *s;
48668 -
48669 - s = split_status_strings[bit];
48670 - printk(s, ahd_name(ahd), "SG");
48671 - }
48672 + if ((sg_split_status[i] & (0x1 << bit)) != 0)
48673 + printk(split_status_strings[bit], ahd_name(ahd), "SG");
48674 }
48675 }
48676 /*
48677 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
48678 index e693af6..2e525b6 100644
48679 --- a/drivers/scsi/bfa/bfa_fcpim.h
48680 +++ b/drivers/scsi/bfa/bfa_fcpim.h
48681 @@ -36,7 +36,7 @@ struct bfa_iotag_s {
48682
48683 struct bfa_itn_s {
48684 bfa_isr_func_t isr;
48685 -};
48686 +} __no_const;
48687
48688 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
48689 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
48690 diff --git a/drivers/scsi/bfa/bfa_fcs.c b/drivers/scsi/bfa/bfa_fcs.c
48691 index a3ab5cc..8143622 100644
48692 --- a/drivers/scsi/bfa/bfa_fcs.c
48693 +++ b/drivers/scsi/bfa/bfa_fcs.c
48694 @@ -38,10 +38,21 @@ struct bfa_fcs_mod_s {
48695 #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
48696
48697 static struct bfa_fcs_mod_s fcs_modules[] = {
48698 - { bfa_fcs_port_attach, NULL, NULL },
48699 - { bfa_fcs_uf_attach, NULL, NULL },
48700 - { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
48701 - bfa_fcs_fabric_modexit },
48702 + {
48703 + .attach = bfa_fcs_port_attach,
48704 + .modinit = NULL,
48705 + .modexit = NULL
48706 + },
48707 + {
48708 + .attach = bfa_fcs_uf_attach,
48709 + .modinit = NULL,
48710 + .modexit = NULL
48711 + },
48712 + {
48713 + .attach = bfa_fcs_fabric_attach,
48714 + .modinit = bfa_fcs_fabric_modinit,
48715 + .modexit = bfa_fcs_fabric_modexit
48716 + },
48717 };
48718
48719 /*
48720 diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
48721 index ff75ef8..2dfe00a 100644
48722 --- a/drivers/scsi/bfa/bfa_fcs_lport.c
48723 +++ b/drivers/scsi/bfa/bfa_fcs_lport.c
48724 @@ -89,15 +89,26 @@ static struct {
48725 void (*offline) (struct bfa_fcs_lport_s *port);
48726 } __port_action[] = {
48727 {
48728 - bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
48729 - bfa_fcs_lport_unknown_offline}, {
48730 - bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
48731 - bfa_fcs_lport_fab_offline}, {
48732 - bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
48733 - bfa_fcs_lport_n2n_offline}, {
48734 - bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
48735 - bfa_fcs_lport_loop_offline},
48736 - };
48737 + .init = bfa_fcs_lport_unknown_init,
48738 + .online = bfa_fcs_lport_unknown_online,
48739 + .offline = bfa_fcs_lport_unknown_offline
48740 + },
48741 + {
48742 + .init = bfa_fcs_lport_fab_init,
48743 + .online = bfa_fcs_lport_fab_online,
48744 + .offline = bfa_fcs_lport_fab_offline
48745 + },
48746 + {
48747 + .init = bfa_fcs_lport_n2n_init,
48748 + .online = bfa_fcs_lport_n2n_online,
48749 + .offline = bfa_fcs_lport_n2n_offline
48750 + },
48751 + {
48752 + .init = bfa_fcs_lport_loop_init,
48753 + .online = bfa_fcs_lport_loop_online,
48754 + .offline = bfa_fcs_lport_loop_offline
48755 + },
48756 +};
48757
48758 /*
48759 * fcs_port_sm FCS logical port state machine
48760 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
48761 index 2e28392..9d865b6 100644
48762 --- a/drivers/scsi/bfa/bfa_ioc.h
48763 +++ b/drivers/scsi/bfa/bfa_ioc.h
48764 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
48765 bfa_ioc_disable_cbfn_t disable_cbfn;
48766 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
48767 bfa_ioc_reset_cbfn_t reset_cbfn;
48768 -};
48769 +} __no_const;
48770
48771 /*
48772 * IOC event notification mechanism.
48773 @@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
48774 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
48775 enum bfi_ioc_state fwstate);
48776 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
48777 -};
48778 +} __no_const;
48779
48780 /*
48781 * Queue element to wait for room in request queue. FIFO order is
48782 diff --git a/drivers/scsi/bfa/bfa_modules.h b/drivers/scsi/bfa/bfa_modules.h
48783 index a14c784..6de6790 100644
48784 --- a/drivers/scsi/bfa/bfa_modules.h
48785 +++ b/drivers/scsi/bfa/bfa_modules.h
48786 @@ -78,12 +78,12 @@ enum {
48787 \
48788 extern struct bfa_module_s hal_mod_ ## __mod; \
48789 struct bfa_module_s hal_mod_ ## __mod = { \
48790 - bfa_ ## __mod ## _meminfo, \
48791 - bfa_ ## __mod ## _attach, \
48792 - bfa_ ## __mod ## _detach, \
48793 - bfa_ ## __mod ## _start, \
48794 - bfa_ ## __mod ## _stop, \
48795 - bfa_ ## __mod ## _iocdisable, \
48796 + .meminfo = bfa_ ## __mod ## _meminfo, \
48797 + .attach = bfa_ ## __mod ## _attach, \
48798 + .detach = bfa_ ## __mod ## _detach, \
48799 + .start = bfa_ ## __mod ## _start, \
48800 + .stop = bfa_ ## __mod ## _stop, \
48801 + .iocdisable = bfa_ ## __mod ## _iocdisable, \
48802 }
48803
48804 #define BFA_CACHELINE_SZ (256)
48805 diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
48806 index 045c4e1..13de803 100644
48807 --- a/drivers/scsi/fcoe/fcoe_sysfs.c
48808 +++ b/drivers/scsi/fcoe/fcoe_sysfs.c
48809 @@ -33,8 +33,8 @@
48810 */
48811 #include "libfcoe.h"
48812
48813 -static atomic_t ctlr_num;
48814 -static atomic_t fcf_num;
48815 +static atomic_unchecked_t ctlr_num;
48816 +static atomic_unchecked_t fcf_num;
48817
48818 /*
48819 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
48820 @@ -685,7 +685,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
48821 if (!ctlr)
48822 goto out;
48823
48824 - ctlr->id = atomic_inc_return(&ctlr_num) - 1;
48825 + ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
48826 ctlr->f = f;
48827 ctlr->mode = FIP_CONN_TYPE_FABRIC;
48828 INIT_LIST_HEAD(&ctlr->fcfs);
48829 @@ -902,7 +902,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
48830 fcf->dev.parent = &ctlr->dev;
48831 fcf->dev.bus = &fcoe_bus_type;
48832 fcf->dev.type = &fcoe_fcf_device_type;
48833 - fcf->id = atomic_inc_return(&fcf_num) - 1;
48834 + fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
48835 fcf->state = FCOE_FCF_STATE_UNKNOWN;
48836
48837 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
48838 @@ -938,8 +938,8 @@ int __init fcoe_sysfs_setup(void)
48839 {
48840 int error;
48841
48842 - atomic_set(&ctlr_num, 0);
48843 - atomic_set(&fcf_num, 0);
48844 + atomic_set_unchecked(&ctlr_num, 0);
48845 + atomic_set_unchecked(&fcf_num, 0);
48846
48847 error = bus_register(&fcoe_bus_type);
48848 if (error)
48849 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
48850 index 3cbb57a..95e47a3 100644
48851 --- a/drivers/scsi/hosts.c
48852 +++ b/drivers/scsi/hosts.c
48853 @@ -42,7 +42,7 @@
48854 #include "scsi_logging.h"
48855
48856
48857 -static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
48858 +static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
48859
48860
48861 static void scsi_host_cls_release(struct device *dev)
48862 @@ -369,7 +369,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
48863 * subtract one because we increment first then return, but we need to
48864 * know what the next host number was before increment
48865 */
48866 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
48867 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
48868 shost->dma_channel = 0xff;
48869
48870 /* These three are default values which can be overridden */
48871 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
48872 index fda6cf1..7a6b5d8 100644
48873 --- a/drivers/scsi/hpsa.c
48874 +++ b/drivers/scsi/hpsa.c
48875 @@ -699,10 +699,10 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
48876 unsigned long flags;
48877
48878 if (h->transMethod & CFGTBL_Trans_io_accel1)
48879 - return h->access.command_completed(h, q);
48880 + return h->access->command_completed(h, q);
48881
48882 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
48883 - return h->access.command_completed(h, q);
48884 + return h->access->command_completed(h, q);
48885
48886 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
48887 a = rq->head[rq->current_entry];
48888 @@ -5460,7 +5460,7 @@ static void start_io(struct ctlr_info *h)
48889 while (!list_empty(&h->reqQ)) {
48890 c = list_entry(h->reqQ.next, struct CommandList, list);
48891 /* can't do anything if fifo is full */
48892 - if ((h->access.fifo_full(h))) {
48893 + if ((h->access->fifo_full(h))) {
48894 h->fifo_recently_full = 1;
48895 dev_warn(&h->pdev->dev, "fifo full\n");
48896 break;
48897 @@ -5484,7 +5484,7 @@ static void start_io(struct ctlr_info *h)
48898
48899 /* Tell the controller execute command */
48900 spin_unlock_irqrestore(&h->lock, flags);
48901 - h->access.submit_command(h, c);
48902 + h->access->submit_command(h, c);
48903 spin_lock_irqsave(&h->lock, flags);
48904 }
48905 spin_unlock_irqrestore(&h->lock, flags);
48906 @@ -5492,17 +5492,17 @@ static void start_io(struct ctlr_info *h)
48907
48908 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
48909 {
48910 - return h->access.command_completed(h, q);
48911 + return h->access->command_completed(h, q);
48912 }
48913
48914 static inline bool interrupt_pending(struct ctlr_info *h)
48915 {
48916 - return h->access.intr_pending(h);
48917 + return h->access->intr_pending(h);
48918 }
48919
48920 static inline long interrupt_not_for_us(struct ctlr_info *h)
48921 {
48922 - return (h->access.intr_pending(h) == 0) ||
48923 + return (h->access->intr_pending(h) == 0) ||
48924 (h->interrupts_enabled == 0);
48925 }
48926
48927 @@ -6456,7 +6456,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
48928 if (prod_index < 0)
48929 return -ENODEV;
48930 h->product_name = products[prod_index].product_name;
48931 - h->access = *(products[prod_index].access);
48932 + h->access = products[prod_index].access;
48933
48934 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
48935 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
48936 @@ -6735,7 +6735,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
48937 {
48938 unsigned long flags;
48939
48940 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
48941 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
48942 spin_lock_irqsave(&h->lock, flags);
48943 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
48944 spin_unlock_irqrestore(&h->lock, flags);
48945 @@ -6963,7 +6963,7 @@ reinit_after_soft_reset:
48946 }
48947
48948 /* make sure the board interrupts are off */
48949 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
48950 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
48951
48952 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
48953 goto clean2;
48954 @@ -6998,7 +6998,7 @@ reinit_after_soft_reset:
48955 * fake ones to scoop up any residual completions.
48956 */
48957 spin_lock_irqsave(&h->lock, flags);
48958 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
48959 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
48960 spin_unlock_irqrestore(&h->lock, flags);
48961 free_irqs(h);
48962 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
48963 @@ -7017,9 +7017,9 @@ reinit_after_soft_reset:
48964 dev_info(&h->pdev->dev, "Board READY.\n");
48965 dev_info(&h->pdev->dev,
48966 "Waiting for stale completions to drain.\n");
48967 - h->access.set_intr_mask(h, HPSA_INTR_ON);
48968 + h->access->set_intr_mask(h, HPSA_INTR_ON);
48969 msleep(10000);
48970 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
48971 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
48972
48973 rc = controller_reset_failed(h->cfgtable);
48974 if (rc)
48975 @@ -7045,7 +7045,7 @@ reinit_after_soft_reset:
48976 h->drv_req_rescan = 0;
48977
48978 /* Turn the interrupts on so we can service requests */
48979 - h->access.set_intr_mask(h, HPSA_INTR_ON);
48980 + h->access->set_intr_mask(h, HPSA_INTR_ON);
48981
48982 hpsa_hba_inquiry(h);
48983 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
48984 @@ -7114,7 +7114,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
48985 * To write all data in the battery backed cache to disks
48986 */
48987 hpsa_flush_cache(h);
48988 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
48989 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
48990 hpsa_free_irqs_and_disable_msix(h);
48991 }
48992
48993 @@ -7232,7 +7232,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
48994 CFGTBL_Trans_enable_directed_msix |
48995 (trans_support & (CFGTBL_Trans_io_accel1 |
48996 CFGTBL_Trans_io_accel2));
48997 - struct access_method access = SA5_performant_access;
48998 + struct access_method *access = &SA5_performant_access;
48999
49000 /* This is a bit complicated. There are 8 registers on
49001 * the controller which we write to to tell it 8 different
49002 @@ -7297,12 +7297,12 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 trans_support)
49003 * enable outbound interrupt coalescing in accelerator mode;
49004 */
49005 if (trans_support & CFGTBL_Trans_io_accel1) {
49006 - access = SA5_ioaccel_mode1_access;
49007 + access = &SA5_ioaccel_mode1_access;
49008 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
49009 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
49010 } else {
49011 if (trans_support & CFGTBL_Trans_io_accel2) {
49012 - access = SA5_ioaccel_mode2_access;
49013 + access = &SA5_ioaccel_mode2_access;
49014 writel(10, &h->cfgtable->HostWrite.CoalIntDelay);
49015 writel(4, &h->cfgtable->HostWrite.CoalIntCount);
49016 }
49017 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
49018 index 44235a2..962e91b 100644
49019 --- a/drivers/scsi/hpsa.h
49020 +++ b/drivers/scsi/hpsa.h
49021 @@ -128,7 +128,7 @@ struct ctlr_info {
49022 unsigned int msix_vector;
49023 unsigned int msi_vector;
49024 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
49025 - struct access_method access;
49026 + struct access_method *access;
49027 char hba_mode_enabled;
49028
49029 /* queue and queue Info */
49030 @@ -541,35 +541,35 @@ static unsigned long SA5_ioaccel_mode1_completed(struct ctlr_info *h, u8 q)
49031 }
49032
49033 static struct access_method SA5_access = {
49034 - SA5_submit_command,
49035 - SA5_intr_mask,
49036 - SA5_fifo_full,
49037 - SA5_intr_pending,
49038 - SA5_completed,
49039 + .submit_command = SA5_submit_command,
49040 + .set_intr_mask = SA5_intr_mask,
49041 + .fifo_full = SA5_fifo_full,
49042 + .intr_pending = SA5_intr_pending,
49043 + .command_completed = SA5_completed,
49044 };
49045
49046 static struct access_method SA5_ioaccel_mode1_access = {
49047 - SA5_submit_command,
49048 - SA5_performant_intr_mask,
49049 - SA5_fifo_full,
49050 - SA5_ioaccel_mode1_intr_pending,
49051 - SA5_ioaccel_mode1_completed,
49052 + .submit_command = SA5_submit_command,
49053 + .set_intr_mask = SA5_performant_intr_mask,
49054 + .fifo_full = SA5_fifo_full,
49055 + .intr_pending = SA5_ioaccel_mode1_intr_pending,
49056 + .command_completed = SA5_ioaccel_mode1_completed,
49057 };
49058
49059 static struct access_method SA5_ioaccel_mode2_access = {
49060 - SA5_submit_command_ioaccel2,
49061 - SA5_performant_intr_mask,
49062 - SA5_fifo_full,
49063 - SA5_performant_intr_pending,
49064 - SA5_performant_completed,
49065 + .submit_command = SA5_submit_command_ioaccel2,
49066 + .set_intr_mask = SA5_performant_intr_mask,
49067 + .fifo_full = SA5_fifo_full,
49068 + .intr_pending = SA5_performant_intr_pending,
49069 + .command_completed = SA5_performant_completed,
49070 };
49071
49072 static struct access_method SA5_performant_access = {
49073 - SA5_submit_command,
49074 - SA5_performant_intr_mask,
49075 - SA5_fifo_full,
49076 - SA5_performant_intr_pending,
49077 - SA5_performant_completed,
49078 + .submit_command = SA5_submit_command,
49079 + .set_intr_mask = SA5_performant_intr_mask,
49080 + .fifo_full = SA5_fifo_full,
49081 + .intr_pending = SA5_performant_intr_pending,
49082 + .command_completed = SA5_performant_completed,
49083 };
49084
49085 struct board_type {
49086 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
49087 index 1b3a094..068e683 100644
49088 --- a/drivers/scsi/libfc/fc_exch.c
49089 +++ b/drivers/scsi/libfc/fc_exch.c
49090 @@ -101,12 +101,12 @@ struct fc_exch_mgr {
49091 u16 pool_max_index;
49092
49093 struct {
49094 - atomic_t no_free_exch;
49095 - atomic_t no_free_exch_xid;
49096 - atomic_t xid_not_found;
49097 - atomic_t xid_busy;
49098 - atomic_t seq_not_found;
49099 - atomic_t non_bls_resp;
49100 + atomic_unchecked_t no_free_exch;
49101 + atomic_unchecked_t no_free_exch_xid;
49102 + atomic_unchecked_t xid_not_found;
49103 + atomic_unchecked_t xid_busy;
49104 + atomic_unchecked_t seq_not_found;
49105 + atomic_unchecked_t non_bls_resp;
49106 } stats;
49107 };
49108
49109 @@ -811,7 +811,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
49110 /* allocate memory for exchange */
49111 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
49112 if (!ep) {
49113 - atomic_inc(&mp->stats.no_free_exch);
49114 + atomic_inc_unchecked(&mp->stats.no_free_exch);
49115 goto out;
49116 }
49117 memset(ep, 0, sizeof(*ep));
49118 @@ -874,7 +874,7 @@ out:
49119 return ep;
49120 err:
49121 spin_unlock_bh(&pool->lock);
49122 - atomic_inc(&mp->stats.no_free_exch_xid);
49123 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
49124 mempool_free(ep, mp->ep_pool);
49125 return NULL;
49126 }
49127 @@ -1023,7 +1023,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
49128 xid = ntohs(fh->fh_ox_id); /* we originated exch */
49129 ep = fc_exch_find(mp, xid);
49130 if (!ep) {
49131 - atomic_inc(&mp->stats.xid_not_found);
49132 + atomic_inc_unchecked(&mp->stats.xid_not_found);
49133 reject = FC_RJT_OX_ID;
49134 goto out;
49135 }
49136 @@ -1053,7 +1053,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
49137 ep = fc_exch_find(mp, xid);
49138 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
49139 if (ep) {
49140 - atomic_inc(&mp->stats.xid_busy);
49141 + atomic_inc_unchecked(&mp->stats.xid_busy);
49142 reject = FC_RJT_RX_ID;
49143 goto rel;
49144 }
49145 @@ -1064,7 +1064,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
49146 }
49147 xid = ep->xid; /* get our XID */
49148 } else if (!ep) {
49149 - atomic_inc(&mp->stats.xid_not_found);
49150 + atomic_inc_unchecked(&mp->stats.xid_not_found);
49151 reject = FC_RJT_RX_ID; /* XID not found */
49152 goto out;
49153 }
49154 @@ -1082,7 +1082,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
49155 } else {
49156 sp = &ep->seq;
49157 if (sp->id != fh->fh_seq_id) {
49158 - atomic_inc(&mp->stats.seq_not_found);
49159 + atomic_inc_unchecked(&mp->stats.seq_not_found);
49160 if (f_ctl & FC_FC_END_SEQ) {
49161 /*
49162 * Update sequence_id based on incoming last
49163 @@ -1533,22 +1533,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
49164
49165 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
49166 if (!ep) {
49167 - atomic_inc(&mp->stats.xid_not_found);
49168 + atomic_inc_unchecked(&mp->stats.xid_not_found);
49169 goto out;
49170 }
49171 if (ep->esb_stat & ESB_ST_COMPLETE) {
49172 - atomic_inc(&mp->stats.xid_not_found);
49173 + atomic_inc_unchecked(&mp->stats.xid_not_found);
49174 goto rel;
49175 }
49176 if (ep->rxid == FC_XID_UNKNOWN)
49177 ep->rxid = ntohs(fh->fh_rx_id);
49178 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
49179 - atomic_inc(&mp->stats.xid_not_found);
49180 + atomic_inc_unchecked(&mp->stats.xid_not_found);
49181 goto rel;
49182 }
49183 if (ep->did != ntoh24(fh->fh_s_id) &&
49184 ep->did != FC_FID_FLOGI) {
49185 - atomic_inc(&mp->stats.xid_not_found);
49186 + atomic_inc_unchecked(&mp->stats.xid_not_found);
49187 goto rel;
49188 }
49189 sof = fr_sof(fp);
49190 @@ -1557,7 +1557,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
49191 sp->ssb_stat |= SSB_ST_RESP;
49192 sp->id = fh->fh_seq_id;
49193 } else if (sp->id != fh->fh_seq_id) {
49194 - atomic_inc(&mp->stats.seq_not_found);
49195 + atomic_inc_unchecked(&mp->stats.seq_not_found);
49196 goto rel;
49197 }
49198
49199 @@ -1619,9 +1619,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
49200 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
49201
49202 if (!sp)
49203 - atomic_inc(&mp->stats.xid_not_found);
49204 + atomic_inc_unchecked(&mp->stats.xid_not_found);
49205 else
49206 - atomic_inc(&mp->stats.non_bls_resp);
49207 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
49208
49209 fc_frame_free(fp);
49210 }
49211 @@ -2261,13 +2261,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
49212
49213 list_for_each_entry(ema, &lport->ema_list, ema_list) {
49214 mp = ema->mp;
49215 - st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
49216 + st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
49217 st->fc_no_free_exch_xid +=
49218 - atomic_read(&mp->stats.no_free_exch_xid);
49219 - st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
49220 - st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
49221 - st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
49222 - st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
49223 + atomic_read_unchecked(&mp->stats.no_free_exch_xid);
49224 + st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
49225 + st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
49226 + st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
49227 + st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
49228 }
49229 }
49230 EXPORT_SYMBOL(fc_exch_update_stats);
49231 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
49232 index 766098a..1c6c971 100644
49233 --- a/drivers/scsi/libsas/sas_ata.c
49234 +++ b/drivers/scsi/libsas/sas_ata.c
49235 @@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
49236 .postreset = ata_std_postreset,
49237 .error_handler = ata_std_error_handler,
49238 .post_internal_cmd = sas_ata_post_internal,
49239 - .qc_defer = ata_std_qc_defer,
49240 + .qc_defer = ata_std_qc_defer,
49241 .qc_prep = ata_noop_qc_prep,
49242 .qc_issue = sas_ata_qc_issue,
49243 .qc_fill_rtf = sas_ata_qc_fill_rtf,
49244 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
49245 index 94a3caf..a118dec 100644
49246 --- a/drivers/scsi/lpfc/lpfc.h
49247 +++ b/drivers/scsi/lpfc/lpfc.h
49248 @@ -430,7 +430,7 @@ struct lpfc_vport {
49249 struct dentry *debug_nodelist;
49250 struct dentry *vport_debugfs_root;
49251 struct lpfc_debugfs_trc *disc_trc;
49252 - atomic_t disc_trc_cnt;
49253 + atomic_unchecked_t disc_trc_cnt;
49254 #endif
49255 uint8_t stat_data_enabled;
49256 uint8_t stat_data_blocked;
49257 @@ -879,8 +879,8 @@ struct lpfc_hba {
49258 struct timer_list fabric_block_timer;
49259 unsigned long bit_flags;
49260 #define FABRIC_COMANDS_BLOCKED 0
49261 - atomic_t num_rsrc_err;
49262 - atomic_t num_cmd_success;
49263 + atomic_unchecked_t num_rsrc_err;
49264 + atomic_unchecked_t num_cmd_success;
49265 unsigned long last_rsrc_error_time;
49266 unsigned long last_ramp_down_time;
49267 #ifdef CONFIG_SCSI_LPFC_DEBUG_FS
49268 @@ -915,7 +915,7 @@ struct lpfc_hba {
49269
49270 struct dentry *debug_slow_ring_trc;
49271 struct lpfc_debugfs_trc *slow_ring_trc;
49272 - atomic_t slow_ring_trc_cnt;
49273 + atomic_unchecked_t slow_ring_trc_cnt;
49274 /* iDiag debugfs sub-directory */
49275 struct dentry *idiag_root;
49276 struct dentry *idiag_pci_cfg;
49277 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
49278 index 828c08e..e3378e0 100644
49279 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
49280 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
49281 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
49282
49283 #include <linux/debugfs.h>
49284
49285 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
49286 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
49287 static unsigned long lpfc_debugfs_start_time = 0L;
49288
49289 /* iDiag */
49290 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
49291 lpfc_debugfs_enable = 0;
49292
49293 len = 0;
49294 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
49295 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
49296 (lpfc_debugfs_max_disc_trc - 1);
49297 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
49298 dtp = vport->disc_trc + i;
49299 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
49300 lpfc_debugfs_enable = 0;
49301
49302 len = 0;
49303 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
49304 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
49305 (lpfc_debugfs_max_slow_ring_trc - 1);
49306 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
49307 dtp = phba->slow_ring_trc + i;
49308 @@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
49309 !vport || !vport->disc_trc)
49310 return;
49311
49312 - index = atomic_inc_return(&vport->disc_trc_cnt) &
49313 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
49314 (lpfc_debugfs_max_disc_trc - 1);
49315 dtp = vport->disc_trc + index;
49316 dtp->fmt = fmt;
49317 dtp->data1 = data1;
49318 dtp->data2 = data2;
49319 dtp->data3 = data3;
49320 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
49321 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
49322 dtp->jif = jiffies;
49323 #endif
49324 return;
49325 @@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
49326 !phba || !phba->slow_ring_trc)
49327 return;
49328
49329 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
49330 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
49331 (lpfc_debugfs_max_slow_ring_trc - 1);
49332 dtp = phba->slow_ring_trc + index;
49333 dtp->fmt = fmt;
49334 dtp->data1 = data1;
49335 dtp->data2 = data2;
49336 dtp->data3 = data3;
49337 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
49338 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
49339 dtp->jif = jiffies;
49340 #endif
49341 return;
49342 @@ -4268,7 +4268,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
49343 "slow_ring buffer\n");
49344 goto debug_failed;
49345 }
49346 - atomic_set(&phba->slow_ring_trc_cnt, 0);
49347 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
49348 memset(phba->slow_ring_trc, 0,
49349 (sizeof(struct lpfc_debugfs_trc) *
49350 lpfc_debugfs_max_slow_ring_trc));
49351 @@ -4314,7 +4314,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
49352 "buffer\n");
49353 goto debug_failed;
49354 }
49355 - atomic_set(&vport->disc_trc_cnt, 0);
49356 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
49357
49358 snprintf(name, sizeof(name), "discovery_trace");
49359 vport->debug_disc_trc =
49360 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
49361 index 635eeb3..038aef6 100644
49362 --- a/drivers/scsi/lpfc/lpfc_init.c
49363 +++ b/drivers/scsi/lpfc/lpfc_init.c
49364 @@ -11194,8 +11194,10 @@ lpfc_init(void)
49365 "misc_register returned with status %d", error);
49366
49367 if (lpfc_enable_npiv) {
49368 - lpfc_transport_functions.vport_create = lpfc_vport_create;
49369 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
49370 + pax_open_kernel();
49371 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
49372 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
49373 + pax_close_kernel();
49374 }
49375 lpfc_transport_template =
49376 fc_attach_transport(&lpfc_transport_functions);
49377 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
49378 index 462453e..c0023a6 100644
49379 --- a/drivers/scsi/lpfc/lpfc_scsi.c
49380 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
49381 @@ -382,7 +382,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
49382 uint32_t evt_posted;
49383
49384 spin_lock_irqsave(&phba->hbalock, flags);
49385 - atomic_inc(&phba->num_rsrc_err);
49386 + atomic_inc_unchecked(&phba->num_rsrc_err);
49387 phba->last_rsrc_error_time = jiffies;
49388
49389 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
49390 @@ -423,8 +423,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
49391 unsigned long num_rsrc_err, num_cmd_success;
49392 int i;
49393
49394 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
49395 - num_cmd_success = atomic_read(&phba->num_cmd_success);
49396 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
49397 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
49398
49399 /*
49400 * The error and success command counters are global per
49401 @@ -452,8 +452,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
49402 }
49403 }
49404 lpfc_destroy_vport_work_array(phba, vports);
49405 - atomic_set(&phba->num_rsrc_err, 0);
49406 - atomic_set(&phba->num_cmd_success, 0);
49407 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
49408 + atomic_set_unchecked(&phba->num_cmd_success, 0);
49409 }
49410
49411 /**
49412 diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49413 index 6fd7d40..b444223 100644
49414 --- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49415 +++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
49416 @@ -1557,7 +1557,7 @@ _scsih_get_resync(struct device *dev)
49417 {
49418 struct scsi_device *sdev = to_scsi_device(dev);
49419 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
49420 - static struct _raid_device *raid_device;
49421 + struct _raid_device *raid_device;
49422 unsigned long flags;
49423 Mpi2RaidVolPage0_t vol_pg0;
49424 Mpi2ConfigReply_t mpi_reply;
49425 @@ -1609,7 +1609,7 @@ _scsih_get_state(struct device *dev)
49426 {
49427 struct scsi_device *sdev = to_scsi_device(dev);
49428 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
49429 - static struct _raid_device *raid_device;
49430 + struct _raid_device *raid_device;
49431 unsigned long flags;
49432 Mpi2RaidVolPage0_t vol_pg0;
49433 Mpi2ConfigReply_t mpi_reply;
49434 @@ -6637,7 +6637,7 @@ _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
49435 struct fw_event_work *fw_event)
49436 {
49437 Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data;
49438 - static struct _raid_device *raid_device;
49439 + struct _raid_device *raid_device;
49440 unsigned long flags;
49441 u16 handle;
49442
49443 @@ -7108,7 +7108,7 @@ _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
49444 u64 sas_address;
49445 struct _sas_device *sas_device;
49446 struct _sas_node *expander_device;
49447 - static struct _raid_device *raid_device;
49448 + struct _raid_device *raid_device;
49449 u8 retry_count;
49450 unsigned long flags;
49451
49452 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
49453 index be8ce54..94ed33a 100644
49454 --- a/drivers/scsi/pmcraid.c
49455 +++ b/drivers/scsi/pmcraid.c
49456 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
49457 res->scsi_dev = scsi_dev;
49458 scsi_dev->hostdata = res;
49459 res->change_detected = 0;
49460 - atomic_set(&res->read_failures, 0);
49461 - atomic_set(&res->write_failures, 0);
49462 + atomic_set_unchecked(&res->read_failures, 0);
49463 + atomic_set_unchecked(&res->write_failures, 0);
49464 rc = 0;
49465 }
49466 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
49467 @@ -2687,9 +2687,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
49468
49469 /* If this was a SCSI read/write command keep count of errors */
49470 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
49471 - atomic_inc(&res->read_failures);
49472 + atomic_inc_unchecked(&res->read_failures);
49473 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
49474 - atomic_inc(&res->write_failures);
49475 + atomic_inc_unchecked(&res->write_failures);
49476
49477 if (!RES_IS_GSCSI(res->cfg_entry) &&
49478 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
49479 @@ -3545,7 +3545,7 @@ static int pmcraid_queuecommand_lck(
49480 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
49481 * hrrq_id assigned here in queuecommand
49482 */
49483 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
49484 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
49485 pinstance->num_hrrq;
49486 cmd->cmd_done = pmcraid_io_done;
49487
49488 @@ -3857,7 +3857,7 @@ static long pmcraid_ioctl_passthrough(
49489 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
49490 * hrrq_id assigned here in queuecommand
49491 */
49492 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
49493 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
49494 pinstance->num_hrrq;
49495
49496 if (request_size) {
49497 @@ -4495,7 +4495,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
49498
49499 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
49500 /* add resources only after host is added into system */
49501 - if (!atomic_read(&pinstance->expose_resources))
49502 + if (!atomic_read_unchecked(&pinstance->expose_resources))
49503 return;
49504
49505 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
49506 @@ -5322,8 +5322,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
49507 init_waitqueue_head(&pinstance->reset_wait_q);
49508
49509 atomic_set(&pinstance->outstanding_cmds, 0);
49510 - atomic_set(&pinstance->last_message_id, 0);
49511 - atomic_set(&pinstance->expose_resources, 0);
49512 + atomic_set_unchecked(&pinstance->last_message_id, 0);
49513 + atomic_set_unchecked(&pinstance->expose_resources, 0);
49514
49515 INIT_LIST_HEAD(&pinstance->free_res_q);
49516 INIT_LIST_HEAD(&pinstance->used_res_q);
49517 @@ -6036,7 +6036,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
49518 /* Schedule worker thread to handle CCN and take care of adding and
49519 * removing devices to OS
49520 */
49521 - atomic_set(&pinstance->expose_resources, 1);
49522 + atomic_set_unchecked(&pinstance->expose_resources, 1);
49523 schedule_work(&pinstance->worker_q);
49524 return rc;
49525
49526 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
49527 index e1d150f..6c6df44 100644
49528 --- a/drivers/scsi/pmcraid.h
49529 +++ b/drivers/scsi/pmcraid.h
49530 @@ -748,7 +748,7 @@ struct pmcraid_instance {
49531 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
49532
49533 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
49534 - atomic_t last_message_id;
49535 + atomic_unchecked_t last_message_id;
49536
49537 /* configuration table */
49538 struct pmcraid_config_table *cfg_table;
49539 @@ -777,7 +777,7 @@ struct pmcraid_instance {
49540 atomic_t outstanding_cmds;
49541
49542 /* should add/delete resources to mid-layer now ?*/
49543 - atomic_t expose_resources;
49544 + atomic_unchecked_t expose_resources;
49545
49546
49547
49548 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
49549 struct pmcraid_config_table_entry_ext cfg_entry_ext;
49550 };
49551 struct scsi_device *scsi_dev; /* Link scsi_device structure */
49552 - atomic_t read_failures; /* count of failed READ commands */
49553 - atomic_t write_failures; /* count of failed WRITE commands */
49554 + atomic_unchecked_t read_failures; /* count of failed READ commands */
49555 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
49556
49557 /* To indicate add/delete/modify during CCN */
49558 u8 change_detected;
49559 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
49560 index 07befcf..c0bff13 100644
49561 --- a/drivers/scsi/qla2xxx/qla_attr.c
49562 +++ b/drivers/scsi/qla2xxx/qla_attr.c
49563 @@ -2188,7 +2188,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
49564 return 0;
49565 }
49566
49567 -struct fc_function_template qla2xxx_transport_functions = {
49568 +fc_function_template_no_const qla2xxx_transport_functions = {
49569
49570 .show_host_node_name = 1,
49571 .show_host_port_name = 1,
49572 @@ -2236,7 +2236,7 @@ struct fc_function_template qla2xxx_transport_functions = {
49573 .bsg_timeout = qla24xx_bsg_timeout,
49574 };
49575
49576 -struct fc_function_template qla2xxx_transport_vport_functions = {
49577 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
49578
49579 .show_host_node_name = 1,
49580 .show_host_port_name = 1,
49581 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
49582 index e665e81..16e84e6 100644
49583 --- a/drivers/scsi/qla2xxx/qla_gbl.h
49584 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
49585 @@ -557,8 +557,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
49586 struct device_attribute;
49587 extern struct device_attribute *qla2x00_host_attrs[];
49588 struct fc_function_template;
49589 -extern struct fc_function_template qla2xxx_transport_functions;
49590 -extern struct fc_function_template qla2xxx_transport_vport_functions;
49591 +extern fc_function_template_no_const qla2xxx_transport_functions;
49592 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
49593 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
49594 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *, bool);
49595 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
49596 diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
49597 index 19e99cc..b3c0b7b 100644
49598 --- a/drivers/scsi/qla2xxx/qla_os.c
49599 +++ b/drivers/scsi/qla2xxx/qla_os.c
49600 @@ -1493,8 +1493,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
49601 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
49602 /* Ok, a 64bit DMA mask is applicable. */
49603 ha->flags.enable_64bit_addressing = 1;
49604 - ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
49605 - ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
49606 + pax_open_kernel();
49607 + *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
49608 + *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
49609 + pax_close_kernel();
49610 return;
49611 }
49612 }
49613 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
49614 index 73a5022..4e0797c 100644
49615 --- a/drivers/scsi/qla4xxx/ql4_def.h
49616 +++ b/drivers/scsi/qla4xxx/ql4_def.h
49617 @@ -305,7 +305,7 @@ struct ddb_entry {
49618 * (4000 only) */
49619 atomic_t relogin_timer; /* Max Time to wait for
49620 * relogin to complete */
49621 - atomic_t relogin_retry_count; /* Num of times relogin has been
49622 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
49623 * retried */
49624 uint32_t default_time2wait; /* Default Min time between
49625 * relogins (+aens) */
49626 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
49627 index 459b9f7..2930a68 100644
49628 --- a/drivers/scsi/qla4xxx/ql4_os.c
49629 +++ b/drivers/scsi/qla4xxx/ql4_os.c
49630 @@ -4499,12 +4499,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
49631 */
49632 if (!iscsi_is_session_online(cls_sess)) {
49633 /* Reset retry relogin timer */
49634 - atomic_inc(&ddb_entry->relogin_retry_count);
49635 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
49636 DEBUG2(ql4_printk(KERN_INFO, ha,
49637 "%s: index[%d] relogin timed out-retrying"
49638 " relogin (%d), retry (%d)\n", __func__,
49639 ddb_entry->fw_ddb_index,
49640 - atomic_read(&ddb_entry->relogin_retry_count),
49641 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
49642 ddb_entry->default_time2wait + 4));
49643 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
49644 atomic_set(&ddb_entry->retry_relogin_timer,
49645 @@ -6609,7 +6609,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
49646
49647 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
49648 atomic_set(&ddb_entry->relogin_timer, 0);
49649 - atomic_set(&ddb_entry->relogin_retry_count, 0);
49650 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
49651 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
49652 ddb_entry->default_relogin_timeout =
49653 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
49654 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
49655 index 88d46fe..7351be5 100644
49656 --- a/drivers/scsi/scsi.c
49657 +++ b/drivers/scsi/scsi.c
49658 @@ -640,7 +640,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
49659 struct Scsi_Host *host = cmd->device->host;
49660 int rtn = 0;
49661
49662 - atomic_inc(&cmd->device->iorequest_cnt);
49663 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
49664
49665 /* check if the device is still usable */
49666 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
49667 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
49668 index 9db097a..ca5c291 100644
49669 --- a/drivers/scsi/scsi_lib.c
49670 +++ b/drivers/scsi/scsi_lib.c
49671 @@ -1464,7 +1464,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
49672 shost = sdev->host;
49673 scsi_init_cmd_errh(cmd);
49674 cmd->result = DID_NO_CONNECT << 16;
49675 - atomic_inc(&cmd->device->iorequest_cnt);
49676 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
49677
49678 /*
49679 * SCSI request completion path will do scsi_device_unbusy(),
49680 @@ -1490,9 +1490,9 @@ static void scsi_softirq_done(struct request *rq)
49681
49682 INIT_LIST_HEAD(&cmd->eh_entry);
49683
49684 - atomic_inc(&cmd->device->iodone_cnt);
49685 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
49686 if (cmd->result)
49687 - atomic_inc(&cmd->device->ioerr_cnt);
49688 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
49689
49690 disposition = scsi_decide_disposition(cmd);
49691 if (disposition != SUCCESS &&
49692 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
49693 index 074e8cc..f612e5c 100644
49694 --- a/drivers/scsi/scsi_sysfs.c
49695 +++ b/drivers/scsi/scsi_sysfs.c
49696 @@ -780,7 +780,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
49697 char *buf) \
49698 { \
49699 struct scsi_device *sdev = to_scsi_device(dev); \
49700 - unsigned long long count = atomic_read(&sdev->field); \
49701 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
49702 return snprintf(buf, 20, "0x%llx\n", count); \
49703 } \
49704 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
49705 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
49706 index e51add0..1e06a96 100644
49707 --- a/drivers/scsi/scsi_tgt_lib.c
49708 +++ b/drivers/scsi/scsi_tgt_lib.c
49709 @@ -363,7 +363,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
49710 int err;
49711
49712 dprintk("%lx %u\n", uaddr, len);
49713 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
49714 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
49715 if (err) {
49716 /*
49717 * TODO: need to fixup sg_tablesize, max_segment_size,
49718 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
49719 index f80908f..22aba76 100644
49720 --- a/drivers/scsi/scsi_transport_fc.c
49721 +++ b/drivers/scsi/scsi_transport_fc.c
49722 @@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
49723 * Netlink Infrastructure
49724 */
49725
49726 -static atomic_t fc_event_seq;
49727 +static atomic_unchecked_t fc_event_seq;
49728
49729 /**
49730 * fc_get_event_number - Obtain the next sequential FC event number
49731 @@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
49732 u32
49733 fc_get_event_number(void)
49734 {
49735 - return atomic_add_return(1, &fc_event_seq);
49736 + return atomic_add_return_unchecked(1, &fc_event_seq);
49737 }
49738 EXPORT_SYMBOL(fc_get_event_number);
49739
49740 @@ -655,7 +655,7 @@ static __init int fc_transport_init(void)
49741 {
49742 int error;
49743
49744 - atomic_set(&fc_event_seq, 0);
49745 + atomic_set_unchecked(&fc_event_seq, 0);
49746
49747 error = transport_class_register(&fc_host_class);
49748 if (error)
49749 @@ -845,7 +845,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
49750 char *cp;
49751
49752 *val = simple_strtoul(buf, &cp, 0);
49753 - if ((*cp && (*cp != '\n')) || (*val < 0))
49754 + if (*cp && (*cp != '\n'))
49755 return -EINVAL;
49756 /*
49757 * Check for overflow; dev_loss_tmo is u32
49758 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
49759 index 0102a2d..cc3f8e9 100644
49760 --- a/drivers/scsi/scsi_transport_iscsi.c
49761 +++ b/drivers/scsi/scsi_transport_iscsi.c
49762 @@ -79,7 +79,7 @@ struct iscsi_internal {
49763 struct transport_container session_cont;
49764 };
49765
49766 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
49767 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
49768 static struct workqueue_struct *iscsi_eh_timer_workq;
49769
49770 static DEFINE_IDA(iscsi_sess_ida);
49771 @@ -2071,7 +2071,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
49772 int err;
49773
49774 ihost = shost->shost_data;
49775 - session->sid = atomic_add_return(1, &iscsi_session_nr);
49776 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
49777
49778 if (target_id == ISCSI_MAX_TARGET) {
49779 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
49780 @@ -4511,7 +4511,7 @@ static __init int iscsi_transport_init(void)
49781 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
49782 ISCSI_TRANSPORT_VERSION);
49783
49784 - atomic_set(&iscsi_session_nr, 0);
49785 + atomic_set_unchecked(&iscsi_session_nr, 0);
49786
49787 err = class_register(&iscsi_transport_class);
49788 if (err)
49789 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
49790 index 13e8983..d306a68 100644
49791 --- a/drivers/scsi/scsi_transport_srp.c
49792 +++ b/drivers/scsi/scsi_transport_srp.c
49793 @@ -36,7 +36,7 @@
49794 #include "scsi_transport_srp_internal.h"
49795
49796 struct srp_host_attrs {
49797 - atomic_t next_port_id;
49798 + atomic_unchecked_t next_port_id;
49799 };
49800 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
49801
49802 @@ -101,7 +101,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
49803 struct Scsi_Host *shost = dev_to_shost(dev);
49804 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
49805
49806 - atomic_set(&srp_host->next_port_id, 0);
49807 + atomic_set_unchecked(&srp_host->next_port_id, 0);
49808 return 0;
49809 }
49810
49811 @@ -734,7 +734,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
49812 rport_fast_io_fail_timedout);
49813 INIT_DELAYED_WORK(&rport->dev_loss_work, rport_dev_loss_timedout);
49814
49815 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
49816 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
49817 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
49818
49819 transport_setup_device(&rport->dev);
49820 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
49821 index bffbd4b..cb1b68a 100644
49822 --- a/drivers/scsi/sd.c
49823 +++ b/drivers/scsi/sd.c
49824 @@ -2971,7 +2971,7 @@ static int sd_probe(struct device *dev)
49825 sdkp->disk = gd;
49826 sdkp->index = index;
49827 atomic_set(&sdkp->openers, 0);
49828 - atomic_set(&sdkp->device->ioerr_cnt, 0);
49829 + atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
49830
49831 if (!sdp->request_queue->rq_timeout) {
49832 if (sdp->type != TYPE_MOD)
49833 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
49834 index df5e961..df6b97f 100644
49835 --- a/drivers/scsi/sg.c
49836 +++ b/drivers/scsi/sg.c
49837 @@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
49838 sdp->disk->disk_name,
49839 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
49840 NULL,
49841 - (char *)arg);
49842 + (char __user *)arg);
49843 case BLKTRACESTART:
49844 return blk_trace_startstop(sdp->device->request_queue, 1);
49845 case BLKTRACESTOP:
49846 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
49847 index 939edf4..3f50423 100644
49848 --- a/drivers/spi/spi.c
49849 +++ b/drivers/spi/spi.c
49850 @@ -2204,7 +2204,7 @@ int spi_bus_unlock(struct spi_master *master)
49851 EXPORT_SYMBOL_GPL(spi_bus_unlock);
49852
49853 /* portable code must never pass more than 32 bytes */
49854 -#define SPI_BUFSIZ max(32, SMP_CACHE_BYTES)
49855 +#define SPI_BUFSIZ max(32UL, SMP_CACHE_BYTES)
49856
49857 static u8 *buf;
49858
49859 diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
49860 index 2c61783..4d49e4e 100644
49861 --- a/drivers/staging/android/timed_output.c
49862 +++ b/drivers/staging/android/timed_output.c
49863 @@ -25,7 +25,7 @@
49864 #include "timed_output.h"
49865
49866 static struct class *timed_output_class;
49867 -static atomic_t device_count;
49868 +static atomic_unchecked_t device_count;
49869
49870 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
49871 char *buf)
49872 @@ -63,7 +63,7 @@ static int create_timed_output_class(void)
49873 timed_output_class = class_create(THIS_MODULE, "timed_output");
49874 if (IS_ERR(timed_output_class))
49875 return PTR_ERR(timed_output_class);
49876 - atomic_set(&device_count, 0);
49877 + atomic_set_unchecked(&device_count, 0);
49878 timed_output_class->dev_groups = timed_output_groups;
49879 }
49880
49881 @@ -81,7 +81,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
49882 if (ret < 0)
49883 return ret;
49884
49885 - tdev->index = atomic_inc_return(&device_count);
49886 + tdev->index = atomic_inc_return_unchecked(&device_count);
49887 tdev->dev = device_create(timed_output_class, NULL,
49888 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
49889 if (IS_ERR(tdev->dev))
49890 diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
49891 index fe47cd3..19a1bd1 100644
49892 --- a/drivers/staging/gdm724x/gdm_tty.c
49893 +++ b/drivers/staging/gdm724x/gdm_tty.c
49894 @@ -44,7 +44,7 @@
49895 #define gdm_tty_send_control(n, r, v, d, l) (\
49896 n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
49897
49898 -#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
49899 +#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && atomic_read(&gdm->port.count))
49900
49901 static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
49902 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
49903 diff --git a/drivers/staging/imx-drm/imx-drm-core.c b/drivers/staging/imx-drm/imx-drm-core.c
49904 index c270c9a..94ddf82 100644
49905 --- a/drivers/staging/imx-drm/imx-drm-core.c
49906 +++ b/drivers/staging/imx-drm/imx-drm-core.c
49907 @@ -362,7 +362,7 @@ int imx_drm_add_crtc(struct drm_device *drm, struct drm_crtc *crtc,
49908 if (imxdrm->pipes >= MAX_CRTC)
49909 return -EINVAL;
49910
49911 - if (imxdrm->drm->open_count)
49912 + if (local_read(&imxdrm->drm->open_count))
49913 return -EBUSY;
49914
49915 imx_drm_crtc = kzalloc(sizeof(*imx_drm_crtc), GFP_KERNEL);
49916 diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
49917 index 3f8020c..649fded 100644
49918 --- a/drivers/staging/lustre/lnet/selftest/brw_test.c
49919 +++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
49920 @@ -488,13 +488,11 @@ brw_server_handle(struct srpc_server_rpc *rpc)
49921 return 0;
49922 }
49923
49924 -sfw_test_client_ops_t brw_test_client;
49925 -void brw_init_test_client(void)
49926 -{
49927 - brw_test_client.tso_init = brw_client_init;
49928 - brw_test_client.tso_fini = brw_client_fini;
49929 - brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
49930 - brw_test_client.tso_done_rpc = brw_client_done_rpc;
49931 +sfw_test_client_ops_t brw_test_client = {
49932 + .tso_init = brw_client_init,
49933 + .tso_fini = brw_client_fini,
49934 + .tso_prep_rpc = brw_client_prep_rpc,
49935 + .tso_done_rpc = brw_client_done_rpc,
49936 };
49937
49938 srpc_service_t brw_test_service;
49939 diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
49940 index 050723a..fa6fdf1 100644
49941 --- a/drivers/staging/lustre/lnet/selftest/framework.c
49942 +++ b/drivers/staging/lustre/lnet/selftest/framework.c
49943 @@ -1635,12 +1635,10 @@ static srpc_service_t sfw_services[] =
49944
49945 extern sfw_test_client_ops_t ping_test_client;
49946 extern srpc_service_t ping_test_service;
49947 -extern void ping_init_test_client(void);
49948 extern void ping_init_test_service(void);
49949
49950 extern sfw_test_client_ops_t brw_test_client;
49951 extern srpc_service_t brw_test_service;
49952 -extern void brw_init_test_client(void);
49953 extern void brw_init_test_service(void);
49954
49955
49956 @@ -1684,12 +1682,10 @@ sfw_startup (void)
49957 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
49958 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
49959
49960 - brw_init_test_client();
49961 brw_init_test_service();
49962 rc = sfw_register_test(&brw_test_service, &brw_test_client);
49963 LASSERT (rc == 0);
49964
49965 - ping_init_test_client();
49966 ping_init_test_service();
49967 rc = sfw_register_test(&ping_test_service, &ping_test_client);
49968 LASSERT (rc == 0);
49969 diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
49970 index 750cac4..e4d751f 100644
49971 --- a/drivers/staging/lustre/lnet/selftest/ping_test.c
49972 +++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
49973 @@ -211,14 +211,12 @@ ping_server_handle(struct srpc_server_rpc *rpc)
49974 return 0;
49975 }
49976
49977 -sfw_test_client_ops_t ping_test_client;
49978 -void ping_init_test_client(void)
49979 -{
49980 - ping_test_client.tso_init = ping_client_init;
49981 - ping_test_client.tso_fini = ping_client_fini;
49982 - ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
49983 - ping_test_client.tso_done_rpc = ping_client_done_rpc;
49984 -}
49985 +sfw_test_client_ops_t ping_test_client = {
49986 + .tso_init = ping_client_init,
49987 + .tso_fini = ping_client_fini,
49988 + .tso_prep_rpc = ping_client_prep_rpc,
49989 + .tso_done_rpc = ping_client_done_rpc,
49990 +};
49991
49992 srpc_service_t ping_test_service;
49993 void ping_init_test_service(void)
49994 diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
49995 index 3e25f00..0d59cf5 100644
49996 --- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
49997 +++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
49998 @@ -1141,7 +1141,7 @@ struct ldlm_callback_suite {
49999 ldlm_completion_callback lcs_completion;
50000 ldlm_blocking_callback lcs_blocking;
50001 ldlm_glimpse_callback lcs_glimpse;
50002 -};
50003 +} __no_const;
50004
50005 /* ldlm_lockd.c */
50006 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
50007 diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
50008 index 72cf3fe..4beac19 100644
50009 --- a/drivers/staging/lustre/lustre/include/obd.h
50010 +++ b/drivers/staging/lustre/lustre/include/obd.h
50011 @@ -1427,7 +1427,7 @@ struct md_ops {
50012 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
50013 * wrapper function in include/linux/obd_class.h.
50014 */
50015 -};
50016 +} __no_const;
50017
50018 struct lsm_operations {
50019 void (*lsm_free)(struct lov_stripe_md *);
50020 diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
50021 index 986bf38..eab2558f 100644
50022 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
50023 +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
50024 @@ -259,7 +259,7 @@ ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
50025 int added = (mode == LCK_NL);
50026 int overlaps = 0;
50027 int splitted = 0;
50028 - const struct ldlm_callback_suite null_cbs = { NULL };
50029 + const struct ldlm_callback_suite null_cbs = { };
50030
50031 CDEBUG(D_DLMTRACE, "flags %#llx owner "LPU64" pid %u mode %u start "
50032 LPU64" end "LPU64"\n", *flags,
50033 diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
50034 index e947b91..f408990 100644
50035 --- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
50036 +++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
50037 @@ -217,7 +217,7 @@ DECLARE_PROC_HANDLER(proc_debug_mb)
50038 int LL_PROC_PROTO(proc_console_max_delay_cs)
50039 {
50040 int rc, max_delay_cs;
50041 - ctl_table_t dummy = *table;
50042 + ctl_table_no_const dummy = *table;
50043 cfs_duration_t d;
50044
50045 dummy.data = &max_delay_cs;
50046 @@ -248,7 +248,7 @@ int LL_PROC_PROTO(proc_console_max_delay_cs)
50047 int LL_PROC_PROTO(proc_console_min_delay_cs)
50048 {
50049 int rc, min_delay_cs;
50050 - ctl_table_t dummy = *table;
50051 + ctl_table_no_const dummy = *table;
50052 cfs_duration_t d;
50053
50054 dummy.data = &min_delay_cs;
50055 @@ -279,7 +279,7 @@ int LL_PROC_PROTO(proc_console_min_delay_cs)
50056 int LL_PROC_PROTO(proc_console_backoff)
50057 {
50058 int rc, backoff;
50059 - ctl_table_t dummy = *table;
50060 + ctl_table_no_const dummy = *table;
50061
50062 dummy.data = &backoff;
50063 dummy.proc_handler = &proc_dointvec;
50064 diff --git a/drivers/staging/lustre/lustre/libcfs/module.c b/drivers/staging/lustre/lustre/libcfs/module.c
50065 index 24ae26d..9d09cab 100644
50066 --- a/drivers/staging/lustre/lustre/libcfs/module.c
50067 +++ b/drivers/staging/lustre/lustre/libcfs/module.c
50068 @@ -313,11 +313,11 @@ out:
50069
50070
50071 struct cfs_psdev_ops libcfs_psdev_ops = {
50072 - libcfs_psdev_open,
50073 - libcfs_psdev_release,
50074 - NULL,
50075 - NULL,
50076 - libcfs_ioctl
50077 + .p_open = libcfs_psdev_open,
50078 + .p_close = libcfs_psdev_release,
50079 + .p_read = NULL,
50080 + .p_write = NULL,
50081 + .p_ioctl = libcfs_ioctl
50082 };
50083
50084 extern int insert_proc(void);
50085 diff --git a/drivers/staging/lustre/lustre/llite/dir.c b/drivers/staging/lustre/lustre/llite/dir.c
50086 index 7fbc18e..f982071 100644
50087 --- a/drivers/staging/lustre/lustre/llite/dir.c
50088 +++ b/drivers/staging/lustre/lustre/llite/dir.c
50089 @@ -660,7 +660,7 @@ int ll_dir_setdirstripe(struct inode *dir, struct lmv_user_md *lump,
50090 int mode;
50091 int err;
50092
50093 - mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current->fs->umask) | S_IFDIR;
50094 + mode = (0755 & (S_IRWXUGO|S_ISVTX) & ~current_umask()) | S_IFDIR;
50095 op_data = ll_prep_md_op_data(NULL, dir, NULL, filename,
50096 strlen(filename), mode, LUSTRE_OPC_MKDIR,
50097 lump);
50098 diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
50099 index f670469..03b7438 100644
50100 --- a/drivers/staging/media/solo6x10/solo6x10-core.c
50101 +++ b/drivers/staging/media/solo6x10/solo6x10-core.c
50102 @@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
50103
50104 static int solo_sysfs_init(struct solo_dev *solo_dev)
50105 {
50106 - struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
50107 + bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
50108 struct device *dev = &solo_dev->dev;
50109 const char *driver;
50110 int i;
50111 diff --git a/drivers/staging/media/solo6x10/solo6x10-g723.c b/drivers/staging/media/solo6x10/solo6x10-g723.c
50112 index 74f037b..5b5bb76 100644
50113 --- a/drivers/staging/media/solo6x10/solo6x10-g723.c
50114 +++ b/drivers/staging/media/solo6x10/solo6x10-g723.c
50115 @@ -355,7 +355,7 @@ static int solo_snd_pcm_init(struct solo_dev *solo_dev)
50116
50117 int solo_g723_init(struct solo_dev *solo_dev)
50118 {
50119 - static struct snd_device_ops ops = { NULL };
50120 + static struct snd_device_ops ops = { };
50121 struct snd_card *card;
50122 struct snd_kcontrol_new kctl;
50123 char name[32];
50124 diff --git a/drivers/staging/media/solo6x10/solo6x10-p2m.c b/drivers/staging/media/solo6x10/solo6x10-p2m.c
50125 index 7f2f247..d999137 100644
50126 --- a/drivers/staging/media/solo6x10/solo6x10-p2m.c
50127 +++ b/drivers/staging/media/solo6x10/solo6x10-p2m.c
50128 @@ -77,7 +77,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
50129
50130 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
50131 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
50132 - p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
50133 + p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
50134 if (p2m_id < 0)
50135 p2m_id = -p2m_id;
50136 }
50137 diff --git a/drivers/staging/media/solo6x10/solo6x10.h b/drivers/staging/media/solo6x10/solo6x10.h
50138 index 8964f8b..36eb087 100644
50139 --- a/drivers/staging/media/solo6x10/solo6x10.h
50140 +++ b/drivers/staging/media/solo6x10/solo6x10.h
50141 @@ -237,7 +237,7 @@ struct solo_dev {
50142
50143 /* P2M DMA Engine */
50144 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
50145 - atomic_t p2m_count;
50146 + atomic_unchecked_t p2m_count;
50147 int p2m_jiffies;
50148 unsigned int p2m_timeouts;
50149
50150 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
50151 index a0f4868..139f1fb 100644
50152 --- a/drivers/staging/octeon/ethernet-rx.c
50153 +++ b/drivers/staging/octeon/ethernet-rx.c
50154 @@ -417,11 +417,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
50155 /* Increment RX stats for virtual ports */
50156 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
50157 #ifdef CONFIG_64BIT
50158 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
50159 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
50160 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
50161 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
50162 #else
50163 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
50164 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
50165 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
50166 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
50167 #endif
50168 }
50169 netif_receive_skb(skb);
50170 @@ -432,9 +432,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
50171 dev->name);
50172 */
50173 #ifdef CONFIG_64BIT
50174 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
50175 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
50176 #else
50177 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
50178 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
50179 #endif
50180 dev_kfree_skb_irq(skb);
50181 }
50182 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
50183 index ff7214a..6dd90f0 100644
50184 --- a/drivers/staging/octeon/ethernet.c
50185 +++ b/drivers/staging/octeon/ethernet.c
50186 @@ -247,11 +247,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
50187 * since the RX tasklet also increments it.
50188 */
50189 #ifdef CONFIG_64BIT
50190 - atomic64_add(rx_status.dropped_packets,
50191 - (atomic64_t *)&priv->stats.rx_dropped);
50192 + atomic64_add_unchecked(rx_status.dropped_packets,
50193 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
50194 #else
50195 - atomic_add(rx_status.dropped_packets,
50196 - (atomic_t *)&priv->stats.rx_dropped);
50197 + atomic_add_unchecked(rx_status.dropped_packets,
50198 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
50199 #endif
50200 }
50201
50202 diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
50203 index c274b34..f84de76 100644
50204 --- a/drivers/staging/rtl8188eu/include/hal_intf.h
50205 +++ b/drivers/staging/rtl8188eu/include/hal_intf.h
50206 @@ -271,7 +271,7 @@ struct hal_ops {
50207 s32 (*c2h_handler)(struct adapter *padapter,
50208 struct c2h_evt_hdr *c2h_evt);
50209 c2h_id_filter c2h_id_filter_ccx;
50210 -};
50211 +} __no_const;
50212
50213 enum rt_eeprom_type {
50214 EEPROM_93C46,
50215 diff --git a/drivers/staging/rtl8188eu/include/rtw_io.h b/drivers/staging/rtl8188eu/include/rtw_io.h
50216 index e8790f8..b4a5980 100644
50217 --- a/drivers/staging/rtl8188eu/include/rtw_io.h
50218 +++ b/drivers/staging/rtl8188eu/include/rtw_io.h
50219 @@ -124,7 +124,7 @@ struct _io_ops {
50220 u32 (*_write_scsi)(struct intf_hdl *pintfhdl, u32 cnt, u8 *pmem);
50221 void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
50222 void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
50223 -};
50224 +} __no_const;
50225
50226 struct io_req {
50227 struct list_head list;
50228 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
50229 index dc23395..cf7e9b1 100644
50230 --- a/drivers/staging/rtl8712/rtl871x_io.h
50231 +++ b/drivers/staging/rtl8712/rtl871x_io.h
50232 @@ -108,7 +108,7 @@ struct _io_ops {
50233 u8 *pmem);
50234 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
50235 u8 *pmem);
50236 -};
50237 +} __no_const;
50238
50239 struct io_req {
50240 struct list_head list;
50241 diff --git a/drivers/staging/rtl8723au/include/hal_intf.h b/drivers/staging/rtl8723au/include/hal_intf.h
50242 index d183f4b..3f4903d 100644
50243 --- a/drivers/staging/rtl8723au/include/hal_intf.h
50244 +++ b/drivers/staging/rtl8723au/include/hal_intf.h
50245 @@ -251,7 +251,7 @@ struct hal_ops {
50246 void (*hal_reset_security_engine)(struct rtw_adapter *adapter);
50247 s32 (*c2h_handler)(struct rtw_adapter *padapter, struct c2h_evt_hdr *c2h_evt);
50248 c2h_id_filter c2h_id_filter_ccx;
50249 -};
50250 +} __no_const;
50251
50252 enum rt_eeprom_type {
50253 EEPROM_93C46,
50254 diff --git a/drivers/staging/rtl8723au/include/rtw_io.h b/drivers/staging/rtl8723au/include/rtw_io.h
50255 index 8d39d800..3f21c0c 100644
50256 --- a/drivers/staging/rtl8723au/include/rtw_io.h
50257 +++ b/drivers/staging/rtl8723au/include/rtw_io.h
50258 @@ -130,7 +130,7 @@ struct _io_ops
50259 void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
50260 void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
50261
50262 -};
50263 +} __no_const;
50264
50265 struct io_req {
50266 struct list_head list;
50267 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
50268 index fe6c951..72935ba 100644
50269 --- a/drivers/staging/sbe-2t3e3/netdev.c
50270 +++ b/drivers/staging/sbe-2t3e3/netdev.c
50271 @@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
50272 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
50273
50274 if (rlen)
50275 - if (copy_to_user(data, &resp, rlen))
50276 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
50277 return -EFAULT;
50278
50279 return 0;
50280 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
50281 index a863a98..d272795 100644
50282 --- a/drivers/staging/usbip/vhci.h
50283 +++ b/drivers/staging/usbip/vhci.h
50284 @@ -83,7 +83,7 @@ struct vhci_hcd {
50285 unsigned resuming:1;
50286 unsigned long re_timeout;
50287
50288 - atomic_t seqnum;
50289 + atomic_unchecked_t seqnum;
50290
50291 /*
50292 * NOTE:
50293 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
50294 index 70e1755..de41855 100644
50295 --- a/drivers/staging/usbip/vhci_hcd.c
50296 +++ b/drivers/staging/usbip/vhci_hcd.c
50297 @@ -439,7 +439,7 @@ static void vhci_tx_urb(struct urb *urb)
50298
50299 spin_lock(&vdev->priv_lock);
50300
50301 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
50302 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
50303 if (priv->seqnum == 0xffff)
50304 dev_info(&urb->dev->dev, "seqnum max\n");
50305
50306 @@ -685,7 +685,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
50307 return -ENOMEM;
50308 }
50309
50310 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
50311 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
50312 if (unlink->seqnum == 0xffff)
50313 pr_info("seqnum max\n");
50314
50315 @@ -889,7 +889,7 @@ static int vhci_start(struct usb_hcd *hcd)
50316 vdev->rhport = rhport;
50317 }
50318
50319 - atomic_set(&vhci->seqnum, 0);
50320 + atomic_set_unchecked(&vhci->seqnum, 0);
50321 spin_lock_init(&vhci->lock);
50322
50323 hcd->power_budget = 0; /* no limit */
50324 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
50325 index d07fcb5..358e1e1 100644
50326 --- a/drivers/staging/usbip/vhci_rx.c
50327 +++ b/drivers/staging/usbip/vhci_rx.c
50328 @@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
50329 if (!urb) {
50330 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
50331 pr_info("max seqnum %d\n",
50332 - atomic_read(&the_controller->seqnum));
50333 + atomic_read_unchecked(&the_controller->seqnum));
50334 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
50335 return;
50336 }
50337 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
50338 index 6eecd53..29317c6 100644
50339 --- a/drivers/staging/vt6655/hostap.c
50340 +++ b/drivers/staging/vt6655/hostap.c
50341 @@ -69,14 +69,13 @@ static int msglevel = MSG_LEVEL_INFO;
50342 *
50343 */
50344
50345 +static net_device_ops_no_const apdev_netdev_ops;
50346 +
50347 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
50348 {
50349 PSDevice apdev_priv;
50350 struct net_device *dev = pDevice->dev;
50351 int ret;
50352 - const struct net_device_ops apdev_netdev_ops = {
50353 - .ndo_start_xmit = pDevice->tx_80211,
50354 - };
50355
50356 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
50357
50358 @@ -88,6 +87,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
50359 *apdev_priv = *pDevice;
50360 eth_hw_addr_inherit(pDevice->apdev, dev);
50361
50362 + /* only half broken now */
50363 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
50364 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
50365
50366 pDevice->apdev->type = ARPHRD_IEEE80211;
50367 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
50368 index 67ba48b..24e602f 100644
50369 --- a/drivers/staging/vt6656/hostap.c
50370 +++ b/drivers/staging/vt6656/hostap.c
50371 @@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
50372 *
50373 */
50374
50375 +static net_device_ops_no_const apdev_netdev_ops;
50376 +
50377 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
50378 {
50379 struct vnt_private *apdev_priv;
50380 struct net_device *dev = pDevice->dev;
50381 int ret;
50382 - const struct net_device_ops apdev_netdev_ops = {
50383 - .ndo_start_xmit = pDevice->tx_80211,
50384 - };
50385
50386 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
50387
50388 @@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
50389 *apdev_priv = *pDevice;
50390 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
50391
50392 + /* only half broken now */
50393 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
50394 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
50395
50396 pDevice->apdev->type = ARPHRD_IEEE80211;
50397 diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
50398 index e7e9372..161f530 100644
50399 --- a/drivers/target/sbp/sbp_target.c
50400 +++ b/drivers/target/sbp/sbp_target.c
50401 @@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
50402
50403 #define SESSION_MAINTENANCE_INTERVAL HZ
50404
50405 -static atomic_t login_id = ATOMIC_INIT(0);
50406 +static atomic_unchecked_t login_id = ATOMIC_INIT(0);
50407
50408 static void session_maintenance_work(struct work_struct *);
50409 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
50410 @@ -444,7 +444,7 @@ static void sbp_management_request_login(
50411 login->lun = se_lun;
50412 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
50413 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
50414 - login->login_id = atomic_inc_return(&login_id);
50415 + login->login_id = atomic_inc_return_unchecked(&login_id);
50416
50417 login->tgt_agt = sbp_target_agent_register(login);
50418 if (IS_ERR(login->tgt_agt)) {
50419 diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
50420 index 6ea95d2..88607b4 100644
50421 --- a/drivers/target/target_core_device.c
50422 +++ b/drivers/target/target_core_device.c
50423 @@ -1525,7 +1525,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
50424 spin_lock_init(&dev->se_tmr_lock);
50425 spin_lock_init(&dev->qf_cmd_lock);
50426 sema_init(&dev->caw_sem, 1);
50427 - atomic_set(&dev->dev_ordered_id, 0);
50428 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
50429 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
50430 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
50431 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
50432 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
50433 index 14772e9..42d9f63 100644
50434 --- a/drivers/target/target_core_transport.c
50435 +++ b/drivers/target/target_core_transport.c
50436 @@ -1165,7 +1165,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
50437 * Used to determine when ORDERED commands should go from
50438 * Dormant to Active status.
50439 */
50440 - cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
50441 + cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
50442 smp_mb__after_atomic_inc();
50443 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
50444 cmd->se_ordered_id, cmd->sam_task_attr,
50445 diff --git a/drivers/thermal/of-thermal.c b/drivers/thermal/of-thermal.c
50446 index 04b1be7..5eff86d 100644
50447 --- a/drivers/thermal/of-thermal.c
50448 +++ b/drivers/thermal/of-thermal.c
50449 @@ -30,6 +30,7 @@
50450 #include <linux/err.h>
50451 #include <linux/export.h>
50452 #include <linux/string.h>
50453 +#include <linux/mm.h>
50454
50455 #include "thermal_core.h"
50456
50457 @@ -341,8 +342,10 @@ thermal_zone_of_add_sensor(struct device_node *zone,
50458 tz->get_trend = get_trend;
50459 tz->sensor_data = data;
50460
50461 - tzd->ops->get_temp = of_thermal_get_temp;
50462 - tzd->ops->get_trend = of_thermal_get_trend;
50463 + pax_open_kernel();
50464 + *(void **)&tzd->ops->get_temp = of_thermal_get_temp;
50465 + *(void **)&tzd->ops->get_trend = of_thermal_get_trend;
50466 + pax_close_kernel();
50467 mutex_unlock(&tzd->lock);
50468
50469 return tzd;
50470 @@ -461,8 +464,10 @@ void thermal_zone_of_sensor_unregister(struct device *dev,
50471 return;
50472
50473 mutex_lock(&tzd->lock);
50474 - tzd->ops->get_temp = NULL;
50475 - tzd->ops->get_trend = NULL;
50476 + pax_open_kernel();
50477 + *(void **)&tzd->ops->get_temp = NULL;
50478 + *(void **)&tzd->ops->get_trend = NULL;
50479 + pax_close_kernel();
50480
50481 tz->get_temp = NULL;
50482 tz->get_trend = NULL;
50483 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
50484 index a57bb5a..1f727d33 100644
50485 --- a/drivers/tty/cyclades.c
50486 +++ b/drivers/tty/cyclades.c
50487 @@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
50488 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
50489 info->port.count);
50490 #endif
50491 - info->port.count++;
50492 + atomic_inc(&info->port.count);
50493 #ifdef CY_DEBUG_COUNT
50494 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
50495 - current->pid, info->port.count);
50496 + current->pid, atomic_read(&info->port.count));
50497 #endif
50498
50499 /*
50500 @@ -3974,7 +3974,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
50501 for (j = 0; j < cy_card[i].nports; j++) {
50502 info = &cy_card[i].ports[j];
50503
50504 - if (info->port.count) {
50505 + if (atomic_read(&info->port.count)) {
50506 /* XXX is the ldisc num worth this? */
50507 struct tty_struct *tty;
50508 struct tty_ldisc *ld;
50509 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
50510 index 0ff7fda..dbc7d52 100644
50511 --- a/drivers/tty/hvc/hvc_console.c
50512 +++ b/drivers/tty/hvc/hvc_console.c
50513 @@ -342,7 +342,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
50514
50515 spin_lock_irqsave(&hp->port.lock, flags);
50516 /* Check and then increment for fast path open. */
50517 - if (hp->port.count++ > 0) {
50518 + if (atomic_inc_return(&hp->port.count) > 1) {
50519 spin_unlock_irqrestore(&hp->port.lock, flags);
50520 hvc_kick();
50521 return 0;
50522 @@ -397,7 +397,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
50523
50524 spin_lock_irqsave(&hp->port.lock, flags);
50525
50526 - if (--hp->port.count == 0) {
50527 + if (atomic_dec_return(&hp->port.count) == 0) {
50528 spin_unlock_irqrestore(&hp->port.lock, flags);
50529 /* We are done with the tty pointer now. */
50530 tty_port_tty_set(&hp->port, NULL);
50531 @@ -419,9 +419,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
50532 */
50533 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
50534 } else {
50535 - if (hp->port.count < 0)
50536 + if (atomic_read(&hp->port.count) < 0)
50537 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
50538 - hp->vtermno, hp->port.count);
50539 + hp->vtermno, atomic_read(&hp->port.count));
50540 spin_unlock_irqrestore(&hp->port.lock, flags);
50541 }
50542 }
50543 @@ -451,12 +451,12 @@ static void hvc_hangup(struct tty_struct *tty)
50544 * open->hangup case this can be called after the final close so prevent
50545 * that from happening for now.
50546 */
50547 - if (hp->port.count <= 0) {
50548 + if (atomic_read(&hp->port.count) <= 0) {
50549 spin_unlock_irqrestore(&hp->port.lock, flags);
50550 return;
50551 }
50552
50553 - hp->port.count = 0;
50554 + atomic_set(&hp->port.count, 0);
50555 spin_unlock_irqrestore(&hp->port.lock, flags);
50556 tty_port_tty_set(&hp->port, NULL);
50557
50558 @@ -504,7 +504,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
50559 return -EPIPE;
50560
50561 /* FIXME what's this (unprotected) check for? */
50562 - if (hp->port.count <= 0)
50563 + if (atomic_read(&hp->port.count) <= 0)
50564 return -EIO;
50565
50566 spin_lock_irqsave(&hp->lock, flags);
50567 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
50568 index 81e939e..95ead10 100644
50569 --- a/drivers/tty/hvc/hvcs.c
50570 +++ b/drivers/tty/hvc/hvcs.c
50571 @@ -83,6 +83,7 @@
50572 #include <asm/hvcserver.h>
50573 #include <asm/uaccess.h>
50574 #include <asm/vio.h>
50575 +#include <asm/local.h>
50576
50577 /*
50578 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
50579 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
50580
50581 spin_lock_irqsave(&hvcsd->lock, flags);
50582
50583 - if (hvcsd->port.count > 0) {
50584 + if (atomic_read(&hvcsd->port.count) > 0) {
50585 spin_unlock_irqrestore(&hvcsd->lock, flags);
50586 printk(KERN_INFO "HVCS: vterm state unchanged. "
50587 "The hvcs device node is still in use.\n");
50588 @@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
50589 }
50590 }
50591
50592 - hvcsd->port.count = 0;
50593 + atomic_set(&hvcsd->port.count, 0);
50594 hvcsd->port.tty = tty;
50595 tty->driver_data = hvcsd;
50596
50597 @@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
50598 unsigned long flags;
50599
50600 spin_lock_irqsave(&hvcsd->lock, flags);
50601 - hvcsd->port.count++;
50602 + atomic_inc(&hvcsd->port.count);
50603 hvcsd->todo_mask |= HVCS_SCHED_READ;
50604 spin_unlock_irqrestore(&hvcsd->lock, flags);
50605
50606 @@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
50607 hvcsd = tty->driver_data;
50608
50609 spin_lock_irqsave(&hvcsd->lock, flags);
50610 - if (--hvcsd->port.count == 0) {
50611 + if (atomic_dec_and_test(&hvcsd->port.count)) {
50612
50613 vio_disable_interrupts(hvcsd->vdev);
50614
50615 @@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
50616
50617 free_irq(irq, hvcsd);
50618 return;
50619 - } else if (hvcsd->port.count < 0) {
50620 + } else if (atomic_read(&hvcsd->port.count) < 0) {
50621 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
50622 " is missmanaged.\n",
50623 - hvcsd->vdev->unit_address, hvcsd->port.count);
50624 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
50625 }
50626
50627 spin_unlock_irqrestore(&hvcsd->lock, flags);
50628 @@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
50629
50630 spin_lock_irqsave(&hvcsd->lock, flags);
50631 /* Preserve this so that we know how many kref refs to put */
50632 - temp_open_count = hvcsd->port.count;
50633 + temp_open_count = atomic_read(&hvcsd->port.count);
50634
50635 /*
50636 * Don't kref put inside the spinlock because the destruction
50637 @@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
50638 tty->driver_data = NULL;
50639 hvcsd->port.tty = NULL;
50640
50641 - hvcsd->port.count = 0;
50642 + atomic_set(&hvcsd->port.count, 0);
50643
50644 /* This will drop any buffered data on the floor which is OK in a hangup
50645 * scenario. */
50646 @@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
50647 * the middle of a write operation? This is a crummy place to do this
50648 * but we want to keep it all in the spinlock.
50649 */
50650 - if (hvcsd->port.count <= 0) {
50651 + if (atomic_read(&hvcsd->port.count) <= 0) {
50652 spin_unlock_irqrestore(&hvcsd->lock, flags);
50653 return -ENODEV;
50654 }
50655 @@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
50656 {
50657 struct hvcs_struct *hvcsd = tty->driver_data;
50658
50659 - if (!hvcsd || hvcsd->port.count <= 0)
50660 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
50661 return 0;
50662
50663 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
50664 diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
50665 index 4190199..06d5bfa 100644
50666 --- a/drivers/tty/hvc/hvsi.c
50667 +++ b/drivers/tty/hvc/hvsi.c
50668 @@ -85,7 +85,7 @@ struct hvsi_struct {
50669 int n_outbuf;
50670 uint32_t vtermno;
50671 uint32_t virq;
50672 - atomic_t seqno; /* HVSI packet sequence number */
50673 + atomic_unchecked_t seqno; /* HVSI packet sequence number */
50674 uint16_t mctrl;
50675 uint8_t state; /* HVSI protocol state */
50676 uint8_t flags;
50677 @@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
50678
50679 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
50680 packet.hdr.len = sizeof(struct hvsi_query_response);
50681 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50682 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50683 packet.verb = VSV_SEND_VERSION_NUMBER;
50684 packet.u.version = HVSI_VERSION;
50685 packet.query_seqno = query_seqno+1;
50686 @@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
50687
50688 packet.hdr.type = VS_QUERY_PACKET_HEADER;
50689 packet.hdr.len = sizeof(struct hvsi_query);
50690 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50691 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50692 packet.verb = verb;
50693
50694 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
50695 @@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
50696 int wrote;
50697
50698 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
50699 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50700 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50701 packet.hdr.len = sizeof(struct hvsi_control);
50702 packet.verb = VSV_SET_MODEM_CTL;
50703 packet.mask = HVSI_TSDTR;
50704 @@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
50705 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
50706
50707 packet.hdr.type = VS_DATA_PACKET_HEADER;
50708 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50709 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50710 packet.hdr.len = count + sizeof(struct hvsi_header);
50711 memcpy(&packet.data, buf, count);
50712
50713 @@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
50714 struct hvsi_control packet __ALIGNED__;
50715
50716 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
50717 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
50718 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
50719 packet.hdr.len = 6;
50720 packet.verb = VSV_CLOSE_PROTOCOL;
50721
50722 @@ -725,7 +725,7 @@ static int hvsi_open(struct tty_struct *tty, struct file *filp)
50723
50724 tty_port_tty_set(&hp->port, tty);
50725 spin_lock_irqsave(&hp->lock, flags);
50726 - hp->port.count++;
50727 + atomic_inc(&hp->port.count);
50728 atomic_set(&hp->seqno, 0);
50729 h_vio_signal(hp->vtermno, VIO_IRQ_ENABLE);
50730 spin_unlock_irqrestore(&hp->lock, flags);
50731 @@ -782,7 +782,7 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
50732
50733 spin_lock_irqsave(&hp->lock, flags);
50734
50735 - if (--hp->port.count == 0) {
50736 + if (atomic_dec_return(&hp->port.count) == 0) {
50737 tty_port_tty_set(&hp->port, NULL);
50738 hp->inbuf_end = hp->inbuf; /* discard remaining partial packets */
50739
50740 @@ -815,9 +815,9 @@ static void hvsi_close(struct tty_struct *tty, struct file *filp)
50741
50742 spin_lock_irqsave(&hp->lock, flags);
50743 }
50744 - } else if (hp->port.count < 0)
50745 + } else if (atomic_read(&hp->port.count) < 0)
50746 printk(KERN_ERR "hvsi_close %lu: oops, count is %d\n",
50747 - hp - hvsi_ports, hp->port.count);
50748 + hp - hvsi_ports, atomic_read(&hp->port.count));
50749
50750 spin_unlock_irqrestore(&hp->lock, flags);
50751 }
50752 @@ -832,7 +832,7 @@ static void hvsi_hangup(struct tty_struct *tty)
50753 tty_port_tty_set(&hp->port, NULL);
50754
50755 spin_lock_irqsave(&hp->lock, flags);
50756 - hp->port.count = 0;
50757 + atomic_set(&hp->port.count, 0);
50758 hp->n_outbuf = 0;
50759 spin_unlock_irqrestore(&hp->lock, flags);
50760 }
50761 diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
50762 index 7ae6c29..05c6dba 100644
50763 --- a/drivers/tty/hvc/hvsi_lib.c
50764 +++ b/drivers/tty/hvc/hvsi_lib.c
50765 @@ -8,7 +8,7 @@
50766
50767 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
50768 {
50769 - packet->seqno = cpu_to_be16(atomic_inc_return(&pv->seqno));
50770 + packet->seqno = cpu_to_be16(atomic_inc_return_unchecked(&pv->seqno));
50771
50772 /* Assumes that always succeeds, works in practice */
50773 return pv->put_chars(pv->termno, (char *)packet, packet->len);
50774 @@ -20,7 +20,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
50775
50776 /* Reset state */
50777 pv->established = 0;
50778 - atomic_set(&pv->seqno, 0);
50779 + atomic_set_unchecked(&pv->seqno, 0);
50780
50781 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
50782
50783 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
50784 index 17ee3bf..8d2520d 100644
50785 --- a/drivers/tty/ipwireless/tty.c
50786 +++ b/drivers/tty/ipwireless/tty.c
50787 @@ -28,6 +28,7 @@
50788 #include <linux/tty_driver.h>
50789 #include <linux/tty_flip.h>
50790 #include <linux/uaccess.h>
50791 +#include <asm/local.h>
50792
50793 #include "tty.h"
50794 #include "network.h"
50795 @@ -98,10 +99,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
50796 mutex_unlock(&tty->ipw_tty_mutex);
50797 return -ENODEV;
50798 }
50799 - if (tty->port.count == 0)
50800 + if (atomic_read(&tty->port.count) == 0)
50801 tty->tx_bytes_queued = 0;
50802
50803 - tty->port.count++;
50804 + atomic_inc(&tty->port.count);
50805
50806 tty->port.tty = linux_tty;
50807 linux_tty->driver_data = tty;
50808 @@ -117,9 +118,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
50809
50810 static void do_ipw_close(struct ipw_tty *tty)
50811 {
50812 - tty->port.count--;
50813 -
50814 - if (tty->port.count == 0) {
50815 + if (atomic_dec_return(&tty->port.count) == 0) {
50816 struct tty_struct *linux_tty = tty->port.tty;
50817
50818 if (linux_tty != NULL) {
50819 @@ -140,7 +139,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
50820 return;
50821
50822 mutex_lock(&tty->ipw_tty_mutex);
50823 - if (tty->port.count == 0) {
50824 + if (atomic_read(&tty->port.count) == 0) {
50825 mutex_unlock(&tty->ipw_tty_mutex);
50826 return;
50827 }
50828 @@ -163,7 +162,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
50829
50830 mutex_lock(&tty->ipw_tty_mutex);
50831
50832 - if (!tty->port.count) {
50833 + if (!atomic_read(&tty->port.count)) {
50834 mutex_unlock(&tty->ipw_tty_mutex);
50835 return;
50836 }
50837 @@ -202,7 +201,7 @@ static int ipw_write(struct tty_struct *linux_tty,
50838 return -ENODEV;
50839
50840 mutex_lock(&tty->ipw_tty_mutex);
50841 - if (!tty->port.count) {
50842 + if (!atomic_read(&tty->port.count)) {
50843 mutex_unlock(&tty->ipw_tty_mutex);
50844 return -EINVAL;
50845 }
50846 @@ -242,7 +241,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
50847 if (!tty)
50848 return -ENODEV;
50849
50850 - if (!tty->port.count)
50851 + if (!atomic_read(&tty->port.count))
50852 return -EINVAL;
50853
50854 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
50855 @@ -284,7 +283,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
50856 if (!tty)
50857 return 0;
50858
50859 - if (!tty->port.count)
50860 + if (!atomic_read(&tty->port.count))
50861 return 0;
50862
50863 return tty->tx_bytes_queued;
50864 @@ -365,7 +364,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
50865 if (!tty)
50866 return -ENODEV;
50867
50868 - if (!tty->port.count)
50869 + if (!atomic_read(&tty->port.count))
50870 return -EINVAL;
50871
50872 return get_control_lines(tty);
50873 @@ -381,7 +380,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
50874 if (!tty)
50875 return -ENODEV;
50876
50877 - if (!tty->port.count)
50878 + if (!atomic_read(&tty->port.count))
50879 return -EINVAL;
50880
50881 return set_control_lines(tty, set, clear);
50882 @@ -395,7 +394,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
50883 if (!tty)
50884 return -ENODEV;
50885
50886 - if (!tty->port.count)
50887 + if (!atomic_read(&tty->port.count))
50888 return -EINVAL;
50889
50890 /* FIXME: Exactly how is the tty object locked here .. */
50891 @@ -551,7 +550,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
50892 * are gone */
50893 mutex_lock(&ttyj->ipw_tty_mutex);
50894 }
50895 - while (ttyj->port.count)
50896 + while (atomic_read(&ttyj->port.count))
50897 do_ipw_close(ttyj);
50898 ipwireless_disassociate_network_ttys(network,
50899 ttyj->channel_idx);
50900 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
50901 index 1deaca4..c8582d4 100644
50902 --- a/drivers/tty/moxa.c
50903 +++ b/drivers/tty/moxa.c
50904 @@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
50905 }
50906
50907 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
50908 - ch->port.count++;
50909 + atomic_inc(&ch->port.count);
50910 tty->driver_data = ch;
50911 tty_port_tty_set(&ch->port, tty);
50912 mutex_lock(&ch->port.mutex);
50913 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
50914 index 2ebe47b..3205833 100644
50915 --- a/drivers/tty/n_gsm.c
50916 +++ b/drivers/tty/n_gsm.c
50917 @@ -1644,7 +1644,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
50918 spin_lock_init(&dlci->lock);
50919 mutex_init(&dlci->mutex);
50920 dlci->fifo = &dlci->_fifo;
50921 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
50922 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
50923 kfree(dlci);
50924 return NULL;
50925 }
50926 @@ -2954,7 +2954,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
50927 struct gsm_dlci *dlci = tty->driver_data;
50928 struct tty_port *port = &dlci->port;
50929
50930 - port->count++;
50931 + atomic_inc(&port->count);
50932 tty_port_tty_set(port, tty);
50933
50934 dlci->modem_rx = 0;
50935 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
50936 index 0391f17..31fa586 100644
50937 --- a/drivers/tty/n_tty.c
50938 +++ b/drivers/tty/n_tty.c
50939 @@ -115,7 +115,7 @@ struct n_tty_data {
50940 int minimum_to_wake;
50941
50942 /* consumer-published */
50943 - size_t read_tail;
50944 + size_t read_tail __intentional_overflow(-1);
50945 size_t line_start;
50946
50947 /* protected by output lock */
50948 @@ -2517,6 +2517,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
50949 {
50950 *ops = tty_ldisc_N_TTY;
50951 ops->owner = NULL;
50952 - ops->refcount = ops->flags = 0;
50953 + atomic_set(&ops->refcount, 0);
50954 + ops->flags = 0;
50955 }
50956 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
50957 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
50958 index 25c9bc7..24077b7 100644
50959 --- a/drivers/tty/pty.c
50960 +++ b/drivers/tty/pty.c
50961 @@ -790,8 +790,10 @@ static void __init unix98_pty_init(void)
50962 panic("Couldn't register Unix98 pts driver");
50963
50964 /* Now create the /dev/ptmx special device */
50965 + pax_open_kernel();
50966 tty_default_fops(&ptmx_fops);
50967 - ptmx_fops.open = ptmx_open;
50968 + *(void **)&ptmx_fops.open = ptmx_open;
50969 + pax_close_kernel();
50970
50971 cdev_init(&ptmx_cdev, &ptmx_fops);
50972 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
50973 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
50974 index 383c4c7..d408e21 100644
50975 --- a/drivers/tty/rocket.c
50976 +++ b/drivers/tty/rocket.c
50977 @@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
50978 tty->driver_data = info;
50979 tty_port_tty_set(port, tty);
50980
50981 - if (port->count++ == 0) {
50982 + if (atomic_inc_return(&port->count) == 1) {
50983 atomic_inc(&rp_num_ports_open);
50984
50985 #ifdef ROCKET_DEBUG_OPEN
50986 @@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
50987 #endif
50988 }
50989 #ifdef ROCKET_DEBUG_OPEN
50990 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
50991 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
50992 #endif
50993
50994 /*
50995 @@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
50996 spin_unlock_irqrestore(&info->port.lock, flags);
50997 return;
50998 }
50999 - if (info->port.count)
51000 + if (atomic_read(&info->port.count))
51001 atomic_dec(&rp_num_ports_open);
51002 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
51003 spin_unlock_irqrestore(&info->port.lock, flags);
51004 diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
51005 index 1274499..f541382 100644
51006 --- a/drivers/tty/serial/ioc4_serial.c
51007 +++ b/drivers/tty/serial/ioc4_serial.c
51008 @@ -437,7 +437,7 @@ struct ioc4_soft {
51009 } is_intr_info[MAX_IOC4_INTR_ENTS];
51010
51011 /* Number of entries active in the above array */
51012 - atomic_t is_num_intrs;
51013 + atomic_unchecked_t is_num_intrs;
51014 } is_intr_type[IOC4_NUM_INTR_TYPES];
51015
51016 /* is_ir_lock must be held while
51017 @@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
51018 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
51019 || (type == IOC4_OTHER_INTR_TYPE)));
51020
51021 - i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
51022 + i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
51023 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
51024
51025 /* Save off the lower level interrupt handler */
51026 @@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
51027
51028 soft = arg;
51029 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
51030 - num_intrs = (int)atomic_read(
51031 + num_intrs = (int)atomic_read_unchecked(
51032 &soft->is_intr_type[intr_type].is_num_intrs);
51033
51034 this_mir = this_ir = pending_intrs(soft, intr_type);
51035 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
51036 index a260cde..6b2b5ce 100644
51037 --- a/drivers/tty/serial/kgdboc.c
51038 +++ b/drivers/tty/serial/kgdboc.c
51039 @@ -24,8 +24,9 @@
51040 #define MAX_CONFIG_LEN 40
51041
51042 static struct kgdb_io kgdboc_io_ops;
51043 +static struct kgdb_io kgdboc_io_ops_console;
51044
51045 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
51046 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
51047 static int configured = -1;
51048
51049 static char config[MAX_CONFIG_LEN];
51050 @@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
51051 kgdboc_unregister_kbd();
51052 if (configured == 1)
51053 kgdb_unregister_io_module(&kgdboc_io_ops);
51054 + else if (configured == 2)
51055 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
51056 }
51057
51058 static int configure_kgdboc(void)
51059 @@ -160,13 +163,13 @@ static int configure_kgdboc(void)
51060 int err;
51061 char *cptr = config;
51062 struct console *cons;
51063 + int is_console = 0;
51064
51065 err = kgdboc_option_setup(config);
51066 if (err || !strlen(config) || isspace(config[0]))
51067 goto noconfig;
51068
51069 err = -ENODEV;
51070 - kgdboc_io_ops.is_console = 0;
51071 kgdb_tty_driver = NULL;
51072
51073 kgdboc_use_kms = 0;
51074 @@ -187,7 +190,7 @@ static int configure_kgdboc(void)
51075 int idx;
51076 if (cons->device && cons->device(cons, &idx) == p &&
51077 idx == tty_line) {
51078 - kgdboc_io_ops.is_console = 1;
51079 + is_console = 1;
51080 break;
51081 }
51082 cons = cons->next;
51083 @@ -197,7 +200,13 @@ static int configure_kgdboc(void)
51084 kgdb_tty_line = tty_line;
51085
51086 do_register:
51087 - err = kgdb_register_io_module(&kgdboc_io_ops);
51088 + if (is_console) {
51089 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
51090 + configured = 2;
51091 + } else {
51092 + err = kgdb_register_io_module(&kgdboc_io_ops);
51093 + configured = 1;
51094 + }
51095 if (err)
51096 goto noconfig;
51097
51098 @@ -205,8 +214,6 @@ do_register:
51099 if (err)
51100 goto nmi_con_failed;
51101
51102 - configured = 1;
51103 -
51104 return 0;
51105
51106 nmi_con_failed:
51107 @@ -223,7 +230,7 @@ noconfig:
51108 static int __init init_kgdboc(void)
51109 {
51110 /* Already configured? */
51111 - if (configured == 1)
51112 + if (configured >= 1)
51113 return 0;
51114
51115 return configure_kgdboc();
51116 @@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
51117 if (config[len - 1] == '\n')
51118 config[len - 1] = '\0';
51119
51120 - if (configured == 1)
51121 + if (configured >= 1)
51122 cleanup_kgdboc();
51123
51124 /* Go and configure with the new params. */
51125 @@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
51126 .post_exception = kgdboc_post_exp_handler,
51127 };
51128
51129 +static struct kgdb_io kgdboc_io_ops_console = {
51130 + .name = "kgdboc",
51131 + .read_char = kgdboc_get_char,
51132 + .write_char = kgdboc_put_char,
51133 + .pre_exception = kgdboc_pre_exp_handler,
51134 + .post_exception = kgdboc_post_exp_handler,
51135 + .is_console = 1
51136 +};
51137 +
51138 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
51139 /* This is only available if kgdboc is a built in for early debugging */
51140 static int __init kgdboc_early_init(char *opt)
51141 diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
51142 index 7307dc4..ce4fe90 100644
51143 --- a/drivers/tty/serial/msm_serial.c
51144 +++ b/drivers/tty/serial/msm_serial.c
51145 @@ -1026,7 +1026,7 @@ static struct uart_driver msm_uart_driver = {
51146 .cons = MSM_CONSOLE,
51147 };
51148
51149 -static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
51150 +static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
51151
51152 static const struct of_device_id msm_uartdm_table[] = {
51153 { .compatible = "qcom,msm-uartdm-v1.1", .data = (void *)UARTDM_1P1 },
51154 @@ -1045,7 +1045,7 @@ static int __init msm_serial_probe(struct platform_device *pdev)
51155 int irq;
51156
51157 if (pdev->id == -1)
51158 - pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
51159 + pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
51160
51161 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
51162 return -ENXIO;
51163 diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
51164 index 1f5505e..a1a767d 100644
51165 --- a/drivers/tty/serial/samsung.c
51166 +++ b/drivers/tty/serial/samsung.c
51167 @@ -463,11 +463,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
51168 }
51169 }
51170
51171 +static int s3c64xx_serial_startup(struct uart_port *port);
51172 static int s3c24xx_serial_startup(struct uart_port *port)
51173 {
51174 struct s3c24xx_uart_port *ourport = to_ourport(port);
51175 int ret;
51176
51177 + /* Startup sequence is different for s3c64xx and higher SoC's */
51178 + if (s3c24xx_serial_has_interrupt_mask(port))
51179 + return s3c64xx_serial_startup(port);
51180 +
51181 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
51182 port->mapbase, port->membase);
51183
51184 @@ -1141,10 +1146,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
51185 /* setup info for port */
51186 port->dev = &platdev->dev;
51187
51188 - /* Startup sequence is different for s3c64xx and higher SoC's */
51189 - if (s3c24xx_serial_has_interrupt_mask(port))
51190 - s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
51191 -
51192 port->uartclk = 1;
51193
51194 if (cfg->uart_flags & UPF_CONS_FLOW) {
51195 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
51196 index b68550d..a62d7f8 100644
51197 --- a/drivers/tty/serial/serial_core.c
51198 +++ b/drivers/tty/serial/serial_core.c
51199 @@ -1329,7 +1329,7 @@ static void uart_close(struct tty_struct *tty, struct file *filp)
51200
51201 pr_debug("uart_close(%d) called\n", uport ? uport->line : -1);
51202
51203 - if (!port->count || tty_port_close_start(port, tty, filp) == 0)
51204 + if (!atomic_read(&port->count) || tty_port_close_start(port, tty, filp) == 0)
51205 return;
51206
51207 /*
51208 @@ -1456,7 +1456,7 @@ static void uart_hangup(struct tty_struct *tty)
51209 uart_flush_buffer(tty);
51210 uart_shutdown(tty, state);
51211 spin_lock_irqsave(&port->lock, flags);
51212 - port->count = 0;
51213 + atomic_set(&port->count, 0);
51214 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
51215 spin_unlock_irqrestore(&port->lock, flags);
51216 tty_port_tty_set(port, NULL);
51217 @@ -1554,7 +1554,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
51218 goto end;
51219 }
51220
51221 - port->count++;
51222 + atomic_inc(&port->count);
51223 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
51224 retval = -ENXIO;
51225 goto err_dec_count;
51226 @@ -1594,7 +1594,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
51227 end:
51228 return retval;
51229 err_dec_count:
51230 - port->count--;
51231 + atomic_inc(&port->count);
51232 mutex_unlock(&port->mutex);
51233 goto end;
51234 }
51235 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
51236 index d48e040..0f52764 100644
51237 --- a/drivers/tty/synclink.c
51238 +++ b/drivers/tty/synclink.c
51239 @@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
51240
51241 if (debug_level >= DEBUG_LEVEL_INFO)
51242 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
51243 - __FILE__,__LINE__, info->device_name, info->port.count);
51244 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
51245
51246 if (tty_port_close_start(&info->port, tty, filp) == 0)
51247 goto cleanup;
51248 @@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
51249 cleanup:
51250 if (debug_level >= DEBUG_LEVEL_INFO)
51251 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
51252 - tty->driver->name, info->port.count);
51253 + tty->driver->name, atomic_read(&info->port.count));
51254
51255 } /* end of mgsl_close() */
51256
51257 @@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
51258
51259 mgsl_flush_buffer(tty);
51260 shutdown(info);
51261 -
51262 - info->port.count = 0;
51263 +
51264 + atomic_set(&info->port.count, 0);
51265 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51266 info->port.tty = NULL;
51267
51268 @@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51269
51270 if (debug_level >= DEBUG_LEVEL_INFO)
51271 printk("%s(%d):block_til_ready before block on %s count=%d\n",
51272 - __FILE__,__LINE__, tty->driver->name, port->count );
51273 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51274
51275 spin_lock_irqsave(&info->irq_spinlock, flags);
51276 if (!tty_hung_up_p(filp)) {
51277 extra_count = true;
51278 - port->count--;
51279 + atomic_dec(&port->count);
51280 }
51281 spin_unlock_irqrestore(&info->irq_spinlock, flags);
51282 port->blocked_open++;
51283 @@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51284
51285 if (debug_level >= DEBUG_LEVEL_INFO)
51286 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
51287 - __FILE__,__LINE__, tty->driver->name, port->count );
51288 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51289
51290 tty_unlock(tty);
51291 schedule();
51292 @@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
51293
51294 /* FIXME: Racy on hangup during close wait */
51295 if (extra_count)
51296 - port->count++;
51297 + atomic_inc(&port->count);
51298 port->blocked_open--;
51299
51300 if (debug_level >= DEBUG_LEVEL_INFO)
51301 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
51302 - __FILE__,__LINE__, tty->driver->name, port->count );
51303 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51304
51305 if (!retval)
51306 port->flags |= ASYNC_NORMAL_ACTIVE;
51307 @@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
51308
51309 if (debug_level >= DEBUG_LEVEL_INFO)
51310 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
51311 - __FILE__,__LINE__,tty->driver->name, info->port.count);
51312 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
51313
51314 /* If port is closing, signal caller to try again */
51315 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51316 @@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
51317 spin_unlock_irqrestore(&info->netlock, flags);
51318 goto cleanup;
51319 }
51320 - info->port.count++;
51321 + atomic_inc(&info->port.count);
51322 spin_unlock_irqrestore(&info->netlock, flags);
51323
51324 - if (info->port.count == 1) {
51325 + if (atomic_read(&info->port.count) == 1) {
51326 /* 1st open on this device, init hardware */
51327 retval = startup(info);
51328 if (retval < 0)
51329 @@ -3446,8 +3446,8 @@ cleanup:
51330 if (retval) {
51331 if (tty->count == 1)
51332 info->port.tty = NULL; /* tty layer will release tty struct */
51333 - if(info->port.count)
51334 - info->port.count--;
51335 + if (atomic_read(&info->port.count))
51336 + atomic_dec(&info->port.count);
51337 }
51338
51339 return retval;
51340 @@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51341 unsigned short new_crctype;
51342
51343 /* return error if TTY interface open */
51344 - if (info->port.count)
51345 + if (atomic_read(&info->port.count))
51346 return -EBUSY;
51347
51348 switch (encoding)
51349 @@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
51350
51351 /* arbitrate between network and tty opens */
51352 spin_lock_irqsave(&info->netlock, flags);
51353 - if (info->port.count != 0 || info->netcount != 0) {
51354 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51355 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
51356 spin_unlock_irqrestore(&info->netlock, flags);
51357 return -EBUSY;
51358 @@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51359 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
51360
51361 /* return error if TTY interface open */
51362 - if (info->port.count)
51363 + if (atomic_read(&info->port.count))
51364 return -EBUSY;
51365
51366 if (cmd != SIOCWANDEV)
51367 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
51368 index c359a91..959fc26 100644
51369 --- a/drivers/tty/synclink_gt.c
51370 +++ b/drivers/tty/synclink_gt.c
51371 @@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
51372 tty->driver_data = info;
51373 info->port.tty = tty;
51374
51375 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
51376 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
51377
51378 /* If port is closing, signal caller to try again */
51379 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51380 @@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
51381 mutex_unlock(&info->port.mutex);
51382 goto cleanup;
51383 }
51384 - info->port.count++;
51385 + atomic_inc(&info->port.count);
51386 spin_unlock_irqrestore(&info->netlock, flags);
51387
51388 - if (info->port.count == 1) {
51389 + if (atomic_read(&info->port.count) == 1) {
51390 /* 1st open on this device, init hardware */
51391 retval = startup(info);
51392 if (retval < 0) {
51393 @@ -715,8 +715,8 @@ cleanup:
51394 if (retval) {
51395 if (tty->count == 1)
51396 info->port.tty = NULL; /* tty layer will release tty struct */
51397 - if(info->port.count)
51398 - info->port.count--;
51399 + if(atomic_read(&info->port.count))
51400 + atomic_dec(&info->port.count);
51401 }
51402
51403 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
51404 @@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51405
51406 if (sanity_check(info, tty->name, "close"))
51407 return;
51408 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
51409 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
51410
51411 if (tty_port_close_start(&info->port, tty, filp) == 0)
51412 goto cleanup;
51413 @@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51414 tty_port_close_end(&info->port, tty);
51415 info->port.tty = NULL;
51416 cleanup:
51417 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
51418 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
51419 }
51420
51421 static void hangup(struct tty_struct *tty)
51422 @@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
51423 shutdown(info);
51424
51425 spin_lock_irqsave(&info->port.lock, flags);
51426 - info->port.count = 0;
51427 + atomic_set(&info->port.count, 0);
51428 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51429 info->port.tty = NULL;
51430 spin_unlock_irqrestore(&info->port.lock, flags);
51431 @@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51432 unsigned short new_crctype;
51433
51434 /* return error if TTY interface open */
51435 - if (info->port.count)
51436 + if (atomic_read(&info->port.count))
51437 return -EBUSY;
51438
51439 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
51440 @@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
51441
51442 /* arbitrate between network and tty opens */
51443 spin_lock_irqsave(&info->netlock, flags);
51444 - if (info->port.count != 0 || info->netcount != 0) {
51445 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51446 DBGINFO(("%s hdlc_open busy\n", dev->name));
51447 spin_unlock_irqrestore(&info->netlock, flags);
51448 return -EBUSY;
51449 @@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51450 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
51451
51452 /* return error if TTY interface open */
51453 - if (info->port.count)
51454 + if (atomic_read(&info->port.count))
51455 return -EBUSY;
51456
51457 if (cmd != SIOCWANDEV)
51458 @@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
51459 if (port == NULL)
51460 continue;
51461 spin_lock(&port->lock);
51462 - if ((port->port.count || port->netcount) &&
51463 + if ((atomic_read(&port->port.count) || port->netcount) &&
51464 port->pending_bh && !port->bh_running &&
51465 !port->bh_requested) {
51466 DBGISR(("%s bh queued\n", port->device_name));
51467 @@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51468 spin_lock_irqsave(&info->lock, flags);
51469 if (!tty_hung_up_p(filp)) {
51470 extra_count = true;
51471 - port->count--;
51472 + atomic_dec(&port->count);
51473 }
51474 spin_unlock_irqrestore(&info->lock, flags);
51475 port->blocked_open++;
51476 @@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51477 remove_wait_queue(&port->open_wait, &wait);
51478
51479 if (extra_count)
51480 - port->count++;
51481 + atomic_inc(&port->count);
51482 port->blocked_open--;
51483
51484 if (!retval)
51485 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
51486 index 53ba853..3c30f6d 100644
51487 --- a/drivers/tty/synclinkmp.c
51488 +++ b/drivers/tty/synclinkmp.c
51489 @@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
51490
51491 if (debug_level >= DEBUG_LEVEL_INFO)
51492 printk("%s(%d):%s open(), old ref count = %d\n",
51493 - __FILE__,__LINE__,tty->driver->name, info->port.count);
51494 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
51495
51496 /* If port is closing, signal caller to try again */
51497 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
51498 @@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
51499 spin_unlock_irqrestore(&info->netlock, flags);
51500 goto cleanup;
51501 }
51502 - info->port.count++;
51503 + atomic_inc(&info->port.count);
51504 spin_unlock_irqrestore(&info->netlock, flags);
51505
51506 - if (info->port.count == 1) {
51507 + if (atomic_read(&info->port.count) == 1) {
51508 /* 1st open on this device, init hardware */
51509 retval = startup(info);
51510 if (retval < 0)
51511 @@ -796,8 +796,8 @@ cleanup:
51512 if (retval) {
51513 if (tty->count == 1)
51514 info->port.tty = NULL; /* tty layer will release tty struct */
51515 - if(info->port.count)
51516 - info->port.count--;
51517 + if(atomic_read(&info->port.count))
51518 + atomic_dec(&info->port.count);
51519 }
51520
51521 return retval;
51522 @@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51523
51524 if (debug_level >= DEBUG_LEVEL_INFO)
51525 printk("%s(%d):%s close() entry, count=%d\n",
51526 - __FILE__,__LINE__, info->device_name, info->port.count);
51527 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
51528
51529 if (tty_port_close_start(&info->port, tty, filp) == 0)
51530 goto cleanup;
51531 @@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
51532 cleanup:
51533 if (debug_level >= DEBUG_LEVEL_INFO)
51534 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
51535 - tty->driver->name, info->port.count);
51536 + tty->driver->name, atomic_read(&info->port.count));
51537 }
51538
51539 /* Called by tty_hangup() when a hangup is signaled.
51540 @@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
51541 shutdown(info);
51542
51543 spin_lock_irqsave(&info->port.lock, flags);
51544 - info->port.count = 0;
51545 + atomic_set(&info->port.count, 0);
51546 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
51547 info->port.tty = NULL;
51548 spin_unlock_irqrestore(&info->port.lock, flags);
51549 @@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
51550 unsigned short new_crctype;
51551
51552 /* return error if TTY interface open */
51553 - if (info->port.count)
51554 + if (atomic_read(&info->port.count))
51555 return -EBUSY;
51556
51557 switch (encoding)
51558 @@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
51559
51560 /* arbitrate between network and tty opens */
51561 spin_lock_irqsave(&info->netlock, flags);
51562 - if (info->port.count != 0 || info->netcount != 0) {
51563 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
51564 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
51565 spin_unlock_irqrestore(&info->netlock, flags);
51566 return -EBUSY;
51567 @@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
51568 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
51569
51570 /* return error if TTY interface open */
51571 - if (info->port.count)
51572 + if (atomic_read(&info->port.count))
51573 return -EBUSY;
51574
51575 if (cmd != SIOCWANDEV)
51576 @@ -2621,7 +2621,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
51577 * do not request bottom half processing if the
51578 * device is not open in a normal mode.
51579 */
51580 - if ( port && (port->port.count || port->netcount) &&
51581 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
51582 port->pending_bh && !port->bh_running &&
51583 !port->bh_requested ) {
51584 if ( debug_level >= DEBUG_LEVEL_ISR )
51585 @@ -3319,12 +3319,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51586
51587 if (debug_level >= DEBUG_LEVEL_INFO)
51588 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
51589 - __FILE__,__LINE__, tty->driver->name, port->count );
51590 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51591
51592 spin_lock_irqsave(&info->lock, flags);
51593 if (!tty_hung_up_p(filp)) {
51594 extra_count = true;
51595 - port->count--;
51596 + atomic_dec(&port->count);
51597 }
51598 spin_unlock_irqrestore(&info->lock, flags);
51599 port->blocked_open++;
51600 @@ -3353,7 +3353,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51601
51602 if (debug_level >= DEBUG_LEVEL_INFO)
51603 printk("%s(%d):%s block_til_ready() count=%d\n",
51604 - __FILE__,__LINE__, tty->driver->name, port->count );
51605 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51606
51607 tty_unlock(tty);
51608 schedule();
51609 @@ -3364,12 +3364,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
51610 remove_wait_queue(&port->open_wait, &wait);
51611
51612 if (extra_count)
51613 - port->count++;
51614 + atomic_inc(&port->count);
51615 port->blocked_open--;
51616
51617 if (debug_level >= DEBUG_LEVEL_INFO)
51618 printk("%s(%d):%s block_til_ready() after, count=%d\n",
51619 - __FILE__,__LINE__, tty->driver->name, port->count );
51620 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
51621
51622 if (!retval)
51623 port->flags |= ASYNC_NORMAL_ACTIVE;
51624 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
51625 index ce396ec..04a37be 100644
51626 --- a/drivers/tty/sysrq.c
51627 +++ b/drivers/tty/sysrq.c
51628 @@ -1075,7 +1075,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
51629 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
51630 size_t count, loff_t *ppos)
51631 {
51632 - if (count) {
51633 + if (count && capable(CAP_SYS_ADMIN)) {
51634 char c;
51635
51636 if (get_user(c, buf))
51637 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
51638 index 3411071..86f2cf2 100644
51639 --- a/drivers/tty/tty_io.c
51640 +++ b/drivers/tty/tty_io.c
51641 @@ -3475,7 +3475,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
51642
51643 void tty_default_fops(struct file_operations *fops)
51644 {
51645 - *fops = tty_fops;
51646 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
51647 }
51648
51649 /*
51650 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
51651 index 2d822aa..a566234 100644
51652 --- a/drivers/tty/tty_ldisc.c
51653 +++ b/drivers/tty/tty_ldisc.c
51654 @@ -71,7 +71,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
51655 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51656 tty_ldiscs[disc] = new_ldisc;
51657 new_ldisc->num = disc;
51658 - new_ldisc->refcount = 0;
51659 + atomic_set(&new_ldisc->refcount, 0);
51660 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
51661
51662 return ret;
51663 @@ -99,7 +99,7 @@ int tty_unregister_ldisc(int disc)
51664 return -EINVAL;
51665
51666 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51667 - if (tty_ldiscs[disc]->refcount)
51668 + if (atomic_read(&tty_ldiscs[disc]->refcount))
51669 ret = -EBUSY;
51670 else
51671 tty_ldiscs[disc] = NULL;
51672 @@ -120,7 +120,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
51673 if (ldops) {
51674 ret = ERR_PTR(-EAGAIN);
51675 if (try_module_get(ldops->owner)) {
51676 - ldops->refcount++;
51677 + atomic_inc(&ldops->refcount);
51678 ret = ldops;
51679 }
51680 }
51681 @@ -133,7 +133,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
51682 unsigned long flags;
51683
51684 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
51685 - ldops->refcount--;
51686 + atomic_dec(&ldops->refcount);
51687 module_put(ldops->owner);
51688 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
51689 }
51690 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
51691 index 3f746c8..2f2fcaa 100644
51692 --- a/drivers/tty/tty_port.c
51693 +++ b/drivers/tty/tty_port.c
51694 @@ -235,7 +235,7 @@ void tty_port_hangup(struct tty_port *port)
51695 unsigned long flags;
51696
51697 spin_lock_irqsave(&port->lock, flags);
51698 - port->count = 0;
51699 + atomic_set(&port->count, 0);
51700 port->flags &= ~ASYNC_NORMAL_ACTIVE;
51701 tty = port->tty;
51702 if (tty)
51703 @@ -393,7 +393,7 @@ int tty_port_block_til_ready(struct tty_port *port,
51704 /* The port lock protects the port counts */
51705 spin_lock_irqsave(&port->lock, flags);
51706 if (!tty_hung_up_p(filp))
51707 - port->count--;
51708 + atomic_dec(&port->count);
51709 port->blocked_open++;
51710 spin_unlock_irqrestore(&port->lock, flags);
51711
51712 @@ -435,7 +435,7 @@ int tty_port_block_til_ready(struct tty_port *port,
51713 we must not mess that up further */
51714 spin_lock_irqsave(&port->lock, flags);
51715 if (!tty_hung_up_p(filp))
51716 - port->count++;
51717 + atomic_inc(&port->count);
51718 port->blocked_open--;
51719 if (retval == 0)
51720 port->flags |= ASYNC_NORMAL_ACTIVE;
51721 @@ -469,19 +469,19 @@ int tty_port_close_start(struct tty_port *port,
51722 return 0;
51723 }
51724
51725 - if (tty->count == 1 && port->count != 1) {
51726 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
51727 printk(KERN_WARNING
51728 "tty_port_close_start: tty->count = 1 port count = %d.\n",
51729 - port->count);
51730 - port->count = 1;
51731 + atomic_read(&port->count));
51732 + atomic_set(&port->count, 1);
51733 }
51734 - if (--port->count < 0) {
51735 + if (atomic_dec_return(&port->count) < 0) {
51736 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
51737 - port->count);
51738 - port->count = 0;
51739 + atomic_read(&port->count));
51740 + atomic_set(&port->count, 0);
51741 }
51742
51743 - if (port->count) {
51744 + if (atomic_read(&port->count)) {
51745 spin_unlock_irqrestore(&port->lock, flags);
51746 return 0;
51747 }
51748 @@ -563,7 +563,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
51749 {
51750 spin_lock_irq(&port->lock);
51751 if (!tty_hung_up_p(filp))
51752 - ++port->count;
51753 + atomic_inc(&port->count);
51754 spin_unlock_irq(&port->lock);
51755 tty_port_tty_set(port, tty);
51756
51757 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
51758 index d0e3a44..5f8b754 100644
51759 --- a/drivers/tty/vt/keyboard.c
51760 +++ b/drivers/tty/vt/keyboard.c
51761 @@ -641,6 +641,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
51762 kbd->kbdmode == VC_OFF) &&
51763 value != KVAL(K_SAK))
51764 return; /* SAK is allowed even in raw mode */
51765 +
51766 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
51767 + {
51768 + void *func = fn_handler[value];
51769 + if (func == fn_show_state || func == fn_show_ptregs ||
51770 + func == fn_show_mem)
51771 + return;
51772 + }
51773 +#endif
51774 +
51775 fn_handler[value](vc);
51776 }
51777
51778 @@ -1776,9 +1786,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
51779 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
51780 return -EFAULT;
51781
51782 - if (!capable(CAP_SYS_TTY_CONFIG))
51783 - perm = 0;
51784 -
51785 switch (cmd) {
51786 case KDGKBENT:
51787 /* Ensure another thread doesn't free it under us */
51788 @@ -1793,6 +1800,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
51789 spin_unlock_irqrestore(&kbd_event_lock, flags);
51790 return put_user(val, &user_kbe->kb_value);
51791 case KDSKBENT:
51792 + if (!capable(CAP_SYS_TTY_CONFIG))
51793 + perm = 0;
51794 +
51795 if (!perm)
51796 return -EPERM;
51797 if (!i && v == K_NOSUCHMAP) {
51798 @@ -1883,9 +1893,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
51799 int i, j, k;
51800 int ret;
51801
51802 - if (!capable(CAP_SYS_TTY_CONFIG))
51803 - perm = 0;
51804 -
51805 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
51806 if (!kbs) {
51807 ret = -ENOMEM;
51808 @@ -1919,6 +1926,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
51809 kfree(kbs);
51810 return ((p && *p) ? -EOVERFLOW : 0);
51811 case KDSKBSENT:
51812 + if (!capable(CAP_SYS_TTY_CONFIG))
51813 + perm = 0;
51814 +
51815 if (!perm) {
51816 ret = -EPERM;
51817 goto reterr;
51818 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
51819 index a673e5b..36e5d32 100644
51820 --- a/drivers/uio/uio.c
51821 +++ b/drivers/uio/uio.c
51822 @@ -25,6 +25,7 @@
51823 #include <linux/kobject.h>
51824 #include <linux/cdev.h>
51825 #include <linux/uio_driver.h>
51826 +#include <asm/local.h>
51827
51828 #define UIO_MAX_DEVICES (1U << MINORBITS)
51829
51830 @@ -32,7 +33,7 @@ struct uio_device {
51831 struct module *owner;
51832 struct device *dev;
51833 int minor;
51834 - atomic_t event;
51835 + atomic_unchecked_t event;
51836 struct fasync_struct *async_queue;
51837 wait_queue_head_t wait;
51838 struct uio_info *info;
51839 @@ -243,7 +244,7 @@ static ssize_t event_show(struct device *dev,
51840 struct device_attribute *attr, char *buf)
51841 {
51842 struct uio_device *idev = dev_get_drvdata(dev);
51843 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
51844 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
51845 }
51846 static DEVICE_ATTR_RO(event);
51847
51848 @@ -405,7 +406,7 @@ void uio_event_notify(struct uio_info *info)
51849 {
51850 struct uio_device *idev = info->uio_dev;
51851
51852 - atomic_inc(&idev->event);
51853 + atomic_inc_unchecked(&idev->event);
51854 wake_up_interruptible(&idev->wait);
51855 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
51856 }
51857 @@ -458,7 +459,7 @@ static int uio_open(struct inode *inode, struct file *filep)
51858 }
51859
51860 listener->dev = idev;
51861 - listener->event_count = atomic_read(&idev->event);
51862 + listener->event_count = atomic_read_unchecked(&idev->event);
51863 filep->private_data = listener;
51864
51865 if (idev->info->open) {
51866 @@ -509,7 +510,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
51867 return -EIO;
51868
51869 poll_wait(filep, &idev->wait, wait);
51870 - if (listener->event_count != atomic_read(&idev->event))
51871 + if (listener->event_count != atomic_read_unchecked(&idev->event))
51872 return POLLIN | POLLRDNORM;
51873 return 0;
51874 }
51875 @@ -534,7 +535,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
51876 do {
51877 set_current_state(TASK_INTERRUPTIBLE);
51878
51879 - event_count = atomic_read(&idev->event);
51880 + event_count = atomic_read_unchecked(&idev->event);
51881 if (event_count != listener->event_count) {
51882 if (copy_to_user(buf, &event_count, count))
51883 retval = -EFAULT;
51884 @@ -591,9 +592,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
51885 static int uio_find_mem_index(struct vm_area_struct *vma)
51886 {
51887 struct uio_device *idev = vma->vm_private_data;
51888 + unsigned long size;
51889
51890 if (vma->vm_pgoff < MAX_UIO_MAPS) {
51891 - if (idev->info->mem[vma->vm_pgoff].size == 0)
51892 + size = idev->info->mem[vma->vm_pgoff].size;
51893 + if (size == 0)
51894 + return -1;
51895 + if (vma->vm_end - vma->vm_start > size)
51896 return -1;
51897 return (int)vma->vm_pgoff;
51898 }
51899 @@ -825,7 +830,7 @@ int __uio_register_device(struct module *owner,
51900 idev->owner = owner;
51901 idev->info = info;
51902 init_waitqueue_head(&idev->wait);
51903 - atomic_set(&idev->event, 0);
51904 + atomic_set_unchecked(&idev->event, 0);
51905
51906 ret = uio_get_minor(idev);
51907 if (ret)
51908 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
51909 index 813d4d3..a71934f 100644
51910 --- a/drivers/usb/atm/cxacru.c
51911 +++ b/drivers/usb/atm/cxacru.c
51912 @@ -472,7 +472,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
51913 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
51914 if (ret < 2)
51915 return -EINVAL;
51916 - if (index < 0 || index > 0x7f)
51917 + if (index > 0x7f)
51918 return -EINVAL;
51919 pos += tmp;
51920
51921 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
51922 index dada014..1d0d517 100644
51923 --- a/drivers/usb/atm/usbatm.c
51924 +++ b/drivers/usb/atm/usbatm.c
51925 @@ -331,7 +331,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51926 if (printk_ratelimit())
51927 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
51928 __func__, vpi, vci);
51929 - atomic_inc(&vcc->stats->rx_err);
51930 + atomic_inc_unchecked(&vcc->stats->rx_err);
51931 return;
51932 }
51933
51934 @@ -358,7 +358,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51935 if (length > ATM_MAX_AAL5_PDU) {
51936 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
51937 __func__, length, vcc);
51938 - atomic_inc(&vcc->stats->rx_err);
51939 + atomic_inc_unchecked(&vcc->stats->rx_err);
51940 goto out;
51941 }
51942
51943 @@ -367,14 +367,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51944 if (sarb->len < pdu_length) {
51945 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
51946 __func__, pdu_length, sarb->len, vcc);
51947 - atomic_inc(&vcc->stats->rx_err);
51948 + atomic_inc_unchecked(&vcc->stats->rx_err);
51949 goto out;
51950 }
51951
51952 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
51953 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
51954 __func__, vcc);
51955 - atomic_inc(&vcc->stats->rx_err);
51956 + atomic_inc_unchecked(&vcc->stats->rx_err);
51957 goto out;
51958 }
51959
51960 @@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51961 if (printk_ratelimit())
51962 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
51963 __func__, length);
51964 - atomic_inc(&vcc->stats->rx_drop);
51965 + atomic_inc_unchecked(&vcc->stats->rx_drop);
51966 goto out;
51967 }
51968
51969 @@ -414,7 +414,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
51970
51971 vcc->push(vcc, skb);
51972
51973 - atomic_inc(&vcc->stats->rx);
51974 + atomic_inc_unchecked(&vcc->stats->rx);
51975 out:
51976 skb_trim(sarb, 0);
51977 }
51978 @@ -612,7 +612,7 @@ static void usbatm_tx_process(unsigned long data)
51979 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
51980
51981 usbatm_pop(vcc, skb);
51982 - atomic_inc(&vcc->stats->tx);
51983 + atomic_inc_unchecked(&vcc->stats->tx);
51984
51985 skb = skb_dequeue(&instance->sndqueue);
51986 }
51987 @@ -756,11 +756,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t *pos, char *page
51988 if (!left--)
51989 return sprintf(page,
51990 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
51991 - atomic_read(&atm_dev->stats.aal5.tx),
51992 - atomic_read(&atm_dev->stats.aal5.tx_err),
51993 - atomic_read(&atm_dev->stats.aal5.rx),
51994 - atomic_read(&atm_dev->stats.aal5.rx_err),
51995 - atomic_read(&atm_dev->stats.aal5.rx_drop));
51996 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
51997 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
51998 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
51999 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
52000 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
52001
52002 if (!left--) {
52003 if (instance->disconnected)
52004 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
52005 index 2a3bbdf..91d72cf 100644
52006 --- a/drivers/usb/core/devices.c
52007 +++ b/drivers/usb/core/devices.c
52008 @@ -126,7 +126,7 @@ static const char format_endpt[] =
52009 * time it gets called.
52010 */
52011 static struct device_connect_event {
52012 - atomic_t count;
52013 + atomic_unchecked_t count;
52014 wait_queue_head_t wait;
52015 } device_event = {
52016 .count = ATOMIC_INIT(1),
52017 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
52018
52019 void usbfs_conn_disc_event(void)
52020 {
52021 - atomic_add(2, &device_event.count);
52022 + atomic_add_unchecked(2, &device_event.count);
52023 wake_up(&device_event.wait);
52024 }
52025
52026 @@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
52027
52028 poll_wait(file, &device_event.wait, wait);
52029
52030 - event_count = atomic_read(&device_event.count);
52031 + event_count = atomic_read_unchecked(&device_event.count);
52032 if (file->f_version != event_count) {
52033 file->f_version = event_count;
52034 return POLLIN | POLLRDNORM;
52035 diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
52036 index 257876e..4304364 100644
52037 --- a/drivers/usb/core/devio.c
52038 +++ b/drivers/usb/core/devio.c
52039 @@ -187,7 +187,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
52040 struct usb_dev_state *ps = file->private_data;
52041 struct usb_device *dev = ps->dev;
52042 ssize_t ret = 0;
52043 - unsigned len;
52044 + size_t len;
52045 loff_t pos;
52046 int i;
52047
52048 @@ -229,22 +229,22 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
52049 for (i = 0; nbytes && i < dev->descriptor.bNumConfigurations; i++) {
52050 struct usb_config_descriptor *config =
52051 (struct usb_config_descriptor *)dev->rawdescriptors[i];
52052 - unsigned int length = le16_to_cpu(config->wTotalLength);
52053 + size_t length = le16_to_cpu(config->wTotalLength);
52054
52055 if (*ppos < pos + length) {
52056
52057 /* The descriptor may claim to be longer than it
52058 * really is. Here is the actual allocated length. */
52059 - unsigned alloclen =
52060 + size_t alloclen =
52061 le16_to_cpu(dev->config[i].desc.wTotalLength);
52062
52063 - len = length - (*ppos - pos);
52064 + len = length + pos - *ppos;
52065 if (len > nbytes)
52066 len = nbytes;
52067
52068 /* Simply don't write (skip over) unallocated parts */
52069 if (alloclen > (*ppos - pos)) {
52070 - alloclen -= (*ppos - pos);
52071 + alloclen = alloclen + pos - *ppos;
52072 if (copy_to_user(buf,
52073 dev->rawdescriptors[i] + (*ppos - pos),
52074 min(len, alloclen))) {
52075 diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
52076 index 9c4e292..b89877f 100644
52077 --- a/drivers/usb/core/hcd.c
52078 +++ b/drivers/usb/core/hcd.c
52079 @@ -1550,7 +1550,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
52080 */
52081 usb_get_urb(urb);
52082 atomic_inc(&urb->use_count);
52083 - atomic_inc(&urb->dev->urbnum);
52084 + atomic_inc_unchecked(&urb->dev->urbnum);
52085 usbmon_urb_submit(&hcd->self, urb);
52086
52087 /* NOTE requirements on root-hub callers (usbfs and the hub
52088 @@ -1577,7 +1577,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
52089 urb->hcpriv = NULL;
52090 INIT_LIST_HEAD(&urb->urb_list);
52091 atomic_dec(&urb->use_count);
52092 - atomic_dec(&urb->dev->urbnum);
52093 + atomic_dec_unchecked(&urb->dev->urbnum);
52094 if (atomic_read(&urb->reject))
52095 wake_up(&usb_kill_urb_queue);
52096 usb_put_urb(urb);
52097 diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
52098 index 229a73f..ef86f98 100644
52099 --- a/drivers/usb/core/hub.c
52100 +++ b/drivers/usb/core/hub.c
52101 @@ -27,6 +27,7 @@
52102 #include <linux/freezer.h>
52103 #include <linux/random.h>
52104 #include <linux/pm_qos.h>
52105 +#include <linux/grsecurity.h>
52106
52107 #include <asm/uaccess.h>
52108 #include <asm/byteorder.h>
52109 @@ -4512,6 +4513,10 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
52110 goto done;
52111 return;
52112 }
52113 +
52114 + if (gr_handle_new_usb())
52115 + goto done;
52116 +
52117 if (hub_is_superspeed(hub->hdev))
52118 unit_load = 150;
52119 else
52120 diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
52121 index 0c8a7fc..c45b40a 100644
52122 --- a/drivers/usb/core/message.c
52123 +++ b/drivers/usb/core/message.c
52124 @@ -128,7 +128,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
52125 * Return: If successful, the number of bytes transferred. Otherwise, a negative
52126 * error number.
52127 */
52128 -int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
52129 +int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
52130 __u8 requesttype, __u16 value, __u16 index, void *data,
52131 __u16 size, int timeout)
52132 {
52133 @@ -180,7 +180,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
52134 * If successful, 0. Otherwise a negative error number. The number of actual
52135 * bytes transferred will be stored in the @actual_length parameter.
52136 */
52137 -int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
52138 +int __intentional_overflow(-1) usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
52139 void *data, int len, int *actual_length, int timeout)
52140 {
52141 return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
52142 @@ -220,7 +220,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
52143 * bytes transferred will be stored in the @actual_length parameter.
52144 *
52145 */
52146 -int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
52147 +int __intentional_overflow(-1) usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
52148 void *data, int len, int *actual_length, int timeout)
52149 {
52150 struct urb *urb;
52151 diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
52152 index 1236c60..d47a51c 100644
52153 --- a/drivers/usb/core/sysfs.c
52154 +++ b/drivers/usb/core/sysfs.c
52155 @@ -244,7 +244,7 @@ static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr,
52156 struct usb_device *udev;
52157
52158 udev = to_usb_device(dev);
52159 - return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
52160 + return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
52161 }
52162 static DEVICE_ATTR_RO(urbnum);
52163
52164 diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
52165 index 4d11449..f4ccabf 100644
52166 --- a/drivers/usb/core/usb.c
52167 +++ b/drivers/usb/core/usb.c
52168 @@ -433,7 +433,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
52169 set_dev_node(&dev->dev, dev_to_node(bus->controller));
52170 dev->state = USB_STATE_ATTACHED;
52171 dev->lpm_disable_count = 1;
52172 - atomic_set(&dev->urbnum, 0);
52173 + atomic_set_unchecked(&dev->urbnum, 0);
52174
52175 INIT_LIST_HEAD(&dev->ep0.urb_list);
52176 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
52177 diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
52178 index 85f398d..d375bbe 100644
52179 --- a/drivers/usb/dwc3/gadget.c
52180 +++ b/drivers/usb/dwc3/gadget.c
52181 @@ -550,8 +550,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
52182 if (!usb_endpoint_xfer_isoc(desc))
52183 return 0;
52184
52185 - memset(&trb_link, 0, sizeof(trb_link));
52186 -
52187 /* Link TRB for ISOC. The HWO bit is never reset */
52188 trb_st_hw = &dep->trb_pool[0];
52189
52190 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
52191 index 8cfc319..4868255 100644
52192 --- a/drivers/usb/early/ehci-dbgp.c
52193 +++ b/drivers/usb/early/ehci-dbgp.c
52194 @@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
52195
52196 #ifdef CONFIG_KGDB
52197 static struct kgdb_io kgdbdbgp_io_ops;
52198 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
52199 +static struct kgdb_io kgdbdbgp_io_ops_console;
52200 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
52201 #else
52202 #define dbgp_kgdb_mode (0)
52203 #endif
52204 @@ -1043,6 +1044,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
52205 .write_char = kgdbdbgp_write_char,
52206 };
52207
52208 +static struct kgdb_io kgdbdbgp_io_ops_console = {
52209 + .name = "kgdbdbgp",
52210 + .read_char = kgdbdbgp_read_char,
52211 + .write_char = kgdbdbgp_write_char,
52212 + .is_console = 1
52213 +};
52214 +
52215 static int kgdbdbgp_wait_time;
52216
52217 static int __init kgdbdbgp_parse_config(char *str)
52218 @@ -1058,8 +1066,10 @@ static int __init kgdbdbgp_parse_config(char *str)
52219 ptr++;
52220 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
52221 }
52222 - kgdb_register_io_module(&kgdbdbgp_io_ops);
52223 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
52224 + if (early_dbgp_console.index != -1)
52225 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
52226 + else
52227 + kgdb_register_io_module(&kgdbdbgp_io_ops);
52228
52229 return 0;
52230 }
52231 diff --git a/drivers/usb/gadget/f_uac1.c b/drivers/usb/gadget/f_uac1.c
52232 index 2b4c82d..06a8ee6 100644
52233 --- a/drivers/usb/gadget/f_uac1.c
52234 +++ b/drivers/usb/gadget/f_uac1.c
52235 @@ -13,6 +13,7 @@
52236 #include <linux/kernel.h>
52237 #include <linux/device.h>
52238 #include <linux/atomic.h>
52239 +#include <linux/module.h>
52240
52241 #include "u_uac1.h"
52242
52243 diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
52244 index ad0aca8..8ff84865 100644
52245 --- a/drivers/usb/gadget/u_serial.c
52246 +++ b/drivers/usb/gadget/u_serial.c
52247 @@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
52248 spin_lock_irq(&port->port_lock);
52249
52250 /* already open? Great. */
52251 - if (port->port.count) {
52252 + if (atomic_read(&port->port.count)) {
52253 status = 0;
52254 - port->port.count++;
52255 + atomic_inc(&port->port.count);
52256
52257 /* currently opening/closing? wait ... */
52258 } else if (port->openclose) {
52259 @@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
52260 tty->driver_data = port;
52261 port->port.tty = tty;
52262
52263 - port->port.count = 1;
52264 + atomic_set(&port->port.count, 1);
52265 port->openclose = false;
52266
52267 /* if connected, start the I/O stream */
52268 @@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
52269
52270 spin_lock_irq(&port->port_lock);
52271
52272 - if (port->port.count != 1) {
52273 - if (port->port.count == 0)
52274 + if (atomic_read(&port->port.count) != 1) {
52275 + if (atomic_read(&port->port.count) == 0)
52276 WARN_ON(1);
52277 else
52278 - --port->port.count;
52279 + atomic_dec(&port->port.count);
52280 goto exit;
52281 }
52282
52283 @@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
52284 * and sleep if necessary
52285 */
52286 port->openclose = true;
52287 - port->port.count = 0;
52288 + atomic_set(&port->port.count, 0);
52289
52290 gser = port->port_usb;
52291 if (gser && gser->disconnect)
52292 @@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
52293 int cond;
52294
52295 spin_lock_irq(&port->port_lock);
52296 - cond = (port->port.count == 0) && !port->openclose;
52297 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
52298 spin_unlock_irq(&port->port_lock);
52299 return cond;
52300 }
52301 @@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
52302 /* if it's already open, start I/O ... and notify the serial
52303 * protocol about open/close status (connect/disconnect).
52304 */
52305 - if (port->port.count) {
52306 + if (atomic_read(&port->port.count)) {
52307 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
52308 gs_start_io(port);
52309 if (gser->connect)
52310 @@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
52311
52312 port->port_usb = NULL;
52313 gser->ioport = NULL;
52314 - if (port->port.count > 0 || port->openclose) {
52315 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
52316 wake_up_interruptible(&port->drain_wait);
52317 if (port->port.tty)
52318 tty_hangup(port->port.tty);
52319 @@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
52320
52321 /* finally, free any unused/unusable I/O buffers */
52322 spin_lock_irqsave(&port->port_lock, flags);
52323 - if (port->port.count == 0 && !port->openclose)
52324 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
52325 gs_buf_free(&port->port_write_buf);
52326 gs_free_requests(gser->out, &port->read_pool, NULL);
52327 gs_free_requests(gser->out, &port->read_queue, NULL);
52328 diff --git a/drivers/usb/gadget/u_uac1.c b/drivers/usb/gadget/u_uac1.c
52329 index 7a55fea..cc0ed4f 100644
52330 --- a/drivers/usb/gadget/u_uac1.c
52331 +++ b/drivers/usb/gadget/u_uac1.c
52332 @@ -16,6 +16,7 @@
52333 #include <linux/ctype.h>
52334 #include <linux/random.h>
52335 #include <linux/syscalls.h>
52336 +#include <linux/module.h>
52337
52338 #include "u_uac1.h"
52339
52340 diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
52341 index 7ae0c4d..35521b7 100644
52342 --- a/drivers/usb/host/ehci-hub.c
52343 +++ b/drivers/usb/host/ehci-hub.c
52344 @@ -780,7 +780,7 @@ static struct urb *request_single_step_set_feature_urb(
52345 urb->transfer_flags = URB_DIR_IN;
52346 usb_get_urb(urb);
52347 atomic_inc(&urb->use_count);
52348 - atomic_inc(&urb->dev->urbnum);
52349 + atomic_inc_unchecked(&urb->dev->urbnum);
52350 urb->setup_dma = dma_map_single(
52351 hcd->self.controller,
52352 urb->setup_packet,
52353 @@ -847,7 +847,7 @@ static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
52354 urb->status = -EINPROGRESS;
52355 usb_get_urb(urb);
52356 atomic_inc(&urb->use_count);
52357 - atomic_inc(&urb->dev->urbnum);
52358 + atomic_inc_unchecked(&urb->dev->urbnum);
52359 retval = submit_single_step_set_feature(hcd, urb, 0);
52360 if (!retval && !wait_for_completion_timeout(&done,
52361 msecs_to_jiffies(2000))) {
52362 diff --git a/drivers/usb/host/hwa-hc.c b/drivers/usb/host/hwa-hc.c
52363 index d0d8fad..668ef7b 100644
52364 --- a/drivers/usb/host/hwa-hc.c
52365 +++ b/drivers/usb/host/hwa-hc.c
52366 @@ -337,7 +337,10 @@ static int __hwahc_op_bwa_set(struct wusbhc *wusbhc, s8 stream_index,
52367 struct hwahc *hwahc = container_of(wusbhc, struct hwahc, wusbhc);
52368 struct wahc *wa = &hwahc->wa;
52369 struct device *dev = &wa->usb_iface->dev;
52370 - u8 mas_le[UWB_NUM_MAS/8];
52371 + u8 *mas_le = kmalloc(UWB_NUM_MAS/8, GFP_KERNEL);
52372 +
52373 + if (mas_le == NULL)
52374 + return -ENOMEM;
52375
52376 /* Set the stream index */
52377 result = usb_control_msg(wa->usb_dev, usb_sndctrlpipe(wa->usb_dev, 0),
52378 @@ -356,10 +359,12 @@ static int __hwahc_op_bwa_set(struct wusbhc *wusbhc, s8 stream_index,
52379 WUSB_REQ_SET_WUSB_MAS,
52380 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
52381 0, wa->usb_iface->cur_altsetting->desc.bInterfaceNumber,
52382 - mas_le, 32, USB_CTRL_SET_TIMEOUT);
52383 + mas_le, UWB_NUM_MAS/8, USB_CTRL_SET_TIMEOUT);
52384 if (result < 0)
52385 dev_err(dev, "Cannot set WUSB MAS allocation: %d\n", result);
52386 out:
52387 + kfree(mas_le);
52388 +
52389 return result;
52390 }
52391
52392 diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
52393 index ba6a5d6..f88f7f3 100644
52394 --- a/drivers/usb/misc/appledisplay.c
52395 +++ b/drivers/usb/misc/appledisplay.c
52396 @@ -83,7 +83,7 @@ struct appledisplay {
52397 spinlock_t lock;
52398 };
52399
52400 -static atomic_t count_displays = ATOMIC_INIT(0);
52401 +static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
52402 static struct workqueue_struct *wq;
52403
52404 static void appledisplay_complete(struct urb *urb)
52405 @@ -281,7 +281,7 @@ static int appledisplay_probe(struct usb_interface *iface,
52406
52407 /* Register backlight device */
52408 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
52409 - atomic_inc_return(&count_displays) - 1);
52410 + atomic_inc_return_unchecked(&count_displays) - 1);
52411 memset(&props, 0, sizeof(struct backlight_properties));
52412 props.type = BACKLIGHT_RAW;
52413 props.max_brightness = 0xff;
52414 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
52415 index 8d7fc48..01c4986 100644
52416 --- a/drivers/usb/serial/console.c
52417 +++ b/drivers/usb/serial/console.c
52418 @@ -123,7 +123,7 @@ static int usb_console_setup(struct console *co, char *options)
52419
52420 info->port = port;
52421
52422 - ++port->port.count;
52423 + atomic_inc(&port->port.count);
52424 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
52425 if (serial->type->set_termios) {
52426 /*
52427 @@ -167,7 +167,7 @@ static int usb_console_setup(struct console *co, char *options)
52428 }
52429 /* Now that any required fake tty operations are completed restore
52430 * the tty port count */
52431 - --port->port.count;
52432 + atomic_dec(&port->port.count);
52433 /* The console is special in terms of closing the device so
52434 * indicate this port is now acting as a system console. */
52435 port->port.console = 1;
52436 @@ -180,7 +180,7 @@ static int usb_console_setup(struct console *co, char *options)
52437 free_tty:
52438 kfree(tty);
52439 reset_open_count:
52440 - port->port.count = 0;
52441 + atomic_set(&port->port.count, 0);
52442 usb_autopm_put_interface(serial->interface);
52443 error_get_interface:
52444 usb_serial_put(serial);
52445 @@ -191,7 +191,7 @@ static int usb_console_setup(struct console *co, char *options)
52446 static void usb_console_write(struct console *co,
52447 const char *buf, unsigned count)
52448 {
52449 - static struct usbcons_info *info = &usbcons_info;
52450 + struct usbcons_info *info = &usbcons_info;
52451 struct usb_serial_port *port = info->port;
52452 struct usb_serial *serial;
52453 int retval = -ENODEV;
52454 diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
52455 index 307e339..6aa97cb 100644
52456 --- a/drivers/usb/storage/usb.h
52457 +++ b/drivers/usb/storage/usb.h
52458 @@ -63,7 +63,7 @@ struct us_unusual_dev {
52459 __u8 useProtocol;
52460 __u8 useTransport;
52461 int (*initFunction)(struct us_data *);
52462 -};
52463 +} __do_const;
52464
52465
52466 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
52467 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
52468 index f2a8d29..7bc3fe7 100644
52469 --- a/drivers/usb/wusbcore/wa-hc.h
52470 +++ b/drivers/usb/wusbcore/wa-hc.h
52471 @@ -240,7 +240,7 @@ struct wahc {
52472 spinlock_t xfer_list_lock;
52473 struct work_struct xfer_enqueue_work;
52474 struct work_struct xfer_error_work;
52475 - atomic_t xfer_id_count;
52476 + atomic_unchecked_t xfer_id_count;
52477
52478 kernel_ulong_t quirks;
52479 };
52480 @@ -305,7 +305,7 @@ static inline void wa_init(struct wahc *wa)
52481 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
52482 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
52483 wa->dto_in_use = 0;
52484 - atomic_set(&wa->xfer_id_count, 1);
52485 + atomic_set_unchecked(&wa->xfer_id_count, 1);
52486 /* init the buf in URBs */
52487 for (index = 0; index < WA_MAX_BUF_IN_URBS; ++index)
52488 usb_init_urb(&(wa->buf_in_urbs[index]));
52489 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
52490 index 3e2e4ed..060c9b8 100644
52491 --- a/drivers/usb/wusbcore/wa-xfer.c
52492 +++ b/drivers/usb/wusbcore/wa-xfer.c
52493 @@ -314,7 +314,7 @@ static void wa_xfer_completion(struct wa_xfer *xfer)
52494 */
52495 static void wa_xfer_id_init(struct wa_xfer *xfer)
52496 {
52497 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
52498 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
52499 }
52500
52501 /* Return the xfer's ID. */
52502 diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
52503 index 512f479..7e041d0 100644
52504 --- a/drivers/vfio/vfio.c
52505 +++ b/drivers/vfio/vfio.c
52506 @@ -487,7 +487,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
52507 return 0;
52508
52509 /* TODO Prevent device auto probing */
52510 - WARN("Device %s added to live group %d!\n", dev_name(dev),
52511 + WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
52512 iommu_group_id(group->iommu_group));
52513
52514 return 0;
52515 diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
52516 index 5174eba..451e6bc 100644
52517 --- a/drivers/vhost/vringh.c
52518 +++ b/drivers/vhost/vringh.c
52519 @@ -530,17 +530,17 @@ static inline void __vringh_notify_disable(struct vringh *vrh,
52520 /* Userspace access helpers: in this case, addresses are really userspace. */
52521 static inline int getu16_user(u16 *val, const u16 *p)
52522 {
52523 - return get_user(*val, (__force u16 __user *)p);
52524 + return get_user(*val, (u16 __force_user *)p);
52525 }
52526
52527 static inline int putu16_user(u16 *p, u16 val)
52528 {
52529 - return put_user(val, (__force u16 __user *)p);
52530 + return put_user(val, (u16 __force_user *)p);
52531 }
52532
52533 static inline int copydesc_user(void *dst, const void *src, size_t len)
52534 {
52535 - return copy_from_user(dst, (__force void __user *)src, len) ?
52536 + return copy_from_user(dst, (void __force_user *)src, len) ?
52537 -EFAULT : 0;
52538 }
52539
52540 @@ -548,19 +548,19 @@ static inline int putused_user(struct vring_used_elem *dst,
52541 const struct vring_used_elem *src,
52542 unsigned int num)
52543 {
52544 - return copy_to_user((__force void __user *)dst, src,
52545 + return copy_to_user((void __force_user *)dst, src,
52546 sizeof(*dst) * num) ? -EFAULT : 0;
52547 }
52548
52549 static inline int xfer_from_user(void *src, void *dst, size_t len)
52550 {
52551 - return copy_from_user(dst, (__force void __user *)src, len) ?
52552 + return copy_from_user(dst, (void __force_user *)src, len) ?
52553 -EFAULT : 0;
52554 }
52555
52556 static inline int xfer_to_user(void *dst, void *src, size_t len)
52557 {
52558 - return copy_to_user((__force void __user *)dst, src, len) ?
52559 + return copy_to_user((void __force_user *)dst, src, len) ?
52560 -EFAULT : 0;
52561 }
52562
52563 @@ -596,9 +596,9 @@ int vringh_init_user(struct vringh *vrh, u32 features,
52564 vrh->last_used_idx = 0;
52565 vrh->vring.num = num;
52566 /* vring expects kernel addresses, but only used via accessors. */
52567 - vrh->vring.desc = (__force struct vring_desc *)desc;
52568 - vrh->vring.avail = (__force struct vring_avail *)avail;
52569 - vrh->vring.used = (__force struct vring_used *)used;
52570 + vrh->vring.desc = (__force_kernel struct vring_desc *)desc;
52571 + vrh->vring.avail = (__force_kernel struct vring_avail *)avail;
52572 + vrh->vring.used = (__force_kernel struct vring_used *)used;
52573 return 0;
52574 }
52575 EXPORT_SYMBOL(vringh_init_user);
52576 @@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
52577
52578 static inline int putu16_kern(u16 *p, u16 val)
52579 {
52580 - ACCESS_ONCE(*p) = val;
52581 + ACCESS_ONCE_RW(*p) = val;
52582 return 0;
52583 }
52584
52585 diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
52586 index 84a110a..96312c3 100644
52587 --- a/drivers/video/backlight/kb3886_bl.c
52588 +++ b/drivers/video/backlight/kb3886_bl.c
52589 @@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
52590 static unsigned long kb3886bl_flags;
52591 #define KB3886BL_SUSPENDED 0x01
52592
52593 -static struct dmi_system_id kb3886bl_device_table[] __initdata = {
52594 +static const struct dmi_system_id kb3886bl_device_table[] __initconst = {
52595 {
52596 .ident = "Sahara Touch-iT",
52597 .matches = {
52598 diff --git a/drivers/video/fbdev/arcfb.c b/drivers/video/fbdev/arcfb.c
52599 index 1b0b233..6f34c2c 100644
52600 --- a/drivers/video/fbdev/arcfb.c
52601 +++ b/drivers/video/fbdev/arcfb.c
52602 @@ -458,7 +458,7 @@ static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
52603 return -ENOSPC;
52604
52605 err = 0;
52606 - if ((count + p) > fbmemlength) {
52607 + if (count > (fbmemlength - p)) {
52608 count = fbmemlength - p;
52609 err = -ENOSPC;
52610 }
52611 diff --git a/drivers/video/fbdev/aty/aty128fb.c b/drivers/video/fbdev/aty/aty128fb.c
52612 index 52108be..c7c110d 100644
52613 --- a/drivers/video/fbdev/aty/aty128fb.c
52614 +++ b/drivers/video/fbdev/aty/aty128fb.c
52615 @@ -149,7 +149,7 @@ enum {
52616 };
52617
52618 /* Must match above enum */
52619 -static char * const r128_family[] = {
52620 +static const char * const r128_family[] = {
52621 "AGP",
52622 "PCI",
52623 "PRO AGP",
52624 diff --git a/drivers/video/fbdev/aty/atyfb_base.c b/drivers/video/fbdev/aty/atyfb_base.c
52625 index c3d0074..0b9077e 100644
52626 --- a/drivers/video/fbdev/aty/atyfb_base.c
52627 +++ b/drivers/video/fbdev/aty/atyfb_base.c
52628 @@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
52629 par->accel_flags = var->accel_flags; /* hack */
52630
52631 if (var->accel_flags) {
52632 - info->fbops->fb_sync = atyfb_sync;
52633 + pax_open_kernel();
52634 + *(void **)&info->fbops->fb_sync = atyfb_sync;
52635 + pax_close_kernel();
52636 info->flags &= ~FBINFO_HWACCEL_DISABLED;
52637 } else {
52638 - info->fbops->fb_sync = NULL;
52639 + pax_open_kernel();
52640 + *(void **)&info->fbops->fb_sync = NULL;
52641 + pax_close_kernel();
52642 info->flags |= FBINFO_HWACCEL_DISABLED;
52643 }
52644
52645 diff --git a/drivers/video/fbdev/aty/mach64_cursor.c b/drivers/video/fbdev/aty/mach64_cursor.c
52646 index 2fa0317..4983f2a 100644
52647 --- a/drivers/video/fbdev/aty/mach64_cursor.c
52648 +++ b/drivers/video/fbdev/aty/mach64_cursor.c
52649 @@ -8,6 +8,7 @@
52650 #include "../core/fb_draw.h"
52651
52652 #include <asm/io.h>
52653 +#include <asm/pgtable.h>
52654
52655 #ifdef __sparc__
52656 #include <asm/fbio.h>
52657 @@ -218,7 +219,9 @@ int aty_init_cursor(struct fb_info *info)
52658 info->sprite.buf_align = 16; /* and 64 lines tall. */
52659 info->sprite.flags = FB_PIXMAP_IO;
52660
52661 - info->fbops->fb_cursor = atyfb_cursor;
52662 + pax_open_kernel();
52663 + *(void **)&info->fbops->fb_cursor = atyfb_cursor;
52664 + pax_close_kernel();
52665
52666 return 0;
52667 }
52668 diff --git a/drivers/video/fbdev/core/fb_defio.c b/drivers/video/fbdev/core/fb_defio.c
52669 index 900aa4e..6d49418 100644
52670 --- a/drivers/video/fbdev/core/fb_defio.c
52671 +++ b/drivers/video/fbdev/core/fb_defio.c
52672 @@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
52673
52674 BUG_ON(!fbdefio);
52675 mutex_init(&fbdefio->lock);
52676 - info->fbops->fb_mmap = fb_deferred_io_mmap;
52677 + pax_open_kernel();
52678 + *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
52679 + pax_close_kernel();
52680 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
52681 INIT_LIST_HEAD(&fbdefio->pagelist);
52682 if (fbdefio->delay == 0) /* set a default of 1 s */
52683 @@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
52684 page->mapping = NULL;
52685 }
52686
52687 - info->fbops->fb_mmap = NULL;
52688 + *(void **)&info->fbops->fb_mmap = NULL;
52689 mutex_destroy(&fbdefio->lock);
52690 }
52691 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
52692 diff --git a/drivers/video/fbdev/core/fbmem.c b/drivers/video/fbdev/core/fbmem.c
52693 index b6d5008..5bca7bf 100644
52694 --- a/drivers/video/fbdev/core/fbmem.c
52695 +++ b/drivers/video/fbdev/core/fbmem.c
52696 @@ -433,7 +433,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
52697 image->dx += image->width + 8;
52698 }
52699 } else if (rotate == FB_ROTATE_UD) {
52700 - for (x = 0; x < num && image->dx >= 0; x++) {
52701 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
52702 info->fbops->fb_imageblit(info, image);
52703 image->dx -= image->width + 8;
52704 }
52705 @@ -445,7 +445,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
52706 image->dy += image->height + 8;
52707 }
52708 } else if (rotate == FB_ROTATE_CCW) {
52709 - for (x = 0; x < num && image->dy >= 0; x++) {
52710 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
52711 info->fbops->fb_imageblit(info, image);
52712 image->dy -= image->height + 8;
52713 }
52714 @@ -1179,7 +1179,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
52715 return -EFAULT;
52716 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
52717 return -EINVAL;
52718 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
52719 + if (con2fb.framebuffer >= FB_MAX)
52720 return -EINVAL;
52721 if (!registered_fb[con2fb.framebuffer])
52722 request_module("fb%d", con2fb.framebuffer);
52723 @@ -1300,7 +1300,7 @@ static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix,
52724 __u32 data;
52725 int err;
52726
52727 - err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id));
52728 + err = copy_to_user(fix32->id, &fix->id, sizeof(fix32->id));
52729
52730 data = (__u32) (unsigned long) fix->smem_start;
52731 err |= put_user(data, &fix32->smem_start);
52732 diff --git a/drivers/video/fbdev/hyperv_fb.c b/drivers/video/fbdev/hyperv_fb.c
52733 index e23392e..8a77540 100644
52734 --- a/drivers/video/fbdev/hyperv_fb.c
52735 +++ b/drivers/video/fbdev/hyperv_fb.c
52736 @@ -235,7 +235,7 @@ static uint screen_fb_size;
52737 static inline int synthvid_send(struct hv_device *hdev,
52738 struct synthvid_msg *msg)
52739 {
52740 - static atomic64_t request_id = ATOMIC64_INIT(0);
52741 + static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
52742 int ret;
52743
52744 msg->pipe_hdr.type = PIPE_MSG_DATA;
52745 @@ -243,7 +243,7 @@ static inline int synthvid_send(struct hv_device *hdev,
52746
52747 ret = vmbus_sendpacket(hdev->channel, msg,
52748 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
52749 - atomic64_inc_return(&request_id),
52750 + atomic64_inc_return_unchecked(&request_id),
52751 VM_PKT_DATA_INBAND, 0);
52752
52753 if (ret)
52754 diff --git a/drivers/video/fbdev/i810/i810_accel.c b/drivers/video/fbdev/i810/i810_accel.c
52755 index 7672d2e..b56437f 100644
52756 --- a/drivers/video/fbdev/i810/i810_accel.c
52757 +++ b/drivers/video/fbdev/i810/i810_accel.c
52758 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
52759 }
52760 }
52761 printk("ringbuffer lockup!!!\n");
52762 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
52763 i810_report_error(mmio);
52764 par->dev_flags |= LOCKUP;
52765 info->pixmap.scan_align = 1;
52766 diff --git a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
52767 index a01147f..5d896f8 100644
52768 --- a/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
52769 +++ b/drivers/video/fbdev/matrox/matroxfb_DAC1064.c
52770 @@ -1088,14 +1088,20 @@ static void MGAG100_restore(struct matrox_fb_info *minfo)
52771
52772 #ifdef CONFIG_FB_MATROX_MYSTIQUE
52773 struct matrox_switch matrox_mystique = {
52774 - MGA1064_preinit, MGA1064_reset, MGA1064_init, MGA1064_restore,
52775 + .preinit = MGA1064_preinit,
52776 + .reset = MGA1064_reset,
52777 + .init = MGA1064_init,
52778 + .restore = MGA1064_restore,
52779 };
52780 EXPORT_SYMBOL(matrox_mystique);
52781 #endif
52782
52783 #ifdef CONFIG_FB_MATROX_G
52784 struct matrox_switch matrox_G100 = {
52785 - MGAG100_preinit, MGAG100_reset, MGAG100_init, MGAG100_restore,
52786 + .preinit = MGAG100_preinit,
52787 + .reset = MGAG100_reset,
52788 + .init = MGAG100_init,
52789 + .restore = MGAG100_restore,
52790 };
52791 EXPORT_SYMBOL(matrox_G100);
52792 #endif
52793 diff --git a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
52794 index 195ad7c..09743fc 100644
52795 --- a/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
52796 +++ b/drivers/video/fbdev/matrox/matroxfb_Ti3026.c
52797 @@ -738,7 +738,10 @@ static int Ti3026_preinit(struct matrox_fb_info *minfo)
52798 }
52799
52800 struct matrox_switch matrox_millennium = {
52801 - Ti3026_preinit, Ti3026_reset, Ti3026_init, Ti3026_restore
52802 + .preinit = Ti3026_preinit,
52803 + .reset = Ti3026_reset,
52804 + .init = Ti3026_init,
52805 + .restore = Ti3026_restore
52806 };
52807 EXPORT_SYMBOL(matrox_millennium);
52808 #endif
52809 diff --git a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
52810 index fe92eed..106e085 100644
52811 --- a/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
52812 +++ b/drivers/video/fbdev/mb862xx/mb862xxfb_accel.c
52813 @@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
52814 struct mb862xxfb_par *par = info->par;
52815
52816 if (info->var.bits_per_pixel == 32) {
52817 - info->fbops->fb_fillrect = cfb_fillrect;
52818 - info->fbops->fb_copyarea = cfb_copyarea;
52819 - info->fbops->fb_imageblit = cfb_imageblit;
52820 + pax_open_kernel();
52821 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
52822 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
52823 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
52824 + pax_close_kernel();
52825 } else {
52826 outreg(disp, GC_L0EM, 3);
52827 - info->fbops->fb_fillrect = mb86290fb_fillrect;
52828 - info->fbops->fb_copyarea = mb86290fb_copyarea;
52829 - info->fbops->fb_imageblit = mb86290fb_imageblit;
52830 + pax_open_kernel();
52831 + *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
52832 + *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
52833 + *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
52834 + pax_close_kernel();
52835 }
52836 outreg(draw, GDC_REG_DRAW_BASE, 0);
52837 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
52838 diff --git a/drivers/video/fbdev/nvidia/nvidia.c b/drivers/video/fbdev/nvidia/nvidia.c
52839 index def0412..fed6529 100644
52840 --- a/drivers/video/fbdev/nvidia/nvidia.c
52841 +++ b/drivers/video/fbdev/nvidia/nvidia.c
52842 @@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
52843 info->fix.line_length = (info->var.xres_virtual *
52844 info->var.bits_per_pixel) >> 3;
52845 if (info->var.accel_flags) {
52846 - info->fbops->fb_imageblit = nvidiafb_imageblit;
52847 - info->fbops->fb_fillrect = nvidiafb_fillrect;
52848 - info->fbops->fb_copyarea = nvidiafb_copyarea;
52849 - info->fbops->fb_sync = nvidiafb_sync;
52850 + pax_open_kernel();
52851 + *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
52852 + *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
52853 + *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
52854 + *(void **)&info->fbops->fb_sync = nvidiafb_sync;
52855 + pax_close_kernel();
52856 info->pixmap.scan_align = 4;
52857 info->flags &= ~FBINFO_HWACCEL_DISABLED;
52858 info->flags |= FBINFO_READS_FAST;
52859 NVResetGraphics(info);
52860 } else {
52861 - info->fbops->fb_imageblit = cfb_imageblit;
52862 - info->fbops->fb_fillrect = cfb_fillrect;
52863 - info->fbops->fb_copyarea = cfb_copyarea;
52864 - info->fbops->fb_sync = NULL;
52865 + pax_open_kernel();
52866 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
52867 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
52868 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
52869 + *(void **)&info->fbops->fb_sync = NULL;
52870 + pax_close_kernel();
52871 info->pixmap.scan_align = 1;
52872 info->flags |= FBINFO_HWACCEL_DISABLED;
52873 info->flags &= ~FBINFO_READS_FAST;
52874 @@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
52875 info->pixmap.size = 8 * 1024;
52876 info->pixmap.flags = FB_PIXMAP_SYSTEM;
52877
52878 - if (!hwcur)
52879 - info->fbops->fb_cursor = NULL;
52880 + if (!hwcur) {
52881 + pax_open_kernel();
52882 + *(void **)&info->fbops->fb_cursor = NULL;
52883 + pax_close_kernel();
52884 + }
52885
52886 info->var.accel_flags = (!noaccel);
52887
52888 diff --git a/drivers/video/fbdev/omap2/dss/display.c b/drivers/video/fbdev/omap2/dss/display.c
52889 index 2412a0d..294215b 100644
52890 --- a/drivers/video/fbdev/omap2/dss/display.c
52891 +++ b/drivers/video/fbdev/omap2/dss/display.c
52892 @@ -161,12 +161,14 @@ int omapdss_register_display(struct omap_dss_device *dssdev)
52893 if (dssdev->name == NULL)
52894 dssdev->name = dssdev->alias;
52895
52896 + pax_open_kernel();
52897 if (drv && drv->get_resolution == NULL)
52898 - drv->get_resolution = omapdss_default_get_resolution;
52899 + *(void **)&drv->get_resolution = omapdss_default_get_resolution;
52900 if (drv && drv->get_recommended_bpp == NULL)
52901 - drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
52902 + *(void **)&drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
52903 if (drv && drv->get_timings == NULL)
52904 - drv->get_timings = omapdss_default_get_timings;
52905 + *(void **)&drv->get_timings = omapdss_default_get_timings;
52906 + pax_close_kernel();
52907
52908 mutex_lock(&panel_list_mutex);
52909 list_add_tail(&dssdev->panel_list, &panel_list);
52910 diff --git a/drivers/video/fbdev/s1d13xxxfb.c b/drivers/video/fbdev/s1d13xxxfb.c
52911 index 83433cb..71e9b98 100644
52912 --- a/drivers/video/fbdev/s1d13xxxfb.c
52913 +++ b/drivers/video/fbdev/s1d13xxxfb.c
52914 @@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
52915
52916 switch(prod_id) {
52917 case S1D13506_PROD_ID: /* activate acceleration */
52918 - s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
52919 - s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
52920 + pax_open_kernel();
52921 + *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
52922 + *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
52923 + pax_close_kernel();
52924 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
52925 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
52926 break;
52927 diff --git a/drivers/video/fbdev/sh_mobile_lcdcfb.c b/drivers/video/fbdev/sh_mobile_lcdcfb.c
52928 index 2bcc84a..29dd1ea 100644
52929 --- a/drivers/video/fbdev/sh_mobile_lcdcfb.c
52930 +++ b/drivers/video/fbdev/sh_mobile_lcdcfb.c
52931 @@ -439,9 +439,9 @@ static unsigned long lcdc_sys_read_data(void *handle)
52932 }
52933
52934 static struct sh_mobile_lcdc_sys_bus_ops sh_mobile_lcdc_sys_bus_ops = {
52935 - lcdc_sys_write_index,
52936 - lcdc_sys_write_data,
52937 - lcdc_sys_read_data,
52938 + .write_index = lcdc_sys_write_index,
52939 + .write_data = lcdc_sys_write_data,
52940 + .read_data = lcdc_sys_read_data,
52941 };
52942
52943 static int sh_mobile_lcdc_sginit(struct fb_info *info,
52944 diff --git a/drivers/video/fbdev/smscufx.c b/drivers/video/fbdev/smscufx.c
52945 index d513ed6..90b0de9 100644
52946 --- a/drivers/video/fbdev/smscufx.c
52947 +++ b/drivers/video/fbdev/smscufx.c
52948 @@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
52949 fb_deferred_io_cleanup(info);
52950 kfree(info->fbdefio);
52951 info->fbdefio = NULL;
52952 - info->fbops->fb_mmap = ufx_ops_mmap;
52953 + pax_open_kernel();
52954 + *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
52955 + pax_close_kernel();
52956 }
52957
52958 pr_debug("released /dev/fb%d user=%d count=%d",
52959 diff --git a/drivers/video/fbdev/udlfb.c b/drivers/video/fbdev/udlfb.c
52960 index 77b890e..458e666 100644
52961 --- a/drivers/video/fbdev/udlfb.c
52962 +++ b/drivers/video/fbdev/udlfb.c
52963 @@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
52964 dlfb_urb_completion(urb);
52965
52966 error:
52967 - atomic_add(bytes_sent, &dev->bytes_sent);
52968 - atomic_add(bytes_identical, &dev->bytes_identical);
52969 - atomic_add(width*height*2, &dev->bytes_rendered);
52970 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
52971 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
52972 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
52973 end_cycles = get_cycles();
52974 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
52975 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
52976 >> 10)), /* Kcycles */
52977 &dev->cpu_kcycles_used);
52978
52979 @@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
52980 dlfb_urb_completion(urb);
52981
52982 error:
52983 - atomic_add(bytes_sent, &dev->bytes_sent);
52984 - atomic_add(bytes_identical, &dev->bytes_identical);
52985 - atomic_add(bytes_rendered, &dev->bytes_rendered);
52986 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
52987 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
52988 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
52989 end_cycles = get_cycles();
52990 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
52991 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
52992 >> 10)), /* Kcycles */
52993 &dev->cpu_kcycles_used);
52994 }
52995 @@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
52996 fb_deferred_io_cleanup(info);
52997 kfree(info->fbdefio);
52998 info->fbdefio = NULL;
52999 - info->fbops->fb_mmap = dlfb_ops_mmap;
53000 + pax_open_kernel();
53001 + *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
53002 + pax_close_kernel();
53003 }
53004
53005 pr_warn("released /dev/fb%d user=%d count=%d\n",
53006 @@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
53007 struct fb_info *fb_info = dev_get_drvdata(fbdev);
53008 struct dlfb_data *dev = fb_info->par;
53009 return snprintf(buf, PAGE_SIZE, "%u\n",
53010 - atomic_read(&dev->bytes_rendered));
53011 + atomic_read_unchecked(&dev->bytes_rendered));
53012 }
53013
53014 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
53015 @@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
53016 struct fb_info *fb_info = dev_get_drvdata(fbdev);
53017 struct dlfb_data *dev = fb_info->par;
53018 return snprintf(buf, PAGE_SIZE, "%u\n",
53019 - atomic_read(&dev->bytes_identical));
53020 + atomic_read_unchecked(&dev->bytes_identical));
53021 }
53022
53023 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
53024 @@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
53025 struct fb_info *fb_info = dev_get_drvdata(fbdev);
53026 struct dlfb_data *dev = fb_info->par;
53027 return snprintf(buf, PAGE_SIZE, "%u\n",
53028 - atomic_read(&dev->bytes_sent));
53029 + atomic_read_unchecked(&dev->bytes_sent));
53030 }
53031
53032 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
53033 @@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
53034 struct fb_info *fb_info = dev_get_drvdata(fbdev);
53035 struct dlfb_data *dev = fb_info->par;
53036 return snprintf(buf, PAGE_SIZE, "%u\n",
53037 - atomic_read(&dev->cpu_kcycles_used));
53038 + atomic_read_unchecked(&dev->cpu_kcycles_used));
53039 }
53040
53041 static ssize_t edid_show(
53042 @@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
53043 struct fb_info *fb_info = dev_get_drvdata(fbdev);
53044 struct dlfb_data *dev = fb_info->par;
53045
53046 - atomic_set(&dev->bytes_rendered, 0);
53047 - atomic_set(&dev->bytes_identical, 0);
53048 - atomic_set(&dev->bytes_sent, 0);
53049 - atomic_set(&dev->cpu_kcycles_used, 0);
53050 + atomic_set_unchecked(&dev->bytes_rendered, 0);
53051 + atomic_set_unchecked(&dev->bytes_identical, 0);
53052 + atomic_set_unchecked(&dev->bytes_sent, 0);
53053 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
53054
53055 return count;
53056 }
53057 diff --git a/drivers/video/fbdev/uvesafb.c b/drivers/video/fbdev/uvesafb.c
53058 index 509d452..7c9d2de 100644
53059 --- a/drivers/video/fbdev/uvesafb.c
53060 +++ b/drivers/video/fbdev/uvesafb.c
53061 @@ -19,6 +19,7 @@
53062 #include <linux/io.h>
53063 #include <linux/mutex.h>
53064 #include <linux/slab.h>
53065 +#include <linux/moduleloader.h>
53066 #include <video/edid.h>
53067 #include <video/uvesafb.h>
53068 #ifdef CONFIG_X86
53069 @@ -565,10 +566,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
53070 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
53071 par->pmi_setpal = par->ypan = 0;
53072 } else {
53073 +
53074 +#ifdef CONFIG_PAX_KERNEXEC
53075 +#ifdef CONFIG_MODULES
53076 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
53077 +#endif
53078 + if (!par->pmi_code) {
53079 + par->pmi_setpal = par->ypan = 0;
53080 + return 0;
53081 + }
53082 +#endif
53083 +
53084 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
53085 + task->t.regs.edi);
53086 +
53087 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53088 + pax_open_kernel();
53089 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
53090 + pax_close_kernel();
53091 +
53092 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
53093 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
53094 +#else
53095 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
53096 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
53097 +#endif
53098 +
53099 printk(KERN_INFO "uvesafb: protected mode interface info at "
53100 "%04x:%04x\n",
53101 (u16)task->t.regs.es, (u16)task->t.regs.edi);
53102 @@ -813,13 +836,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
53103 par->ypan = ypan;
53104
53105 if (par->pmi_setpal || par->ypan) {
53106 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
53107 if (__supported_pte_mask & _PAGE_NX) {
53108 par->pmi_setpal = par->ypan = 0;
53109 printk(KERN_WARNING "uvesafb: NX protection is active, "
53110 "better not use the PMI.\n");
53111 - } else {
53112 + } else
53113 +#endif
53114 uvesafb_vbe_getpmi(task, par);
53115 - }
53116 }
53117 #else
53118 /* The protected mode interface is not available on non-x86. */
53119 @@ -1453,8 +1477,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
53120 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
53121
53122 /* Disable blanking if the user requested so. */
53123 - if (!blank)
53124 - info->fbops->fb_blank = NULL;
53125 + if (!blank) {
53126 + pax_open_kernel();
53127 + *(void **)&info->fbops->fb_blank = NULL;
53128 + pax_close_kernel();
53129 + }
53130
53131 /*
53132 * Find out how much IO memory is required for the mode with
53133 @@ -1525,8 +1552,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
53134 info->flags = FBINFO_FLAG_DEFAULT |
53135 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
53136
53137 - if (!par->ypan)
53138 - info->fbops->fb_pan_display = NULL;
53139 + if (!par->ypan) {
53140 + pax_open_kernel();
53141 + *(void **)&info->fbops->fb_pan_display = NULL;
53142 + pax_close_kernel();
53143 + }
53144 }
53145
53146 static void uvesafb_init_mtrr(struct fb_info *info)
53147 @@ -1787,6 +1817,11 @@ out_mode:
53148 out:
53149 kfree(par->vbe_modes);
53150
53151 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53152 + if (par->pmi_code)
53153 + module_free_exec(NULL, par->pmi_code);
53154 +#endif
53155 +
53156 framebuffer_release(info);
53157 return err;
53158 }
53159 @@ -1811,6 +1846,11 @@ static int uvesafb_remove(struct platform_device *dev)
53160 kfree(par->vbe_state_orig);
53161 kfree(par->vbe_state_saved);
53162
53163 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53164 + if (par->pmi_code)
53165 + module_free_exec(NULL, par->pmi_code);
53166 +#endif
53167 +
53168 framebuffer_release(info);
53169 }
53170 return 0;
53171 diff --git a/drivers/video/fbdev/vesafb.c b/drivers/video/fbdev/vesafb.c
53172 index 6170e7f..dd63031 100644
53173 --- a/drivers/video/fbdev/vesafb.c
53174 +++ b/drivers/video/fbdev/vesafb.c
53175 @@ -9,6 +9,7 @@
53176 */
53177
53178 #include <linux/module.h>
53179 +#include <linux/moduleloader.h>
53180 #include <linux/kernel.h>
53181 #include <linux/errno.h>
53182 #include <linux/string.h>
53183 @@ -52,8 +53,8 @@ static int vram_remap; /* Set amount of memory to be used */
53184 static int vram_total; /* Set total amount of memory */
53185 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
53186 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
53187 -static void (*pmi_start)(void) __read_mostly;
53188 -static void (*pmi_pal) (void) __read_mostly;
53189 +static void (*pmi_start)(void) __read_only;
53190 +static void (*pmi_pal) (void) __read_only;
53191 static int depth __read_mostly;
53192 static int vga_compat __read_mostly;
53193 /* --------------------------------------------------------------------- */
53194 @@ -233,6 +234,7 @@ static int vesafb_probe(struct platform_device *dev)
53195 unsigned int size_remap;
53196 unsigned int size_total;
53197 char *option = NULL;
53198 + void *pmi_code = NULL;
53199
53200 /* ignore error return of fb_get_options */
53201 fb_get_options("vesafb", &option);
53202 @@ -279,10 +281,6 @@ static int vesafb_probe(struct platform_device *dev)
53203 size_remap = size_total;
53204 vesafb_fix.smem_len = size_remap;
53205
53206 -#ifndef __i386__
53207 - screen_info.vesapm_seg = 0;
53208 -#endif
53209 -
53210 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
53211 printk(KERN_WARNING
53212 "vesafb: cannot reserve video memory at 0x%lx\n",
53213 @@ -312,9 +310,21 @@ static int vesafb_probe(struct platform_device *dev)
53214 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
53215 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
53216
53217 +#ifdef __i386__
53218 +
53219 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53220 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
53221 + if (!pmi_code)
53222 +#elif !defined(CONFIG_PAX_KERNEXEC)
53223 + if (0)
53224 +#endif
53225 +
53226 +#endif
53227 + screen_info.vesapm_seg = 0;
53228 +
53229 if (screen_info.vesapm_seg) {
53230 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
53231 - screen_info.vesapm_seg,screen_info.vesapm_off);
53232 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
53233 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
53234 }
53235
53236 if (screen_info.vesapm_seg < 0xc000)
53237 @@ -322,9 +332,25 @@ static int vesafb_probe(struct platform_device *dev)
53238
53239 if (ypan || pmi_setpal) {
53240 unsigned short *pmi_base;
53241 +
53242 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
53243 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
53244 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
53245 +
53246 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53247 + pax_open_kernel();
53248 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
53249 +#else
53250 + pmi_code = pmi_base;
53251 +#endif
53252 +
53253 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
53254 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
53255 +
53256 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53257 + pmi_start = ktva_ktla(pmi_start);
53258 + pmi_pal = ktva_ktla(pmi_pal);
53259 + pax_close_kernel();
53260 +#endif
53261 +
53262 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
53263 if (pmi_base[3]) {
53264 printk(KERN_INFO "vesafb: pmi: ports = ");
53265 @@ -477,8 +503,11 @@ static int vesafb_probe(struct platform_device *dev)
53266 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
53267 (ypan ? FBINFO_HWACCEL_YPAN : 0);
53268
53269 - if (!ypan)
53270 - info->fbops->fb_pan_display = NULL;
53271 + if (!ypan) {
53272 + pax_open_kernel();
53273 + *(void **)&info->fbops->fb_pan_display = NULL;
53274 + pax_close_kernel();
53275 + }
53276
53277 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
53278 err = -ENOMEM;
53279 @@ -492,6 +521,11 @@ static int vesafb_probe(struct platform_device *dev)
53280 fb_info(info, "%s frame buffer device\n", info->fix.id);
53281 return 0;
53282 err:
53283 +
53284 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
53285 + module_free_exec(NULL, pmi_code);
53286 +#endif
53287 +
53288 if (info->screen_base)
53289 iounmap(info->screen_base);
53290 framebuffer_release(info);
53291 diff --git a/drivers/video/fbdev/via/via_clock.h b/drivers/video/fbdev/via/via_clock.h
53292 index 88714ae..16c2e11 100644
53293 --- a/drivers/video/fbdev/via/via_clock.h
53294 +++ b/drivers/video/fbdev/via/via_clock.h
53295 @@ -56,7 +56,7 @@ struct via_clock {
53296
53297 void (*set_engine_pll_state)(u8 state);
53298 void (*set_engine_pll)(struct via_pll_config config);
53299 -};
53300 +} __no_const;
53301
53302
53303 static inline u32 get_pll_internal_frequency(u32 ref_freq,
53304 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
53305 index 3c14e43..2630570 100644
53306 --- a/drivers/video/logo/logo_linux_clut224.ppm
53307 +++ b/drivers/video/logo/logo_linux_clut224.ppm
53308 @@ -2,1603 +2,1123 @@ P3
53309 # Standard 224-color Linux logo
53310 80 80
53311 255
53312 - 0 0 0 0 0 0 0 0 0 0 0 0
53313 - 0 0 0 0 0 0 0 0 0 0 0 0
53314 - 0 0 0 0 0 0 0 0 0 0 0 0
53315 - 0 0 0 0 0 0 0 0 0 0 0 0
53316 - 0 0 0 0 0 0 0 0 0 0 0 0
53317 - 0 0 0 0 0 0 0 0 0 0 0 0
53318 - 0 0 0 0 0 0 0 0 0 0 0 0
53319 - 0 0 0 0 0 0 0 0 0 0 0 0
53320 - 0 0 0 0 0 0 0 0 0 0 0 0
53321 - 6 6 6 6 6 6 10 10 10 10 10 10
53322 - 10 10 10 6 6 6 6 6 6 6 6 6
53323 - 0 0 0 0 0 0 0 0 0 0 0 0
53324 - 0 0 0 0 0 0 0 0 0 0 0 0
53325 - 0 0 0 0 0 0 0 0 0 0 0 0
53326 - 0 0 0 0 0 0 0 0 0 0 0 0
53327 - 0 0 0 0 0 0 0 0 0 0 0 0
53328 - 0 0 0 0 0 0 0 0 0 0 0 0
53329 - 0 0 0 0 0 0 0 0 0 0 0 0
53330 - 0 0 0 0 0 0 0 0 0 0 0 0
53331 - 0 0 0 0 0 0 0 0 0 0 0 0
53332 - 0 0 0 0 0 0 0 0 0 0 0 0
53333 - 0 0 0 0 0 0 0 0 0 0 0 0
53334 - 0 0 0 0 0 0 0 0 0 0 0 0
53335 - 0 0 0 0 0 0 0 0 0 0 0 0
53336 - 0 0 0 0 0 0 0 0 0 0 0 0
53337 - 0 0 0 0 0 0 0 0 0 0 0 0
53338 - 0 0 0 0 0 0 0 0 0 0 0 0
53339 - 0 0 0 0 0 0 0 0 0 0 0 0
53340 - 0 0 0 6 6 6 10 10 10 14 14 14
53341 - 22 22 22 26 26 26 30 30 30 34 34 34
53342 - 30 30 30 30 30 30 26 26 26 18 18 18
53343 - 14 14 14 10 10 10 6 6 6 0 0 0
53344 - 0 0 0 0 0 0 0 0 0 0 0 0
53345 - 0 0 0 0 0 0 0 0 0 0 0 0
53346 - 0 0 0 0 0 0 0 0 0 0 0 0
53347 - 0 0 0 0 0 0 0 0 0 0 0 0
53348 - 0 0 0 0 0 0 0 0 0 0 0 0
53349 - 0 0 0 0 0 0 0 0 0 0 0 0
53350 - 0 0 0 0 0 0 0 0 0 0 0 0
53351 - 0 0 0 0 0 0 0 0 0 0 0 0
53352 - 0 0 0 0 0 0 0 0 0 0 0 0
53353 - 0 0 0 0 0 1 0 0 1 0 0 0
53354 - 0 0 0 0 0 0 0 0 0 0 0 0
53355 - 0 0 0 0 0 0 0 0 0 0 0 0
53356 - 0 0 0 0 0 0 0 0 0 0 0 0
53357 - 0 0 0 0 0 0 0 0 0 0 0 0
53358 - 0 0 0 0 0 0 0 0 0 0 0 0
53359 - 0 0 0 0 0 0 0 0 0 0 0 0
53360 - 6 6 6 14 14 14 26 26 26 42 42 42
53361 - 54 54 54 66 66 66 78 78 78 78 78 78
53362 - 78 78 78 74 74 74 66 66 66 54 54 54
53363 - 42 42 42 26 26 26 18 18 18 10 10 10
53364 - 6 6 6 0 0 0 0 0 0 0 0 0
53365 - 0 0 0 0 0 0 0 0 0 0 0 0
53366 - 0 0 0 0 0 0 0 0 0 0 0 0
53367 - 0 0 0 0 0 0 0 0 0 0 0 0
53368 - 0 0 0 0 0 0 0 0 0 0 0 0
53369 - 0 0 0 0 0 0 0 0 0 0 0 0
53370 - 0 0 0 0 0 0 0 0 0 0 0 0
53371 - 0 0 0 0 0 0 0 0 0 0 0 0
53372 - 0 0 0 0 0 0 0 0 0 0 0 0
53373 - 0 0 1 0 0 0 0 0 0 0 0 0
53374 - 0 0 0 0 0 0 0 0 0 0 0 0
53375 - 0 0 0 0 0 0 0 0 0 0 0 0
53376 - 0 0 0 0 0 0 0 0 0 0 0 0
53377 - 0 0 0 0 0 0 0 0 0 0 0 0
53378 - 0 0 0 0 0 0 0 0 0 0 0 0
53379 - 0 0 0 0 0 0 0 0 0 10 10 10
53380 - 22 22 22 42 42 42 66 66 66 86 86 86
53381 - 66 66 66 38 38 38 38 38 38 22 22 22
53382 - 26 26 26 34 34 34 54 54 54 66 66 66
53383 - 86 86 86 70 70 70 46 46 46 26 26 26
53384 - 14 14 14 6 6 6 0 0 0 0 0 0
53385 - 0 0 0 0 0 0 0 0 0 0 0 0
53386 - 0 0 0 0 0 0 0 0 0 0 0 0
53387 - 0 0 0 0 0 0 0 0 0 0 0 0
53388 - 0 0 0 0 0 0 0 0 0 0 0 0
53389 - 0 0 0 0 0 0 0 0 0 0 0 0
53390 - 0 0 0 0 0 0 0 0 0 0 0 0
53391 - 0 0 0 0 0 0 0 0 0 0 0 0
53392 - 0 0 0 0 0 0 0 0 0 0 0 0
53393 - 0 0 1 0 0 1 0 0 1 0 0 0
53394 - 0 0 0 0 0 0 0 0 0 0 0 0
53395 - 0 0 0 0 0 0 0 0 0 0 0 0
53396 - 0 0 0 0 0 0 0 0 0 0 0 0
53397 - 0 0 0 0 0 0 0 0 0 0 0 0
53398 - 0 0 0 0 0 0 0 0 0 0 0 0
53399 - 0 0 0 0 0 0 10 10 10 26 26 26
53400 - 50 50 50 82 82 82 58 58 58 6 6 6
53401 - 2 2 6 2 2 6 2 2 6 2 2 6
53402 - 2 2 6 2 2 6 2 2 6 2 2 6
53403 - 6 6 6 54 54 54 86 86 86 66 66 66
53404 - 38 38 38 18 18 18 6 6 6 0 0 0
53405 - 0 0 0 0 0 0 0 0 0 0 0 0
53406 - 0 0 0 0 0 0 0 0 0 0 0 0
53407 - 0 0 0 0 0 0 0 0 0 0 0 0
53408 - 0 0 0 0 0 0 0 0 0 0 0 0
53409 - 0 0 0 0 0 0 0 0 0 0 0 0
53410 - 0 0 0 0 0 0 0 0 0 0 0 0
53411 - 0 0 0 0 0 0 0 0 0 0 0 0
53412 - 0 0 0 0 0 0 0 0 0 0 0 0
53413 - 0 0 0 0 0 0 0 0 0 0 0 0
53414 - 0 0 0 0 0 0 0 0 0 0 0 0
53415 - 0 0 0 0 0 0 0 0 0 0 0 0
53416 - 0 0 0 0 0 0 0 0 0 0 0 0
53417 - 0 0 0 0 0 0 0 0 0 0 0 0
53418 - 0 0 0 0 0 0 0 0 0 0 0 0
53419 - 0 0 0 6 6 6 22 22 22 50 50 50
53420 - 78 78 78 34 34 34 2 2 6 2 2 6
53421 - 2 2 6 2 2 6 2 2 6 2 2 6
53422 - 2 2 6 2 2 6 2 2 6 2 2 6
53423 - 2 2 6 2 2 6 6 6 6 70 70 70
53424 - 78 78 78 46 46 46 22 22 22 6 6 6
53425 - 0 0 0 0 0 0 0 0 0 0 0 0
53426 - 0 0 0 0 0 0 0 0 0 0 0 0
53427 - 0 0 0 0 0 0 0 0 0 0 0 0
53428 - 0 0 0 0 0 0 0 0 0 0 0 0
53429 - 0 0 0 0 0 0 0 0 0 0 0 0
53430 - 0 0 0 0 0 0 0 0 0 0 0 0
53431 - 0 0 0 0 0 0 0 0 0 0 0 0
53432 - 0 0 0 0 0 0 0 0 0 0 0 0
53433 - 0 0 1 0 0 1 0 0 1 0 0 0
53434 - 0 0 0 0 0 0 0 0 0 0 0 0
53435 - 0 0 0 0 0 0 0 0 0 0 0 0
53436 - 0 0 0 0 0 0 0 0 0 0 0 0
53437 - 0 0 0 0 0 0 0 0 0 0 0 0
53438 - 0 0 0 0 0 0 0 0 0 0 0 0
53439 - 6 6 6 18 18 18 42 42 42 82 82 82
53440 - 26 26 26 2 2 6 2 2 6 2 2 6
53441 - 2 2 6 2 2 6 2 2 6 2 2 6
53442 - 2 2 6 2 2 6 2 2 6 14 14 14
53443 - 46 46 46 34 34 34 6 6 6 2 2 6
53444 - 42 42 42 78 78 78 42 42 42 18 18 18
53445 - 6 6 6 0 0 0 0 0 0 0 0 0
53446 - 0 0 0 0 0 0 0 0 0 0 0 0
53447 - 0 0 0 0 0 0 0 0 0 0 0 0
53448 - 0 0 0 0 0 0 0 0 0 0 0 0
53449 - 0 0 0 0 0 0 0 0 0 0 0 0
53450 - 0 0 0 0 0 0 0 0 0 0 0 0
53451 - 0 0 0 0 0 0 0 0 0 0 0 0
53452 - 0 0 0 0 0 0 0 0 0 0 0 0
53453 - 0 0 1 0 0 0 0 0 1 0 0 0
53454 - 0 0 0 0 0 0 0 0 0 0 0 0
53455 - 0 0 0 0 0 0 0 0 0 0 0 0
53456 - 0 0 0 0 0 0 0 0 0 0 0 0
53457 - 0 0 0 0 0 0 0 0 0 0 0 0
53458 - 0 0 0 0 0 0 0 0 0 0 0 0
53459 - 10 10 10 30 30 30 66 66 66 58 58 58
53460 - 2 2 6 2 2 6 2 2 6 2 2 6
53461 - 2 2 6 2 2 6 2 2 6 2 2 6
53462 - 2 2 6 2 2 6 2 2 6 26 26 26
53463 - 86 86 86 101 101 101 46 46 46 10 10 10
53464 - 2 2 6 58 58 58 70 70 70 34 34 34
53465 - 10 10 10 0 0 0 0 0 0 0 0 0
53466 - 0 0 0 0 0 0 0 0 0 0 0 0
53467 - 0 0 0 0 0 0 0 0 0 0 0 0
53468 - 0 0 0 0 0 0 0 0 0 0 0 0
53469 - 0 0 0 0 0 0 0 0 0 0 0 0
53470 - 0 0 0 0 0 0 0 0 0 0 0 0
53471 - 0 0 0 0 0 0 0 0 0 0 0 0
53472 - 0 0 0 0 0 0 0 0 0 0 0 0
53473 - 0 0 1 0 0 1 0 0 1 0 0 0
53474 - 0 0 0 0 0 0 0 0 0 0 0 0
53475 - 0 0 0 0 0 0 0 0 0 0 0 0
53476 - 0 0 0 0 0 0 0 0 0 0 0 0
53477 - 0 0 0 0 0 0 0 0 0 0 0 0
53478 - 0 0 0 0 0 0 0 0 0 0 0 0
53479 - 14 14 14 42 42 42 86 86 86 10 10 10
53480 - 2 2 6 2 2 6 2 2 6 2 2 6
53481 - 2 2 6 2 2 6 2 2 6 2 2 6
53482 - 2 2 6 2 2 6 2 2 6 30 30 30
53483 - 94 94 94 94 94 94 58 58 58 26 26 26
53484 - 2 2 6 6 6 6 78 78 78 54 54 54
53485 - 22 22 22 6 6 6 0 0 0 0 0 0
53486 - 0 0 0 0 0 0 0 0 0 0 0 0
53487 - 0 0 0 0 0 0 0 0 0 0 0 0
53488 - 0 0 0 0 0 0 0 0 0 0 0 0
53489 - 0 0 0 0 0 0 0 0 0 0 0 0
53490 - 0 0 0 0 0 0 0 0 0 0 0 0
53491 - 0 0 0 0 0 0 0 0 0 0 0 0
53492 - 0 0 0 0 0 0 0 0 0 0 0 0
53493 - 0 0 0 0 0 0 0 0 0 0 0 0
53494 - 0 0 0 0 0 0 0 0 0 0 0 0
53495 - 0 0 0 0 0 0 0 0 0 0 0 0
53496 - 0 0 0 0 0 0 0 0 0 0 0 0
53497 - 0 0 0 0 0 0 0 0 0 0 0 0
53498 - 0 0 0 0 0 0 0 0 0 6 6 6
53499 - 22 22 22 62 62 62 62 62 62 2 2 6
53500 - 2 2 6 2 2 6 2 2 6 2 2 6
53501 - 2 2 6 2 2 6 2 2 6 2 2 6
53502 - 2 2 6 2 2 6 2 2 6 26 26 26
53503 - 54 54 54 38 38 38 18 18 18 10 10 10
53504 - 2 2 6 2 2 6 34 34 34 82 82 82
53505 - 38 38 38 14 14 14 0 0 0 0 0 0
53506 - 0 0 0 0 0 0 0 0 0 0 0 0
53507 - 0 0 0 0 0 0 0 0 0 0 0 0
53508 - 0 0 0 0 0 0 0 0 0 0 0 0
53509 - 0 0 0 0 0 0 0 0 0 0 0 0
53510 - 0 0 0 0 0 0 0 0 0 0 0 0
53511 - 0 0 0 0 0 0 0 0 0 0 0 0
53512 - 0 0 0 0 0 0 0 0 0 0 0 0
53513 - 0 0 0 0 0 1 0 0 1 0 0 0
53514 - 0 0 0 0 0 0 0 0 0 0 0 0
53515 - 0 0 0 0 0 0 0 0 0 0 0 0
53516 - 0 0 0 0 0 0 0 0 0 0 0 0
53517 - 0 0 0 0 0 0 0 0 0 0 0 0
53518 - 0 0 0 0 0 0 0 0 0 6 6 6
53519 - 30 30 30 78 78 78 30 30 30 2 2 6
53520 - 2 2 6 2 2 6 2 2 6 2 2 6
53521 - 2 2 6 2 2 6 2 2 6 2 2 6
53522 - 2 2 6 2 2 6 2 2 6 10 10 10
53523 - 10 10 10 2 2 6 2 2 6 2 2 6
53524 - 2 2 6 2 2 6 2 2 6 78 78 78
53525 - 50 50 50 18 18 18 6 6 6 0 0 0
53526 - 0 0 0 0 0 0 0 0 0 0 0 0
53527 - 0 0 0 0 0 0 0 0 0 0 0 0
53528 - 0 0 0 0 0 0 0 0 0 0 0 0
53529 - 0 0 0 0 0 0 0 0 0 0 0 0
53530 - 0 0 0 0 0 0 0 0 0 0 0 0
53531 - 0 0 0 0 0 0 0 0 0 0 0 0
53532 - 0 0 0 0 0 0 0 0 0 0 0 0
53533 - 0 0 1 0 0 0 0 0 0 0 0 0
53534 - 0 0 0 0 0 0 0 0 0 0 0 0
53535 - 0 0 0 0 0 0 0 0 0 0 0 0
53536 - 0 0 0 0 0 0 0 0 0 0 0 0
53537 - 0 0 0 0 0 0 0 0 0 0 0 0
53538 - 0 0 0 0 0 0 0 0 0 10 10 10
53539 - 38 38 38 86 86 86 14 14 14 2 2 6
53540 - 2 2 6 2 2 6 2 2 6 2 2 6
53541 - 2 2 6 2 2 6 2 2 6 2 2 6
53542 - 2 2 6 2 2 6 2 2 6 2 2 6
53543 - 2 2 6 2 2 6 2 2 6 2 2 6
53544 - 2 2 6 2 2 6 2 2 6 54 54 54
53545 - 66 66 66 26 26 26 6 6 6 0 0 0
53546 - 0 0 0 0 0 0 0 0 0 0 0 0
53547 - 0 0 0 0 0 0 0 0 0 0 0 0
53548 - 0 0 0 0 0 0 0 0 0 0 0 0
53549 - 0 0 0 0 0 0 0 0 0 0 0 0
53550 - 0 0 0 0 0 0 0 0 0 0 0 0
53551 - 0 0 0 0 0 0 0 0 0 0 0 0
53552 - 0 0 0 0 0 0 0 0 0 0 0 0
53553 - 0 0 0 0 0 1 0 0 1 0 0 0
53554 - 0 0 0 0 0 0 0 0 0 0 0 0
53555 - 0 0 0 0 0 0 0 0 0 0 0 0
53556 - 0 0 0 0 0 0 0 0 0 0 0 0
53557 - 0 0 0 0 0 0 0 0 0 0 0 0
53558 - 0 0 0 0 0 0 0 0 0 14 14 14
53559 - 42 42 42 82 82 82 2 2 6 2 2 6
53560 - 2 2 6 6 6 6 10 10 10 2 2 6
53561 - 2 2 6 2 2 6 2 2 6 2 2 6
53562 - 2 2 6 2 2 6 2 2 6 6 6 6
53563 - 14 14 14 10 10 10 2 2 6 2 2 6
53564 - 2 2 6 2 2 6 2 2 6 18 18 18
53565 - 82 82 82 34 34 34 10 10 10 0 0 0
53566 - 0 0 0 0 0 0 0 0 0 0 0 0
53567 - 0 0 0 0 0 0 0 0 0 0 0 0
53568 - 0 0 0 0 0 0 0 0 0 0 0 0
53569 - 0 0 0 0 0 0 0 0 0 0 0 0
53570 - 0 0 0 0 0 0 0 0 0 0 0 0
53571 - 0 0 0 0 0 0 0 0 0 0 0 0
53572 - 0 0 0 0 0 0 0 0 0 0 0 0
53573 - 0 0 1 0 0 0 0 0 0 0 0 0
53574 - 0 0 0 0 0 0 0 0 0 0 0 0
53575 - 0 0 0 0 0 0 0 0 0 0 0 0
53576 - 0 0 0 0 0 0 0 0 0 0 0 0
53577 - 0 0 0 0 0 0 0 0 0 0 0 0
53578 - 0 0 0 0 0 0 0 0 0 14 14 14
53579 - 46 46 46 86 86 86 2 2 6 2 2 6
53580 - 6 6 6 6 6 6 22 22 22 34 34 34
53581 - 6 6 6 2 2 6 2 2 6 2 2 6
53582 - 2 2 6 2 2 6 18 18 18 34 34 34
53583 - 10 10 10 50 50 50 22 22 22 2 2 6
53584 - 2 2 6 2 2 6 2 2 6 10 10 10
53585 - 86 86 86 42 42 42 14 14 14 0 0 0
53586 - 0 0 0 0 0 0 0 0 0 0 0 0
53587 - 0 0 0 0 0 0 0 0 0 0 0 0
53588 - 0 0 0 0 0 0 0 0 0 0 0 0
53589 - 0 0 0 0 0 0 0 0 0 0 0 0
53590 - 0 0 0 0 0 0 0 0 0 0 0 0
53591 - 0 0 0 0 0 0 0 0 0 0 0 0
53592 - 0 0 0 0 0 0 0 0 0 0 0 0
53593 - 0 0 1 0 0 1 0 0 1 0 0 0
53594 - 0 0 0 0 0 0 0 0 0 0 0 0
53595 - 0 0 0 0 0 0 0 0 0 0 0 0
53596 - 0 0 0 0 0 0 0 0 0 0 0 0
53597 - 0 0 0 0 0 0 0 0 0 0 0 0
53598 - 0 0 0 0 0 0 0 0 0 14 14 14
53599 - 46 46 46 86 86 86 2 2 6 2 2 6
53600 - 38 38 38 116 116 116 94 94 94 22 22 22
53601 - 22 22 22 2 2 6 2 2 6 2 2 6
53602 - 14 14 14 86 86 86 138 138 138 162 162 162
53603 -154 154 154 38 38 38 26 26 26 6 6 6
53604 - 2 2 6 2 2 6 2 2 6 2 2 6
53605 - 86 86 86 46 46 46 14 14 14 0 0 0
53606 - 0 0 0 0 0 0 0 0 0 0 0 0
53607 - 0 0 0 0 0 0 0 0 0 0 0 0
53608 - 0 0 0 0 0 0 0 0 0 0 0 0
53609 - 0 0 0 0 0 0 0 0 0 0 0 0
53610 - 0 0 0 0 0 0 0 0 0 0 0 0
53611 - 0 0 0 0 0 0 0 0 0 0 0 0
53612 - 0 0 0 0 0 0 0 0 0 0 0 0
53613 - 0 0 0 0 0 0 0 0 0 0 0 0
53614 - 0 0 0 0 0 0 0 0 0 0 0 0
53615 - 0 0 0 0 0 0 0 0 0 0 0 0
53616 - 0 0 0 0 0 0 0 0 0 0 0 0
53617 - 0 0 0 0 0 0 0 0 0 0 0 0
53618 - 0 0 0 0 0 0 0 0 0 14 14 14
53619 - 46 46 46 86 86 86 2 2 6 14 14 14
53620 -134 134 134 198 198 198 195 195 195 116 116 116
53621 - 10 10 10 2 2 6 2 2 6 6 6 6
53622 -101 98 89 187 187 187 210 210 210 218 218 218
53623 -214 214 214 134 134 134 14 14 14 6 6 6
53624 - 2 2 6 2 2 6 2 2 6 2 2 6
53625 - 86 86 86 50 50 50 18 18 18 6 6 6
53626 - 0 0 0 0 0 0 0 0 0 0 0 0
53627 - 0 0 0 0 0 0 0 0 0 0 0 0
53628 - 0 0 0 0 0 0 0 0 0 0 0 0
53629 - 0 0 0 0 0 0 0 0 0 0 0 0
53630 - 0 0 0 0 0 0 0 0 0 0 0 0
53631 - 0 0 0 0 0 0 0 0 0 0 0 0
53632 - 0 0 0 0 0 0 0 0 1 0 0 0
53633 - 0 0 1 0 0 1 0 0 1 0 0 0
53634 - 0 0 0 0 0 0 0 0 0 0 0 0
53635 - 0 0 0 0 0 0 0 0 0 0 0 0
53636 - 0 0 0 0 0 0 0 0 0 0 0 0
53637 - 0 0 0 0 0 0 0 0 0 0 0 0
53638 - 0 0 0 0 0 0 0 0 0 14 14 14
53639 - 46 46 46 86 86 86 2 2 6 54 54 54
53640 -218 218 218 195 195 195 226 226 226 246 246 246
53641 - 58 58 58 2 2 6 2 2 6 30 30 30
53642 -210 210 210 253 253 253 174 174 174 123 123 123
53643 -221 221 221 234 234 234 74 74 74 2 2 6
53644 - 2 2 6 2 2 6 2 2 6 2 2 6
53645 - 70 70 70 58 58 58 22 22 22 6 6 6
53646 - 0 0 0 0 0 0 0 0 0 0 0 0
53647 - 0 0 0 0 0 0 0 0 0 0 0 0
53648 - 0 0 0 0 0 0 0 0 0 0 0 0
53649 - 0 0 0 0 0 0 0 0 0 0 0 0
53650 - 0 0 0 0 0 0 0 0 0 0 0 0
53651 - 0 0 0 0 0 0 0 0 0 0 0 0
53652 - 0 0 0 0 0 0 0 0 0 0 0 0
53653 - 0 0 0 0 0 0 0 0 0 0 0 0
53654 - 0 0 0 0 0 0 0 0 0 0 0 0
53655 - 0 0 0 0 0 0 0 0 0 0 0 0
53656 - 0 0 0 0 0 0 0 0 0 0 0 0
53657 - 0 0 0 0 0 0 0 0 0 0 0 0
53658 - 0 0 0 0 0 0 0 0 0 14 14 14
53659 - 46 46 46 82 82 82 2 2 6 106 106 106
53660 -170 170 170 26 26 26 86 86 86 226 226 226
53661 -123 123 123 10 10 10 14 14 14 46 46 46
53662 -231 231 231 190 190 190 6 6 6 70 70 70
53663 - 90 90 90 238 238 238 158 158 158 2 2 6
53664 - 2 2 6 2 2 6 2 2 6 2 2 6
53665 - 70 70 70 58 58 58 22 22 22 6 6 6
53666 - 0 0 0 0 0 0 0 0 0 0 0 0
53667 - 0 0 0 0 0 0 0 0 0 0 0 0
53668 - 0 0 0 0 0 0 0 0 0 0 0 0
53669 - 0 0 0 0 0 0 0 0 0 0 0 0
53670 - 0 0 0 0 0 0 0 0 0 0 0 0
53671 - 0 0 0 0 0 0 0 0 0 0 0 0
53672 - 0 0 0 0 0 0 0 0 1 0 0 0
53673 - 0 0 1 0 0 1 0 0 1 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 14 14 14
53679 - 42 42 42 86 86 86 6 6 6 116 116 116
53680 -106 106 106 6 6 6 70 70 70 149 149 149
53681 -128 128 128 18 18 18 38 38 38 54 54 54
53682 -221 221 221 106 106 106 2 2 6 14 14 14
53683 - 46 46 46 190 190 190 198 198 198 2 2 6
53684 - 2 2 6 2 2 6 2 2 6 2 2 6
53685 - 74 74 74 62 62 62 22 22 22 6 6 6
53686 - 0 0 0 0 0 0 0 0 0 0 0 0
53687 - 0 0 0 0 0 0 0 0 0 0 0 0
53688 - 0 0 0 0 0 0 0 0 0 0 0 0
53689 - 0 0 0 0 0 0 0 0 0 0 0 0
53690 - 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 1 0 0 0
53693 - 0 0 1 0 0 0 0 0 1 0 0 0
53694 - 0 0 0 0 0 0 0 0 0 0 0 0
53695 - 0 0 0 0 0 0 0 0 0 0 0 0
53696 - 0 0 0 0 0 0 0 0 0 0 0 0
53697 - 0 0 0 0 0 0 0 0 0 0 0 0
53698 - 0 0 0 0 0 0 0 0 0 14 14 14
53699 - 42 42 42 94 94 94 14 14 14 101 101 101
53700 -128 128 128 2 2 6 18 18 18 116 116 116
53701 -118 98 46 121 92 8 121 92 8 98 78 10
53702 -162 162 162 106 106 106 2 2 6 2 2 6
53703 - 2 2 6 195 195 195 195 195 195 6 6 6
53704 - 2 2 6 2 2 6 2 2 6 2 2 6
53705 - 74 74 74 62 62 62 22 22 22 6 6 6
53706 - 0 0 0 0 0 0 0 0 0 0 0 0
53707 - 0 0 0 0 0 0 0 0 0 0 0 0
53708 - 0 0 0 0 0 0 0 0 0 0 0 0
53709 - 0 0 0 0 0 0 0 0 0 0 0 0
53710 - 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 1 0 0 1
53713 - 0 0 1 0 0 0 0 0 1 0 0 0
53714 - 0 0 0 0 0 0 0 0 0 0 0 0
53715 - 0 0 0 0 0 0 0 0 0 0 0 0
53716 - 0 0 0 0 0 0 0 0 0 0 0 0
53717 - 0 0 0 0 0 0 0 0 0 0 0 0
53718 - 0 0 0 0 0 0 0 0 0 10 10 10
53719 - 38 38 38 90 90 90 14 14 14 58 58 58
53720 -210 210 210 26 26 26 54 38 6 154 114 10
53721 -226 170 11 236 186 11 225 175 15 184 144 12
53722 -215 174 15 175 146 61 37 26 9 2 2 6
53723 - 70 70 70 246 246 246 138 138 138 2 2 6
53724 - 2 2 6 2 2 6 2 2 6 2 2 6
53725 - 70 70 70 66 66 66 26 26 26 6 6 6
53726 - 0 0 0 0 0 0 0 0 0 0 0 0
53727 - 0 0 0 0 0 0 0 0 0 0 0 0
53728 - 0 0 0 0 0 0 0 0 0 0 0 0
53729 - 0 0 0 0 0 0 0 0 0 0 0 0
53730 - 0 0 0 0 0 0 0 0 0 0 0 0
53731 - 0 0 0 0 0 0 0 0 0 0 0 0
53732 - 0 0 0 0 0 0 0 0 0 0 0 0
53733 - 0 0 0 0 0 0 0 0 0 0 0 0
53734 - 0 0 0 0 0 0 0 0 0 0 0 0
53735 - 0 0 0 0 0 0 0 0 0 0 0 0
53736 - 0 0 0 0 0 0 0 0 0 0 0 0
53737 - 0 0 0 0 0 0 0 0 0 0 0 0
53738 - 0 0 0 0 0 0 0 0 0 10 10 10
53739 - 38 38 38 86 86 86 14 14 14 10 10 10
53740 -195 195 195 188 164 115 192 133 9 225 175 15
53741 -239 182 13 234 190 10 232 195 16 232 200 30
53742 -245 207 45 241 208 19 232 195 16 184 144 12
53743 -218 194 134 211 206 186 42 42 42 2 2 6
53744 - 2 2 6 2 2 6 2 2 6 2 2 6
53745 - 50 50 50 74 74 74 30 30 30 6 6 6
53746 - 0 0 0 0 0 0 0 0 0 0 0 0
53747 - 0 0 0 0 0 0 0 0 0 0 0 0
53748 - 0 0 0 0 0 0 0 0 0 0 0 0
53749 - 0 0 0 0 0 0 0 0 0 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 10 10 10
53759 - 34 34 34 86 86 86 14 14 14 2 2 6
53760 -121 87 25 192 133 9 219 162 10 239 182 13
53761 -236 186 11 232 195 16 241 208 19 244 214 54
53762 -246 218 60 246 218 38 246 215 20 241 208 19
53763 -241 208 19 226 184 13 121 87 25 2 2 6
53764 - 2 2 6 2 2 6 2 2 6 2 2 6
53765 - 50 50 50 82 82 82 34 34 34 10 10 10
53766 - 0 0 0 0 0 0 0 0 0 0 0 0
53767 - 0 0 0 0 0 0 0 0 0 0 0 0
53768 - 0 0 0 0 0 0 0 0 0 0 0 0
53769 - 0 0 0 0 0 0 0 0 0 0 0 0
53770 - 0 0 0 0 0 0 0 0 0 0 0 0
53771 - 0 0 0 0 0 0 0 0 0 0 0 0
53772 - 0 0 0 0 0 0 0 0 0 0 0 0
53773 - 0 0 0 0 0 0 0 0 0 0 0 0
53774 - 0 0 0 0 0 0 0 0 0 0 0 0
53775 - 0 0 0 0 0 0 0 0 0 0 0 0
53776 - 0 0 0 0 0 0 0 0 0 0 0 0
53777 - 0 0 0 0 0 0 0 0 0 0 0 0
53778 - 0 0 0 0 0 0 0 0 0 10 10 10
53779 - 34 34 34 82 82 82 30 30 30 61 42 6
53780 -180 123 7 206 145 10 230 174 11 239 182 13
53781 -234 190 10 238 202 15 241 208 19 246 218 74
53782 -246 218 38 246 215 20 246 215 20 246 215 20
53783 -226 184 13 215 174 15 184 144 12 6 6 6
53784 - 2 2 6 2 2 6 2 2 6 2 2 6
53785 - 26 26 26 94 94 94 42 42 42 14 14 14
53786 - 0 0 0 0 0 0 0 0 0 0 0 0
53787 - 0 0 0 0 0 0 0 0 0 0 0 0
53788 - 0 0 0 0 0 0 0 0 0 0 0 0
53789 - 0 0 0 0 0 0 0 0 0 0 0 0
53790 - 0 0 0 0 0 0 0 0 0 0 0 0
53791 - 0 0 0 0 0 0 0 0 0 0 0 0
53792 - 0 0 0 0 0 0 0 0 0 0 0 0
53793 - 0 0 0 0 0 0 0 0 0 0 0 0
53794 - 0 0 0 0 0 0 0 0 0 0 0 0
53795 - 0 0 0 0 0 0 0 0 0 0 0 0
53796 - 0 0 0 0 0 0 0 0 0 0 0 0
53797 - 0 0 0 0 0 0 0 0 0 0 0 0
53798 - 0 0 0 0 0 0 0 0 0 10 10 10
53799 - 30 30 30 78 78 78 50 50 50 104 69 6
53800 -192 133 9 216 158 10 236 178 12 236 186 11
53801 -232 195 16 241 208 19 244 214 54 245 215 43
53802 -246 215 20 246 215 20 241 208 19 198 155 10
53803 -200 144 11 216 158 10 156 118 10 2 2 6
53804 - 2 2 6 2 2 6 2 2 6 2 2 6
53805 - 6 6 6 90 90 90 54 54 54 18 18 18
53806 - 6 6 6 0 0 0 0 0 0 0 0 0
53807 - 0 0 0 0 0 0 0 0 0 0 0 0
53808 - 0 0 0 0 0 0 0 0 0 0 0 0
53809 - 0 0 0 0 0 0 0 0 0 0 0 0
53810 - 0 0 0 0 0 0 0 0 0 0 0 0
53811 - 0 0 0 0 0 0 0 0 0 0 0 0
53812 - 0 0 0 0 0 0 0 0 0 0 0 0
53813 - 0 0 0 0 0 0 0 0 0 0 0 0
53814 - 0 0 0 0 0 0 0 0 0 0 0 0
53815 - 0 0 0 0 0 0 0 0 0 0 0 0
53816 - 0 0 0 0 0 0 0 0 0 0 0 0
53817 - 0 0 0 0 0 0 0 0 0 0 0 0
53818 - 0 0 0 0 0 0 0 0 0 10 10 10
53819 - 30 30 30 78 78 78 46 46 46 22 22 22
53820 -137 92 6 210 162 10 239 182 13 238 190 10
53821 -238 202 15 241 208 19 246 215 20 246 215 20
53822 -241 208 19 203 166 17 185 133 11 210 150 10
53823 -216 158 10 210 150 10 102 78 10 2 2 6
53824 - 6 6 6 54 54 54 14 14 14 2 2 6
53825 - 2 2 6 62 62 62 74 74 74 30 30 30
53826 - 10 10 10 0 0 0 0 0 0 0 0 0
53827 - 0 0 0 0 0 0 0 0 0 0 0 0
53828 - 0 0 0 0 0 0 0 0 0 0 0 0
53829 - 0 0 0 0 0 0 0 0 0 0 0 0
53830 - 0 0 0 0 0 0 0 0 0 0 0 0
53831 - 0 0 0 0 0 0 0 0 0 0 0 0
53832 - 0 0 0 0 0 0 0 0 0 0 0 0
53833 - 0 0 0 0 0 0 0 0 0 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 10 10 10
53839 - 34 34 34 78 78 78 50 50 50 6 6 6
53840 - 94 70 30 139 102 15 190 146 13 226 184 13
53841 -232 200 30 232 195 16 215 174 15 190 146 13
53842 -168 122 10 192 133 9 210 150 10 213 154 11
53843 -202 150 34 182 157 106 101 98 89 2 2 6
53844 - 2 2 6 78 78 78 116 116 116 58 58 58
53845 - 2 2 6 22 22 22 90 90 90 46 46 46
53846 - 18 18 18 6 6 6 0 0 0 0 0 0
53847 - 0 0 0 0 0 0 0 0 0 0 0 0
53848 - 0 0 0 0 0 0 0 0 0 0 0 0
53849 - 0 0 0 0 0 0 0 0 0 0 0 0
53850 - 0 0 0 0 0 0 0 0 0 0 0 0
53851 - 0 0 0 0 0 0 0 0 0 0 0 0
53852 - 0 0 0 0 0 0 0 0 0 0 0 0
53853 - 0 0 0 0 0 0 0 0 0 0 0 0
53854 - 0 0 0 0 0 0 0 0 0 0 0 0
53855 - 0 0 0 0 0 0 0 0 0 0 0 0
53856 - 0 0 0 0 0 0 0 0 0 0 0 0
53857 - 0 0 0 0 0 0 0 0 0 0 0 0
53858 - 0 0 0 0 0 0 0 0 0 10 10 10
53859 - 38 38 38 86 86 86 50 50 50 6 6 6
53860 -128 128 128 174 154 114 156 107 11 168 122 10
53861 -198 155 10 184 144 12 197 138 11 200 144 11
53862 -206 145 10 206 145 10 197 138 11 188 164 115
53863 -195 195 195 198 198 198 174 174 174 14 14 14
53864 - 2 2 6 22 22 22 116 116 116 116 116 116
53865 - 22 22 22 2 2 6 74 74 74 70 70 70
53866 - 30 30 30 10 10 10 0 0 0 0 0 0
53867 - 0 0 0 0 0 0 0 0 0 0 0 0
53868 - 0 0 0 0 0 0 0 0 0 0 0 0
53869 - 0 0 0 0 0 0 0 0 0 0 0 0
53870 - 0 0 0 0 0 0 0 0 0 0 0 0
53871 - 0 0 0 0 0 0 0 0 0 0 0 0
53872 - 0 0 0 0 0 0 0 0 0 0 0 0
53873 - 0 0 0 0 0 0 0 0 0 0 0 0
53874 - 0 0 0 0 0 0 0 0 0 0 0 0
53875 - 0 0 0 0 0 0 0 0 0 0 0 0
53876 - 0 0 0 0 0 0 0 0 0 0 0 0
53877 - 0 0 0 0 0 0 0 0 0 0 0 0
53878 - 0 0 0 0 0 0 6 6 6 18 18 18
53879 - 50 50 50 101 101 101 26 26 26 10 10 10
53880 -138 138 138 190 190 190 174 154 114 156 107 11
53881 -197 138 11 200 144 11 197 138 11 192 133 9
53882 -180 123 7 190 142 34 190 178 144 187 187 187
53883 -202 202 202 221 221 221 214 214 214 66 66 66
53884 - 2 2 6 2 2 6 50 50 50 62 62 62
53885 - 6 6 6 2 2 6 10 10 10 90 90 90
53886 - 50 50 50 18 18 18 6 6 6 0 0 0
53887 - 0 0 0 0 0 0 0 0 0 0 0 0
53888 - 0 0 0 0 0 0 0 0 0 0 0 0
53889 - 0 0 0 0 0 0 0 0 0 0 0 0
53890 - 0 0 0 0 0 0 0 0 0 0 0 0
53891 - 0 0 0 0 0 0 0 0 0 0 0 0
53892 - 0 0 0 0 0 0 0 0 0 0 0 0
53893 - 0 0 0 0 0 0 0 0 0 0 0 0
53894 - 0 0 0 0 0 0 0 0 0 0 0 0
53895 - 0 0 0 0 0 0 0 0 0 0 0 0
53896 - 0 0 0 0 0 0 0 0 0 0 0 0
53897 - 0 0 0 0 0 0 0 0 0 0 0 0
53898 - 0 0 0 0 0 0 10 10 10 34 34 34
53899 - 74 74 74 74 74 74 2 2 6 6 6 6
53900 -144 144 144 198 198 198 190 190 190 178 166 146
53901 -154 121 60 156 107 11 156 107 11 168 124 44
53902 -174 154 114 187 187 187 190 190 190 210 210 210
53903 -246 246 246 253 253 253 253 253 253 182 182 182
53904 - 6 6 6 2 2 6 2 2 6 2 2 6
53905 - 2 2 6 2 2 6 2 2 6 62 62 62
53906 - 74 74 74 34 34 34 14 14 14 0 0 0
53907 - 0 0 0 0 0 0 0 0 0 0 0 0
53908 - 0 0 0 0 0 0 0 0 0 0 0 0
53909 - 0 0 0 0 0 0 0 0 0 0 0 0
53910 - 0 0 0 0 0 0 0 0 0 0 0 0
53911 - 0 0 0 0 0 0 0 0 0 0 0 0
53912 - 0 0 0 0 0 0 0 0 0 0 0 0
53913 - 0 0 0 0 0 0 0 0 0 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 0 10 10 10 22 22 22 54 54 54
53919 - 94 94 94 18 18 18 2 2 6 46 46 46
53920 -234 234 234 221 221 221 190 190 190 190 190 190
53921 -190 190 190 187 187 187 187 187 187 190 190 190
53922 -190 190 190 195 195 195 214 214 214 242 242 242
53923 -253 253 253 253 253 253 253 253 253 253 253 253
53924 - 82 82 82 2 2 6 2 2 6 2 2 6
53925 - 2 2 6 2 2 6 2 2 6 14 14 14
53926 - 86 86 86 54 54 54 22 22 22 6 6 6
53927 - 0 0 0 0 0 0 0 0 0 0 0 0
53928 - 0 0 0 0 0 0 0 0 0 0 0 0
53929 - 0 0 0 0 0 0 0 0 0 0 0 0
53930 - 0 0 0 0 0 0 0 0 0 0 0 0
53931 - 0 0 0 0 0 0 0 0 0 0 0 0
53932 - 0 0 0 0 0 0 0 0 0 0 0 0
53933 - 0 0 0 0 0 0 0 0 0 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 - 6 6 6 18 18 18 46 46 46 90 90 90
53939 - 46 46 46 18 18 18 6 6 6 182 182 182
53940 -253 253 253 246 246 246 206 206 206 190 190 190
53941 -190 190 190 190 190 190 190 190 190 190 190 190
53942 -206 206 206 231 231 231 250 250 250 253 253 253
53943 -253 253 253 253 253 253 253 253 253 253 253 253
53944 -202 202 202 14 14 14 2 2 6 2 2 6
53945 - 2 2 6 2 2 6 2 2 6 2 2 6
53946 - 42 42 42 86 86 86 42 42 42 18 18 18
53947 - 6 6 6 0 0 0 0 0 0 0 0 0
53948 - 0 0 0 0 0 0 0 0 0 0 0 0
53949 - 0 0 0 0 0 0 0 0 0 0 0 0
53950 - 0 0 0 0 0 0 0 0 0 0 0 0
53951 - 0 0 0 0 0 0 0 0 0 0 0 0
53952 - 0 0 0 0 0 0 0 0 0 0 0 0
53953 - 0 0 0 0 0 0 0 0 0 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 6 6 6
53958 - 14 14 14 38 38 38 74 74 74 66 66 66
53959 - 2 2 6 6 6 6 90 90 90 250 250 250
53960 -253 253 253 253 253 253 238 238 238 198 198 198
53961 -190 190 190 190 190 190 195 195 195 221 221 221
53962 -246 246 246 253 253 253 253 253 253 253 253 253
53963 -253 253 253 253 253 253 253 253 253 253 253 253
53964 -253 253 253 82 82 82 2 2 6 2 2 6
53965 - 2 2 6 2 2 6 2 2 6 2 2 6
53966 - 2 2 6 78 78 78 70 70 70 34 34 34
53967 - 14 14 14 6 6 6 0 0 0 0 0 0
53968 - 0 0 0 0 0 0 0 0 0 0 0 0
53969 - 0 0 0 0 0 0 0 0 0 0 0 0
53970 - 0 0 0 0 0 0 0 0 0 0 0 0
53971 - 0 0 0 0 0 0 0 0 0 0 0 0
53972 - 0 0 0 0 0 0 0 0 0 0 0 0
53973 - 0 0 0 0 0 0 0 0 0 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 0 14 14 14
53978 - 34 34 34 66 66 66 78 78 78 6 6 6
53979 - 2 2 6 18 18 18 218 218 218 253 253 253
53980 -253 253 253 253 253 253 253 253 253 246 246 246
53981 -226 226 226 231 231 231 246 246 246 253 253 253
53982 -253 253 253 253 253 253 253 253 253 253 253 253
53983 -253 253 253 253 253 253 253 253 253 253 253 253
53984 -253 253 253 178 178 178 2 2 6 2 2 6
53985 - 2 2 6 2 2 6 2 2 6 2 2 6
53986 - 2 2 6 18 18 18 90 90 90 62 62 62
53987 - 30 30 30 10 10 10 0 0 0 0 0 0
53988 - 0 0 0 0 0 0 0 0 0 0 0 0
53989 - 0 0 0 0 0 0 0 0 0 0 0 0
53990 - 0 0 0 0 0 0 0 0 0 0 0 0
53991 - 0 0 0 0 0 0 0 0 0 0 0 0
53992 - 0 0 0 0 0 0 0 0 0 0 0 0
53993 - 0 0 0 0 0 0 0 0 0 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 10 10 10 26 26 26
53998 - 58 58 58 90 90 90 18 18 18 2 2 6
53999 - 2 2 6 110 110 110 253 253 253 253 253 253
54000 -253 253 253 253 253 253 253 253 253 253 253 253
54001 -250 250 250 253 253 253 253 253 253 253 253 253
54002 -253 253 253 253 253 253 253 253 253 253 253 253
54003 -253 253 253 253 253 253 253 253 253 253 253 253
54004 -253 253 253 231 231 231 18 18 18 2 2 6
54005 - 2 2 6 2 2 6 2 2 6 2 2 6
54006 - 2 2 6 2 2 6 18 18 18 94 94 94
54007 - 54 54 54 26 26 26 10 10 10 0 0 0
54008 - 0 0 0 0 0 0 0 0 0 0 0 0
54009 - 0 0 0 0 0 0 0 0 0 0 0 0
54010 - 0 0 0 0 0 0 0 0 0 0 0 0
54011 - 0 0 0 0 0 0 0 0 0 0 0 0
54012 - 0 0 0 0 0 0 0 0 0 0 0 0
54013 - 0 0 0 0 0 0 0 0 0 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 6 6 6 22 22 22 50 50 50
54018 - 90 90 90 26 26 26 2 2 6 2 2 6
54019 - 14 14 14 195 195 195 250 250 250 253 253 253
54020 -253 253 253 253 253 253 253 253 253 253 253 253
54021 -253 253 253 253 253 253 253 253 253 253 253 253
54022 -253 253 253 253 253 253 253 253 253 253 253 253
54023 -253 253 253 253 253 253 253 253 253 253 253 253
54024 -250 250 250 242 242 242 54 54 54 2 2 6
54025 - 2 2 6 2 2 6 2 2 6 2 2 6
54026 - 2 2 6 2 2 6 2 2 6 38 38 38
54027 - 86 86 86 50 50 50 22 22 22 6 6 6
54028 - 0 0 0 0 0 0 0 0 0 0 0 0
54029 - 0 0 0 0 0 0 0 0 0 0 0 0
54030 - 0 0 0 0 0 0 0 0 0 0 0 0
54031 - 0 0 0 0 0 0 0 0 0 0 0 0
54032 - 0 0 0 0 0 0 0 0 0 0 0 0
54033 - 0 0 0 0 0 0 0 0 0 0 0 0
54034 - 0 0 0 0 0 0 0 0 0 0 0 0
54035 - 0 0 0 0 0 0 0 0 0 0 0 0
54036 - 0 0 0 0 0 0 0 0 0 0 0 0
54037 - 6 6 6 14 14 14 38 38 38 82 82 82
54038 - 34 34 34 2 2 6 2 2 6 2 2 6
54039 - 42 42 42 195 195 195 246 246 246 253 253 253
54040 -253 253 253 253 253 253 253 253 253 250 250 250
54041 -242 242 242 242 242 242 250 250 250 253 253 253
54042 -253 253 253 253 253 253 253 253 253 253 253 253
54043 -253 253 253 250 250 250 246 246 246 238 238 238
54044 -226 226 226 231 231 231 101 101 101 6 6 6
54045 - 2 2 6 2 2 6 2 2 6 2 2 6
54046 - 2 2 6 2 2 6 2 2 6 2 2 6
54047 - 38 38 38 82 82 82 42 42 42 14 14 14
54048 - 6 6 6 0 0 0 0 0 0 0 0 0
54049 - 0 0 0 0 0 0 0 0 0 0 0 0
54050 - 0 0 0 0 0 0 0 0 0 0 0 0
54051 - 0 0 0 0 0 0 0 0 0 0 0 0
54052 - 0 0 0 0 0 0 0 0 0 0 0 0
54053 - 0 0 0 0 0 0 0 0 0 0 0 0
54054 - 0 0 0 0 0 0 0 0 0 0 0 0
54055 - 0 0 0 0 0 0 0 0 0 0 0 0
54056 - 0 0 0 0 0 0 0 0 0 0 0 0
54057 - 10 10 10 26 26 26 62 62 62 66 66 66
54058 - 2 2 6 2 2 6 2 2 6 6 6 6
54059 - 70 70 70 170 170 170 206 206 206 234 234 234
54060 -246 246 246 250 250 250 250 250 250 238 238 238
54061 -226 226 226 231 231 231 238 238 238 250 250 250
54062 -250 250 250 250 250 250 246 246 246 231 231 231
54063 -214 214 214 206 206 206 202 202 202 202 202 202
54064 -198 198 198 202 202 202 182 182 182 18 18 18
54065 - 2 2 6 2 2 6 2 2 6 2 2 6
54066 - 2 2 6 2 2 6 2 2 6 2 2 6
54067 - 2 2 6 62 62 62 66 66 66 30 30 30
54068 - 10 10 10 0 0 0 0 0 0 0 0 0
54069 - 0 0 0 0 0 0 0 0 0 0 0 0
54070 - 0 0 0 0 0 0 0 0 0 0 0 0
54071 - 0 0 0 0 0 0 0 0 0 0 0 0
54072 - 0 0 0 0 0 0 0 0 0 0 0 0
54073 - 0 0 0 0 0 0 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 - 14 14 14 42 42 42 82 82 82 18 18 18
54078 - 2 2 6 2 2 6 2 2 6 10 10 10
54079 - 94 94 94 182 182 182 218 218 218 242 242 242
54080 -250 250 250 253 253 253 253 253 253 250 250 250
54081 -234 234 234 253 253 253 253 253 253 253 253 253
54082 -253 253 253 253 253 253 253 253 253 246 246 246
54083 -238 238 238 226 226 226 210 210 210 202 202 202
54084 -195 195 195 195 195 195 210 210 210 158 158 158
54085 - 6 6 6 14 14 14 50 50 50 14 14 14
54086 - 2 2 6 2 2 6 2 2 6 2 2 6
54087 - 2 2 6 6 6 6 86 86 86 46 46 46
54088 - 18 18 18 6 6 6 0 0 0 0 0 0
54089 - 0 0 0 0 0 0 0 0 0 0 0 0
54090 - 0 0 0 0 0 0 0 0 0 0 0 0
54091 - 0 0 0 0 0 0 0 0 0 0 0 0
54092 - 0 0 0 0 0 0 0 0 0 0 0 0
54093 - 0 0 0 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 6 6 6
54097 - 22 22 22 54 54 54 70 70 70 2 2 6
54098 - 2 2 6 10 10 10 2 2 6 22 22 22
54099 -166 166 166 231 231 231 250 250 250 253 253 253
54100 -253 253 253 253 253 253 253 253 253 250 250 250
54101 -242 242 242 253 253 253 253 253 253 253 253 253
54102 -253 253 253 253 253 253 253 253 253 253 253 253
54103 -253 253 253 253 253 253 253 253 253 246 246 246
54104 -231 231 231 206 206 206 198 198 198 226 226 226
54105 - 94 94 94 2 2 6 6 6 6 38 38 38
54106 - 30 30 30 2 2 6 2 2 6 2 2 6
54107 - 2 2 6 2 2 6 62 62 62 66 66 66
54108 - 26 26 26 10 10 10 0 0 0 0 0 0
54109 - 0 0 0 0 0 0 0 0 0 0 0 0
54110 - 0 0 0 0 0 0 0 0 0 0 0 0
54111 - 0 0 0 0 0 0 0 0 0 0 0 0
54112 - 0 0 0 0 0 0 0 0 0 0 0 0
54113 - 0 0 0 0 0 0 0 0 0 0 0 0
54114 - 0 0 0 0 0 0 0 0 0 0 0 0
54115 - 0 0 0 0 0 0 0 0 0 0 0 0
54116 - 0 0 0 0 0 0 0 0 0 10 10 10
54117 - 30 30 30 74 74 74 50 50 50 2 2 6
54118 - 26 26 26 26 26 26 2 2 6 106 106 106
54119 -238 238 238 253 253 253 253 253 253 253 253 253
54120 -253 253 253 253 253 253 253 253 253 253 253 253
54121 -253 253 253 253 253 253 253 253 253 253 253 253
54122 -253 253 253 253 253 253 253 253 253 253 253 253
54123 -253 253 253 253 253 253 253 253 253 253 253 253
54124 -253 253 253 246 246 246 218 218 218 202 202 202
54125 -210 210 210 14 14 14 2 2 6 2 2 6
54126 - 30 30 30 22 22 22 2 2 6 2 2 6
54127 - 2 2 6 2 2 6 18 18 18 86 86 86
54128 - 42 42 42 14 14 14 0 0 0 0 0 0
54129 - 0 0 0 0 0 0 0 0 0 0 0 0
54130 - 0 0 0 0 0 0 0 0 0 0 0 0
54131 - 0 0 0 0 0 0 0 0 0 0 0 0
54132 - 0 0 0 0 0 0 0 0 0 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 14 14 14
54137 - 42 42 42 90 90 90 22 22 22 2 2 6
54138 - 42 42 42 2 2 6 18 18 18 218 218 218
54139 -253 253 253 253 253 253 253 253 253 253 253 253
54140 -253 253 253 253 253 253 253 253 253 253 253 253
54141 -253 253 253 253 253 253 253 253 253 253 253 253
54142 -253 253 253 253 253 253 253 253 253 253 253 253
54143 -253 253 253 253 253 253 253 253 253 253 253 253
54144 -253 253 253 253 253 253 250 250 250 221 221 221
54145 -218 218 218 101 101 101 2 2 6 14 14 14
54146 - 18 18 18 38 38 38 10 10 10 2 2 6
54147 - 2 2 6 2 2 6 2 2 6 78 78 78
54148 - 58 58 58 22 22 22 6 6 6 0 0 0
54149 - 0 0 0 0 0 0 0 0 0 0 0 0
54150 - 0 0 0 0 0 0 0 0 0 0 0 0
54151 - 0 0 0 0 0 0 0 0 0 0 0 0
54152 - 0 0 0 0 0 0 0 0 0 0 0 0
54153 - 0 0 0 0 0 0 0 0 0 0 0 0
54154 - 0 0 0 0 0 0 0 0 0 0 0 0
54155 - 0 0 0 0 0 0 0 0 0 0 0 0
54156 - 0 0 0 0 0 0 6 6 6 18 18 18
54157 - 54 54 54 82 82 82 2 2 6 26 26 26
54158 - 22 22 22 2 2 6 123 123 123 253 253 253
54159 -253 253 253 253 253 253 253 253 253 253 253 253
54160 -253 253 253 253 253 253 253 253 253 253 253 253
54161 -253 253 253 253 253 253 253 253 253 253 253 253
54162 -253 253 253 253 253 253 253 253 253 253 253 253
54163 -253 253 253 253 253 253 253 253 253 253 253 253
54164 -253 253 253 253 253 253 253 253 253 250 250 250
54165 -238 238 238 198 198 198 6 6 6 38 38 38
54166 - 58 58 58 26 26 26 38 38 38 2 2 6
54167 - 2 2 6 2 2 6 2 2 6 46 46 46
54168 - 78 78 78 30 30 30 10 10 10 0 0 0
54169 - 0 0 0 0 0 0 0 0 0 0 0 0
54170 - 0 0 0 0 0 0 0 0 0 0 0 0
54171 - 0 0 0 0 0 0 0 0 0 0 0 0
54172 - 0 0 0 0 0 0 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 10 10 10 30 30 30
54177 - 74 74 74 58 58 58 2 2 6 42 42 42
54178 - 2 2 6 22 22 22 231 231 231 253 253 253
54179 -253 253 253 253 253 253 253 253 253 253 253 253
54180 -253 253 253 253 253 253 253 253 253 250 250 250
54181 -253 253 253 253 253 253 253 253 253 253 253 253
54182 -253 253 253 253 253 253 253 253 253 253 253 253
54183 -253 253 253 253 253 253 253 253 253 253 253 253
54184 -253 253 253 253 253 253 253 253 253 253 253 253
54185 -253 253 253 246 246 246 46 46 46 38 38 38
54186 - 42 42 42 14 14 14 38 38 38 14 14 14
54187 - 2 2 6 2 2 6 2 2 6 6 6 6
54188 - 86 86 86 46 46 46 14 14 14 0 0 0
54189 - 0 0 0 0 0 0 0 0 0 0 0 0
54190 - 0 0 0 0 0 0 0 0 0 0 0 0
54191 - 0 0 0 0 0 0 0 0 0 0 0 0
54192 - 0 0 0 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 6 6 6 14 14 14 42 42 42
54197 - 90 90 90 18 18 18 18 18 18 26 26 26
54198 - 2 2 6 116 116 116 253 253 253 253 253 253
54199 -253 253 253 253 253 253 253 253 253 253 253 253
54200 -253 253 253 253 253 253 250 250 250 238 238 238
54201 -253 253 253 253 253 253 253 253 253 253 253 253
54202 -253 253 253 253 253 253 253 253 253 253 253 253
54203 -253 253 253 253 253 253 253 253 253 253 253 253
54204 -253 253 253 253 253 253 253 253 253 253 253 253
54205 -253 253 253 253 253 253 94 94 94 6 6 6
54206 - 2 2 6 2 2 6 10 10 10 34 34 34
54207 - 2 2 6 2 2 6 2 2 6 2 2 6
54208 - 74 74 74 58 58 58 22 22 22 6 6 6
54209 - 0 0 0 0 0 0 0 0 0 0 0 0
54210 - 0 0 0 0 0 0 0 0 0 0 0 0
54211 - 0 0 0 0 0 0 0 0 0 0 0 0
54212 - 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 10 10 10 26 26 26 66 66 66
54217 - 82 82 82 2 2 6 38 38 38 6 6 6
54218 - 14 14 14 210 210 210 253 253 253 253 253 253
54219 -253 253 253 253 253 253 253 253 253 253 253 253
54220 -253 253 253 253 253 253 246 246 246 242 242 242
54221 -253 253 253 253 253 253 253 253 253 253 253 253
54222 -253 253 253 253 253 253 253 253 253 253 253 253
54223 -253 253 253 253 253 253 253 253 253 253 253 253
54224 -253 253 253 253 253 253 253 253 253 253 253 253
54225 -253 253 253 253 253 253 144 144 144 2 2 6
54226 - 2 2 6 2 2 6 2 2 6 46 46 46
54227 - 2 2 6 2 2 6 2 2 6 2 2 6
54228 - 42 42 42 74 74 74 30 30 30 10 10 10
54229 - 0 0 0 0 0 0 0 0 0 0 0 0
54230 - 0 0 0 0 0 0 0 0 0 0 0 0
54231 - 0 0 0 0 0 0 0 0 0 0 0 0
54232 - 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 - 6 6 6 14 14 14 42 42 42 90 90 90
54237 - 26 26 26 6 6 6 42 42 42 2 2 6
54238 - 74 74 74 250 250 250 253 253 253 253 253 253
54239 -253 253 253 253 253 253 253 253 253 253 253 253
54240 -253 253 253 253 253 253 242 242 242 242 242 242
54241 -253 253 253 253 253 253 253 253 253 253 253 253
54242 -253 253 253 253 253 253 253 253 253 253 253 253
54243 -253 253 253 253 253 253 253 253 253 253 253 253
54244 -253 253 253 253 253 253 253 253 253 253 253 253
54245 -253 253 253 253 253 253 182 182 182 2 2 6
54246 - 2 2 6 2 2 6 2 2 6 46 46 46
54247 - 2 2 6 2 2 6 2 2 6 2 2 6
54248 - 10 10 10 86 86 86 38 38 38 10 10 10
54249 - 0 0 0 0 0 0 0 0 0 0 0 0
54250 - 0 0 0 0 0 0 0 0 0 0 0 0
54251 - 0 0 0 0 0 0 0 0 0 0 0 0
54252 - 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 - 10 10 10 26 26 26 66 66 66 82 82 82
54257 - 2 2 6 22 22 22 18 18 18 2 2 6
54258 -149 149 149 253 253 253 253 253 253 253 253 253
54259 -253 253 253 253 253 253 253 253 253 253 253 253
54260 -253 253 253 253 253 253 234 234 234 242 242 242
54261 -253 253 253 253 253 253 253 253 253 253 253 253
54262 -253 253 253 253 253 253 253 253 253 253 253 253
54263 -253 253 253 253 253 253 253 253 253 253 253 253
54264 -253 253 253 253 253 253 253 253 253 253 253 253
54265 -253 253 253 253 253 253 206 206 206 2 2 6
54266 - 2 2 6 2 2 6 2 2 6 38 38 38
54267 - 2 2 6 2 2 6 2 2 6 2 2 6
54268 - 6 6 6 86 86 86 46 46 46 14 14 14
54269 - 0 0 0 0 0 0 0 0 0 0 0 0
54270 - 0 0 0 0 0 0 0 0 0 0 0 0
54271 - 0 0 0 0 0 0 0 0 0 0 0 0
54272 - 0 0 0 0 0 0 0 0 0 0 0 0
54273 - 0 0 0 0 0 0 0 0 0 0 0 0
54274 - 0 0 0 0 0 0 0 0 0 0 0 0
54275 - 0 0 0 0 0 0 0 0 0 6 6 6
54276 - 18 18 18 46 46 46 86 86 86 18 18 18
54277 - 2 2 6 34 34 34 10 10 10 6 6 6
54278 -210 210 210 253 253 253 253 253 253 253 253 253
54279 -253 253 253 253 253 253 253 253 253 253 253 253
54280 -253 253 253 253 253 253 234 234 234 242 242 242
54281 -253 253 253 253 253 253 253 253 253 253 253 253
54282 -253 253 253 253 253 253 253 253 253 253 253 253
54283 -253 253 253 253 253 253 253 253 253 253 253 253
54284 -253 253 253 253 253 253 253 253 253 253 253 253
54285 -253 253 253 253 253 253 221 221 221 6 6 6
54286 - 2 2 6 2 2 6 6 6 6 30 30 30
54287 - 2 2 6 2 2 6 2 2 6 2 2 6
54288 - 2 2 6 82 82 82 54 54 54 18 18 18
54289 - 6 6 6 0 0 0 0 0 0 0 0 0
54290 - 0 0 0 0 0 0 0 0 0 0 0 0
54291 - 0 0 0 0 0 0 0 0 0 0 0 0
54292 - 0 0 0 0 0 0 0 0 0 0 0 0
54293 - 0 0 0 0 0 0 0 0 0 0 0 0
54294 - 0 0 0 0 0 0 0 0 0 0 0 0
54295 - 0 0 0 0 0 0 0 0 0 10 10 10
54296 - 26 26 26 66 66 66 62 62 62 2 2 6
54297 - 2 2 6 38 38 38 10 10 10 26 26 26
54298 -238 238 238 253 253 253 253 253 253 253 253 253
54299 -253 253 253 253 253 253 253 253 253 253 253 253
54300 -253 253 253 253 253 253 231 231 231 238 238 238
54301 -253 253 253 253 253 253 253 253 253 253 253 253
54302 -253 253 253 253 253 253 253 253 253 253 253 253
54303 -253 253 253 253 253 253 253 253 253 253 253 253
54304 -253 253 253 253 253 253 253 253 253 253 253 253
54305 -253 253 253 253 253 253 231 231 231 6 6 6
54306 - 2 2 6 2 2 6 10 10 10 30 30 30
54307 - 2 2 6 2 2 6 2 2 6 2 2 6
54308 - 2 2 6 66 66 66 58 58 58 22 22 22
54309 - 6 6 6 0 0 0 0 0 0 0 0 0
54310 - 0 0 0 0 0 0 0 0 0 0 0 0
54311 - 0 0 0 0 0 0 0 0 0 0 0 0
54312 - 0 0 0 0 0 0 0 0 0 0 0 0
54313 - 0 0 0 0 0 0 0 0 0 0 0 0
54314 - 0 0 0 0 0 0 0 0 0 0 0 0
54315 - 0 0 0 0 0 0 0 0 0 10 10 10
54316 - 38 38 38 78 78 78 6 6 6 2 2 6
54317 - 2 2 6 46 46 46 14 14 14 42 42 42
54318 -246 246 246 253 253 253 253 253 253 253 253 253
54319 -253 253 253 253 253 253 253 253 253 253 253 253
54320 -253 253 253 253 253 253 231 231 231 242 242 242
54321 -253 253 253 253 253 253 253 253 253 253 253 253
54322 -253 253 253 253 253 253 253 253 253 253 253 253
54323 -253 253 253 253 253 253 253 253 253 253 253 253
54324 -253 253 253 253 253 253 253 253 253 253 253 253
54325 -253 253 253 253 253 253 234 234 234 10 10 10
54326 - 2 2 6 2 2 6 22 22 22 14 14 14
54327 - 2 2 6 2 2 6 2 2 6 2 2 6
54328 - 2 2 6 66 66 66 62 62 62 22 22 22
54329 - 6 6 6 0 0 0 0 0 0 0 0 0
54330 - 0 0 0 0 0 0 0 0 0 0 0 0
54331 - 0 0 0 0 0 0 0 0 0 0 0 0
54332 - 0 0 0 0 0 0 0 0 0 0 0 0
54333 - 0 0 0 0 0 0 0 0 0 0 0 0
54334 - 0 0 0 0 0 0 0 0 0 0 0 0
54335 - 0 0 0 0 0 0 6 6 6 18 18 18
54336 - 50 50 50 74 74 74 2 2 6 2 2 6
54337 - 14 14 14 70 70 70 34 34 34 62 62 62
54338 -250 250 250 253 253 253 253 253 253 253 253 253
54339 -253 253 253 253 253 253 253 253 253 253 253 253
54340 -253 253 253 253 253 253 231 231 231 246 246 246
54341 -253 253 253 253 253 253 253 253 253 253 253 253
54342 -253 253 253 253 253 253 253 253 253 253 253 253
54343 -253 253 253 253 253 253 253 253 253 253 253 253
54344 -253 253 253 253 253 253 253 253 253 253 253 253
54345 -253 253 253 253 253 253 234 234 234 14 14 14
54346 - 2 2 6 2 2 6 30 30 30 2 2 6
54347 - 2 2 6 2 2 6 2 2 6 2 2 6
54348 - 2 2 6 66 66 66 62 62 62 22 22 22
54349 - 6 6 6 0 0 0 0 0 0 0 0 0
54350 - 0 0 0 0 0 0 0 0 0 0 0 0
54351 - 0 0 0 0 0 0 0 0 0 0 0 0
54352 - 0 0 0 0 0 0 0 0 0 0 0 0
54353 - 0 0 0 0 0 0 0 0 0 0 0 0
54354 - 0 0 0 0 0 0 0 0 0 0 0 0
54355 - 0 0 0 0 0 0 6 6 6 18 18 18
54356 - 54 54 54 62 62 62 2 2 6 2 2 6
54357 - 2 2 6 30 30 30 46 46 46 70 70 70
54358 -250 250 250 253 253 253 253 253 253 253 253 253
54359 -253 253 253 253 253 253 253 253 253 253 253 253
54360 -253 253 253 253 253 253 231 231 231 246 246 246
54361 -253 253 253 253 253 253 253 253 253 253 253 253
54362 -253 253 253 253 253 253 253 253 253 253 253 253
54363 -253 253 253 253 253 253 253 253 253 253 253 253
54364 -253 253 253 253 253 253 253 253 253 253 253 253
54365 -253 253 253 253 253 253 226 226 226 10 10 10
54366 - 2 2 6 6 6 6 30 30 30 2 2 6
54367 - 2 2 6 2 2 6 2 2 6 2 2 6
54368 - 2 2 6 66 66 66 58 58 58 22 22 22
54369 - 6 6 6 0 0 0 0 0 0 0 0 0
54370 - 0 0 0 0 0 0 0 0 0 0 0 0
54371 - 0 0 0 0 0 0 0 0 0 0 0 0
54372 - 0 0 0 0 0 0 0 0 0 0 0 0
54373 - 0 0 0 0 0 0 0 0 0 0 0 0
54374 - 0 0 0 0 0 0 0 0 0 0 0 0
54375 - 0 0 0 0 0 0 6 6 6 22 22 22
54376 - 58 58 58 62 62 62 2 2 6 2 2 6
54377 - 2 2 6 2 2 6 30 30 30 78 78 78
54378 -250 250 250 253 253 253 253 253 253 253 253 253
54379 -253 253 253 253 253 253 253 253 253 253 253 253
54380 -253 253 253 253 253 253 231 231 231 246 246 246
54381 -253 253 253 253 253 253 253 253 253 253 253 253
54382 -253 253 253 253 253 253 253 253 253 253 253 253
54383 -253 253 253 253 253 253 253 253 253 253 253 253
54384 -253 253 253 253 253 253 253 253 253 253 253 253
54385 -253 253 253 253 253 253 206 206 206 2 2 6
54386 - 22 22 22 34 34 34 18 14 6 22 22 22
54387 - 26 26 26 18 18 18 6 6 6 2 2 6
54388 - 2 2 6 82 82 82 54 54 54 18 18 18
54389 - 6 6 6 0 0 0 0 0 0 0 0 0
54390 - 0 0 0 0 0 0 0 0 0 0 0 0
54391 - 0 0 0 0 0 0 0 0 0 0 0 0
54392 - 0 0 0 0 0 0 0 0 0 0 0 0
54393 - 0 0 0 0 0 0 0 0 0 0 0 0
54394 - 0 0 0 0 0 0 0 0 0 0 0 0
54395 - 0 0 0 0 0 0 6 6 6 26 26 26
54396 - 62 62 62 106 106 106 74 54 14 185 133 11
54397 -210 162 10 121 92 8 6 6 6 62 62 62
54398 -238 238 238 253 253 253 253 253 253 253 253 253
54399 -253 253 253 253 253 253 253 253 253 253 253 253
54400 -253 253 253 253 253 253 231 231 231 246 246 246
54401 -253 253 253 253 253 253 253 253 253 253 253 253
54402 -253 253 253 253 253 253 253 253 253 253 253 253
54403 -253 253 253 253 253 253 253 253 253 253 253 253
54404 -253 253 253 253 253 253 253 253 253 253 253 253
54405 -253 253 253 253 253 253 158 158 158 18 18 18
54406 - 14 14 14 2 2 6 2 2 6 2 2 6
54407 - 6 6 6 18 18 18 66 66 66 38 38 38
54408 - 6 6 6 94 94 94 50 50 50 18 18 18
54409 - 6 6 6 0 0 0 0 0 0 0 0 0
54410 - 0 0 0 0 0 0 0 0 0 0 0 0
54411 - 0 0 0 0 0 0 0 0 0 0 0 0
54412 - 0 0 0 0 0 0 0 0 0 0 0 0
54413 - 0 0 0 0 0 0 0 0 0 0 0 0
54414 - 0 0 0 0 0 0 0 0 0 6 6 6
54415 - 10 10 10 10 10 10 18 18 18 38 38 38
54416 - 78 78 78 142 134 106 216 158 10 242 186 14
54417 -246 190 14 246 190 14 156 118 10 10 10 10
54418 - 90 90 90 238 238 238 253 253 253 253 253 253
54419 -253 253 253 253 253 253 253 253 253 253 253 253
54420 -253 253 253 253 253 253 231 231 231 250 250 250
54421 -253 253 253 253 253 253 253 253 253 253 253 253
54422 -253 253 253 253 253 253 253 253 253 253 253 253
54423 -253 253 253 253 253 253 253 253 253 253 253 253
54424 -253 253 253 253 253 253 253 253 253 246 230 190
54425 -238 204 91 238 204 91 181 142 44 37 26 9
54426 - 2 2 6 2 2 6 2 2 6 2 2 6
54427 - 2 2 6 2 2 6 38 38 38 46 46 46
54428 - 26 26 26 106 106 106 54 54 54 18 18 18
54429 - 6 6 6 0 0 0 0 0 0 0 0 0
54430 - 0 0 0 0 0 0 0 0 0 0 0 0
54431 - 0 0 0 0 0 0 0 0 0 0 0 0
54432 - 0 0 0 0 0 0 0 0 0 0 0 0
54433 - 0 0 0 0 0 0 0 0 0 0 0 0
54434 - 0 0 0 6 6 6 14 14 14 22 22 22
54435 - 30 30 30 38 38 38 50 50 50 70 70 70
54436 -106 106 106 190 142 34 226 170 11 242 186 14
54437 -246 190 14 246 190 14 246 190 14 154 114 10
54438 - 6 6 6 74 74 74 226 226 226 253 253 253
54439 -253 253 253 253 253 253 253 253 253 253 253 253
54440 -253 253 253 253 253 253 231 231 231 250 250 250
54441 -253 253 253 253 253 253 253 253 253 253 253 253
54442 -253 253 253 253 253 253 253 253 253 253 253 253
54443 -253 253 253 253 253 253 253 253 253 253 253 253
54444 -253 253 253 253 253 253 253 253 253 228 184 62
54445 -241 196 14 241 208 19 232 195 16 38 30 10
54446 - 2 2 6 2 2 6 2 2 6 2 2 6
54447 - 2 2 6 6 6 6 30 30 30 26 26 26
54448 -203 166 17 154 142 90 66 66 66 26 26 26
54449 - 6 6 6 0 0 0 0 0 0 0 0 0
54450 - 0 0 0 0 0 0 0 0 0 0 0 0
54451 - 0 0 0 0 0 0 0 0 0 0 0 0
54452 - 0 0 0 0 0 0 0 0 0 0 0 0
54453 - 0 0 0 0 0 0 0 0 0 0 0 0
54454 - 6 6 6 18 18 18 38 38 38 58 58 58
54455 - 78 78 78 86 86 86 101 101 101 123 123 123
54456 -175 146 61 210 150 10 234 174 13 246 186 14
54457 -246 190 14 246 190 14 246 190 14 238 190 10
54458 -102 78 10 2 2 6 46 46 46 198 198 198
54459 -253 253 253 253 253 253 253 253 253 253 253 253
54460 -253 253 253 253 253 253 234 234 234 242 242 242
54461 -253 253 253 253 253 253 253 253 253 253 253 253
54462 -253 253 253 253 253 253 253 253 253 253 253 253
54463 -253 253 253 253 253 253 253 253 253 253 253 253
54464 -253 253 253 253 253 253 253 253 253 224 178 62
54465 -242 186 14 241 196 14 210 166 10 22 18 6
54466 - 2 2 6 2 2 6 2 2 6 2 2 6
54467 - 2 2 6 2 2 6 6 6 6 121 92 8
54468 -238 202 15 232 195 16 82 82 82 34 34 34
54469 - 10 10 10 0 0 0 0 0 0 0 0 0
54470 - 0 0 0 0 0 0 0 0 0 0 0 0
54471 - 0 0 0 0 0 0 0 0 0 0 0 0
54472 - 0 0 0 0 0 0 0 0 0 0 0 0
54473 - 0 0 0 0 0 0 0 0 0 0 0 0
54474 - 14 14 14 38 38 38 70 70 70 154 122 46
54475 -190 142 34 200 144 11 197 138 11 197 138 11
54476 -213 154 11 226 170 11 242 186 14 246 190 14
54477 -246 190 14 246 190 14 246 190 14 246 190 14
54478 -225 175 15 46 32 6 2 2 6 22 22 22
54479 -158 158 158 250 250 250 253 253 253 253 253 253
54480 -253 253 253 253 253 253 253 253 253 253 253 253
54481 -253 253 253 253 253 253 253 253 253 253 253 253
54482 -253 253 253 253 253 253 253 253 253 253 253 253
54483 -253 253 253 253 253 253 253 253 253 253 253 253
54484 -253 253 253 250 250 250 242 242 242 224 178 62
54485 -239 182 13 236 186 11 213 154 11 46 32 6
54486 - 2 2 6 2 2 6 2 2 6 2 2 6
54487 - 2 2 6 2 2 6 61 42 6 225 175 15
54488 -238 190 10 236 186 11 112 100 78 42 42 42
54489 - 14 14 14 0 0 0 0 0 0 0 0 0
54490 - 0 0 0 0 0 0 0 0 0 0 0 0
54491 - 0 0 0 0 0 0 0 0 0 0 0 0
54492 - 0 0 0 0 0 0 0 0 0 0 0 0
54493 - 0 0 0 0 0 0 0 0 0 6 6 6
54494 - 22 22 22 54 54 54 154 122 46 213 154 11
54495 -226 170 11 230 174 11 226 170 11 226 170 11
54496 -236 178 12 242 186 14 246 190 14 246 190 14
54497 -246 190 14 246 190 14 246 190 14 246 190 14
54498 -241 196 14 184 144 12 10 10 10 2 2 6
54499 - 6 6 6 116 116 116 242 242 242 253 253 253
54500 -253 253 253 253 253 253 253 253 253 253 253 253
54501 -253 253 253 253 253 253 253 253 253 253 253 253
54502 -253 253 253 253 253 253 253 253 253 253 253 253
54503 -253 253 253 253 253 253 253 253 253 253 253 253
54504 -253 253 253 231 231 231 198 198 198 214 170 54
54505 -236 178 12 236 178 12 210 150 10 137 92 6
54506 - 18 14 6 2 2 6 2 2 6 2 2 6
54507 - 6 6 6 70 47 6 200 144 11 236 178 12
54508 -239 182 13 239 182 13 124 112 88 58 58 58
54509 - 22 22 22 6 6 6 0 0 0 0 0 0
54510 - 0 0 0 0 0 0 0 0 0 0 0 0
54511 - 0 0 0 0 0 0 0 0 0 0 0 0
54512 - 0 0 0 0 0 0 0 0 0 0 0 0
54513 - 0 0 0 0 0 0 0 0 0 10 10 10
54514 - 30 30 30 70 70 70 180 133 36 226 170 11
54515 -239 182 13 242 186 14 242 186 14 246 186 14
54516 -246 190 14 246 190 14 246 190 14 246 190 14
54517 -246 190 14 246 190 14 246 190 14 246 190 14
54518 -246 190 14 232 195 16 98 70 6 2 2 6
54519 - 2 2 6 2 2 6 66 66 66 221 221 221
54520 -253 253 253 253 253 253 253 253 253 253 253 253
54521 -253 253 253 253 253 253 253 253 253 253 253 253
54522 -253 253 253 253 253 253 253 253 253 253 253 253
54523 -253 253 253 253 253 253 253 253 253 253 253 253
54524 -253 253 253 206 206 206 198 198 198 214 166 58
54525 -230 174 11 230 174 11 216 158 10 192 133 9
54526 -163 110 8 116 81 8 102 78 10 116 81 8
54527 -167 114 7 197 138 11 226 170 11 239 182 13
54528 -242 186 14 242 186 14 162 146 94 78 78 78
54529 - 34 34 34 14 14 14 6 6 6 0 0 0
54530 - 0 0 0 0 0 0 0 0 0 0 0 0
54531 - 0 0 0 0 0 0 0 0 0 0 0 0
54532 - 0 0 0 0 0 0 0 0 0 0 0 0
54533 - 0 0 0 0 0 0 0 0 0 6 6 6
54534 - 30 30 30 78 78 78 190 142 34 226 170 11
54535 -239 182 13 246 190 14 246 190 14 246 190 14
54536 -246 190 14 246 190 14 246 190 14 246 190 14
54537 -246 190 14 246 190 14 246 190 14 246 190 14
54538 -246 190 14 241 196 14 203 166 17 22 18 6
54539 - 2 2 6 2 2 6 2 2 6 38 38 38
54540 -218 218 218 253 253 253 253 253 253 253 253 253
54541 -253 253 253 253 253 253 253 253 253 253 253 253
54542 -253 253 253 253 253 253 253 253 253 253 253 253
54543 -253 253 253 253 253 253 253 253 253 253 253 253
54544 -250 250 250 206 206 206 198 198 198 202 162 69
54545 -226 170 11 236 178 12 224 166 10 210 150 10
54546 -200 144 11 197 138 11 192 133 9 197 138 11
54547 -210 150 10 226 170 11 242 186 14 246 190 14
54548 -246 190 14 246 186 14 225 175 15 124 112 88
54549 - 62 62 62 30 30 30 14 14 14 6 6 6
54550 - 0 0 0 0 0 0 0 0 0 0 0 0
54551 - 0 0 0 0 0 0 0 0 0 0 0 0
54552 - 0 0 0 0 0 0 0 0 0 0 0 0
54553 - 0 0 0 0 0 0 0 0 0 10 10 10
54554 - 30 30 30 78 78 78 174 135 50 224 166 10
54555 -239 182 13 246 190 14 246 190 14 246 190 14
54556 -246 190 14 246 190 14 246 190 14 246 190 14
54557 -246 190 14 246 190 14 246 190 14 246 190 14
54558 -246 190 14 246 190 14 241 196 14 139 102 15
54559 - 2 2 6 2 2 6 2 2 6 2 2 6
54560 - 78 78 78 250 250 250 253 253 253 253 253 253
54561 -253 253 253 253 253 253 253 253 253 253 253 253
54562 -253 253 253 253 253 253 253 253 253 253 253 253
54563 -253 253 253 253 253 253 253 253 253 253 253 253
54564 -250 250 250 214 214 214 198 198 198 190 150 46
54565 -219 162 10 236 178 12 234 174 13 224 166 10
54566 -216 158 10 213 154 11 213 154 11 216 158 10
54567 -226 170 11 239 182 13 246 190 14 246 190 14
54568 -246 190 14 246 190 14 242 186 14 206 162 42
54569 -101 101 101 58 58 58 30 30 30 14 14 14
54570 - 6 6 6 0 0 0 0 0 0 0 0 0
54571 - 0 0 0 0 0 0 0 0 0 0 0 0
54572 - 0 0 0 0 0 0 0 0 0 0 0 0
54573 - 0 0 0 0 0 0 0 0 0 10 10 10
54574 - 30 30 30 74 74 74 174 135 50 216 158 10
54575 -236 178 12 246 190 14 246 190 14 246 190 14
54576 -246 190 14 246 190 14 246 190 14 246 190 14
54577 -246 190 14 246 190 14 246 190 14 246 190 14
54578 -246 190 14 246 190 14 241 196 14 226 184 13
54579 - 61 42 6 2 2 6 2 2 6 2 2 6
54580 - 22 22 22 238 238 238 253 253 253 253 253 253
54581 -253 253 253 253 253 253 253 253 253 253 253 253
54582 -253 253 253 253 253 253 253 253 253 253 253 253
54583 -253 253 253 253 253 253 253 253 253 253 253 253
54584 -253 253 253 226 226 226 187 187 187 180 133 36
54585 -216 158 10 236 178 12 239 182 13 236 178 12
54586 -230 174 11 226 170 11 226 170 11 230 174 11
54587 -236 178 12 242 186 14 246 190 14 246 190 14
54588 -246 190 14 246 190 14 246 186 14 239 182 13
54589 -206 162 42 106 106 106 66 66 66 34 34 34
54590 - 14 14 14 6 6 6 0 0 0 0 0 0
54591 - 0 0 0 0 0 0 0 0 0 0 0 0
54592 - 0 0 0 0 0 0 0 0 0 0 0 0
54593 - 0 0 0 0 0 0 0 0 0 6 6 6
54594 - 26 26 26 70 70 70 163 133 67 213 154 11
54595 -236 178 12 246 190 14 246 190 14 246 190 14
54596 -246 190 14 246 190 14 246 190 14 246 190 14
54597 -246 190 14 246 190 14 246 190 14 246 190 14
54598 -246 190 14 246 190 14 246 190 14 241 196 14
54599 -190 146 13 18 14 6 2 2 6 2 2 6
54600 - 46 46 46 246 246 246 253 253 253 253 253 253
54601 -253 253 253 253 253 253 253 253 253 253 253 253
54602 -253 253 253 253 253 253 253 253 253 253 253 253
54603 -253 253 253 253 253 253 253 253 253 253 253 253
54604 -253 253 253 221 221 221 86 86 86 156 107 11
54605 -216 158 10 236 178 12 242 186 14 246 186 14
54606 -242 186 14 239 182 13 239 182 13 242 186 14
54607 -242 186 14 246 186 14 246 190 14 246 190 14
54608 -246 190 14 246 190 14 246 190 14 246 190 14
54609 -242 186 14 225 175 15 142 122 72 66 66 66
54610 - 30 30 30 10 10 10 0 0 0 0 0 0
54611 - 0 0 0 0 0 0 0 0 0 0 0 0
54612 - 0 0 0 0 0 0 0 0 0 0 0 0
54613 - 0 0 0 0 0 0 0 0 0 6 6 6
54614 - 26 26 26 70 70 70 163 133 67 210 150 10
54615 -236 178 12 246 190 14 246 190 14 246 190 14
54616 -246 190 14 246 190 14 246 190 14 246 190 14
54617 -246 190 14 246 190 14 246 190 14 246 190 14
54618 -246 190 14 246 190 14 246 190 14 246 190 14
54619 -232 195 16 121 92 8 34 34 34 106 106 106
54620 -221 221 221 253 253 253 253 253 253 253 253 253
54621 -253 253 253 253 253 253 253 253 253 253 253 253
54622 -253 253 253 253 253 253 253 253 253 253 253 253
54623 -253 253 253 253 253 253 253 253 253 253 253 253
54624 -242 242 242 82 82 82 18 14 6 163 110 8
54625 -216 158 10 236 178 12 242 186 14 246 190 14
54626 -246 190 14 246 190 14 246 190 14 246 190 14
54627 -246 190 14 246 190 14 246 190 14 246 190 14
54628 -246 190 14 246 190 14 246 190 14 246 190 14
54629 -246 190 14 246 190 14 242 186 14 163 133 67
54630 - 46 46 46 18 18 18 6 6 6 0 0 0
54631 - 0 0 0 0 0 0 0 0 0 0 0 0
54632 - 0 0 0 0 0 0 0 0 0 0 0 0
54633 - 0 0 0 0 0 0 0 0 0 10 10 10
54634 - 30 30 30 78 78 78 163 133 67 210 150 10
54635 -236 178 12 246 186 14 246 190 14 246 190 14
54636 -246 190 14 246 190 14 246 190 14 246 190 14
54637 -246 190 14 246 190 14 246 190 14 246 190 14
54638 -246 190 14 246 190 14 246 190 14 246 190 14
54639 -241 196 14 215 174 15 190 178 144 253 253 253
54640 -253 253 253 253 253 253 253 253 253 253 253 253
54641 -253 253 253 253 253 253 253 253 253 253 253 253
54642 -253 253 253 253 253 253 253 253 253 253 253 253
54643 -253 253 253 253 253 253 253 253 253 218 218 218
54644 - 58 58 58 2 2 6 22 18 6 167 114 7
54645 -216 158 10 236 178 12 246 186 14 246 190 14
54646 -246 190 14 246 190 14 246 190 14 246 190 14
54647 -246 190 14 246 190 14 246 190 14 246 190 14
54648 -246 190 14 246 190 14 246 190 14 246 190 14
54649 -246 190 14 246 186 14 242 186 14 190 150 46
54650 - 54 54 54 22 22 22 6 6 6 0 0 0
54651 - 0 0 0 0 0 0 0 0 0 0 0 0
54652 - 0 0 0 0 0 0 0 0 0 0 0 0
54653 - 0 0 0 0 0 0 0 0 0 14 14 14
54654 - 38 38 38 86 86 86 180 133 36 213 154 11
54655 -236 178 12 246 186 14 246 190 14 246 190 14
54656 -246 190 14 246 190 14 246 190 14 246 190 14
54657 -246 190 14 246 190 14 246 190 14 246 190 14
54658 -246 190 14 246 190 14 246 190 14 246 190 14
54659 -246 190 14 232 195 16 190 146 13 214 214 214
54660 -253 253 253 253 253 253 253 253 253 253 253 253
54661 -253 253 253 253 253 253 253 253 253 253 253 253
54662 -253 253 253 253 253 253 253 253 253 253 253 253
54663 -253 253 253 250 250 250 170 170 170 26 26 26
54664 - 2 2 6 2 2 6 37 26 9 163 110 8
54665 -219 162 10 239 182 13 246 186 14 246 190 14
54666 -246 190 14 246 190 14 246 190 14 246 190 14
54667 -246 190 14 246 190 14 246 190 14 246 190 14
54668 -246 190 14 246 190 14 246 190 14 246 190 14
54669 -246 186 14 236 178 12 224 166 10 142 122 72
54670 - 46 46 46 18 18 18 6 6 6 0 0 0
54671 - 0 0 0 0 0 0 0 0 0 0 0 0
54672 - 0 0 0 0 0 0 0 0 0 0 0 0
54673 - 0 0 0 0 0 0 6 6 6 18 18 18
54674 - 50 50 50 109 106 95 192 133 9 224 166 10
54675 -242 186 14 246 190 14 246 190 14 246 190 14
54676 -246 190 14 246 190 14 246 190 14 246 190 14
54677 -246 190 14 246 190 14 246 190 14 246 190 14
54678 -246 190 14 246 190 14 246 190 14 246 190 14
54679 -242 186 14 226 184 13 210 162 10 142 110 46
54680 -226 226 226 253 253 253 253 253 253 253 253 253
54681 -253 253 253 253 253 253 253 253 253 253 253 253
54682 -253 253 253 253 253 253 253 253 253 253 253 253
54683 -198 198 198 66 66 66 2 2 6 2 2 6
54684 - 2 2 6 2 2 6 50 34 6 156 107 11
54685 -219 162 10 239 182 13 246 186 14 246 190 14
54686 -246 190 14 246 190 14 246 190 14 246 190 14
54687 -246 190 14 246 190 14 246 190 14 246 190 14
54688 -246 190 14 246 190 14 246 190 14 242 186 14
54689 -234 174 13 213 154 11 154 122 46 66 66 66
54690 - 30 30 30 10 10 10 0 0 0 0 0 0
54691 - 0 0 0 0 0 0 0 0 0 0 0 0
54692 - 0 0 0 0 0 0 0 0 0 0 0 0
54693 - 0 0 0 0 0 0 6 6 6 22 22 22
54694 - 58 58 58 154 121 60 206 145 10 234 174 13
54695 -242 186 14 246 186 14 246 190 14 246 190 14
54696 -246 190 14 246 190 14 246 190 14 246 190 14
54697 -246 190 14 246 190 14 246 190 14 246 190 14
54698 -246 190 14 246 190 14 246 190 14 246 190 14
54699 -246 186 14 236 178 12 210 162 10 163 110 8
54700 - 61 42 6 138 138 138 218 218 218 250 250 250
54701 -253 253 253 253 253 253 253 253 253 250 250 250
54702 -242 242 242 210 210 210 144 144 144 66 66 66
54703 - 6 6 6 2 2 6 2 2 6 2 2 6
54704 - 2 2 6 2 2 6 61 42 6 163 110 8
54705 -216 158 10 236 178 12 246 190 14 246 190 14
54706 -246 190 14 246 190 14 246 190 14 246 190 14
54707 -246 190 14 246 190 14 246 190 14 246 190 14
54708 -246 190 14 239 182 13 230 174 11 216 158 10
54709 -190 142 34 124 112 88 70 70 70 38 38 38
54710 - 18 18 18 6 6 6 0 0 0 0 0 0
54711 - 0 0 0 0 0 0 0 0 0 0 0 0
54712 - 0 0 0 0 0 0 0 0 0 0 0 0
54713 - 0 0 0 0 0 0 6 6 6 22 22 22
54714 - 62 62 62 168 124 44 206 145 10 224 166 10
54715 -236 178 12 239 182 13 242 186 14 242 186 14
54716 -246 186 14 246 190 14 246 190 14 246 190 14
54717 -246 190 14 246 190 14 246 190 14 246 190 14
54718 -246 190 14 246 190 14 246 190 14 246 190 14
54719 -246 190 14 236 178 12 216 158 10 175 118 6
54720 - 80 54 7 2 2 6 6 6 6 30 30 30
54721 - 54 54 54 62 62 62 50 50 50 38 38 38
54722 - 14 14 14 2 2 6 2 2 6 2 2 6
54723 - 2 2 6 2 2 6 2 2 6 2 2 6
54724 - 2 2 6 6 6 6 80 54 7 167 114 7
54725 -213 154 11 236 178 12 246 190 14 246 190 14
54726 -246 190 14 246 190 14 246 190 14 246 190 14
54727 -246 190 14 242 186 14 239 182 13 239 182 13
54728 -230 174 11 210 150 10 174 135 50 124 112 88
54729 - 82 82 82 54 54 54 34 34 34 18 18 18
54730 - 6 6 6 0 0 0 0 0 0 0 0 0
54731 - 0 0 0 0 0 0 0 0 0 0 0 0
54732 - 0 0 0 0 0 0 0 0 0 0 0 0
54733 - 0 0 0 0 0 0 6 6 6 18 18 18
54734 - 50 50 50 158 118 36 192 133 9 200 144 11
54735 -216 158 10 219 162 10 224 166 10 226 170 11
54736 -230 174 11 236 178 12 239 182 13 239 182 13
54737 -242 186 14 246 186 14 246 190 14 246 190 14
54738 -246 190 14 246 190 14 246 190 14 246 190 14
54739 -246 186 14 230 174 11 210 150 10 163 110 8
54740 -104 69 6 10 10 10 2 2 6 2 2 6
54741 - 2 2 6 2 2 6 2 2 6 2 2 6
54742 - 2 2 6 2 2 6 2 2 6 2 2 6
54743 - 2 2 6 2 2 6 2 2 6 2 2 6
54744 - 2 2 6 6 6 6 91 60 6 167 114 7
54745 -206 145 10 230 174 11 242 186 14 246 190 14
54746 -246 190 14 246 190 14 246 186 14 242 186 14
54747 -239 182 13 230 174 11 224 166 10 213 154 11
54748 -180 133 36 124 112 88 86 86 86 58 58 58
54749 - 38 38 38 22 22 22 10 10 10 6 6 6
54750 - 0 0 0 0 0 0 0 0 0 0 0 0
54751 - 0 0 0 0 0 0 0 0 0 0 0 0
54752 - 0 0 0 0 0 0 0 0 0 0 0 0
54753 - 0 0 0 0 0 0 0 0 0 14 14 14
54754 - 34 34 34 70 70 70 138 110 50 158 118 36
54755 -167 114 7 180 123 7 192 133 9 197 138 11
54756 -200 144 11 206 145 10 213 154 11 219 162 10
54757 -224 166 10 230 174 11 239 182 13 242 186 14
54758 -246 186 14 246 186 14 246 186 14 246 186 14
54759 -239 182 13 216 158 10 185 133 11 152 99 6
54760 -104 69 6 18 14 6 2 2 6 2 2 6
54761 - 2 2 6 2 2 6 2 2 6 2 2 6
54762 - 2 2 6 2 2 6 2 2 6 2 2 6
54763 - 2 2 6 2 2 6 2 2 6 2 2 6
54764 - 2 2 6 6 6 6 80 54 7 152 99 6
54765 -192 133 9 219 162 10 236 178 12 239 182 13
54766 -246 186 14 242 186 14 239 182 13 236 178 12
54767 -224 166 10 206 145 10 192 133 9 154 121 60
54768 - 94 94 94 62 62 62 42 42 42 22 22 22
54769 - 14 14 14 6 6 6 0 0 0 0 0 0
54770 - 0 0 0 0 0 0 0 0 0 0 0 0
54771 - 0 0 0 0 0 0 0 0 0 0 0 0
54772 - 0 0 0 0 0 0 0 0 0 0 0 0
54773 - 0 0 0 0 0 0 0 0 0 6 6 6
54774 - 18 18 18 34 34 34 58 58 58 78 78 78
54775 -101 98 89 124 112 88 142 110 46 156 107 11
54776 -163 110 8 167 114 7 175 118 6 180 123 7
54777 -185 133 11 197 138 11 210 150 10 219 162 10
54778 -226 170 11 236 178 12 236 178 12 234 174 13
54779 -219 162 10 197 138 11 163 110 8 130 83 6
54780 - 91 60 6 10 10 10 2 2 6 2 2 6
54781 - 18 18 18 38 38 38 38 38 38 38 38 38
54782 - 38 38 38 38 38 38 38 38 38 38 38 38
54783 - 38 38 38 38 38 38 26 26 26 2 2 6
54784 - 2 2 6 6 6 6 70 47 6 137 92 6
54785 -175 118 6 200 144 11 219 162 10 230 174 11
54786 -234 174 13 230 174 11 219 162 10 210 150 10
54787 -192 133 9 163 110 8 124 112 88 82 82 82
54788 - 50 50 50 30 30 30 14 14 14 6 6 6
54789 - 0 0 0 0 0 0 0 0 0 0 0 0
54790 - 0 0 0 0 0 0 0 0 0 0 0 0
54791 - 0 0 0 0 0 0 0 0 0 0 0 0
54792 - 0 0 0 0 0 0 0 0 0 0 0 0
54793 - 0 0 0 0 0 0 0 0 0 0 0 0
54794 - 6 6 6 14 14 14 22 22 22 34 34 34
54795 - 42 42 42 58 58 58 74 74 74 86 86 86
54796 -101 98 89 122 102 70 130 98 46 121 87 25
54797 -137 92 6 152 99 6 163 110 8 180 123 7
54798 -185 133 11 197 138 11 206 145 10 200 144 11
54799 -180 123 7 156 107 11 130 83 6 104 69 6
54800 - 50 34 6 54 54 54 110 110 110 101 98 89
54801 - 86 86 86 82 82 82 78 78 78 78 78 78
54802 - 78 78 78 78 78 78 78 78 78 78 78 78
54803 - 78 78 78 82 82 82 86 86 86 94 94 94
54804 -106 106 106 101 101 101 86 66 34 124 80 6
54805 -156 107 11 180 123 7 192 133 9 200 144 11
54806 -206 145 10 200 144 11 192 133 9 175 118 6
54807 -139 102 15 109 106 95 70 70 70 42 42 42
54808 - 22 22 22 10 10 10 0 0 0 0 0 0
54809 - 0 0 0 0 0 0 0 0 0 0 0 0
54810 - 0 0 0 0 0 0 0 0 0 0 0 0
54811 - 0 0 0 0 0 0 0 0 0 0 0 0
54812 - 0 0 0 0 0 0 0 0 0 0 0 0
54813 - 0 0 0 0 0 0 0 0 0 0 0 0
54814 - 0 0 0 0 0 0 6 6 6 10 10 10
54815 - 14 14 14 22 22 22 30 30 30 38 38 38
54816 - 50 50 50 62 62 62 74 74 74 90 90 90
54817 -101 98 89 112 100 78 121 87 25 124 80 6
54818 -137 92 6 152 99 6 152 99 6 152 99 6
54819 -138 86 6 124 80 6 98 70 6 86 66 30
54820 -101 98 89 82 82 82 58 58 58 46 46 46
54821 - 38 38 38 34 34 34 34 34 34 34 34 34
54822 - 34 34 34 34 34 34 34 34 34 34 34 34
54823 - 34 34 34 34 34 34 38 38 38 42 42 42
54824 - 54 54 54 82 82 82 94 86 76 91 60 6
54825 -134 86 6 156 107 11 167 114 7 175 118 6
54826 -175 118 6 167 114 7 152 99 6 121 87 25
54827 -101 98 89 62 62 62 34 34 34 18 18 18
54828 - 6 6 6 0 0 0 0 0 0 0 0 0
54829 - 0 0 0 0 0 0 0 0 0 0 0 0
54830 - 0 0 0 0 0 0 0 0 0 0 0 0
54831 - 0 0 0 0 0 0 0 0 0 0 0 0
54832 - 0 0 0 0 0 0 0 0 0 0 0 0
54833 - 0 0 0 0 0 0 0 0 0 0 0 0
54834 - 0 0 0 0 0 0 0 0 0 0 0 0
54835 - 0 0 0 6 6 6 6 6 6 10 10 10
54836 - 18 18 18 22 22 22 30 30 30 42 42 42
54837 - 50 50 50 66 66 66 86 86 86 101 98 89
54838 -106 86 58 98 70 6 104 69 6 104 69 6
54839 -104 69 6 91 60 6 82 62 34 90 90 90
54840 - 62 62 62 38 38 38 22 22 22 14 14 14
54841 - 10 10 10 10 10 10 10 10 10 10 10 10
54842 - 10 10 10 10 10 10 6 6 6 10 10 10
54843 - 10 10 10 10 10 10 10 10 10 14 14 14
54844 - 22 22 22 42 42 42 70 70 70 89 81 66
54845 - 80 54 7 104 69 6 124 80 6 137 92 6
54846 -134 86 6 116 81 8 100 82 52 86 86 86
54847 - 58 58 58 30 30 30 14 14 14 6 6 6
54848 - 0 0 0 0 0 0 0 0 0 0 0 0
54849 - 0 0 0 0 0 0 0 0 0 0 0 0
54850 - 0 0 0 0 0 0 0 0 0 0 0 0
54851 - 0 0 0 0 0 0 0 0 0 0 0 0
54852 - 0 0 0 0 0 0 0 0 0 0 0 0
54853 - 0 0 0 0 0 0 0 0 0 0 0 0
54854 - 0 0 0 0 0 0 0 0 0 0 0 0
54855 - 0 0 0 0 0 0 0 0 0 0 0 0
54856 - 0 0 0 6 6 6 10 10 10 14 14 14
54857 - 18 18 18 26 26 26 38 38 38 54 54 54
54858 - 70 70 70 86 86 86 94 86 76 89 81 66
54859 - 89 81 66 86 86 86 74 74 74 50 50 50
54860 - 30 30 30 14 14 14 6 6 6 0 0 0
54861 - 0 0 0 0 0 0 0 0 0 0 0 0
54862 - 0 0 0 0 0 0 0 0 0 0 0 0
54863 - 0 0 0 0 0 0 0 0 0 0 0 0
54864 - 6 6 6 18 18 18 34 34 34 58 58 58
54865 - 82 82 82 89 81 66 89 81 66 89 81 66
54866 - 94 86 66 94 86 76 74 74 74 50 50 50
54867 - 26 26 26 14 14 14 6 6 6 0 0 0
54868 - 0 0 0 0 0 0 0 0 0 0 0 0
54869 - 0 0 0 0 0 0 0 0 0 0 0 0
54870 - 0 0 0 0 0 0 0 0 0 0 0 0
54871 - 0 0 0 0 0 0 0 0 0 0 0 0
54872 - 0 0 0 0 0 0 0 0 0 0 0 0
54873 - 0 0 0 0 0 0 0 0 0 0 0 0
54874 - 0 0 0 0 0 0 0 0 0 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 - 6 6 6 6 6 6 14 14 14 18 18 18
54878 - 30 30 30 38 38 38 46 46 46 54 54 54
54879 - 50 50 50 42 42 42 30 30 30 18 18 18
54880 - 10 10 10 0 0 0 0 0 0 0 0 0
54881 - 0 0 0 0 0 0 0 0 0 0 0 0
54882 - 0 0 0 0 0 0 0 0 0 0 0 0
54883 - 0 0 0 0 0 0 0 0 0 0 0 0
54884 - 0 0 0 6 6 6 14 14 14 26 26 26
54885 - 38 38 38 50 50 50 58 58 58 58 58 58
54886 - 54 54 54 42 42 42 30 30 30 18 18 18
54887 - 10 10 10 0 0 0 0 0 0 0 0 0
54888 - 0 0 0 0 0 0 0 0 0 0 0 0
54889 - 0 0 0 0 0 0 0 0 0 0 0 0
54890 - 0 0 0 0 0 0 0 0 0 0 0 0
54891 - 0 0 0 0 0 0 0 0 0 0 0 0
54892 - 0 0 0 0 0 0 0 0 0 0 0 0
54893 - 0 0 0 0 0 0 0 0 0 0 0 0
54894 - 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6
54898 - 6 6 6 10 10 10 14 14 14 18 18 18
54899 - 18 18 18 14 14 14 10 10 10 6 6 6
54900 - 0 0 0 0 0 0 0 0 0 0 0 0
54901 - 0 0 0 0 0 0 0 0 0 0 0 0
54902 - 0 0 0 0 0 0 0 0 0 0 0 0
54903 - 0 0 0 0 0 0 0 0 0 0 0 0
54904 - 0 0 0 0 0 0 0 0 0 6 6 6
54905 - 14 14 14 18 18 18 22 22 22 22 22 22
54906 - 18 18 18 14 14 14 10 10 10 6 6 6
54907 - 0 0 0 0 0 0 0 0 0 0 0 0
54908 - 0 0 0 0 0 0 0 0 0 0 0 0
54909 - 0 0 0 0 0 0 0 0 0 0 0 0
54910 - 0 0 0 0 0 0 0 0 0 0 0 0
54911 - 0 0 0 0 0 0 0 0 0 0 0 0
54912 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54913 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54914 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54915 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54916 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54917 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54918 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54919 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54920 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54921 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54922 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54923 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54924 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54925 +4 4 4 4 4 4
54926 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54927 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54928 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54929 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54930 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54931 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54932 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54933 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54934 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54935 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54936 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54937 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54938 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54939 +4 4 4 4 4 4
54940 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54941 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54942 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54943 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54944 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54945 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54946 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54947 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54948 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54949 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54950 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54951 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54952 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54953 +4 4 4 4 4 4
54954 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54955 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54956 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54957 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54958 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54959 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54960 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54961 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54962 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54963 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54964 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54965 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54966 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54967 +4 4 4 4 4 4
54968 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54969 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54970 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54971 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54972 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54973 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54974 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54975 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54976 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54977 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54978 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54979 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54980 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54981 +4 4 4 4 4 4
54982 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54983 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54984 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54985 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54986 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54987 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54988 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54989 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54990 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54991 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54992 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54993 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54994 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54995 +4 4 4 4 4 4
54996 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54997 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54998 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54999 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55000 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
55001 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
55002 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55003 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55004 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55005 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
55006 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
55007 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
55008 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55009 +4 4 4 4 4 4
55010 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55011 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55012 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55013 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55014 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
55015 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
55016 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55017 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55018 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55019 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
55020 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
55021 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
55022 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55023 +4 4 4 4 4 4
55024 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55025 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55026 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55027 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55028 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
55029 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
55030 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
55031 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55032 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55033 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
55034 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
55035 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
55036 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
55037 +4 4 4 4 4 4
55038 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55039 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55040 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55041 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
55042 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
55043 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
55044 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
55045 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55046 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
55047 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
55048 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
55049 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
55050 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
55051 +4 4 4 4 4 4
55052 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55053 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55054 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55055 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
55056 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
55057 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
55058 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
55059 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55060 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
55061 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
55062 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
55063 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
55064 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
55065 +4 4 4 4 4 4
55066 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55067 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55068 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
55069 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
55070 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
55071 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
55072 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
55073 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
55074 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
55075 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
55076 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
55077 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
55078 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
55079 +4 4 4 4 4 4
55080 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55081 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55082 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
55083 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
55084 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
55085 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
55086 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
55087 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
55088 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
55089 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
55090 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
55091 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
55092 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
55093 +4 4 4 4 4 4
55094 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55095 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55096 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
55097 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
55098 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
55099 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
55100 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
55101 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
55102 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
55103 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
55104 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
55105 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
55106 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
55107 +4 4 4 4 4 4
55108 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55109 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55110 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
55111 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
55112 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
55113 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
55114 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
55115 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
55116 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
55117 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
55118 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
55119 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
55120 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
55121 +4 4 4 4 4 4
55122 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55123 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55124 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
55125 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
55126 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
55127 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
55128 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
55129 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
55130 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
55131 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
55132 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
55133 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
55134 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
55135 +4 4 4 4 4 4
55136 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55137 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
55138 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
55139 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
55140 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
55141 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
55142 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
55143 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
55144 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
55145 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
55146 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
55147 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
55148 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
55149 +4 4 4 4 4 4
55150 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55151 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
55152 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
55153 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
55154 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
55155 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
55156 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
55157 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
55158 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
55159 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
55160 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
55161 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
55162 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
55163 +0 0 0 4 4 4
55164 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
55165 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
55166 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
55167 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
55168 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
55169 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
55170 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
55171 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
55172 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
55173 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
55174 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
55175 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
55176 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
55177 +2 0 0 0 0 0
55178 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
55179 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
55180 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
55181 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
55182 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
55183 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
55184 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
55185 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
55186 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
55187 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
55188 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
55189 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
55190 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
55191 +37 38 37 0 0 0
55192 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
55193 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
55194 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
55195 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
55196 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
55197 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
55198 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
55199 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
55200 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
55201 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
55202 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
55203 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
55204 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
55205 +85 115 134 4 0 0
55206 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
55207 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
55208 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
55209 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
55210 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
55211 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
55212 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
55213 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
55214 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
55215 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
55216 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
55217 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
55218 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
55219 +60 73 81 4 0 0
55220 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
55221 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
55222 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
55223 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
55224 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
55225 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
55226 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
55227 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
55228 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
55229 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
55230 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
55231 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
55232 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
55233 +16 19 21 4 0 0
55234 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
55235 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
55236 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
55237 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
55238 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
55239 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
55240 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
55241 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
55242 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
55243 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
55244 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
55245 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
55246 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
55247 +4 0 0 4 3 3
55248 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
55249 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
55250 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
55251 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
55252 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
55253 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
55254 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
55255 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
55256 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
55257 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
55258 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
55259 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
55260 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
55261 +3 2 2 4 4 4
55262 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
55263 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
55264 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
55265 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
55266 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
55267 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
55268 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
55269 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
55270 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
55271 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
55272 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
55273 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
55274 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
55275 +4 4 4 4 4 4
55276 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
55277 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
55278 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
55279 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
55280 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
55281 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
55282 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
55283 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
55284 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
55285 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
55286 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
55287 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
55288 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
55289 +4 4 4 4 4 4
55290 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
55291 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
55292 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
55293 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
55294 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
55295 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
55296 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
55297 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
55298 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
55299 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
55300 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
55301 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
55302 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
55303 +5 5 5 5 5 5
55304 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
55305 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
55306 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
55307 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
55308 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
55309 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55310 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
55311 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
55312 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
55313 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
55314 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
55315 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
55316 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
55317 +5 5 5 4 4 4
55318 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
55319 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
55320 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
55321 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
55322 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
55323 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
55324 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
55325 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
55326 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
55327 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
55328 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
55329 +4 0 0 4 0 0 5 5 5 5 5 5 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
55332 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
55333 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
55334 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
55335 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
55336 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
55337 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55338 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55339 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
55340 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
55341 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
55342 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
55343 +3 3 3 5 5 5 6 6 6 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
55346 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
55347 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
55348 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
55349 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
55350 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
55351 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
55352 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
55353 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
55354 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
55355 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
55356 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 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
55360 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
55361 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
55362 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
55363 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
55364 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
55365 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55366 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
55367 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
55368 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
55369 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
55370 +6 6 6 4 0 0 4 0 0 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 +4 4 4 4 4 4
55374 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
55375 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
55376 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
55377 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
55378 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
55379 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
55380 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
55381 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
55382 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
55383 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
55384 +4 0 0 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
55387 +4 4 4 4 4 4
55388 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
55389 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
55390 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
55391 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
55392 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
55393 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
55394 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
55395 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
55396 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
55397 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
55398 +6 6 6 4 0 0 6 6 6 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 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55401 +4 4 4 4 4 4
55402 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
55403 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
55404 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
55405 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
55406 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
55407 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
55408 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
55409 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
55410 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
55411 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
55412 +4 0 0 3 2 2 5 5 5 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 4 4 4
55414 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55415 +4 4 4 4 4 4
55416 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
55417 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
55418 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
55419 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
55420 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
55421 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
55422 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
55423 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
55424 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
55425 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
55426 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55427 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55428 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55429 +4 4 4 4 4 4
55430 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
55431 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
55432 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
55433 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
55434 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55435 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
55436 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
55437 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
55438 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
55439 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
55440 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55441 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55442 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55443 +4 4 4 4 4 4
55444 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
55445 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
55446 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
55447 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
55448 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55449 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
55450 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
55451 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
55452 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
55453 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
55454 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55455 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55456 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55457 +4 4 4 4 4 4
55458 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
55459 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
55460 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
55461 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
55462 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55463 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
55464 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
55465 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
55466 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
55467 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55468 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55469 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55470 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55471 +4 4 4 4 4 4
55472 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
55473 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
55474 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
55475 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
55476 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
55477 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
55478 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
55479 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
55480 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55481 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55482 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55483 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55484 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55485 +4 4 4 4 4 4
55486 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
55487 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
55488 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
55489 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
55490 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55491 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
55492 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
55493 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
55494 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
55495 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55496 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55497 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55498 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55499 +4 4 4 4 4 4
55500 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
55501 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
55502 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
55503 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
55504 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
55505 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
55506 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
55507 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
55508 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55509 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55510 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55511 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55512 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55513 +4 4 4 4 4 4
55514 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
55515 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
55516 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
55517 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
55518 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
55519 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
55520 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
55521 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
55522 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
55523 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55524 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55525 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55526 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55527 +4 4 4 4 4 4
55528 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
55529 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
55530 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
55531 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
55532 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
55533 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
55534 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
55535 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
55536 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55537 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55538 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55539 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55540 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55541 +4 4 4 4 4 4
55542 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
55543 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
55544 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
55545 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
55546 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
55547 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
55548 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
55549 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
55550 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
55551 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55552 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55553 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55554 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55555 +4 4 4 4 4 4
55556 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
55557 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
55558 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
55559 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
55560 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
55561 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
55562 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
55563 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
55564 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55565 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55566 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55567 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55568 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55569 +4 4 4 4 4 4
55570 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
55571 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
55572 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
55573 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
55574 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
55575 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
55576 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
55577 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
55578 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
55579 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55580 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55581 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55582 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55583 +4 4 4 4 4 4
55584 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
55585 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
55586 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
55587 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
55588 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
55589 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
55590 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55591 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
55592 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
55593 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55594 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55595 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55596 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55597 +4 4 4 4 4 4
55598 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
55599 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
55600 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
55601 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
55602 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
55603 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
55604 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
55605 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
55606 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
55607 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55608 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55609 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55610 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55611 +4 4 4 4 4 4
55612 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
55613 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
55614 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
55615 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
55616 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
55617 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
55618 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
55619 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
55620 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
55621 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55622 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55623 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55624 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55625 +4 4 4 4 4 4
55626 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
55627 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
55628 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
55629 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
55630 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
55631 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
55632 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
55633 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
55634 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
55635 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55636 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55637 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55638 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55639 +4 4 4 4 4 4
55640 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
55641 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
55642 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
55643 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
55644 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
55645 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
55646 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
55647 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
55648 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
55649 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55650 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55651 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55652 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55653 +4 4 4 4 4 4
55654 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
55655 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
55656 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
55657 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
55658 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
55659 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
55660 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
55661 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
55662 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
55663 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
55664 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55665 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55666 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55667 +4 4 4 4 4 4
55668 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
55669 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
55670 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
55671 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
55672 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
55673 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
55674 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
55675 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
55676 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
55677 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
55678 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
55679 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55680 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55681 +4 4 4 4 4 4
55682 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
55683 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
55684 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
55685 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
55686 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
55687 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
55688 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
55689 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
55690 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
55691 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
55692 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55693 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55694 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55695 +4 4 4 4 4 4
55696 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
55697 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
55698 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
55699 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
55700 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
55701 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
55702 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55703 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
55704 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
55705 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
55706 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55707 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55708 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55709 +4 4 4 4 4 4
55710 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
55711 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
55712 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
55713 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
55714 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
55715 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
55716 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
55717 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
55718 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
55719 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
55720 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55721 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55722 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55723 +4 4 4 4 4 4
55724 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
55725 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
55726 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
55727 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
55728 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
55729 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
55730 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
55731 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
55732 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
55733 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
55734 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55735 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55736 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55737 +4 4 4 4 4 4
55738 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
55739 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
55740 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
55741 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
55742 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
55743 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
55744 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
55745 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
55746 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
55747 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
55748 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55749 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55750 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55751 +4 4 4 4 4 4
55752 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
55753 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
55754 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
55755 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
55756 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
55757 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
55758 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
55759 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
55760 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
55761 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
55762 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55763 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55764 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55765 +4 4 4 4 4 4
55766 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
55767 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
55768 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
55769 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
55770 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
55771 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
55772 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
55773 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
55774 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
55775 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55776 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55777 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55778 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55779 +4 4 4 4 4 4
55780 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
55781 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
55782 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
55783 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
55784 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
55785 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
55786 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
55787 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
55788 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
55789 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55790 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55791 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55792 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55793 +4 4 4 4 4 4
55794 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
55795 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
55796 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
55797 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
55798 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
55799 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
55800 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
55801 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
55802 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
55803 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55804 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55805 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55806 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55807 +4 4 4 4 4 4
55808 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
55809 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
55810 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
55811 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
55812 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
55813 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
55814 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
55815 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
55816 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55817 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55818 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55819 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55820 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55821 +4 4 4 4 4 4
55822 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
55823 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
55824 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
55825 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
55826 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
55827 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
55828 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
55829 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
55830 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55831 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55832 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55833 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55834 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55835 +4 4 4 4 4 4
55836 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
55837 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
55838 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
55839 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
55840 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
55841 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
55842 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
55843 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
55844 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55845 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55846 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55847 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55848 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55849 +4 4 4 4 4 4
55850 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
55851 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
55852 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
55853 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
55854 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
55855 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
55856 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
55857 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
55858 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55859 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55860 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55861 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55862 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55863 +4 4 4 4 4 4
55864 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55865 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
55866 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
55867 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
55868 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
55869 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
55870 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
55871 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
55872 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55873 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55874 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55875 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55876 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55877 +4 4 4 4 4 4
55878 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55879 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
55880 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
55881 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
55882 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
55883 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
55884 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
55885 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55886 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55887 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55888 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55889 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55890 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55891 +4 4 4 4 4 4
55892 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55893 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55894 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
55895 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
55896 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
55897 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
55898 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
55899 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
55900 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55901 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55902 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55903 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55904 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55905 +4 4 4 4 4 4
55906 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55907 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55908 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
55909 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
55910 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
55911 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
55912 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
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 4 4 4 4 4 4 4 4 4 4 4 4
55915 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55916 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55917 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55918 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55919 +4 4 4 4 4 4
55920 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55921 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55922 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55923 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
55924 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
55925 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
55926 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
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 4 4 4 4 4 4 4 4 4 4 4 4
55929 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55930 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55931 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55932 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55933 +4 4 4 4 4 4
55934 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55935 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55936 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55937 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
55938 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
55939 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
55940 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
55943 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55944 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55945 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55946 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55947 +4 4 4 4 4 4
55948 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55949 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55950 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55951 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
55952 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
55953 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
55954 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
55957 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55958 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55959 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55960 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55961 +4 4 4 4 4 4
55962 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55963 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55964 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55965 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
55966 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
55967 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
55968 +6 6 6 4 3 3 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
55971 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55972 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55973 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55974 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55975 +4 4 4 4 4 4
55976 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55977 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55978 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55979 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55980 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
55981 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
55982 +4 3 3 5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
55985 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55986 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55987 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55988 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55989 +4 4 4 4 4 4
55990 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55991 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55992 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55993 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
55994 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
55995 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
55996 +5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
55999 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56000 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56001 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56002 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56003 +4 4 4 4 4 4
56004 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56005 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56006 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56007 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56008 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
56009 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
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 4 4 4 4 4 4 4 4 4 4 4 4
56013 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56014 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56015 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56016 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56017 +4 4 4 4 4 4
56018 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56019 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56020 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56021 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56022 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
56023 +5 5 5 4 3 3 5 5 5 5 5 5 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 4 4 4 4 4 4 4 4 4 4 4 4
56027 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56028 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56029 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56030 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
56031 +4 4 4 4 4 4
56032 diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
56033 index fef20db..d28b1ab 100644
56034 --- a/drivers/xen/xenfs/xenstored.c
56035 +++ b/drivers/xen/xenfs/xenstored.c
56036 @@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
56037 static int xsd_kva_open(struct inode *inode, struct file *file)
56038 {
56039 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
56040 +#ifdef CONFIG_GRKERNSEC_HIDESYM
56041 + NULL);
56042 +#else
56043 xen_store_interface);
56044 +#endif
56045 +
56046 if (!file->private_data)
56047 return -ENOMEM;
56048 return 0;
56049 diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
56050 index c71e886..61d3d44b 100644
56051 --- a/fs/9p/vfs_addr.c
56052 +++ b/fs/9p/vfs_addr.c
56053 @@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
56054
56055 retval = v9fs_file_write_internal(inode,
56056 v9inode->writeback_fid,
56057 - (__force const char __user *)buffer,
56058 + (const char __force_user *)buffer,
56059 len, &offset, 0);
56060 if (retval > 0)
56061 retval = 0;
56062 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
56063 index 53161ec..e261d8a 100644
56064 --- a/fs/9p/vfs_inode.c
56065 +++ b/fs/9p/vfs_inode.c
56066 @@ -1312,7 +1312,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
56067 void
56068 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
56069 {
56070 - char *s = nd_get_link(nd);
56071 + const char *s = nd_get_link(nd);
56072
56073 p9_debug(P9_DEBUG_VFS, " %s %s\n",
56074 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
56075 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
56076 index 370b24c..ff0be7b 100644
56077 --- a/fs/Kconfig.binfmt
56078 +++ b/fs/Kconfig.binfmt
56079 @@ -103,7 +103,7 @@ config HAVE_AOUT
56080
56081 config BINFMT_AOUT
56082 tristate "Kernel support for a.out and ECOFF binaries"
56083 - depends on HAVE_AOUT
56084 + depends on HAVE_AOUT && BROKEN
56085 ---help---
56086 A.out (Assembler.OUTput) is a set of formats for libraries and
56087 executables used in the earliest versions of UNIX. Linux used
56088 diff --git a/fs/afs/inode.c b/fs/afs/inode.c
56089 index 2946712..f737435 100644
56090 --- a/fs/afs/inode.c
56091 +++ b/fs/afs/inode.c
56092 @@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
56093 struct afs_vnode *vnode;
56094 struct super_block *sb;
56095 struct inode *inode;
56096 - static atomic_t afs_autocell_ino;
56097 + static atomic_unchecked_t afs_autocell_ino;
56098
56099 _enter("{%x:%u},%*.*s,",
56100 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
56101 @@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
56102 data.fid.unique = 0;
56103 data.fid.vnode = 0;
56104
56105 - inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
56106 + inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
56107 afs_iget5_autocell_test, afs_iget5_set,
56108 &data);
56109 if (!inode) {
56110 diff --git a/fs/aio.c b/fs/aio.c
56111 index e609e15..c9fcd97 100644
56112 --- a/fs/aio.c
56113 +++ b/fs/aio.c
56114 @@ -380,7 +380,7 @@ static int aio_setup_ring(struct kioctx *ctx)
56115 size += sizeof(struct io_event) * nr_events;
56116
56117 nr_pages = PFN_UP(size);
56118 - if (nr_pages < 0)
56119 + if (nr_pages <= 0)
56120 return -EINVAL;
56121
56122 file = aio_private_file(ctx, nr_pages);
56123 diff --git a/fs/attr.c b/fs/attr.c
56124 index 6530ced..4a827e2 100644
56125 --- a/fs/attr.c
56126 +++ b/fs/attr.c
56127 @@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
56128 unsigned long limit;
56129
56130 limit = rlimit(RLIMIT_FSIZE);
56131 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
56132 if (limit != RLIM_INFINITY && offset > limit)
56133 goto out_sig;
56134 if (offset > inode->i_sb->s_maxbytes)
56135 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
56136 index 116fd38..c04182da 100644
56137 --- a/fs/autofs4/waitq.c
56138 +++ b/fs/autofs4/waitq.c
56139 @@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
56140 {
56141 unsigned long sigpipe, flags;
56142 mm_segment_t fs;
56143 - const char *data = (const char *)addr;
56144 + const char __user *data = (const char __force_user *)addr;
56145 ssize_t wr = 0;
56146
56147 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
56148 @@ -340,6 +340,10 @@ static int validate_request(struct autofs_wait_queue **wait,
56149 return 1;
56150 }
56151
56152 +#ifdef CONFIG_GRKERNSEC_HIDESYM
56153 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
56154 +#endif
56155 +
56156 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
56157 enum autofs_notify notify)
56158 {
56159 @@ -385,7 +389,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
56160
56161 /* If this is a direct mount request create a dummy name */
56162 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
56163 +#ifdef CONFIG_GRKERNSEC_HIDESYM
56164 + /* this name does get written to userland via autofs4_write() */
56165 + qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
56166 +#else
56167 qstr.len = sprintf(name, "%p", dentry);
56168 +#endif
56169 else {
56170 qstr.len = autofs4_getpath(sbi, dentry, &name);
56171 if (!qstr.len) {
56172 diff --git a/fs/befs/endian.h b/fs/befs/endian.h
56173 index 2722387..56059b5 100644
56174 --- a/fs/befs/endian.h
56175 +++ b/fs/befs/endian.h
56176 @@ -11,7 +11,7 @@
56177
56178 #include <asm/byteorder.h>
56179
56180 -static inline u64
56181 +static inline u64 __intentional_overflow(-1)
56182 fs64_to_cpu(const struct super_block *sb, fs64 n)
56183 {
56184 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
56185 @@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
56186 return (__force fs64)cpu_to_be64(n);
56187 }
56188
56189 -static inline u32
56190 +static inline u32 __intentional_overflow(-1)
56191 fs32_to_cpu(const struct super_block *sb, fs32 n)
56192 {
56193 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
56194 @@ -47,7 +47,7 @@ cpu_to_fs32(const struct super_block *sb, u32 n)
56195 return (__force fs32)cpu_to_be32(n);
56196 }
56197
56198 -static inline u16
56199 +static inline u16 __intentional_overflow(-1)
56200 fs16_to_cpu(const struct super_block *sb, fs16 n)
56201 {
56202 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
56203 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
56204 index ca0ba15..0fa3257 100644
56205 --- a/fs/binfmt_aout.c
56206 +++ b/fs/binfmt_aout.c
56207 @@ -16,6 +16,7 @@
56208 #include <linux/string.h>
56209 #include <linux/fs.h>
56210 #include <linux/file.h>
56211 +#include <linux/security.h>
56212 #include <linux/stat.h>
56213 #include <linux/fcntl.h>
56214 #include <linux/ptrace.h>
56215 @@ -58,6 +59,8 @@ static int aout_core_dump(struct coredump_params *cprm)
56216 #endif
56217 # define START_STACK(u) ((void __user *)u.start_stack)
56218
56219 + memset(&dump, 0, sizeof(dump));
56220 +
56221 fs = get_fs();
56222 set_fs(KERNEL_DS);
56223 has_dumped = 1;
56224 @@ -68,10 +71,12 @@ static int aout_core_dump(struct coredump_params *cprm)
56225
56226 /* If the size of the dump file exceeds the rlimit, then see what would happen
56227 if we wrote the stack, but not the data area. */
56228 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
56229 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
56230 dump.u_dsize = 0;
56231
56232 /* Make sure we have enough room to write the stack and data areas. */
56233 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
56234 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
56235 dump.u_ssize = 0;
56236
56237 @@ -232,6 +237,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
56238 rlim = rlimit(RLIMIT_DATA);
56239 if (rlim >= RLIM_INFINITY)
56240 rlim = ~0;
56241 +
56242 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
56243 if (ex.a_data + ex.a_bss > rlim)
56244 return -ENOMEM;
56245
56246 @@ -264,6 +271,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
56247
56248 install_exec_creds(bprm);
56249
56250 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56251 + current->mm->pax_flags = 0UL;
56252 +#endif
56253 +
56254 +#ifdef CONFIG_PAX_PAGEEXEC
56255 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
56256 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
56257 +
56258 +#ifdef CONFIG_PAX_EMUTRAMP
56259 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
56260 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
56261 +#endif
56262 +
56263 +#ifdef CONFIG_PAX_MPROTECT
56264 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
56265 + current->mm->pax_flags |= MF_PAX_MPROTECT;
56266 +#endif
56267 +
56268 + }
56269 +#endif
56270 +
56271 if (N_MAGIC(ex) == OMAGIC) {
56272 unsigned long text_addr, map_size;
56273 loff_t pos;
56274 @@ -321,7 +349,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
56275 }
56276
56277 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
56278 - PROT_READ | PROT_WRITE | PROT_EXEC,
56279 + PROT_READ | PROT_WRITE,
56280 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
56281 fd_offset + ex.a_text);
56282 if (error != N_DATADDR(ex)) {
56283 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
56284 index aa3cb62..bc53934 100644
56285 --- a/fs/binfmt_elf.c
56286 +++ b/fs/binfmt_elf.c
56287 @@ -34,6 +34,7 @@
56288 #include <linux/utsname.h>
56289 #include <linux/coredump.h>
56290 #include <linux/sched.h>
56291 +#include <linux/xattr.h>
56292 #include <asm/uaccess.h>
56293 #include <asm/param.h>
56294 #include <asm/page.h>
56295 @@ -47,7 +48,7 @@
56296
56297 static int load_elf_binary(struct linux_binprm *bprm);
56298 static unsigned long elf_map(struct file *, unsigned long, struct elf_phdr *,
56299 - int, int, unsigned long);
56300 + int, int, unsigned long) __intentional_overflow(-1);
56301
56302 #ifdef CONFIG_USELIB
56303 static int load_elf_library(struct file *);
56304 @@ -65,6 +66,14 @@ static int elf_core_dump(struct coredump_params *cprm);
56305 #define elf_core_dump NULL
56306 #endif
56307
56308 +#ifdef CONFIG_PAX_MPROTECT
56309 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
56310 +#endif
56311 +
56312 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56313 +static void elf_handle_mmap(struct file *file);
56314 +#endif
56315 +
56316 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
56317 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
56318 #else
56319 @@ -84,6 +93,15 @@ static struct linux_binfmt elf_format = {
56320 .load_binary = load_elf_binary,
56321 .load_shlib = load_elf_library,
56322 .core_dump = elf_core_dump,
56323 +
56324 +#ifdef CONFIG_PAX_MPROTECT
56325 + .handle_mprotect= elf_handle_mprotect,
56326 +#endif
56327 +
56328 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56329 + .handle_mmap = elf_handle_mmap,
56330 +#endif
56331 +
56332 .min_coredump = ELF_EXEC_PAGESIZE,
56333 };
56334
56335 @@ -91,6 +109,8 @@ static struct linux_binfmt elf_format = {
56336
56337 static int set_brk(unsigned long start, unsigned long end)
56338 {
56339 + unsigned long e = end;
56340 +
56341 start = ELF_PAGEALIGN(start);
56342 end = ELF_PAGEALIGN(end);
56343 if (end > start) {
56344 @@ -99,7 +119,7 @@ static int set_brk(unsigned long start, unsigned long end)
56345 if (BAD_ADDR(addr))
56346 return addr;
56347 }
56348 - current->mm->start_brk = current->mm->brk = end;
56349 + current->mm->start_brk = current->mm->brk = e;
56350 return 0;
56351 }
56352
56353 @@ -160,12 +180,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56354 elf_addr_t __user *u_rand_bytes;
56355 const char *k_platform = ELF_PLATFORM;
56356 const char *k_base_platform = ELF_BASE_PLATFORM;
56357 - unsigned char k_rand_bytes[16];
56358 + u32 k_rand_bytes[4];
56359 int items;
56360 elf_addr_t *elf_info;
56361 int ei_index = 0;
56362 const struct cred *cred = current_cred();
56363 struct vm_area_struct *vma;
56364 + unsigned long saved_auxv[AT_VECTOR_SIZE];
56365
56366 /*
56367 * In some cases (e.g. Hyper-Threading), we want to avoid L1
56368 @@ -207,8 +228,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56369 * Generate 16 random bytes for userspace PRNG seeding.
56370 */
56371 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
56372 - u_rand_bytes = (elf_addr_t __user *)
56373 - STACK_ALLOC(p, sizeof(k_rand_bytes));
56374 + prandom_seed(k_rand_bytes[0] ^ prandom_u32());
56375 + prandom_seed(k_rand_bytes[1] ^ prandom_u32());
56376 + prandom_seed(k_rand_bytes[2] ^ prandom_u32());
56377 + prandom_seed(k_rand_bytes[3] ^ prandom_u32());
56378 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
56379 + u_rand_bytes = (elf_addr_t __user *) p;
56380 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
56381 return -EFAULT;
56382
56383 @@ -323,9 +348,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
56384 return -EFAULT;
56385 current->mm->env_end = p;
56386
56387 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
56388 +
56389 /* Put the elf_info on the stack in the right place. */
56390 sp = (elf_addr_t __user *)envp + 1;
56391 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
56392 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
56393 return -EFAULT;
56394 return 0;
56395 }
56396 @@ -393,15 +420,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
56397 an ELF header */
56398
56399 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56400 - struct file *interpreter, unsigned long *interp_map_addr,
56401 - unsigned long no_base)
56402 + struct file *interpreter, unsigned long no_base)
56403 {
56404 struct elf_phdr *elf_phdata;
56405 struct elf_phdr *eppnt;
56406 - unsigned long load_addr = 0;
56407 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
56408 int load_addr_set = 0;
56409 unsigned long last_bss = 0, elf_bss = 0;
56410 - unsigned long error = ~0UL;
56411 + unsigned long error = -EINVAL;
56412 unsigned long total_size;
56413 int retval, i, size;
56414
56415 @@ -447,6 +473,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56416 goto out_close;
56417 }
56418
56419 +#ifdef CONFIG_PAX_SEGMEXEC
56420 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
56421 + pax_task_size = SEGMEXEC_TASK_SIZE;
56422 +#endif
56423 +
56424 eppnt = elf_phdata;
56425 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
56426 if (eppnt->p_type == PT_LOAD) {
56427 @@ -470,8 +501,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56428 map_addr = elf_map(interpreter, load_addr + vaddr,
56429 eppnt, elf_prot, elf_type, total_size);
56430 total_size = 0;
56431 - if (!*interp_map_addr)
56432 - *interp_map_addr = map_addr;
56433 error = map_addr;
56434 if (BAD_ADDR(map_addr))
56435 goto out_close;
56436 @@ -490,8 +519,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56437 k = load_addr + eppnt->p_vaddr;
56438 if (BAD_ADDR(k) ||
56439 eppnt->p_filesz > eppnt->p_memsz ||
56440 - eppnt->p_memsz > TASK_SIZE ||
56441 - TASK_SIZE - eppnt->p_memsz < k) {
56442 + eppnt->p_memsz > pax_task_size ||
56443 + pax_task_size - eppnt->p_memsz < k) {
56444 error = -ENOMEM;
56445 goto out_close;
56446 }
56447 @@ -530,9 +559,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
56448 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
56449
56450 /* Map the last of the bss segment */
56451 - error = vm_brk(elf_bss, last_bss - elf_bss);
56452 - if (BAD_ADDR(error))
56453 - goto out_close;
56454 + if (last_bss > elf_bss) {
56455 + error = vm_brk(elf_bss, last_bss - elf_bss);
56456 + if (BAD_ADDR(error))
56457 + goto out_close;
56458 + }
56459 }
56460
56461 error = load_addr;
56462 @@ -543,6 +574,336 @@ out:
56463 return error;
56464 }
56465
56466 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
56467 +#ifdef CONFIG_PAX_SOFTMODE
56468 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
56469 +{
56470 + unsigned long pax_flags = 0UL;
56471 +
56472 +#ifdef CONFIG_PAX_PAGEEXEC
56473 + if (elf_phdata->p_flags & PF_PAGEEXEC)
56474 + pax_flags |= MF_PAX_PAGEEXEC;
56475 +#endif
56476 +
56477 +#ifdef CONFIG_PAX_SEGMEXEC
56478 + if (elf_phdata->p_flags & PF_SEGMEXEC)
56479 + pax_flags |= MF_PAX_SEGMEXEC;
56480 +#endif
56481 +
56482 +#ifdef CONFIG_PAX_EMUTRAMP
56483 + if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
56484 + pax_flags |= MF_PAX_EMUTRAMP;
56485 +#endif
56486 +
56487 +#ifdef CONFIG_PAX_MPROTECT
56488 + if (elf_phdata->p_flags & PF_MPROTECT)
56489 + pax_flags |= MF_PAX_MPROTECT;
56490 +#endif
56491 +
56492 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56493 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
56494 + pax_flags |= MF_PAX_RANDMMAP;
56495 +#endif
56496 +
56497 + return pax_flags;
56498 +}
56499 +#endif
56500 +
56501 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
56502 +{
56503 + unsigned long pax_flags = 0UL;
56504 +
56505 +#ifdef CONFIG_PAX_PAGEEXEC
56506 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
56507 + pax_flags |= MF_PAX_PAGEEXEC;
56508 +#endif
56509 +
56510 +#ifdef CONFIG_PAX_SEGMEXEC
56511 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
56512 + pax_flags |= MF_PAX_SEGMEXEC;
56513 +#endif
56514 +
56515 +#ifdef CONFIG_PAX_EMUTRAMP
56516 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
56517 + pax_flags |= MF_PAX_EMUTRAMP;
56518 +#endif
56519 +
56520 +#ifdef CONFIG_PAX_MPROTECT
56521 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
56522 + pax_flags |= MF_PAX_MPROTECT;
56523 +#endif
56524 +
56525 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56526 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
56527 + pax_flags |= MF_PAX_RANDMMAP;
56528 +#endif
56529 +
56530 + return pax_flags;
56531 +}
56532 +#endif
56533 +
56534 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
56535 +#ifdef CONFIG_PAX_SOFTMODE
56536 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
56537 +{
56538 + unsigned long pax_flags = 0UL;
56539 +
56540 +#ifdef CONFIG_PAX_PAGEEXEC
56541 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
56542 + pax_flags |= MF_PAX_PAGEEXEC;
56543 +#endif
56544 +
56545 +#ifdef CONFIG_PAX_SEGMEXEC
56546 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
56547 + pax_flags |= MF_PAX_SEGMEXEC;
56548 +#endif
56549 +
56550 +#ifdef CONFIG_PAX_EMUTRAMP
56551 + if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
56552 + pax_flags |= MF_PAX_EMUTRAMP;
56553 +#endif
56554 +
56555 +#ifdef CONFIG_PAX_MPROTECT
56556 + if (pax_flags_softmode & MF_PAX_MPROTECT)
56557 + pax_flags |= MF_PAX_MPROTECT;
56558 +#endif
56559 +
56560 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56561 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
56562 + pax_flags |= MF_PAX_RANDMMAP;
56563 +#endif
56564 +
56565 + return pax_flags;
56566 +}
56567 +#endif
56568 +
56569 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
56570 +{
56571 + unsigned long pax_flags = 0UL;
56572 +
56573 +#ifdef CONFIG_PAX_PAGEEXEC
56574 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
56575 + pax_flags |= MF_PAX_PAGEEXEC;
56576 +#endif
56577 +
56578 +#ifdef CONFIG_PAX_SEGMEXEC
56579 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
56580 + pax_flags |= MF_PAX_SEGMEXEC;
56581 +#endif
56582 +
56583 +#ifdef CONFIG_PAX_EMUTRAMP
56584 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
56585 + pax_flags |= MF_PAX_EMUTRAMP;
56586 +#endif
56587 +
56588 +#ifdef CONFIG_PAX_MPROTECT
56589 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
56590 + pax_flags |= MF_PAX_MPROTECT;
56591 +#endif
56592 +
56593 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
56594 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
56595 + pax_flags |= MF_PAX_RANDMMAP;
56596 +#endif
56597 +
56598 + return pax_flags;
56599 +}
56600 +#endif
56601 +
56602 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56603 +static unsigned long pax_parse_defaults(void)
56604 +{
56605 + unsigned long pax_flags = 0UL;
56606 +
56607 +#ifdef CONFIG_PAX_SOFTMODE
56608 + if (pax_softmode)
56609 + return pax_flags;
56610 +#endif
56611 +
56612 +#ifdef CONFIG_PAX_PAGEEXEC
56613 + pax_flags |= MF_PAX_PAGEEXEC;
56614 +#endif
56615 +
56616 +#ifdef CONFIG_PAX_SEGMEXEC
56617 + pax_flags |= MF_PAX_SEGMEXEC;
56618 +#endif
56619 +
56620 +#ifdef CONFIG_PAX_MPROTECT
56621 + pax_flags |= MF_PAX_MPROTECT;
56622 +#endif
56623 +
56624 +#ifdef CONFIG_PAX_RANDMMAP
56625 + if (randomize_va_space)
56626 + pax_flags |= MF_PAX_RANDMMAP;
56627 +#endif
56628 +
56629 + return pax_flags;
56630 +}
56631 +
56632 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
56633 +{
56634 + unsigned long pax_flags = PAX_PARSE_FLAGS_FALLBACK;
56635 +
56636 +#ifdef CONFIG_PAX_EI_PAX
56637 +
56638 +#ifdef CONFIG_PAX_SOFTMODE
56639 + if (pax_softmode)
56640 + return pax_flags;
56641 +#endif
56642 +
56643 + pax_flags = 0UL;
56644 +
56645 +#ifdef CONFIG_PAX_PAGEEXEC
56646 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
56647 + pax_flags |= MF_PAX_PAGEEXEC;
56648 +#endif
56649 +
56650 +#ifdef CONFIG_PAX_SEGMEXEC
56651 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
56652 + pax_flags |= MF_PAX_SEGMEXEC;
56653 +#endif
56654 +
56655 +#ifdef CONFIG_PAX_EMUTRAMP
56656 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
56657 + pax_flags |= MF_PAX_EMUTRAMP;
56658 +#endif
56659 +
56660 +#ifdef CONFIG_PAX_MPROTECT
56661 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
56662 + pax_flags |= MF_PAX_MPROTECT;
56663 +#endif
56664 +
56665 +#ifdef CONFIG_PAX_ASLR
56666 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
56667 + pax_flags |= MF_PAX_RANDMMAP;
56668 +#endif
56669 +
56670 +#endif
56671 +
56672 + return pax_flags;
56673 +
56674 +}
56675 +
56676 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
56677 +{
56678 +
56679 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
56680 + unsigned long i;
56681 +
56682 + for (i = 0UL; i < elf_ex->e_phnum; i++)
56683 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
56684 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
56685 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
56686 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
56687 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
56688 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
56689 + return PAX_PARSE_FLAGS_FALLBACK;
56690 +
56691 +#ifdef CONFIG_PAX_SOFTMODE
56692 + if (pax_softmode)
56693 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
56694 + else
56695 +#endif
56696 +
56697 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
56698 + break;
56699 + }
56700 +#endif
56701 +
56702 + return PAX_PARSE_FLAGS_FALLBACK;
56703 +}
56704 +
56705 +static unsigned long pax_parse_xattr_pax(struct file * const file)
56706 +{
56707 +
56708 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
56709 + ssize_t xattr_size, i;
56710 + unsigned char xattr_value[sizeof("pemrs") - 1];
56711 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
56712 +
56713 + xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
56714 + if (xattr_size < 0 || xattr_size > sizeof xattr_value)
56715 + return PAX_PARSE_FLAGS_FALLBACK;
56716 +
56717 + for (i = 0; i < xattr_size; i++)
56718 + switch (xattr_value[i]) {
56719 + default:
56720 + return PAX_PARSE_FLAGS_FALLBACK;
56721 +
56722 +#define parse_flag(option1, option2, flag) \
56723 + case option1: \
56724 + if (pax_flags_hardmode & MF_PAX_##flag) \
56725 + return PAX_PARSE_FLAGS_FALLBACK;\
56726 + pax_flags_hardmode |= MF_PAX_##flag; \
56727 + break; \
56728 + case option2: \
56729 + if (pax_flags_softmode & MF_PAX_##flag) \
56730 + return PAX_PARSE_FLAGS_FALLBACK;\
56731 + pax_flags_softmode |= MF_PAX_##flag; \
56732 + break;
56733 +
56734 + parse_flag('p', 'P', PAGEEXEC);
56735 + parse_flag('e', 'E', EMUTRAMP);
56736 + parse_flag('m', 'M', MPROTECT);
56737 + parse_flag('r', 'R', RANDMMAP);
56738 + parse_flag('s', 'S', SEGMEXEC);
56739 +
56740 +#undef parse_flag
56741 + }
56742 +
56743 + if (pax_flags_hardmode & pax_flags_softmode)
56744 + return PAX_PARSE_FLAGS_FALLBACK;
56745 +
56746 +#ifdef CONFIG_PAX_SOFTMODE
56747 + if (pax_softmode)
56748 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
56749 + else
56750 +#endif
56751 +
56752 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
56753 +#else
56754 + return PAX_PARSE_FLAGS_FALLBACK;
56755 +#endif
56756 +
56757 +}
56758 +
56759 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
56760 +{
56761 + unsigned long pax_flags, ei_pax_flags, pt_pax_flags, xattr_pax_flags;
56762 +
56763 + pax_flags = pax_parse_defaults();
56764 + ei_pax_flags = pax_parse_ei_pax(elf_ex);
56765 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
56766 + xattr_pax_flags = pax_parse_xattr_pax(file);
56767 +
56768 + if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
56769 + xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
56770 + pt_pax_flags != xattr_pax_flags)
56771 + return -EINVAL;
56772 + if (xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
56773 + pax_flags = xattr_pax_flags;
56774 + else if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
56775 + pax_flags = pt_pax_flags;
56776 + else if (ei_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
56777 + pax_flags = ei_pax_flags;
56778 +
56779 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
56780 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
56781 + if ((__supported_pte_mask & _PAGE_NX))
56782 + pax_flags &= ~MF_PAX_SEGMEXEC;
56783 + else
56784 + pax_flags &= ~MF_PAX_PAGEEXEC;
56785 + }
56786 +#endif
56787 +
56788 + if (0 > pax_check_flags(&pax_flags))
56789 + return -EINVAL;
56790 +
56791 + current->mm->pax_flags = pax_flags;
56792 + return 0;
56793 +}
56794 +#endif
56795 +
56796 /*
56797 * These are the functions used to load ELF style executables and shared
56798 * libraries. There is no binary dependent code anywhere else.
56799 @@ -556,6 +917,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
56800 {
56801 unsigned int random_variable = 0;
56802
56803 +#ifdef CONFIG_PAX_RANDUSTACK
56804 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
56805 + return stack_top - current->mm->delta_stack;
56806 +#endif
56807 +
56808 if ((current->flags & PF_RANDOMIZE) &&
56809 !(current->personality & ADDR_NO_RANDOMIZE)) {
56810 random_variable = get_random_int() & STACK_RND_MASK;
56811 @@ -574,7 +940,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
56812 unsigned long load_addr = 0, load_bias = 0;
56813 int load_addr_set = 0;
56814 char * elf_interpreter = NULL;
56815 - unsigned long error;
56816 + unsigned long error = 0;
56817 struct elf_phdr *elf_ppnt, *elf_phdata;
56818 unsigned long elf_bss, elf_brk;
56819 int retval, i;
56820 @@ -589,6 +955,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
56821 struct elfhdr elf_ex;
56822 struct elfhdr interp_elf_ex;
56823 } *loc;
56824 + unsigned long pax_task_size;
56825
56826 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
56827 if (!loc) {
56828 @@ -726,6 +1093,77 @@ static int load_elf_binary(struct linux_binprm *bprm)
56829 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
56830 may depend on the personality. */
56831 SET_PERSONALITY(loc->elf_ex);
56832 +
56833 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56834 + current->mm->pax_flags = 0UL;
56835 +#endif
56836 +
56837 +#ifdef CONFIG_PAX_DLRESOLVE
56838 + current->mm->call_dl_resolve = 0UL;
56839 +#endif
56840 +
56841 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
56842 + current->mm->call_syscall = 0UL;
56843 +#endif
56844 +
56845 +#ifdef CONFIG_PAX_ASLR
56846 + current->mm->delta_mmap = 0UL;
56847 + current->mm->delta_stack = 0UL;
56848 +#endif
56849 +
56850 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
56851 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
56852 + send_sig(SIGKILL, current, 0);
56853 + goto out_free_dentry;
56854 + }
56855 +#endif
56856 +
56857 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
56858 + pax_set_initial_flags(bprm);
56859 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
56860 + if (pax_set_initial_flags_func)
56861 + (pax_set_initial_flags_func)(bprm);
56862 +#endif
56863 +
56864 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
56865 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
56866 + current->mm->context.user_cs_limit = PAGE_SIZE;
56867 + current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
56868 + }
56869 +#endif
56870 +
56871 +#ifdef CONFIG_PAX_SEGMEXEC
56872 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
56873 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
56874 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
56875 + pax_task_size = SEGMEXEC_TASK_SIZE;
56876 + current->mm->def_flags |= VM_NOHUGEPAGE;
56877 + } else
56878 +#endif
56879 +
56880 + pax_task_size = TASK_SIZE;
56881 +
56882 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
56883 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
56884 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
56885 + put_cpu();
56886 + }
56887 +#endif
56888 +
56889 +#ifdef CONFIG_PAX_ASLR
56890 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
56891 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
56892 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
56893 + }
56894 +#endif
56895 +
56896 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
56897 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
56898 + executable_stack = EXSTACK_DISABLE_X;
56899 + current->personality &= ~READ_IMPLIES_EXEC;
56900 + } else
56901 +#endif
56902 +
56903 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
56904 current->personality |= READ_IMPLIES_EXEC;
56905
56906 @@ -815,6 +1253,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
56907 #else
56908 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
56909 #endif
56910 +
56911 +#ifdef CONFIG_PAX_RANDMMAP
56912 + /* PaX: randomize base address at the default exe base if requested */
56913 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
56914 +#ifdef CONFIG_SPARC64
56915 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
56916 +#else
56917 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
56918 +#endif
56919 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
56920 + elf_flags |= MAP_FIXED;
56921 + }
56922 +#endif
56923 +
56924 }
56925
56926 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
56927 @@ -847,9 +1299,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
56928 * allowed task size. Note that p_filesz must always be
56929 * <= p_memsz so it is only necessary to check p_memsz.
56930 */
56931 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
56932 - elf_ppnt->p_memsz > TASK_SIZE ||
56933 - TASK_SIZE - elf_ppnt->p_memsz < k) {
56934 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
56935 + elf_ppnt->p_memsz > pax_task_size ||
56936 + pax_task_size - elf_ppnt->p_memsz < k) {
56937 /* set_brk can never work. Avoid overflows. */
56938 send_sig(SIGKILL, current, 0);
56939 retval = -EINVAL;
56940 @@ -888,17 +1340,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
56941 goto out_free_dentry;
56942 }
56943 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
56944 - send_sig(SIGSEGV, current, 0);
56945 - retval = -EFAULT; /* Nobody gets to see this, but.. */
56946 - goto out_free_dentry;
56947 + /*
56948 + * This bss-zeroing can fail if the ELF
56949 + * file specifies odd protections. So
56950 + * we don't check the return value
56951 + */
56952 }
56953
56954 +#ifdef CONFIG_PAX_RANDMMAP
56955 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
56956 + unsigned long start, size, flags;
56957 + vm_flags_t vm_flags;
56958 +
56959 + start = ELF_PAGEALIGN(elf_brk);
56960 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
56961 + flags = MAP_FIXED | MAP_PRIVATE;
56962 + vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
56963 +
56964 + down_write(&current->mm->mmap_sem);
56965 + start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
56966 + retval = -ENOMEM;
56967 + if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
56968 +// if (current->personality & ADDR_NO_RANDOMIZE)
56969 +// vm_flags |= VM_READ | VM_MAYREAD;
56970 + start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
56971 + retval = IS_ERR_VALUE(start) ? start : 0;
56972 + }
56973 + up_write(&current->mm->mmap_sem);
56974 + if (retval == 0)
56975 + retval = set_brk(start + size, start + size + PAGE_SIZE);
56976 + if (retval < 0) {
56977 + send_sig(SIGKILL, current, 0);
56978 + goto out_free_dentry;
56979 + }
56980 + }
56981 +#endif
56982 +
56983 if (elf_interpreter) {
56984 - unsigned long interp_map_addr = 0;
56985 -
56986 elf_entry = load_elf_interp(&loc->interp_elf_ex,
56987 interpreter,
56988 - &interp_map_addr,
56989 load_bias);
56990 if (!IS_ERR((void *)elf_entry)) {
56991 /*
56992 @@ -1122,7 +1602,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
56993 * Decide what to dump of a segment, part, all or none.
56994 */
56995 static unsigned long vma_dump_size(struct vm_area_struct *vma,
56996 - unsigned long mm_flags)
56997 + unsigned long mm_flags, long signr)
56998 {
56999 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
57000
57001 @@ -1160,7 +1640,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
57002 if (vma->vm_file == NULL)
57003 return 0;
57004
57005 - if (FILTER(MAPPED_PRIVATE))
57006 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
57007 goto whole;
57008
57009 /*
57010 @@ -1367,9 +1847,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
57011 {
57012 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
57013 int i = 0;
57014 - do
57015 + do {
57016 i += 2;
57017 - while (auxv[i - 2] != AT_NULL);
57018 + } while (auxv[i - 2] != AT_NULL);
57019 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
57020 }
57021
57022 @@ -1378,7 +1858,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
57023 {
57024 mm_segment_t old_fs = get_fs();
57025 set_fs(KERNEL_DS);
57026 - copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
57027 + copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
57028 set_fs(old_fs);
57029 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
57030 }
57031 @@ -2002,14 +2482,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
57032 }
57033
57034 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
57035 - unsigned long mm_flags)
57036 + struct coredump_params *cprm)
57037 {
57038 struct vm_area_struct *vma;
57039 size_t size = 0;
57040
57041 for (vma = first_vma(current, gate_vma); vma != NULL;
57042 vma = next_vma(vma, gate_vma))
57043 - size += vma_dump_size(vma, mm_flags);
57044 + size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
57045 return size;
57046 }
57047
57048 @@ -2100,7 +2580,7 @@ static int elf_core_dump(struct coredump_params *cprm)
57049
57050 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
57051
57052 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
57053 + offset += elf_core_vma_data_size(gate_vma, cprm);
57054 offset += elf_core_extra_data_size();
57055 e_shoff = offset;
57056
57057 @@ -2128,7 +2608,7 @@ static int elf_core_dump(struct coredump_params *cprm)
57058 phdr.p_offset = offset;
57059 phdr.p_vaddr = vma->vm_start;
57060 phdr.p_paddr = 0;
57061 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
57062 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
57063 phdr.p_memsz = vma->vm_end - vma->vm_start;
57064 offset += phdr.p_filesz;
57065 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
57066 @@ -2161,7 +2641,7 @@ static int elf_core_dump(struct coredump_params *cprm)
57067 unsigned long addr;
57068 unsigned long end;
57069
57070 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
57071 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
57072
57073 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
57074 struct page *page;
57075 @@ -2202,6 +2682,167 @@ out:
57076
57077 #endif /* CONFIG_ELF_CORE */
57078
57079 +#ifdef CONFIG_PAX_MPROTECT
57080 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
57081 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
57082 + * we'll remove VM_MAYWRITE for good on RELRO segments.
57083 + *
57084 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
57085 + * basis because we want to allow the common case and not the special ones.
57086 + */
57087 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
57088 +{
57089 + struct elfhdr elf_h;
57090 + struct elf_phdr elf_p;
57091 + unsigned long i;
57092 + unsigned long oldflags;
57093 + bool is_textrel_rw, is_textrel_rx, is_relro;
57094 +
57095 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
57096 + return;
57097 +
57098 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
57099 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
57100 +
57101 +#ifdef CONFIG_PAX_ELFRELOCS
57102 + /* possible TEXTREL */
57103 + is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
57104 + is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
57105 +#else
57106 + is_textrel_rw = false;
57107 + is_textrel_rx = false;
57108 +#endif
57109 +
57110 + /* possible RELRO */
57111 + is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
57112 +
57113 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
57114 + return;
57115 +
57116 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
57117 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
57118 +
57119 +#ifdef CONFIG_PAX_ETEXECRELOCS
57120 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
57121 +#else
57122 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
57123 +#endif
57124 +
57125 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
57126 + !elf_check_arch(&elf_h) ||
57127 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
57128 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
57129 + return;
57130 +
57131 + for (i = 0UL; i < elf_h.e_phnum; i++) {
57132 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
57133 + return;
57134 + switch (elf_p.p_type) {
57135 + case PT_DYNAMIC:
57136 + if (!is_textrel_rw && !is_textrel_rx)
57137 + continue;
57138 + i = 0UL;
57139 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
57140 + elf_dyn dyn;
57141 +
57142 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
57143 + break;
57144 + if (dyn.d_tag == DT_NULL)
57145 + break;
57146 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
57147 + gr_log_textrel(vma);
57148 + if (is_textrel_rw)
57149 + vma->vm_flags |= VM_MAYWRITE;
57150 + else
57151 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
57152 + vma->vm_flags &= ~VM_MAYWRITE;
57153 + break;
57154 + }
57155 + i++;
57156 + }
57157 + is_textrel_rw = false;
57158 + is_textrel_rx = false;
57159 + continue;
57160 +
57161 + case PT_GNU_RELRO:
57162 + if (!is_relro)
57163 + continue;
57164 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
57165 + vma->vm_flags &= ~VM_MAYWRITE;
57166 + is_relro = false;
57167 + continue;
57168 +
57169 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
57170 + case PT_PAX_FLAGS: {
57171 + const char *msg_mprotect = "", *msg_emutramp = "";
57172 + char *buffer_lib, *buffer_exe;
57173 +
57174 + if (elf_p.p_flags & PF_NOMPROTECT)
57175 + msg_mprotect = "MPROTECT disabled";
57176 +
57177 +#ifdef CONFIG_PAX_EMUTRAMP
57178 + if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
57179 + msg_emutramp = "EMUTRAMP enabled";
57180 +#endif
57181 +
57182 + if (!msg_mprotect[0] && !msg_emutramp[0])
57183 + continue;
57184 +
57185 + if (!printk_ratelimit())
57186 + continue;
57187 +
57188 + buffer_lib = (char *)__get_free_page(GFP_KERNEL);
57189 + buffer_exe = (char *)__get_free_page(GFP_KERNEL);
57190 + if (buffer_lib && buffer_exe) {
57191 + char *path_lib, *path_exe;
57192 +
57193 + path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
57194 + path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
57195 +
57196 + pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
57197 + (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
57198 +
57199 + }
57200 + free_page((unsigned long)buffer_exe);
57201 + free_page((unsigned long)buffer_lib);
57202 + continue;
57203 + }
57204 +#endif
57205 +
57206 + }
57207 + }
57208 +}
57209 +#endif
57210 +
57211 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
57212 +
57213 +extern int grsec_enable_log_rwxmaps;
57214 +
57215 +static void elf_handle_mmap(struct file *file)
57216 +{
57217 + struct elfhdr elf_h;
57218 + struct elf_phdr elf_p;
57219 + unsigned long i;
57220 +
57221 + if (!grsec_enable_log_rwxmaps)
57222 + return;
57223 +
57224 + if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
57225 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
57226 + (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
57227 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
57228 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
57229 + return;
57230 +
57231 + for (i = 0UL; i < elf_h.e_phnum; i++) {
57232 + if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
57233 + return;
57234 + if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
57235 + gr_log_ptgnustack(file);
57236 + }
57237 +}
57238 +#endif
57239 +
57240 static int __init init_elf_binfmt(void)
57241 {
57242 register_binfmt(&elf_format);
57243 diff --git a/fs/bio.c b/fs/bio.c
57244 index 6f0362b..26a7496 100644
57245 --- a/fs/bio.c
57246 +++ b/fs/bio.c
57247 @@ -1144,7 +1144,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
57248 /*
57249 * Overflow, abort
57250 */
57251 - if (end < start)
57252 + if (end < start || end - start > INT_MAX - nr_pages)
57253 return ERR_PTR(-EINVAL);
57254
57255 nr_pages += end - start;
57256 @@ -1278,7 +1278,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
57257 /*
57258 * Overflow, abort
57259 */
57260 - if (end < start)
57261 + if (end < start || end - start > INT_MAX - nr_pages)
57262 return ERR_PTR(-EINVAL);
57263
57264 nr_pages += end - start;
57265 @@ -1540,7 +1540,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
57266 const int read = bio_data_dir(bio) == READ;
57267 struct bio_map_data *bmd = bio->bi_private;
57268 int i;
57269 - char *p = bmd->sgvecs[0].iov_base;
57270 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
57271
57272 bio_for_each_segment_all(bvec, bio, i) {
57273 char *addr = page_address(bvec->bv_page);
57274 diff --git a/fs/block_dev.c b/fs/block_dev.c
57275 index 552a8d1..d51ccf3 100644
57276 --- a/fs/block_dev.c
57277 +++ b/fs/block_dev.c
57278 @@ -637,7 +637,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
57279 else if (bdev->bd_contains == bdev)
57280 return true; /* is a whole device which isn't held */
57281
57282 - else if (whole->bd_holder == bd_may_claim)
57283 + else if (whole->bd_holder == (void *)bd_may_claim)
57284 return true; /* is a partition of a device that is being partitioned */
57285 else if (whole->bd_holder != NULL)
57286 return false; /* is a partition of a held device */
57287 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
57288 index 1bcfcdb..e942132 100644
57289 --- a/fs/btrfs/ctree.c
57290 +++ b/fs/btrfs/ctree.c
57291 @@ -1216,9 +1216,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
57292 free_extent_buffer(buf);
57293 add_root_to_dirty_list(root);
57294 } else {
57295 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
57296 - parent_start = parent->start;
57297 - else
57298 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
57299 + if (parent)
57300 + parent_start = parent->start;
57301 + else
57302 + parent_start = 0;
57303 + } else
57304 parent_start = 0;
57305
57306 WARN_ON(trans->transid != btrfs_header_generation(parent));
57307 diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
57308 index 33e561a..16df7ae 100644
57309 --- a/fs/btrfs/delayed-inode.c
57310 +++ b/fs/btrfs/delayed-inode.c
57311 @@ -459,7 +459,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
57312
57313 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
57314 {
57315 - int seq = atomic_inc_return(&delayed_root->items_seq);
57316 + int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
57317 if ((atomic_dec_return(&delayed_root->items) <
57318 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
57319 waitqueue_active(&delayed_root->wait))
57320 @@ -1409,7 +1409,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
57321
57322 static int could_end_wait(struct btrfs_delayed_root *delayed_root, int seq)
57323 {
57324 - int val = atomic_read(&delayed_root->items_seq);
57325 + int val = atomic_read_unchecked(&delayed_root->items_seq);
57326
57327 if (val < seq || val >= seq + BTRFS_DELAYED_BATCH)
57328 return 1;
57329 @@ -1433,7 +1433,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
57330 int seq;
57331 int ret;
57332
57333 - seq = atomic_read(&delayed_root->items_seq);
57334 + seq = atomic_read_unchecked(&delayed_root->items_seq);
57335
57336 ret = btrfs_wq_run_delayed_node(delayed_root, root, 0);
57337 if (ret)
57338 diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
57339 index f70119f..ab5894d 100644
57340 --- a/fs/btrfs/delayed-inode.h
57341 +++ b/fs/btrfs/delayed-inode.h
57342 @@ -43,7 +43,7 @@ struct btrfs_delayed_root {
57343 */
57344 struct list_head prepare_list;
57345 atomic_t items; /* for delayed items */
57346 - atomic_t items_seq; /* for delayed items */
57347 + atomic_unchecked_t items_seq; /* for delayed items */
57348 int nodes; /* for delayed nodes */
57349 wait_queue_head_t wait;
57350 };
57351 @@ -90,7 +90,7 @@ static inline void btrfs_init_delayed_root(
57352 struct btrfs_delayed_root *delayed_root)
57353 {
57354 atomic_set(&delayed_root->items, 0);
57355 - atomic_set(&delayed_root->items_seq, 0);
57356 + atomic_set_unchecked(&delayed_root->items_seq, 0);
57357 delayed_root->nodes = 0;
57358 spin_lock_init(&delayed_root->lock);
57359 init_waitqueue_head(&delayed_root->wait);
57360 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
57361 index 2f6d7b1..f186382 100644
57362 --- a/fs/btrfs/ioctl.c
57363 +++ b/fs/btrfs/ioctl.c
57364 @@ -3575,9 +3575,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
57365 for (i = 0; i < num_types; i++) {
57366 struct btrfs_space_info *tmp;
57367
57368 + /* Don't copy in more than we allocated */
57369 if (!slot_count)
57370 break;
57371
57372 + slot_count--;
57373 +
57374 info = NULL;
57375 rcu_read_lock();
57376 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
57377 @@ -3599,10 +3602,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
57378 memcpy(dest, &space, sizeof(space));
57379 dest++;
57380 space_args.total_spaces++;
57381 - slot_count--;
57382 }
57383 - if (!slot_count)
57384 - break;
57385 }
57386 up_read(&info->groups_sem);
57387 }
57388 diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
57389 index 9601d25..2896d6c 100644
57390 --- a/fs/btrfs/super.c
57391 +++ b/fs/btrfs/super.c
57392 @@ -270,7 +270,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
57393 function, line, errstr);
57394 return;
57395 }
57396 - ACCESS_ONCE(trans->transaction->aborted) = errno;
57397 + ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
57398 /* Wake up anybody who may be waiting on this transaction */
57399 wake_up(&root->fs_info->transaction_wait);
57400 wake_up(&root->fs_info->transaction_blocked_wait);
57401 diff --git a/fs/btrfs/sysfs.c b/fs/btrfs/sysfs.c
57402 index 4825cd2..b2fe768 100644
57403 --- a/fs/btrfs/sysfs.c
57404 +++ b/fs/btrfs/sysfs.c
57405 @@ -438,7 +438,7 @@ static int addrm_unknown_feature_attrs(struct btrfs_fs_info *fs_info, bool add)
57406 for (set = 0; set < FEAT_MAX; set++) {
57407 int i;
57408 struct attribute *attrs[2];
57409 - struct attribute_group agroup = {
57410 + attribute_group_no_const agroup = {
57411 .name = "features",
57412 .attrs = attrs,
57413 };
57414 diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c
57415 index e2f45fc..b036909 100644
57416 --- a/fs/btrfs/tree-log.c
57417 +++ b/fs/btrfs/tree-log.c
57418 @@ -2533,7 +2533,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
57419 blk_finish_plug(&plug);
57420 btrfs_abort_transaction(trans, root, ret);
57421 btrfs_free_logged_extents(log, log_transid);
57422 - ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) =
57423 + ACCESS_ONCE_RW(root->fs_info->last_trans_log_full_commit) =
57424 trans->transid;
57425 mutex_unlock(&root->log_mutex);
57426 goto out;
57427 @@ -2577,7 +2577,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
57428 list_del_init(&root_log_ctx.list);
57429
57430 blk_finish_plug(&plug);
57431 - ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) =
57432 + ACCESS_ONCE_RW(root->fs_info->last_trans_log_full_commit) =
57433 trans->transid;
57434 if (ret != -ENOSPC) {
57435 btrfs_abort_transaction(trans, root, ret);
57436 @@ -2622,7 +2622,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
57437 * now that we've moved on to the tree of log tree roots,
57438 * check the full commit flag again
57439 */
57440 - if (ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) ==
57441 + if (ACCESS_ONCE_RW(root->fs_info->last_trans_log_full_commit) ==
57442 trans->transid) {
57443 blk_finish_plug(&plug);
57444 btrfs_wait_marked_extents(log, &log->dirty_log_pages, mark);
57445 @@ -2637,7 +2637,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
57446 EXTENT_DIRTY | EXTENT_NEW);
57447 blk_finish_plug(&plug);
57448 if (ret) {
57449 - ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) =
57450 + ACCESS_ONCE_RW(root->fs_info->last_trans_log_full_commit) =
57451 trans->transid;
57452 btrfs_abort_transaction(trans, root, ret);
57453 btrfs_free_logged_extents(log, log_transid);
57454 @@ -2667,7 +2667,7 @@ int btrfs_sync_log(struct btrfs_trans_handle *trans,
57455 */
57456 ret = write_ctree_super(trans, root->fs_info->tree_root, 1);
57457 if (ret) {
57458 - ACCESS_ONCE(root->fs_info->last_trans_log_full_commit) =
57459 + ACCESS_ONCE_RW(root->fs_info->last_trans_log_full_commit) =
57460 trans->transid;
57461 btrfs_abort_transaction(trans, root, ret);
57462 goto out_wake_log_root;
57463 diff --git a/fs/buffer.c b/fs/buffer.c
57464 index 9ddb9fc..7aa2487 100644
57465 --- a/fs/buffer.c
57466 +++ b/fs/buffer.c
57467 @@ -3428,7 +3428,7 @@ void __init buffer_init(void)
57468 bh_cachep = kmem_cache_create("buffer_head",
57469 sizeof(struct buffer_head), 0,
57470 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
57471 - SLAB_MEM_SPREAD),
57472 + SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
57473 NULL);
57474
57475 /*
57476 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
57477 index 5b99baf..47fffb5 100644
57478 --- a/fs/cachefiles/bind.c
57479 +++ b/fs/cachefiles/bind.c
57480 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
57481 args);
57482
57483 /* start by checking things over */
57484 - ASSERT(cache->fstop_percent >= 0 &&
57485 - cache->fstop_percent < cache->fcull_percent &&
57486 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
57487 cache->fcull_percent < cache->frun_percent &&
57488 cache->frun_percent < 100);
57489
57490 - ASSERT(cache->bstop_percent >= 0 &&
57491 - cache->bstop_percent < cache->bcull_percent &&
57492 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
57493 cache->bcull_percent < cache->brun_percent &&
57494 cache->brun_percent < 100);
57495
57496 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
57497 index 0a1467b..6a53245 100644
57498 --- a/fs/cachefiles/daemon.c
57499 +++ b/fs/cachefiles/daemon.c
57500 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
57501 if (n > buflen)
57502 return -EMSGSIZE;
57503
57504 - if (copy_to_user(_buffer, buffer, n) != 0)
57505 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
57506 return -EFAULT;
57507
57508 return n;
57509 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
57510 if (test_bit(CACHEFILES_DEAD, &cache->flags))
57511 return -EIO;
57512
57513 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
57514 + if (datalen > PAGE_SIZE - 1)
57515 return -EOPNOTSUPP;
57516
57517 /* drag the command string into the kernel so we can parse it */
57518 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
57519 if (args[0] != '%' || args[1] != '\0')
57520 return -EINVAL;
57521
57522 - if (fstop < 0 || fstop >= cache->fcull_percent)
57523 + if (fstop >= cache->fcull_percent)
57524 return cachefiles_daemon_range_error(cache, args);
57525
57526 cache->fstop_percent = fstop;
57527 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
57528 if (args[0] != '%' || args[1] != '\0')
57529 return -EINVAL;
57530
57531 - if (bstop < 0 || bstop >= cache->bcull_percent)
57532 + if (bstop >= cache->bcull_percent)
57533 return cachefiles_daemon_range_error(cache, args);
57534
57535 cache->bstop_percent = bstop;
57536 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
57537 index 5349473..d6c0b93 100644
57538 --- a/fs/cachefiles/internal.h
57539 +++ b/fs/cachefiles/internal.h
57540 @@ -59,7 +59,7 @@ struct cachefiles_cache {
57541 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
57542 struct rb_root active_nodes; /* active nodes (can't be culled) */
57543 rwlock_t active_lock; /* lock for active_nodes */
57544 - atomic_t gravecounter; /* graveyard uniquifier */
57545 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
57546 unsigned frun_percent; /* when to stop culling (% files) */
57547 unsigned fcull_percent; /* when to start culling (% files) */
57548 unsigned fstop_percent; /* when to stop allocating (% files) */
57549 @@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
57550 * proc.c
57551 */
57552 #ifdef CONFIG_CACHEFILES_HISTOGRAM
57553 -extern atomic_t cachefiles_lookup_histogram[HZ];
57554 -extern atomic_t cachefiles_mkdir_histogram[HZ];
57555 -extern atomic_t cachefiles_create_histogram[HZ];
57556 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
57557 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
57558 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
57559
57560 extern int __init cachefiles_proc_init(void);
57561 extern void cachefiles_proc_cleanup(void);
57562 static inline
57563 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
57564 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
57565 {
57566 unsigned long jif = jiffies - start_jif;
57567 if (jif >= HZ)
57568 jif = HZ - 1;
57569 - atomic_inc(&histogram[jif]);
57570 + atomic_inc_unchecked(&histogram[jif]);
57571 }
57572
57573 #else
57574 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
57575 index c0a6817..ea811166 100644
57576 --- a/fs/cachefiles/namei.c
57577 +++ b/fs/cachefiles/namei.c
57578 @@ -317,7 +317,7 @@ try_again:
57579 /* first step is to make up a grave dentry in the graveyard */
57580 sprintf(nbuffer, "%08x%08x",
57581 (uint32_t) get_seconds(),
57582 - (uint32_t) atomic_inc_return(&cache->gravecounter));
57583 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
57584
57585 /* do the multiway lock magic */
57586 trap = lock_rename(cache->graveyard, dir);
57587 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
57588 index eccd339..4c1d995 100644
57589 --- a/fs/cachefiles/proc.c
57590 +++ b/fs/cachefiles/proc.c
57591 @@ -14,9 +14,9 @@
57592 #include <linux/seq_file.h>
57593 #include "internal.h"
57594
57595 -atomic_t cachefiles_lookup_histogram[HZ];
57596 -atomic_t cachefiles_mkdir_histogram[HZ];
57597 -atomic_t cachefiles_create_histogram[HZ];
57598 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
57599 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
57600 +atomic_unchecked_t cachefiles_create_histogram[HZ];
57601
57602 /*
57603 * display the latency histogram
57604 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
57605 return 0;
57606 default:
57607 index = (unsigned long) v - 3;
57608 - x = atomic_read(&cachefiles_lookup_histogram[index]);
57609 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
57610 - z = atomic_read(&cachefiles_create_histogram[index]);
57611 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
57612 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
57613 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
57614 if (x == 0 && y == 0 && z == 0)
57615 return 0;
57616
57617 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
57618 index 4b1fb5c..0d2a699 100644
57619 --- a/fs/cachefiles/rdwr.c
57620 +++ b/fs/cachefiles/rdwr.c
57621 @@ -943,7 +943,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
57622 old_fs = get_fs();
57623 set_fs(KERNEL_DS);
57624 ret = file->f_op->write(
57625 - file, (const void __user *) data, len, &pos);
57626 + file, (const void __force_user *) data, len, &pos);
57627 set_fs(old_fs);
57628 kunmap(page);
57629 file_end_write(file);
57630 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
57631 index c29d6ae..a56c4ae 100644
57632 --- a/fs/ceph/dir.c
57633 +++ b/fs/ceph/dir.c
57634 @@ -250,7 +250,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
57635 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
57636 struct ceph_mds_client *mdsc = fsc->mdsc;
57637 unsigned frag = fpos_frag(ctx->pos);
57638 - int off = fpos_off(ctx->pos);
57639 + unsigned int off = fpos_off(ctx->pos);
57640 int err;
57641 u32 ftype;
57642 struct ceph_mds_reply_info_parsed *rinfo;
57643 diff --git a/fs/ceph/super.c b/fs/ceph/super.c
57644 index 06150fd..192061b 100644
57645 --- a/fs/ceph/super.c
57646 +++ b/fs/ceph/super.c
57647 @@ -895,7 +895,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
57648 /*
57649 * construct our own bdi so we can control readahead, etc.
57650 */
57651 -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
57652 +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
57653
57654 static int ceph_register_bdi(struct super_block *sb,
57655 struct ceph_fs_client *fsc)
57656 @@ -912,7 +912,7 @@ static int ceph_register_bdi(struct super_block *sb,
57657 default_backing_dev_info.ra_pages;
57658
57659 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
57660 - atomic_long_inc_return(&bdi_seq));
57661 + atomic_long_inc_return_unchecked(&bdi_seq));
57662 if (!err)
57663 sb->s_bdi = &fsc->backing_dev_info;
57664 return err;
57665 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
57666 index f3ac415..3d2420c 100644
57667 --- a/fs/cifs/cifs_debug.c
57668 +++ b/fs/cifs/cifs_debug.c
57669 @@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
57670
57671 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
57672 #ifdef CONFIG_CIFS_STATS2
57673 - atomic_set(&totBufAllocCount, 0);
57674 - atomic_set(&totSmBufAllocCount, 0);
57675 + atomic_set_unchecked(&totBufAllocCount, 0);
57676 + atomic_set_unchecked(&totSmBufAllocCount, 0);
57677 #endif /* CONFIG_CIFS_STATS2 */
57678 spin_lock(&cifs_tcp_ses_lock);
57679 list_for_each(tmp1, &cifs_tcp_ses_list) {
57680 @@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
57681 tcon = list_entry(tmp3,
57682 struct cifs_tcon,
57683 tcon_list);
57684 - atomic_set(&tcon->num_smbs_sent, 0);
57685 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
57686 if (server->ops->clear_stats)
57687 server->ops->clear_stats(tcon);
57688 }
57689 @@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
57690 smBufAllocCount.counter, cifs_min_small);
57691 #ifdef CONFIG_CIFS_STATS2
57692 seq_printf(m, "Total Large %d Small %d Allocations\n",
57693 - atomic_read(&totBufAllocCount),
57694 - atomic_read(&totSmBufAllocCount));
57695 + atomic_read_unchecked(&totBufAllocCount),
57696 + atomic_read_unchecked(&totSmBufAllocCount));
57697 #endif /* CONFIG_CIFS_STATS2 */
57698
57699 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
57700 @@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
57701 if (tcon->need_reconnect)
57702 seq_puts(m, "\tDISCONNECTED ");
57703 seq_printf(m, "\nSMBs: %d",
57704 - atomic_read(&tcon->num_smbs_sent));
57705 + atomic_read_unchecked(&tcon->num_smbs_sent));
57706 if (server->ops->print_stats)
57707 server->ops->print_stats(m, tcon);
57708 }
57709 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
57710 index 5be1f997..fa1015a1 100644
57711 --- a/fs/cifs/cifsfs.c
57712 +++ b/fs/cifs/cifsfs.c
57713 @@ -1068,7 +1068,7 @@ cifs_init_request_bufs(void)
57714 */
57715 cifs_req_cachep = kmem_cache_create("cifs_request",
57716 CIFSMaxBufSize + max_hdr_size, 0,
57717 - SLAB_HWCACHE_ALIGN, NULL);
57718 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
57719 if (cifs_req_cachep == NULL)
57720 return -ENOMEM;
57721
57722 @@ -1095,7 +1095,7 @@ cifs_init_request_bufs(void)
57723 efficient to alloc 1 per page off the slab compared to 17K (5page)
57724 alloc of large cifs buffers even when page debugging is on */
57725 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
57726 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
57727 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
57728 NULL);
57729 if (cifs_sm_req_cachep == NULL) {
57730 mempool_destroy(cifs_req_poolp);
57731 @@ -1180,8 +1180,8 @@ init_cifs(void)
57732 atomic_set(&bufAllocCount, 0);
57733 atomic_set(&smBufAllocCount, 0);
57734 #ifdef CONFIG_CIFS_STATS2
57735 - atomic_set(&totBufAllocCount, 0);
57736 - atomic_set(&totSmBufAllocCount, 0);
57737 + atomic_set_unchecked(&totBufAllocCount, 0);
57738 + atomic_set_unchecked(&totSmBufAllocCount, 0);
57739 #endif /* CONFIG_CIFS_STATS2 */
57740
57741 atomic_set(&midCount, 0);
57742 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
57743 index 30f6e92..e915ba5 100644
57744 --- a/fs/cifs/cifsglob.h
57745 +++ b/fs/cifs/cifsglob.h
57746 @@ -806,35 +806,35 @@ struct cifs_tcon {
57747 __u16 Flags; /* optional support bits */
57748 enum statusEnum tidStatus;
57749 #ifdef CONFIG_CIFS_STATS
57750 - atomic_t num_smbs_sent;
57751 + atomic_unchecked_t num_smbs_sent;
57752 union {
57753 struct {
57754 - atomic_t num_writes;
57755 - atomic_t num_reads;
57756 - atomic_t num_flushes;
57757 - atomic_t num_oplock_brks;
57758 - atomic_t num_opens;
57759 - atomic_t num_closes;
57760 - atomic_t num_deletes;
57761 - atomic_t num_mkdirs;
57762 - atomic_t num_posixopens;
57763 - atomic_t num_posixmkdirs;
57764 - atomic_t num_rmdirs;
57765 - atomic_t num_renames;
57766 - atomic_t num_t2renames;
57767 - atomic_t num_ffirst;
57768 - atomic_t num_fnext;
57769 - atomic_t num_fclose;
57770 - atomic_t num_hardlinks;
57771 - atomic_t num_symlinks;
57772 - atomic_t num_locks;
57773 - atomic_t num_acl_get;
57774 - atomic_t num_acl_set;
57775 + atomic_unchecked_t num_writes;
57776 + atomic_unchecked_t num_reads;
57777 + atomic_unchecked_t num_flushes;
57778 + atomic_unchecked_t num_oplock_brks;
57779 + atomic_unchecked_t num_opens;
57780 + atomic_unchecked_t num_closes;
57781 + atomic_unchecked_t num_deletes;
57782 + atomic_unchecked_t num_mkdirs;
57783 + atomic_unchecked_t num_posixopens;
57784 + atomic_unchecked_t num_posixmkdirs;
57785 + atomic_unchecked_t num_rmdirs;
57786 + atomic_unchecked_t num_renames;
57787 + atomic_unchecked_t num_t2renames;
57788 + atomic_unchecked_t num_ffirst;
57789 + atomic_unchecked_t num_fnext;
57790 + atomic_unchecked_t num_fclose;
57791 + atomic_unchecked_t num_hardlinks;
57792 + atomic_unchecked_t num_symlinks;
57793 + atomic_unchecked_t num_locks;
57794 + atomic_unchecked_t num_acl_get;
57795 + atomic_unchecked_t num_acl_set;
57796 } cifs_stats;
57797 #ifdef CONFIG_CIFS_SMB2
57798 struct {
57799 - atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
57800 - atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
57801 + atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
57802 + atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
57803 } smb2_stats;
57804 #endif /* CONFIG_CIFS_SMB2 */
57805 } stats;
57806 @@ -1170,7 +1170,7 @@ convert_delimiter(char *path, char delim)
57807 }
57808
57809 #ifdef CONFIG_CIFS_STATS
57810 -#define cifs_stats_inc atomic_inc
57811 +#define cifs_stats_inc atomic_inc_unchecked
57812
57813 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
57814 unsigned int bytes)
57815 @@ -1536,8 +1536,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
57816 /* Various Debug counters */
57817 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
57818 #ifdef CONFIG_CIFS_STATS2
57819 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
57820 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
57821 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
57822 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
57823 #endif
57824 GLOBAL_EXTERN atomic_t smBufAllocCount;
57825 GLOBAL_EXTERN atomic_t midCount;
57826 diff --git a/fs/cifs/file.c b/fs/cifs/file.c
57827 index 5ed03e0..e9a3a6c 100644
57828 --- a/fs/cifs/file.c
57829 +++ b/fs/cifs/file.c
57830 @@ -1900,10 +1900,14 @@ static int cifs_writepages(struct address_space *mapping,
57831 index = mapping->writeback_index; /* Start from prev offset */
57832 end = -1;
57833 } else {
57834 - index = wbc->range_start >> PAGE_CACHE_SHIFT;
57835 - end = wbc->range_end >> PAGE_CACHE_SHIFT;
57836 - if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
57837 + if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) {
57838 range_whole = true;
57839 + index = 0;
57840 + end = ULONG_MAX;
57841 + } else {
57842 + index = wbc->range_start >> PAGE_CACHE_SHIFT;
57843 + end = wbc->range_end >> PAGE_CACHE_SHIFT;
57844 + }
57845 scanned = true;
57846 }
57847 retry:
57848 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
57849 index 3b0c62e..f7d090c 100644
57850 --- a/fs/cifs/misc.c
57851 +++ b/fs/cifs/misc.c
57852 @@ -170,7 +170,7 @@ cifs_buf_get(void)
57853 memset(ret_buf, 0, buf_size + 3);
57854 atomic_inc(&bufAllocCount);
57855 #ifdef CONFIG_CIFS_STATS2
57856 - atomic_inc(&totBufAllocCount);
57857 + atomic_inc_unchecked(&totBufAllocCount);
57858 #endif /* CONFIG_CIFS_STATS2 */
57859 }
57860
57861 @@ -205,7 +205,7 @@ cifs_small_buf_get(void)
57862 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
57863 atomic_inc(&smBufAllocCount);
57864 #ifdef CONFIG_CIFS_STATS2
57865 - atomic_inc(&totSmBufAllocCount);
57866 + atomic_inc_unchecked(&totSmBufAllocCount);
57867 #endif /* CONFIG_CIFS_STATS2 */
57868
57869 }
57870 diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
57871 index d1fdfa8..94558f8 100644
57872 --- a/fs/cifs/smb1ops.c
57873 +++ b/fs/cifs/smb1ops.c
57874 @@ -626,27 +626,27 @@ static void
57875 cifs_clear_stats(struct cifs_tcon *tcon)
57876 {
57877 #ifdef CONFIG_CIFS_STATS
57878 - atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
57879 - atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
57880 - atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
57881 - atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
57882 - atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
57883 - atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
57884 - atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
57885 - atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
57886 - atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
57887 - atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
57888 - atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
57889 - atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
57890 - atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
57891 - atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
57892 - atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
57893 - atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
57894 - atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
57895 - atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
57896 - atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
57897 - atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
57898 - atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
57899 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
57900 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
57901 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
57902 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
57903 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
57904 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
57905 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
57906 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
57907 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
57908 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
57909 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
57910 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
57911 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
57912 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
57913 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
57914 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
57915 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
57916 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
57917 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
57918 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
57919 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
57920 #endif
57921 }
57922
57923 @@ -655,36 +655,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
57924 {
57925 #ifdef CONFIG_CIFS_STATS
57926 seq_printf(m, " Oplocks breaks: %d",
57927 - atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
57928 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
57929 seq_printf(m, "\nReads: %d Bytes: %llu",
57930 - atomic_read(&tcon->stats.cifs_stats.num_reads),
57931 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
57932 (long long)(tcon->bytes_read));
57933 seq_printf(m, "\nWrites: %d Bytes: %llu",
57934 - atomic_read(&tcon->stats.cifs_stats.num_writes),
57935 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
57936 (long long)(tcon->bytes_written));
57937 seq_printf(m, "\nFlushes: %d",
57938 - atomic_read(&tcon->stats.cifs_stats.num_flushes));
57939 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
57940 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
57941 - atomic_read(&tcon->stats.cifs_stats.num_locks),
57942 - atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
57943 - atomic_read(&tcon->stats.cifs_stats.num_symlinks));
57944 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
57945 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
57946 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
57947 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
57948 - atomic_read(&tcon->stats.cifs_stats.num_opens),
57949 - atomic_read(&tcon->stats.cifs_stats.num_closes),
57950 - atomic_read(&tcon->stats.cifs_stats.num_deletes));
57951 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
57952 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
57953 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
57954 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
57955 - atomic_read(&tcon->stats.cifs_stats.num_posixopens),
57956 - atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
57957 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
57958 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
57959 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
57960 - atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
57961 - atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
57962 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
57963 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
57964 seq_printf(m, "\nRenames: %d T2 Renames %d",
57965 - atomic_read(&tcon->stats.cifs_stats.num_renames),
57966 - atomic_read(&tcon->stats.cifs_stats.num_t2renames));
57967 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
57968 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
57969 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
57970 - atomic_read(&tcon->stats.cifs_stats.num_ffirst),
57971 - atomic_read(&tcon->stats.cifs_stats.num_fnext),
57972 - atomic_read(&tcon->stats.cifs_stats.num_fclose));
57973 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
57974 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
57975 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
57976 #endif
57977 }
57978
57979 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
57980 index 35ddc3e..563e809 100644
57981 --- a/fs/cifs/smb2ops.c
57982 +++ b/fs/cifs/smb2ops.c
57983 @@ -364,8 +364,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
57984 #ifdef CONFIG_CIFS_STATS
57985 int i;
57986 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
57987 - atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
57988 - atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
57989 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
57990 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
57991 }
57992 #endif
57993 }
57994 @@ -405,65 +405,65 @@ static void
57995 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
57996 {
57997 #ifdef CONFIG_CIFS_STATS
57998 - atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
57999 - atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
58000 + atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
58001 + atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
58002 seq_printf(m, "\nNegotiates: %d sent %d failed",
58003 - atomic_read(&sent[SMB2_NEGOTIATE_HE]),
58004 - atomic_read(&failed[SMB2_NEGOTIATE_HE]));
58005 + atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
58006 + atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
58007 seq_printf(m, "\nSessionSetups: %d sent %d failed",
58008 - atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
58009 - atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
58010 + atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
58011 + atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
58012 seq_printf(m, "\nLogoffs: %d sent %d failed",
58013 - atomic_read(&sent[SMB2_LOGOFF_HE]),
58014 - atomic_read(&failed[SMB2_LOGOFF_HE]));
58015 + atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
58016 + atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
58017 seq_printf(m, "\nTreeConnects: %d sent %d failed",
58018 - atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
58019 - atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
58020 + atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
58021 + atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
58022 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
58023 - atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
58024 - atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
58025 + atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
58026 + atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
58027 seq_printf(m, "\nCreates: %d sent %d failed",
58028 - atomic_read(&sent[SMB2_CREATE_HE]),
58029 - atomic_read(&failed[SMB2_CREATE_HE]));
58030 + atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
58031 + atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
58032 seq_printf(m, "\nCloses: %d sent %d failed",
58033 - atomic_read(&sent[SMB2_CLOSE_HE]),
58034 - atomic_read(&failed[SMB2_CLOSE_HE]));
58035 + atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
58036 + atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
58037 seq_printf(m, "\nFlushes: %d sent %d failed",
58038 - atomic_read(&sent[SMB2_FLUSH_HE]),
58039 - atomic_read(&failed[SMB2_FLUSH_HE]));
58040 + atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
58041 + atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
58042 seq_printf(m, "\nReads: %d sent %d failed",
58043 - atomic_read(&sent[SMB2_READ_HE]),
58044 - atomic_read(&failed[SMB2_READ_HE]));
58045 + atomic_read_unchecked(&sent[SMB2_READ_HE]),
58046 + atomic_read_unchecked(&failed[SMB2_READ_HE]));
58047 seq_printf(m, "\nWrites: %d sent %d failed",
58048 - atomic_read(&sent[SMB2_WRITE_HE]),
58049 - atomic_read(&failed[SMB2_WRITE_HE]));
58050 + atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
58051 + atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
58052 seq_printf(m, "\nLocks: %d sent %d failed",
58053 - atomic_read(&sent[SMB2_LOCK_HE]),
58054 - atomic_read(&failed[SMB2_LOCK_HE]));
58055 + atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
58056 + atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
58057 seq_printf(m, "\nIOCTLs: %d sent %d failed",
58058 - atomic_read(&sent[SMB2_IOCTL_HE]),
58059 - atomic_read(&failed[SMB2_IOCTL_HE]));
58060 + atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
58061 + atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
58062 seq_printf(m, "\nCancels: %d sent %d failed",
58063 - atomic_read(&sent[SMB2_CANCEL_HE]),
58064 - atomic_read(&failed[SMB2_CANCEL_HE]));
58065 + atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
58066 + atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
58067 seq_printf(m, "\nEchos: %d sent %d failed",
58068 - atomic_read(&sent[SMB2_ECHO_HE]),
58069 - atomic_read(&failed[SMB2_ECHO_HE]));
58070 + atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
58071 + atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
58072 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
58073 - atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
58074 - atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
58075 + atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
58076 + atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
58077 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
58078 - atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
58079 - atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
58080 + atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
58081 + atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
58082 seq_printf(m, "\nQueryInfos: %d sent %d failed",
58083 - atomic_read(&sent[SMB2_QUERY_INFO_HE]),
58084 - atomic_read(&failed[SMB2_QUERY_INFO_HE]));
58085 + atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
58086 + atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
58087 seq_printf(m, "\nSetInfos: %d sent %d failed",
58088 - atomic_read(&sent[SMB2_SET_INFO_HE]),
58089 - atomic_read(&failed[SMB2_SET_INFO_HE]));
58090 + atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
58091 + atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
58092 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
58093 - atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
58094 - atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
58095 + atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
58096 + atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
58097 #endif
58098 }
58099
58100 diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
58101 index 1fb6ad2..758e171 100644
58102 --- a/fs/cifs/smb2pdu.c
58103 +++ b/fs/cifs/smb2pdu.c
58104 @@ -2097,8 +2097,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
58105 default:
58106 cifs_dbg(VFS, "info level %u isn't supported\n",
58107 srch_inf->info_level);
58108 - rc = -EINVAL;
58109 - goto qdir_exit;
58110 + return -EINVAL;
58111 }
58112
58113 req->FileIndex = cpu_to_le32(index);
58114 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
58115 index 1da168c..8bc7ff6 100644
58116 --- a/fs/coda/cache.c
58117 +++ b/fs/coda/cache.c
58118 @@ -24,7 +24,7 @@
58119 #include "coda_linux.h"
58120 #include "coda_cache.h"
58121
58122 -static atomic_t permission_epoch = ATOMIC_INIT(0);
58123 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
58124
58125 /* replace or extend an acl cache hit */
58126 void coda_cache_enter(struct inode *inode, int mask)
58127 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
58128 struct coda_inode_info *cii = ITOC(inode);
58129
58130 spin_lock(&cii->c_lock);
58131 - cii->c_cached_epoch = atomic_read(&permission_epoch);
58132 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
58133 if (!uid_eq(cii->c_uid, current_fsuid())) {
58134 cii->c_uid = current_fsuid();
58135 cii->c_cached_perm = mask;
58136 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
58137 {
58138 struct coda_inode_info *cii = ITOC(inode);
58139 spin_lock(&cii->c_lock);
58140 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
58141 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
58142 spin_unlock(&cii->c_lock);
58143 }
58144
58145 /* remove all acl caches */
58146 void coda_cache_clear_all(struct super_block *sb)
58147 {
58148 - atomic_inc(&permission_epoch);
58149 + atomic_inc_unchecked(&permission_epoch);
58150 }
58151
58152
58153 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
58154 spin_lock(&cii->c_lock);
58155 hit = (mask & cii->c_cached_perm) == mask &&
58156 uid_eq(cii->c_uid, current_fsuid()) &&
58157 - cii->c_cached_epoch == atomic_read(&permission_epoch);
58158 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
58159 spin_unlock(&cii->c_lock);
58160
58161 return hit;
58162 diff --git a/fs/compat.c b/fs/compat.c
58163 index 66d3d3c..9c10175 100644
58164 --- a/fs/compat.c
58165 +++ b/fs/compat.c
58166 @@ -54,7 +54,7 @@
58167 #include <asm/ioctls.h>
58168 #include "internal.h"
58169
58170 -int compat_log = 1;
58171 +int compat_log = 0;
58172
58173 int compat_printk(const char *fmt, ...)
58174 {
58175 @@ -512,7 +512,7 @@ COMPAT_SYSCALL_DEFINE2(io_setup, unsigned, nr_reqs, u32 __user *, ctx32p)
58176
58177 set_fs(KERNEL_DS);
58178 /* The __user pointer cast is valid because of the set_fs() */
58179 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
58180 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
58181 set_fs(oldfs);
58182 /* truncating is ok because it's a user address */
58183 if (!ret)
58184 @@ -562,7 +562,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
58185 goto out;
58186
58187 ret = -EINVAL;
58188 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
58189 + if (nr_segs > UIO_MAXIOV)
58190 goto out;
58191 if (nr_segs > fast_segs) {
58192 ret = -ENOMEM;
58193 @@ -850,6 +850,7 @@ struct compat_old_linux_dirent {
58194 struct compat_readdir_callback {
58195 struct dir_context ctx;
58196 struct compat_old_linux_dirent __user *dirent;
58197 + struct file * file;
58198 int result;
58199 };
58200
58201 @@ -867,6 +868,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
58202 buf->result = -EOVERFLOW;
58203 return -EOVERFLOW;
58204 }
58205 +
58206 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58207 + return 0;
58208 +
58209 buf->result++;
58210 dirent = buf->dirent;
58211 if (!access_ok(VERIFY_WRITE, dirent,
58212 @@ -898,6 +903,7 @@ COMPAT_SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
58213 if (!f.file)
58214 return -EBADF;
58215
58216 + buf.file = f.file;
58217 error = iterate_dir(f.file, &buf.ctx);
58218 if (buf.result)
58219 error = buf.result;
58220 @@ -917,6 +923,7 @@ struct compat_getdents_callback {
58221 struct dir_context ctx;
58222 struct compat_linux_dirent __user *current_dir;
58223 struct compat_linux_dirent __user *previous;
58224 + struct file * file;
58225 int count;
58226 int error;
58227 };
58228 @@ -938,6 +945,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
58229 buf->error = -EOVERFLOW;
58230 return -EOVERFLOW;
58231 }
58232 +
58233 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58234 + return 0;
58235 +
58236 dirent = buf->previous;
58237 if (dirent) {
58238 if (__put_user(offset, &dirent->d_off))
58239 @@ -983,6 +994,7 @@ COMPAT_SYSCALL_DEFINE3(getdents, unsigned int, fd,
58240 if (!f.file)
58241 return -EBADF;
58242
58243 + buf.file = f.file;
58244 error = iterate_dir(f.file, &buf.ctx);
58245 if (error >= 0)
58246 error = buf.error;
58247 @@ -1003,6 +1015,7 @@ struct compat_getdents_callback64 {
58248 struct dir_context ctx;
58249 struct linux_dirent64 __user *current_dir;
58250 struct linux_dirent64 __user *previous;
58251 + struct file * file;
58252 int count;
58253 int error;
58254 };
58255 @@ -1019,6 +1032,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
58256 buf->error = -EINVAL; /* only used if we fail.. */
58257 if (reclen > buf->count)
58258 return -EINVAL;
58259 +
58260 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
58261 + return 0;
58262 +
58263 dirent = buf->previous;
58264
58265 if (dirent) {
58266 @@ -1068,6 +1085,7 @@ COMPAT_SYSCALL_DEFINE3(getdents64, unsigned int, fd,
58267 if (!f.file)
58268 return -EBADF;
58269
58270 + buf.file = f.file;
58271 error = iterate_dir(f.file, &buf.ctx);
58272 if (error >= 0)
58273 error = buf.error;
58274 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
58275 index 4d24d17..4f8c09e 100644
58276 --- a/fs/compat_binfmt_elf.c
58277 +++ b/fs/compat_binfmt_elf.c
58278 @@ -30,11 +30,13 @@
58279 #undef elf_phdr
58280 #undef elf_shdr
58281 #undef elf_note
58282 +#undef elf_dyn
58283 #undef elf_addr_t
58284 #define elfhdr elf32_hdr
58285 #define elf_phdr elf32_phdr
58286 #define elf_shdr elf32_shdr
58287 #define elf_note elf32_note
58288 +#define elf_dyn Elf32_Dyn
58289 #define elf_addr_t Elf32_Addr
58290
58291 /*
58292 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
58293 index e822890..59374d5 100644
58294 --- a/fs/compat_ioctl.c
58295 +++ b/fs/compat_ioctl.c
58296 @@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
58297 return -EFAULT;
58298 if (__get_user(udata, &ss32->iomem_base))
58299 return -EFAULT;
58300 - ss.iomem_base = compat_ptr(udata);
58301 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
58302 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
58303 __get_user(ss.port_high, &ss32->port_high))
58304 return -EFAULT;
58305 @@ -703,8 +703,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
58306 for (i = 0; i < nmsgs; i++) {
58307 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
58308 return -EFAULT;
58309 - if (get_user(datap, &umsgs[i].buf) ||
58310 - put_user(compat_ptr(datap), &tmsgs[i].buf))
58311 + if (get_user(datap, (u8 __user * __user *)&umsgs[i].buf) ||
58312 + put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
58313 return -EFAULT;
58314 }
58315 return sys_ioctl(fd, cmd, (unsigned long)tdata);
58316 @@ -797,7 +797,7 @@ static int compat_ioctl_preallocate(struct file *file,
58317 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
58318 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
58319 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
58320 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
58321 + copy_in_user(p->l_pad, p32->l_pad, 4*sizeof(u32)))
58322 return -EFAULT;
58323
58324 return ioctl_preallocate(file, p);
58325 @@ -1618,8 +1618,8 @@ COMPAT_SYSCALL_DEFINE3(ioctl, unsigned int, fd, unsigned int, cmd,
58326 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
58327 {
58328 unsigned int a, b;
58329 - a = *(unsigned int *)p;
58330 - b = *(unsigned int *)q;
58331 + a = *(const unsigned int *)p;
58332 + b = *(const unsigned int *)q;
58333 if (a > b)
58334 return 1;
58335 if (a < b)
58336 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
58337 index e081acb..911df21 100644
58338 --- a/fs/configfs/dir.c
58339 +++ b/fs/configfs/dir.c
58340 @@ -1548,7 +1548,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
58341 }
58342 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
58343 struct configfs_dirent *next;
58344 - const char *name;
58345 + const unsigned char * name;
58346 + char d_name[sizeof(next->s_dentry->d_iname)];
58347 int len;
58348 struct inode *inode = NULL;
58349
58350 @@ -1557,7 +1558,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
58351 continue;
58352
58353 name = configfs_get_name(next);
58354 - len = strlen(name);
58355 + if (next->s_dentry && name == next->s_dentry->d_iname) {
58356 + len = next->s_dentry->d_name.len;
58357 + memcpy(d_name, name, len);
58358 + name = d_name;
58359 + } else
58360 + len = strlen(name);
58361
58362 /*
58363 * We'll have a dentry and an inode for
58364 diff --git a/fs/coredump.c b/fs/coredump.c
58365 index 0b2528f..836c55f 100644
58366 --- a/fs/coredump.c
58367 +++ b/fs/coredump.c
58368 @@ -442,8 +442,8 @@ static void wait_for_dump_helpers(struct file *file)
58369 struct pipe_inode_info *pipe = file->private_data;
58370
58371 pipe_lock(pipe);
58372 - pipe->readers++;
58373 - pipe->writers--;
58374 + atomic_inc(&pipe->readers);
58375 + atomic_dec(&pipe->writers);
58376 wake_up_interruptible_sync(&pipe->wait);
58377 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
58378 pipe_unlock(pipe);
58379 @@ -452,11 +452,11 @@ static void wait_for_dump_helpers(struct file *file)
58380 * We actually want wait_event_freezable() but then we need
58381 * to clear TIF_SIGPENDING and improve dump_interrupted().
58382 */
58383 - wait_event_interruptible(pipe->wait, pipe->readers == 1);
58384 + wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
58385
58386 pipe_lock(pipe);
58387 - pipe->readers--;
58388 - pipe->writers++;
58389 + atomic_dec(&pipe->readers);
58390 + atomic_inc(&pipe->writers);
58391 pipe_unlock(pipe);
58392 }
58393
58394 @@ -503,7 +503,9 @@ void do_coredump(const siginfo_t *siginfo)
58395 struct files_struct *displaced;
58396 bool need_nonrelative = false;
58397 bool core_dumped = false;
58398 - static atomic_t core_dump_count = ATOMIC_INIT(0);
58399 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
58400 + long signr = siginfo->si_signo;
58401 + int dumpable;
58402 struct coredump_params cprm = {
58403 .siginfo = siginfo,
58404 .regs = signal_pt_regs(),
58405 @@ -516,12 +518,17 @@ void do_coredump(const siginfo_t *siginfo)
58406 .mm_flags = mm->flags,
58407 };
58408
58409 - audit_core_dumps(siginfo->si_signo);
58410 + audit_core_dumps(signr);
58411 +
58412 + dumpable = __get_dumpable(cprm.mm_flags);
58413 +
58414 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
58415 + gr_handle_brute_attach(dumpable);
58416
58417 binfmt = mm->binfmt;
58418 if (!binfmt || !binfmt->core_dump)
58419 goto fail;
58420 - if (!__get_dumpable(cprm.mm_flags))
58421 + if (!dumpable)
58422 goto fail;
58423
58424 cred = prepare_creds();
58425 @@ -540,7 +547,7 @@ void do_coredump(const siginfo_t *siginfo)
58426 need_nonrelative = true;
58427 }
58428
58429 - retval = coredump_wait(siginfo->si_signo, &core_state);
58430 + retval = coredump_wait(signr, &core_state);
58431 if (retval < 0)
58432 goto fail_creds;
58433
58434 @@ -583,7 +590,7 @@ void do_coredump(const siginfo_t *siginfo)
58435 }
58436 cprm.limit = RLIM_INFINITY;
58437
58438 - dump_count = atomic_inc_return(&core_dump_count);
58439 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
58440 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
58441 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
58442 task_tgid_vnr(current), current->comm);
58443 @@ -615,6 +622,8 @@ void do_coredump(const siginfo_t *siginfo)
58444 } else {
58445 struct inode *inode;
58446
58447 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
58448 +
58449 if (cprm.limit < binfmt->min_coredump)
58450 goto fail_unlock;
58451
58452 @@ -673,7 +682,7 @@ close_fail:
58453 filp_close(cprm.file, NULL);
58454 fail_dropcount:
58455 if (ispipe)
58456 - atomic_dec(&core_dump_count);
58457 + atomic_dec_unchecked(&core_dump_count);
58458 fail_unlock:
58459 kfree(cn.corename);
58460 coredump_finish(mm, core_dumped);
58461 @@ -694,6 +703,8 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
58462 struct file *file = cprm->file;
58463 loff_t pos = file->f_pos;
58464 ssize_t n;
58465 +
58466 + gr_learn_resource(current, RLIMIT_CORE, cprm->written + nr, 1);
58467 if (cprm->written + nr > cprm->limit)
58468 return 0;
58469 while (nr) {
58470 diff --git a/fs/dcache.c b/fs/dcache.c
58471 index e99c6f5..2838bf58 100644
58472 --- a/fs/dcache.c
58473 +++ b/fs/dcache.c
58474 @@ -1445,7 +1445,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
58475 */
58476 dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
58477 if (name->len > DNAME_INLINE_LEN-1) {
58478 - dname = kmalloc(name->len + 1, GFP_KERNEL);
58479 + dname = kmalloc(round_up(name->len + 1, sizeof(unsigned long)), GFP_KERNEL);
58480 if (!dname) {
58481 kmem_cache_free(dentry_cache, dentry);
58482 return NULL;
58483 @@ -3413,7 +3413,8 @@ void __init vfs_caches_init(unsigned long mempages)
58484 mempages -= reserve;
58485
58486 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
58487 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
58488 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
58489 + SLAB_NO_SANITIZE, NULL);
58490
58491 dcache_init();
58492 inode_init();
58493 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
58494 index 8c41b52..145b1b9 100644
58495 --- a/fs/debugfs/inode.c
58496 +++ b/fs/debugfs/inode.c
58497 @@ -416,7 +416,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
58498 */
58499 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
58500 {
58501 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
58502 + return __create_file(name, S_IFDIR | S_IRWXU,
58503 +#else
58504 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
58505 +#endif
58506 parent, NULL, NULL);
58507 }
58508 EXPORT_SYMBOL_GPL(debugfs_create_dir);
58509 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
58510 index d4a9431..77f9b2e 100644
58511 --- a/fs/ecryptfs/inode.c
58512 +++ b/fs/ecryptfs/inode.c
58513 @@ -673,7 +673,7 @@ static char *ecryptfs_readlink_lower(struct dentry *dentry, size_t *bufsiz)
58514 old_fs = get_fs();
58515 set_fs(get_ds());
58516 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
58517 - (char __user *)lower_buf,
58518 + (char __force_user *)lower_buf,
58519 PATH_MAX);
58520 set_fs(old_fs);
58521 if (rc < 0)
58522 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
58523 index e4141f2..d8263e8 100644
58524 --- a/fs/ecryptfs/miscdev.c
58525 +++ b/fs/ecryptfs/miscdev.c
58526 @@ -304,7 +304,7 @@ check_list:
58527 goto out_unlock_msg_ctx;
58528 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
58529 if (msg_ctx->msg) {
58530 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
58531 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
58532 goto out_unlock_msg_ctx;
58533 i += packet_length_size;
58534 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
58535 diff --git a/fs/exec.c b/fs/exec.c
58536 index 238b7aa..a421d91 100644
58537 --- a/fs/exec.c
58538 +++ b/fs/exec.c
58539 @@ -56,8 +56,20 @@
58540 #include <linux/pipe_fs_i.h>
58541 #include <linux/oom.h>
58542 #include <linux/compat.h>
58543 +#include <linux/random.h>
58544 +#include <linux/seq_file.h>
58545 +#include <linux/coredump.h>
58546 +#include <linux/mman.h>
58547 +
58548 +#ifdef CONFIG_PAX_REFCOUNT
58549 +#include <linux/kallsyms.h>
58550 +#include <linux/kdebug.h>
58551 +#endif
58552 +
58553 +#include <trace/events/fs.h>
58554
58555 #include <asm/uaccess.h>
58556 +#include <asm/sections.h>
58557 #include <asm/mmu_context.h>
58558 #include <asm/tlb.h>
58559
58560 @@ -66,19 +78,34 @@
58561
58562 #include <trace/events/sched.h>
58563
58564 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
58565 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
58566 +{
58567 + 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");
58568 +}
58569 +#endif
58570 +
58571 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
58572 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
58573 +EXPORT_SYMBOL(pax_set_initial_flags_func);
58574 +#endif
58575 +
58576 int suid_dumpable = 0;
58577
58578 static LIST_HEAD(formats);
58579 static DEFINE_RWLOCK(binfmt_lock);
58580
58581 +extern int gr_process_kernel_exec_ban(void);
58582 +extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
58583 +
58584 void __register_binfmt(struct linux_binfmt * fmt, int insert)
58585 {
58586 BUG_ON(!fmt);
58587 if (WARN_ON(!fmt->load_binary))
58588 return;
58589 write_lock(&binfmt_lock);
58590 - insert ? list_add(&fmt->lh, &formats) :
58591 - list_add_tail(&fmt->lh, &formats);
58592 + insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
58593 + pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
58594 write_unlock(&binfmt_lock);
58595 }
58596
58597 @@ -87,7 +114,7 @@ EXPORT_SYMBOL(__register_binfmt);
58598 void unregister_binfmt(struct linux_binfmt * fmt)
58599 {
58600 write_lock(&binfmt_lock);
58601 - list_del(&fmt->lh);
58602 + pax_list_del((struct list_head *)&fmt->lh);
58603 write_unlock(&binfmt_lock);
58604 }
58605
58606 @@ -183,18 +210,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
58607 int write)
58608 {
58609 struct page *page;
58610 - int ret;
58611
58612 -#ifdef CONFIG_STACK_GROWSUP
58613 - if (write) {
58614 - ret = expand_downwards(bprm->vma, pos);
58615 - if (ret < 0)
58616 - return NULL;
58617 - }
58618 -#endif
58619 - ret = get_user_pages(current, bprm->mm, pos,
58620 - 1, write, 1, &page, NULL);
58621 - if (ret <= 0)
58622 + if (0 > expand_downwards(bprm->vma, pos))
58623 + return NULL;
58624 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
58625 return NULL;
58626
58627 if (write) {
58628 @@ -210,6 +229,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
58629 if (size <= ARG_MAX)
58630 return page;
58631
58632 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58633 + // only allow 512KB for argv+env on suid/sgid binaries
58634 + // to prevent easy ASLR exhaustion
58635 + if (((!uid_eq(bprm->cred->euid, current_euid())) ||
58636 + (!gid_eq(bprm->cred->egid, current_egid()))) &&
58637 + (size > (512 * 1024))) {
58638 + put_page(page);
58639 + return NULL;
58640 + }
58641 +#endif
58642 +
58643 /*
58644 * Limit to 1/4-th the stack size for the argv+env strings.
58645 * This ensures that:
58646 @@ -269,6 +299,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
58647 vma->vm_end = STACK_TOP_MAX;
58648 vma->vm_start = vma->vm_end - PAGE_SIZE;
58649 vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
58650 +
58651 +#ifdef CONFIG_PAX_SEGMEXEC
58652 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
58653 +#endif
58654 +
58655 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
58656 INIT_LIST_HEAD(&vma->anon_vma_chain);
58657
58658 @@ -279,6 +314,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
58659 mm->stack_vm = mm->total_vm = 1;
58660 up_write(&mm->mmap_sem);
58661 bprm->p = vma->vm_end - sizeof(void *);
58662 +
58663 +#ifdef CONFIG_PAX_RANDUSTACK
58664 + if (randomize_va_space)
58665 + bprm->p ^= prandom_u32() & ~PAGE_MASK;
58666 +#endif
58667 +
58668 return 0;
58669 err:
58670 up_write(&mm->mmap_sem);
58671 @@ -399,7 +440,7 @@ struct user_arg_ptr {
58672 } ptr;
58673 };
58674
58675 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58676 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58677 {
58678 const char __user *native;
58679
58680 @@ -408,14 +449,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
58681 compat_uptr_t compat;
58682
58683 if (get_user(compat, argv.ptr.compat + nr))
58684 - return ERR_PTR(-EFAULT);
58685 + return (const char __force_user *)ERR_PTR(-EFAULT);
58686
58687 return compat_ptr(compat);
58688 }
58689 #endif
58690
58691 if (get_user(native, argv.ptr.native + nr))
58692 - return ERR_PTR(-EFAULT);
58693 + return (const char __force_user *)ERR_PTR(-EFAULT);
58694
58695 return native;
58696 }
58697 @@ -434,7 +475,7 @@ static int count(struct user_arg_ptr argv, int max)
58698 if (!p)
58699 break;
58700
58701 - if (IS_ERR(p))
58702 + if (IS_ERR((const char __force_kernel *)p))
58703 return -EFAULT;
58704
58705 if (i >= max)
58706 @@ -469,7 +510,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
58707
58708 ret = -EFAULT;
58709 str = get_user_arg_ptr(argv, argc);
58710 - if (IS_ERR(str))
58711 + if (IS_ERR((const char __force_kernel *)str))
58712 goto out;
58713
58714 len = strnlen_user(str, MAX_ARG_STRLEN);
58715 @@ -551,7 +592,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
58716 int r;
58717 mm_segment_t oldfs = get_fs();
58718 struct user_arg_ptr argv = {
58719 - .ptr.native = (const char __user *const __user *)__argv,
58720 + .ptr.native = (const char __user * const __force_user *)__argv,
58721 };
58722
58723 set_fs(KERNEL_DS);
58724 @@ -586,7 +627,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
58725 unsigned long new_end = old_end - shift;
58726 struct mmu_gather tlb;
58727
58728 - BUG_ON(new_start > new_end);
58729 + if (new_start >= new_end || new_start < mmap_min_addr)
58730 + return -ENOMEM;
58731
58732 /*
58733 * ensure there are no vmas between where we want to go
58734 @@ -595,6 +637,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
58735 if (vma != find_vma(mm, new_start))
58736 return -EFAULT;
58737
58738 +#ifdef CONFIG_PAX_SEGMEXEC
58739 + BUG_ON(pax_find_mirror_vma(vma));
58740 +#endif
58741 +
58742 /*
58743 * cover the whole range: [new_start, old_end)
58744 */
58745 @@ -675,10 +721,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
58746 stack_top = arch_align_stack(stack_top);
58747 stack_top = PAGE_ALIGN(stack_top);
58748
58749 - if (unlikely(stack_top < mmap_min_addr) ||
58750 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
58751 - return -ENOMEM;
58752 -
58753 stack_shift = vma->vm_end - stack_top;
58754
58755 bprm->p -= stack_shift;
58756 @@ -690,8 +732,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
58757 bprm->exec -= stack_shift;
58758
58759 down_write(&mm->mmap_sem);
58760 +
58761 + /* Move stack pages down in memory. */
58762 + if (stack_shift) {
58763 + ret = shift_arg_pages(vma, stack_shift);
58764 + if (ret)
58765 + goto out_unlock;
58766 + }
58767 +
58768 vm_flags = VM_STACK_FLAGS;
58769
58770 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
58771 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
58772 + vm_flags &= ~VM_EXEC;
58773 +
58774 +#ifdef CONFIG_PAX_MPROTECT
58775 + if (mm->pax_flags & MF_PAX_MPROTECT)
58776 + vm_flags &= ~VM_MAYEXEC;
58777 +#endif
58778 +
58779 + }
58780 +#endif
58781 +
58782 /*
58783 * Adjust stack execute permissions; explicitly enable for
58784 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
58785 @@ -710,13 +772,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
58786 goto out_unlock;
58787 BUG_ON(prev != vma);
58788
58789 - /* Move stack pages down in memory. */
58790 - if (stack_shift) {
58791 - ret = shift_arg_pages(vma, stack_shift);
58792 - if (ret)
58793 - goto out_unlock;
58794 - }
58795 -
58796 /* mprotect_fixup is overkill to remove the temporary stack flags */
58797 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
58798
58799 @@ -740,6 +795,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
58800 #endif
58801 current->mm->start_stack = bprm->p;
58802 ret = expand_stack(vma, stack_base);
58803 +
58804 +#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
58805 + if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
58806 + unsigned long size;
58807 + vm_flags_t vm_flags;
58808 +
58809 + size = STACK_TOP - vma->vm_end;
58810 + vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
58811 +
58812 + ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
58813 +
58814 +#ifdef CONFIG_X86
58815 + if (!ret) {
58816 + size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
58817 + ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
58818 + }
58819 +#endif
58820 +
58821 + }
58822 +#endif
58823 +
58824 if (ret)
58825 ret = -EFAULT;
58826
58827 @@ -775,6 +851,8 @@ static struct file *do_open_exec(struct filename *name)
58828
58829 fsnotify_open(file);
58830
58831 + trace_open_exec(name->name);
58832 +
58833 err = deny_write_access(file);
58834 if (err)
58835 goto exit;
58836 @@ -804,7 +882,7 @@ int kernel_read(struct file *file, loff_t offset,
58837 old_fs = get_fs();
58838 set_fs(get_ds());
58839 /* The cast to a user pointer is valid due to the set_fs() */
58840 - result = vfs_read(file, (void __user *)addr, count, &pos);
58841 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
58842 set_fs(old_fs);
58843 return result;
58844 }
58845 @@ -849,6 +927,7 @@ static int exec_mmap(struct mm_struct *mm)
58846 tsk->mm = mm;
58847 tsk->active_mm = mm;
58848 activate_mm(active_mm, mm);
58849 + populate_stack();
58850 tsk->mm->vmacache_seqnum = 0;
58851 vmacache_flush(tsk);
58852 task_unlock(tsk);
58853 @@ -1246,7 +1325,7 @@ static void check_unsafe_exec(struct linux_binprm *bprm)
58854 }
58855 rcu_read_unlock();
58856
58857 - if (p->fs->users > n_fs)
58858 + if (atomic_read(&p->fs->users) > n_fs)
58859 bprm->unsafe |= LSM_UNSAFE_SHARE;
58860 else
58861 p->fs->in_exec = 1;
58862 @@ -1422,6 +1501,31 @@ static int exec_binprm(struct linux_binprm *bprm)
58863 return ret;
58864 }
58865
58866 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58867 +static DEFINE_PER_CPU(u64, exec_counter);
58868 +static int __init init_exec_counters(void)
58869 +{
58870 + unsigned int cpu;
58871 +
58872 + for_each_possible_cpu(cpu) {
58873 + per_cpu(exec_counter, cpu) = (u64)cpu;
58874 + }
58875 +
58876 + return 0;
58877 +}
58878 +early_initcall(init_exec_counters);
58879 +static inline void increment_exec_counter(void)
58880 +{
58881 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
58882 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
58883 +}
58884 +#else
58885 +static inline void increment_exec_counter(void) {}
58886 +#endif
58887 +
58888 +extern void gr_handle_exec_args(struct linux_binprm *bprm,
58889 + struct user_arg_ptr argv);
58890 +
58891 /*
58892 * sys_execve() executes a new program.
58893 */
58894 @@ -1429,6 +1533,11 @@ static int do_execve_common(struct filename *filename,
58895 struct user_arg_ptr argv,
58896 struct user_arg_ptr envp)
58897 {
58898 +#ifdef CONFIG_GRKERNSEC
58899 + struct file *old_exec_file;
58900 + struct acl_subject_label *old_acl;
58901 + struct rlimit old_rlim[RLIM_NLIMITS];
58902 +#endif
58903 struct linux_binprm *bprm;
58904 struct file *file;
58905 struct files_struct *displaced;
58906 @@ -1437,6 +1546,8 @@ static int do_execve_common(struct filename *filename,
58907 if (IS_ERR(filename))
58908 return PTR_ERR(filename);
58909
58910 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
58911 +
58912 /*
58913 * We move the actual failure in case of RLIMIT_NPROC excess from
58914 * set*uid() to execve() because too many poorly written programs
58915 @@ -1474,11 +1585,21 @@ static int do_execve_common(struct filename *filename,
58916 if (IS_ERR(file))
58917 goto out_unmark;
58918
58919 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
58920 + retval = -EPERM;
58921 + goto out_unmark;
58922 + }
58923 +
58924 sched_exec();
58925
58926 bprm->file = file;
58927 bprm->filename = bprm->interp = filename->name;
58928
58929 + if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
58930 + retval = -EACCES;
58931 + goto out_unmark;
58932 + }
58933 +
58934 retval = bprm_mm_init(bprm);
58935 if (retval)
58936 goto out_unmark;
58937 @@ -1495,24 +1616,70 @@ static int do_execve_common(struct filename *filename,
58938 if (retval < 0)
58939 goto out;
58940
58941 +#ifdef CONFIG_GRKERNSEC
58942 + old_acl = current->acl;
58943 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
58944 + old_exec_file = current->exec_file;
58945 + get_file(file);
58946 + current->exec_file = file;
58947 +#endif
58948 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
58949 + /* limit suid stack to 8MB
58950 + * we saved the old limits above and will restore them if this exec fails
58951 + */
58952 + if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
58953 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
58954 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
58955 +#endif
58956 +
58957 + if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
58958 + retval = -EPERM;
58959 + goto out_fail;
58960 + }
58961 +
58962 + if (!gr_tpe_allow(file)) {
58963 + retval = -EACCES;
58964 + goto out_fail;
58965 + }
58966 +
58967 + if (gr_check_crash_exec(file)) {
58968 + retval = -EACCES;
58969 + goto out_fail;
58970 + }
58971 +
58972 + retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
58973 + bprm->unsafe);
58974 + if (retval < 0)
58975 + goto out_fail;
58976 +
58977 retval = copy_strings_kernel(1, &bprm->filename, bprm);
58978 if (retval < 0)
58979 - goto out;
58980 + goto out_fail;
58981
58982 bprm->exec = bprm->p;
58983 retval = copy_strings(bprm->envc, envp, bprm);
58984 if (retval < 0)
58985 - goto out;
58986 + goto out_fail;
58987
58988 retval = copy_strings(bprm->argc, argv, bprm);
58989 if (retval < 0)
58990 - goto out;
58991 + goto out_fail;
58992 +
58993 + gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
58994 +
58995 + gr_handle_exec_args(bprm, argv);
58996
58997 retval = exec_binprm(bprm);
58998 if (retval < 0)
58999 - goto out;
59000 + goto out_fail;
59001 +#ifdef CONFIG_GRKERNSEC
59002 + if (old_exec_file)
59003 + fput(old_exec_file);
59004 +#endif
59005
59006 /* execve succeeded */
59007 +
59008 + increment_exec_counter();
59009 current->fs->in_exec = 0;
59010 current->in_execve = 0;
59011 acct_update_integrals(current);
59012 @@ -1523,6 +1690,14 @@ static int do_execve_common(struct filename *filename,
59013 put_files_struct(displaced);
59014 return retval;
59015
59016 +out_fail:
59017 +#ifdef CONFIG_GRKERNSEC
59018 + current->acl = old_acl;
59019 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
59020 + fput(current->exec_file);
59021 + current->exec_file = old_exec_file;
59022 +#endif
59023 +
59024 out:
59025 if (bprm->mm) {
59026 acct_arg_size(bprm, 0);
59027 @@ -1614,3 +1789,312 @@ COMPAT_SYSCALL_DEFINE3(execve, const char __user *, filename,
59028 return compat_do_execve(getname(filename), argv, envp);
59029 }
59030 #endif
59031 +
59032 +int pax_check_flags(unsigned long *flags)
59033 +{
59034 + int retval = 0;
59035 +
59036 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
59037 + if (*flags & MF_PAX_SEGMEXEC)
59038 + {
59039 + *flags &= ~MF_PAX_SEGMEXEC;
59040 + retval = -EINVAL;
59041 + }
59042 +#endif
59043 +
59044 + if ((*flags & MF_PAX_PAGEEXEC)
59045 +
59046 +#ifdef CONFIG_PAX_PAGEEXEC
59047 + && (*flags & MF_PAX_SEGMEXEC)
59048 +#endif
59049 +
59050 + )
59051 + {
59052 + *flags &= ~MF_PAX_PAGEEXEC;
59053 + retval = -EINVAL;
59054 + }
59055 +
59056 + if ((*flags & MF_PAX_MPROTECT)
59057 +
59058 +#ifdef CONFIG_PAX_MPROTECT
59059 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
59060 +#endif
59061 +
59062 + )
59063 + {
59064 + *flags &= ~MF_PAX_MPROTECT;
59065 + retval = -EINVAL;
59066 + }
59067 +
59068 + if ((*flags & MF_PAX_EMUTRAMP)
59069 +
59070 +#ifdef CONFIG_PAX_EMUTRAMP
59071 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
59072 +#endif
59073 +
59074 + )
59075 + {
59076 + *flags &= ~MF_PAX_EMUTRAMP;
59077 + retval = -EINVAL;
59078 + }
59079 +
59080 + return retval;
59081 +}
59082 +
59083 +EXPORT_SYMBOL(pax_check_flags);
59084 +
59085 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
59086 +char *pax_get_path(const struct path *path, char *buf, int buflen)
59087 +{
59088 + char *pathname = d_path(path, buf, buflen);
59089 +
59090 + if (IS_ERR(pathname))
59091 + goto toolong;
59092 +
59093 + pathname = mangle_path(buf, pathname, "\t\n\\");
59094 + if (!pathname)
59095 + goto toolong;
59096 +
59097 + *pathname = 0;
59098 + return buf;
59099 +
59100 +toolong:
59101 + return "<path too long>";
59102 +}
59103 +EXPORT_SYMBOL(pax_get_path);
59104 +
59105 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
59106 +{
59107 + struct task_struct *tsk = current;
59108 + struct mm_struct *mm = current->mm;
59109 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
59110 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
59111 + char *path_exec = NULL;
59112 + char *path_fault = NULL;
59113 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
59114 + siginfo_t info = { };
59115 +
59116 + if (buffer_exec && buffer_fault) {
59117 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
59118 +
59119 + down_read(&mm->mmap_sem);
59120 + vma = mm->mmap;
59121 + while (vma && (!vma_exec || !vma_fault)) {
59122 + if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
59123 + vma_exec = vma;
59124 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
59125 + vma_fault = vma;
59126 + vma = vma->vm_next;
59127 + }
59128 + if (vma_exec)
59129 + path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
59130 + if (vma_fault) {
59131 + start = vma_fault->vm_start;
59132 + end = vma_fault->vm_end;
59133 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
59134 + if (vma_fault->vm_file)
59135 + path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
59136 + else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
59137 + path_fault = "<heap>";
59138 + else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
59139 + path_fault = "<stack>";
59140 + else
59141 + path_fault = "<anonymous mapping>";
59142 + }
59143 + up_read(&mm->mmap_sem);
59144 + }
59145 + if (tsk->signal->curr_ip)
59146 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
59147 + else
59148 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
59149 + 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),
59150 + from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
59151 + free_page((unsigned long)buffer_exec);
59152 + free_page((unsigned long)buffer_fault);
59153 + pax_report_insns(regs, pc, sp);
59154 + info.si_signo = SIGKILL;
59155 + info.si_errno = 0;
59156 + info.si_code = SI_KERNEL;
59157 + info.si_pid = 0;
59158 + info.si_uid = 0;
59159 + do_coredump(&info);
59160 +}
59161 +#endif
59162 +
59163 +#ifdef CONFIG_PAX_REFCOUNT
59164 +void pax_report_refcount_overflow(struct pt_regs *regs)
59165 +{
59166 + if (current->signal->curr_ip)
59167 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
59168 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
59169 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
59170 + else
59171 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
59172 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
59173 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
59174 + preempt_disable();
59175 + show_regs(regs);
59176 + preempt_enable();
59177 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
59178 +}
59179 +#endif
59180 +
59181 +#ifdef CONFIG_PAX_USERCOPY
59182 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
59183 +static noinline int check_stack_object(const void *obj, unsigned long len)
59184 +{
59185 + const void * const stack = task_stack_page(current);
59186 + const void * const stackend = stack + THREAD_SIZE;
59187 +
59188 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
59189 + const void *frame = NULL;
59190 + const void *oldframe;
59191 +#endif
59192 +
59193 + if (obj + len < obj)
59194 + return -1;
59195 +
59196 + if (obj + len <= stack || stackend <= obj)
59197 + return 0;
59198 +
59199 + if (obj < stack || stackend < obj + len)
59200 + return -1;
59201 +
59202 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
59203 + oldframe = __builtin_frame_address(1);
59204 + if (oldframe)
59205 + frame = __builtin_frame_address(2);
59206 + /*
59207 + low ----------------------------------------------> high
59208 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
59209 + ^----------------^
59210 + allow copies only within here
59211 + */
59212 + while (stack <= frame && frame < stackend) {
59213 + /* if obj + len extends past the last frame, this
59214 + check won't pass and the next frame will be 0,
59215 + causing us to bail out and correctly report
59216 + the copy as invalid
59217 + */
59218 + if (obj + len <= frame)
59219 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
59220 + oldframe = frame;
59221 + frame = *(const void * const *)frame;
59222 + }
59223 + return -1;
59224 +#else
59225 + return 1;
59226 +#endif
59227 +}
59228 +
59229 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
59230 +{
59231 + if (current->signal->curr_ip)
59232 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
59233 + &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
59234 + else
59235 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
59236 + to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
59237 + dump_stack();
59238 + gr_handle_kernel_exploit();
59239 + do_group_exit(SIGKILL);
59240 +}
59241 +#endif
59242 +
59243 +#ifdef CONFIG_PAX_USERCOPY
59244 +
59245 +static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
59246 +{
59247 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
59248 + unsigned long textlow = ktla_ktva((unsigned long)_stext);
59249 +#ifdef CONFIG_MODULES
59250 + unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
59251 +#else
59252 + unsigned long texthigh = ktla_ktva((unsigned long)_etext);
59253 +#endif
59254 +
59255 +#else
59256 + unsigned long textlow = (unsigned long)_stext;
59257 + unsigned long texthigh = (unsigned long)_etext;
59258 +
59259 +#ifdef CONFIG_X86_64
59260 + /* check against linear mapping as well */
59261 + if (high > (unsigned long)__va(__pa(textlow)) &&
59262 + low < (unsigned long)__va(__pa(texthigh)))
59263 + return true;
59264 +#endif
59265 +
59266 +#endif
59267 +
59268 + if (high <= textlow || low >= texthigh)
59269 + return false;
59270 + else
59271 + return true;
59272 +}
59273 +#endif
59274 +
59275 +void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size)
59276 +{
59277 +#ifdef CONFIG_PAX_USERCOPY
59278 + const char *type;
59279 +#endif
59280 +
59281 +#ifndef CONFIG_STACK_GROWSUP
59282 + unsigned long stackstart = (unsigned long)task_stack_page(current);
59283 + unsigned long currentsp = (unsigned long)&stackstart;
59284 + if (unlikely((currentsp < stackstart + 512 ||
59285 + currentsp >= stackstart + THREAD_SIZE) && !in_interrupt()))
59286 + BUG();
59287 +#endif
59288 +
59289 +#ifndef CONFIG_PAX_USERCOPY_DEBUG
59290 + if (const_size)
59291 + return;
59292 +#endif
59293 +
59294 +#ifdef CONFIG_PAX_USERCOPY
59295 + if (!n)
59296 + return;
59297 +
59298 + type = check_heap_object(ptr, n);
59299 + if (!type) {
59300 + int ret = check_stack_object(ptr, n);
59301 + if (ret == 1 || ret == 2)
59302 + return;
59303 + if (ret == 0) {
59304 + if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
59305 + type = "<kernel text>";
59306 + else
59307 + return;
59308 + } else
59309 + type = "<process stack>";
59310 + }
59311 +
59312 + pax_report_usercopy(ptr, n, to_user, type);
59313 +#endif
59314 +
59315 +}
59316 +EXPORT_SYMBOL(__check_object_size);
59317 +
59318 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
59319 +void pax_track_stack(void)
59320 +{
59321 + unsigned long sp = (unsigned long)&sp;
59322 + if (sp < current_thread_info()->lowest_stack &&
59323 + sp > (unsigned long)task_stack_page(current))
59324 + current_thread_info()->lowest_stack = sp;
59325 + if (unlikely((sp & ~(THREAD_SIZE - 1)) < (THREAD_SIZE/16)))
59326 + BUG();
59327 +}
59328 +EXPORT_SYMBOL(pax_track_stack);
59329 +#endif
59330 +
59331 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
59332 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
59333 +{
59334 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
59335 + dump_stack();
59336 + do_group_exit(SIGKILL);
59337 +}
59338 +EXPORT_SYMBOL(report_size_overflow);
59339 +#endif
59340 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
59341 index 9f9992b..8b59411 100644
59342 --- a/fs/ext2/balloc.c
59343 +++ b/fs/ext2/balloc.c
59344 @@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
59345
59346 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
59347 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
59348 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
59349 + if (free_blocks < root_blocks + 1 &&
59350 !uid_eq(sbi->s_resuid, current_fsuid()) &&
59351 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
59352 - !in_group_p (sbi->s_resgid))) {
59353 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
59354 return 0;
59355 }
59356 return 1;
59357 diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
59358 index 9142614..97484fa 100644
59359 --- a/fs/ext2/xattr.c
59360 +++ b/fs/ext2/xattr.c
59361 @@ -247,7 +247,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
59362 struct buffer_head *bh = NULL;
59363 struct ext2_xattr_entry *entry;
59364 char *end;
59365 - size_t rest = buffer_size;
59366 + size_t rest = buffer_size, total_size = 0;
59367 int error;
59368
59369 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
59370 @@ -305,9 +305,10 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
59371 buffer += size;
59372 }
59373 rest -= size;
59374 + total_size += size;
59375 }
59376 }
59377 - error = buffer_size - rest; /* total size */
59378 + error = total_size;
59379
59380 cleanup:
59381 brelse(bh);
59382 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
59383 index 158b5d4..2432610 100644
59384 --- a/fs/ext3/balloc.c
59385 +++ b/fs/ext3/balloc.c
59386 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
59387
59388 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
59389 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
59390 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
59391 + if (free_blocks < root_blocks + 1 &&
59392 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
59393 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
59394 - !in_group_p (sbi->s_resgid))) {
59395 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
59396 return 0;
59397 }
59398 return 1;
59399 diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
59400 index c6874be..f8a6ae8 100644
59401 --- a/fs/ext3/xattr.c
59402 +++ b/fs/ext3/xattr.c
59403 @@ -330,7 +330,7 @@ static int
59404 ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
59405 char *buffer, size_t buffer_size)
59406 {
59407 - size_t rest = buffer_size;
59408 + size_t rest = buffer_size, total_size = 0;
59409
59410 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
59411 const struct xattr_handler *handler =
59412 @@ -347,9 +347,10 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
59413 buffer += size;
59414 }
59415 rest -= size;
59416 + total_size += size;
59417 }
59418 }
59419 - return buffer_size - rest;
59420 + return total_size;
59421 }
59422
59423 static int
59424 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
59425 index 5c56785..77698a2 100644
59426 --- a/fs/ext4/balloc.c
59427 +++ b/fs/ext4/balloc.c
59428 @@ -534,8 +534,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
59429 /* Hm, nope. Are (enough) root reserved clusters available? */
59430 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
59431 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
59432 - capable(CAP_SYS_RESOURCE) ||
59433 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
59434 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
59435 + capable_nolog(CAP_SYS_RESOURCE)) {
59436
59437 if (free_clusters >= (nclusters + dirty_clusters +
59438 resv_clusters))
59439 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
59440 index f542e48..c0275f5 100644
59441 --- a/fs/ext4/ext4.h
59442 +++ b/fs/ext4/ext4.h
59443 @@ -1274,19 +1274,19 @@ struct ext4_sb_info {
59444 unsigned long s_mb_last_start;
59445
59446 /* stats for buddy allocator */
59447 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
59448 - atomic_t s_bal_success; /* we found long enough chunks */
59449 - atomic_t s_bal_allocated; /* in blocks */
59450 - atomic_t s_bal_ex_scanned; /* total extents scanned */
59451 - atomic_t s_bal_goals; /* goal hits */
59452 - atomic_t s_bal_breaks; /* too long searches */
59453 - atomic_t s_bal_2orders; /* 2^order hits */
59454 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
59455 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
59456 + atomic_unchecked_t s_bal_allocated; /* in blocks */
59457 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
59458 + atomic_unchecked_t s_bal_goals; /* goal hits */
59459 + atomic_unchecked_t s_bal_breaks; /* too long searches */
59460 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
59461 spinlock_t s_bal_lock;
59462 unsigned long s_mb_buddies_generated;
59463 unsigned long long s_mb_generation_time;
59464 - atomic_t s_mb_lost_chunks;
59465 - atomic_t s_mb_preallocated;
59466 - atomic_t s_mb_discarded;
59467 + atomic_unchecked_t s_mb_lost_chunks;
59468 + atomic_unchecked_t s_mb_preallocated;
59469 + atomic_unchecked_t s_mb_discarded;
59470 atomic_t s_lock_busy;
59471
59472 /* locality groups */
59473 diff --git a/fs/ext4/indirect.c b/fs/ext4/indirect.c
59474 index e6574d7..c30cbe2 100644
59475 --- a/fs/ext4/indirect.c
59476 +++ b/fs/ext4/indirect.c
59477 @@ -1345,8 +1345,8 @@ static int free_hole_blocks(handle_t *handle, struct inode *inode,
59478 if (level == 0 ||
59479 (bh && all_zeroes((__le32 *)bh->b_data,
59480 (__le32 *)bh->b_data + addr_per_block))) {
59481 - ext4_free_data(handle, inode, parent_bh, &blk, &blk+1);
59482 - *i_data = 0;
59483 + ext4_free_data(handle, inode, parent_bh,
59484 + i_data, i_data + 1);
59485 }
59486 brelse(bh);
59487 bh = NULL;
59488 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
59489 index fe4e668..f983538 100644
59490 --- a/fs/ext4/mballoc.c
59491 +++ b/fs/ext4/mballoc.c
59492 @@ -1889,7 +1889,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
59493 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
59494
59495 if (EXT4_SB(sb)->s_mb_stats)
59496 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
59497 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
59498
59499 break;
59500 }
59501 @@ -2199,7 +2199,7 @@ repeat:
59502 ac->ac_status = AC_STATUS_CONTINUE;
59503 ac->ac_flags |= EXT4_MB_HINT_FIRST;
59504 cr = 3;
59505 - atomic_inc(&sbi->s_mb_lost_chunks);
59506 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
59507 goto repeat;
59508 }
59509 }
59510 @@ -2707,25 +2707,25 @@ int ext4_mb_release(struct super_block *sb)
59511 if (sbi->s_mb_stats) {
59512 ext4_msg(sb, KERN_INFO,
59513 "mballoc: %u blocks %u reqs (%u success)",
59514 - atomic_read(&sbi->s_bal_allocated),
59515 - atomic_read(&sbi->s_bal_reqs),
59516 - atomic_read(&sbi->s_bal_success));
59517 + atomic_read_unchecked(&sbi->s_bal_allocated),
59518 + atomic_read_unchecked(&sbi->s_bal_reqs),
59519 + atomic_read_unchecked(&sbi->s_bal_success));
59520 ext4_msg(sb, KERN_INFO,
59521 "mballoc: %u extents scanned, %u goal hits, "
59522 "%u 2^N hits, %u breaks, %u lost",
59523 - atomic_read(&sbi->s_bal_ex_scanned),
59524 - atomic_read(&sbi->s_bal_goals),
59525 - atomic_read(&sbi->s_bal_2orders),
59526 - atomic_read(&sbi->s_bal_breaks),
59527 - atomic_read(&sbi->s_mb_lost_chunks));
59528 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
59529 + atomic_read_unchecked(&sbi->s_bal_goals),
59530 + atomic_read_unchecked(&sbi->s_bal_2orders),
59531 + atomic_read_unchecked(&sbi->s_bal_breaks),
59532 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
59533 ext4_msg(sb, KERN_INFO,
59534 "mballoc: %lu generated and it took %Lu",
59535 sbi->s_mb_buddies_generated,
59536 sbi->s_mb_generation_time);
59537 ext4_msg(sb, KERN_INFO,
59538 "mballoc: %u preallocated, %u discarded",
59539 - atomic_read(&sbi->s_mb_preallocated),
59540 - atomic_read(&sbi->s_mb_discarded));
59541 + atomic_read_unchecked(&sbi->s_mb_preallocated),
59542 + atomic_read_unchecked(&sbi->s_mb_discarded));
59543 }
59544
59545 free_percpu(sbi->s_locality_groups);
59546 @@ -3179,16 +3179,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
59547 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
59548
59549 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
59550 - atomic_inc(&sbi->s_bal_reqs);
59551 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
59552 + atomic_inc_unchecked(&sbi->s_bal_reqs);
59553 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
59554 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
59555 - atomic_inc(&sbi->s_bal_success);
59556 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
59557 + atomic_inc_unchecked(&sbi->s_bal_success);
59558 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
59559 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
59560 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
59561 - atomic_inc(&sbi->s_bal_goals);
59562 + atomic_inc_unchecked(&sbi->s_bal_goals);
59563 if (ac->ac_found > sbi->s_mb_max_to_scan)
59564 - atomic_inc(&sbi->s_bal_breaks);
59565 + atomic_inc_unchecked(&sbi->s_bal_breaks);
59566 }
59567
59568 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
59569 @@ -3593,7 +3593,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
59570 trace_ext4_mb_new_inode_pa(ac, pa);
59571
59572 ext4_mb_use_inode_pa(ac, pa);
59573 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
59574 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
59575
59576 ei = EXT4_I(ac->ac_inode);
59577 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
59578 @@ -3653,7 +3653,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
59579 trace_ext4_mb_new_group_pa(ac, pa);
59580
59581 ext4_mb_use_group_pa(ac, pa);
59582 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
59583 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
59584
59585 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
59586 lg = ac->ac_lg;
59587 @@ -3742,7 +3742,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
59588 * from the bitmap and continue.
59589 */
59590 }
59591 - atomic_add(free, &sbi->s_mb_discarded);
59592 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
59593
59594 return err;
59595 }
59596 @@ -3760,7 +3760,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
59597 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
59598 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
59599 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
59600 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
59601 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
59602 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
59603
59604 return 0;
59605 diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
59606 index 04434ad..6404663 100644
59607 --- a/fs/ext4/mmp.c
59608 +++ b/fs/ext4/mmp.c
59609 @@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
59610 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
59611 const char *function, unsigned int line, const char *msg)
59612 {
59613 - __ext4_warning(sb, function, line, msg);
59614 + __ext4_warning(sb, function, line, "%s", msg);
59615 __ext4_warning(sb, function, line,
59616 "MMP failure info: last update time: %llu, last update "
59617 "node: %s, last update device: %s\n",
59618 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
59619 index 6f9e6fa..5431c02 100644
59620 --- a/fs/ext4/super.c
59621 +++ b/fs/ext4/super.c
59622 @@ -1275,7 +1275,7 @@ static ext4_fsblk_t get_sb_block(void **data)
59623 }
59624
59625 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
59626 -static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
59627 +static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
59628 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
59629
59630 #ifdef CONFIG_QUOTA
59631 @@ -2455,7 +2455,7 @@ struct ext4_attr {
59632 int offset;
59633 int deprecated_val;
59634 } u;
59635 -};
59636 +} __do_const;
59637
59638 static int parse_strtoull(const char *buf,
59639 unsigned long long max, unsigned long long *value)
59640 diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
59641 index 4eec399..1d9444c 100644
59642 --- a/fs/ext4/xattr.c
59643 +++ b/fs/ext4/xattr.c
59644 @@ -383,7 +383,7 @@ static int
59645 ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
59646 char *buffer, size_t buffer_size)
59647 {
59648 - size_t rest = buffer_size;
59649 + size_t rest = buffer_size, total_size = 0;
59650
59651 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
59652 const struct xattr_handler *handler =
59653 @@ -400,9 +400,10 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
59654 buffer += size;
59655 }
59656 rest -= size;
59657 + total_size += size;
59658 }
59659 }
59660 - return buffer_size - rest;
59661 + return total_size;
59662 }
59663
59664 static int
59665 diff --git a/fs/fcntl.c b/fs/fcntl.c
59666 index 72c82f6..a18b263 100644
59667 --- a/fs/fcntl.c
59668 +++ b/fs/fcntl.c
59669 @@ -106,6 +106,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
59670 if (err)
59671 return err;
59672
59673 + if (gr_handle_chroot_fowner(pid, type))
59674 + return -ENOENT;
59675 + if (gr_check_protected_task_fowner(pid, type))
59676 + return -EACCES;
59677 +
59678 f_modown(filp, pid, type, force);
59679 return 0;
59680 }
59681 diff --git a/fs/fhandle.c b/fs/fhandle.c
59682 index 999ff5c..ac037c9 100644
59683 --- a/fs/fhandle.c
59684 +++ b/fs/fhandle.c
59685 @@ -8,6 +8,7 @@
59686 #include <linux/fs_struct.h>
59687 #include <linux/fsnotify.h>
59688 #include <linux/personality.h>
59689 +#include <linux/grsecurity.h>
59690 #include <asm/uaccess.h>
59691 #include "internal.h"
59692 #include "mount.h"
59693 @@ -67,8 +68,7 @@ static long do_sys_name_to_handle(struct path *path,
59694 } else
59695 retval = 0;
59696 /* copy the mount id */
59697 - if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
59698 - sizeof(*mnt_id)) ||
59699 + if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
59700 copy_to_user(ufh, handle,
59701 sizeof(struct file_handle) + handle_bytes))
59702 retval = -EFAULT;
59703 @@ -175,7 +175,7 @@ static int handle_to_path(int mountdirfd, struct file_handle __user *ufh,
59704 * the directory. Ideally we would like CAP_DAC_SEARCH.
59705 * But we don't have that
59706 */
59707 - if (!capable(CAP_DAC_READ_SEARCH)) {
59708 + if (!capable(CAP_DAC_READ_SEARCH) || !gr_chroot_fhandle()) {
59709 retval = -EPERM;
59710 goto out_err;
59711 }
59712 diff --git a/fs/file.c b/fs/file.c
59713 index 8f294cf..d0f3872 100644
59714 --- a/fs/file.c
59715 +++ b/fs/file.c
59716 @@ -16,6 +16,7 @@
59717 #include <linux/slab.h>
59718 #include <linux/vmalloc.h>
59719 #include <linux/file.h>
59720 +#include <linux/security.h>
59721 #include <linux/fdtable.h>
59722 #include <linux/bitops.h>
59723 #include <linux/interrupt.h>
59724 @@ -144,7 +145,7 @@ out:
59725 * Return <0 error code on error; 1 on successful completion.
59726 * The files->file_lock should be held on entry, and will be held on exit.
59727 */
59728 -static int expand_fdtable(struct files_struct *files, int nr)
59729 +static int expand_fdtable(struct files_struct *files, unsigned int nr)
59730 __releases(files->file_lock)
59731 __acquires(files->file_lock)
59732 {
59733 @@ -189,7 +190,7 @@ static int expand_fdtable(struct files_struct *files, int nr)
59734 * expanded and execution may have blocked.
59735 * The files->file_lock should be held on entry, and will be held on exit.
59736 */
59737 -static int expand_files(struct files_struct *files, int nr)
59738 +static int expand_files(struct files_struct *files, unsigned int nr)
59739 {
59740 struct fdtable *fdt;
59741
59742 @@ -804,6 +805,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
59743 if (!file)
59744 return __close_fd(files, fd);
59745
59746 + gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
59747 if (fd >= rlimit(RLIMIT_NOFILE))
59748 return -EBADF;
59749
59750 @@ -830,6 +832,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
59751 if (unlikely(oldfd == newfd))
59752 return -EINVAL;
59753
59754 + gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
59755 if (newfd >= rlimit(RLIMIT_NOFILE))
59756 return -EBADF;
59757
59758 @@ -885,6 +888,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
59759 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
59760 {
59761 int err;
59762 + gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
59763 if (from >= rlimit(RLIMIT_NOFILE))
59764 return -EINVAL;
59765 err = alloc_fd(from, flags);
59766 diff --git a/fs/filesystems.c b/fs/filesystems.c
59767 index 5797d45..7d7d79a 100644
59768 --- a/fs/filesystems.c
59769 +++ b/fs/filesystems.c
59770 @@ -275,7 +275,11 @@ struct file_system_type *get_fs_type(const char *name)
59771 int len = dot ? dot - name : strlen(name);
59772
59773 fs = __get_fs_type(name, len);
59774 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
59775 + if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
59776 +#else
59777 if (!fs && (request_module("fs-%.*s", len, name) == 0))
59778 +#endif
59779 fs = __get_fs_type(name, len);
59780
59781 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
59782 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
59783 index 7dca743..543d620 100644
59784 --- a/fs/fs_struct.c
59785 +++ b/fs/fs_struct.c
59786 @@ -4,6 +4,7 @@
59787 #include <linux/path.h>
59788 #include <linux/slab.h>
59789 #include <linux/fs_struct.h>
59790 +#include <linux/grsecurity.h>
59791 #include "internal.h"
59792
59793 /*
59794 @@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
59795 write_seqcount_begin(&fs->seq);
59796 old_root = fs->root;
59797 fs->root = *path;
59798 + gr_set_chroot_entries(current, path);
59799 write_seqcount_end(&fs->seq);
59800 spin_unlock(&fs->lock);
59801 if (old_root.dentry)
59802 @@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
59803 int hits = 0;
59804 spin_lock(&fs->lock);
59805 write_seqcount_begin(&fs->seq);
59806 + /* this root replacement is only done by pivot_root,
59807 + leave grsec's chroot tagging alone for this task
59808 + so that a pivoted root isn't treated as a chroot
59809 + */
59810 hits += replace_path(&fs->root, old_root, new_root);
59811 hits += replace_path(&fs->pwd, old_root, new_root);
59812 write_seqcount_end(&fs->seq);
59813 @@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
59814 task_lock(tsk);
59815 spin_lock(&fs->lock);
59816 tsk->fs = NULL;
59817 - kill = !--fs->users;
59818 + gr_clear_chroot_entries(tsk);
59819 + kill = !atomic_dec_return(&fs->users);
59820 spin_unlock(&fs->lock);
59821 task_unlock(tsk);
59822 if (kill)
59823 @@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
59824 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
59825 /* We don't need to lock fs - think why ;-) */
59826 if (fs) {
59827 - fs->users = 1;
59828 + atomic_set(&fs->users, 1);
59829 fs->in_exec = 0;
59830 spin_lock_init(&fs->lock);
59831 seqcount_init(&fs->seq);
59832 @@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
59833 spin_lock(&old->lock);
59834 fs->root = old->root;
59835 path_get(&fs->root);
59836 + /* instead of calling gr_set_chroot_entries here,
59837 + we call it from every caller of this function
59838 + */
59839 fs->pwd = old->pwd;
59840 path_get(&fs->pwd);
59841 spin_unlock(&old->lock);
59842 @@ -139,8 +149,9 @@ int unshare_fs_struct(void)
59843
59844 task_lock(current);
59845 spin_lock(&fs->lock);
59846 - kill = !--fs->users;
59847 + kill = !atomic_dec_return(&fs->users);
59848 current->fs = new_fs;
59849 + gr_set_chroot_entries(current, &new_fs->root);
59850 spin_unlock(&fs->lock);
59851 task_unlock(current);
59852
59853 @@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
59854
59855 int current_umask(void)
59856 {
59857 - return current->fs->umask;
59858 + return current->fs->umask | gr_acl_umask();
59859 }
59860 EXPORT_SYMBOL(current_umask);
59861
59862 /* to be mentioned only in INIT_TASK */
59863 struct fs_struct init_fs = {
59864 - .users = 1,
59865 + .users = ATOMIC_INIT(1),
59866 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
59867 .seq = SEQCNT_ZERO(init_fs.seq),
59868 .umask = 0022,
59869 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
59870 index 29d7feb..303644d 100644
59871 --- a/fs/fscache/cookie.c
59872 +++ b/fs/fscache/cookie.c
59873 @@ -19,7 +19,7 @@
59874
59875 struct kmem_cache *fscache_cookie_jar;
59876
59877 -static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
59878 +static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
59879
59880 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
59881 static int fscache_alloc_object(struct fscache_cache *cache,
59882 @@ -69,11 +69,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
59883 parent ? (char *) parent->def->name : "<no-parent>",
59884 def->name, netfs_data, enable);
59885
59886 - fscache_stat(&fscache_n_acquires);
59887 + fscache_stat_unchecked(&fscache_n_acquires);
59888
59889 /* if there's no parent cookie, then we don't create one here either */
59890 if (!parent) {
59891 - fscache_stat(&fscache_n_acquires_null);
59892 + fscache_stat_unchecked(&fscache_n_acquires_null);
59893 _leave(" [no parent]");
59894 return NULL;
59895 }
59896 @@ -88,7 +88,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
59897 /* allocate and initialise a cookie */
59898 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
59899 if (!cookie) {
59900 - fscache_stat(&fscache_n_acquires_oom);
59901 + fscache_stat_unchecked(&fscache_n_acquires_oom);
59902 _leave(" [ENOMEM]");
59903 return NULL;
59904 }
59905 @@ -115,13 +115,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
59906
59907 switch (cookie->def->type) {
59908 case FSCACHE_COOKIE_TYPE_INDEX:
59909 - fscache_stat(&fscache_n_cookie_index);
59910 + fscache_stat_unchecked(&fscache_n_cookie_index);
59911 break;
59912 case FSCACHE_COOKIE_TYPE_DATAFILE:
59913 - fscache_stat(&fscache_n_cookie_data);
59914 + fscache_stat_unchecked(&fscache_n_cookie_data);
59915 break;
59916 default:
59917 - fscache_stat(&fscache_n_cookie_special);
59918 + fscache_stat_unchecked(&fscache_n_cookie_special);
59919 break;
59920 }
59921
59922 @@ -135,7 +135,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
59923 } else {
59924 atomic_dec(&parent->n_children);
59925 __fscache_cookie_put(cookie);
59926 - fscache_stat(&fscache_n_acquires_nobufs);
59927 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
59928 _leave(" = NULL");
59929 return NULL;
59930 }
59931 @@ -144,7 +144,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
59932 }
59933 }
59934
59935 - fscache_stat(&fscache_n_acquires_ok);
59936 + fscache_stat_unchecked(&fscache_n_acquires_ok);
59937 _leave(" = %p", cookie);
59938 return cookie;
59939 }
59940 @@ -213,7 +213,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
59941 cache = fscache_select_cache_for_object(cookie->parent);
59942 if (!cache) {
59943 up_read(&fscache_addremove_sem);
59944 - fscache_stat(&fscache_n_acquires_no_cache);
59945 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
59946 _leave(" = -ENOMEDIUM [no cache]");
59947 return -ENOMEDIUM;
59948 }
59949 @@ -297,14 +297,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
59950 object = cache->ops->alloc_object(cache, cookie);
59951 fscache_stat_d(&fscache_n_cop_alloc_object);
59952 if (IS_ERR(object)) {
59953 - fscache_stat(&fscache_n_object_no_alloc);
59954 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
59955 ret = PTR_ERR(object);
59956 goto error;
59957 }
59958
59959 - fscache_stat(&fscache_n_object_alloc);
59960 + fscache_stat_unchecked(&fscache_n_object_alloc);
59961
59962 - object->debug_id = atomic_inc_return(&fscache_object_debug_id);
59963 + object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
59964
59965 _debug("ALLOC OBJ%x: %s {%lx}",
59966 object->debug_id, cookie->def->name, object->events);
59967 @@ -418,7 +418,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
59968
59969 _enter("{%s}", cookie->def->name);
59970
59971 - fscache_stat(&fscache_n_invalidates);
59972 + fscache_stat_unchecked(&fscache_n_invalidates);
59973
59974 /* Only permit invalidation of data files. Invalidating an index will
59975 * require the caller to release all its attachments to the tree rooted
59976 @@ -477,10 +477,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
59977 {
59978 struct fscache_object *object;
59979
59980 - fscache_stat(&fscache_n_updates);
59981 + fscache_stat_unchecked(&fscache_n_updates);
59982
59983 if (!cookie) {
59984 - fscache_stat(&fscache_n_updates_null);
59985 + fscache_stat_unchecked(&fscache_n_updates_null);
59986 _leave(" [no cookie]");
59987 return;
59988 }
59989 @@ -581,12 +581,12 @@ EXPORT_SYMBOL(__fscache_disable_cookie);
59990 */
59991 void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
59992 {
59993 - fscache_stat(&fscache_n_relinquishes);
59994 + fscache_stat_unchecked(&fscache_n_relinquishes);
59995 if (retire)
59996 - fscache_stat(&fscache_n_relinquishes_retire);
59997 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
59998
59999 if (!cookie) {
60000 - fscache_stat(&fscache_n_relinquishes_null);
60001 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
60002 _leave(" [no cookie]");
60003 return;
60004 }
60005 @@ -687,7 +687,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
60006 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
60007 goto inconsistent;
60008
60009 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
60010 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
60011
60012 __fscache_use_cookie(cookie);
60013 if (fscache_submit_op(object, op) < 0)
60014 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
60015 index 4226f66..0fb3f45 100644
60016 --- a/fs/fscache/internal.h
60017 +++ b/fs/fscache/internal.h
60018 @@ -133,8 +133,8 @@ extern void fscache_operation_gc(struct work_struct *);
60019 extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
60020 extern int fscache_wait_for_operation_activation(struct fscache_object *,
60021 struct fscache_operation *,
60022 - atomic_t *,
60023 - atomic_t *,
60024 + atomic_unchecked_t *,
60025 + atomic_unchecked_t *,
60026 void (*)(struct fscache_operation *));
60027 extern void fscache_invalidate_writes(struct fscache_cookie *);
60028
60029 @@ -153,101 +153,101 @@ extern void fscache_proc_cleanup(void);
60030 * stats.c
60031 */
60032 #ifdef CONFIG_FSCACHE_STATS
60033 -extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
60034 -extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
60035 +extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
60036 +extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
60037
60038 -extern atomic_t fscache_n_op_pend;
60039 -extern atomic_t fscache_n_op_run;
60040 -extern atomic_t fscache_n_op_enqueue;
60041 -extern atomic_t fscache_n_op_deferred_release;
60042 -extern atomic_t fscache_n_op_release;
60043 -extern atomic_t fscache_n_op_gc;
60044 -extern atomic_t fscache_n_op_cancelled;
60045 -extern atomic_t fscache_n_op_rejected;
60046 +extern atomic_unchecked_t fscache_n_op_pend;
60047 +extern atomic_unchecked_t fscache_n_op_run;
60048 +extern atomic_unchecked_t fscache_n_op_enqueue;
60049 +extern atomic_unchecked_t fscache_n_op_deferred_release;
60050 +extern atomic_unchecked_t fscache_n_op_release;
60051 +extern atomic_unchecked_t fscache_n_op_gc;
60052 +extern atomic_unchecked_t fscache_n_op_cancelled;
60053 +extern atomic_unchecked_t fscache_n_op_rejected;
60054
60055 -extern atomic_t fscache_n_attr_changed;
60056 -extern atomic_t fscache_n_attr_changed_ok;
60057 -extern atomic_t fscache_n_attr_changed_nobufs;
60058 -extern atomic_t fscache_n_attr_changed_nomem;
60059 -extern atomic_t fscache_n_attr_changed_calls;
60060 +extern atomic_unchecked_t fscache_n_attr_changed;
60061 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
60062 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
60063 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
60064 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
60065
60066 -extern atomic_t fscache_n_allocs;
60067 -extern atomic_t fscache_n_allocs_ok;
60068 -extern atomic_t fscache_n_allocs_wait;
60069 -extern atomic_t fscache_n_allocs_nobufs;
60070 -extern atomic_t fscache_n_allocs_intr;
60071 -extern atomic_t fscache_n_allocs_object_dead;
60072 -extern atomic_t fscache_n_alloc_ops;
60073 -extern atomic_t fscache_n_alloc_op_waits;
60074 +extern atomic_unchecked_t fscache_n_allocs;
60075 +extern atomic_unchecked_t fscache_n_allocs_ok;
60076 +extern atomic_unchecked_t fscache_n_allocs_wait;
60077 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
60078 +extern atomic_unchecked_t fscache_n_allocs_intr;
60079 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
60080 +extern atomic_unchecked_t fscache_n_alloc_ops;
60081 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
60082
60083 -extern atomic_t fscache_n_retrievals;
60084 -extern atomic_t fscache_n_retrievals_ok;
60085 -extern atomic_t fscache_n_retrievals_wait;
60086 -extern atomic_t fscache_n_retrievals_nodata;
60087 -extern atomic_t fscache_n_retrievals_nobufs;
60088 -extern atomic_t fscache_n_retrievals_intr;
60089 -extern atomic_t fscache_n_retrievals_nomem;
60090 -extern atomic_t fscache_n_retrievals_object_dead;
60091 -extern atomic_t fscache_n_retrieval_ops;
60092 -extern atomic_t fscache_n_retrieval_op_waits;
60093 +extern atomic_unchecked_t fscache_n_retrievals;
60094 +extern atomic_unchecked_t fscache_n_retrievals_ok;
60095 +extern atomic_unchecked_t fscache_n_retrievals_wait;
60096 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
60097 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
60098 +extern atomic_unchecked_t fscache_n_retrievals_intr;
60099 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
60100 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
60101 +extern atomic_unchecked_t fscache_n_retrieval_ops;
60102 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
60103
60104 -extern atomic_t fscache_n_stores;
60105 -extern atomic_t fscache_n_stores_ok;
60106 -extern atomic_t fscache_n_stores_again;
60107 -extern atomic_t fscache_n_stores_nobufs;
60108 -extern atomic_t fscache_n_stores_oom;
60109 -extern atomic_t fscache_n_store_ops;
60110 -extern atomic_t fscache_n_store_calls;
60111 -extern atomic_t fscache_n_store_pages;
60112 -extern atomic_t fscache_n_store_radix_deletes;
60113 -extern atomic_t fscache_n_store_pages_over_limit;
60114 +extern atomic_unchecked_t fscache_n_stores;
60115 +extern atomic_unchecked_t fscache_n_stores_ok;
60116 +extern atomic_unchecked_t fscache_n_stores_again;
60117 +extern atomic_unchecked_t fscache_n_stores_nobufs;
60118 +extern atomic_unchecked_t fscache_n_stores_oom;
60119 +extern atomic_unchecked_t fscache_n_store_ops;
60120 +extern atomic_unchecked_t fscache_n_store_calls;
60121 +extern atomic_unchecked_t fscache_n_store_pages;
60122 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
60123 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
60124
60125 -extern atomic_t fscache_n_store_vmscan_not_storing;
60126 -extern atomic_t fscache_n_store_vmscan_gone;
60127 -extern atomic_t fscache_n_store_vmscan_busy;
60128 -extern atomic_t fscache_n_store_vmscan_cancelled;
60129 -extern atomic_t fscache_n_store_vmscan_wait;
60130 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
60131 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
60132 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
60133 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
60134 +extern atomic_unchecked_t fscache_n_store_vmscan_wait;
60135
60136 -extern atomic_t fscache_n_marks;
60137 -extern atomic_t fscache_n_uncaches;
60138 +extern atomic_unchecked_t fscache_n_marks;
60139 +extern atomic_unchecked_t fscache_n_uncaches;
60140
60141 -extern atomic_t fscache_n_acquires;
60142 -extern atomic_t fscache_n_acquires_null;
60143 -extern atomic_t fscache_n_acquires_no_cache;
60144 -extern atomic_t fscache_n_acquires_ok;
60145 -extern atomic_t fscache_n_acquires_nobufs;
60146 -extern atomic_t fscache_n_acquires_oom;
60147 +extern atomic_unchecked_t fscache_n_acquires;
60148 +extern atomic_unchecked_t fscache_n_acquires_null;
60149 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
60150 +extern atomic_unchecked_t fscache_n_acquires_ok;
60151 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
60152 +extern atomic_unchecked_t fscache_n_acquires_oom;
60153
60154 -extern atomic_t fscache_n_invalidates;
60155 -extern atomic_t fscache_n_invalidates_run;
60156 +extern atomic_unchecked_t fscache_n_invalidates;
60157 +extern atomic_unchecked_t fscache_n_invalidates_run;
60158
60159 -extern atomic_t fscache_n_updates;
60160 -extern atomic_t fscache_n_updates_null;
60161 -extern atomic_t fscache_n_updates_run;
60162 +extern atomic_unchecked_t fscache_n_updates;
60163 +extern atomic_unchecked_t fscache_n_updates_null;
60164 +extern atomic_unchecked_t fscache_n_updates_run;
60165
60166 -extern atomic_t fscache_n_relinquishes;
60167 -extern atomic_t fscache_n_relinquishes_null;
60168 -extern atomic_t fscache_n_relinquishes_waitcrt;
60169 -extern atomic_t fscache_n_relinquishes_retire;
60170 +extern atomic_unchecked_t fscache_n_relinquishes;
60171 +extern atomic_unchecked_t fscache_n_relinquishes_null;
60172 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
60173 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
60174
60175 -extern atomic_t fscache_n_cookie_index;
60176 -extern atomic_t fscache_n_cookie_data;
60177 -extern atomic_t fscache_n_cookie_special;
60178 +extern atomic_unchecked_t fscache_n_cookie_index;
60179 +extern atomic_unchecked_t fscache_n_cookie_data;
60180 +extern atomic_unchecked_t fscache_n_cookie_special;
60181
60182 -extern atomic_t fscache_n_object_alloc;
60183 -extern atomic_t fscache_n_object_no_alloc;
60184 -extern atomic_t fscache_n_object_lookups;
60185 -extern atomic_t fscache_n_object_lookups_negative;
60186 -extern atomic_t fscache_n_object_lookups_positive;
60187 -extern atomic_t fscache_n_object_lookups_timed_out;
60188 -extern atomic_t fscache_n_object_created;
60189 -extern atomic_t fscache_n_object_avail;
60190 -extern atomic_t fscache_n_object_dead;
60191 +extern atomic_unchecked_t fscache_n_object_alloc;
60192 +extern atomic_unchecked_t fscache_n_object_no_alloc;
60193 +extern atomic_unchecked_t fscache_n_object_lookups;
60194 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
60195 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
60196 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
60197 +extern atomic_unchecked_t fscache_n_object_created;
60198 +extern atomic_unchecked_t fscache_n_object_avail;
60199 +extern atomic_unchecked_t fscache_n_object_dead;
60200
60201 -extern atomic_t fscache_n_checkaux_none;
60202 -extern atomic_t fscache_n_checkaux_okay;
60203 -extern atomic_t fscache_n_checkaux_update;
60204 -extern atomic_t fscache_n_checkaux_obsolete;
60205 +extern atomic_unchecked_t fscache_n_checkaux_none;
60206 +extern atomic_unchecked_t fscache_n_checkaux_okay;
60207 +extern atomic_unchecked_t fscache_n_checkaux_update;
60208 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
60209
60210 extern atomic_t fscache_n_cop_alloc_object;
60211 extern atomic_t fscache_n_cop_lookup_object;
60212 @@ -272,6 +272,11 @@ static inline void fscache_stat(atomic_t *stat)
60213 atomic_inc(stat);
60214 }
60215
60216 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
60217 +{
60218 + atomic_inc_unchecked(stat);
60219 +}
60220 +
60221 static inline void fscache_stat_d(atomic_t *stat)
60222 {
60223 atomic_dec(stat);
60224 @@ -284,6 +289,7 @@ extern const struct file_operations fscache_stats_fops;
60225
60226 #define __fscache_stat(stat) (NULL)
60227 #define fscache_stat(stat) do {} while (0)
60228 +#define fscache_stat_unchecked(stat) do {} while (0)
60229 #define fscache_stat_d(stat) do {} while (0)
60230 #endif
60231
60232 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
60233 index d3b4539..ed0c659 100644
60234 --- a/fs/fscache/object.c
60235 +++ b/fs/fscache/object.c
60236 @@ -454,7 +454,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
60237 _debug("LOOKUP \"%s\" in \"%s\"",
60238 cookie->def->name, object->cache->tag->name);
60239
60240 - fscache_stat(&fscache_n_object_lookups);
60241 + fscache_stat_unchecked(&fscache_n_object_lookups);
60242 fscache_stat(&fscache_n_cop_lookup_object);
60243 ret = object->cache->ops->lookup_object(object);
60244 fscache_stat_d(&fscache_n_cop_lookup_object);
60245 @@ -464,7 +464,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
60246 if (ret == -ETIMEDOUT) {
60247 /* probably stuck behind another object, so move this one to
60248 * the back of the queue */
60249 - fscache_stat(&fscache_n_object_lookups_timed_out);
60250 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
60251 _leave(" [timeout]");
60252 return NO_TRANSIT;
60253 }
60254 @@ -492,7 +492,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
60255 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
60256
60257 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
60258 - fscache_stat(&fscache_n_object_lookups_negative);
60259 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
60260
60261 /* Allow write requests to begin stacking up and read requests to begin
60262 * returning ENODATA.
60263 @@ -527,7 +527,7 @@ void fscache_obtained_object(struct fscache_object *object)
60264 /* if we were still looking up, then we must have a positive lookup
60265 * result, in which case there may be data available */
60266 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
60267 - fscache_stat(&fscache_n_object_lookups_positive);
60268 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
60269
60270 /* We do (presumably) have data */
60271 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
60272 @@ -539,7 +539,7 @@ void fscache_obtained_object(struct fscache_object *object)
60273 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
60274 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
60275 } else {
60276 - fscache_stat(&fscache_n_object_created);
60277 + fscache_stat_unchecked(&fscache_n_object_created);
60278 }
60279
60280 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
60281 @@ -575,7 +575,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
60282 fscache_stat_d(&fscache_n_cop_lookup_complete);
60283
60284 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
60285 - fscache_stat(&fscache_n_object_avail);
60286 + fscache_stat_unchecked(&fscache_n_object_avail);
60287
60288 _leave("");
60289 return transit_to(JUMPSTART_DEPS);
60290 @@ -722,7 +722,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
60291
60292 /* this just shifts the object release to the work processor */
60293 fscache_put_object(object);
60294 - fscache_stat(&fscache_n_object_dead);
60295 + fscache_stat_unchecked(&fscache_n_object_dead);
60296
60297 _leave("");
60298 return transit_to(OBJECT_DEAD);
60299 @@ -887,7 +887,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
60300 enum fscache_checkaux result;
60301
60302 if (!object->cookie->def->check_aux) {
60303 - fscache_stat(&fscache_n_checkaux_none);
60304 + fscache_stat_unchecked(&fscache_n_checkaux_none);
60305 return FSCACHE_CHECKAUX_OKAY;
60306 }
60307
60308 @@ -896,17 +896,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
60309 switch (result) {
60310 /* entry okay as is */
60311 case FSCACHE_CHECKAUX_OKAY:
60312 - fscache_stat(&fscache_n_checkaux_okay);
60313 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
60314 break;
60315
60316 /* entry requires update */
60317 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
60318 - fscache_stat(&fscache_n_checkaux_update);
60319 + fscache_stat_unchecked(&fscache_n_checkaux_update);
60320 break;
60321
60322 /* entry requires deletion */
60323 case FSCACHE_CHECKAUX_OBSOLETE:
60324 - fscache_stat(&fscache_n_checkaux_obsolete);
60325 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
60326 break;
60327
60328 default:
60329 @@ -992,7 +992,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
60330 {
60331 const struct fscache_state *s;
60332
60333 - fscache_stat(&fscache_n_invalidates_run);
60334 + fscache_stat_unchecked(&fscache_n_invalidates_run);
60335 fscache_stat(&fscache_n_cop_invalidate_object);
60336 s = _fscache_invalidate_object(object, event);
60337 fscache_stat_d(&fscache_n_cop_invalidate_object);
60338 @@ -1007,7 +1007,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
60339 {
60340 _enter("{OBJ%x},%d", object->debug_id, event);
60341
60342 - fscache_stat(&fscache_n_updates_run);
60343 + fscache_stat_unchecked(&fscache_n_updates_run);
60344 fscache_stat(&fscache_n_cop_update_object);
60345 object->cache->ops->update_object(object);
60346 fscache_stat_d(&fscache_n_cop_update_object);
60347 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
60348 index 318071a..379938b 100644
60349 --- a/fs/fscache/operation.c
60350 +++ b/fs/fscache/operation.c
60351 @@ -17,7 +17,7 @@
60352 #include <linux/slab.h>
60353 #include "internal.h"
60354
60355 -atomic_t fscache_op_debug_id;
60356 +atomic_unchecked_t fscache_op_debug_id;
60357 EXPORT_SYMBOL(fscache_op_debug_id);
60358
60359 /**
60360 @@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
60361 ASSERTCMP(atomic_read(&op->usage), >, 0);
60362 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
60363
60364 - fscache_stat(&fscache_n_op_enqueue);
60365 + fscache_stat_unchecked(&fscache_n_op_enqueue);
60366 switch (op->flags & FSCACHE_OP_TYPE) {
60367 case FSCACHE_OP_ASYNC:
60368 _debug("queue async");
60369 @@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
60370 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
60371 if (op->processor)
60372 fscache_enqueue_operation(op);
60373 - fscache_stat(&fscache_n_op_run);
60374 + fscache_stat_unchecked(&fscache_n_op_run);
60375 }
60376
60377 /*
60378 @@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
60379 if (object->n_in_progress > 0) {
60380 atomic_inc(&op->usage);
60381 list_add_tail(&op->pend_link, &object->pending_ops);
60382 - fscache_stat(&fscache_n_op_pend);
60383 + fscache_stat_unchecked(&fscache_n_op_pend);
60384 } else if (!list_empty(&object->pending_ops)) {
60385 atomic_inc(&op->usage);
60386 list_add_tail(&op->pend_link, &object->pending_ops);
60387 - fscache_stat(&fscache_n_op_pend);
60388 + fscache_stat_unchecked(&fscache_n_op_pend);
60389 fscache_start_operations(object);
60390 } else {
60391 ASSERTCMP(object->n_in_progress, ==, 0);
60392 @@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
60393 object->n_exclusive++; /* reads and writes must wait */
60394 atomic_inc(&op->usage);
60395 list_add_tail(&op->pend_link, &object->pending_ops);
60396 - fscache_stat(&fscache_n_op_pend);
60397 + fscache_stat_unchecked(&fscache_n_op_pend);
60398 ret = 0;
60399 } else {
60400 /* If we're in any other state, there must have been an I/O
60401 @@ -212,11 +212,11 @@ int fscache_submit_op(struct fscache_object *object,
60402 if (object->n_exclusive > 0) {
60403 atomic_inc(&op->usage);
60404 list_add_tail(&op->pend_link, &object->pending_ops);
60405 - fscache_stat(&fscache_n_op_pend);
60406 + fscache_stat_unchecked(&fscache_n_op_pend);
60407 } else if (!list_empty(&object->pending_ops)) {
60408 atomic_inc(&op->usage);
60409 list_add_tail(&op->pend_link, &object->pending_ops);
60410 - fscache_stat(&fscache_n_op_pend);
60411 + fscache_stat_unchecked(&fscache_n_op_pend);
60412 fscache_start_operations(object);
60413 } else {
60414 ASSERTCMP(object->n_exclusive, ==, 0);
60415 @@ -228,10 +228,10 @@ int fscache_submit_op(struct fscache_object *object,
60416 object->n_ops++;
60417 atomic_inc(&op->usage);
60418 list_add_tail(&op->pend_link, &object->pending_ops);
60419 - fscache_stat(&fscache_n_op_pend);
60420 + fscache_stat_unchecked(&fscache_n_op_pend);
60421 ret = 0;
60422 } else if (fscache_object_is_dying(object)) {
60423 - fscache_stat(&fscache_n_op_rejected);
60424 + fscache_stat_unchecked(&fscache_n_op_rejected);
60425 op->state = FSCACHE_OP_ST_CANCELLED;
60426 ret = -ENOBUFS;
60427 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
60428 @@ -310,7 +310,7 @@ int fscache_cancel_op(struct fscache_operation *op,
60429 ret = -EBUSY;
60430 if (op->state == FSCACHE_OP_ST_PENDING) {
60431 ASSERT(!list_empty(&op->pend_link));
60432 - fscache_stat(&fscache_n_op_cancelled);
60433 + fscache_stat_unchecked(&fscache_n_op_cancelled);
60434 list_del_init(&op->pend_link);
60435 if (do_cancel)
60436 do_cancel(op);
60437 @@ -342,7 +342,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
60438 while (!list_empty(&object->pending_ops)) {
60439 op = list_entry(object->pending_ops.next,
60440 struct fscache_operation, pend_link);
60441 - fscache_stat(&fscache_n_op_cancelled);
60442 + fscache_stat_unchecked(&fscache_n_op_cancelled);
60443 list_del_init(&op->pend_link);
60444
60445 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
60446 @@ -414,7 +414,7 @@ void fscache_put_operation(struct fscache_operation *op)
60447 op->state, ==, FSCACHE_OP_ST_CANCELLED);
60448 op->state = FSCACHE_OP_ST_DEAD;
60449
60450 - fscache_stat(&fscache_n_op_release);
60451 + fscache_stat_unchecked(&fscache_n_op_release);
60452
60453 if (op->release) {
60454 op->release(op);
60455 @@ -433,7 +433,7 @@ void fscache_put_operation(struct fscache_operation *op)
60456 * lock, and defer it otherwise */
60457 if (!spin_trylock(&object->lock)) {
60458 _debug("defer put");
60459 - fscache_stat(&fscache_n_op_deferred_release);
60460 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
60461
60462 cache = object->cache;
60463 spin_lock(&cache->op_gc_list_lock);
60464 @@ -486,7 +486,7 @@ void fscache_operation_gc(struct work_struct *work)
60465
60466 _debug("GC DEFERRED REL OBJ%x OP%x",
60467 object->debug_id, op->debug_id);
60468 - fscache_stat(&fscache_n_op_gc);
60469 + fscache_stat_unchecked(&fscache_n_op_gc);
60470
60471 ASSERTCMP(atomic_read(&op->usage), ==, 0);
60472 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
60473 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
60474 index 7f5c658..6c1e164 100644
60475 --- a/fs/fscache/page.c
60476 +++ b/fs/fscache/page.c
60477 @@ -61,7 +61,7 @@ try_again:
60478 val = radix_tree_lookup(&cookie->stores, page->index);
60479 if (!val) {
60480 rcu_read_unlock();
60481 - fscache_stat(&fscache_n_store_vmscan_not_storing);
60482 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
60483 __fscache_uncache_page(cookie, page);
60484 return true;
60485 }
60486 @@ -91,11 +91,11 @@ try_again:
60487 spin_unlock(&cookie->stores_lock);
60488
60489 if (xpage) {
60490 - fscache_stat(&fscache_n_store_vmscan_cancelled);
60491 - fscache_stat(&fscache_n_store_radix_deletes);
60492 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
60493 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
60494 ASSERTCMP(xpage, ==, page);
60495 } else {
60496 - fscache_stat(&fscache_n_store_vmscan_gone);
60497 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
60498 }
60499
60500 wake_up_bit(&cookie->flags, 0);
60501 @@ -110,11 +110,11 @@ page_busy:
60502 * sleeping on memory allocation, so we may need to impose a timeout
60503 * too. */
60504 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
60505 - fscache_stat(&fscache_n_store_vmscan_busy);
60506 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
60507 return false;
60508 }
60509
60510 - fscache_stat(&fscache_n_store_vmscan_wait);
60511 + fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
60512 __fscache_wait_on_page_write(cookie, page);
60513 gfp &= ~__GFP_WAIT;
60514 goto try_again;
60515 @@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
60516 FSCACHE_COOKIE_STORING_TAG);
60517 if (!radix_tree_tag_get(&cookie->stores, page->index,
60518 FSCACHE_COOKIE_PENDING_TAG)) {
60519 - fscache_stat(&fscache_n_store_radix_deletes);
60520 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
60521 xpage = radix_tree_delete(&cookie->stores, page->index);
60522 }
60523 spin_unlock(&cookie->stores_lock);
60524 @@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
60525
60526 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
60527
60528 - fscache_stat(&fscache_n_attr_changed_calls);
60529 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
60530
60531 if (fscache_object_is_active(object)) {
60532 fscache_stat(&fscache_n_cop_attr_changed);
60533 @@ -188,11 +188,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
60534
60535 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60536
60537 - fscache_stat(&fscache_n_attr_changed);
60538 + fscache_stat_unchecked(&fscache_n_attr_changed);
60539
60540 op = kzalloc(sizeof(*op), GFP_KERNEL);
60541 if (!op) {
60542 - fscache_stat(&fscache_n_attr_changed_nomem);
60543 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
60544 _leave(" = -ENOMEM");
60545 return -ENOMEM;
60546 }
60547 @@ -214,7 +214,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
60548 if (fscache_submit_exclusive_op(object, op) < 0)
60549 goto nobufs;
60550 spin_unlock(&cookie->lock);
60551 - fscache_stat(&fscache_n_attr_changed_ok);
60552 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
60553 fscache_put_operation(op);
60554 _leave(" = 0");
60555 return 0;
60556 @@ -225,7 +225,7 @@ nobufs:
60557 kfree(op);
60558 if (wake_cookie)
60559 __fscache_wake_unused_cookie(cookie);
60560 - fscache_stat(&fscache_n_attr_changed_nobufs);
60561 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
60562 _leave(" = %d", -ENOBUFS);
60563 return -ENOBUFS;
60564 }
60565 @@ -264,7 +264,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
60566 /* allocate a retrieval operation and attempt to submit it */
60567 op = kzalloc(sizeof(*op), GFP_NOIO);
60568 if (!op) {
60569 - fscache_stat(&fscache_n_retrievals_nomem);
60570 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60571 return NULL;
60572 }
60573
60574 @@ -294,13 +294,13 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
60575 return 0;
60576 }
60577
60578 - fscache_stat(&fscache_n_retrievals_wait);
60579 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
60580
60581 jif = jiffies;
60582 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
60583 fscache_wait_bit_interruptible,
60584 TASK_INTERRUPTIBLE) != 0) {
60585 - fscache_stat(&fscache_n_retrievals_intr);
60586 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
60587 _leave(" = -ERESTARTSYS");
60588 return -ERESTARTSYS;
60589 }
60590 @@ -329,8 +329,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
60591 */
60592 int fscache_wait_for_operation_activation(struct fscache_object *object,
60593 struct fscache_operation *op,
60594 - atomic_t *stat_op_waits,
60595 - atomic_t *stat_object_dead,
60596 + atomic_unchecked_t *stat_op_waits,
60597 + atomic_unchecked_t *stat_object_dead,
60598 void (*do_cancel)(struct fscache_operation *))
60599 {
60600 int ret;
60601 @@ -340,7 +340,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
60602
60603 _debug(">>> WT");
60604 if (stat_op_waits)
60605 - fscache_stat(stat_op_waits);
60606 + fscache_stat_unchecked(stat_op_waits);
60607 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
60608 fscache_wait_bit_interruptible,
60609 TASK_INTERRUPTIBLE) != 0) {
60610 @@ -358,7 +358,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
60611 check_if_dead:
60612 if (op->state == FSCACHE_OP_ST_CANCELLED) {
60613 if (stat_object_dead)
60614 - fscache_stat(stat_object_dead);
60615 + fscache_stat_unchecked(stat_object_dead);
60616 _leave(" = -ENOBUFS [cancelled]");
60617 return -ENOBUFS;
60618 }
60619 @@ -366,7 +366,7 @@ check_if_dead:
60620 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state);
60621 fscache_cancel_op(op, do_cancel);
60622 if (stat_object_dead)
60623 - fscache_stat(stat_object_dead);
60624 + fscache_stat_unchecked(stat_object_dead);
60625 return -ENOBUFS;
60626 }
60627 return 0;
60628 @@ -394,7 +394,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60629
60630 _enter("%p,%p,,,", cookie, page);
60631
60632 - fscache_stat(&fscache_n_retrievals);
60633 + fscache_stat_unchecked(&fscache_n_retrievals);
60634
60635 if (hlist_empty(&cookie->backing_objects))
60636 goto nobufs;
60637 @@ -436,7 +436,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60638 goto nobufs_unlock_dec;
60639 spin_unlock(&cookie->lock);
60640
60641 - fscache_stat(&fscache_n_retrieval_ops);
60642 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
60643
60644 /* pin the netfs read context in case we need to do the actual netfs
60645 * read because we've encountered a cache read failure */
60646 @@ -467,15 +467,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
60647
60648 error:
60649 if (ret == -ENOMEM)
60650 - fscache_stat(&fscache_n_retrievals_nomem);
60651 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60652 else if (ret == -ERESTARTSYS)
60653 - fscache_stat(&fscache_n_retrievals_intr);
60654 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
60655 else if (ret == -ENODATA)
60656 - fscache_stat(&fscache_n_retrievals_nodata);
60657 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
60658 else if (ret < 0)
60659 - fscache_stat(&fscache_n_retrievals_nobufs);
60660 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60661 else
60662 - fscache_stat(&fscache_n_retrievals_ok);
60663 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
60664
60665 fscache_put_retrieval(op);
60666 _leave(" = %d", ret);
60667 @@ -490,7 +490,7 @@ nobufs_unlock:
60668 __fscache_wake_unused_cookie(cookie);
60669 kfree(op);
60670 nobufs:
60671 - fscache_stat(&fscache_n_retrievals_nobufs);
60672 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60673 _leave(" = -ENOBUFS");
60674 return -ENOBUFS;
60675 }
60676 @@ -529,7 +529,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60677
60678 _enter("%p,,%d,,,", cookie, *nr_pages);
60679
60680 - fscache_stat(&fscache_n_retrievals);
60681 + fscache_stat_unchecked(&fscache_n_retrievals);
60682
60683 if (hlist_empty(&cookie->backing_objects))
60684 goto nobufs;
60685 @@ -567,7 +567,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60686 goto nobufs_unlock_dec;
60687 spin_unlock(&cookie->lock);
60688
60689 - fscache_stat(&fscache_n_retrieval_ops);
60690 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
60691
60692 /* pin the netfs read context in case we need to do the actual netfs
60693 * read because we've encountered a cache read failure */
60694 @@ -598,15 +598,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
60695
60696 error:
60697 if (ret == -ENOMEM)
60698 - fscache_stat(&fscache_n_retrievals_nomem);
60699 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
60700 else if (ret == -ERESTARTSYS)
60701 - fscache_stat(&fscache_n_retrievals_intr);
60702 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
60703 else if (ret == -ENODATA)
60704 - fscache_stat(&fscache_n_retrievals_nodata);
60705 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
60706 else if (ret < 0)
60707 - fscache_stat(&fscache_n_retrievals_nobufs);
60708 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60709 else
60710 - fscache_stat(&fscache_n_retrievals_ok);
60711 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
60712
60713 fscache_put_retrieval(op);
60714 _leave(" = %d", ret);
60715 @@ -621,7 +621,7 @@ nobufs_unlock:
60716 if (wake_cookie)
60717 __fscache_wake_unused_cookie(cookie);
60718 nobufs:
60719 - fscache_stat(&fscache_n_retrievals_nobufs);
60720 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
60721 _leave(" = -ENOBUFS");
60722 return -ENOBUFS;
60723 }
60724 @@ -646,7 +646,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60725
60726 _enter("%p,%p,,,", cookie, page);
60727
60728 - fscache_stat(&fscache_n_allocs);
60729 + fscache_stat_unchecked(&fscache_n_allocs);
60730
60731 if (hlist_empty(&cookie->backing_objects))
60732 goto nobufs;
60733 @@ -680,7 +680,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60734 goto nobufs_unlock_dec;
60735 spin_unlock(&cookie->lock);
60736
60737 - fscache_stat(&fscache_n_alloc_ops);
60738 + fscache_stat_unchecked(&fscache_n_alloc_ops);
60739
60740 ret = fscache_wait_for_operation_activation(
60741 object, &op->op,
60742 @@ -697,11 +697,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
60743
60744 error:
60745 if (ret == -ERESTARTSYS)
60746 - fscache_stat(&fscache_n_allocs_intr);
60747 + fscache_stat_unchecked(&fscache_n_allocs_intr);
60748 else if (ret < 0)
60749 - fscache_stat(&fscache_n_allocs_nobufs);
60750 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
60751 else
60752 - fscache_stat(&fscache_n_allocs_ok);
60753 + fscache_stat_unchecked(&fscache_n_allocs_ok);
60754
60755 fscache_put_retrieval(op);
60756 _leave(" = %d", ret);
60757 @@ -715,7 +715,7 @@ nobufs_unlock:
60758 if (wake_cookie)
60759 __fscache_wake_unused_cookie(cookie);
60760 nobufs:
60761 - fscache_stat(&fscache_n_allocs_nobufs);
60762 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
60763 _leave(" = -ENOBUFS");
60764 return -ENOBUFS;
60765 }
60766 @@ -791,7 +791,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60767
60768 spin_lock(&cookie->stores_lock);
60769
60770 - fscache_stat(&fscache_n_store_calls);
60771 + fscache_stat_unchecked(&fscache_n_store_calls);
60772
60773 /* find a page to store */
60774 page = NULL;
60775 @@ -802,7 +802,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60776 page = results[0];
60777 _debug("gang %d [%lx]", n, page->index);
60778 if (page->index > op->store_limit) {
60779 - fscache_stat(&fscache_n_store_pages_over_limit);
60780 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
60781 goto superseded;
60782 }
60783
60784 @@ -814,7 +814,7 @@ static void fscache_write_op(struct fscache_operation *_op)
60785 spin_unlock(&cookie->stores_lock);
60786 spin_unlock(&object->lock);
60787
60788 - fscache_stat(&fscache_n_store_pages);
60789 + fscache_stat_unchecked(&fscache_n_store_pages);
60790 fscache_stat(&fscache_n_cop_write_page);
60791 ret = object->cache->ops->write_page(op, page);
60792 fscache_stat_d(&fscache_n_cop_write_page);
60793 @@ -918,7 +918,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60794 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60795 ASSERT(PageFsCache(page));
60796
60797 - fscache_stat(&fscache_n_stores);
60798 + fscache_stat_unchecked(&fscache_n_stores);
60799
60800 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
60801 _leave(" = -ENOBUFS [invalidating]");
60802 @@ -977,7 +977,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60803 spin_unlock(&cookie->stores_lock);
60804 spin_unlock(&object->lock);
60805
60806 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
60807 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
60808 op->store_limit = object->store_limit;
60809
60810 __fscache_use_cookie(cookie);
60811 @@ -986,8 +986,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60812
60813 spin_unlock(&cookie->lock);
60814 radix_tree_preload_end();
60815 - fscache_stat(&fscache_n_store_ops);
60816 - fscache_stat(&fscache_n_stores_ok);
60817 + fscache_stat_unchecked(&fscache_n_store_ops);
60818 + fscache_stat_unchecked(&fscache_n_stores_ok);
60819
60820 /* the work queue now carries its own ref on the object */
60821 fscache_put_operation(&op->op);
60822 @@ -995,14 +995,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
60823 return 0;
60824
60825 already_queued:
60826 - fscache_stat(&fscache_n_stores_again);
60827 + fscache_stat_unchecked(&fscache_n_stores_again);
60828 already_pending:
60829 spin_unlock(&cookie->stores_lock);
60830 spin_unlock(&object->lock);
60831 spin_unlock(&cookie->lock);
60832 radix_tree_preload_end();
60833 kfree(op);
60834 - fscache_stat(&fscache_n_stores_ok);
60835 + fscache_stat_unchecked(&fscache_n_stores_ok);
60836 _leave(" = 0");
60837 return 0;
60838
60839 @@ -1024,14 +1024,14 @@ nobufs:
60840 kfree(op);
60841 if (wake_cookie)
60842 __fscache_wake_unused_cookie(cookie);
60843 - fscache_stat(&fscache_n_stores_nobufs);
60844 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
60845 _leave(" = -ENOBUFS");
60846 return -ENOBUFS;
60847
60848 nomem_free:
60849 kfree(op);
60850 nomem:
60851 - fscache_stat(&fscache_n_stores_oom);
60852 + fscache_stat_unchecked(&fscache_n_stores_oom);
60853 _leave(" = -ENOMEM");
60854 return -ENOMEM;
60855 }
60856 @@ -1049,7 +1049,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
60857 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
60858 ASSERTCMP(page, !=, NULL);
60859
60860 - fscache_stat(&fscache_n_uncaches);
60861 + fscache_stat_unchecked(&fscache_n_uncaches);
60862
60863 /* cache withdrawal may beat us to it */
60864 if (!PageFsCache(page))
60865 @@ -1100,7 +1100,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
60866 struct fscache_cookie *cookie = op->op.object->cookie;
60867
60868 #ifdef CONFIG_FSCACHE_STATS
60869 - atomic_inc(&fscache_n_marks);
60870 + atomic_inc_unchecked(&fscache_n_marks);
60871 #endif
60872
60873 _debug("- mark %p{%lx}", page, page->index);
60874 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
60875 index 40d13c7..ddf52b9 100644
60876 --- a/fs/fscache/stats.c
60877 +++ b/fs/fscache/stats.c
60878 @@ -18,99 +18,99 @@
60879 /*
60880 * operation counters
60881 */
60882 -atomic_t fscache_n_op_pend;
60883 -atomic_t fscache_n_op_run;
60884 -atomic_t fscache_n_op_enqueue;
60885 -atomic_t fscache_n_op_requeue;
60886 -atomic_t fscache_n_op_deferred_release;
60887 -atomic_t fscache_n_op_release;
60888 -atomic_t fscache_n_op_gc;
60889 -atomic_t fscache_n_op_cancelled;
60890 -atomic_t fscache_n_op_rejected;
60891 +atomic_unchecked_t fscache_n_op_pend;
60892 +atomic_unchecked_t fscache_n_op_run;
60893 +atomic_unchecked_t fscache_n_op_enqueue;
60894 +atomic_unchecked_t fscache_n_op_requeue;
60895 +atomic_unchecked_t fscache_n_op_deferred_release;
60896 +atomic_unchecked_t fscache_n_op_release;
60897 +atomic_unchecked_t fscache_n_op_gc;
60898 +atomic_unchecked_t fscache_n_op_cancelled;
60899 +atomic_unchecked_t fscache_n_op_rejected;
60900
60901 -atomic_t fscache_n_attr_changed;
60902 -atomic_t fscache_n_attr_changed_ok;
60903 -atomic_t fscache_n_attr_changed_nobufs;
60904 -atomic_t fscache_n_attr_changed_nomem;
60905 -atomic_t fscache_n_attr_changed_calls;
60906 +atomic_unchecked_t fscache_n_attr_changed;
60907 +atomic_unchecked_t fscache_n_attr_changed_ok;
60908 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
60909 +atomic_unchecked_t fscache_n_attr_changed_nomem;
60910 +atomic_unchecked_t fscache_n_attr_changed_calls;
60911
60912 -atomic_t fscache_n_allocs;
60913 -atomic_t fscache_n_allocs_ok;
60914 -atomic_t fscache_n_allocs_wait;
60915 -atomic_t fscache_n_allocs_nobufs;
60916 -atomic_t fscache_n_allocs_intr;
60917 -atomic_t fscache_n_allocs_object_dead;
60918 -atomic_t fscache_n_alloc_ops;
60919 -atomic_t fscache_n_alloc_op_waits;
60920 +atomic_unchecked_t fscache_n_allocs;
60921 +atomic_unchecked_t fscache_n_allocs_ok;
60922 +atomic_unchecked_t fscache_n_allocs_wait;
60923 +atomic_unchecked_t fscache_n_allocs_nobufs;
60924 +atomic_unchecked_t fscache_n_allocs_intr;
60925 +atomic_unchecked_t fscache_n_allocs_object_dead;
60926 +atomic_unchecked_t fscache_n_alloc_ops;
60927 +atomic_unchecked_t fscache_n_alloc_op_waits;
60928
60929 -atomic_t fscache_n_retrievals;
60930 -atomic_t fscache_n_retrievals_ok;
60931 -atomic_t fscache_n_retrievals_wait;
60932 -atomic_t fscache_n_retrievals_nodata;
60933 -atomic_t fscache_n_retrievals_nobufs;
60934 -atomic_t fscache_n_retrievals_intr;
60935 -atomic_t fscache_n_retrievals_nomem;
60936 -atomic_t fscache_n_retrievals_object_dead;
60937 -atomic_t fscache_n_retrieval_ops;
60938 -atomic_t fscache_n_retrieval_op_waits;
60939 +atomic_unchecked_t fscache_n_retrievals;
60940 +atomic_unchecked_t fscache_n_retrievals_ok;
60941 +atomic_unchecked_t fscache_n_retrievals_wait;
60942 +atomic_unchecked_t fscache_n_retrievals_nodata;
60943 +atomic_unchecked_t fscache_n_retrievals_nobufs;
60944 +atomic_unchecked_t fscache_n_retrievals_intr;
60945 +atomic_unchecked_t fscache_n_retrievals_nomem;
60946 +atomic_unchecked_t fscache_n_retrievals_object_dead;
60947 +atomic_unchecked_t fscache_n_retrieval_ops;
60948 +atomic_unchecked_t fscache_n_retrieval_op_waits;
60949
60950 -atomic_t fscache_n_stores;
60951 -atomic_t fscache_n_stores_ok;
60952 -atomic_t fscache_n_stores_again;
60953 -atomic_t fscache_n_stores_nobufs;
60954 -atomic_t fscache_n_stores_oom;
60955 -atomic_t fscache_n_store_ops;
60956 -atomic_t fscache_n_store_calls;
60957 -atomic_t fscache_n_store_pages;
60958 -atomic_t fscache_n_store_radix_deletes;
60959 -atomic_t fscache_n_store_pages_over_limit;
60960 +atomic_unchecked_t fscache_n_stores;
60961 +atomic_unchecked_t fscache_n_stores_ok;
60962 +atomic_unchecked_t fscache_n_stores_again;
60963 +atomic_unchecked_t fscache_n_stores_nobufs;
60964 +atomic_unchecked_t fscache_n_stores_oom;
60965 +atomic_unchecked_t fscache_n_store_ops;
60966 +atomic_unchecked_t fscache_n_store_calls;
60967 +atomic_unchecked_t fscache_n_store_pages;
60968 +atomic_unchecked_t fscache_n_store_radix_deletes;
60969 +atomic_unchecked_t fscache_n_store_pages_over_limit;
60970
60971 -atomic_t fscache_n_store_vmscan_not_storing;
60972 -atomic_t fscache_n_store_vmscan_gone;
60973 -atomic_t fscache_n_store_vmscan_busy;
60974 -atomic_t fscache_n_store_vmscan_cancelled;
60975 -atomic_t fscache_n_store_vmscan_wait;
60976 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
60977 +atomic_unchecked_t fscache_n_store_vmscan_gone;
60978 +atomic_unchecked_t fscache_n_store_vmscan_busy;
60979 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
60980 +atomic_unchecked_t fscache_n_store_vmscan_wait;
60981
60982 -atomic_t fscache_n_marks;
60983 -atomic_t fscache_n_uncaches;
60984 +atomic_unchecked_t fscache_n_marks;
60985 +atomic_unchecked_t fscache_n_uncaches;
60986
60987 -atomic_t fscache_n_acquires;
60988 -atomic_t fscache_n_acquires_null;
60989 -atomic_t fscache_n_acquires_no_cache;
60990 -atomic_t fscache_n_acquires_ok;
60991 -atomic_t fscache_n_acquires_nobufs;
60992 -atomic_t fscache_n_acquires_oom;
60993 +atomic_unchecked_t fscache_n_acquires;
60994 +atomic_unchecked_t fscache_n_acquires_null;
60995 +atomic_unchecked_t fscache_n_acquires_no_cache;
60996 +atomic_unchecked_t fscache_n_acquires_ok;
60997 +atomic_unchecked_t fscache_n_acquires_nobufs;
60998 +atomic_unchecked_t fscache_n_acquires_oom;
60999
61000 -atomic_t fscache_n_invalidates;
61001 -atomic_t fscache_n_invalidates_run;
61002 +atomic_unchecked_t fscache_n_invalidates;
61003 +atomic_unchecked_t fscache_n_invalidates_run;
61004
61005 -atomic_t fscache_n_updates;
61006 -atomic_t fscache_n_updates_null;
61007 -atomic_t fscache_n_updates_run;
61008 +atomic_unchecked_t fscache_n_updates;
61009 +atomic_unchecked_t fscache_n_updates_null;
61010 +atomic_unchecked_t fscache_n_updates_run;
61011
61012 -atomic_t fscache_n_relinquishes;
61013 -atomic_t fscache_n_relinquishes_null;
61014 -atomic_t fscache_n_relinquishes_waitcrt;
61015 -atomic_t fscache_n_relinquishes_retire;
61016 +atomic_unchecked_t fscache_n_relinquishes;
61017 +atomic_unchecked_t fscache_n_relinquishes_null;
61018 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
61019 +atomic_unchecked_t fscache_n_relinquishes_retire;
61020
61021 -atomic_t fscache_n_cookie_index;
61022 -atomic_t fscache_n_cookie_data;
61023 -atomic_t fscache_n_cookie_special;
61024 +atomic_unchecked_t fscache_n_cookie_index;
61025 +atomic_unchecked_t fscache_n_cookie_data;
61026 +atomic_unchecked_t fscache_n_cookie_special;
61027
61028 -atomic_t fscache_n_object_alloc;
61029 -atomic_t fscache_n_object_no_alloc;
61030 -atomic_t fscache_n_object_lookups;
61031 -atomic_t fscache_n_object_lookups_negative;
61032 -atomic_t fscache_n_object_lookups_positive;
61033 -atomic_t fscache_n_object_lookups_timed_out;
61034 -atomic_t fscache_n_object_created;
61035 -atomic_t fscache_n_object_avail;
61036 -atomic_t fscache_n_object_dead;
61037 +atomic_unchecked_t fscache_n_object_alloc;
61038 +atomic_unchecked_t fscache_n_object_no_alloc;
61039 +atomic_unchecked_t fscache_n_object_lookups;
61040 +atomic_unchecked_t fscache_n_object_lookups_negative;
61041 +atomic_unchecked_t fscache_n_object_lookups_positive;
61042 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
61043 +atomic_unchecked_t fscache_n_object_created;
61044 +atomic_unchecked_t fscache_n_object_avail;
61045 +atomic_unchecked_t fscache_n_object_dead;
61046
61047 -atomic_t fscache_n_checkaux_none;
61048 -atomic_t fscache_n_checkaux_okay;
61049 -atomic_t fscache_n_checkaux_update;
61050 -atomic_t fscache_n_checkaux_obsolete;
61051 +atomic_unchecked_t fscache_n_checkaux_none;
61052 +atomic_unchecked_t fscache_n_checkaux_okay;
61053 +atomic_unchecked_t fscache_n_checkaux_update;
61054 +atomic_unchecked_t fscache_n_checkaux_obsolete;
61055
61056 atomic_t fscache_n_cop_alloc_object;
61057 atomic_t fscache_n_cop_lookup_object;
61058 @@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
61059 seq_puts(m, "FS-Cache statistics\n");
61060
61061 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
61062 - atomic_read(&fscache_n_cookie_index),
61063 - atomic_read(&fscache_n_cookie_data),
61064 - atomic_read(&fscache_n_cookie_special));
61065 + atomic_read_unchecked(&fscache_n_cookie_index),
61066 + atomic_read_unchecked(&fscache_n_cookie_data),
61067 + atomic_read_unchecked(&fscache_n_cookie_special));
61068
61069 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
61070 - atomic_read(&fscache_n_object_alloc),
61071 - atomic_read(&fscache_n_object_no_alloc),
61072 - atomic_read(&fscache_n_object_avail),
61073 - atomic_read(&fscache_n_object_dead));
61074 + atomic_read_unchecked(&fscache_n_object_alloc),
61075 + atomic_read_unchecked(&fscache_n_object_no_alloc),
61076 + atomic_read_unchecked(&fscache_n_object_avail),
61077 + atomic_read_unchecked(&fscache_n_object_dead));
61078 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
61079 - atomic_read(&fscache_n_checkaux_none),
61080 - atomic_read(&fscache_n_checkaux_okay),
61081 - atomic_read(&fscache_n_checkaux_update),
61082 - atomic_read(&fscache_n_checkaux_obsolete));
61083 + atomic_read_unchecked(&fscache_n_checkaux_none),
61084 + atomic_read_unchecked(&fscache_n_checkaux_okay),
61085 + atomic_read_unchecked(&fscache_n_checkaux_update),
61086 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
61087
61088 seq_printf(m, "Pages : mrk=%u unc=%u\n",
61089 - atomic_read(&fscache_n_marks),
61090 - atomic_read(&fscache_n_uncaches));
61091 + atomic_read_unchecked(&fscache_n_marks),
61092 + atomic_read_unchecked(&fscache_n_uncaches));
61093
61094 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
61095 " oom=%u\n",
61096 - atomic_read(&fscache_n_acquires),
61097 - atomic_read(&fscache_n_acquires_null),
61098 - atomic_read(&fscache_n_acquires_no_cache),
61099 - atomic_read(&fscache_n_acquires_ok),
61100 - atomic_read(&fscache_n_acquires_nobufs),
61101 - atomic_read(&fscache_n_acquires_oom));
61102 + atomic_read_unchecked(&fscache_n_acquires),
61103 + atomic_read_unchecked(&fscache_n_acquires_null),
61104 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
61105 + atomic_read_unchecked(&fscache_n_acquires_ok),
61106 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
61107 + atomic_read_unchecked(&fscache_n_acquires_oom));
61108
61109 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
61110 - atomic_read(&fscache_n_object_lookups),
61111 - atomic_read(&fscache_n_object_lookups_negative),
61112 - atomic_read(&fscache_n_object_lookups_positive),
61113 - atomic_read(&fscache_n_object_created),
61114 - atomic_read(&fscache_n_object_lookups_timed_out));
61115 + atomic_read_unchecked(&fscache_n_object_lookups),
61116 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
61117 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
61118 + atomic_read_unchecked(&fscache_n_object_created),
61119 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
61120
61121 seq_printf(m, "Invals : n=%u run=%u\n",
61122 - atomic_read(&fscache_n_invalidates),
61123 - atomic_read(&fscache_n_invalidates_run));
61124 + atomic_read_unchecked(&fscache_n_invalidates),
61125 + atomic_read_unchecked(&fscache_n_invalidates_run));
61126
61127 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
61128 - atomic_read(&fscache_n_updates),
61129 - atomic_read(&fscache_n_updates_null),
61130 - atomic_read(&fscache_n_updates_run));
61131 + atomic_read_unchecked(&fscache_n_updates),
61132 + atomic_read_unchecked(&fscache_n_updates_null),
61133 + atomic_read_unchecked(&fscache_n_updates_run));
61134
61135 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
61136 - atomic_read(&fscache_n_relinquishes),
61137 - atomic_read(&fscache_n_relinquishes_null),
61138 - atomic_read(&fscache_n_relinquishes_waitcrt),
61139 - atomic_read(&fscache_n_relinquishes_retire));
61140 + atomic_read_unchecked(&fscache_n_relinquishes),
61141 + atomic_read_unchecked(&fscache_n_relinquishes_null),
61142 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
61143 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
61144
61145 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
61146 - atomic_read(&fscache_n_attr_changed),
61147 - atomic_read(&fscache_n_attr_changed_ok),
61148 - atomic_read(&fscache_n_attr_changed_nobufs),
61149 - atomic_read(&fscache_n_attr_changed_nomem),
61150 - atomic_read(&fscache_n_attr_changed_calls));
61151 + atomic_read_unchecked(&fscache_n_attr_changed),
61152 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
61153 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
61154 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
61155 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
61156
61157 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
61158 - atomic_read(&fscache_n_allocs),
61159 - atomic_read(&fscache_n_allocs_ok),
61160 - atomic_read(&fscache_n_allocs_wait),
61161 - atomic_read(&fscache_n_allocs_nobufs),
61162 - atomic_read(&fscache_n_allocs_intr));
61163 + atomic_read_unchecked(&fscache_n_allocs),
61164 + atomic_read_unchecked(&fscache_n_allocs_ok),
61165 + atomic_read_unchecked(&fscache_n_allocs_wait),
61166 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
61167 + atomic_read_unchecked(&fscache_n_allocs_intr));
61168 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
61169 - atomic_read(&fscache_n_alloc_ops),
61170 - atomic_read(&fscache_n_alloc_op_waits),
61171 - atomic_read(&fscache_n_allocs_object_dead));
61172 + atomic_read_unchecked(&fscache_n_alloc_ops),
61173 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
61174 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
61175
61176 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
61177 " int=%u oom=%u\n",
61178 - atomic_read(&fscache_n_retrievals),
61179 - atomic_read(&fscache_n_retrievals_ok),
61180 - atomic_read(&fscache_n_retrievals_wait),
61181 - atomic_read(&fscache_n_retrievals_nodata),
61182 - atomic_read(&fscache_n_retrievals_nobufs),
61183 - atomic_read(&fscache_n_retrievals_intr),
61184 - atomic_read(&fscache_n_retrievals_nomem));
61185 + atomic_read_unchecked(&fscache_n_retrievals),
61186 + atomic_read_unchecked(&fscache_n_retrievals_ok),
61187 + atomic_read_unchecked(&fscache_n_retrievals_wait),
61188 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
61189 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
61190 + atomic_read_unchecked(&fscache_n_retrievals_intr),
61191 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
61192 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
61193 - atomic_read(&fscache_n_retrieval_ops),
61194 - atomic_read(&fscache_n_retrieval_op_waits),
61195 - atomic_read(&fscache_n_retrievals_object_dead));
61196 + atomic_read_unchecked(&fscache_n_retrieval_ops),
61197 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
61198 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
61199
61200 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
61201 - atomic_read(&fscache_n_stores),
61202 - atomic_read(&fscache_n_stores_ok),
61203 - atomic_read(&fscache_n_stores_again),
61204 - atomic_read(&fscache_n_stores_nobufs),
61205 - atomic_read(&fscache_n_stores_oom));
61206 + atomic_read_unchecked(&fscache_n_stores),
61207 + atomic_read_unchecked(&fscache_n_stores_ok),
61208 + atomic_read_unchecked(&fscache_n_stores_again),
61209 + atomic_read_unchecked(&fscache_n_stores_nobufs),
61210 + atomic_read_unchecked(&fscache_n_stores_oom));
61211 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
61212 - atomic_read(&fscache_n_store_ops),
61213 - atomic_read(&fscache_n_store_calls),
61214 - atomic_read(&fscache_n_store_pages),
61215 - atomic_read(&fscache_n_store_radix_deletes),
61216 - atomic_read(&fscache_n_store_pages_over_limit));
61217 + atomic_read_unchecked(&fscache_n_store_ops),
61218 + atomic_read_unchecked(&fscache_n_store_calls),
61219 + atomic_read_unchecked(&fscache_n_store_pages),
61220 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
61221 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
61222
61223 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
61224 - atomic_read(&fscache_n_store_vmscan_not_storing),
61225 - atomic_read(&fscache_n_store_vmscan_gone),
61226 - atomic_read(&fscache_n_store_vmscan_busy),
61227 - atomic_read(&fscache_n_store_vmscan_cancelled),
61228 - atomic_read(&fscache_n_store_vmscan_wait));
61229 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
61230 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
61231 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
61232 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
61233 + atomic_read_unchecked(&fscache_n_store_vmscan_wait));
61234
61235 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
61236 - atomic_read(&fscache_n_op_pend),
61237 - atomic_read(&fscache_n_op_run),
61238 - atomic_read(&fscache_n_op_enqueue),
61239 - atomic_read(&fscache_n_op_cancelled),
61240 - atomic_read(&fscache_n_op_rejected));
61241 + atomic_read_unchecked(&fscache_n_op_pend),
61242 + atomic_read_unchecked(&fscache_n_op_run),
61243 + atomic_read_unchecked(&fscache_n_op_enqueue),
61244 + atomic_read_unchecked(&fscache_n_op_cancelled),
61245 + atomic_read_unchecked(&fscache_n_op_rejected));
61246 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
61247 - atomic_read(&fscache_n_op_deferred_release),
61248 - atomic_read(&fscache_n_op_release),
61249 - atomic_read(&fscache_n_op_gc));
61250 + atomic_read_unchecked(&fscache_n_op_deferred_release),
61251 + atomic_read_unchecked(&fscache_n_op_release),
61252 + atomic_read_unchecked(&fscache_n_op_gc));
61253
61254 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
61255 atomic_read(&fscache_n_cop_alloc_object),
61256 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
61257 index 13b691a..1ffca5ae 100644
61258 --- a/fs/fuse/cuse.c
61259 +++ b/fs/fuse/cuse.c
61260 @@ -607,10 +607,12 @@ static int __init cuse_init(void)
61261 INIT_LIST_HEAD(&cuse_conntbl[i]);
61262
61263 /* inherit and extend fuse_dev_operations */
61264 - cuse_channel_fops = fuse_dev_operations;
61265 - cuse_channel_fops.owner = THIS_MODULE;
61266 - cuse_channel_fops.open = cuse_channel_open;
61267 - cuse_channel_fops.release = cuse_channel_release;
61268 + pax_open_kernel();
61269 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
61270 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
61271 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
61272 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
61273 + pax_close_kernel();
61274
61275 cuse_class = class_create(THIS_MODULE, "cuse");
61276 if (IS_ERR(cuse_class))
61277 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
61278 index aac71ce..fcd6a1b 100644
61279 --- a/fs/fuse/dev.c
61280 +++ b/fs/fuse/dev.c
61281 @@ -1323,7 +1323,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
61282 ret = 0;
61283 pipe_lock(pipe);
61284
61285 - if (!pipe->readers) {
61286 + if (!atomic_read(&pipe->readers)) {
61287 send_sig(SIGPIPE, current, 0);
61288 if (!ret)
61289 ret = -EPIPE;
61290 @@ -1352,7 +1352,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
61291 page_nr++;
61292 ret += buf->len;
61293
61294 - if (pipe->files)
61295 + if (atomic_read(&pipe->files))
61296 do_wakeup = 1;
61297 }
61298
61299 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
61300 index 4219835..3473b7e 100644
61301 --- a/fs/fuse/dir.c
61302 +++ b/fs/fuse/dir.c
61303 @@ -1478,7 +1478,7 @@ static char *read_link(struct dentry *dentry)
61304 return link;
61305 }
61306
61307 -static void free_link(char *link)
61308 +static void free_link(const char *link)
61309 {
61310 if (!IS_ERR(link))
61311 free_page((unsigned long) link);
61312 diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
61313 index 9c470fd..aae410e 100644
61314 --- a/fs/hostfs/hostfs_kern.c
61315 +++ b/fs/hostfs/hostfs_kern.c
61316 @@ -898,7 +898,7 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd)
61317
61318 static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
61319 {
61320 - char *s = nd_get_link(nd);
61321 + const char *s = nd_get_link(nd);
61322 if (!IS_ERR(s))
61323 __putname(s);
61324 }
61325 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
61326 index e19d4c0..8a357a9 100644
61327 --- a/fs/hugetlbfs/inode.c
61328 +++ b/fs/hugetlbfs/inode.c
61329 @@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
61330 struct mm_struct *mm = current->mm;
61331 struct vm_area_struct *vma;
61332 struct hstate *h = hstate_file(file);
61333 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
61334 struct vm_unmapped_area_info info;
61335
61336 if (len & ~huge_page_mask(h))
61337 @@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
61338 return addr;
61339 }
61340
61341 +#ifdef CONFIG_PAX_RANDMMAP
61342 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
61343 +#endif
61344 +
61345 if (addr) {
61346 addr = ALIGN(addr, huge_page_size(h));
61347 vma = find_vma(mm, addr);
61348 - if (TASK_SIZE - len >= addr &&
61349 - (!vma || addr + len <= vma->vm_start))
61350 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
61351 return addr;
61352 }
61353
61354 info.flags = 0;
61355 info.length = len;
61356 info.low_limit = TASK_UNMAPPED_BASE;
61357 +
61358 +#ifdef CONFIG_PAX_RANDMMAP
61359 + if (mm->pax_flags & MF_PAX_RANDMMAP)
61360 + info.low_limit += mm->delta_mmap;
61361 +#endif
61362 +
61363 info.high_limit = TASK_SIZE;
61364 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
61365 info.align_offset = 0;
61366 @@ -921,7 +931,7 @@ static struct file_system_type hugetlbfs_fs_type = {
61367 };
61368 MODULE_ALIAS_FS("hugetlbfs");
61369
61370 -static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
61371 +struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
61372
61373 static int can_do_hugetlb_shm(void)
61374 {
61375 diff --git a/fs/inode.c b/fs/inode.c
61376 index d2fb2f2..a6444b0 100644
61377 --- a/fs/inode.c
61378 +++ b/fs/inode.c
61379 @@ -839,16 +839,20 @@ unsigned int get_next_ino(void)
61380 unsigned int *p = &get_cpu_var(last_ino);
61381 unsigned int res = *p;
61382
61383 +start:
61384 +
61385 #ifdef CONFIG_SMP
61386 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
61387 - static atomic_t shared_last_ino;
61388 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
61389 + static atomic_unchecked_t shared_last_ino;
61390 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
61391
61392 res = next - LAST_INO_BATCH;
61393 }
61394 #endif
61395
61396 - *p = ++res;
61397 + if (unlikely(!++res))
61398 + goto start; /* never zero */
61399 + *p = res;
61400 put_cpu_var(last_ino);
61401 return res;
61402 }
61403 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
61404 index 4a6cf28..d3a29d3 100644
61405 --- a/fs/jffs2/erase.c
61406 +++ b/fs/jffs2/erase.c
61407 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
61408 struct jffs2_unknown_node marker = {
61409 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
61410 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
61411 - .totlen = cpu_to_je32(c->cleanmarker_size)
61412 + .totlen = cpu_to_je32(c->cleanmarker_size),
61413 + .hdr_crc = cpu_to_je32(0)
61414 };
61415
61416 jffs2_prealloc_raw_node_refs(c, jeb, 1);
61417 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
61418 index a6597d6..41b30ec 100644
61419 --- a/fs/jffs2/wbuf.c
61420 +++ b/fs/jffs2/wbuf.c
61421 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
61422 {
61423 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
61424 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
61425 - .totlen = constant_cpu_to_je32(8)
61426 + .totlen = constant_cpu_to_je32(8),
61427 + .hdr_crc = constant_cpu_to_je32(0)
61428 };
61429
61430 /*
61431 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
61432 index 97f7fda..09bd33d 100644
61433 --- a/fs/jfs/super.c
61434 +++ b/fs/jfs/super.c
61435 @@ -885,7 +885,7 @@ static int __init init_jfs_fs(void)
61436
61437 jfs_inode_cachep =
61438 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
61439 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
61440 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
61441 init_once);
61442 if (jfs_inode_cachep == NULL)
61443 return -ENOMEM;
61444 diff --git a/fs/kernfs/dir.c b/fs/kernfs/dir.c
61445 index ac127cd..d8079db 100644
61446 --- a/fs/kernfs/dir.c
61447 +++ b/fs/kernfs/dir.c
61448 @@ -182,7 +182,7 @@ struct kernfs_node *kernfs_get_parent(struct kernfs_node *kn)
61449 *
61450 * Returns 31 bit hash of ns + name (so it fits in an off_t )
61451 */
61452 -static unsigned int kernfs_name_hash(const char *name, const void *ns)
61453 +static unsigned int kernfs_name_hash(const unsigned char *name, const void *ns)
61454 {
61455 unsigned long hash = init_name_hash();
61456 unsigned int len = strlen(name);
61457 diff --git a/fs/kernfs/file.c b/fs/kernfs/file.c
61458 index 5e9a80c..3853a24 100644
61459 --- a/fs/kernfs/file.c
61460 +++ b/fs/kernfs/file.c
61461 @@ -33,7 +33,7 @@ static DEFINE_MUTEX(kernfs_open_file_mutex);
61462
61463 struct kernfs_open_node {
61464 atomic_t refcnt;
61465 - atomic_t event;
61466 + atomic_unchecked_t event;
61467 wait_queue_head_t poll;
61468 struct list_head files; /* goes through kernfs_open_file.list */
61469 };
61470 @@ -149,7 +149,7 @@ static int kernfs_seq_show(struct seq_file *sf, void *v)
61471 {
61472 struct kernfs_open_file *of = sf->private;
61473
61474 - of->event = atomic_read(&of->kn->attr.open->event);
61475 + of->event = atomic_read_unchecked(&of->kn->attr.open->event);
61476
61477 return of->kn->attr.ops->seq_show(sf, v);
61478 }
61479 @@ -361,12 +361,12 @@ static int kernfs_vma_page_mkwrite(struct vm_area_struct *vma,
61480 return ret;
61481 }
61482
61483 -static int kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
61484 - void *buf, int len, int write)
61485 +static ssize_t kernfs_vma_access(struct vm_area_struct *vma, unsigned long addr,
61486 + void *buf, size_t len, int write)
61487 {
61488 struct file *file = vma->vm_file;
61489 struct kernfs_open_file *of = kernfs_of(file);
61490 - int ret;
61491 + ssize_t ret;
61492
61493 if (!of->vm_ops)
61494 return -EINVAL;
61495 @@ -567,7 +567,7 @@ static int kernfs_get_open_node(struct kernfs_node *kn,
61496 return -ENOMEM;
61497
61498 atomic_set(&new_on->refcnt, 0);
61499 - atomic_set(&new_on->event, 1);
61500 + atomic_set_unchecked(&new_on->event, 1);
61501 init_waitqueue_head(&new_on->poll);
61502 INIT_LIST_HEAD(&new_on->files);
61503 goto retry;
61504 @@ -773,7 +773,7 @@ static unsigned int kernfs_fop_poll(struct file *filp, poll_table *wait)
61505
61506 kernfs_put_active(kn);
61507
61508 - if (of->event != atomic_read(&on->event))
61509 + if (of->event != atomic_read_unchecked(&on->event))
61510 goto trigger;
61511
61512 return DEFAULT_POLLMASK;
61513 @@ -798,7 +798,7 @@ void kernfs_notify(struct kernfs_node *kn)
61514 if (!WARN_ON(kernfs_type(kn) != KERNFS_FILE)) {
61515 on = kn->attr.open;
61516 if (on) {
61517 - atomic_inc(&on->event);
61518 + atomic_inc_unchecked(&on->event);
61519 wake_up_interruptible(&on->poll);
61520 }
61521 }
61522 diff --git a/fs/kernfs/symlink.c b/fs/kernfs/symlink.c
61523 index 8a19889..4c3069a 100644
61524 --- a/fs/kernfs/symlink.c
61525 +++ b/fs/kernfs/symlink.c
61526 @@ -128,7 +128,7 @@ static void *kernfs_iop_follow_link(struct dentry *dentry, struct nameidata *nd)
61527 static void kernfs_iop_put_link(struct dentry *dentry, struct nameidata *nd,
61528 void *cookie)
61529 {
61530 - char *page = nd_get_link(nd);
61531 + const char *page = nd_get_link(nd);
61532 if (!IS_ERR(page))
61533 free_page((unsigned long)page);
61534 }
61535 diff --git a/fs/libfs.c b/fs/libfs.c
61536 index a184424..944ddce 100644
61537 --- a/fs/libfs.c
61538 +++ b/fs/libfs.c
61539 @@ -159,6 +159,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
61540
61541 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
61542 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
61543 + char d_name[sizeof(next->d_iname)];
61544 + const unsigned char *name;
61545 +
61546 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
61547 if (!simple_positive(next)) {
61548 spin_unlock(&next->d_lock);
61549 @@ -167,7 +170,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
61550
61551 spin_unlock(&next->d_lock);
61552 spin_unlock(&dentry->d_lock);
61553 - if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
61554 + name = next->d_name.name;
61555 + if (name == next->d_iname) {
61556 + memcpy(d_name, name, next->d_name.len);
61557 + name = d_name;
61558 + }
61559 + if (!dir_emit(ctx, name, next->d_name.len,
61560 next->d_inode->i_ino, dt_type(next->d_inode)))
61561 return 0;
61562 spin_lock(&dentry->d_lock);
61563 @@ -999,7 +1007,7 @@ EXPORT_SYMBOL(noop_fsync);
61564 void kfree_put_link(struct dentry *dentry, struct nameidata *nd,
61565 void *cookie)
61566 {
61567 - char *s = nd_get_link(nd);
61568 + const char *s = nd_get_link(nd);
61569 if (!IS_ERR(s))
61570 kfree(s);
61571 }
61572 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
61573 index acd3947..1f896e2 100644
61574 --- a/fs/lockd/clntproc.c
61575 +++ b/fs/lockd/clntproc.c
61576 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
61577 /*
61578 * Cookie counter for NLM requests
61579 */
61580 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
61581 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
61582
61583 void nlmclnt_next_cookie(struct nlm_cookie *c)
61584 {
61585 - u32 cookie = atomic_inc_return(&nlm_cookie);
61586 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
61587
61588 memcpy(c->data, &cookie, 4);
61589 c->len=4;
61590 diff --git a/fs/locks.c b/fs/locks.c
61591 index e390bd9..c79870e 100644
61592 --- a/fs/locks.c
61593 +++ b/fs/locks.c
61594 @@ -2315,16 +2315,16 @@ void locks_remove_file(struct file *filp)
61595 locks_remove_posix(filp, (fl_owner_t)filp);
61596
61597 if (filp->f_op->flock) {
61598 - struct file_lock fl = {
61599 + struct file_lock flock = {
61600 .fl_pid = current->tgid,
61601 .fl_file = filp,
61602 .fl_flags = FL_FLOCK,
61603 .fl_type = F_UNLCK,
61604 .fl_end = OFFSET_MAX,
61605 };
61606 - filp->f_op->flock(filp, F_SETLKW, &fl);
61607 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
61608 - fl.fl_ops->fl_release_private(&fl);
61609 + filp->f_op->flock(filp, F_SETLKW, &flock);
61610 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
61611 + flock.fl_ops->fl_release_private(&flock);
61612 }
61613
61614 spin_lock(&inode->i_lock);
61615 diff --git a/fs/mount.h b/fs/mount.h
61616 index d55297f..f5b28c5 100644
61617 --- a/fs/mount.h
61618 +++ b/fs/mount.h
61619 @@ -11,7 +11,7 @@ struct mnt_namespace {
61620 u64 seq; /* Sequence number to prevent loops */
61621 wait_queue_head_t poll;
61622 u64 event;
61623 -};
61624 +} __randomize_layout;
61625
61626 struct mnt_pcp {
61627 int mnt_count;
61628 @@ -57,7 +57,7 @@ struct mount {
61629 int mnt_expiry_mark; /* true if marked for expiry */
61630 int mnt_pinned;
61631 struct path mnt_ex_mountpoint;
61632 -};
61633 +} __randomize_layout;
61634
61635 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
61636
61637 diff --git a/fs/namei.c b/fs/namei.c
61638 index 985c6f3..f67a0f8 100644
61639 --- a/fs/namei.c
61640 +++ b/fs/namei.c
61641 @@ -330,17 +330,32 @@ int generic_permission(struct inode *inode, int mask)
61642 if (ret != -EACCES)
61643 return ret;
61644
61645 +#ifdef CONFIG_GRKERNSEC
61646 + /* we'll block if we have to log due to a denied capability use */
61647 + if (mask & MAY_NOT_BLOCK)
61648 + return -ECHILD;
61649 +#endif
61650 +
61651 if (S_ISDIR(inode->i_mode)) {
61652 /* DACs are overridable for directories */
61653 - if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
61654 - return 0;
61655 if (!(mask & MAY_WRITE))
61656 - if (capable_wrt_inode_uidgid(inode,
61657 - CAP_DAC_READ_SEARCH))
61658 + if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
61659 + capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
61660 return 0;
61661 + if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
61662 + return 0;
61663 return -EACCES;
61664 }
61665 /*
61666 + * Searching includes executable on directories, else just read.
61667 + */
61668 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
61669 + if (mask == MAY_READ)
61670 + if (capable_wrt_inode_uidgid_nolog(inode, CAP_DAC_OVERRIDE) ||
61671 + capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
61672 + return 0;
61673 +
61674 + /*
61675 * Read/write DACs are always overridable.
61676 * Executable DACs are overridable when there is
61677 * at least one exec bit set.
61678 @@ -349,14 +364,6 @@ int generic_permission(struct inode *inode, int mask)
61679 if (capable_wrt_inode_uidgid(inode, CAP_DAC_OVERRIDE))
61680 return 0;
61681
61682 - /*
61683 - * Searching includes executable on directories, else just read.
61684 - */
61685 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
61686 - if (mask == MAY_READ)
61687 - if (capable_wrt_inode_uidgid(inode, CAP_DAC_READ_SEARCH))
61688 - return 0;
61689 -
61690 return -EACCES;
61691 }
61692 EXPORT_SYMBOL(generic_permission);
61693 @@ -824,7 +831,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
61694 {
61695 struct dentry *dentry = link->dentry;
61696 int error;
61697 - char *s;
61698 + const char *s;
61699
61700 BUG_ON(nd->flags & LOOKUP_RCU);
61701
61702 @@ -845,6 +852,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
61703 if (error)
61704 goto out_put_nd_path;
61705
61706 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
61707 + dentry->d_inode, dentry, nd->path.mnt)) {
61708 + error = -EACCES;
61709 + goto out_put_nd_path;
61710 + }
61711 +
61712 nd->last_type = LAST_BIND;
61713 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
61714 error = PTR_ERR(*p);
61715 @@ -1596,6 +1609,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
61716 if (res)
61717 break;
61718 res = walk_component(nd, path, LOOKUP_FOLLOW);
61719 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
61720 + res = -EACCES;
61721 put_link(nd, &link, cookie);
61722 } while (res > 0);
61723
61724 @@ -1669,7 +1684,7 @@ EXPORT_SYMBOL(full_name_hash);
61725 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
61726 {
61727 unsigned long a, b, adata, bdata, mask, hash, len;
61728 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
61729 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
61730
61731 hash = a = 0;
61732 len = -sizeof(unsigned long);
61733 @@ -1953,6 +1968,8 @@ static int path_lookupat(int dfd, const char *name,
61734 if (err)
61735 break;
61736 err = lookup_last(nd, &path);
61737 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
61738 + err = -EACCES;
61739 put_link(nd, &link, cookie);
61740 }
61741 }
61742 @@ -1960,6 +1977,13 @@ static int path_lookupat(int dfd, const char *name,
61743 if (!err)
61744 err = complete_walk(nd);
61745
61746 + if (!err && !(nd->flags & LOOKUP_PARENT)) {
61747 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
61748 + path_put(&nd->path);
61749 + err = -ENOENT;
61750 + }
61751 + }
61752 +
61753 if (!err && nd->flags & LOOKUP_DIRECTORY) {
61754 if (!d_can_lookup(nd->path.dentry)) {
61755 path_put(&nd->path);
61756 @@ -1987,8 +2011,15 @@ static int filename_lookup(int dfd, struct filename *name,
61757 retval = path_lookupat(dfd, name->name,
61758 flags | LOOKUP_REVAL, nd);
61759
61760 - if (likely(!retval))
61761 + if (likely(!retval)) {
61762 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
61763 + if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
61764 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
61765 + path_put(&nd->path);
61766 + return -ENOENT;
61767 + }
61768 + }
61769 + }
61770 return retval;
61771 }
61772
61773 @@ -2569,6 +2600,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
61774 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
61775 return -EPERM;
61776
61777 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
61778 + return -EPERM;
61779 + if (gr_handle_rawio(inode))
61780 + return -EPERM;
61781 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
61782 + return -EACCES;
61783 +
61784 return 0;
61785 }
61786
61787 @@ -2800,7 +2838,7 @@ looked_up:
61788 * cleared otherwise prior to returning.
61789 */
61790 static int lookup_open(struct nameidata *nd, struct path *path,
61791 - struct file *file,
61792 + struct path *link, struct file *file,
61793 const struct open_flags *op,
61794 bool got_write, int *opened)
61795 {
61796 @@ -2835,6 +2873,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
61797 /* Negative dentry, just create the file */
61798 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
61799 umode_t mode = op->mode;
61800 +
61801 + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
61802 + error = -EACCES;
61803 + goto out_dput;
61804 + }
61805 +
61806 + if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
61807 + error = -EACCES;
61808 + goto out_dput;
61809 + }
61810 +
61811 if (!IS_POSIXACL(dir->d_inode))
61812 mode &= ~current_umask();
61813 /*
61814 @@ -2856,6 +2905,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
61815 nd->flags & LOOKUP_EXCL);
61816 if (error)
61817 goto out_dput;
61818 + else
61819 + gr_handle_create(dentry, nd->path.mnt);
61820 }
61821 out_no_open:
61822 path->dentry = dentry;
61823 @@ -2870,7 +2921,7 @@ out_dput:
61824 /*
61825 * Handle the last step of open()
61826 */
61827 -static int do_last(struct nameidata *nd, struct path *path,
61828 +static int do_last(struct nameidata *nd, struct path *path, struct path *link,
61829 struct file *file, const struct open_flags *op,
61830 int *opened, struct filename *name)
61831 {
61832 @@ -2920,6 +2971,15 @@ static int do_last(struct nameidata *nd, struct path *path,
61833 if (error)
61834 return error;
61835
61836 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
61837 + error = -ENOENT;
61838 + goto out;
61839 + }
61840 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
61841 + error = -EACCES;
61842 + goto out;
61843 + }
61844 +
61845 audit_inode(name, dir, LOOKUP_PARENT);
61846 error = -EISDIR;
61847 /* trailing slashes? */
61848 @@ -2939,7 +2999,7 @@ retry_lookup:
61849 */
61850 }
61851 mutex_lock(&dir->d_inode->i_mutex);
61852 - error = lookup_open(nd, path, file, op, got_write, opened);
61853 + error = lookup_open(nd, path, link, file, op, got_write, opened);
61854 mutex_unlock(&dir->d_inode->i_mutex);
61855
61856 if (error <= 0) {
61857 @@ -2963,11 +3023,28 @@ retry_lookup:
61858 goto finish_open_created;
61859 }
61860
61861 + if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
61862 + error = -ENOENT;
61863 + goto exit_dput;
61864 + }
61865 + if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
61866 + error = -EACCES;
61867 + goto exit_dput;
61868 + }
61869 +
61870 /*
61871 * create/update audit record if it already exists.
61872 */
61873 - if (d_is_positive(path->dentry))
61874 + if (d_is_positive(path->dentry)) {
61875 + /* only check if O_CREAT is specified, all other checks need to go
61876 + into may_open */
61877 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
61878 + error = -EACCES;
61879 + goto exit_dput;
61880 + }
61881 +
61882 audit_inode(name, path->dentry, 0);
61883 + }
61884
61885 /*
61886 * If atomic_open() acquired write access it is dropped now due to
61887 @@ -3008,6 +3085,11 @@ finish_lookup:
61888 }
61889 }
61890 BUG_ON(inode != path->dentry->d_inode);
61891 + /* if we're resolving a symlink to another symlink */
61892 + if (link && gr_handle_symlink_owner(link, inode)) {
61893 + error = -EACCES;
61894 + goto out;
61895 + }
61896 return 1;
61897 }
61898
61899 @@ -3017,7 +3099,6 @@ finish_lookup:
61900 save_parent.dentry = nd->path.dentry;
61901 save_parent.mnt = mntget(path->mnt);
61902 nd->path.dentry = path->dentry;
61903 -
61904 }
61905 nd->inode = inode;
61906 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
61907 @@ -3027,7 +3108,18 @@ finish_open:
61908 path_put(&save_parent);
61909 return error;
61910 }
61911 +
61912 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
61913 + error = -ENOENT;
61914 + goto out;
61915 + }
61916 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
61917 + error = -EACCES;
61918 + goto out;
61919 + }
61920 +
61921 audit_inode(name, nd->path.dentry, 0);
61922 +
61923 error = -EISDIR;
61924 if ((open_flag & O_CREAT) && d_is_dir(nd->path.dentry))
61925 goto out;
61926 @@ -3190,7 +3282,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
61927 if (unlikely(error))
61928 goto out;
61929
61930 - error = do_last(nd, &path, file, op, &opened, pathname);
61931 + error = do_last(nd, &path, NULL, file, op, &opened, pathname);
61932 while (unlikely(error > 0)) { /* trailing symlink */
61933 struct path link = path;
61934 void *cookie;
61935 @@ -3208,7 +3300,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
61936 error = follow_link(&link, nd, &cookie);
61937 if (unlikely(error))
61938 break;
61939 - error = do_last(nd, &path, file, op, &opened, pathname);
61940 + error = do_last(nd, &path, &link, file, op, &opened, pathname);
61941 put_link(nd, &link, cookie);
61942 }
61943 out:
61944 @@ -3308,9 +3400,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
61945 goto unlock;
61946
61947 error = -EEXIST;
61948 - if (d_is_positive(dentry))
61949 + if (d_is_positive(dentry)) {
61950 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt))
61951 + error = -ENOENT;
61952 goto fail;
61953 -
61954 + }
61955 /*
61956 * Special case - lookup gave negative, but... we had foo/bar/
61957 * From the vfs_mknod() POV we just have a negative dentry -
61958 @@ -3362,6 +3456,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
61959 }
61960 EXPORT_SYMBOL(user_path_create);
61961
61962 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
61963 +{
61964 + struct filename *tmp = getname(pathname);
61965 + struct dentry *res;
61966 + if (IS_ERR(tmp))
61967 + return ERR_CAST(tmp);
61968 + res = kern_path_create(dfd, tmp->name, path, lookup_flags);
61969 + if (IS_ERR(res))
61970 + putname(tmp);
61971 + else
61972 + *to = tmp;
61973 + return res;
61974 +}
61975 +
61976 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
61977 {
61978 int error = may_create(dir, dentry);
61979 @@ -3425,6 +3533,17 @@ retry:
61980
61981 if (!IS_POSIXACL(path.dentry->d_inode))
61982 mode &= ~current_umask();
61983 +
61984 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
61985 + error = -EPERM;
61986 + goto out;
61987 + }
61988 +
61989 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
61990 + error = -EACCES;
61991 + goto out;
61992 + }
61993 +
61994 error = security_path_mknod(&path, dentry, mode, dev);
61995 if (error)
61996 goto out;
61997 @@ -3441,6 +3560,8 @@ retry:
61998 break;
61999 }
62000 out:
62001 + if (!error)
62002 + gr_handle_create(dentry, path.mnt);
62003 done_path_create(&path, dentry);
62004 if (retry_estale(error, lookup_flags)) {
62005 lookup_flags |= LOOKUP_REVAL;
62006 @@ -3494,9 +3615,16 @@ retry:
62007
62008 if (!IS_POSIXACL(path.dentry->d_inode))
62009 mode &= ~current_umask();
62010 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
62011 + error = -EACCES;
62012 + goto out;
62013 + }
62014 error = security_path_mkdir(&path, dentry, mode);
62015 if (!error)
62016 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
62017 + if (!error)
62018 + gr_handle_create(dentry, path.mnt);
62019 +out:
62020 done_path_create(&path, dentry);
62021 if (retry_estale(error, lookup_flags)) {
62022 lookup_flags |= LOOKUP_REVAL;
62023 @@ -3579,6 +3707,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
62024 struct filename *name;
62025 struct dentry *dentry;
62026 struct nameidata nd;
62027 + ino_t saved_ino = 0;
62028 + dev_t saved_dev = 0;
62029 unsigned int lookup_flags = 0;
62030 retry:
62031 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
62032 @@ -3611,10 +3741,21 @@ retry:
62033 error = -ENOENT;
62034 goto exit3;
62035 }
62036 +
62037 + saved_ino = dentry->d_inode->i_ino;
62038 + saved_dev = gr_get_dev_from_dentry(dentry);
62039 +
62040 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
62041 + error = -EACCES;
62042 + goto exit3;
62043 + }
62044 +
62045 error = security_path_rmdir(&nd.path, dentry);
62046 if (error)
62047 goto exit3;
62048 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
62049 + if (!error && (saved_dev || saved_ino))
62050 + gr_handle_delete(saved_ino, saved_dev);
62051 exit3:
62052 dput(dentry);
62053 exit2:
62054 @@ -3705,6 +3846,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
62055 struct nameidata nd;
62056 struct inode *inode = NULL;
62057 struct inode *delegated_inode = NULL;
62058 + ino_t saved_ino = 0;
62059 + dev_t saved_dev = 0;
62060 unsigned int lookup_flags = 0;
62061 retry:
62062 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
62063 @@ -3731,10 +3874,22 @@ retry_deleg:
62064 if (d_is_negative(dentry))
62065 goto slashes;
62066 ihold(inode);
62067 +
62068 + if (inode->i_nlink <= 1) {
62069 + saved_ino = inode->i_ino;
62070 + saved_dev = gr_get_dev_from_dentry(dentry);
62071 + }
62072 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
62073 + error = -EACCES;
62074 + goto exit2;
62075 + }
62076 +
62077 error = security_path_unlink(&nd.path, dentry);
62078 if (error)
62079 goto exit2;
62080 error = vfs_unlink(nd.path.dentry->d_inode, dentry, &delegated_inode);
62081 + if (!error && (saved_ino || saved_dev))
62082 + gr_handle_delete(saved_ino, saved_dev);
62083 exit2:
62084 dput(dentry);
62085 }
62086 @@ -3823,9 +3978,17 @@ retry:
62087 if (IS_ERR(dentry))
62088 goto out_putname;
62089
62090 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
62091 + error = -EACCES;
62092 + goto out;
62093 + }
62094 +
62095 error = security_path_symlink(&path, dentry, from->name);
62096 if (!error)
62097 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
62098 + if (!error)
62099 + gr_handle_create(dentry, path.mnt);
62100 +out:
62101 done_path_create(&path, dentry);
62102 if (retry_estale(error, lookup_flags)) {
62103 lookup_flags |= LOOKUP_REVAL;
62104 @@ -3929,6 +4092,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
62105 struct dentry *new_dentry;
62106 struct path old_path, new_path;
62107 struct inode *delegated_inode = NULL;
62108 + struct filename *to = NULL;
62109 int how = 0;
62110 int error;
62111
62112 @@ -3952,7 +4116,7 @@ retry:
62113 if (error)
62114 return error;
62115
62116 - new_dentry = user_path_create(newdfd, newname, &new_path,
62117 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
62118 (how & LOOKUP_REVAL));
62119 error = PTR_ERR(new_dentry);
62120 if (IS_ERR(new_dentry))
62121 @@ -3964,11 +4128,28 @@ retry:
62122 error = may_linkat(&old_path);
62123 if (unlikely(error))
62124 goto out_dput;
62125 +
62126 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
62127 + old_path.dentry->d_inode,
62128 + old_path.dentry->d_inode->i_mode, to)) {
62129 + error = -EACCES;
62130 + goto out_dput;
62131 + }
62132 +
62133 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
62134 + old_path.dentry, old_path.mnt, to)) {
62135 + error = -EACCES;
62136 + goto out_dput;
62137 + }
62138 +
62139 error = security_path_link(old_path.dentry, &new_path, new_dentry);
62140 if (error)
62141 goto out_dput;
62142 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry, &delegated_inode);
62143 + if (!error)
62144 + gr_handle_create(new_dentry, new_path.mnt);
62145 out_dput:
62146 + putname(to);
62147 done_path_create(&new_path, new_dentry);
62148 if (delegated_inode) {
62149 error = break_deleg_wait(&delegated_inode);
62150 @@ -4278,6 +4459,12 @@ retry_deleg:
62151 if (new_dentry == trap)
62152 goto exit5;
62153
62154 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
62155 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
62156 + to, flags);
62157 + if (error)
62158 + goto exit5;
62159 +
62160 error = security_path_rename(&oldnd.path, old_dentry,
62161 &newnd.path, new_dentry, flags);
62162 if (error)
62163 @@ -4285,6 +4472,9 @@ retry_deleg:
62164 error = vfs_rename(old_dir->d_inode, old_dentry,
62165 new_dir->d_inode, new_dentry,
62166 &delegated_inode, flags);
62167 + if (!error)
62168 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
62169 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0, flags);
62170 exit5:
62171 dput(new_dentry);
62172 exit4:
62173 @@ -4327,14 +4517,24 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
62174
62175 int readlink_copy(char __user *buffer, int buflen, const char *link)
62176 {
62177 + char tmpbuf[64];
62178 + const char *newlink;
62179 int len = PTR_ERR(link);
62180 +
62181 if (IS_ERR(link))
62182 goto out;
62183
62184 len = strlen(link);
62185 if (len > (unsigned) buflen)
62186 len = buflen;
62187 - if (copy_to_user(buffer, link, len))
62188 +
62189 + if (len < sizeof(tmpbuf)) {
62190 + memcpy(tmpbuf, link, len);
62191 + newlink = tmpbuf;
62192 + } else
62193 + newlink = link;
62194 +
62195 + if (copy_to_user(buffer, newlink, len))
62196 len = -EFAULT;
62197 out:
62198 return len;
62199 diff --git a/fs/namespace.c b/fs/namespace.c
62200 index 182bc41..72e3cf1 100644
62201 --- a/fs/namespace.c
62202 +++ b/fs/namespace.c
62203 @@ -1348,6 +1348,9 @@ static int do_umount(struct mount *mnt, int flags)
62204 if (!(sb->s_flags & MS_RDONLY))
62205 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
62206 up_write(&sb->s_umount);
62207 +
62208 + gr_log_remount(mnt->mnt_devname, retval);
62209 +
62210 return retval;
62211 }
62212
62213 @@ -1370,6 +1373,9 @@ static int do_umount(struct mount *mnt, int flags)
62214 }
62215 unlock_mount_hash();
62216 namespace_unlock();
62217 +
62218 + gr_log_unmount(mnt->mnt_devname, retval);
62219 +
62220 return retval;
62221 }
62222
62223 @@ -1389,7 +1395,7 @@ static inline bool may_mount(void)
62224 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
62225 */
62226
62227 -SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
62228 +SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
62229 {
62230 struct path path;
62231 struct mount *mnt;
62232 @@ -1431,7 +1437,7 @@ out:
62233 /*
62234 * The 2.0 compatible umount. No flags.
62235 */
62236 -SYSCALL_DEFINE1(oldumount, char __user *, name)
62237 +SYSCALL_DEFINE1(oldumount, const char __user *, name)
62238 {
62239 return sys_umount(name, 0);
62240 }
62241 @@ -2440,6 +2446,16 @@ long do_mount(const char *dev_name, const char *dir_name,
62242 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
62243 MS_STRICTATIME);
62244
62245 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
62246 + retval = -EPERM;
62247 + goto dput_out;
62248 + }
62249 +
62250 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
62251 + retval = -EPERM;
62252 + goto dput_out;
62253 + }
62254 +
62255 if (flags & MS_REMOUNT)
62256 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
62257 data_page);
62258 @@ -2454,6 +2470,9 @@ long do_mount(const char *dev_name, const char *dir_name,
62259 dev_name, data_page);
62260 dput_out:
62261 path_put(&path);
62262 +
62263 + gr_log_mount(dev_name, dir_name, retval);
62264 +
62265 return retval;
62266 }
62267
62268 @@ -2471,7 +2490,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
62269 * number incrementing at 10Ghz will take 12,427 years to wrap which
62270 * is effectively never, so we can ignore the possibility.
62271 */
62272 -static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
62273 +static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
62274
62275 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
62276 {
62277 @@ -2486,7 +2505,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
62278 kfree(new_ns);
62279 return ERR_PTR(ret);
62280 }
62281 - new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
62282 + new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
62283 atomic_set(&new_ns->count, 1);
62284 new_ns->root = NULL;
62285 INIT_LIST_HEAD(&new_ns->list);
62286 @@ -2496,7 +2515,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
62287 return new_ns;
62288 }
62289
62290 -struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
62291 +__latent_entropy struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
62292 struct user_namespace *user_ns, struct fs_struct *new_fs)
62293 {
62294 struct mnt_namespace *new_ns;
62295 @@ -2617,8 +2636,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
62296 }
62297 EXPORT_SYMBOL(mount_subtree);
62298
62299 -SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
62300 - char __user *, type, unsigned long, flags, void __user *, data)
62301 +SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
62302 + const char __user *, type, unsigned long, flags, void __user *, data)
62303 {
62304 int ret;
62305 char *kernel_type;
62306 @@ -2731,6 +2750,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
62307 if (error)
62308 goto out2;
62309
62310 + if (gr_handle_chroot_pivot()) {
62311 + error = -EPERM;
62312 + goto out2;
62313 + }
62314 +
62315 get_fs_root(current->fs, &root);
62316 old_mp = lock_mount(&old);
62317 error = PTR_ERR(old_mp);
62318 @@ -2999,7 +3023,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
62319 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
62320 return -EPERM;
62321
62322 - if (fs->users != 1)
62323 + if (atomic_read(&fs->users) != 1)
62324 return -EINVAL;
62325
62326 get_mnt_ns(mnt_ns);
62327 diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
62328 index f4ccfe6..a5cf064 100644
62329 --- a/fs/nfs/callback_xdr.c
62330 +++ b/fs/nfs/callback_xdr.c
62331 @@ -51,7 +51,7 @@ struct callback_op {
62332 callback_decode_arg_t decode_args;
62333 callback_encode_res_t encode_res;
62334 long res_maxsize;
62335 -};
62336 +} __do_const;
62337
62338 static struct callback_op callback_ops[];
62339
62340 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
62341 index c79f3e7..d61d671 100644
62342 --- a/fs/nfs/inode.c
62343 +++ b/fs/nfs/inode.c
62344 @@ -1209,16 +1209,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
62345 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
62346 }
62347
62348 -static atomic_long_t nfs_attr_generation_counter;
62349 +static atomic_long_unchecked_t nfs_attr_generation_counter;
62350
62351 static unsigned long nfs_read_attr_generation_counter(void)
62352 {
62353 - return atomic_long_read(&nfs_attr_generation_counter);
62354 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
62355 }
62356
62357 unsigned long nfs_inc_attr_generation_counter(void)
62358 {
62359 - return atomic_long_inc_return(&nfs_attr_generation_counter);
62360 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
62361 }
62362
62363 void nfs_fattr_init(struct nfs_fattr *fattr)
62364 diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
62365 index 95e3720..46c23fa 100644
62366 --- a/fs/nfsd/nfs4proc.c
62367 +++ b/fs/nfsd/nfs4proc.c
62368 @@ -1169,7 +1169,7 @@ struct nfsd4_operation {
62369 nfsd4op_rsize op_rsize_bop;
62370 stateid_getter op_get_currentstateid;
62371 stateid_setter op_set_currentstateid;
62372 -};
62373 +} __do_const;
62374
62375 static struct nfsd4_operation nfsd4_ops[];
62376
62377 diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
62378 index 3297158..7bb8436 100644
62379 --- a/fs/nfsd/nfs4xdr.c
62380 +++ b/fs/nfsd/nfs4xdr.c
62381 @@ -1541,7 +1541,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
62382
62383 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
62384
62385 -static nfsd4_dec nfsd4_dec_ops[] = {
62386 +static const nfsd4_dec nfsd4_dec_ops[] = {
62387 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
62388 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
62389 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
62390 diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
62391 index f8f060f..c4ba09a 100644
62392 --- a/fs/nfsd/nfscache.c
62393 +++ b/fs/nfsd/nfscache.c
62394 @@ -519,14 +519,17 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
62395 {
62396 struct svc_cacherep *rp = rqstp->rq_cacherep;
62397 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
62398 - int len;
62399 + long len;
62400 size_t bufsize = 0;
62401
62402 if (!rp)
62403 return;
62404
62405 - len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
62406 - len >>= 2;
62407 + if (statp) {
62408 + len = (char*)statp - (char*)resv->iov_base;
62409 + len = resv->iov_len - len;
62410 + len >>= 2;
62411 + }
62412
62413 /* Don't cache excessive amounts of data and XDR failures */
62414 if (!statp || len > (256 >> 2)) {
62415 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
62416 index 16f0673..1c2c30ab 100644
62417 --- a/fs/nfsd/vfs.c
62418 +++ b/fs/nfsd/vfs.c
62419 @@ -843,7 +843,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
62420 } else {
62421 oldfs = get_fs();
62422 set_fs(KERNEL_DS);
62423 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
62424 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
62425 set_fs(oldfs);
62426 }
62427
62428 @@ -934,7 +934,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
62429
62430 /* Write the data. */
62431 oldfs = get_fs(); set_fs(KERNEL_DS);
62432 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
62433 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
62434 set_fs(oldfs);
62435 if (host_err < 0)
62436 goto out_nfserr;
62437 @@ -1479,7 +1479,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
62438 */
62439
62440 oldfs = get_fs(); set_fs(KERNEL_DS);
62441 - host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
62442 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
62443 set_fs(oldfs);
62444
62445 if (host_err < 0)
62446 diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
62447 index 52ccd34..43a53b1 100644
62448 --- a/fs/nls/nls_base.c
62449 +++ b/fs/nls/nls_base.c
62450 @@ -234,21 +234,25 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
62451
62452 int __register_nls(struct nls_table *nls, struct module *owner)
62453 {
62454 - struct nls_table ** tmp = &tables;
62455 + struct nls_table *tmp = tables;
62456
62457 if (nls->next)
62458 return -EBUSY;
62459
62460 - nls->owner = owner;
62461 + pax_open_kernel();
62462 + *(void **)&nls->owner = owner;
62463 + pax_close_kernel();
62464 spin_lock(&nls_lock);
62465 - while (*tmp) {
62466 - if (nls == *tmp) {
62467 + while (tmp) {
62468 + if (nls == tmp) {
62469 spin_unlock(&nls_lock);
62470 return -EBUSY;
62471 }
62472 - tmp = &(*tmp)->next;
62473 + tmp = tmp->next;
62474 }
62475 - nls->next = tables;
62476 + pax_open_kernel();
62477 + *(struct nls_table **)&nls->next = tables;
62478 + pax_close_kernel();
62479 tables = nls;
62480 spin_unlock(&nls_lock);
62481 return 0;
62482 @@ -257,12 +261,14 @@ EXPORT_SYMBOL(__register_nls);
62483
62484 int unregister_nls(struct nls_table * nls)
62485 {
62486 - struct nls_table ** tmp = &tables;
62487 + struct nls_table * const * tmp = &tables;
62488
62489 spin_lock(&nls_lock);
62490 while (*tmp) {
62491 if (nls == *tmp) {
62492 - *tmp = nls->next;
62493 + pax_open_kernel();
62494 + *(struct nls_table **)tmp = nls->next;
62495 + pax_close_kernel();
62496 spin_unlock(&nls_lock);
62497 return 0;
62498 }
62499 diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
62500 index 162b3f1..6076a7c 100644
62501 --- a/fs/nls/nls_euc-jp.c
62502 +++ b/fs/nls/nls_euc-jp.c
62503 @@ -560,8 +560,10 @@ static int __init init_nls_euc_jp(void)
62504 p_nls = load_nls("cp932");
62505
62506 if (p_nls) {
62507 - table.charset2upper = p_nls->charset2upper;
62508 - table.charset2lower = p_nls->charset2lower;
62509 + pax_open_kernel();
62510 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
62511 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
62512 + pax_close_kernel();
62513 return register_nls(&table);
62514 }
62515
62516 diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
62517 index a80a741..7b96e1b 100644
62518 --- a/fs/nls/nls_koi8-ru.c
62519 +++ b/fs/nls/nls_koi8-ru.c
62520 @@ -62,8 +62,10 @@ static int __init init_nls_koi8_ru(void)
62521 p_nls = load_nls("koi8-u");
62522
62523 if (p_nls) {
62524 - table.charset2upper = p_nls->charset2upper;
62525 - table.charset2lower = p_nls->charset2lower;
62526 + pax_open_kernel();
62527 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
62528 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
62529 + pax_close_kernel();
62530 return register_nls(&table);
62531 }
62532
62533 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
62534 index 732648b..d3b017f 100644
62535 --- a/fs/notify/fanotify/fanotify_user.c
62536 +++ b/fs/notify/fanotify/fanotify_user.c
62537 @@ -203,8 +203,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
62538
62539 fd = fanotify_event_metadata.fd;
62540 ret = -EFAULT;
62541 - if (copy_to_user(buf, &fanotify_event_metadata,
62542 - fanotify_event_metadata.event_len))
62543 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
62544 + copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
62545 goto out_close_fd;
62546
62547 #ifdef CONFIG_FANOTIFY_ACCESS_PERMISSIONS
62548 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
62549 index 1e58402..bb2d6f4 100644
62550 --- a/fs/notify/notification.c
62551 +++ b/fs/notify/notification.c
62552 @@ -48,7 +48,7 @@
62553 #include <linux/fsnotify_backend.h>
62554 #include "fsnotify.h"
62555
62556 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62557 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62558
62559 /**
62560 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
62561 @@ -56,7 +56,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
62562 */
62563 u32 fsnotify_get_cookie(void)
62564 {
62565 - return atomic_inc_return(&fsnotify_sync_cookie);
62566 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
62567 }
62568 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
62569
62570 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
62571 index 9e38daf..5727cae 100644
62572 --- a/fs/ntfs/dir.c
62573 +++ b/fs/ntfs/dir.c
62574 @@ -1310,7 +1310,7 @@ find_next_index_buffer:
62575 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
62576 ~(s64)(ndir->itype.index.block_size - 1)));
62577 /* Bounds checks. */
62578 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
62579 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
62580 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
62581 "inode 0x%lx or driver bug.", vdir->i_ino);
62582 goto err_out;
62583 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
62584 index db9bd8a..8338fb6 100644
62585 --- a/fs/ntfs/file.c
62586 +++ b/fs/ntfs/file.c
62587 @@ -1282,7 +1282,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
62588 char *addr;
62589 size_t total = 0;
62590 unsigned len;
62591 - int left;
62592 + unsigned left;
62593
62594 do {
62595 len = PAGE_CACHE_SIZE - ofs;
62596 diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
62597 index 9de2491..3306095 100644
62598 --- a/fs/ntfs/super.c
62599 +++ b/fs/ntfs/super.c
62600 @@ -688,7 +688,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62601 if (!silent)
62602 ntfs_error(sb, "Primary boot sector is invalid.");
62603 } else if (!silent)
62604 - ntfs_error(sb, read_err_str, "primary");
62605 + ntfs_error(sb, read_err_str, "%s", "primary");
62606 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
62607 if (bh_primary)
62608 brelse(bh_primary);
62609 @@ -704,7 +704,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62610 goto hotfix_primary_boot_sector;
62611 brelse(bh_backup);
62612 } else if (!silent)
62613 - ntfs_error(sb, read_err_str, "backup");
62614 + ntfs_error(sb, read_err_str, "%s", "backup");
62615 /* Try to read NT3.51- backup boot sector. */
62616 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
62617 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
62618 @@ -715,7 +715,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
62619 "sector.");
62620 brelse(bh_backup);
62621 } else if (!silent)
62622 - ntfs_error(sb, read_err_str, "backup");
62623 + ntfs_error(sb, read_err_str, "%s", "backup");
62624 /* We failed. Cleanup and return. */
62625 if (bh_primary)
62626 brelse(bh_primary);
62627 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
62628 index 0440134..d52c93a 100644
62629 --- a/fs/ocfs2/localalloc.c
62630 +++ b/fs/ocfs2/localalloc.c
62631 @@ -1320,7 +1320,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
62632 goto bail;
62633 }
62634
62635 - atomic_inc(&osb->alloc_stats.moves);
62636 + atomic_inc_unchecked(&osb->alloc_stats.moves);
62637
62638 bail:
62639 if (handle)
62640 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
62641 index 8d64a97..c37665d 100644
62642 --- a/fs/ocfs2/ocfs2.h
62643 +++ b/fs/ocfs2/ocfs2.h
62644 @@ -236,11 +236,11 @@ enum ocfs2_vol_state
62645
62646 struct ocfs2_alloc_stats
62647 {
62648 - atomic_t moves;
62649 - atomic_t local_data;
62650 - atomic_t bitmap_data;
62651 - atomic_t bg_allocs;
62652 - atomic_t bg_extends;
62653 + atomic_unchecked_t moves;
62654 + atomic_unchecked_t local_data;
62655 + atomic_unchecked_t bitmap_data;
62656 + atomic_unchecked_t bg_allocs;
62657 + atomic_unchecked_t bg_extends;
62658 };
62659
62660 enum ocfs2_local_alloc_state
62661 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
62662 index 0cb889a..6a26b24 100644
62663 --- a/fs/ocfs2/suballoc.c
62664 +++ b/fs/ocfs2/suballoc.c
62665 @@ -867,7 +867,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
62666 mlog_errno(status);
62667 goto bail;
62668 }
62669 - atomic_inc(&osb->alloc_stats.bg_extends);
62670 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
62671
62672 /* You should never ask for this much metadata */
62673 BUG_ON(bits_wanted >
62674 @@ -2014,7 +2014,7 @@ int ocfs2_claim_metadata(handle_t *handle,
62675 mlog_errno(status);
62676 goto bail;
62677 }
62678 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62679 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62680
62681 *suballoc_loc = res.sr_bg_blkno;
62682 *suballoc_bit_start = res.sr_bit_offset;
62683 @@ -2180,7 +2180,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
62684 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
62685 res->sr_bits);
62686
62687 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62688 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62689
62690 BUG_ON(res->sr_bits != 1);
62691
62692 @@ -2222,7 +2222,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
62693 mlog_errno(status);
62694 goto bail;
62695 }
62696 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62697 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
62698
62699 BUG_ON(res.sr_bits != 1);
62700
62701 @@ -2326,7 +2326,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
62702 cluster_start,
62703 num_clusters);
62704 if (!status)
62705 - atomic_inc(&osb->alloc_stats.local_data);
62706 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
62707 } else {
62708 if (min_clusters > (osb->bitmap_cpg - 1)) {
62709 /* The only paths asking for contiguousness
62710 @@ -2352,7 +2352,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
62711 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
62712 res.sr_bg_blkno,
62713 res.sr_bit_offset);
62714 - atomic_inc(&osb->alloc_stats.bitmap_data);
62715 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
62716 *num_clusters = res.sr_bits;
62717 }
62718 }
62719 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
62720 index a7cdd56..c583144 100644
62721 --- a/fs/ocfs2/super.c
62722 +++ b/fs/ocfs2/super.c
62723 @@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
62724 "%10s => GlobalAllocs: %d LocalAllocs: %d "
62725 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
62726 "Stats",
62727 - atomic_read(&osb->alloc_stats.bitmap_data),
62728 - atomic_read(&osb->alloc_stats.local_data),
62729 - atomic_read(&osb->alloc_stats.bg_allocs),
62730 - atomic_read(&osb->alloc_stats.moves),
62731 - atomic_read(&osb->alloc_stats.bg_extends));
62732 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
62733 + atomic_read_unchecked(&osb->alloc_stats.local_data),
62734 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
62735 + atomic_read_unchecked(&osb->alloc_stats.moves),
62736 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
62737
62738 out += snprintf(buf + out, len - out,
62739 "%10s => State: %u Descriptor: %llu Size: %u bits "
62740 @@ -2104,11 +2104,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
62741
62742 mutex_init(&osb->system_file_mutex);
62743
62744 - atomic_set(&osb->alloc_stats.moves, 0);
62745 - atomic_set(&osb->alloc_stats.local_data, 0);
62746 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
62747 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
62748 - atomic_set(&osb->alloc_stats.bg_extends, 0);
62749 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
62750 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
62751 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
62752 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
62753 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
62754
62755 /* Copy the blockcheck stats from the superblock probe */
62756 osb->osb_ecc_stats = *stats;
62757 diff --git a/fs/open.c b/fs/open.c
62758 index 9d64679..75f925c 100644
62759 --- a/fs/open.c
62760 +++ b/fs/open.c
62761 @@ -32,6 +32,8 @@
62762 #include <linux/dnotify.h>
62763 #include <linux/compat.h>
62764
62765 +#define CREATE_TRACE_POINTS
62766 +#include <trace/events/fs.h>
62767 #include "internal.h"
62768
62769 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
62770 @@ -103,6 +105,8 @@ long vfs_truncate(struct path *path, loff_t length)
62771 error = locks_verify_truncate(inode, NULL, length);
62772 if (!error)
62773 error = security_path_truncate(path);
62774 + if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
62775 + error = -EACCES;
62776 if (!error)
62777 error = do_truncate(path->dentry, length, 0, NULL);
62778
62779 @@ -187,6 +191,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
62780 error = locks_verify_truncate(inode, f.file, length);
62781 if (!error)
62782 error = security_path_truncate(&f.file->f_path);
62783 + if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
62784 + error = -EACCES;
62785 if (!error)
62786 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
62787 sb_end_write(inode->i_sb);
62788 @@ -381,6 +387,9 @@ retry:
62789 if (__mnt_is_readonly(path.mnt))
62790 res = -EROFS;
62791
62792 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
62793 + res = -EACCES;
62794 +
62795 out_path_release:
62796 path_put(&path);
62797 if (retry_estale(res, lookup_flags)) {
62798 @@ -412,6 +421,8 @@ retry:
62799 if (error)
62800 goto dput_and_out;
62801
62802 + gr_log_chdir(path.dentry, path.mnt);
62803 +
62804 set_fs_pwd(current->fs, &path);
62805
62806 dput_and_out:
62807 @@ -441,6 +452,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
62808 goto out_putf;
62809
62810 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
62811 +
62812 + if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
62813 + error = -EPERM;
62814 +
62815 + if (!error)
62816 + gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
62817 +
62818 if (!error)
62819 set_fs_pwd(current->fs, &f.file->f_path);
62820 out_putf:
62821 @@ -470,7 +488,13 @@ retry:
62822 if (error)
62823 goto dput_and_out;
62824
62825 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
62826 + goto dput_and_out;
62827 +
62828 set_fs_root(current->fs, &path);
62829 +
62830 + gr_handle_chroot_chdir(&path);
62831 +
62832 error = 0;
62833 dput_and_out:
62834 path_put(&path);
62835 @@ -494,6 +518,16 @@ static int chmod_common(struct path *path, umode_t mode)
62836 return error;
62837 retry_deleg:
62838 mutex_lock(&inode->i_mutex);
62839 +
62840 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
62841 + error = -EACCES;
62842 + goto out_unlock;
62843 + }
62844 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
62845 + error = -EACCES;
62846 + goto out_unlock;
62847 + }
62848 +
62849 error = security_path_chmod(path, mode);
62850 if (error)
62851 goto out_unlock;
62852 @@ -559,6 +593,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
62853 uid = make_kuid(current_user_ns(), user);
62854 gid = make_kgid(current_user_ns(), group);
62855
62856 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
62857 + return -EACCES;
62858 +
62859 newattrs.ia_valid = ATTR_CTIME;
62860 if (user != (uid_t) -1) {
62861 if (!uid_valid(uid))
62862 @@ -978,6 +1015,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
62863 } else {
62864 fsnotify_open(f);
62865 fd_install(fd, f);
62866 + trace_do_sys_open(tmp->name, flags, mode);
62867 }
62868 }
62869 putname(tmp);
62870 diff --git a/fs/pipe.c b/fs/pipe.c
62871 index 034bffa..6c6b522 100644
62872 --- a/fs/pipe.c
62873 +++ b/fs/pipe.c
62874 @@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
62875
62876 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
62877 {
62878 - if (pipe->files)
62879 + if (atomic_read(&pipe->files))
62880 mutex_lock_nested(&pipe->mutex, subclass);
62881 }
62882
62883 @@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
62884
62885 void pipe_unlock(struct pipe_inode_info *pipe)
62886 {
62887 - if (pipe->files)
62888 + if (atomic_read(&pipe->files))
62889 mutex_unlock(&pipe->mutex);
62890 }
62891 EXPORT_SYMBOL(pipe_unlock);
62892 @@ -342,9 +342,9 @@ pipe_read(struct kiocb *iocb, const struct iovec *_iov,
62893 }
62894 if (bufs) /* More to do? */
62895 continue;
62896 - if (!pipe->writers)
62897 + if (!atomic_read(&pipe->writers))
62898 break;
62899 - if (!pipe->waiting_writers) {
62900 + if (!atomic_read(&pipe->waiting_writers)) {
62901 /* syscall merging: Usually we must not sleep
62902 * if O_NONBLOCK is set, or if we got some data.
62903 * But if a writer sleeps in kernel space, then
62904 @@ -406,7 +406,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
62905 ret = 0;
62906 __pipe_lock(pipe);
62907
62908 - if (!pipe->readers) {
62909 + if (!atomic_read(&pipe->readers)) {
62910 send_sig(SIGPIPE, current, 0);
62911 ret = -EPIPE;
62912 goto out;
62913 @@ -461,7 +461,7 @@ redo1:
62914 for (;;) {
62915 int bufs;
62916
62917 - if (!pipe->readers) {
62918 + if (!atomic_read(&pipe->readers)) {
62919 send_sig(SIGPIPE, current, 0);
62920 if (!ret)
62921 ret = -EPIPE;
62922 @@ -552,9 +552,9 @@ redo2:
62923 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
62924 do_wakeup = 0;
62925 }
62926 - pipe->waiting_writers++;
62927 + atomic_inc(&pipe->waiting_writers);
62928 pipe_wait(pipe);
62929 - pipe->waiting_writers--;
62930 + atomic_dec(&pipe->waiting_writers);
62931 }
62932 out:
62933 __pipe_unlock(pipe);
62934 @@ -609,7 +609,7 @@ pipe_poll(struct file *filp, poll_table *wait)
62935 mask = 0;
62936 if (filp->f_mode & FMODE_READ) {
62937 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
62938 - if (!pipe->writers && filp->f_version != pipe->w_counter)
62939 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
62940 mask |= POLLHUP;
62941 }
62942
62943 @@ -619,7 +619,7 @@ pipe_poll(struct file *filp, poll_table *wait)
62944 * Most Unices do not set POLLERR for FIFOs but on Linux they
62945 * behave exactly like pipes for poll().
62946 */
62947 - if (!pipe->readers)
62948 + if (!atomic_read(&pipe->readers))
62949 mask |= POLLERR;
62950 }
62951
62952 @@ -631,7 +631,7 @@ static void put_pipe_info(struct inode *inode, struct pipe_inode_info *pipe)
62953 int kill = 0;
62954
62955 spin_lock(&inode->i_lock);
62956 - if (!--pipe->files) {
62957 + if (atomic_dec_and_test(&pipe->files)) {
62958 inode->i_pipe = NULL;
62959 kill = 1;
62960 }
62961 @@ -648,11 +648,11 @@ pipe_release(struct inode *inode, struct file *file)
62962
62963 __pipe_lock(pipe);
62964 if (file->f_mode & FMODE_READ)
62965 - pipe->readers--;
62966 + atomic_dec(&pipe->readers);
62967 if (file->f_mode & FMODE_WRITE)
62968 - pipe->writers--;
62969 + atomic_dec(&pipe->writers);
62970
62971 - if (pipe->readers || pipe->writers) {
62972 + if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
62973 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
62974 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
62975 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
62976 @@ -717,7 +717,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
62977 kfree(pipe);
62978 }
62979
62980 -static struct vfsmount *pipe_mnt __read_mostly;
62981 +struct vfsmount *pipe_mnt __read_mostly;
62982
62983 /*
62984 * pipefs_dname() is called from d_path().
62985 @@ -747,8 +747,9 @@ static struct inode * get_pipe_inode(void)
62986 goto fail_iput;
62987
62988 inode->i_pipe = pipe;
62989 - pipe->files = 2;
62990 - pipe->readers = pipe->writers = 1;
62991 + atomic_set(&pipe->files, 2);
62992 + atomic_set(&pipe->readers, 1);
62993 + atomic_set(&pipe->writers, 1);
62994 inode->i_fop = &pipefifo_fops;
62995
62996 /*
62997 @@ -927,17 +928,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
62998 spin_lock(&inode->i_lock);
62999 if (inode->i_pipe) {
63000 pipe = inode->i_pipe;
63001 - pipe->files++;
63002 + atomic_inc(&pipe->files);
63003 spin_unlock(&inode->i_lock);
63004 } else {
63005 spin_unlock(&inode->i_lock);
63006 pipe = alloc_pipe_info();
63007 if (!pipe)
63008 return -ENOMEM;
63009 - pipe->files = 1;
63010 + atomic_set(&pipe->files, 1);
63011 spin_lock(&inode->i_lock);
63012 if (unlikely(inode->i_pipe)) {
63013 - inode->i_pipe->files++;
63014 + atomic_inc(&inode->i_pipe->files);
63015 spin_unlock(&inode->i_lock);
63016 free_pipe_info(pipe);
63017 pipe = inode->i_pipe;
63018 @@ -962,10 +963,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
63019 * opened, even when there is no process writing the FIFO.
63020 */
63021 pipe->r_counter++;
63022 - if (pipe->readers++ == 0)
63023 + if (atomic_inc_return(&pipe->readers) == 1)
63024 wake_up_partner(pipe);
63025
63026 - if (!is_pipe && !pipe->writers) {
63027 + if (!is_pipe && !atomic_read(&pipe->writers)) {
63028 if ((filp->f_flags & O_NONBLOCK)) {
63029 /* suppress POLLHUP until we have
63030 * seen a writer */
63031 @@ -984,14 +985,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
63032 * errno=ENXIO when there is no process reading the FIFO.
63033 */
63034 ret = -ENXIO;
63035 - if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
63036 + if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
63037 goto err;
63038
63039 pipe->w_counter++;
63040 - if (!pipe->writers++)
63041 + if (atomic_inc_return(&pipe->writers) == 1)
63042 wake_up_partner(pipe);
63043
63044 - if (!is_pipe && !pipe->readers) {
63045 + if (!is_pipe && !atomic_read(&pipe->readers)) {
63046 if (wait_for_partner(pipe, &pipe->r_counter))
63047 goto err_wr;
63048 }
63049 @@ -1005,11 +1006,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
63050 * the process can at least talk to itself.
63051 */
63052
63053 - pipe->readers++;
63054 - pipe->writers++;
63055 + atomic_inc(&pipe->readers);
63056 + atomic_inc(&pipe->writers);
63057 pipe->r_counter++;
63058 pipe->w_counter++;
63059 - if (pipe->readers == 1 || pipe->writers == 1)
63060 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
63061 wake_up_partner(pipe);
63062 break;
63063
63064 @@ -1023,13 +1024,13 @@ static int fifo_open(struct inode *inode, struct file *filp)
63065 return 0;
63066
63067 err_rd:
63068 - if (!--pipe->readers)
63069 + if (atomic_dec_and_test(&pipe->readers))
63070 wake_up_interruptible(&pipe->wait);
63071 ret = -ERESTARTSYS;
63072 goto err;
63073
63074 err_wr:
63075 - if (!--pipe->writers)
63076 + if (atomic_dec_and_test(&pipe->writers))
63077 wake_up_interruptible(&pipe->wait);
63078 ret = -ERESTARTSYS;
63079 goto err;
63080 diff --git a/fs/posix_acl.c b/fs/posix_acl.c
63081 index 0855f77..6787d50 100644
63082 --- a/fs/posix_acl.c
63083 +++ b/fs/posix_acl.c
63084 @@ -20,6 +20,7 @@
63085 #include <linux/xattr.h>
63086 #include <linux/export.h>
63087 #include <linux/user_namespace.h>
63088 +#include <linux/grsecurity.h>
63089
63090 struct posix_acl **acl_by_type(struct inode *inode, int type)
63091 {
63092 @@ -277,7 +278,7 @@ posix_acl_equiv_mode(const struct posix_acl *acl, umode_t *mode_p)
63093 }
63094 }
63095 if (mode_p)
63096 - *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
63097 + *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
63098 return not_equiv;
63099 }
63100 EXPORT_SYMBOL(posix_acl_equiv_mode);
63101 @@ -427,7 +428,7 @@ static int posix_acl_create_masq(struct posix_acl *acl, umode_t *mode_p)
63102 mode &= (group_obj->e_perm << 3) | ~S_IRWXG;
63103 }
63104
63105 - *mode_p = (*mode_p & ~S_IRWXUGO) | mode;
63106 + *mode_p = ((*mode_p & ~S_IRWXUGO) | mode) & ~gr_acl_umask();
63107 return not_equiv;
63108 }
63109
63110 @@ -485,6 +486,8 @@ __posix_acl_create(struct posix_acl **acl, gfp_t gfp, umode_t *mode_p)
63111 struct posix_acl *clone = posix_acl_clone(*acl, gfp);
63112 int err = -ENOMEM;
63113 if (clone) {
63114 + *mode_p &= ~gr_acl_umask();
63115 +
63116 err = posix_acl_create_masq(clone, mode_p);
63117 if (err < 0) {
63118 posix_acl_release(clone);
63119 @@ -659,11 +662,12 @@ struct posix_acl *
63120 posix_acl_from_xattr(struct user_namespace *user_ns,
63121 const void *value, size_t size)
63122 {
63123 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
63124 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
63125 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
63126 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
63127 int count;
63128 struct posix_acl *acl;
63129 struct posix_acl_entry *acl_e;
63130 + umode_t umask = gr_acl_umask();
63131
63132 if (!value)
63133 return NULL;
63134 @@ -689,12 +693,18 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
63135
63136 switch(acl_e->e_tag) {
63137 case ACL_USER_OBJ:
63138 + acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
63139 + break;
63140 case ACL_GROUP_OBJ:
63141 case ACL_MASK:
63142 + acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
63143 + break;
63144 case ACL_OTHER:
63145 + acl_e->e_perm &= ~(umask & S_IRWXO);
63146 break;
63147
63148 case ACL_USER:
63149 + acl_e->e_perm &= ~((umask & S_IRWXU) >> 6);
63150 acl_e->e_uid =
63151 make_kuid(user_ns,
63152 le32_to_cpu(entry->e_id));
63153 @@ -702,6 +712,7 @@ posix_acl_from_xattr(struct user_namespace *user_ns,
63154 goto fail;
63155 break;
63156 case ACL_GROUP:
63157 + acl_e->e_perm &= ~((umask & S_IRWXG) >> 3);
63158 acl_e->e_gid =
63159 make_kgid(user_ns,
63160 le32_to_cpu(entry->e_id));
63161 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
63162 index 2183fcf..3c32a98 100644
63163 --- a/fs/proc/Kconfig
63164 +++ b/fs/proc/Kconfig
63165 @@ -30,7 +30,7 @@ config PROC_FS
63166
63167 config PROC_KCORE
63168 bool "/proc/kcore support" if !ARM
63169 - depends on PROC_FS && MMU
63170 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
63171 help
63172 Provides a virtual ELF core file of the live kernel. This can
63173 be read with gdb and other ELF tools. No modifications can be
63174 @@ -38,8 +38,8 @@ config PROC_KCORE
63175
63176 config PROC_VMCORE
63177 bool "/proc/vmcore support"
63178 - depends on PROC_FS && CRASH_DUMP
63179 - default y
63180 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
63181 + default n
63182 help
63183 Exports the dump image of crashed kernel in ELF format.
63184
63185 @@ -63,8 +63,8 @@ config PROC_SYSCTL
63186 limited in memory.
63187
63188 config PROC_PAGE_MONITOR
63189 - default y
63190 - depends on PROC_FS && MMU
63191 + default n
63192 + depends on PROC_FS && MMU && !GRKERNSEC
63193 bool "Enable /proc page monitoring" if EXPERT
63194 help
63195 Various /proc files exist to monitor process memory utilization:
63196 diff --git a/fs/proc/array.c b/fs/proc/array.c
63197 index 64db2bc..a8185d6 100644
63198 --- a/fs/proc/array.c
63199 +++ b/fs/proc/array.c
63200 @@ -60,6 +60,7 @@
63201 #include <linux/tty.h>
63202 #include <linux/string.h>
63203 #include <linux/mman.h>
63204 +#include <linux/grsecurity.h>
63205 #include <linux/proc_fs.h>
63206 #include <linux/ioport.h>
63207 #include <linux/uaccess.h>
63208 @@ -356,6 +357,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
63209 seq_putc(m, '\n');
63210 }
63211
63212 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63213 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
63214 +{
63215 + if (p->mm)
63216 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
63217 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
63218 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
63219 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
63220 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
63221 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
63222 + else
63223 + seq_printf(m, "PaX:\t-----\n");
63224 +}
63225 +#endif
63226 +
63227 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
63228 struct pid *pid, struct task_struct *task)
63229 {
63230 @@ -374,9 +390,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
63231 task_cpus_allowed(m, task);
63232 cpuset_task_status_allowed(m, task);
63233 task_context_switch_counts(m, task);
63234 +
63235 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63236 + task_pax(m, task);
63237 +#endif
63238 +
63239 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
63240 + task_grsec_rbac(m, task);
63241 +#endif
63242 +
63243 return 0;
63244 }
63245
63246 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63247 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
63248 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
63249 + _mm->pax_flags & MF_PAX_SEGMEXEC))
63250 +#endif
63251 +
63252 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63253 struct pid *pid, struct task_struct *task, int whole)
63254 {
63255 @@ -398,6 +429,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63256 char tcomm[sizeof(task->comm)];
63257 unsigned long flags;
63258
63259 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63260 + if (current->exec_id != m->exec_id) {
63261 + gr_log_badprocpid("stat");
63262 + return 0;
63263 + }
63264 +#endif
63265 +
63266 state = *get_task_state(task);
63267 vsize = eip = esp = 0;
63268 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
63269 @@ -468,6 +506,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63270 gtime = task_gtime(task);
63271 }
63272
63273 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63274 + if (PAX_RAND_FLAGS(mm)) {
63275 + eip = 0;
63276 + esp = 0;
63277 + wchan = 0;
63278 + }
63279 +#endif
63280 +#ifdef CONFIG_GRKERNSEC_HIDESYM
63281 + wchan = 0;
63282 + eip =0;
63283 + esp =0;
63284 +#endif
63285 +
63286 /* scale priority and nice values from timeslices to -20..20 */
63287 /* to make it look like a "normal" Unix priority/nice value */
63288 priority = task_prio(task);
63289 @@ -504,9 +555,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63290 seq_put_decimal_ull(m, ' ', vsize);
63291 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
63292 seq_put_decimal_ull(m, ' ', rsslim);
63293 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63294 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
63295 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
63296 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
63297 +#else
63298 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
63299 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
63300 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
63301 +#endif
63302 seq_put_decimal_ull(m, ' ', esp);
63303 seq_put_decimal_ull(m, ' ', eip);
63304 /* The signal information here is obsolete.
63305 @@ -528,7 +585,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
63306 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
63307 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
63308
63309 - if (mm && permitted) {
63310 + if (mm && permitted
63311 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63312 + && !PAX_RAND_FLAGS(mm)
63313 +#endif
63314 + ) {
63315 seq_put_decimal_ull(m, ' ', mm->start_data);
63316 seq_put_decimal_ull(m, ' ', mm->end_data);
63317 seq_put_decimal_ull(m, ' ', mm->start_brk);
63318 @@ -566,8 +627,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
63319 struct pid *pid, struct task_struct *task)
63320 {
63321 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
63322 - struct mm_struct *mm = get_task_mm(task);
63323 + struct mm_struct *mm;
63324
63325 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63326 + if (current->exec_id != m->exec_id) {
63327 + gr_log_badprocpid("statm");
63328 + return 0;
63329 + }
63330 +#endif
63331 + mm = get_task_mm(task);
63332 if (mm) {
63333 size = task_statm(mm, &shared, &text, &data, &resident);
63334 mmput(mm);
63335 @@ -590,6 +658,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
63336 return 0;
63337 }
63338
63339 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63340 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
63341 +{
63342 + return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
63343 +}
63344 +#endif
63345 +
63346 #ifdef CONFIG_CHECKPOINT_RESTORE
63347 static struct pid *
63348 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
63349 diff --git a/fs/proc/base.c b/fs/proc/base.c
63350 index 2d696b0..b9da447 100644
63351 --- a/fs/proc/base.c
63352 +++ b/fs/proc/base.c
63353 @@ -113,6 +113,14 @@ struct pid_entry {
63354 union proc_op op;
63355 };
63356
63357 +struct getdents_callback {
63358 + struct linux_dirent __user * current_dir;
63359 + struct linux_dirent __user * previous;
63360 + struct file * file;
63361 + int count;
63362 + int error;
63363 +};
63364 +
63365 #define NOD(NAME, MODE, IOP, FOP, OP) { \
63366 .name = (NAME), \
63367 .len = sizeof(NAME) - 1, \
63368 @@ -205,12 +213,28 @@ static int proc_pid_cmdline(struct task_struct *task, char *buffer)
63369 return get_cmdline(task, buffer, PAGE_SIZE);
63370 }
63371
63372 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63373 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
63374 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
63375 + _mm->pax_flags & MF_PAX_SEGMEXEC))
63376 +#endif
63377 +
63378 static int proc_pid_auxv(struct task_struct *task, char *buffer)
63379 {
63380 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
63381 int res = PTR_ERR(mm);
63382 if (mm && !IS_ERR(mm)) {
63383 unsigned int nwords = 0;
63384 +
63385 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63386 + /* allow if we're currently ptracing this task */
63387 + if (PAX_RAND_FLAGS(mm) &&
63388 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
63389 + mmput(mm);
63390 + return 0;
63391 + }
63392 +#endif
63393 +
63394 do {
63395 nwords += 2;
63396 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
63397 @@ -224,7 +248,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
63398 }
63399
63400
63401 -#ifdef CONFIG_KALLSYMS
63402 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63403 /*
63404 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
63405 * Returns the resolved symbol. If that fails, simply return the address.
63406 @@ -263,7 +287,7 @@ static void unlock_trace(struct task_struct *task)
63407 mutex_unlock(&task->signal->cred_guard_mutex);
63408 }
63409
63410 -#ifdef CONFIG_STACKTRACE
63411 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63412
63413 #define MAX_STACK_TRACE_DEPTH 64
63414
63415 @@ -486,7 +510,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
63416 return count;
63417 }
63418
63419 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63420 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63421 static int proc_pid_syscall(struct task_struct *task, char *buffer)
63422 {
63423 long nr;
63424 @@ -515,7 +539,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
63425 /************************************************************************/
63426
63427 /* permission checks */
63428 -static int proc_fd_access_allowed(struct inode *inode)
63429 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
63430 {
63431 struct task_struct *task;
63432 int allowed = 0;
63433 @@ -525,7 +549,10 @@ static int proc_fd_access_allowed(struct inode *inode)
63434 */
63435 task = get_proc_task(inode);
63436 if (task) {
63437 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
63438 + if (log)
63439 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
63440 + else
63441 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
63442 put_task_struct(task);
63443 }
63444 return allowed;
63445 @@ -556,10 +583,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
63446 struct task_struct *task,
63447 int hide_pid_min)
63448 {
63449 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63450 + return false;
63451 +
63452 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63453 + rcu_read_lock();
63454 + {
63455 + const struct cred *tmpcred = current_cred();
63456 + const struct cred *cred = __task_cred(task);
63457 +
63458 + if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
63459 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63460 + || in_group_p(grsec_proc_gid)
63461 +#endif
63462 + ) {
63463 + rcu_read_unlock();
63464 + return true;
63465 + }
63466 + }
63467 + rcu_read_unlock();
63468 +
63469 + if (!pid->hide_pid)
63470 + return false;
63471 +#endif
63472 +
63473 if (pid->hide_pid < hide_pid_min)
63474 return true;
63475 if (in_group_p(pid->pid_gid))
63476 return true;
63477 +
63478 return ptrace_may_access(task, PTRACE_MODE_READ);
63479 }
63480
63481 @@ -577,7 +629,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
63482 put_task_struct(task);
63483
63484 if (!has_perms) {
63485 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63486 + {
63487 +#else
63488 if (pid->hide_pid == 2) {
63489 +#endif
63490 /*
63491 * Let's make getdents(), stat(), and open()
63492 * consistent with each other. If a process
63493 @@ -675,6 +731,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
63494 if (!task)
63495 return -ESRCH;
63496
63497 + if (gr_acl_handle_procpidmem(task)) {
63498 + put_task_struct(task);
63499 + return -EPERM;
63500 + }
63501 +
63502 mm = mm_access(task, mode);
63503 put_task_struct(task);
63504
63505 @@ -690,6 +751,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
63506
63507 file->private_data = mm;
63508
63509 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63510 + file->f_version = current->exec_id;
63511 +#endif
63512 +
63513 return 0;
63514 }
63515
63516 @@ -711,6 +776,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
63517 ssize_t copied;
63518 char *page;
63519
63520 +#ifdef CONFIG_GRKERNSEC
63521 + if (write)
63522 + return -EPERM;
63523 +#endif
63524 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63525 + if (file->f_version != current->exec_id) {
63526 + gr_log_badprocpid("mem");
63527 + return 0;
63528 + }
63529 +#endif
63530 +
63531 if (!mm)
63532 return 0;
63533
63534 @@ -723,7 +799,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
63535 goto free;
63536
63537 while (count > 0) {
63538 - int this_len = min_t(int, count, PAGE_SIZE);
63539 + ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
63540
63541 if (write && copy_from_user(page, buf, this_len)) {
63542 copied = -EFAULT;
63543 @@ -815,6 +891,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
63544 if (!mm)
63545 return 0;
63546
63547 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63548 + if (file->f_version != current->exec_id) {
63549 + gr_log_badprocpid("environ");
63550 + return 0;
63551 + }
63552 +#endif
63553 +
63554 page = (char *)__get_free_page(GFP_TEMPORARY);
63555 if (!page)
63556 return -ENOMEM;
63557 @@ -824,7 +907,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
63558 goto free;
63559 while (count > 0) {
63560 size_t this_len, max_len;
63561 - int retval;
63562 + ssize_t retval;
63563
63564 if (src >= (mm->env_end - mm->env_start))
63565 break;
63566 @@ -1438,7 +1521,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
63567 int error = -EACCES;
63568
63569 /* Are we allowed to snoop on the tasks file descriptors? */
63570 - if (!proc_fd_access_allowed(inode))
63571 + if (!proc_fd_access_allowed(inode, 0))
63572 goto out;
63573
63574 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
63575 @@ -1482,8 +1565,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
63576 struct path path;
63577
63578 /* Are we allowed to snoop on the tasks file descriptors? */
63579 - if (!proc_fd_access_allowed(inode))
63580 - goto out;
63581 + /* logging this is needed for learning on chromium to work properly,
63582 + but we don't want to flood the logs from 'ps' which does a readlink
63583 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
63584 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
63585 + */
63586 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
63587 + if (!proc_fd_access_allowed(inode,0))
63588 + goto out;
63589 + } else {
63590 + if (!proc_fd_access_allowed(inode,1))
63591 + goto out;
63592 + }
63593
63594 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
63595 if (error)
63596 @@ -1533,7 +1626,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
63597 rcu_read_lock();
63598 cred = __task_cred(task);
63599 inode->i_uid = cred->euid;
63600 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63601 + inode->i_gid = grsec_proc_gid;
63602 +#else
63603 inode->i_gid = cred->egid;
63604 +#endif
63605 rcu_read_unlock();
63606 }
63607 security_task_to_inode(task, inode);
63608 @@ -1569,10 +1666,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
63609 return -ENOENT;
63610 }
63611 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
63612 +#ifdef CONFIG_GRKERNSEC_PROC_USER
63613 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
63614 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63615 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
63616 +#endif
63617 task_dumpable(task)) {
63618 cred = __task_cred(task);
63619 stat->uid = cred->euid;
63620 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63621 + stat->gid = grsec_proc_gid;
63622 +#else
63623 stat->gid = cred->egid;
63624 +#endif
63625 }
63626 }
63627 rcu_read_unlock();
63628 @@ -1610,11 +1716,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
63629
63630 if (task) {
63631 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
63632 +#ifdef CONFIG_GRKERNSEC_PROC_USER
63633 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
63634 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63635 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
63636 +#endif
63637 task_dumpable(task)) {
63638 rcu_read_lock();
63639 cred = __task_cred(task);
63640 inode->i_uid = cred->euid;
63641 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63642 + inode->i_gid = grsec_proc_gid;
63643 +#else
63644 inode->i_gid = cred->egid;
63645 +#endif
63646 rcu_read_unlock();
63647 } else {
63648 inode->i_uid = GLOBAL_ROOT_UID;
63649 @@ -2149,6 +2264,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
63650 if (!task)
63651 goto out_no_task;
63652
63653 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63654 + goto out;
63655 +
63656 /*
63657 * Yes, it does not scale. And it should not. Don't add
63658 * new entries into /proc/<tgid>/ without very good reasons.
63659 @@ -2179,6 +2297,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
63660 if (!task)
63661 return -ENOENT;
63662
63663 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63664 + goto out;
63665 +
63666 if (!dir_emit_dots(file, ctx))
63667 goto out;
63668
63669 @@ -2568,7 +2689,7 @@ static const struct pid_entry tgid_base_stuff[] = {
63670 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
63671 #endif
63672 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
63673 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63674 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63675 INF("syscall", S_IRUSR, proc_pid_syscall),
63676 #endif
63677 INF("cmdline", S_IRUGO, proc_pid_cmdline),
63678 @@ -2593,10 +2714,10 @@ static const struct pid_entry tgid_base_stuff[] = {
63679 #ifdef CONFIG_SECURITY
63680 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
63681 #endif
63682 -#ifdef CONFIG_KALLSYMS
63683 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63684 INF("wchan", S_IRUGO, proc_pid_wchan),
63685 #endif
63686 -#ifdef CONFIG_STACKTRACE
63687 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63688 ONE("stack", S_IRUSR, proc_pid_stack),
63689 #endif
63690 #ifdef CONFIG_SCHEDSTATS
63691 @@ -2630,6 +2751,9 @@ static const struct pid_entry tgid_base_stuff[] = {
63692 #ifdef CONFIG_HARDWALL
63693 INF("hardwall", S_IRUGO, proc_pid_hardwall),
63694 #endif
63695 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
63696 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
63697 +#endif
63698 #ifdef CONFIG_USER_NS
63699 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
63700 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
63701 @@ -2760,7 +2884,14 @@ static int proc_pid_instantiate(struct inode *dir,
63702 if (!inode)
63703 goto out;
63704
63705 +#ifdef CONFIG_GRKERNSEC_PROC_USER
63706 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
63707 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63708 + inode->i_gid = grsec_proc_gid;
63709 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
63710 +#else
63711 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
63712 +#endif
63713 inode->i_op = &proc_tgid_base_inode_operations;
63714 inode->i_fop = &proc_tgid_base_operations;
63715 inode->i_flags|=S_IMMUTABLE;
63716 @@ -2798,7 +2929,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
63717 if (!task)
63718 goto out;
63719
63720 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
63721 + goto out_put_task;
63722 +
63723 result = proc_pid_instantiate(dir, dentry, task, NULL);
63724 +out_put_task:
63725 put_task_struct(task);
63726 out:
63727 return ERR_PTR(result);
63728 @@ -2904,7 +3039,7 @@ static const struct pid_entry tid_base_stuff[] = {
63729 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
63730 #endif
63731 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
63732 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
63733 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
63734 INF("syscall", S_IRUSR, proc_pid_syscall),
63735 #endif
63736 INF("cmdline", S_IRUGO, proc_pid_cmdline),
63737 @@ -2931,10 +3066,10 @@ static const struct pid_entry tid_base_stuff[] = {
63738 #ifdef CONFIG_SECURITY
63739 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
63740 #endif
63741 -#ifdef CONFIG_KALLSYMS
63742 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63743 INF("wchan", S_IRUGO, proc_pid_wchan),
63744 #endif
63745 -#ifdef CONFIG_STACKTRACE
63746 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63747 ONE("stack", S_IRUSR, proc_pid_stack),
63748 #endif
63749 #ifdef CONFIG_SCHEDSTATS
63750 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
63751 index cbd82df..c0407d2 100644
63752 --- a/fs/proc/cmdline.c
63753 +++ b/fs/proc/cmdline.c
63754 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
63755
63756 static int __init proc_cmdline_init(void)
63757 {
63758 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
63759 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
63760 +#else
63761 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
63762 +#endif
63763 return 0;
63764 }
63765 fs_initcall(proc_cmdline_init);
63766 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
63767 index 50493ed..248166b 100644
63768 --- a/fs/proc/devices.c
63769 +++ b/fs/proc/devices.c
63770 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
63771
63772 static int __init proc_devices_init(void)
63773 {
63774 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
63775 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
63776 +#else
63777 proc_create("devices", 0, NULL, &proc_devinfo_operations);
63778 +#endif
63779 return 0;
63780 }
63781 fs_initcall(proc_devices_init);
63782 diff --git a/fs/proc/fd.c b/fs/proc/fd.c
63783 index 0788d09..9cc1385 100644
63784 --- a/fs/proc/fd.c
63785 +++ b/fs/proc/fd.c
63786 @@ -26,7 +26,8 @@ static int seq_show(struct seq_file *m, void *v)
63787 if (!task)
63788 return -ENOENT;
63789
63790 - files = get_files_struct(task);
63791 + if (!gr_acl_handle_procpidmem(task))
63792 + files = get_files_struct(task);
63793 put_task_struct(task);
63794
63795 if (files) {
63796 @@ -285,11 +286,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
63797 */
63798 int proc_fd_permission(struct inode *inode, int mask)
63799 {
63800 + struct task_struct *task;
63801 int rv = generic_permission(inode, mask);
63802 - if (rv == 0)
63803 - return 0;
63804 +
63805 if (task_tgid(current) == proc_pid(inode))
63806 rv = 0;
63807 +
63808 + task = get_proc_task(inode);
63809 + if (task == NULL)
63810 + return rv;
63811 +
63812 + if (gr_acl_handle_procpidmem(task))
63813 + rv = -EACCES;
63814 +
63815 + put_task_struct(task);
63816 +
63817 return rv;
63818 }
63819
63820 diff --git a/fs/proc/generic.c b/fs/proc/generic.c
63821 index b7f268e..3bea6b7 100644
63822 --- a/fs/proc/generic.c
63823 +++ b/fs/proc/generic.c
63824 @@ -23,6 +23,7 @@
63825 #include <linux/bitops.h>
63826 #include <linux/spinlock.h>
63827 #include <linux/completion.h>
63828 +#include <linux/grsecurity.h>
63829 #include <asm/uaccess.h>
63830
63831 #include "internal.h"
63832 @@ -207,6 +208,15 @@ struct dentry *proc_lookup(struct inode *dir, struct dentry *dentry,
63833 return proc_lookup_de(PDE(dir), dir, dentry);
63834 }
63835
63836 +struct dentry *proc_lookup_restrict(struct inode *dir, struct dentry *dentry,
63837 + unsigned int flags)
63838 +{
63839 + if (gr_proc_is_restricted())
63840 + return ERR_PTR(-EACCES);
63841 +
63842 + return proc_lookup_de(PDE(dir), dir, dentry);
63843 +}
63844 +
63845 /*
63846 * This returns non-zero if at EOF, so that the /proc
63847 * root directory can use this and check if it should
63848 @@ -264,6 +274,16 @@ int proc_readdir(struct file *file, struct dir_context *ctx)
63849 return proc_readdir_de(PDE(inode), file, ctx);
63850 }
63851
63852 +int proc_readdir_restrict(struct file *file, struct dir_context *ctx)
63853 +{
63854 + struct inode *inode = file_inode(file);
63855 +
63856 + if (gr_proc_is_restricted())
63857 + return -EACCES;
63858 +
63859 + return proc_readdir_de(PDE(inode), file, ctx);
63860 +}
63861 +
63862 /*
63863 * These are the generic /proc directory operations. They
63864 * use the in-memory "struct proc_dir_entry" tree to parse
63865 @@ -275,6 +295,12 @@ static const struct file_operations proc_dir_operations = {
63866 .iterate = proc_readdir,
63867 };
63868
63869 +static const struct file_operations proc_dir_restricted_operations = {
63870 + .llseek = generic_file_llseek,
63871 + .read = generic_read_dir,
63872 + .iterate = proc_readdir_restrict,
63873 +};
63874 +
63875 /*
63876 * proc directories can do almost nothing..
63877 */
63878 @@ -284,6 +310,12 @@ static const struct inode_operations proc_dir_inode_operations = {
63879 .setattr = proc_notify_change,
63880 };
63881
63882 +static const struct inode_operations proc_dir_restricted_inode_operations = {
63883 + .lookup = proc_lookup_restrict,
63884 + .getattr = proc_getattr,
63885 + .setattr = proc_notify_change,
63886 +};
63887 +
63888 static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp)
63889 {
63890 struct proc_dir_entry *tmp;
63891 @@ -294,8 +326,13 @@ static int proc_register(struct proc_dir_entry * dir, struct proc_dir_entry * dp
63892 return ret;
63893
63894 if (S_ISDIR(dp->mode)) {
63895 - dp->proc_fops = &proc_dir_operations;
63896 - dp->proc_iops = &proc_dir_inode_operations;
63897 + if (dp->restricted) {
63898 + dp->proc_fops = &proc_dir_restricted_operations;
63899 + dp->proc_iops = &proc_dir_restricted_inode_operations;
63900 + } else {
63901 + dp->proc_fops = &proc_dir_operations;
63902 + dp->proc_iops = &proc_dir_inode_operations;
63903 + }
63904 dir->nlink++;
63905 } else if (S_ISLNK(dp->mode)) {
63906 dp->proc_iops = &proc_link_inode_operations;
63907 @@ -407,6 +444,27 @@ struct proc_dir_entry *proc_mkdir_data(const char *name, umode_t mode,
63908 }
63909 EXPORT_SYMBOL_GPL(proc_mkdir_data);
63910
63911 +struct proc_dir_entry *proc_mkdir_data_restrict(const char *name, umode_t mode,
63912 + struct proc_dir_entry *parent, void *data)
63913 +{
63914 + struct proc_dir_entry *ent;
63915 +
63916 + if (mode == 0)
63917 + mode = S_IRUGO | S_IXUGO;
63918 +
63919 + ent = __proc_create(&parent, name, S_IFDIR | mode, 2);
63920 + if (ent) {
63921 + ent->data = data;
63922 + ent->restricted = 1;
63923 + if (proc_register(parent, ent) < 0) {
63924 + kfree(ent);
63925 + ent = NULL;
63926 + }
63927 + }
63928 + return ent;
63929 +}
63930 +EXPORT_SYMBOL_GPL(proc_mkdir_data_restrict);
63931 +
63932 struct proc_dir_entry *proc_mkdir_mode(const char *name, umode_t mode,
63933 struct proc_dir_entry *parent)
63934 {
63935 @@ -421,6 +479,13 @@ struct proc_dir_entry *proc_mkdir(const char *name,
63936 }
63937 EXPORT_SYMBOL(proc_mkdir);
63938
63939 +struct proc_dir_entry *proc_mkdir_restrict(const char *name,
63940 + struct proc_dir_entry *parent)
63941 +{
63942 + return proc_mkdir_data_restrict(name, 0, parent, NULL);
63943 +}
63944 +EXPORT_SYMBOL(proc_mkdir_restrict);
63945 +
63946 struct proc_dir_entry *proc_create_data(const char *name, umode_t mode,
63947 struct proc_dir_entry *parent,
63948 const struct file_operations *proc_fops,
63949 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
63950 index 0adbc02..bee4d0b 100644
63951 --- a/fs/proc/inode.c
63952 +++ b/fs/proc/inode.c
63953 @@ -23,11 +23,17 @@
63954 #include <linux/slab.h>
63955 #include <linux/mount.h>
63956 #include <linux/magic.h>
63957 +#include <linux/grsecurity.h>
63958
63959 #include <asm/uaccess.h>
63960
63961 #include "internal.h"
63962
63963 +#ifdef CONFIG_PROC_SYSCTL
63964 +extern const struct inode_operations proc_sys_inode_operations;
63965 +extern const struct inode_operations proc_sys_dir_operations;
63966 +#endif
63967 +
63968 static void proc_evict_inode(struct inode *inode)
63969 {
63970 struct proc_dir_entry *de;
63971 @@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
63972 ns = PROC_I(inode)->ns.ns;
63973 if (ns_ops && ns)
63974 ns_ops->put(ns);
63975 +
63976 +#ifdef CONFIG_PROC_SYSCTL
63977 + if (inode->i_op == &proc_sys_inode_operations ||
63978 + inode->i_op == &proc_sys_dir_operations)
63979 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
63980 +#endif
63981 +
63982 }
63983
63984 static struct kmem_cache * proc_inode_cachep;
63985 @@ -413,7 +426,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
63986 if (de->mode) {
63987 inode->i_mode = de->mode;
63988 inode->i_uid = de->uid;
63989 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
63990 + inode->i_gid = grsec_proc_gid;
63991 +#else
63992 inode->i_gid = de->gid;
63993 +#endif
63994 }
63995 if (de->size)
63996 inode->i_size = de->size;
63997 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
63998 index 3ab6d14..b26174e 100644
63999 --- a/fs/proc/internal.h
64000 +++ b/fs/proc/internal.h
64001 @@ -46,9 +46,10 @@ struct proc_dir_entry {
64002 struct completion *pde_unload_completion;
64003 struct list_head pde_openers; /* who did ->open, but not ->release */
64004 spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
64005 + u8 restricted; /* a directory in /proc/net that should be restricted via GRKERNSEC_PROC */
64006 u8 namelen;
64007 char name[];
64008 -};
64009 +} __randomize_layout;
64010
64011 union proc_op {
64012 int (*proc_get_link)(struct dentry *, struct path *);
64013 @@ -67,7 +68,7 @@ struct proc_inode {
64014 struct ctl_table *sysctl_entry;
64015 struct proc_ns ns;
64016 struct inode vfs_inode;
64017 -};
64018 +} __randomize_layout;
64019
64020 /*
64021 * General functions
64022 @@ -155,6 +156,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
64023 struct pid *, struct task_struct *);
64024 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
64025 struct pid *, struct task_struct *);
64026 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
64027 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
64028 +#endif
64029
64030 /*
64031 * base.c
64032 @@ -181,9 +185,11 @@ extern bool proc_fill_cache(struct file *, struct dir_context *, const char *, i
64033 extern spinlock_t proc_subdir_lock;
64034
64035 extern struct dentry *proc_lookup(struct inode *, struct dentry *, unsigned int);
64036 +extern struct dentry *proc_lookup_restrict(struct inode *, struct dentry *, unsigned int);
64037 extern struct dentry *proc_lookup_de(struct proc_dir_entry *, struct inode *,
64038 struct dentry *);
64039 extern int proc_readdir(struct file *, struct dir_context *);
64040 +extern int proc_readdir_restrict(struct file *, struct dir_context *);
64041 extern int proc_readdir_de(struct proc_dir_entry *, struct file *, struct dir_context *);
64042
64043 static inline struct proc_dir_entry *pde_get(struct proc_dir_entry *pde)
64044 diff --git a/fs/proc/interrupts.c b/fs/proc/interrupts.c
64045 index a352d57..cb94a5c 100644
64046 --- a/fs/proc/interrupts.c
64047 +++ b/fs/proc/interrupts.c
64048 @@ -47,7 +47,11 @@ static const struct file_operations proc_interrupts_operations = {
64049
64050 static int __init proc_interrupts_init(void)
64051 {
64052 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
64053 + proc_create_grsec("interrupts", 0, NULL, &proc_interrupts_operations);
64054 +#else
64055 proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
64056 +#endif
64057 return 0;
64058 }
64059 fs_initcall(proc_interrupts_init);
64060 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
64061 index 39e6ef3..2f9cb5e 100644
64062 --- a/fs/proc/kcore.c
64063 +++ b/fs/proc/kcore.c
64064 @@ -483,9 +483,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
64065 * the addresses in the elf_phdr on our list.
64066 */
64067 start = kc_offset_to_vaddr(*fpos - elf_buflen);
64068 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
64069 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
64070 + if (tsz > buflen)
64071 tsz = buflen;
64072 -
64073 +
64074 while (buflen) {
64075 struct kcore_list *m;
64076
64077 @@ -514,20 +515,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
64078 kfree(elf_buf);
64079 } else {
64080 if (kern_addr_valid(start)) {
64081 - unsigned long n;
64082 + char *elf_buf;
64083 + mm_segment_t oldfs;
64084
64085 - n = copy_to_user(buffer, (char *)start, tsz);
64086 - /*
64087 - * We cannot distinguish between fault on source
64088 - * and fault on destination. When this happens
64089 - * we clear too and hope it will trigger the
64090 - * EFAULT again.
64091 - */
64092 - if (n) {
64093 - if (clear_user(buffer + tsz - n,
64094 - n))
64095 + elf_buf = kmalloc(tsz, GFP_KERNEL);
64096 + if (!elf_buf)
64097 + return -ENOMEM;
64098 + oldfs = get_fs();
64099 + set_fs(KERNEL_DS);
64100 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
64101 + set_fs(oldfs);
64102 + if (copy_to_user(buffer, elf_buf, tsz)) {
64103 + kfree(elf_buf);
64104 return -EFAULT;
64105 + }
64106 }
64107 + set_fs(oldfs);
64108 + kfree(elf_buf);
64109 } else {
64110 if (clear_user(buffer, tsz))
64111 return -EFAULT;
64112 @@ -547,6 +551,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
64113
64114 static int open_kcore(struct inode *inode, struct file *filp)
64115 {
64116 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
64117 + return -EPERM;
64118 +#endif
64119 if (!capable(CAP_SYS_RAWIO))
64120 return -EPERM;
64121 if (kcore_need_update)
64122 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
64123 index 7445af0..7c5113c 100644
64124 --- a/fs/proc/meminfo.c
64125 +++ b/fs/proc/meminfo.c
64126 @@ -187,7 +187,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
64127 vmi.used >> 10,
64128 vmi.largest_chunk >> 10
64129 #ifdef CONFIG_MEMORY_FAILURE
64130 - ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
64131 + ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
64132 #endif
64133 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
64134 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
64135 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
64136 index d4a3574..b421ce9 100644
64137 --- a/fs/proc/nommu.c
64138 +++ b/fs/proc/nommu.c
64139 @@ -64,7 +64,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
64140
64141 if (file) {
64142 seq_pad(m, ' ');
64143 - seq_path(m, &file->f_path, "");
64144 + seq_path(m, &file->f_path, "\n\\");
64145 }
64146
64147 seq_putc(m, '\n');
64148 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
64149 index 4677bb7..dad3045 100644
64150 --- a/fs/proc/proc_net.c
64151 +++ b/fs/proc/proc_net.c
64152 @@ -23,9 +23,27 @@
64153 #include <linux/nsproxy.h>
64154 #include <net/net_namespace.h>
64155 #include <linux/seq_file.h>
64156 +#include <linux/grsecurity.h>
64157
64158 #include "internal.h"
64159
64160 +#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
64161 +static struct seq_operations *ipv6_seq_ops_addr;
64162 +
64163 +void register_ipv6_seq_ops_addr(struct seq_operations *addr)
64164 +{
64165 + ipv6_seq_ops_addr = addr;
64166 +}
64167 +
64168 +void unregister_ipv6_seq_ops_addr(void)
64169 +{
64170 + ipv6_seq_ops_addr = NULL;
64171 +}
64172 +
64173 +EXPORT_SYMBOL_GPL(register_ipv6_seq_ops_addr);
64174 +EXPORT_SYMBOL_GPL(unregister_ipv6_seq_ops_addr);
64175 +#endif
64176 +
64177 static inline struct net *PDE_NET(struct proc_dir_entry *pde)
64178 {
64179 return pde->parent->data;
64180 @@ -36,6 +54,8 @@ static struct net *get_proc_net(const struct inode *inode)
64181 return maybe_get_net(PDE_NET(PDE(inode)));
64182 }
64183
64184 +extern const struct seq_operations dev_seq_ops;
64185 +
64186 int seq_open_net(struct inode *ino, struct file *f,
64187 const struct seq_operations *ops, int size)
64188 {
64189 @@ -44,6 +64,14 @@ int seq_open_net(struct inode *ino, struct file *f,
64190
64191 BUG_ON(size < sizeof(*p));
64192
64193 + /* only permit access to /proc/net/dev */
64194 + if (
64195 +#if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
64196 + ops != ipv6_seq_ops_addr &&
64197 +#endif
64198 + ops != &dev_seq_ops && gr_proc_is_restricted())
64199 + return -EACCES;
64200 +
64201 net = get_proc_net(ino);
64202 if (net == NULL)
64203 return -ENXIO;
64204 @@ -66,6 +94,9 @@ int single_open_net(struct inode *inode, struct file *file,
64205 int err;
64206 struct net *net;
64207
64208 + if (gr_proc_is_restricted())
64209 + return -EACCES;
64210 +
64211 err = -ENXIO;
64212 net = get_proc_net(inode);
64213 if (net == NULL)
64214 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
64215 index 7129046..6914844 100644
64216 --- a/fs/proc/proc_sysctl.c
64217 +++ b/fs/proc/proc_sysctl.c
64218 @@ -11,13 +11,21 @@
64219 #include <linux/namei.h>
64220 #include <linux/mm.h>
64221 #include <linux/module.h>
64222 +#include <linux/nsproxy.h>
64223 +#ifdef CONFIG_GRKERNSEC
64224 +#include <net/net_namespace.h>
64225 +#endif
64226 #include "internal.h"
64227
64228 +extern int gr_handle_chroot_sysctl(const int op);
64229 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
64230 + const int op);
64231 +
64232 static const struct dentry_operations proc_sys_dentry_operations;
64233 static const struct file_operations proc_sys_file_operations;
64234 -static const struct inode_operations proc_sys_inode_operations;
64235 +const struct inode_operations proc_sys_inode_operations;
64236 static const struct file_operations proc_sys_dir_file_operations;
64237 -static const struct inode_operations proc_sys_dir_operations;
64238 +const struct inode_operations proc_sys_dir_operations;
64239
64240 void proc_sys_poll_notify(struct ctl_table_poll *poll)
64241 {
64242 @@ -467,6 +475,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
64243
64244 err = NULL;
64245 d_set_d_op(dentry, &proc_sys_dentry_operations);
64246 +
64247 + gr_handle_proc_create(dentry, inode);
64248 +
64249 d_add(dentry, inode);
64250
64251 out:
64252 @@ -482,6 +493,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
64253 struct inode *inode = file_inode(filp);
64254 struct ctl_table_header *head = grab_header(inode);
64255 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
64256 + int op = write ? MAY_WRITE : MAY_READ;
64257 ssize_t error;
64258 size_t res;
64259
64260 @@ -493,7 +505,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
64261 * and won't be until we finish.
64262 */
64263 error = -EPERM;
64264 - if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
64265 + if (sysctl_perm(head, table, op))
64266 goto out;
64267
64268 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
64269 @@ -501,6 +513,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
64270 if (!table->proc_handler)
64271 goto out;
64272
64273 +#ifdef CONFIG_GRKERNSEC
64274 + error = -EPERM;
64275 + if (gr_handle_chroot_sysctl(op))
64276 + goto out;
64277 + dget(filp->f_path.dentry);
64278 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
64279 + dput(filp->f_path.dentry);
64280 + goto out;
64281 + }
64282 + dput(filp->f_path.dentry);
64283 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
64284 + goto out;
64285 + if (write) {
64286 + if (current->nsproxy->net_ns != table->extra2) {
64287 + if (!capable(CAP_SYS_ADMIN))
64288 + goto out;
64289 + } else if (!ns_capable(current->nsproxy->net_ns->user_ns, CAP_NET_ADMIN))
64290 + goto out;
64291 + }
64292 +#endif
64293 +
64294 /* careful: calling conventions are nasty here */
64295 res = count;
64296 error = table->proc_handler(table, write, buf, &res, ppos);
64297 @@ -598,6 +631,9 @@ static bool proc_sys_fill_cache(struct file *file,
64298 return false;
64299 } else {
64300 d_set_d_op(child, &proc_sys_dentry_operations);
64301 +
64302 + gr_handle_proc_create(child, inode);
64303 +
64304 d_add(child, inode);
64305 }
64306 } else {
64307 @@ -641,6 +677,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
64308 if ((*pos)++ < ctx->pos)
64309 return true;
64310
64311 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
64312 + return 0;
64313 +
64314 if (unlikely(S_ISLNK(table->mode)))
64315 res = proc_sys_link_fill_cache(file, ctx, head, table);
64316 else
64317 @@ -734,6 +773,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
64318 if (IS_ERR(head))
64319 return PTR_ERR(head);
64320
64321 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
64322 + return -ENOENT;
64323 +
64324 generic_fillattr(inode, stat);
64325 if (table)
64326 stat->mode = (stat->mode & S_IFMT) | table->mode;
64327 @@ -756,13 +798,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
64328 .llseek = generic_file_llseek,
64329 };
64330
64331 -static const struct inode_operations proc_sys_inode_operations = {
64332 +const struct inode_operations proc_sys_inode_operations = {
64333 .permission = proc_sys_permission,
64334 .setattr = proc_sys_setattr,
64335 .getattr = proc_sys_getattr,
64336 };
64337
64338 -static const struct inode_operations proc_sys_dir_operations = {
64339 +const struct inode_operations proc_sys_dir_operations = {
64340 .lookup = proc_sys_lookup,
64341 .permission = proc_sys_permission,
64342 .setattr = proc_sys_setattr,
64343 @@ -839,7 +881,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
64344 static struct ctl_dir *new_dir(struct ctl_table_set *set,
64345 const char *name, int namelen)
64346 {
64347 - struct ctl_table *table;
64348 + ctl_table_no_const *table;
64349 struct ctl_dir *new;
64350 struct ctl_node *node;
64351 char *new_name;
64352 @@ -851,7 +893,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
64353 return NULL;
64354
64355 node = (struct ctl_node *)(new + 1);
64356 - table = (struct ctl_table *)(node + 1);
64357 + table = (ctl_table_no_const *)(node + 1);
64358 new_name = (char *)(table + 2);
64359 memcpy(new_name, name, namelen);
64360 new_name[namelen] = '\0';
64361 @@ -1020,7 +1062,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
64362 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
64363 struct ctl_table_root *link_root)
64364 {
64365 - struct ctl_table *link_table, *entry, *link;
64366 + ctl_table_no_const *link_table, *link;
64367 + struct ctl_table *entry;
64368 struct ctl_table_header *links;
64369 struct ctl_node *node;
64370 char *link_name;
64371 @@ -1043,7 +1086,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
64372 return NULL;
64373
64374 node = (struct ctl_node *)(links + 1);
64375 - link_table = (struct ctl_table *)(node + nr_entries);
64376 + link_table = (ctl_table_no_const *)(node + nr_entries);
64377 link_name = (char *)&link_table[nr_entries + 1];
64378
64379 for (link = link_table, entry = table; entry->procname; link++, entry++) {
64380 @@ -1291,8 +1334,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
64381 struct ctl_table_header ***subheader, struct ctl_table_set *set,
64382 struct ctl_table *table)
64383 {
64384 - struct ctl_table *ctl_table_arg = NULL;
64385 - struct ctl_table *entry, *files;
64386 + ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
64387 + struct ctl_table *entry;
64388 int nr_files = 0;
64389 int nr_dirs = 0;
64390 int err = -ENOMEM;
64391 @@ -1304,10 +1347,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
64392 nr_files++;
64393 }
64394
64395 - files = table;
64396 /* If there are mixed files and directories we need a new table */
64397 if (nr_dirs && nr_files) {
64398 - struct ctl_table *new;
64399 + ctl_table_no_const *new;
64400 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
64401 GFP_KERNEL);
64402 if (!files)
64403 @@ -1325,7 +1367,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
64404 /* Register everything except a directory full of subdirectories */
64405 if (nr_files || !nr_dirs) {
64406 struct ctl_table_header *header;
64407 - header = __register_sysctl_table(set, path, files);
64408 + header = __register_sysctl_table(set, path, files ? files : table);
64409 if (!header) {
64410 kfree(ctl_table_arg);
64411 goto out;
64412 diff --git a/fs/proc/root.c b/fs/proc/root.c
64413 index 5dbadec..473af2f 100644
64414 --- a/fs/proc/root.c
64415 +++ b/fs/proc/root.c
64416 @@ -185,7 +185,15 @@ void __init proc_root_init(void)
64417 proc_mkdir("openprom", NULL);
64418 #endif
64419 proc_tty_init();
64420 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
64421 +#ifdef CONFIG_GRKERNSEC_PROC_USER
64422 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
64423 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64424 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
64425 +#endif
64426 +#else
64427 proc_mkdir("bus", NULL);
64428 +#endif
64429 proc_sys_init();
64430 }
64431
64432 diff --git a/fs/proc/stat.c b/fs/proc/stat.c
64433 index 9d231e9..2e1b51a 100644
64434 --- a/fs/proc/stat.c
64435 +++ b/fs/proc/stat.c
64436 @@ -11,6 +11,7 @@
64437 #include <linux/irqnr.h>
64438 #include <linux/cputime.h>
64439 #include <linux/tick.h>
64440 +#include <linux/grsecurity.h>
64441
64442 #ifndef arch_irq_stat_cpu
64443 #define arch_irq_stat_cpu(cpu) 0
64444 @@ -87,6 +88,18 @@ static int show_stat(struct seq_file *p, void *v)
64445 u64 sum_softirq = 0;
64446 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
64447 struct timespec boottime;
64448 + int unrestricted = 1;
64449 +
64450 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
64451 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
64452 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
64453 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
64454 + && !in_group_p(grsec_proc_gid)
64455 +#endif
64456 + )
64457 + unrestricted = 0;
64458 +#endif
64459 +#endif
64460
64461 user = nice = system = idle = iowait =
64462 irq = softirq = steal = 0;
64463 @@ -99,23 +112,25 @@ static int show_stat(struct seq_file *p, void *v)
64464 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
64465 system += kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
64466 idle += get_idle_time(i);
64467 - iowait += get_iowait_time(i);
64468 - irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64469 - softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64470 - steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64471 - guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64472 - guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64473 - sum += kstat_cpu_irqs_sum(i);
64474 - sum += arch_irq_stat_cpu(i);
64475 + if (unrestricted) {
64476 + iowait += get_iowait_time(i);
64477 + irq += kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64478 + softirq += kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64479 + steal += kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64480 + guest += kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64481 + guest_nice += kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64482 + sum += kstat_cpu_irqs_sum(i);
64483 + sum += arch_irq_stat_cpu(i);
64484 + for (j = 0; j < NR_SOFTIRQS; j++) {
64485 + unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
64486
64487 - for (j = 0; j < NR_SOFTIRQS; j++) {
64488 - unsigned int softirq_stat = kstat_softirqs_cpu(j, i);
64489 -
64490 - per_softirq_sums[j] += softirq_stat;
64491 - sum_softirq += softirq_stat;
64492 + per_softirq_sums[j] += softirq_stat;
64493 + sum_softirq += softirq_stat;
64494 + }
64495 }
64496 }
64497 - sum += arch_irq_stat();
64498 + if (unrestricted)
64499 + sum += arch_irq_stat();
64500
64501 seq_puts(p, "cpu ");
64502 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
64503 @@ -136,12 +151,14 @@ static int show_stat(struct seq_file *p, void *v)
64504 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
64505 system = kcpustat_cpu(i).cpustat[CPUTIME_SYSTEM];
64506 idle = get_idle_time(i);
64507 - iowait = get_iowait_time(i);
64508 - irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64509 - softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64510 - steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64511 - guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64512 - guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64513 + if (unrestricted) {
64514 + iowait = get_iowait_time(i);
64515 + irq = kcpustat_cpu(i).cpustat[CPUTIME_IRQ];
64516 + softirq = kcpustat_cpu(i).cpustat[CPUTIME_SOFTIRQ];
64517 + steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
64518 + guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
64519 + guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
64520 + }
64521 seq_printf(p, "cpu%d", i);
64522 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
64523 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice));
64524 @@ -159,7 +176,7 @@ static int show_stat(struct seq_file *p, void *v)
64525
64526 /* sum again ? it could be updated? */
64527 for_each_irq_nr(j)
64528 - seq_put_decimal_ull(p, ' ', kstat_irqs(j));
64529 + seq_put_decimal_ull(p, ' ', unrestricted ? kstat_irqs(j) : 0ULL);
64530
64531 seq_printf(p,
64532 "\nctxt %llu\n"
64533 @@ -167,11 +184,11 @@ static int show_stat(struct seq_file *p, void *v)
64534 "processes %lu\n"
64535 "procs_running %lu\n"
64536 "procs_blocked %lu\n",
64537 - nr_context_switches(),
64538 + unrestricted ? nr_context_switches() : 0ULL,
64539 (unsigned long)jif,
64540 - total_forks,
64541 - nr_running(),
64542 - nr_iowait());
64543 + unrestricted ? total_forks : 0UL,
64544 + unrestricted ? nr_running() : 0UL,
64545 + unrestricted ? nr_iowait() : 0UL);
64546
64547 seq_printf(p, "softirq %llu", (unsigned long long)sum_softirq);
64548
64549 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
64550 index c4b2646..84f0d7b 100644
64551 --- a/fs/proc/task_mmu.c
64552 +++ b/fs/proc/task_mmu.c
64553 @@ -13,12 +13,19 @@
64554 #include <linux/swap.h>
64555 #include <linux/swapops.h>
64556 #include <linux/mmu_notifier.h>
64557 +#include <linux/grsecurity.h>
64558
64559 #include <asm/elf.h>
64560 #include <asm/uaccess.h>
64561 #include <asm/tlbflush.h>
64562 #include "internal.h"
64563
64564 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64565 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
64566 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
64567 + _mm->pax_flags & MF_PAX_SEGMEXEC))
64568 +#endif
64569 +
64570 void task_mem(struct seq_file *m, struct mm_struct *mm)
64571 {
64572 unsigned long data, text, lib, swap;
64573 @@ -54,8 +61,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64574 "VmExe:\t%8lu kB\n"
64575 "VmLib:\t%8lu kB\n"
64576 "VmPTE:\t%8lu kB\n"
64577 - "VmSwap:\t%8lu kB\n",
64578 - hiwater_vm << (PAGE_SHIFT-10),
64579 + "VmSwap:\t%8lu kB\n"
64580 +
64581 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
64582 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
64583 +#endif
64584 +
64585 + ,hiwater_vm << (PAGE_SHIFT-10),
64586 total_vm << (PAGE_SHIFT-10),
64587 mm->locked_vm << (PAGE_SHIFT-10),
64588 mm->pinned_vm << (PAGE_SHIFT-10),
64589 @@ -65,7 +77,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64590 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
64591 (PTRS_PER_PTE * sizeof(pte_t) *
64592 atomic_long_read(&mm->nr_ptes)) >> 10,
64593 - swap << (PAGE_SHIFT-10));
64594 + swap << (PAGE_SHIFT-10)
64595 +
64596 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
64597 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64598 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
64599 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
64600 +#else
64601 + , mm->context.user_cs_base
64602 + , mm->context.user_cs_limit
64603 +#endif
64604 +#endif
64605 +
64606 + );
64607 }
64608
64609 unsigned long task_vsize(struct mm_struct *mm)
64610 @@ -271,13 +295,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64611 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
64612 }
64613
64614 - /* We don't show the stack guard page in /proc/maps */
64615 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64616 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
64617 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
64618 +#else
64619 start = vma->vm_start;
64620 - if (stack_guard_page_start(vma, start))
64621 - start += PAGE_SIZE;
64622 end = vma->vm_end;
64623 - if (stack_guard_page_end(vma, end))
64624 - end -= PAGE_SIZE;
64625 +#endif
64626
64627 seq_setwidth(m, 25 + sizeof(void *) * 6 - 1);
64628 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
64629 @@ -287,7 +311,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64630 flags & VM_WRITE ? 'w' : '-',
64631 flags & VM_EXEC ? 'x' : '-',
64632 flags & VM_MAYSHARE ? 's' : 'p',
64633 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64634 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
64635 +#else
64636 pgoff,
64637 +#endif
64638 MAJOR(dev), MINOR(dev), ino);
64639
64640 /*
64641 @@ -296,7 +324,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64642 */
64643 if (file) {
64644 seq_pad(m, ' ');
64645 - seq_path(m, &file->f_path, "\n");
64646 + seq_path(m, &file->f_path, "\n\\");
64647 goto done;
64648 }
64649
64650 @@ -322,8 +350,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
64651 * Thread stack in /proc/PID/task/TID/maps or
64652 * the main process stack.
64653 */
64654 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
64655 - vma->vm_end >= mm->start_stack)) {
64656 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
64657 + (vma->vm_start <= mm->start_stack &&
64658 + vma->vm_end >= mm->start_stack)) {
64659 name = "[stack]";
64660 } else {
64661 /* Thread stack in /proc/PID/maps */
64662 @@ -347,6 +376,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
64663 struct proc_maps_private *priv = m->private;
64664 struct task_struct *task = priv->task;
64665
64666 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64667 + if (current->exec_id != m->exec_id) {
64668 + gr_log_badprocpid("maps");
64669 + return 0;
64670 + }
64671 +#endif
64672 +
64673 show_map_vma(m, vma, is_pid);
64674
64675 if (m->count < m->size) /* vma is copied successfully */
64676 @@ -587,12 +623,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
64677 .private = &mss,
64678 };
64679
64680 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64681 + if (current->exec_id != m->exec_id) {
64682 + gr_log_badprocpid("smaps");
64683 + return 0;
64684 + }
64685 +#endif
64686 memset(&mss, 0, sizeof mss);
64687 - mss.vma = vma;
64688 - /* mmap_sem is held in m_start */
64689 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
64690 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
64691 -
64692 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64693 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
64694 +#endif
64695 + mss.vma = vma;
64696 + /* mmap_sem is held in m_start */
64697 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
64698 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
64699 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64700 + }
64701 +#endif
64702 show_map_vma(m, vma, is_pid);
64703
64704 seq_printf(m,
64705 @@ -610,7 +657,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
64706 "KernelPageSize: %8lu kB\n"
64707 "MMUPageSize: %8lu kB\n"
64708 "Locked: %8lu kB\n",
64709 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64710 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
64711 +#else
64712 (vma->vm_end - vma->vm_start) >> 10,
64713 +#endif
64714 mss.resident >> 10,
64715 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
64716 mss.shared_clean >> 10,
64717 @@ -1388,6 +1439,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
64718 char buffer[64];
64719 int nid;
64720
64721 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64722 + if (current->exec_id != m->exec_id) {
64723 + gr_log_badprocpid("numa_maps");
64724 + return 0;
64725 + }
64726 +#endif
64727 +
64728 if (!mm)
64729 return 0;
64730
64731 @@ -1405,11 +1463,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
64732 mpol_to_str(buffer, sizeof(buffer), pol);
64733 mpol_cond_put(pol);
64734
64735 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64736 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
64737 +#else
64738 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
64739 +#endif
64740
64741 if (file) {
64742 seq_printf(m, " file=");
64743 - seq_path(m, &file->f_path, "\n\t= ");
64744 + seq_path(m, &file->f_path, "\n\t\\= ");
64745 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
64746 seq_printf(m, " heap");
64747 } else {
64748 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
64749 index 678455d..ebd3245 100644
64750 --- a/fs/proc/task_nommu.c
64751 +++ b/fs/proc/task_nommu.c
64752 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
64753 else
64754 bytes += kobjsize(mm);
64755
64756 - if (current->fs && current->fs->users > 1)
64757 + if (current->fs && atomic_read(&current->fs->users) > 1)
64758 sbytes += kobjsize(current->fs);
64759 else
64760 bytes += kobjsize(current->fs);
64761 @@ -161,7 +161,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
64762
64763 if (file) {
64764 seq_pad(m, ' ');
64765 - seq_path(m, &file->f_path, "");
64766 + seq_path(m, &file->f_path, "\n\\");
64767 } else if (mm) {
64768 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
64769
64770 diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
64771 index 6a8e785..41f2a6c 100644
64772 --- a/fs/proc/vmcore.c
64773 +++ b/fs/proc/vmcore.c
64774 @@ -105,9 +105,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
64775 nr_bytes = count;
64776
64777 /* If pfn is not ram, return zeros for sparse dump files */
64778 - if (pfn_is_ram(pfn) == 0)
64779 - memset(buf, 0, nr_bytes);
64780 - else {
64781 + if (pfn_is_ram(pfn) == 0) {
64782 + if (userbuf) {
64783 + if (clear_user((char __force_user *)buf, nr_bytes))
64784 + return -EFAULT;
64785 + } else
64786 + memset(buf, 0, nr_bytes);
64787 + } else {
64788 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
64789 offset, userbuf);
64790 if (tmp < 0)
64791 @@ -170,7 +174,7 @@ int __weak remap_oldmem_pfn_range(struct vm_area_struct *vma,
64792 static int copy_to(void *target, void *src, size_t size, int userbuf)
64793 {
64794 if (userbuf) {
64795 - if (copy_to_user((char __user *) target, src, size))
64796 + if (copy_to_user((char __force_user *) target, src, size))
64797 return -EFAULT;
64798 } else {
64799 memcpy(target, src, size);
64800 @@ -233,7 +237,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
64801 if (*fpos < m->offset + m->size) {
64802 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
64803 start = m->paddr + *fpos - m->offset;
64804 - tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
64805 + tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, userbuf);
64806 if (tmp < 0)
64807 return tmp;
64808 buflen -= tsz;
64809 @@ -253,7 +257,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
64810 static ssize_t read_vmcore(struct file *file, char __user *buffer,
64811 size_t buflen, loff_t *fpos)
64812 {
64813 - return __read_vmcore((__force char *) buffer, buflen, fpos, 1);
64814 + return __read_vmcore((__force_kernel char *) buffer, buflen, fpos, 1);
64815 }
64816
64817 /*
64818 diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
64819 index b00fcc9..e0c6381 100644
64820 --- a/fs/qnx6/qnx6.h
64821 +++ b/fs/qnx6/qnx6.h
64822 @@ -74,7 +74,7 @@ enum {
64823 BYTESEX_BE,
64824 };
64825
64826 -static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
64827 +static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
64828 {
64829 if (sbi->s_bytesex == BYTESEX_LE)
64830 return le64_to_cpu((__force __le64)n);
64831 @@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
64832 return (__force __fs64)cpu_to_be64(n);
64833 }
64834
64835 -static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
64836 +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
64837 {
64838 if (sbi->s_bytesex == BYTESEX_LE)
64839 return le32_to_cpu((__force __le32)n);
64840 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
64841 index 72d2917..c917c12 100644
64842 --- a/fs/quota/netlink.c
64843 +++ b/fs/quota/netlink.c
64844 @@ -45,7 +45,7 @@ static struct genl_family quota_genl_family = {
64845 void quota_send_warning(struct kqid qid, dev_t dev,
64846 const char warntype)
64847 {
64848 - static atomic_t seq;
64849 + static atomic_unchecked_t seq;
64850 struct sk_buff *skb;
64851 void *msg_head;
64852 int ret;
64853 @@ -61,7 +61,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
64854 "VFS: Not enough memory to send quota warning.\n");
64855 return;
64856 }
64857 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
64858 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
64859 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
64860 if (!msg_head) {
64861 printk(KERN_ERR
64862 diff --git a/fs/read_write.c b/fs/read_write.c
64863 index 31c6efa..a068805 100644
64864 --- a/fs/read_write.c
64865 +++ b/fs/read_write.c
64866 @@ -450,7 +450,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
64867
64868 old_fs = get_fs();
64869 set_fs(get_ds());
64870 - p = (__force const char __user *)buf;
64871 + p = (const char __force_user *)buf;
64872 if (count > MAX_RW_COUNT)
64873 count = MAX_RW_COUNT;
64874 if (file->f_op->write)
64875 diff --git a/fs/readdir.c b/fs/readdir.c
64876 index 5b53d99..a6c3049 100644
64877 --- a/fs/readdir.c
64878 +++ b/fs/readdir.c
64879 @@ -17,6 +17,7 @@
64880 #include <linux/security.h>
64881 #include <linux/syscalls.h>
64882 #include <linux/unistd.h>
64883 +#include <linux/namei.h>
64884
64885 #include <asm/uaccess.h>
64886
64887 @@ -69,6 +70,7 @@ struct old_linux_dirent {
64888 struct readdir_callback {
64889 struct dir_context ctx;
64890 struct old_linux_dirent __user * dirent;
64891 + struct file * file;
64892 int result;
64893 };
64894
64895 @@ -86,6 +88,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
64896 buf->result = -EOVERFLOW;
64897 return -EOVERFLOW;
64898 }
64899 +
64900 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
64901 + return 0;
64902 +
64903 buf->result++;
64904 dirent = buf->dirent;
64905 if (!access_ok(VERIFY_WRITE, dirent,
64906 @@ -117,6 +123,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
64907 if (!f.file)
64908 return -EBADF;
64909
64910 + buf.file = f.file;
64911 error = iterate_dir(f.file, &buf.ctx);
64912 if (buf.result)
64913 error = buf.result;
64914 @@ -142,6 +149,7 @@ struct getdents_callback {
64915 struct dir_context ctx;
64916 struct linux_dirent __user * current_dir;
64917 struct linux_dirent __user * previous;
64918 + struct file * file;
64919 int count;
64920 int error;
64921 };
64922 @@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
64923 buf->error = -EOVERFLOW;
64924 return -EOVERFLOW;
64925 }
64926 +
64927 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
64928 + return 0;
64929 +
64930 dirent = buf->previous;
64931 if (dirent) {
64932 if (__put_user(offset, &dirent->d_off))
64933 @@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
64934 if (!f.file)
64935 return -EBADF;
64936
64937 + buf.file = f.file;
64938 error = iterate_dir(f.file, &buf.ctx);
64939 if (error >= 0)
64940 error = buf.error;
64941 @@ -226,6 +239,7 @@ struct getdents_callback64 {
64942 struct dir_context ctx;
64943 struct linux_dirent64 __user * current_dir;
64944 struct linux_dirent64 __user * previous;
64945 + struct file *file;
64946 int count;
64947 int error;
64948 };
64949 @@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
64950 buf->error = -EINVAL; /* only used if we fail.. */
64951 if (reclen > buf->count)
64952 return -EINVAL;
64953 +
64954 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
64955 + return 0;
64956 +
64957 dirent = buf->previous;
64958 if (dirent) {
64959 if (__put_user(offset, &dirent->d_off))
64960 @@ -288,6 +306,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
64961 if (!f.file)
64962 return -EBADF;
64963
64964 + buf.file = f.file;
64965 error = iterate_dir(f.file, &buf.ctx);
64966 if (error >= 0)
64967 error = buf.error;
64968 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
64969 index 9a3c68c..767933e 100644
64970 --- a/fs/reiserfs/do_balan.c
64971 +++ b/fs/reiserfs/do_balan.c
64972 @@ -1546,7 +1546,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
64973 return;
64974 }
64975
64976 - atomic_inc(&(fs_generation(tb->tb_sb)));
64977 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
64978 do_balance_starts(tb);
64979
64980 /* balance leaf returns 0 except if combining L R and S into
64981 diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
64982 index ee382ef..f4eb6eb5 100644
64983 --- a/fs/reiserfs/item_ops.c
64984 +++ b/fs/reiserfs/item_ops.c
64985 @@ -725,18 +725,18 @@ static void errcatch_print_vi(struct virtual_item *vi)
64986 }
64987
64988 static struct item_operations errcatch_ops = {
64989 - errcatch_bytes_number,
64990 - errcatch_decrement_key,
64991 - errcatch_is_left_mergeable,
64992 - errcatch_print_item,
64993 - errcatch_check_item,
64994 + .bytes_number = errcatch_bytes_number,
64995 + .decrement_key = errcatch_decrement_key,
64996 + .is_left_mergeable = errcatch_is_left_mergeable,
64997 + .print_item = errcatch_print_item,
64998 + .check_item = errcatch_check_item,
64999
65000 - errcatch_create_vi,
65001 - errcatch_check_left,
65002 - errcatch_check_right,
65003 - errcatch_part_size,
65004 - errcatch_unit_num,
65005 - errcatch_print_vi
65006 + .create_vi = errcatch_create_vi,
65007 + .check_left = errcatch_check_left,
65008 + .check_right = errcatch_check_right,
65009 + .part_size = errcatch_part_size,
65010 + .unit_num = errcatch_unit_num,
65011 + .print_vi = errcatch_print_vi
65012 };
65013
65014 //////////////////////////////////////////////////////////////////////////////
65015 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
65016 index 02b0b7d..c85018b 100644
65017 --- a/fs/reiserfs/procfs.c
65018 +++ b/fs/reiserfs/procfs.c
65019 @@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
65020 "SMALL_TAILS " : "NO_TAILS ",
65021 replay_only(sb) ? "REPLAY_ONLY " : "",
65022 convert_reiserfs(sb) ? "CONV " : "",
65023 - atomic_read(&r->s_generation_counter),
65024 + atomic_read_unchecked(&r->s_generation_counter),
65025 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
65026 SF(s_do_balance), SF(s_unneeded_left_neighbor),
65027 SF(s_good_search_by_key_reada), SF(s_bmaps),
65028 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
65029 index 83d4eac..04e39a7 100644
65030 --- a/fs/reiserfs/reiserfs.h
65031 +++ b/fs/reiserfs/reiserfs.h
65032 @@ -453,7 +453,7 @@ struct reiserfs_sb_info {
65033 /* Comment? -Hans */
65034 wait_queue_head_t s_wait;
65035 /* To be obsoleted soon by per buffer seals.. -Hans */
65036 - atomic_t s_generation_counter; // increased by one every time the
65037 + atomic_unchecked_t s_generation_counter; // increased by one every time the
65038 // tree gets re-balanced
65039 unsigned long s_properties; /* File system properties. Currently holds
65040 on-disk FS format */
65041 @@ -1972,7 +1972,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
65042 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
65043
65044 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
65045 -#define get_generation(s) atomic_read (&fs_generation(s))
65046 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
65047 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
65048 #define __fs_changed(gen,s) (gen != get_generation (s))
65049 #define fs_changed(gen,s) \
65050 diff --git a/fs/select.c b/fs/select.c
65051 index 467bb1c..cf9d65a 100644
65052 --- a/fs/select.c
65053 +++ b/fs/select.c
65054 @@ -20,6 +20,7 @@
65055 #include <linux/export.h>
65056 #include <linux/slab.h>
65057 #include <linux/poll.h>
65058 +#include <linux/security.h>
65059 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
65060 #include <linux/file.h>
65061 #include <linux/fdtable.h>
65062 @@ -880,6 +881,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
65063 struct poll_list *walk = head;
65064 unsigned long todo = nfds;
65065
65066 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
65067 if (nfds > rlimit(RLIMIT_NOFILE))
65068 return -EINVAL;
65069
65070 diff --git a/fs/seq_file.c b/fs/seq_file.c
65071 index 1d641bb..c2f4743 100644
65072 --- a/fs/seq_file.c
65073 +++ b/fs/seq_file.c
65074 @@ -10,6 +10,8 @@
65075 #include <linux/seq_file.h>
65076 #include <linux/slab.h>
65077 #include <linux/cred.h>
65078 +#include <linux/sched.h>
65079 +#include <linux/grsecurity.h>
65080
65081 #include <asm/uaccess.h>
65082 #include <asm/page.h>
65083 @@ -60,6 +62,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
65084 #ifdef CONFIG_USER_NS
65085 p->user_ns = file->f_cred->user_ns;
65086 #endif
65087 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
65088 + p->exec_id = current->exec_id;
65089 +#endif
65090
65091 /*
65092 * Wrappers around seq_open(e.g. swaps_open) need to be
65093 @@ -82,6 +87,16 @@ int seq_open(struct file *file, const struct seq_operations *op)
65094 }
65095 EXPORT_SYMBOL(seq_open);
65096
65097 +
65098 +int seq_open_restrict(struct file *file, const struct seq_operations *op)
65099 +{
65100 + if (gr_proc_is_restricted())
65101 + return -EACCES;
65102 +
65103 + return seq_open(file, op);
65104 +}
65105 +EXPORT_SYMBOL(seq_open_restrict);
65106 +
65107 static int traverse(struct seq_file *m, loff_t offset)
65108 {
65109 loff_t pos = 0, index;
65110 @@ -96,7 +111,7 @@ static int traverse(struct seq_file *m, loff_t offset)
65111 return 0;
65112 }
65113 if (!m->buf) {
65114 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
65115 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
65116 if (!m->buf)
65117 return -ENOMEM;
65118 }
65119 @@ -137,7 +152,7 @@ Eoverflow:
65120 m->op->stop(m, p);
65121 kfree(m->buf);
65122 m->count = 0;
65123 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
65124 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
65125 return !m->buf ? -ENOMEM : -EAGAIN;
65126 }
65127
65128 @@ -153,7 +168,7 @@ Eoverflow:
65129 ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
65130 {
65131 struct seq_file *m = file->private_data;
65132 - size_t copied = 0;
65133 + ssize_t copied = 0;
65134 loff_t pos;
65135 size_t n;
65136 void *p;
65137 @@ -192,7 +207,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
65138
65139 /* grab buffer if we didn't have one */
65140 if (!m->buf) {
65141 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
65142 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
65143 if (!m->buf)
65144 goto Enomem;
65145 }
65146 @@ -234,7 +249,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
65147 m->op->stop(m, p);
65148 kfree(m->buf);
65149 m->count = 0;
65150 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
65151 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
65152 if (!m->buf)
65153 goto Enomem;
65154 m->version = 0;
65155 @@ -584,7 +599,7 @@ static void single_stop(struct seq_file *p, void *v)
65156 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
65157 void *data)
65158 {
65159 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
65160 + seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
65161 int res = -ENOMEM;
65162
65163 if (op) {
65164 @@ -620,6 +635,17 @@ int single_open_size(struct file *file, int (*show)(struct seq_file *, void *),
65165 }
65166 EXPORT_SYMBOL(single_open_size);
65167
65168 +int single_open_restrict(struct file *file, int (*show)(struct seq_file *, void *),
65169 + void *data)
65170 +{
65171 + if (gr_proc_is_restricted())
65172 + return -EACCES;
65173 +
65174 + return single_open(file, show, data);
65175 +}
65176 +EXPORT_SYMBOL(single_open_restrict);
65177 +
65178 +
65179 int single_release(struct inode *inode, struct file *file)
65180 {
65181 const struct seq_operations *op = ((struct seq_file *)file->private_data)->op;
65182 diff --git a/fs/splice.c b/fs/splice.c
65183 index e246954..bd4f5b5 100644
65184 --- a/fs/splice.c
65185 +++ b/fs/splice.c
65186 @@ -192,7 +192,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
65187 pipe_lock(pipe);
65188
65189 for (;;) {
65190 - if (!pipe->readers) {
65191 + if (!atomic_read(&pipe->readers)) {
65192 send_sig(SIGPIPE, current, 0);
65193 if (!ret)
65194 ret = -EPIPE;
65195 @@ -215,7 +215,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
65196 page_nr++;
65197 ret += buf->len;
65198
65199 - if (pipe->files)
65200 + if (atomic_read(&pipe->files))
65201 do_wakeup = 1;
65202
65203 if (!--spd->nr_pages)
65204 @@ -246,9 +246,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
65205 do_wakeup = 0;
65206 }
65207
65208 - pipe->waiting_writers++;
65209 + atomic_inc(&pipe->waiting_writers);
65210 pipe_wait(pipe);
65211 - pipe->waiting_writers--;
65212 + atomic_dec(&pipe->waiting_writers);
65213 }
65214
65215 pipe_unlock(pipe);
65216 @@ -575,7 +575,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
65217 old_fs = get_fs();
65218 set_fs(get_ds());
65219 /* The cast to a user pointer is valid due to the set_fs() */
65220 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
65221 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
65222 set_fs(old_fs);
65223
65224 return res;
65225 @@ -590,7 +590,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
65226 old_fs = get_fs();
65227 set_fs(get_ds());
65228 /* The cast to a user pointer is valid due to the set_fs() */
65229 - res = vfs_write(file, (__force const char __user *)buf, count, &pos);
65230 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
65231 set_fs(old_fs);
65232
65233 return res;
65234 @@ -643,7 +643,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
65235 goto err;
65236
65237 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
65238 - vec[i].iov_base = (void __user *) page_address(page);
65239 + vec[i].iov_base = (void __force_user *) page_address(page);
65240 vec[i].iov_len = this_len;
65241 spd.pages[i] = page;
65242 spd.nr_pages++;
65243 @@ -839,7 +839,7 @@ int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd,
65244 ops->release(pipe, buf);
65245 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
65246 pipe->nrbufs--;
65247 - if (pipe->files)
65248 + if (atomic_read(&pipe->files))
65249 sd->need_wakeup = true;
65250 }
65251
65252 @@ -864,10 +864,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
65253 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
65254 {
65255 while (!pipe->nrbufs) {
65256 - if (!pipe->writers)
65257 + if (!atomic_read(&pipe->writers))
65258 return 0;
65259
65260 - if (!pipe->waiting_writers && sd->num_spliced)
65261 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
65262 return 0;
65263
65264 if (sd->flags & SPLICE_F_NONBLOCK)
65265 @@ -1189,7 +1189,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
65266 * out of the pipe right after the splice_to_pipe(). So set
65267 * PIPE_READERS appropriately.
65268 */
65269 - pipe->readers = 1;
65270 + atomic_set(&pipe->readers, 1);
65271
65272 current->splice_pipe = pipe;
65273 }
65274 @@ -1485,6 +1485,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
65275
65276 partial[buffers].offset = off;
65277 partial[buffers].len = plen;
65278 + partial[buffers].private = 0;
65279
65280 off = 0;
65281 len -= plen;
65282 @@ -1721,9 +1722,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
65283 ret = -ERESTARTSYS;
65284 break;
65285 }
65286 - if (!pipe->writers)
65287 + if (!atomic_read(&pipe->writers))
65288 break;
65289 - if (!pipe->waiting_writers) {
65290 + if (!atomic_read(&pipe->waiting_writers)) {
65291 if (flags & SPLICE_F_NONBLOCK) {
65292 ret = -EAGAIN;
65293 break;
65294 @@ -1755,7 +1756,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
65295 pipe_lock(pipe);
65296
65297 while (pipe->nrbufs >= pipe->buffers) {
65298 - if (!pipe->readers) {
65299 + if (!atomic_read(&pipe->readers)) {
65300 send_sig(SIGPIPE, current, 0);
65301 ret = -EPIPE;
65302 break;
65303 @@ -1768,9 +1769,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
65304 ret = -ERESTARTSYS;
65305 break;
65306 }
65307 - pipe->waiting_writers++;
65308 + atomic_inc(&pipe->waiting_writers);
65309 pipe_wait(pipe);
65310 - pipe->waiting_writers--;
65311 + atomic_dec(&pipe->waiting_writers);
65312 }
65313
65314 pipe_unlock(pipe);
65315 @@ -1806,14 +1807,14 @@ retry:
65316 pipe_double_lock(ipipe, opipe);
65317
65318 do {
65319 - if (!opipe->readers) {
65320 + if (!atomic_read(&opipe->readers)) {
65321 send_sig(SIGPIPE, current, 0);
65322 if (!ret)
65323 ret = -EPIPE;
65324 break;
65325 }
65326
65327 - if (!ipipe->nrbufs && !ipipe->writers)
65328 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
65329 break;
65330
65331 /*
65332 @@ -1910,7 +1911,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
65333 pipe_double_lock(ipipe, opipe);
65334
65335 do {
65336 - if (!opipe->readers) {
65337 + if (!atomic_read(&opipe->readers)) {
65338 send_sig(SIGPIPE, current, 0);
65339 if (!ret)
65340 ret = -EPIPE;
65341 @@ -1955,7 +1956,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
65342 * return EAGAIN if we have the potential of some data in the
65343 * future, otherwise just return 0
65344 */
65345 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
65346 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
65347 ret = -EAGAIN;
65348
65349 pipe_unlock(ipipe);
65350 diff --git a/fs/stat.c b/fs/stat.c
65351 index ae0c3ce..9ee641c 100644
65352 --- a/fs/stat.c
65353 +++ b/fs/stat.c
65354 @@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
65355 stat->gid = inode->i_gid;
65356 stat->rdev = inode->i_rdev;
65357 stat->size = i_size_read(inode);
65358 - stat->atime = inode->i_atime;
65359 - stat->mtime = inode->i_mtime;
65360 + if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
65361 + stat->atime = inode->i_ctime;
65362 + stat->mtime = inode->i_ctime;
65363 + } else {
65364 + stat->atime = inode->i_atime;
65365 + stat->mtime = inode->i_mtime;
65366 + }
65367 stat->ctime = inode->i_ctime;
65368 stat->blksize = (1 << inode->i_blkbits);
65369 stat->blocks = inode->i_blocks;
65370 @@ -52,9 +57,16 @@ EXPORT_SYMBOL(generic_fillattr);
65371 int vfs_getattr_nosec(struct path *path, struct kstat *stat)
65372 {
65373 struct inode *inode = path->dentry->d_inode;
65374 + int retval;
65375
65376 - if (inode->i_op->getattr)
65377 - return inode->i_op->getattr(path->mnt, path->dentry, stat);
65378 + if (inode->i_op->getattr) {
65379 + retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
65380 + if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
65381 + stat->atime = stat->ctime;
65382 + stat->mtime = stat->ctime;
65383 + }
65384 + return retval;
65385 + }
65386
65387 generic_fillattr(inode, stat);
65388 return 0;
65389 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
65390 index 0b45ff4..847de5b 100644
65391 --- a/fs/sysfs/dir.c
65392 +++ b/fs/sysfs/dir.c
65393 @@ -41,9 +41,16 @@ void sysfs_warn_dup(struct kernfs_node *parent, const char *name)
65394 int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
65395 {
65396 struct kernfs_node *parent, *kn;
65397 + const char *name;
65398 + umode_t mode = S_IRWXU | S_IRUGO | S_IXUGO;
65399 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
65400 + const char *parent_name;
65401 +#endif
65402
65403 BUG_ON(!kobj);
65404
65405 + name = kobject_name(kobj);
65406 +
65407 if (kobj->parent)
65408 parent = kobj->parent->sd;
65409 else
65410 @@ -52,11 +59,22 @@ int sysfs_create_dir_ns(struct kobject *kobj, const void *ns)
65411 if (!parent)
65412 return -ENOENT;
65413
65414 - kn = kernfs_create_dir_ns(parent, kobject_name(kobj),
65415 - S_IRWXU | S_IRUGO | S_IXUGO, kobj, ns);
65416 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
65417 + parent_name = parent->name;
65418 + mode = S_IRWXU;
65419 +
65420 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
65421 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
65422 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
65423 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
65424 + mode = S_IRWXU | S_IRUGO | S_IXUGO;
65425 +#endif
65426 +
65427 + kn = kernfs_create_dir_ns(parent, name,
65428 + mode, kobj, ns);
65429 if (IS_ERR(kn)) {
65430 if (PTR_ERR(kn) == -EEXIST)
65431 - sysfs_warn_dup(parent, kobject_name(kobj));
65432 + sysfs_warn_dup(parent, name);
65433 return PTR_ERR(kn);
65434 }
65435
65436 diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
65437 index 69d4889..a810bd4 100644
65438 --- a/fs/sysv/sysv.h
65439 +++ b/fs/sysv/sysv.h
65440 @@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
65441 #endif
65442 }
65443
65444 -static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
65445 +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
65446 {
65447 if (sbi->s_bytesex == BYTESEX_PDP)
65448 return PDP_swab((__force __u32)n);
65449 diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
65450 index e18b988..f1d4ad0f 100644
65451 --- a/fs/ubifs/io.c
65452 +++ b/fs/ubifs/io.c
65453 @@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
65454 return err;
65455 }
65456
65457 -int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
65458 +int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
65459 {
65460 int err;
65461
65462 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
65463 index c175b4d..8f36a16 100644
65464 --- a/fs/udf/misc.c
65465 +++ b/fs/udf/misc.c
65466 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
65467
65468 u8 udf_tag_checksum(const struct tag *t)
65469 {
65470 - u8 *data = (u8 *)t;
65471 + const u8 *data = (const u8 *)t;
65472 u8 checksum = 0;
65473 int i;
65474 for (i = 0; i < sizeof(struct tag); ++i)
65475 diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
65476 index 8d974c4..b82f6ec 100644
65477 --- a/fs/ufs/swab.h
65478 +++ b/fs/ufs/swab.h
65479 @@ -22,7 +22,7 @@ enum {
65480 BYTESEX_BE
65481 };
65482
65483 -static inline u64
65484 +static inline u64 __intentional_overflow(-1)
65485 fs64_to_cpu(struct super_block *sbp, __fs64 n)
65486 {
65487 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
65488 @@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
65489 return (__force __fs64)cpu_to_be64(n);
65490 }
65491
65492 -static inline u32
65493 +static inline u32 __intentional_overflow(-1)
65494 fs32_to_cpu(struct super_block *sbp, __fs32 n)
65495 {
65496 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
65497 diff --git a/fs/utimes.c b/fs/utimes.c
65498 index aa138d6..5f3a811 100644
65499 --- a/fs/utimes.c
65500 +++ b/fs/utimes.c
65501 @@ -1,6 +1,7 @@
65502 #include <linux/compiler.h>
65503 #include <linux/file.h>
65504 #include <linux/fs.h>
65505 +#include <linux/security.h>
65506 #include <linux/linkage.h>
65507 #include <linux/mount.h>
65508 #include <linux/namei.h>
65509 @@ -103,6 +104,12 @@ static int utimes_common(struct path *path, struct timespec *times)
65510 }
65511 }
65512 retry_deleg:
65513 +
65514 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
65515 + error = -EACCES;
65516 + goto mnt_drop_write_and_out;
65517 + }
65518 +
65519 mutex_lock(&inode->i_mutex);
65520 error = notify_change(path->dentry, &newattrs, &delegated_inode);
65521 mutex_unlock(&inode->i_mutex);
65522 diff --git a/fs/xattr.c b/fs/xattr.c
65523 index 3377dff..f394815 100644
65524 --- a/fs/xattr.c
65525 +++ b/fs/xattr.c
65526 @@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
65527 return rc;
65528 }
65529
65530 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
65531 +ssize_t
65532 +pax_getxattr(struct dentry *dentry, void *value, size_t size)
65533 +{
65534 + struct inode *inode = dentry->d_inode;
65535 + ssize_t error;
65536 +
65537 + error = inode_permission(inode, MAY_EXEC);
65538 + if (error)
65539 + return error;
65540 +
65541 + if (inode->i_op->getxattr)
65542 + error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
65543 + else
65544 + error = -EOPNOTSUPP;
65545 +
65546 + return error;
65547 +}
65548 +EXPORT_SYMBOL(pax_getxattr);
65549 +#endif
65550 +
65551 ssize_t
65552 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
65553 {
65554 @@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
65555 * Extended attribute SET operations
65556 */
65557 static long
65558 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
65559 +setxattr(struct path *path, const char __user *name, const void __user *value,
65560 size_t size, int flags)
65561 {
65562 int error;
65563 @@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
65564 posix_acl_fix_xattr_from_user(kvalue, size);
65565 }
65566
65567 - error = vfs_setxattr(d, kname, kvalue, size, flags);
65568 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
65569 + error = -EACCES;
65570 + goto out;
65571 + }
65572 +
65573 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
65574 out:
65575 if (vvalue)
65576 vfree(vvalue);
65577 @@ -377,7 +403,7 @@ retry:
65578 return error;
65579 error = mnt_want_write(path.mnt);
65580 if (!error) {
65581 - error = setxattr(path.dentry, name, value, size, flags);
65582 + error = setxattr(&path, name, value, size, flags);
65583 mnt_drop_write(path.mnt);
65584 }
65585 path_put(&path);
65586 @@ -401,7 +427,7 @@ retry:
65587 return error;
65588 error = mnt_want_write(path.mnt);
65589 if (!error) {
65590 - error = setxattr(path.dentry, name, value, size, flags);
65591 + error = setxattr(&path, name, value, size, flags);
65592 mnt_drop_write(path.mnt);
65593 }
65594 path_put(&path);
65595 @@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
65596 const void __user *,value, size_t, size, int, flags)
65597 {
65598 struct fd f = fdget(fd);
65599 - struct dentry *dentry;
65600 int error = -EBADF;
65601
65602 if (!f.file)
65603 return error;
65604 - dentry = f.file->f_path.dentry;
65605 - audit_inode(NULL, dentry, 0);
65606 + audit_inode(NULL, f.file->f_path.dentry, 0);
65607 error = mnt_want_write_file(f.file);
65608 if (!error) {
65609 - error = setxattr(dentry, name, value, size, flags);
65610 + error = setxattr(&f.file->f_path, name, value, size, flags);
65611 mnt_drop_write_file(f.file);
65612 }
65613 fdput(f);
65614 @@ -626,7 +650,7 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
65615 * Extended attribute REMOVE operations
65616 */
65617 static long
65618 -removexattr(struct dentry *d, const char __user *name)
65619 +removexattr(struct path *path, const char __user *name)
65620 {
65621 int error;
65622 char kname[XATTR_NAME_MAX + 1];
65623 @@ -637,7 +661,10 @@ removexattr(struct dentry *d, const char __user *name)
65624 if (error < 0)
65625 return error;
65626
65627 - return vfs_removexattr(d, kname);
65628 + if (!gr_acl_handle_removexattr(path->dentry, path->mnt))
65629 + return -EACCES;
65630 +
65631 + return vfs_removexattr(path->dentry, kname);
65632 }
65633
65634 SYSCALL_DEFINE2(removexattr, const char __user *, pathname,
65635 @@ -652,7 +679,7 @@ retry:
65636 return error;
65637 error = mnt_want_write(path.mnt);
65638 if (!error) {
65639 - error = removexattr(path.dentry, name);
65640 + error = removexattr(&path, name);
65641 mnt_drop_write(path.mnt);
65642 }
65643 path_put(&path);
65644 @@ -675,7 +702,7 @@ retry:
65645 return error;
65646 error = mnt_want_write(path.mnt);
65647 if (!error) {
65648 - error = removexattr(path.dentry, name);
65649 + error = removexattr(&path, name);
65650 mnt_drop_write(path.mnt);
65651 }
65652 path_put(&path);
65653 @@ -689,16 +716,16 @@ retry:
65654 SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
65655 {
65656 struct fd f = fdget(fd);
65657 - struct dentry *dentry;
65658 + struct path *path;
65659 int error = -EBADF;
65660
65661 if (!f.file)
65662 return error;
65663 - dentry = f.file->f_path.dentry;
65664 - audit_inode(NULL, dentry, 0);
65665 + path = &f.file->f_path;
65666 + audit_inode(NULL, path->dentry, 0);
65667 error = mnt_want_write_file(f.file);
65668 if (!error) {
65669 - error = removexattr(dentry, name);
65670 + error = removexattr(path, name);
65671 mnt_drop_write_file(f.file);
65672 }
65673 fdput(f);
65674 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
65675 index f0efc7e..ba72910 100644
65676 --- a/fs/xfs/xfs_bmap.c
65677 +++ b/fs/xfs/xfs_bmap.c
65678 @@ -584,7 +584,7 @@ xfs_bmap_validate_ret(
65679
65680 #else
65681 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
65682 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
65683 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
65684 #endif /* DEBUG */
65685
65686 /*
65687 diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
65688 index aead369..0dfecfd 100644
65689 --- a/fs/xfs/xfs_dir2_readdir.c
65690 +++ b/fs/xfs/xfs_dir2_readdir.c
65691 @@ -160,7 +160,12 @@ xfs_dir2_sf_getdents(
65692 ino = dp->d_ops->sf_get_ino(sfp, sfep);
65693 filetype = dp->d_ops->sf_get_ftype(sfep);
65694 ctx->pos = off & 0x7fffffff;
65695 - if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
65696 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
65697 + char name[sfep->namelen];
65698 + memcpy(name, sfep->name, sfep->namelen);
65699 + if (!dir_emit(ctx, name, sfep->namelen, ino, xfs_dir3_get_dtype(mp, filetype)))
65700 + return 0;
65701 + } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
65702 xfs_dir3_get_dtype(mp, filetype)))
65703 return 0;
65704 sfep = dp->d_ops->sf_nextentry(sfp, sfep);
65705 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
65706 index 6152cbe..f0f9eaa 100644
65707 --- a/fs/xfs/xfs_ioctl.c
65708 +++ b/fs/xfs/xfs_ioctl.c
65709 @@ -122,7 +122,7 @@ xfs_find_handle(
65710 }
65711
65712 error = -EFAULT;
65713 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
65714 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
65715 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
65716 goto out_put;
65717
65718 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
65719 new file mode 100644
65720 index 0000000..bfd482c
65721 --- /dev/null
65722 +++ b/grsecurity/Kconfig
65723 @@ -0,0 +1,1176 @@
65724 +#
65725 +# grecurity configuration
65726 +#
65727 +menu "Memory Protections"
65728 +depends on GRKERNSEC
65729 +
65730 +config GRKERNSEC_KMEM
65731 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
65732 + default y if GRKERNSEC_CONFIG_AUTO
65733 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
65734 + help
65735 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
65736 + be written to or read from to modify or leak the contents of the running
65737 + kernel. /dev/port will also not be allowed to be opened, writing to
65738 + /dev/cpu/*/msr will be prevented, and support for kexec will be removed.
65739 + If you have module support disabled, enabling this will close up several
65740 + ways that are currently used to insert malicious code into the running
65741 + kernel.
65742 +
65743 + Even with this feature enabled, we still highly recommend that
65744 + you use the RBAC system, as it is still possible for an attacker to
65745 + modify the running kernel through other more obscure methods.
65746 +
65747 + It is highly recommended that you say Y here if you meet all the
65748 + conditions above.
65749 +
65750 +config GRKERNSEC_VM86
65751 + bool "Restrict VM86 mode"
65752 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
65753 + depends on X86_32
65754 +
65755 + help
65756 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
65757 + make use of a special execution mode on 32bit x86 processors called
65758 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
65759 + video cards and will still work with this option enabled. The purpose
65760 + of the option is to prevent exploitation of emulation errors in
65761 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
65762 + Nearly all users should be able to enable this option.
65763 +
65764 +config GRKERNSEC_IO
65765 + bool "Disable privileged I/O"
65766 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
65767 + depends on X86
65768 + select RTC_CLASS
65769 + select RTC_INTF_DEV
65770 + select RTC_DRV_CMOS
65771 +
65772 + help
65773 + If you say Y here, all ioperm and iopl calls will return an error.
65774 + Ioperm and iopl can be used to modify the running kernel.
65775 + Unfortunately, some programs need this access to operate properly,
65776 + the most notable of which are XFree86 and hwclock. hwclock can be
65777 + remedied by having RTC support in the kernel, so real-time
65778 + clock support is enabled if this option is enabled, to ensure
65779 + that hwclock operates correctly. If hwclock still does not work,
65780 + either update udev or symlink /dev/rtc to /dev/rtc0.
65781 +
65782 + If you're using XFree86 or a version of Xorg from 2012 or earlier,
65783 + you may not be able to boot into a graphical environment with this
65784 + option enabled. In this case, you should use the RBAC system instead.
65785 +
65786 +config GRKERNSEC_JIT_HARDEN
65787 + bool "Harden BPF JIT against spray attacks"
65788 + default y if GRKERNSEC_CONFIG_AUTO
65789 + depends on BPF_JIT && X86
65790 + help
65791 + If you say Y here, the native code generated by the kernel's Berkeley
65792 + Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
65793 + attacks that attempt to fit attacker-beneficial instructions in
65794 + 32bit immediate fields of JIT-generated native instructions. The
65795 + attacker will generally aim to cause an unintended instruction sequence
65796 + of JIT-generated native code to execute by jumping into the middle of
65797 + a generated instruction. This feature effectively randomizes the 32bit
65798 + immediate constants present in the generated code to thwart such attacks.
65799 +
65800 + If you're using KERNEXEC, it's recommended that you enable this option
65801 + to supplement the hardening of the kernel.
65802 +
65803 +config GRKERNSEC_PERF_HARDEN
65804 + bool "Disable unprivileged PERF_EVENTS usage by default"
65805 + default y if GRKERNSEC_CONFIG_AUTO
65806 + depends on PERF_EVENTS
65807 + help
65808 + If you say Y here, the range of acceptable values for the
65809 + /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
65810 + default to a new value: 3. When the sysctl is set to this value, no
65811 + unprivileged use of the PERF_EVENTS syscall interface will be permitted.
65812 +
65813 + Though PERF_EVENTS can be used legitimately for performance monitoring
65814 + and low-level application profiling, it is forced on regardless of
65815 + configuration, has been at fault for several vulnerabilities, and
65816 + creates new opportunities for side channels and other information leaks.
65817 +
65818 + This feature puts PERF_EVENTS into a secure default state and permits
65819 + the administrator to change out of it temporarily if unprivileged
65820 + application profiling is needed.
65821 +
65822 +config GRKERNSEC_RAND_THREADSTACK
65823 + bool "Insert random gaps between thread stacks"
65824 + default y if GRKERNSEC_CONFIG_AUTO
65825 + depends on PAX_RANDMMAP && !PPC
65826 + help
65827 + If you say Y here, a random-sized gap will be enforced between allocated
65828 + thread stacks. Glibc's NPTL and other threading libraries that
65829 + pass MAP_STACK to the kernel for thread stack allocation are supported.
65830 + The implementation currently provides 8 bits of entropy for the gap.
65831 +
65832 + Many distributions do not compile threaded remote services with the
65833 + -fstack-check argument to GCC, causing the variable-sized stack-based
65834 + allocator, alloca(), to not probe the stack on allocation. This
65835 + permits an unbounded alloca() to skip over any guard page and potentially
65836 + modify another thread's stack reliably. An enforced random gap
65837 + reduces the reliability of such an attack and increases the chance
65838 + that such a read/write to another thread's stack instead lands in
65839 + an unmapped area, causing a crash and triggering grsecurity's
65840 + anti-bruteforcing logic.
65841 +
65842 +config GRKERNSEC_PROC_MEMMAP
65843 + bool "Harden ASLR against information leaks and entropy reduction"
65844 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
65845 + depends on PAX_NOEXEC || PAX_ASLR
65846 + help
65847 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
65848 + give no information about the addresses of its mappings if
65849 + PaX features that rely on random addresses are enabled on the task.
65850 + In addition to sanitizing this information and disabling other
65851 + dangerous sources of information, this option causes reads of sensitive
65852 + /proc/<pid> entries where the file descriptor was opened in a different
65853 + task than the one performing the read. Such attempts are logged.
65854 + This option also limits argv/env strings for suid/sgid binaries
65855 + to 512KB to prevent a complete exhaustion of the stack entropy provided
65856 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
65857 + binaries to prevent alternative mmap layouts from being abused.
65858 +
65859 + If you use PaX it is essential that you say Y here as it closes up
65860 + several holes that make full ASLR useless locally.
65861 +
65862 +
65863 +config GRKERNSEC_KSTACKOVERFLOW
65864 + bool "Prevent kernel stack overflows"
65865 + default y if GRKERNSEC_CONFIG_AUTO
65866 + depends on !IA64 && 64BIT
65867 + help
65868 + If you say Y here, the kernel's process stacks will be allocated
65869 + with vmalloc instead of the kernel's default allocator. This
65870 + introduces guard pages that in combination with the alloca checking
65871 + of the STACKLEAK feature prevents all forms of kernel process stack
65872 + overflow abuse. Note that this is different from kernel stack
65873 + buffer overflows.
65874 +
65875 +config GRKERNSEC_BRUTE
65876 + bool "Deter exploit bruteforcing"
65877 + default y if GRKERNSEC_CONFIG_AUTO
65878 + help
65879 + If you say Y here, attempts to bruteforce exploits against forking
65880 + daemons such as apache or sshd, as well as against suid/sgid binaries
65881 + will be deterred. When a child of a forking daemon is killed by PaX
65882 + or crashes due to an illegal instruction or other suspicious signal,
65883 + the parent process will be delayed 30 seconds upon every subsequent
65884 + fork until the administrator is able to assess the situation and
65885 + restart the daemon.
65886 + In the suid/sgid case, the attempt is logged, the user has all their
65887 + existing instances of the suid/sgid binary terminated and will
65888 + be unable to execute any suid/sgid binaries for 15 minutes.
65889 +
65890 + It is recommended that you also enable signal logging in the auditing
65891 + section so that logs are generated when a process triggers a suspicious
65892 + signal.
65893 + If the sysctl option is enabled, a sysctl option with name
65894 + "deter_bruteforce" is created.
65895 +
65896 +config GRKERNSEC_MODHARDEN
65897 + bool "Harden module auto-loading"
65898 + default y if GRKERNSEC_CONFIG_AUTO
65899 + depends on MODULES
65900 + help
65901 + If you say Y here, module auto-loading in response to use of some
65902 + feature implemented by an unloaded module will be restricted to
65903 + root users. Enabling this option helps defend against attacks
65904 + by unprivileged users who abuse the auto-loading behavior to
65905 + cause a vulnerable module to load that is then exploited.
65906 +
65907 + If this option prevents a legitimate use of auto-loading for a
65908 + non-root user, the administrator can execute modprobe manually
65909 + with the exact name of the module mentioned in the alert log.
65910 + Alternatively, the administrator can add the module to the list
65911 + of modules loaded at boot by modifying init scripts.
65912 +
65913 + Modification of init scripts will most likely be needed on
65914 + Ubuntu servers with encrypted home directory support enabled,
65915 + as the first non-root user logging in will cause the ecb(aes),
65916 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
65917 +
65918 +config GRKERNSEC_HIDESYM
65919 + bool "Hide kernel symbols"
65920 + default y if GRKERNSEC_CONFIG_AUTO
65921 + select PAX_USERCOPY_SLABS
65922 + help
65923 + If you say Y here, getting information on loaded modules, and
65924 + displaying all kernel symbols through a syscall will be restricted
65925 + to users with CAP_SYS_MODULE. For software compatibility reasons,
65926 + /proc/kallsyms will be restricted to the root user. The RBAC
65927 + system can hide that entry even from root.
65928 +
65929 + This option also prevents leaking of kernel addresses through
65930 + several /proc entries.
65931 +
65932 + Note that this option is only effective provided the following
65933 + conditions are met:
65934 + 1) The kernel using grsecurity is not precompiled by some distribution
65935 + 2) You have also enabled GRKERNSEC_DMESG
65936 + 3) You are using the RBAC system and hiding other files such as your
65937 + kernel image and System.map. Alternatively, enabling this option
65938 + causes the permissions on /boot, /lib/modules, and the kernel
65939 + source directory to change at compile time to prevent
65940 + reading by non-root users.
65941 + If the above conditions are met, this option will aid in providing a
65942 + useful protection against local kernel exploitation of overflows
65943 + and arbitrary read/write vulnerabilities.
65944 +
65945 + It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
65946 + in addition to this feature.
65947 +
65948 +config GRKERNSEC_RANDSTRUCT
65949 + bool "Randomize layout of sensitive kernel structures"
65950 + default y if GRKERNSEC_CONFIG_AUTO
65951 + select GRKERNSEC_HIDESYM
65952 + select MODVERSIONS if MODULES
65953 + help
65954 + If you say Y here, the layouts of a number of sensitive kernel
65955 + structures (task, fs, cred, etc) and all structures composed entirely
65956 + of function pointers (aka "ops" structs) will be randomized at compile-time.
65957 + This can introduce the requirement of an additional infoleak
65958 + vulnerability for exploits targeting these structure types.
65959 +
65960 + Enabling this feature will introduce some performance impact, slightly
65961 + increase memory usage, and prevent the use of forensic tools like
65962 + Volatility against the system (unless the kernel source tree isn't
65963 + cleaned after kernel installation).
65964 +
65965 + The seed used for compilation is located at tools/gcc/randomize_layout_seed.h.
65966 + It remains after a make clean to allow for external modules to be compiled
65967 + with the existing seed and will be removed by a make mrproper or
65968 + make distclean.
65969 +
65970 + Note that the implementation requires gcc 4.6.4. or newer. You may need
65971 + to install the supporting headers explicitly in addition to the normal
65972 + gcc package.
65973 +
65974 +config GRKERNSEC_RANDSTRUCT_PERFORMANCE
65975 + bool "Use cacheline-aware structure randomization"
65976 + depends on GRKERNSEC_RANDSTRUCT
65977 + default y if GRKERNSEC_CONFIG_PRIORITY_PERF
65978 + help
65979 + If you say Y here, the RANDSTRUCT randomization will make a best effort
65980 + at restricting randomization to cacheline-sized groups of elements. It
65981 + will further not randomize bitfields in structures. This reduces the
65982 + performance hit of RANDSTRUCT at the cost of weakened randomization.
65983 +
65984 +config GRKERNSEC_KERN_LOCKOUT
65985 + bool "Active kernel exploit response"
65986 + default y if GRKERNSEC_CONFIG_AUTO
65987 + depends on X86 || ARM || PPC || SPARC
65988 + help
65989 + If you say Y here, when a PaX alert is triggered due to suspicious
65990 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
65991 + or an OOPS occurs due to bad memory accesses, instead of just
65992 + terminating the offending process (and potentially allowing
65993 + a subsequent exploit from the same user), we will take one of two
65994 + actions:
65995 + If the user was root, we will panic the system
65996 + If the user was non-root, we will log the attempt, terminate
65997 + all processes owned by the user, then prevent them from creating
65998 + any new processes until the system is restarted
65999 + This deters repeated kernel exploitation/bruteforcing attempts
66000 + and is useful for later forensics.
66001 +
66002 +config GRKERNSEC_OLD_ARM_USERLAND
66003 + bool "Old ARM userland compatibility"
66004 + depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
66005 + help
66006 + If you say Y here, stubs of executable code to perform such operations
66007 + as "compare-exchange" will be placed at fixed locations in the ARM vector
66008 + table. This is unfortunately needed for old ARM userland meant to run
66009 + across a wide range of processors. Without this option enabled,
66010 + the get_tls and data memory barrier stubs will be emulated by the kernel,
66011 + which is enough for Linaro userlands or other userlands designed for v6
66012 + and newer ARM CPUs. It's recommended that you try without this option enabled
66013 + first, and only enable it if your userland does not boot (it will likely fail
66014 + at init time).
66015 +
66016 +endmenu
66017 +menu "Role Based Access Control Options"
66018 +depends on GRKERNSEC
66019 +
66020 +config GRKERNSEC_RBAC_DEBUG
66021 + bool
66022 +
66023 +config GRKERNSEC_NO_RBAC
66024 + bool "Disable RBAC system"
66025 + help
66026 + If you say Y here, the /dev/grsec device will be removed from the kernel,
66027 + preventing the RBAC system from being enabled. You should only say Y
66028 + here if you have no intention of using the RBAC system, so as to prevent
66029 + an attacker with root access from misusing the RBAC system to hide files
66030 + and processes when loadable module support and /dev/[k]mem have been
66031 + locked down.
66032 +
66033 +config GRKERNSEC_ACL_HIDEKERN
66034 + bool "Hide kernel processes"
66035 + help
66036 + If you say Y here, all kernel threads will be hidden to all
66037 + processes but those whose subject has the "view hidden processes"
66038 + flag.
66039 +
66040 +config GRKERNSEC_ACL_MAXTRIES
66041 + int "Maximum tries before password lockout"
66042 + default 3
66043 + help
66044 + This option enforces the maximum number of times a user can attempt
66045 + to authorize themselves with the grsecurity RBAC system before being
66046 + denied the ability to attempt authorization again for a specified time.
66047 + The lower the number, the harder it will be to brute-force a password.
66048 +
66049 +config GRKERNSEC_ACL_TIMEOUT
66050 + int "Time to wait after max password tries, in seconds"
66051 + default 30
66052 + help
66053 + This option specifies the time the user must wait after attempting to
66054 + authorize to the RBAC system with the maximum number of invalid
66055 + passwords. The higher the number, the harder it will be to brute-force
66056 + a password.
66057 +
66058 +endmenu
66059 +menu "Filesystem Protections"
66060 +depends on GRKERNSEC
66061 +
66062 +config GRKERNSEC_PROC
66063 + bool "Proc restrictions"
66064 + default y if GRKERNSEC_CONFIG_AUTO
66065 + help
66066 + If you say Y here, the permissions of the /proc filesystem
66067 + will be altered to enhance system security and privacy. You MUST
66068 + choose either a user only restriction or a user and group restriction.
66069 + Depending upon the option you choose, you can either restrict users to
66070 + see only the processes they themselves run, or choose a group that can
66071 + view all processes and files normally restricted to root if you choose
66072 + the "restrict to user only" option. NOTE: If you're running identd or
66073 + ntpd as a non-root user, you will have to run it as the group you
66074 + specify here.
66075 +
66076 +config GRKERNSEC_PROC_USER
66077 + bool "Restrict /proc to user only"
66078 + depends on GRKERNSEC_PROC
66079 + help
66080 + If you say Y here, non-root users will only be able to view their own
66081 + processes, and restricts them from viewing network-related information,
66082 + and viewing kernel symbol and module information.
66083 +
66084 +config GRKERNSEC_PROC_USERGROUP
66085 + bool "Allow special group"
66086 + default y if GRKERNSEC_CONFIG_AUTO
66087 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
66088 + help
66089 + If you say Y here, you will be able to select a group that will be
66090 + able to view all processes and network-related information. If you've
66091 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
66092 + remain hidden. This option is useful if you want to run identd as
66093 + a non-root user. The group you select may also be chosen at boot time
66094 + via "grsec_proc_gid=" on the kernel commandline.
66095 +
66096 +config GRKERNSEC_PROC_GID
66097 + int "GID for special group"
66098 + depends on GRKERNSEC_PROC_USERGROUP
66099 + default 1001
66100 +
66101 +config GRKERNSEC_PROC_ADD
66102 + bool "Additional restrictions"
66103 + default y if GRKERNSEC_CONFIG_AUTO
66104 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
66105 + help
66106 + If you say Y here, additional restrictions will be placed on
66107 + /proc that keep normal users from viewing device information and
66108 + slabinfo information that could be useful for exploits.
66109 +
66110 +config GRKERNSEC_LINK
66111 + bool "Linking restrictions"
66112 + default y if GRKERNSEC_CONFIG_AUTO
66113 + help
66114 + If you say Y here, /tmp race exploits will be prevented, since users
66115 + will no longer be able to follow symlinks owned by other users in
66116 + world-writable +t directories (e.g. /tmp), unless the owner of the
66117 + symlink is the owner of the directory. users will also not be
66118 + able to hardlink to files they do not own. If the sysctl option is
66119 + enabled, a sysctl option with name "linking_restrictions" is created.
66120 +
66121 +config GRKERNSEC_SYMLINKOWN
66122 + bool "Kernel-enforced SymlinksIfOwnerMatch"
66123 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
66124 + help
66125 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
66126 + that prevents it from being used as a security feature. As Apache
66127 + verifies the symlink by performing a stat() against the target of
66128 + the symlink before it is followed, an attacker can setup a symlink
66129 + to point to a same-owned file, then replace the symlink with one
66130 + that targets another user's file just after Apache "validates" the
66131 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
66132 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
66133 + will be in place for the group you specify. If the sysctl option
66134 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
66135 + created.
66136 +
66137 +config GRKERNSEC_SYMLINKOWN_GID
66138 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
66139 + depends on GRKERNSEC_SYMLINKOWN
66140 + default 1006
66141 + help
66142 + Setting this GID determines what group kernel-enforced
66143 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
66144 + is enabled, a sysctl option with name "symlinkown_gid" is created.
66145 +
66146 +config GRKERNSEC_FIFO
66147 + bool "FIFO restrictions"
66148 + default y if GRKERNSEC_CONFIG_AUTO
66149 + help
66150 + If you say Y here, users will not be able to write to FIFOs they don't
66151 + own in world-writable +t directories (e.g. /tmp), unless the owner of
66152 + the FIFO is the same owner of the directory it's held in. If the sysctl
66153 + option is enabled, a sysctl option with name "fifo_restrictions" is
66154 + created.
66155 +
66156 +config GRKERNSEC_SYSFS_RESTRICT
66157 + bool "Sysfs/debugfs restriction"
66158 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
66159 + depends on SYSFS
66160 + help
66161 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
66162 + any filesystem normally mounted under it (e.g. debugfs) will be
66163 + mostly accessible only by root. These filesystems generally provide access
66164 + to hardware and debug information that isn't appropriate for unprivileged
66165 + users of the system. Sysfs and debugfs have also become a large source
66166 + of new vulnerabilities, ranging from infoleaks to local compromise.
66167 + There has been very little oversight with an eye toward security involved
66168 + in adding new exporters of information to these filesystems, so their
66169 + use is discouraged.
66170 + For reasons of compatibility, a few directories have been whitelisted
66171 + for access by non-root users:
66172 + /sys/fs/selinux
66173 + /sys/fs/fuse
66174 + /sys/devices/system/cpu
66175 +
66176 +config GRKERNSEC_ROFS
66177 + bool "Runtime read-only mount protection"
66178 + depends on SYSCTL
66179 + help
66180 + If you say Y here, a sysctl option with name "romount_protect" will
66181 + be created. By setting this option to 1 at runtime, filesystems
66182 + will be protected in the following ways:
66183 + * No new writable mounts will be allowed
66184 + * Existing read-only mounts won't be able to be remounted read/write
66185 + * Write operations will be denied on all block devices
66186 + This option acts independently of grsec_lock: once it is set to 1,
66187 + it cannot be turned off. Therefore, please be mindful of the resulting
66188 + behavior if this option is enabled in an init script on a read-only
66189 + filesystem.
66190 + Also be aware that as with other root-focused features, GRKERNSEC_KMEM
66191 + and GRKERNSEC_IO should be enabled and module loading disabled via
66192 + config or at runtime.
66193 + This feature is mainly intended for secure embedded systems.
66194 +
66195 +
66196 +config GRKERNSEC_DEVICE_SIDECHANNEL
66197 + bool "Eliminate stat/notify-based device sidechannels"
66198 + default y if GRKERNSEC_CONFIG_AUTO
66199 + help
66200 + If you say Y here, timing analyses on block or character
66201 + devices like /dev/ptmx using stat or inotify/dnotify/fanotify
66202 + will be thwarted for unprivileged users. If a process without
66203 + CAP_MKNOD stats such a device, the last access and last modify times
66204 + will match the device's create time. No access or modify events
66205 + will be triggered through inotify/dnotify/fanotify for such devices.
66206 + This feature will prevent attacks that may at a minimum
66207 + allow an attacker to determine the administrator's password length.
66208 +
66209 +config GRKERNSEC_CHROOT
66210 + bool "Chroot jail restrictions"
66211 + default y if GRKERNSEC_CONFIG_AUTO
66212 + help
66213 + If you say Y here, you will be able to choose several options that will
66214 + make breaking out of a chrooted jail much more difficult. If you
66215 + encounter no software incompatibilities with the following options, it
66216 + is recommended that you enable each one.
66217 +
66218 + Note that the chroot restrictions are not intended to apply to "chroots"
66219 + to directories that are simple bind mounts of the global root filesystem.
66220 + For several other reasons, a user shouldn't expect any significant
66221 + security by performing such a chroot.
66222 +
66223 +config GRKERNSEC_CHROOT_MOUNT
66224 + bool "Deny mounts"
66225 + default y if GRKERNSEC_CONFIG_AUTO
66226 + depends on GRKERNSEC_CHROOT
66227 + help
66228 + If you say Y here, processes inside a chroot will not be able to
66229 + mount or remount filesystems. If the sysctl option is enabled, a
66230 + sysctl option with name "chroot_deny_mount" is created.
66231 +
66232 +config GRKERNSEC_CHROOT_DOUBLE
66233 + bool "Deny double-chroots"
66234 + default y if GRKERNSEC_CONFIG_AUTO
66235 + depends on GRKERNSEC_CHROOT
66236 + help
66237 + If you say Y here, processes inside a chroot will not be able to chroot
66238 + again outside the chroot. This is a widely used method of breaking
66239 + out of a chroot jail and should not be allowed. If the sysctl
66240 + option is enabled, a sysctl option with name
66241 + "chroot_deny_chroot" is created.
66242 +
66243 +config GRKERNSEC_CHROOT_PIVOT
66244 + bool "Deny pivot_root in chroot"
66245 + default y if GRKERNSEC_CONFIG_AUTO
66246 + depends on GRKERNSEC_CHROOT
66247 + help
66248 + If you say Y here, processes inside a chroot will not be able to use
66249 + a function called pivot_root() that was introduced in Linux 2.3.41. It
66250 + works similar to chroot in that it changes the root filesystem. This
66251 + function could be misused in a chrooted process to attempt to break out
66252 + of the chroot, and therefore should not be allowed. If the sysctl
66253 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
66254 + created.
66255 +
66256 +config GRKERNSEC_CHROOT_CHDIR
66257 + bool "Enforce chdir(\"/\") on all chroots"
66258 + default y if GRKERNSEC_CONFIG_AUTO
66259 + depends on GRKERNSEC_CHROOT
66260 + help
66261 + If you say Y here, the current working directory of all newly-chrooted
66262 + applications will be set to the the root directory of the chroot.
66263 + The man page on chroot(2) states:
66264 + Note that this call does not change the current working
66265 + directory, so that `.' can be outside the tree rooted at
66266 + `/'. In particular, the super-user can escape from a
66267 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
66268 +
66269 + It is recommended that you say Y here, since it's not known to break
66270 + any software. If the sysctl option is enabled, a sysctl option with
66271 + name "chroot_enforce_chdir" is created.
66272 +
66273 +config GRKERNSEC_CHROOT_CHMOD
66274 + bool "Deny (f)chmod +s"
66275 + default y if GRKERNSEC_CONFIG_AUTO
66276 + depends on GRKERNSEC_CHROOT
66277 + help
66278 + If you say Y here, processes inside a chroot will not be able to chmod
66279 + or fchmod files to make them have suid or sgid bits. This protects
66280 + against another published method of breaking a chroot. If the sysctl
66281 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
66282 + created.
66283 +
66284 +config GRKERNSEC_CHROOT_FCHDIR
66285 + bool "Deny fchdir and fhandle out of chroot"
66286 + default y if GRKERNSEC_CONFIG_AUTO
66287 + depends on GRKERNSEC_CHROOT
66288 + help
66289 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
66290 + to a file descriptor of the chrooting process that points to a directory
66291 + outside the filesystem will be stopped. Additionally, this option prevents
66292 + use of the recently-created syscall for opening files by a guessable "file
66293 + handle" inside a chroot. If the sysctl option is enabled, a sysctl option
66294 + with name "chroot_deny_fchdir" is created.
66295 +
66296 +config GRKERNSEC_CHROOT_MKNOD
66297 + bool "Deny mknod"
66298 + default y if GRKERNSEC_CONFIG_AUTO
66299 + depends on GRKERNSEC_CHROOT
66300 + help
66301 + If you say Y here, processes inside a chroot will not be allowed to
66302 + mknod. The problem with using mknod inside a chroot is that it
66303 + would allow an attacker to create a device entry that is the same
66304 + as one on the physical root of your system, which could range from
66305 + anything from the console device to a device for your harddrive (which
66306 + they could then use to wipe the drive or steal data). It is recommended
66307 + that you say Y here, unless you run into software incompatibilities.
66308 + If the sysctl option is enabled, a sysctl option with name
66309 + "chroot_deny_mknod" is created.
66310 +
66311 +config GRKERNSEC_CHROOT_SHMAT
66312 + bool "Deny shmat() out of chroot"
66313 + default y if GRKERNSEC_CONFIG_AUTO
66314 + depends on GRKERNSEC_CHROOT
66315 + help
66316 + If you say Y here, processes inside a chroot will not be able to attach
66317 + to shared memory segments that were created outside of the chroot jail.
66318 + It is recommended that you say Y here. If the sysctl option is enabled,
66319 + a sysctl option with name "chroot_deny_shmat" is created.
66320 +
66321 +config GRKERNSEC_CHROOT_UNIX
66322 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
66323 + default y if GRKERNSEC_CONFIG_AUTO
66324 + depends on GRKERNSEC_CHROOT
66325 + help
66326 + If you say Y here, processes inside a chroot will not be able to
66327 + connect to abstract (meaning not belonging to a filesystem) Unix
66328 + domain sockets that were bound outside of a chroot. It is recommended
66329 + that you say Y here. If the sysctl option is enabled, a sysctl option
66330 + with name "chroot_deny_unix" is created.
66331 +
66332 +config GRKERNSEC_CHROOT_FINDTASK
66333 + bool "Protect outside processes"
66334 + default y if GRKERNSEC_CONFIG_AUTO
66335 + depends on GRKERNSEC_CHROOT
66336 + help
66337 + If you say Y here, processes inside a chroot will not be able to
66338 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
66339 + getsid, or view any process outside of the chroot. If the sysctl
66340 + option is enabled, a sysctl option with name "chroot_findtask" is
66341 + created.
66342 +
66343 +config GRKERNSEC_CHROOT_NICE
66344 + bool "Restrict priority changes"
66345 + default y if GRKERNSEC_CONFIG_AUTO
66346 + depends on GRKERNSEC_CHROOT
66347 + help
66348 + If you say Y here, processes inside a chroot will not be able to raise
66349 + the priority of processes in the chroot, or alter the priority of
66350 + processes outside the chroot. This provides more security than simply
66351 + removing CAP_SYS_NICE from the process' capability set. If the
66352 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
66353 + is created.
66354 +
66355 +config GRKERNSEC_CHROOT_SYSCTL
66356 + bool "Deny sysctl writes"
66357 + default y if GRKERNSEC_CONFIG_AUTO
66358 + depends on GRKERNSEC_CHROOT
66359 + help
66360 + If you say Y here, an attacker in a chroot will not be able to
66361 + write to sysctl entries, either by sysctl(2) or through a /proc
66362 + interface. It is strongly recommended that you say Y here. If the
66363 + sysctl option is enabled, a sysctl option with name
66364 + "chroot_deny_sysctl" is created.
66365 +
66366 +config GRKERNSEC_CHROOT_CAPS
66367 + bool "Capability restrictions"
66368 + default y if GRKERNSEC_CONFIG_AUTO
66369 + depends on GRKERNSEC_CHROOT
66370 + help
66371 + If you say Y here, the capabilities on all processes within a
66372 + chroot jail will be lowered to stop module insertion, raw i/o,
66373 + system and net admin tasks, rebooting the system, modifying immutable
66374 + files, modifying IPC owned by another, and changing the system time.
66375 + This is left an option because it can break some apps. Disable this
66376 + if your chrooted apps are having problems performing those kinds of
66377 + tasks. If the sysctl option is enabled, a sysctl option with
66378 + name "chroot_caps" is created.
66379 +
66380 +config GRKERNSEC_CHROOT_INITRD
66381 + bool "Exempt initrd tasks from restrictions"
66382 + default y if GRKERNSEC_CONFIG_AUTO
66383 + depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
66384 + help
66385 + If you say Y here, tasks started prior to init will be exempted from
66386 + grsecurity's chroot restrictions. This option is mainly meant to
66387 + resolve Plymouth's performing privileged operations unnecessarily
66388 + in a chroot.
66389 +
66390 +endmenu
66391 +menu "Kernel Auditing"
66392 +depends on GRKERNSEC
66393 +
66394 +config GRKERNSEC_AUDIT_GROUP
66395 + bool "Single group for auditing"
66396 + help
66397 + If you say Y here, the exec and chdir logging features will only operate
66398 + on a group you specify. This option is recommended if you only want to
66399 + watch certain users instead of having a large amount of logs from the
66400 + entire system. If the sysctl option is enabled, a sysctl option with
66401 + name "audit_group" is created.
66402 +
66403 +config GRKERNSEC_AUDIT_GID
66404 + int "GID for auditing"
66405 + depends on GRKERNSEC_AUDIT_GROUP
66406 + default 1007
66407 +
66408 +config GRKERNSEC_EXECLOG
66409 + bool "Exec logging"
66410 + help
66411 + If you say Y here, all execve() calls will be logged (since the
66412 + other exec*() calls are frontends to execve(), all execution
66413 + will be logged). Useful for shell-servers that like to keep track
66414 + of their users. If the sysctl option is enabled, a sysctl option with
66415 + name "exec_logging" is created.
66416 + WARNING: This option when enabled will produce a LOT of logs, especially
66417 + on an active system.
66418 +
66419 +config GRKERNSEC_RESLOG
66420 + bool "Resource logging"
66421 + default y if GRKERNSEC_CONFIG_AUTO
66422 + help
66423 + If you say Y here, all attempts to overstep resource limits will
66424 + be logged with the resource name, the requested size, and the current
66425 + limit. It is highly recommended that you say Y here. If the sysctl
66426 + option is enabled, a sysctl option with name "resource_logging" is
66427 + created. If the RBAC system is enabled, the sysctl value is ignored.
66428 +
66429 +config GRKERNSEC_CHROOT_EXECLOG
66430 + bool "Log execs within chroot"
66431 + help
66432 + If you say Y here, all executions inside a chroot jail will be logged
66433 + to syslog. This can cause a large amount of logs if certain
66434 + applications (eg. djb's daemontools) are installed on the system, and
66435 + is therefore left as an option. If the sysctl option is enabled, a
66436 + sysctl option with name "chroot_execlog" is created.
66437 +
66438 +config GRKERNSEC_AUDIT_PTRACE
66439 + bool "Ptrace logging"
66440 + help
66441 + If you say Y here, all attempts to attach to a process via ptrace
66442 + will be logged. If the sysctl option is enabled, a sysctl option
66443 + with name "audit_ptrace" is created.
66444 +
66445 +config GRKERNSEC_AUDIT_CHDIR
66446 + bool "Chdir logging"
66447 + help
66448 + If you say Y here, all chdir() calls will be logged. If the sysctl
66449 + option is enabled, a sysctl option with name "audit_chdir" is created.
66450 +
66451 +config GRKERNSEC_AUDIT_MOUNT
66452 + bool "(Un)Mount logging"
66453 + help
66454 + If you say Y here, all mounts and unmounts will be logged. If the
66455 + sysctl option is enabled, a sysctl option with name "audit_mount" is
66456 + created.
66457 +
66458 +config GRKERNSEC_SIGNAL
66459 + bool "Signal logging"
66460 + default y if GRKERNSEC_CONFIG_AUTO
66461 + help
66462 + If you say Y here, certain important signals will be logged, such as
66463 + SIGSEGV, which will as a result inform you of when a error in a program
66464 + occurred, which in some cases could mean a possible exploit attempt.
66465 + If the sysctl option is enabled, a sysctl option with name
66466 + "signal_logging" is created.
66467 +
66468 +config GRKERNSEC_FORKFAIL
66469 + bool "Fork failure logging"
66470 + help
66471 + If you say Y here, all failed fork() attempts will be logged.
66472 + This could suggest a fork bomb, or someone attempting to overstep
66473 + their process limit. If the sysctl option is enabled, a sysctl option
66474 + with name "forkfail_logging" is created.
66475 +
66476 +config GRKERNSEC_TIME
66477 + bool "Time change logging"
66478 + default y if GRKERNSEC_CONFIG_AUTO
66479 + help
66480 + If you say Y here, any changes of the system clock will be logged.
66481 + If the sysctl option is enabled, a sysctl option with name
66482 + "timechange_logging" is created.
66483 +
66484 +config GRKERNSEC_PROC_IPADDR
66485 + bool "/proc/<pid>/ipaddr support"
66486 + default y if GRKERNSEC_CONFIG_AUTO
66487 + help
66488 + If you say Y here, a new entry will be added to each /proc/<pid>
66489 + directory that contains the IP address of the person using the task.
66490 + The IP is carried across local TCP and AF_UNIX stream sockets.
66491 + This information can be useful for IDS/IPSes to perform remote response
66492 + to a local attack. The entry is readable by only the owner of the
66493 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
66494 + the RBAC system), and thus does not create privacy concerns.
66495 +
66496 +config GRKERNSEC_RWXMAP_LOG
66497 + bool 'Denied RWX mmap/mprotect logging'
66498 + default y if GRKERNSEC_CONFIG_AUTO
66499 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
66500 + help
66501 + If you say Y here, calls to mmap() and mprotect() with explicit
66502 + usage of PROT_WRITE and PROT_EXEC together will be logged when
66503 + denied by the PAX_MPROTECT feature. This feature will also
66504 + log other problematic scenarios that can occur when PAX_MPROTECT
66505 + is enabled on a binary, like textrels and PT_GNU_STACK. If the
66506 + sysctl option is enabled, a sysctl option with name "rwxmap_logging"
66507 + is created.
66508 +
66509 +endmenu
66510 +
66511 +menu "Executable Protections"
66512 +depends on GRKERNSEC
66513 +
66514 +config GRKERNSEC_DMESG
66515 + bool "Dmesg(8) restriction"
66516 + default y if GRKERNSEC_CONFIG_AUTO
66517 + help
66518 + If you say Y here, non-root users will not be able to use dmesg(8)
66519 + to view the contents of the kernel's circular log buffer.
66520 + The kernel's log buffer often contains kernel addresses and other
66521 + identifying information useful to an attacker in fingerprinting a
66522 + system for a targeted exploit.
66523 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
66524 + created.
66525 +
66526 +config GRKERNSEC_HARDEN_PTRACE
66527 + bool "Deter ptrace-based process snooping"
66528 + default y if GRKERNSEC_CONFIG_AUTO
66529 + help
66530 + If you say Y here, TTY sniffers and other malicious monitoring
66531 + programs implemented through ptrace will be defeated. If you
66532 + have been using the RBAC system, this option has already been
66533 + enabled for several years for all users, with the ability to make
66534 + fine-grained exceptions.
66535 +
66536 + This option only affects the ability of non-root users to ptrace
66537 + processes that are not a descendent of the ptracing process.
66538 + This means that strace ./binary and gdb ./binary will still work,
66539 + but attaching to arbitrary processes will not. If the sysctl
66540 + option is enabled, a sysctl option with name "harden_ptrace" is
66541 + created.
66542 +
66543 +config GRKERNSEC_PTRACE_READEXEC
66544 + bool "Require read access to ptrace sensitive binaries"
66545 + default y if GRKERNSEC_CONFIG_AUTO
66546 + help
66547 + If you say Y here, unprivileged users will not be able to ptrace unreadable
66548 + binaries. This option is useful in environments that
66549 + remove the read bits (e.g. file mode 4711) from suid binaries to
66550 + prevent infoleaking of their contents. This option adds
66551 + consistency to the use of that file mode, as the binary could normally
66552 + be read out when run without privileges while ptracing.
66553 +
66554 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
66555 + is created.
66556 +
66557 +config GRKERNSEC_SETXID
66558 + bool "Enforce consistent multithreaded privileges"
66559 + default y if GRKERNSEC_CONFIG_AUTO
66560 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
66561 + help
66562 + If you say Y here, a change from a root uid to a non-root uid
66563 + in a multithreaded application will cause the resulting uids,
66564 + gids, supplementary groups, and capabilities in that thread
66565 + to be propagated to the other threads of the process. In most
66566 + cases this is unnecessary, as glibc will emulate this behavior
66567 + on behalf of the application. Other libcs do not act in the
66568 + same way, allowing the other threads of the process to continue
66569 + running with root privileges. If the sysctl option is enabled,
66570 + a sysctl option with name "consistent_setxid" is created.
66571 +
66572 +config GRKERNSEC_HARDEN_IPC
66573 + bool "Disallow access to overly-permissive IPC objects"
66574 + default y if GRKERNSEC_CONFIG_AUTO
66575 + depends on SYSVIPC
66576 + help
66577 + If you say Y here, access to overly-permissive IPC objects (shared
66578 + memory, message queues, and semaphores) will be denied for processes
66579 + given the following criteria beyond normal permission checks:
66580 + 1) If the IPC object is world-accessible and the euid doesn't match
66581 + that of the creator or current uid for the IPC object
66582 + 2) If the IPC object is group-accessible and the egid doesn't
66583 + match that of the creator or current gid for the IPC object
66584 + It's a common error to grant too much permission to these objects,
66585 + with impact ranging from denial of service and information leaking to
66586 + privilege escalation. This feature was developed in response to
66587 + research by Tim Brown:
66588 + http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
66589 + who found hundreds of such insecure usages. Processes with
66590 + CAP_IPC_OWNER are still permitted to access these IPC objects.
66591 + If the sysctl option is enabled, a sysctl option with name
66592 + "harden_ipc" is created.
66593 +
66594 +config GRKERNSEC_TPE
66595 + bool "Trusted Path Execution (TPE)"
66596 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
66597 + help
66598 + If you say Y here, you will be able to choose a gid to add to the
66599 + supplementary groups of users you want to mark as "untrusted."
66600 + These users will not be able to execute any files that are not in
66601 + root-owned directories writable only by root. If the sysctl option
66602 + is enabled, a sysctl option with name "tpe" is created.
66603 +
66604 +config GRKERNSEC_TPE_ALL
66605 + bool "Partially restrict all non-root users"
66606 + depends on GRKERNSEC_TPE
66607 + help
66608 + If you say Y here, all non-root users will be covered under
66609 + a weaker TPE restriction. This is separate from, and in addition to,
66610 + the main TPE options that you have selected elsewhere. Thus, if a
66611 + "trusted" GID is chosen, this restriction applies to even that GID.
66612 + Under this restriction, all non-root users will only be allowed to
66613 + execute files in directories they own that are not group or
66614 + world-writable, or in directories owned by root and writable only by
66615 + root. If the sysctl option is enabled, a sysctl option with name
66616 + "tpe_restrict_all" is created.
66617 +
66618 +config GRKERNSEC_TPE_INVERT
66619 + bool "Invert GID option"
66620 + depends on GRKERNSEC_TPE
66621 + help
66622 + If you say Y here, the group you specify in the TPE configuration will
66623 + decide what group TPE restrictions will be *disabled* for. This
66624 + option is useful if you want TPE restrictions to be applied to most
66625 + users on the system. If the sysctl option is enabled, a sysctl option
66626 + with name "tpe_invert" is created. Unlike other sysctl options, this
66627 + entry will default to on for backward-compatibility.
66628 +
66629 +config GRKERNSEC_TPE_GID
66630 + int
66631 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
66632 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
66633 +
66634 +config GRKERNSEC_TPE_UNTRUSTED_GID
66635 + int "GID for TPE-untrusted users"
66636 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
66637 + default 1005
66638 + help
66639 + Setting this GID determines what group TPE restrictions will be
66640 + *enabled* for. If the sysctl option is enabled, a sysctl option
66641 + with name "tpe_gid" is created.
66642 +
66643 +config GRKERNSEC_TPE_TRUSTED_GID
66644 + int "GID for TPE-trusted users"
66645 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
66646 + default 1005
66647 + help
66648 + Setting this GID determines what group TPE restrictions will be
66649 + *disabled* for. If the sysctl option is enabled, a sysctl option
66650 + with name "tpe_gid" is created.
66651 +
66652 +endmenu
66653 +menu "Network Protections"
66654 +depends on GRKERNSEC
66655 +
66656 +config GRKERNSEC_RANDNET
66657 + bool "Larger entropy pools"
66658 + default y if GRKERNSEC_CONFIG_AUTO
66659 + help
66660 + If you say Y here, the entropy pools used for many features of Linux
66661 + and grsecurity will be doubled in size. Since several grsecurity
66662 + features use additional randomness, it is recommended that you say Y
66663 + here. Saying Y here has a similar effect as modifying
66664 + /proc/sys/kernel/random/poolsize.
66665 +
66666 +config GRKERNSEC_BLACKHOLE
66667 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
66668 + default y if GRKERNSEC_CONFIG_AUTO
66669 + depends on NET
66670 + help
66671 + If you say Y here, neither TCP resets nor ICMP
66672 + destination-unreachable packets will be sent in response to packets
66673 + sent to ports for which no associated listening process exists.
66674 + This feature supports both IPV4 and IPV6 and exempts the
66675 + loopback interface from blackholing. Enabling this feature
66676 + makes a host more resilient to DoS attacks and reduces network
66677 + visibility against scanners.
66678 +
66679 + The blackhole feature as-implemented is equivalent to the FreeBSD
66680 + blackhole feature, as it prevents RST responses to all packets, not
66681 + just SYNs. Under most application behavior this causes no
66682 + problems, but applications (like haproxy) may not close certain
66683 + connections in a way that cleanly terminates them on the remote
66684 + end, leaving the remote host in LAST_ACK state. Because of this
66685 + side-effect and to prevent intentional LAST_ACK DoSes, this
66686 + feature also adds automatic mitigation against such attacks.
66687 + The mitigation drastically reduces the amount of time a socket
66688 + can spend in LAST_ACK state. If you're using haproxy and not
66689 + all servers it connects to have this option enabled, consider
66690 + disabling this feature on the haproxy host.
66691 +
66692 + If the sysctl option is enabled, two sysctl options with names
66693 + "ip_blackhole" and "lastack_retries" will be created.
66694 + While "ip_blackhole" takes the standard zero/non-zero on/off
66695 + toggle, "lastack_retries" uses the same kinds of values as
66696 + "tcp_retries1" and "tcp_retries2". The default value of 4
66697 + prevents a socket from lasting more than 45 seconds in LAST_ACK
66698 + state.
66699 +
66700 +config GRKERNSEC_NO_SIMULT_CONNECT
66701 + bool "Disable TCP Simultaneous Connect"
66702 + default y if GRKERNSEC_CONFIG_AUTO
66703 + depends on NET
66704 + help
66705 + If you say Y here, a feature by Willy Tarreau will be enabled that
66706 + removes a weakness in Linux's strict implementation of TCP that
66707 + allows two clients to connect to each other without either entering
66708 + a listening state. The weakness allows an attacker to easily prevent
66709 + a client from connecting to a known server provided the source port
66710 + for the connection is guessed correctly.
66711 +
66712 + As the weakness could be used to prevent an antivirus or IPS from
66713 + fetching updates, or prevent an SSL gateway from fetching a CRL,
66714 + it should be eliminated by enabling this option. Though Linux is
66715 + one of few operating systems supporting simultaneous connect, it
66716 + has no legitimate use in practice and is rarely supported by firewalls.
66717 +
66718 +config GRKERNSEC_SOCKET
66719 + bool "Socket restrictions"
66720 + depends on NET
66721 + help
66722 + If you say Y here, you will be able to choose from several options.
66723 + If you assign a GID on your system and add it to the supplementary
66724 + groups of users you want to restrict socket access to, this patch
66725 + will perform up to three things, based on the option(s) you choose.
66726 +
66727 +config GRKERNSEC_SOCKET_ALL
66728 + bool "Deny any sockets to group"
66729 + depends on GRKERNSEC_SOCKET
66730 + help
66731 + If you say Y here, you will be able to choose a GID of whose users will
66732 + be unable to connect to other hosts from your machine or run server
66733 + applications from your machine. If the sysctl option is enabled, a
66734 + sysctl option with name "socket_all" is created.
66735 +
66736 +config GRKERNSEC_SOCKET_ALL_GID
66737 + int "GID to deny all sockets for"
66738 + depends on GRKERNSEC_SOCKET_ALL
66739 + default 1004
66740 + help
66741 + Here you can choose the GID to disable socket access for. Remember to
66742 + add the users you want socket access disabled for to the GID
66743 + specified here. If the sysctl option is enabled, a sysctl option
66744 + with name "socket_all_gid" is created.
66745 +
66746 +config GRKERNSEC_SOCKET_CLIENT
66747 + bool "Deny client sockets to group"
66748 + depends on GRKERNSEC_SOCKET
66749 + help
66750 + If you say Y here, you will be able to choose a GID of whose users will
66751 + be unable to connect to other hosts from your machine, but will be
66752 + able to run servers. If this option is enabled, all users in the group
66753 + you specify will have to use passive mode when initiating ftp transfers
66754 + from the shell on your machine. If the sysctl option is enabled, a
66755 + sysctl option with name "socket_client" is created.
66756 +
66757 +config GRKERNSEC_SOCKET_CLIENT_GID
66758 + int "GID to deny client sockets for"
66759 + depends on GRKERNSEC_SOCKET_CLIENT
66760 + default 1003
66761 + help
66762 + Here you can choose the GID to disable client socket access for.
66763 + Remember to add the users you want client socket access disabled for to
66764 + the GID specified here. If the sysctl option is enabled, a sysctl
66765 + option with name "socket_client_gid" is created.
66766 +
66767 +config GRKERNSEC_SOCKET_SERVER
66768 + bool "Deny server sockets to group"
66769 + depends on GRKERNSEC_SOCKET
66770 + help
66771 + If you say Y here, you will be able to choose a GID of whose users will
66772 + be unable to run server applications from your machine. If the sysctl
66773 + option is enabled, a sysctl option with name "socket_server" is created.
66774 +
66775 +config GRKERNSEC_SOCKET_SERVER_GID
66776 + int "GID to deny server sockets for"
66777 + depends on GRKERNSEC_SOCKET_SERVER
66778 + default 1002
66779 + help
66780 + Here you can choose the GID to disable server socket access for.
66781 + Remember to add the users you want server socket access disabled for to
66782 + the GID specified here. If the sysctl option is enabled, a sysctl
66783 + option with name "socket_server_gid" is created.
66784 +
66785 +endmenu
66786 +
66787 +menu "Physical Protections"
66788 +depends on GRKERNSEC
66789 +
66790 +config GRKERNSEC_DENYUSB
66791 + bool "Deny new USB connections after toggle"
66792 + default y if GRKERNSEC_CONFIG_AUTO
66793 + depends on SYSCTL && USB_SUPPORT
66794 + help
66795 + If you say Y here, a new sysctl option with name "deny_new_usb"
66796 + will be created. Setting its value to 1 will prevent any new
66797 + USB devices from being recognized by the OS. Any attempted USB
66798 + device insertion will be logged. This option is intended to be
66799 + used against custom USB devices designed to exploit vulnerabilities
66800 + in various USB device drivers.
66801 +
66802 + For greatest effectiveness, this sysctl should be set after any
66803 + relevant init scripts. This option is safe to enable in distros
66804 + as each user can choose whether or not to toggle the sysctl.
66805 +
66806 +config GRKERNSEC_DENYUSB_FORCE
66807 + bool "Reject all USB devices not connected at boot"
66808 + select USB
66809 + depends on GRKERNSEC_DENYUSB
66810 + help
66811 + If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
66812 + that doesn't involve a sysctl entry. This option should only be
66813 + enabled if you're sure you want to deny all new USB connections
66814 + at runtime and don't want to modify init scripts. This should not
66815 + be enabled by distros. It forces the core USB code to be built
66816 + into the kernel image so that all devices connected at boot time
66817 + can be recognized and new USB device connections can be prevented
66818 + prior to init running.
66819 +
66820 +endmenu
66821 +
66822 +menu "Sysctl Support"
66823 +depends on GRKERNSEC && SYSCTL
66824 +
66825 +config GRKERNSEC_SYSCTL
66826 + bool "Sysctl support"
66827 + default y if GRKERNSEC_CONFIG_AUTO
66828 + help
66829 + If you say Y here, you will be able to change the options that
66830 + grsecurity runs with at bootup, without having to recompile your
66831 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
66832 + to enable (1) or disable (0) various features. All the sysctl entries
66833 + are mutable until the "grsec_lock" entry is set to a non-zero value.
66834 + All features enabled in the kernel configuration are disabled at boot
66835 + if you do not say Y to the "Turn on features by default" option.
66836 + All options should be set at startup, and the grsec_lock entry should
66837 + be set to a non-zero value after all the options are set.
66838 + *THIS IS EXTREMELY IMPORTANT*
66839 +
66840 +config GRKERNSEC_SYSCTL_DISTRO
66841 + bool "Extra sysctl support for distro makers (READ HELP)"
66842 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
66843 + help
66844 + If you say Y here, additional sysctl options will be created
66845 + for features that affect processes running as root. Therefore,
66846 + it is critical when using this option that the grsec_lock entry be
66847 + enabled after boot. Only distros with prebuilt kernel packages
66848 + with this option enabled that can ensure grsec_lock is enabled
66849 + after boot should use this option.
66850 + *Failure to set grsec_lock after boot makes all grsec features
66851 + this option covers useless*
66852 +
66853 + Currently this option creates the following sysctl entries:
66854 + "Disable Privileged I/O": "disable_priv_io"
66855 +
66856 +config GRKERNSEC_SYSCTL_ON
66857 + bool "Turn on features by default"
66858 + default y if GRKERNSEC_CONFIG_AUTO
66859 + depends on GRKERNSEC_SYSCTL
66860 + help
66861 + If you say Y here, instead of having all features enabled in the
66862 + kernel configuration disabled at boot time, the features will be
66863 + enabled at boot time. It is recommended you say Y here unless
66864 + there is some reason you would want all sysctl-tunable features to
66865 + be disabled by default. As mentioned elsewhere, it is important
66866 + to enable the grsec_lock entry once you have finished modifying
66867 + the sysctl entries.
66868 +
66869 +endmenu
66870 +menu "Logging Options"
66871 +depends on GRKERNSEC
66872 +
66873 +config GRKERNSEC_FLOODTIME
66874 + int "Seconds in between log messages (minimum)"
66875 + default 10
66876 + help
66877 + This option allows you to enforce the number of seconds between
66878 + grsecurity log messages. The default should be suitable for most
66879 + people, however, if you choose to change it, choose a value small enough
66880 + to allow informative logs to be produced, but large enough to
66881 + prevent flooding.
66882 +
66883 + Setting both this value and GRKERNSEC_FLOODBURST to 0 will disable
66884 + any rate limiting on grsecurity log messages.
66885 +
66886 +config GRKERNSEC_FLOODBURST
66887 + int "Number of messages in a burst (maximum)"
66888 + default 6
66889 + help
66890 + This option allows you to choose the maximum number of messages allowed
66891 + within the flood time interval you chose in a separate option. The
66892 + default should be suitable for most people, however if you find that
66893 + many of your logs are being interpreted as flooding, you may want to
66894 + raise this value.
66895 +
66896 + Setting both this value and GRKERNSEC_FLOODTIME to 0 will disable
66897 + any rate limiting on grsecurity log messages.
66898 +
66899 +endmenu
66900 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
66901 new file mode 100644
66902 index 0000000..30ababb
66903 --- /dev/null
66904 +++ b/grsecurity/Makefile
66905 @@ -0,0 +1,54 @@
66906 +# grsecurity – access control and security hardening for Linux
66907 +# All code in this directory and various hooks located throughout the Linux kernel are
66908 +# Copyright (C) 2001-2014 Bradley Spengler, Open Source Security, Inc.
66909 +# http://www.grsecurity.net spender@grsecurity.net
66910 +#
66911 +# This program is free software; you can redistribute it and/or
66912 +# modify it under the terms of the GNU General Public License version 2
66913 +# as published by the Free Software Foundation.
66914 +#
66915 +# This program is distributed in the hope that it will be useful,
66916 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
66917 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
66918 +# GNU General Public License for more details.
66919 +#
66920 +# You should have received a copy of the GNU General Public License
66921 +# along with this program; if not, write to the Free Software
66922 +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
66923 +
66924 +KBUILD_CFLAGS += -Werror
66925 +
66926 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
66927 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
66928 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
66929 + grsec_usb.o grsec_ipc.o grsec_proc.o
66930 +
66931 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
66932 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
66933 + gracl_learn.o grsec_log.o gracl_policy.o
66934 +ifdef CONFIG_COMPAT
66935 +obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
66936 +endif
66937 +
66938 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
66939 +
66940 +ifdef CONFIG_NET
66941 +obj-y += grsec_sock.o
66942 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
66943 +endif
66944 +
66945 +ifndef CONFIG_GRKERNSEC
66946 +obj-y += grsec_disabled.o
66947 +endif
66948 +
66949 +ifdef CONFIG_GRKERNSEC_HIDESYM
66950 +extra-y := grsec_hidesym.o
66951 +$(obj)/grsec_hidesym.o:
66952 + @-chmod -f 500 /boot
66953 + @-chmod -f 500 /lib/modules
66954 + @-chmod -f 500 /lib64/modules
66955 + @-chmod -f 500 /lib32/modules
66956 + @-chmod -f 700 .
66957 + @-chmod -f 700 $(objtree)
66958 + @echo ' grsec: protected kernel image paths'
66959 +endif
66960 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
66961 new file mode 100644
66962 index 0000000..58223f6
66963 --- /dev/null
66964 +++ b/grsecurity/gracl.c
66965 @@ -0,0 +1,2702 @@
66966 +#include <linux/kernel.h>
66967 +#include <linux/module.h>
66968 +#include <linux/sched.h>
66969 +#include <linux/mm.h>
66970 +#include <linux/file.h>
66971 +#include <linux/fs.h>
66972 +#include <linux/namei.h>
66973 +#include <linux/mount.h>
66974 +#include <linux/tty.h>
66975 +#include <linux/proc_fs.h>
66976 +#include <linux/lglock.h>
66977 +#include <linux/slab.h>
66978 +#include <linux/vmalloc.h>
66979 +#include <linux/types.h>
66980 +#include <linux/sysctl.h>
66981 +#include <linux/netdevice.h>
66982 +#include <linux/ptrace.h>
66983 +#include <linux/gracl.h>
66984 +#include <linux/gralloc.h>
66985 +#include <linux/security.h>
66986 +#include <linux/grinternal.h>
66987 +#include <linux/pid_namespace.h>
66988 +#include <linux/stop_machine.h>
66989 +#include <linux/fdtable.h>
66990 +#include <linux/percpu.h>
66991 +#include <linux/lglock.h>
66992 +#include <linux/hugetlb.h>
66993 +#include <linux/posix-timers.h>
66994 +#include <linux/prefetch.h>
66995 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
66996 +#include <linux/magic.h>
66997 +#include <linux/pagemap.h>
66998 +#include "../fs/btrfs/async-thread.h"
66999 +#include "../fs/btrfs/ctree.h"
67000 +#include "../fs/btrfs/btrfs_inode.h"
67001 +#endif
67002 +#include "../fs/mount.h"
67003 +
67004 +#include <asm/uaccess.h>
67005 +#include <asm/errno.h>
67006 +#include <asm/mman.h>
67007 +
67008 +#define FOR_EACH_ROLE_START(role) \
67009 + role = running_polstate.role_list; \
67010 + while (role) {
67011 +
67012 +#define FOR_EACH_ROLE_END(role) \
67013 + role = role->prev; \
67014 + }
67015 +
67016 +extern struct path gr_real_root;
67017 +
67018 +static struct gr_policy_state running_polstate;
67019 +struct gr_policy_state *polstate = &running_polstate;
67020 +extern struct gr_alloc_state *current_alloc_state;
67021 +
67022 +extern char *gr_shared_page[4];
67023 +DEFINE_RWLOCK(gr_inode_lock);
67024 +
67025 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
67026 +
67027 +#ifdef CONFIG_NET
67028 +extern struct vfsmount *sock_mnt;
67029 +#endif
67030 +
67031 +extern struct vfsmount *pipe_mnt;
67032 +extern struct vfsmount *shm_mnt;
67033 +
67034 +#ifdef CONFIG_HUGETLBFS
67035 +extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
67036 +#endif
67037 +
67038 +extern u16 acl_sp_role_value;
67039 +extern struct acl_object_label *fakefs_obj_rw;
67040 +extern struct acl_object_label *fakefs_obj_rwx;
67041 +
67042 +int gr_acl_is_enabled(void)
67043 +{
67044 + return (gr_status & GR_READY);
67045 +}
67046 +
67047 +void gr_enable_rbac_system(void)
67048 +{
67049 + pax_open_kernel();
67050 + gr_status |= GR_READY;
67051 + pax_close_kernel();
67052 +}
67053 +
67054 +int gr_rbac_disable(void *unused)
67055 +{
67056 + pax_open_kernel();
67057 + gr_status &= ~GR_READY;
67058 + pax_close_kernel();
67059 +
67060 + return 0;
67061 +}
67062 +
67063 +static inline dev_t __get_dev(const struct dentry *dentry)
67064 +{
67065 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
67066 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
67067 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
67068 + else
67069 +#endif
67070 + return dentry->d_sb->s_dev;
67071 +}
67072 +
67073 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
67074 +{
67075 + return __get_dev(dentry);
67076 +}
67077 +
67078 +static char gr_task_roletype_to_char(struct task_struct *task)
67079 +{
67080 + switch (task->role->roletype &
67081 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
67082 + GR_ROLE_SPECIAL)) {
67083 + case GR_ROLE_DEFAULT:
67084 + return 'D';
67085 + case GR_ROLE_USER:
67086 + return 'U';
67087 + case GR_ROLE_GROUP:
67088 + return 'G';
67089 + case GR_ROLE_SPECIAL:
67090 + return 'S';
67091 + }
67092 +
67093 + return 'X';
67094 +}
67095 +
67096 +char gr_roletype_to_char(void)
67097 +{
67098 + return gr_task_roletype_to_char(current);
67099 +}
67100 +
67101 +__inline__ int
67102 +gr_acl_tpe_check(void)
67103 +{
67104 + if (unlikely(!(gr_status & GR_READY)))
67105 + return 0;
67106 + if (current->role->roletype & GR_ROLE_TPE)
67107 + return 1;
67108 + else
67109 + return 0;
67110 +}
67111 +
67112 +int
67113 +gr_handle_rawio(const struct inode *inode)
67114 +{
67115 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
67116 + if (inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR)) &&
67117 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
67118 + !capable(CAP_SYS_RAWIO))
67119 + return 1;
67120 +#endif
67121 + return 0;
67122 +}
67123 +
67124 +int
67125 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
67126 +{
67127 + if (likely(lena != lenb))
67128 + return 0;
67129 +
67130 + return !memcmp(a, b, lena);
67131 +}
67132 +
67133 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
67134 +{
67135 + *buflen -= namelen;
67136 + if (*buflen < 0)
67137 + return -ENAMETOOLONG;
67138 + *buffer -= namelen;
67139 + memcpy(*buffer, str, namelen);
67140 + return 0;
67141 +}
67142 +
67143 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
67144 +{
67145 + return prepend(buffer, buflen, name->name, name->len);
67146 +}
67147 +
67148 +static int prepend_path(const struct path *path, struct path *root,
67149 + char **buffer, int *buflen)
67150 +{
67151 + struct dentry *dentry = path->dentry;
67152 + struct vfsmount *vfsmnt = path->mnt;
67153 + struct mount *mnt = real_mount(vfsmnt);
67154 + bool slash = false;
67155 + int error = 0;
67156 +
67157 + while (dentry != root->dentry || vfsmnt != root->mnt) {
67158 + struct dentry * parent;
67159 +
67160 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
67161 + /* Global root? */
67162 + if (!mnt_has_parent(mnt)) {
67163 + goto out;
67164 + }
67165 + dentry = mnt->mnt_mountpoint;
67166 + mnt = mnt->mnt_parent;
67167 + vfsmnt = &mnt->mnt;
67168 + continue;
67169 + }
67170 + parent = dentry->d_parent;
67171 + prefetch(parent);
67172 + spin_lock(&dentry->d_lock);
67173 + error = prepend_name(buffer, buflen, &dentry->d_name);
67174 + spin_unlock(&dentry->d_lock);
67175 + if (!error)
67176 + error = prepend(buffer, buflen, "/", 1);
67177 + if (error)
67178 + break;
67179 +
67180 + slash = true;
67181 + dentry = parent;
67182 + }
67183 +
67184 +out:
67185 + if (!error && !slash)
67186 + error = prepend(buffer, buflen, "/", 1);
67187 +
67188 + return error;
67189 +}
67190 +
67191 +/* this must be called with mount_lock and rename_lock held */
67192 +
67193 +static char *__our_d_path(const struct path *path, struct path *root,
67194 + char *buf, int buflen)
67195 +{
67196 + char *res = buf + buflen;
67197 + int error;
67198 +
67199 + prepend(&res, &buflen, "\0", 1);
67200 + error = prepend_path(path, root, &res, &buflen);
67201 + if (error)
67202 + return ERR_PTR(error);
67203 +
67204 + return res;
67205 +}
67206 +
67207 +static char *
67208 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
67209 +{
67210 + char *retval;
67211 +
67212 + retval = __our_d_path(path, root, buf, buflen);
67213 + if (unlikely(IS_ERR(retval)))
67214 + retval = strcpy(buf, "<path too long>");
67215 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
67216 + retval[1] = '\0';
67217 +
67218 + return retval;
67219 +}
67220 +
67221 +static char *
67222 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
67223 + char *buf, int buflen)
67224 +{
67225 + struct path path;
67226 + char *res;
67227 +
67228 + path.dentry = (struct dentry *)dentry;
67229 + path.mnt = (struct vfsmount *)vfsmnt;
67230 +
67231 + /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
67232 + by the RBAC system */
67233 + res = gen_full_path(&path, &gr_real_root, buf, buflen);
67234 +
67235 + return res;
67236 +}
67237 +
67238 +static char *
67239 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
67240 + char *buf, int buflen)
67241 +{
67242 + char *res;
67243 + struct path path;
67244 + struct path root;
67245 + struct task_struct *reaper = init_pid_ns.child_reaper;
67246 +
67247 + path.dentry = (struct dentry *)dentry;
67248 + path.mnt = (struct vfsmount *)vfsmnt;
67249 +
67250 + /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
67251 + get_fs_root(reaper->fs, &root);
67252 +
67253 + read_seqlock_excl(&mount_lock);
67254 + write_seqlock(&rename_lock);
67255 + res = gen_full_path(&path, &root, buf, buflen);
67256 + write_sequnlock(&rename_lock);
67257 + read_sequnlock_excl(&mount_lock);
67258 +
67259 + path_put(&root);
67260 + return res;
67261 +}
67262 +
67263 +char *
67264 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
67265 +{
67266 + char *ret;
67267 + read_seqlock_excl(&mount_lock);
67268 + write_seqlock(&rename_lock);
67269 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
67270 + PAGE_SIZE);
67271 + write_sequnlock(&rename_lock);
67272 + read_sequnlock_excl(&mount_lock);
67273 + return ret;
67274 +}
67275 +
67276 +static char *
67277 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
67278 +{
67279 + char *ret;
67280 + char *buf;
67281 + int buflen;
67282 +
67283 + read_seqlock_excl(&mount_lock);
67284 + write_seqlock(&rename_lock);
67285 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
67286 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
67287 + buflen = (int)(ret - buf);
67288 + if (buflen >= 5)
67289 + prepend(&ret, &buflen, "/proc", 5);
67290 + else
67291 + ret = strcpy(buf, "<path too long>");
67292 + write_sequnlock(&rename_lock);
67293 + read_sequnlock_excl(&mount_lock);
67294 + return ret;
67295 +}
67296 +
67297 +char *
67298 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
67299 +{
67300 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
67301 + PAGE_SIZE);
67302 +}
67303 +
67304 +char *
67305 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
67306 +{
67307 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
67308 + PAGE_SIZE);
67309 +}
67310 +
67311 +char *
67312 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
67313 +{
67314 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
67315 + PAGE_SIZE);
67316 +}
67317 +
67318 +char *
67319 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
67320 +{
67321 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
67322 + PAGE_SIZE);
67323 +}
67324 +
67325 +char *
67326 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
67327 +{
67328 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
67329 + PAGE_SIZE);
67330 +}
67331 +
67332 +__inline__ __u32
67333 +to_gr_audit(const __u32 reqmode)
67334 +{
67335 + /* masks off auditable permission flags, then shifts them to create
67336 + auditing flags, and adds the special case of append auditing if
67337 + we're requesting write */
67338 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
67339 +}
67340 +
67341 +struct acl_role_label *
67342 +__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
67343 + const gid_t gid)
67344 +{
67345 + unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
67346 + struct acl_role_label *match;
67347 + struct role_allowed_ip *ipp;
67348 + unsigned int x;
67349 + u32 curr_ip = task->signal->saved_ip;
67350 +
67351 + match = state->acl_role_set.r_hash[index];
67352 +
67353 + while (match) {
67354 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
67355 + for (x = 0; x < match->domain_child_num; x++) {
67356 + if (match->domain_children[x] == uid)
67357 + goto found;
67358 + }
67359 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
67360 + break;
67361 + match = match->next;
67362 + }
67363 +found:
67364 + if (match == NULL) {
67365 + try_group:
67366 + index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
67367 + match = state->acl_role_set.r_hash[index];
67368 +
67369 + while (match) {
67370 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
67371 + for (x = 0; x < match->domain_child_num; x++) {
67372 + if (match->domain_children[x] == gid)
67373 + goto found2;
67374 + }
67375 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
67376 + break;
67377 + match = match->next;
67378 + }
67379 +found2:
67380 + if (match == NULL)
67381 + match = state->default_role;
67382 + if (match->allowed_ips == NULL)
67383 + return match;
67384 + else {
67385 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
67386 + if (likely
67387 + ((ntohl(curr_ip) & ipp->netmask) ==
67388 + (ntohl(ipp->addr) & ipp->netmask)))
67389 + return match;
67390 + }
67391 + match = state->default_role;
67392 + }
67393 + } else if (match->allowed_ips == NULL) {
67394 + return match;
67395 + } else {
67396 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
67397 + if (likely
67398 + ((ntohl(curr_ip) & ipp->netmask) ==
67399 + (ntohl(ipp->addr) & ipp->netmask)))
67400 + return match;
67401 + }
67402 + goto try_group;
67403 + }
67404 +
67405 + return match;
67406 +}
67407 +
67408 +static struct acl_role_label *
67409 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
67410 + const gid_t gid)
67411 +{
67412 + return __lookup_acl_role_label(&running_polstate, task, uid, gid);
67413 +}
67414 +
67415 +struct acl_subject_label *
67416 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
67417 + const struct acl_role_label *role)
67418 +{
67419 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
67420 + struct acl_subject_label *match;
67421 +
67422 + match = role->subj_hash[index];
67423 +
67424 + while (match && (match->inode != ino || match->device != dev ||
67425 + (match->mode & GR_DELETED))) {
67426 + match = match->next;
67427 + }
67428 +
67429 + if (match && !(match->mode & GR_DELETED))
67430 + return match;
67431 + else
67432 + return NULL;
67433 +}
67434 +
67435 +struct acl_subject_label *
67436 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
67437 + const struct acl_role_label *role)
67438 +{
67439 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
67440 + struct acl_subject_label *match;
67441 +
67442 + match = role->subj_hash[index];
67443 +
67444 + while (match && (match->inode != ino || match->device != dev ||
67445 + !(match->mode & GR_DELETED))) {
67446 + match = match->next;
67447 + }
67448 +
67449 + if (match && (match->mode & GR_DELETED))
67450 + return match;
67451 + else
67452 + return NULL;
67453 +}
67454 +
67455 +static struct acl_object_label *
67456 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
67457 + const struct acl_subject_label *subj)
67458 +{
67459 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
67460 + struct acl_object_label *match;
67461 +
67462 + match = subj->obj_hash[index];
67463 +
67464 + while (match && (match->inode != ino || match->device != dev ||
67465 + (match->mode & GR_DELETED))) {
67466 + match = match->next;
67467 + }
67468 +
67469 + if (match && !(match->mode & GR_DELETED))
67470 + return match;
67471 + else
67472 + return NULL;
67473 +}
67474 +
67475 +static struct acl_object_label *
67476 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
67477 + const struct acl_subject_label *subj)
67478 +{
67479 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
67480 + struct acl_object_label *match;
67481 +
67482 + match = subj->obj_hash[index];
67483 +
67484 + while (match && (match->inode != ino || match->device != dev ||
67485 + !(match->mode & GR_DELETED))) {
67486 + match = match->next;
67487 + }
67488 +
67489 + if (match && (match->mode & GR_DELETED))
67490 + return match;
67491 +
67492 + match = subj->obj_hash[index];
67493 +
67494 + while (match && (match->inode != ino || match->device != dev ||
67495 + (match->mode & GR_DELETED))) {
67496 + match = match->next;
67497 + }
67498 +
67499 + if (match && !(match->mode & GR_DELETED))
67500 + return match;
67501 + else
67502 + return NULL;
67503 +}
67504 +
67505 +struct name_entry *
67506 +__lookup_name_entry(const struct gr_policy_state *state, const char *name)
67507 +{
67508 + unsigned int len = strlen(name);
67509 + unsigned int key = full_name_hash(name, len);
67510 + unsigned int index = key % state->name_set.n_size;
67511 + struct name_entry *match;
67512 +
67513 + match = state->name_set.n_hash[index];
67514 +
67515 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
67516 + match = match->next;
67517 +
67518 + return match;
67519 +}
67520 +
67521 +static struct name_entry *
67522 +lookup_name_entry(const char *name)
67523 +{
67524 + return __lookup_name_entry(&running_polstate, name);
67525 +}
67526 +
67527 +static struct name_entry *
67528 +lookup_name_entry_create(const char *name)
67529 +{
67530 + unsigned int len = strlen(name);
67531 + unsigned int key = full_name_hash(name, len);
67532 + unsigned int index = key % running_polstate.name_set.n_size;
67533 + struct name_entry *match;
67534 +
67535 + match = running_polstate.name_set.n_hash[index];
67536 +
67537 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
67538 + !match->deleted))
67539 + match = match->next;
67540 +
67541 + if (match && match->deleted)
67542 + return match;
67543 +
67544 + match = running_polstate.name_set.n_hash[index];
67545 +
67546 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
67547 + match->deleted))
67548 + match = match->next;
67549 +
67550 + if (match && !match->deleted)
67551 + return match;
67552 + else
67553 + return NULL;
67554 +}
67555 +
67556 +static struct inodev_entry *
67557 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
67558 +{
67559 + unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
67560 + struct inodev_entry *match;
67561 +
67562 + match = running_polstate.inodev_set.i_hash[index];
67563 +
67564 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
67565 + match = match->next;
67566 +
67567 + return match;
67568 +}
67569 +
67570 +void
67571 +__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
67572 +{
67573 + unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
67574 + state->inodev_set.i_size);
67575 + struct inodev_entry **curr;
67576 +
67577 + entry->prev = NULL;
67578 +
67579 + curr = &state->inodev_set.i_hash[index];
67580 + if (*curr != NULL)
67581 + (*curr)->prev = entry;
67582 +
67583 + entry->next = *curr;
67584 + *curr = entry;
67585 +
67586 + return;
67587 +}
67588 +
67589 +static void
67590 +insert_inodev_entry(struct inodev_entry *entry)
67591 +{
67592 + __insert_inodev_entry(&running_polstate, entry);
67593 +}
67594 +
67595 +void
67596 +insert_acl_obj_label(struct acl_object_label *obj,
67597 + struct acl_subject_label *subj)
67598 +{
67599 + unsigned int index =
67600 + gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
67601 + struct acl_object_label **curr;
67602 +
67603 + obj->prev = NULL;
67604 +
67605 + curr = &subj->obj_hash[index];
67606 + if (*curr != NULL)
67607 + (*curr)->prev = obj;
67608 +
67609 + obj->next = *curr;
67610 + *curr = obj;
67611 +
67612 + return;
67613 +}
67614 +
67615 +void
67616 +insert_acl_subj_label(struct acl_subject_label *obj,
67617 + struct acl_role_label *role)
67618 +{
67619 + unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
67620 + struct acl_subject_label **curr;
67621 +
67622 + obj->prev = NULL;
67623 +
67624 + curr = &role->subj_hash[index];
67625 + if (*curr != NULL)
67626 + (*curr)->prev = obj;
67627 +
67628 + obj->next = *curr;
67629 + *curr = obj;
67630 +
67631 + return;
67632 +}
67633 +
67634 +/* derived from glibc fnmatch() 0: match, 1: no match*/
67635 +
67636 +static int
67637 +glob_match(const char *p, const char *n)
67638 +{
67639 + char c;
67640 +
67641 + while ((c = *p++) != '\0') {
67642 + switch (c) {
67643 + case '?':
67644 + if (*n == '\0')
67645 + return 1;
67646 + else if (*n == '/')
67647 + return 1;
67648 + break;
67649 + case '\\':
67650 + if (*n != c)
67651 + return 1;
67652 + break;
67653 + case '*':
67654 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
67655 + if (*n == '/')
67656 + return 1;
67657 + else if (c == '?') {
67658 + if (*n == '\0')
67659 + return 1;
67660 + else
67661 + ++n;
67662 + }
67663 + }
67664 + if (c == '\0') {
67665 + return 0;
67666 + } else {
67667 + const char *endp;
67668 +
67669 + if ((endp = strchr(n, '/')) == NULL)
67670 + endp = n + strlen(n);
67671 +
67672 + if (c == '[') {
67673 + for (--p; n < endp; ++n)
67674 + if (!glob_match(p, n))
67675 + return 0;
67676 + } else if (c == '/') {
67677 + while (*n != '\0' && *n != '/')
67678 + ++n;
67679 + if (*n == '/' && !glob_match(p, n + 1))
67680 + return 0;
67681 + } else {
67682 + for (--p; n < endp; ++n)
67683 + if (*n == c && !glob_match(p, n))
67684 + return 0;
67685 + }
67686 +
67687 + return 1;
67688 + }
67689 + case '[':
67690 + {
67691 + int not;
67692 + char cold;
67693 +
67694 + if (*n == '\0' || *n == '/')
67695 + return 1;
67696 +
67697 + not = (*p == '!' || *p == '^');
67698 + if (not)
67699 + ++p;
67700 +
67701 + c = *p++;
67702 + for (;;) {
67703 + unsigned char fn = (unsigned char)*n;
67704 +
67705 + if (c == '\0')
67706 + return 1;
67707 + else {
67708 + if (c == fn)
67709 + goto matched;
67710 + cold = c;
67711 + c = *p++;
67712 +
67713 + if (c == '-' && *p != ']') {
67714 + unsigned char cend = *p++;
67715 +
67716 + if (cend == '\0')
67717 + return 1;
67718 +
67719 + if (cold <= fn && fn <= cend)
67720 + goto matched;
67721 +
67722 + c = *p++;
67723 + }
67724 + }
67725 +
67726 + if (c == ']')
67727 + break;
67728 + }
67729 + if (!not)
67730 + return 1;
67731 + break;
67732 + matched:
67733 + while (c != ']') {
67734 + if (c == '\0')
67735 + return 1;
67736 +
67737 + c = *p++;
67738 + }
67739 + if (not)
67740 + return 1;
67741 + }
67742 + break;
67743 + default:
67744 + if (c != *n)
67745 + return 1;
67746 + }
67747 +
67748 + ++n;
67749 + }
67750 +
67751 + if (*n == '\0')
67752 + return 0;
67753 +
67754 + if (*n == '/')
67755 + return 0;
67756 +
67757 + return 1;
67758 +}
67759 +
67760 +static struct acl_object_label *
67761 +chk_glob_label(struct acl_object_label *globbed,
67762 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
67763 +{
67764 + struct acl_object_label *tmp;
67765 +
67766 + if (*path == NULL)
67767 + *path = gr_to_filename_nolock(dentry, mnt);
67768 +
67769 + tmp = globbed;
67770 +
67771 + while (tmp) {
67772 + if (!glob_match(tmp->filename, *path))
67773 + return tmp;
67774 + tmp = tmp->next;
67775 + }
67776 +
67777 + return NULL;
67778 +}
67779 +
67780 +static struct acl_object_label *
67781 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
67782 + const ino_t curr_ino, const dev_t curr_dev,
67783 + const struct acl_subject_label *subj, char **path, const int checkglob)
67784 +{
67785 + struct acl_subject_label *tmpsubj;
67786 + struct acl_object_label *retval;
67787 + struct acl_object_label *retval2;
67788 +
67789 + tmpsubj = (struct acl_subject_label *) subj;
67790 + read_lock(&gr_inode_lock);
67791 + do {
67792 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
67793 + if (retval) {
67794 + if (checkglob && retval->globbed) {
67795 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
67796 + if (retval2)
67797 + retval = retval2;
67798 + }
67799 + break;
67800 + }
67801 + } while ((tmpsubj = tmpsubj->parent_subject));
67802 + read_unlock(&gr_inode_lock);
67803 +
67804 + return retval;
67805 +}
67806 +
67807 +static __inline__ struct acl_object_label *
67808 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
67809 + struct dentry *curr_dentry,
67810 + const struct acl_subject_label *subj, char **path, const int checkglob)
67811 +{
67812 + int newglob = checkglob;
67813 + ino_t inode;
67814 + dev_t device;
67815 +
67816 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
67817 + as we don't want a / * rule to match instead of the / object
67818 + don't do this for create lookups that call this function though, since they're looking up
67819 + on the parent and thus need globbing checks on all paths
67820 + */
67821 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
67822 + newglob = GR_NO_GLOB;
67823 +
67824 + spin_lock(&curr_dentry->d_lock);
67825 + inode = curr_dentry->d_inode->i_ino;
67826 + device = __get_dev(curr_dentry);
67827 + spin_unlock(&curr_dentry->d_lock);
67828 +
67829 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
67830 +}
67831 +
67832 +#ifdef CONFIG_HUGETLBFS
67833 +static inline bool
67834 +is_hugetlbfs_mnt(const struct vfsmount *mnt)
67835 +{
67836 + int i;
67837 + for (i = 0; i < HUGE_MAX_HSTATE; i++) {
67838 + if (unlikely(hugetlbfs_vfsmount[i] == mnt))
67839 + return true;
67840 + }
67841 +
67842 + return false;
67843 +}
67844 +#endif
67845 +
67846 +static struct acl_object_label *
67847 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67848 + const struct acl_subject_label *subj, char *path, const int checkglob)
67849 +{
67850 + struct dentry *dentry = (struct dentry *) l_dentry;
67851 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
67852 + struct mount *real_mnt = real_mount(mnt);
67853 + struct acl_object_label *retval;
67854 + struct dentry *parent;
67855 +
67856 + read_seqlock_excl(&mount_lock);
67857 + write_seqlock(&rename_lock);
67858 +
67859 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
67860 +#ifdef CONFIG_NET
67861 + mnt == sock_mnt ||
67862 +#endif
67863 +#ifdef CONFIG_HUGETLBFS
67864 + (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
67865 +#endif
67866 + /* ignore Eric Biederman */
67867 + IS_PRIVATE(l_dentry->d_inode))) {
67868 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
67869 + goto out;
67870 + }
67871 +
67872 + for (;;) {
67873 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
67874 + break;
67875 +
67876 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
67877 + if (!mnt_has_parent(real_mnt))
67878 + break;
67879 +
67880 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
67881 + if (retval != NULL)
67882 + goto out;
67883 +
67884 + dentry = real_mnt->mnt_mountpoint;
67885 + real_mnt = real_mnt->mnt_parent;
67886 + mnt = &real_mnt->mnt;
67887 + continue;
67888 + }
67889 +
67890 + parent = dentry->d_parent;
67891 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
67892 + if (retval != NULL)
67893 + goto out;
67894 +
67895 + dentry = parent;
67896 + }
67897 +
67898 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
67899 +
67900 + /* gr_real_root is pinned so we don't have to hold a reference */
67901 + if (retval == NULL)
67902 + retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
67903 +out:
67904 + write_sequnlock(&rename_lock);
67905 + read_sequnlock_excl(&mount_lock);
67906 +
67907 + BUG_ON(retval == NULL);
67908 +
67909 + return retval;
67910 +}
67911 +
67912 +static __inline__ struct acl_object_label *
67913 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67914 + const struct acl_subject_label *subj)
67915 +{
67916 + char *path = NULL;
67917 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
67918 +}
67919 +
67920 +static __inline__ struct acl_object_label *
67921 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67922 + const struct acl_subject_label *subj)
67923 +{
67924 + char *path = NULL;
67925 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
67926 +}
67927 +
67928 +static __inline__ struct acl_object_label *
67929 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67930 + const struct acl_subject_label *subj, char *path)
67931 +{
67932 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
67933 +}
67934 +
67935 +struct acl_subject_label *
67936 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
67937 + const struct acl_role_label *role)
67938 +{
67939 + struct dentry *dentry = (struct dentry *) l_dentry;
67940 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
67941 + struct mount *real_mnt = real_mount(mnt);
67942 + struct acl_subject_label *retval;
67943 + struct dentry *parent;
67944 +
67945 + read_seqlock_excl(&mount_lock);
67946 + write_seqlock(&rename_lock);
67947 +
67948 + for (;;) {
67949 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
67950 + break;
67951 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
67952 + if (!mnt_has_parent(real_mnt))
67953 + break;
67954 +
67955 + spin_lock(&dentry->d_lock);
67956 + read_lock(&gr_inode_lock);
67957 + retval =
67958 + lookup_acl_subj_label(dentry->d_inode->i_ino,
67959 + __get_dev(dentry), role);
67960 + read_unlock(&gr_inode_lock);
67961 + spin_unlock(&dentry->d_lock);
67962 + if (retval != NULL)
67963 + goto out;
67964 +
67965 + dentry = real_mnt->mnt_mountpoint;
67966 + real_mnt = real_mnt->mnt_parent;
67967 + mnt = &real_mnt->mnt;
67968 + continue;
67969 + }
67970 +
67971 + spin_lock(&dentry->d_lock);
67972 + read_lock(&gr_inode_lock);
67973 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
67974 + __get_dev(dentry), role);
67975 + read_unlock(&gr_inode_lock);
67976 + parent = dentry->d_parent;
67977 + spin_unlock(&dentry->d_lock);
67978 +
67979 + if (retval != NULL)
67980 + goto out;
67981 +
67982 + dentry = parent;
67983 + }
67984 +
67985 + spin_lock(&dentry->d_lock);
67986 + read_lock(&gr_inode_lock);
67987 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
67988 + __get_dev(dentry), role);
67989 + read_unlock(&gr_inode_lock);
67990 + spin_unlock(&dentry->d_lock);
67991 +
67992 + if (unlikely(retval == NULL)) {
67993 + /* gr_real_root is pinned, we don't need to hold a reference */
67994 + read_lock(&gr_inode_lock);
67995 + retval = lookup_acl_subj_label(gr_real_root.dentry->d_inode->i_ino,
67996 + __get_dev(gr_real_root.dentry), role);
67997 + read_unlock(&gr_inode_lock);
67998 + }
67999 +out:
68000 + write_sequnlock(&rename_lock);
68001 + read_sequnlock_excl(&mount_lock);
68002 +
68003 + BUG_ON(retval == NULL);
68004 +
68005 + return retval;
68006 +}
68007 +
68008 +void
68009 +assign_special_role(const char *rolename)
68010 +{
68011 + struct acl_object_label *obj;
68012 + struct acl_role_label *r;
68013 + struct acl_role_label *assigned = NULL;
68014 + struct task_struct *tsk;
68015 + struct file *filp;
68016 +
68017 + FOR_EACH_ROLE_START(r)
68018 + if (!strcmp(rolename, r->rolename) &&
68019 + (r->roletype & GR_ROLE_SPECIAL)) {
68020 + assigned = r;
68021 + break;
68022 + }
68023 + FOR_EACH_ROLE_END(r)
68024 +
68025 + if (!assigned)
68026 + return;
68027 +
68028 + read_lock(&tasklist_lock);
68029 + read_lock(&grsec_exec_file_lock);
68030 +
68031 + tsk = current->real_parent;
68032 + if (tsk == NULL)
68033 + goto out_unlock;
68034 +
68035 + filp = tsk->exec_file;
68036 + if (filp == NULL)
68037 + goto out_unlock;
68038 +
68039 + tsk->is_writable = 0;
68040 + tsk->inherited = 0;
68041 +
68042 + tsk->acl_sp_role = 1;
68043 + tsk->acl_role_id = ++acl_sp_role_value;
68044 + tsk->role = assigned;
68045 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
68046 +
68047 + /* ignore additional mmap checks for processes that are writable
68048 + by the default ACL */
68049 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
68050 + if (unlikely(obj->mode & GR_WRITE))
68051 + tsk->is_writable = 1;
68052 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
68053 + if (unlikely(obj->mode & GR_WRITE))
68054 + tsk->is_writable = 1;
68055 +
68056 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68057 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
68058 + tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
68059 +#endif
68060 +
68061 +out_unlock:
68062 + read_unlock(&grsec_exec_file_lock);
68063 + read_unlock(&tasklist_lock);
68064 + return;
68065 +}
68066 +
68067 +
68068 +static void
68069 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
68070 +{
68071 + struct task_struct *task = current;
68072 + const struct cred *cred = current_cred();
68073 +
68074 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
68075 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
68076 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
68077 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
68078 +
68079 + return;
68080 +}
68081 +
68082 +static void
68083 +gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
68084 +{
68085 + struct task_struct *task = current;
68086 + const struct cred *cred = current_cred();
68087 +
68088 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
68089 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
68090 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
68091 + 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
68092 +
68093 + return;
68094 +}
68095 +
68096 +static void
68097 +gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
68098 +{
68099 + struct task_struct *task = current;
68100 + const struct cred *cred = current_cred();
68101 +
68102 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
68103 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
68104 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
68105 + 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
68106 +
68107 + return;
68108 +}
68109 +
68110 +static void
68111 +gr_set_proc_res(struct task_struct *task)
68112 +{
68113 + struct acl_subject_label *proc;
68114 + unsigned short i;
68115 +
68116 + proc = task->acl;
68117 +
68118 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
68119 + return;
68120 +
68121 + for (i = 0; i < RLIM_NLIMITS; i++) {
68122 + if (!(proc->resmask & (1U << i)))
68123 + continue;
68124 +
68125 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
68126 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
68127 +
68128 + if (i == RLIMIT_CPU)
68129 + update_rlimit_cpu(task, proc->res[i].rlim_cur);
68130 + }
68131 +
68132 + return;
68133 +}
68134 +
68135 +/* both of the below must be called with
68136 + rcu_read_lock();
68137 + read_lock(&tasklist_lock);
68138 + read_lock(&grsec_exec_file_lock);
68139 +*/
68140 +
68141 +struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename)
68142 +{
68143 + char *tmpname;
68144 + struct acl_subject_label *tmpsubj;
68145 + struct file *filp;
68146 + struct name_entry *nmatch;
68147 +
68148 + filp = task->exec_file;
68149 + if (filp == NULL)
68150 + return NULL;
68151 +
68152 + /* the following is to apply the correct subject
68153 + on binaries running when the RBAC system
68154 + is enabled, when the binaries have been
68155 + replaced or deleted since their execution
68156 + -----
68157 + when the RBAC system starts, the inode/dev
68158 + from exec_file will be one the RBAC system
68159 + is unaware of. It only knows the inode/dev
68160 + of the present file on disk, or the absence
68161 + of it.
68162 + */
68163 +
68164 + if (filename)
68165 + nmatch = __lookup_name_entry(state, filename);
68166 + else {
68167 + preempt_disable();
68168 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
68169 +
68170 + nmatch = __lookup_name_entry(state, tmpname);
68171 + preempt_enable();
68172 + }
68173 + tmpsubj = NULL;
68174 + if (nmatch) {
68175 + if (nmatch->deleted)
68176 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
68177 + else
68178 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
68179 + }
68180 + /* this also works for the reload case -- if we don't match a potentially inherited subject
68181 + then we fall back to a normal lookup based on the binary's ino/dev
68182 + */
68183 + if (tmpsubj == NULL)
68184 + tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, task->role);
68185 +
68186 + return tmpsubj;
68187 +}
68188 +
68189 +static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename)
68190 +{
68191 + return __gr_get_subject_for_task(&running_polstate, task, filename);
68192 +}
68193 +
68194 +void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
68195 +{
68196 + struct acl_object_label *obj;
68197 + struct file *filp;
68198 +
68199 + filp = task->exec_file;
68200 +
68201 + task->acl = subj;
68202 + task->is_writable = 0;
68203 + /* ignore additional mmap checks for processes that are writable
68204 + by the default ACL */
68205 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
68206 + if (unlikely(obj->mode & GR_WRITE))
68207 + task->is_writable = 1;
68208 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
68209 + if (unlikely(obj->mode & GR_WRITE))
68210 + task->is_writable = 1;
68211 +
68212 + gr_set_proc_res(task);
68213 +
68214 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68215 + 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);
68216 +#endif
68217 +}
68218 +
68219 +static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
68220 +{
68221 + __gr_apply_subject_to_task(&running_polstate, task, subj);
68222 +}
68223 +
68224 +__u32
68225 +gr_search_file(const struct dentry * dentry, const __u32 mode,
68226 + const struct vfsmount * mnt)
68227 +{
68228 + __u32 retval = mode;
68229 + struct acl_subject_label *curracl;
68230 + struct acl_object_label *currobj;
68231 +
68232 + if (unlikely(!(gr_status & GR_READY)))
68233 + return (mode & ~GR_AUDITS);
68234 +
68235 + curracl = current->acl;
68236 +
68237 + currobj = chk_obj_label(dentry, mnt, curracl);
68238 + retval = currobj->mode & mode;
68239 +
68240 + /* if we're opening a specified transfer file for writing
68241 + (e.g. /dev/initctl), then transfer our role to init
68242 + */
68243 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
68244 + current->role->roletype & GR_ROLE_PERSIST)) {
68245 + struct task_struct *task = init_pid_ns.child_reaper;
68246 +
68247 + if (task->role != current->role) {
68248 + struct acl_subject_label *subj;
68249 +
68250 + task->acl_sp_role = 0;
68251 + task->acl_role_id = current->acl_role_id;
68252 + task->role = current->role;
68253 + rcu_read_lock();
68254 + read_lock(&grsec_exec_file_lock);
68255 + subj = gr_get_subject_for_task(task, NULL);
68256 + gr_apply_subject_to_task(task, subj);
68257 + read_unlock(&grsec_exec_file_lock);
68258 + rcu_read_unlock();
68259 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
68260 + }
68261 + }
68262 +
68263 + if (unlikely
68264 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
68265 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
68266 + __u32 new_mode = mode;
68267 +
68268 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
68269 +
68270 + retval = new_mode;
68271 +
68272 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
68273 + new_mode |= GR_INHERIT;
68274 +
68275 + if (!(mode & GR_NOLEARN))
68276 + gr_log_learn(dentry, mnt, new_mode);
68277 + }
68278 +
68279 + return retval;
68280 +}
68281 +
68282 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
68283 + const struct dentry *parent,
68284 + const struct vfsmount *mnt)
68285 +{
68286 + struct name_entry *match;
68287 + struct acl_object_label *matchpo;
68288 + struct acl_subject_label *curracl;
68289 + char *path;
68290 +
68291 + if (unlikely(!(gr_status & GR_READY)))
68292 + return NULL;
68293 +
68294 + preempt_disable();
68295 + path = gr_to_filename_rbac(new_dentry, mnt);
68296 + match = lookup_name_entry_create(path);
68297 +
68298 + curracl = current->acl;
68299 +
68300 + if (match) {
68301 + read_lock(&gr_inode_lock);
68302 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
68303 + read_unlock(&gr_inode_lock);
68304 +
68305 + if (matchpo) {
68306 + preempt_enable();
68307 + return matchpo;
68308 + }
68309 + }
68310 +
68311 + // lookup parent
68312 +
68313 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
68314 +
68315 + preempt_enable();
68316 + return matchpo;
68317 +}
68318 +
68319 +__u32
68320 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
68321 + const struct vfsmount * mnt, const __u32 mode)
68322 +{
68323 + struct acl_object_label *matchpo;
68324 + __u32 retval;
68325 +
68326 + if (unlikely(!(gr_status & GR_READY)))
68327 + return (mode & ~GR_AUDITS);
68328 +
68329 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
68330 +
68331 + retval = matchpo->mode & mode;
68332 +
68333 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
68334 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
68335 + __u32 new_mode = mode;
68336 +
68337 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
68338 +
68339 + gr_log_learn(new_dentry, mnt, new_mode);
68340 + return new_mode;
68341 + }
68342 +
68343 + return retval;
68344 +}
68345 +
68346 +__u32
68347 +gr_check_link(const struct dentry * new_dentry,
68348 + const struct dentry * parent_dentry,
68349 + const struct vfsmount * parent_mnt,
68350 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
68351 +{
68352 + struct acl_object_label *obj;
68353 + __u32 oldmode, newmode;
68354 + __u32 needmode;
68355 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
68356 + GR_DELETE | GR_INHERIT;
68357 +
68358 + if (unlikely(!(gr_status & GR_READY)))
68359 + return (GR_CREATE | GR_LINK);
68360 +
68361 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
68362 + oldmode = obj->mode;
68363 +
68364 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
68365 + newmode = obj->mode;
68366 +
68367 + needmode = newmode & checkmodes;
68368 +
68369 + // old name for hardlink must have at least the permissions of the new name
68370 + if ((oldmode & needmode) != needmode)
68371 + goto bad;
68372 +
68373 + // if old name had restrictions/auditing, make sure the new name does as well
68374 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
68375 +
68376 + // don't allow hardlinking of suid/sgid/fcapped files without permission
68377 + if (is_privileged_binary(old_dentry))
68378 + needmode |= GR_SETID;
68379 +
68380 + if ((newmode & needmode) != needmode)
68381 + goto bad;
68382 +
68383 + // enforce minimum permissions
68384 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
68385 + return newmode;
68386 +bad:
68387 + needmode = oldmode;
68388 + if (is_privileged_binary(old_dentry))
68389 + needmode |= GR_SETID;
68390 +
68391 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
68392 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
68393 + return (GR_CREATE | GR_LINK);
68394 + } else if (newmode & GR_SUPPRESS)
68395 + return GR_SUPPRESS;
68396 + else
68397 + return 0;
68398 +}
68399 +
68400 +int
68401 +gr_check_hidden_task(const struct task_struct *task)
68402 +{
68403 + if (unlikely(!(gr_status & GR_READY)))
68404 + return 0;
68405 +
68406 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
68407 + return 1;
68408 +
68409 + return 0;
68410 +}
68411 +
68412 +int
68413 +gr_check_protected_task(const struct task_struct *task)
68414 +{
68415 + if (unlikely(!(gr_status & GR_READY) || !task))
68416 + return 0;
68417 +
68418 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
68419 + task->acl != current->acl)
68420 + return 1;
68421 +
68422 + return 0;
68423 +}
68424 +
68425 +int
68426 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
68427 +{
68428 + struct task_struct *p;
68429 + int ret = 0;
68430 +
68431 + if (unlikely(!(gr_status & GR_READY) || !pid))
68432 + return ret;
68433 +
68434 + read_lock(&tasklist_lock);
68435 + do_each_pid_task(pid, type, p) {
68436 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
68437 + p->acl != current->acl) {
68438 + ret = 1;
68439 + goto out;
68440 + }
68441 + } while_each_pid_task(pid, type, p);
68442 +out:
68443 + read_unlock(&tasklist_lock);
68444 +
68445 + return ret;
68446 +}
68447 +
68448 +void
68449 +gr_copy_label(struct task_struct *tsk)
68450 +{
68451 + struct task_struct *p = current;
68452 +
68453 + tsk->inherited = p->inherited;
68454 + tsk->acl_sp_role = 0;
68455 + tsk->acl_role_id = p->acl_role_id;
68456 + tsk->acl = p->acl;
68457 + tsk->role = p->role;
68458 + tsk->signal->used_accept = 0;
68459 + tsk->signal->curr_ip = p->signal->curr_ip;
68460 + tsk->signal->saved_ip = p->signal->saved_ip;
68461 + if (p->exec_file)
68462 + get_file(p->exec_file);
68463 + tsk->exec_file = p->exec_file;
68464 + tsk->is_writable = p->is_writable;
68465 + if (unlikely(p->signal->used_accept)) {
68466 + p->signal->curr_ip = 0;
68467 + p->signal->saved_ip = 0;
68468 + }
68469 +
68470 + return;
68471 +}
68472 +
68473 +extern int gr_process_kernel_setuid_ban(struct user_struct *user);
68474 +
68475 +int
68476 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
68477 +{
68478 + unsigned int i;
68479 + __u16 num;
68480 + uid_t *uidlist;
68481 + uid_t curuid;
68482 + int realok = 0;
68483 + int effectiveok = 0;
68484 + int fsok = 0;
68485 + uid_t globalreal, globaleffective, globalfs;
68486 +
68487 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
68488 + struct user_struct *user;
68489 +
68490 + if (!uid_valid(real))
68491 + goto skipit;
68492 +
68493 + /* find user based on global namespace */
68494 +
68495 + globalreal = GR_GLOBAL_UID(real);
68496 +
68497 + user = find_user(make_kuid(&init_user_ns, globalreal));
68498 + if (user == NULL)
68499 + goto skipit;
68500 +
68501 + if (gr_process_kernel_setuid_ban(user)) {
68502 + /* for find_user */
68503 + free_uid(user);
68504 + return 1;
68505 + }
68506 +
68507 + /* for find_user */
68508 + free_uid(user);
68509 +
68510 +skipit:
68511 +#endif
68512 +
68513 + if (unlikely(!(gr_status & GR_READY)))
68514 + return 0;
68515 +
68516 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
68517 + gr_log_learn_uid_change(real, effective, fs);
68518 +
68519 + num = current->acl->user_trans_num;
68520 + uidlist = current->acl->user_transitions;
68521 +
68522 + if (uidlist == NULL)
68523 + return 0;
68524 +
68525 + if (!uid_valid(real)) {
68526 + realok = 1;
68527 + globalreal = (uid_t)-1;
68528 + } else {
68529 + globalreal = GR_GLOBAL_UID(real);
68530 + }
68531 + if (!uid_valid(effective)) {
68532 + effectiveok = 1;
68533 + globaleffective = (uid_t)-1;
68534 + } else {
68535 + globaleffective = GR_GLOBAL_UID(effective);
68536 + }
68537 + if (!uid_valid(fs)) {
68538 + fsok = 1;
68539 + globalfs = (uid_t)-1;
68540 + } else {
68541 + globalfs = GR_GLOBAL_UID(fs);
68542 + }
68543 +
68544 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
68545 + for (i = 0; i < num; i++) {
68546 + curuid = uidlist[i];
68547 + if (globalreal == curuid)
68548 + realok = 1;
68549 + if (globaleffective == curuid)
68550 + effectiveok = 1;
68551 + if (globalfs == curuid)
68552 + fsok = 1;
68553 + }
68554 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
68555 + for (i = 0; i < num; i++) {
68556 + curuid = uidlist[i];
68557 + if (globalreal == curuid)
68558 + break;
68559 + if (globaleffective == curuid)
68560 + break;
68561 + if (globalfs == curuid)
68562 + break;
68563 + }
68564 + /* not in deny list */
68565 + if (i == num) {
68566 + realok = 1;
68567 + effectiveok = 1;
68568 + fsok = 1;
68569 + }
68570 + }
68571 +
68572 + if (realok && effectiveok && fsok)
68573 + return 0;
68574 + else {
68575 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
68576 + return 1;
68577 + }
68578 +}
68579 +
68580 +int
68581 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
68582 +{
68583 + unsigned int i;
68584 + __u16 num;
68585 + gid_t *gidlist;
68586 + gid_t curgid;
68587 + int realok = 0;
68588 + int effectiveok = 0;
68589 + int fsok = 0;
68590 + gid_t globalreal, globaleffective, globalfs;
68591 +
68592 + if (unlikely(!(gr_status & GR_READY)))
68593 + return 0;
68594 +
68595 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
68596 + gr_log_learn_gid_change(real, effective, fs);
68597 +
68598 + num = current->acl->group_trans_num;
68599 + gidlist = current->acl->group_transitions;
68600 +
68601 + if (gidlist == NULL)
68602 + return 0;
68603 +
68604 + if (!gid_valid(real)) {
68605 + realok = 1;
68606 + globalreal = (gid_t)-1;
68607 + } else {
68608 + globalreal = GR_GLOBAL_GID(real);
68609 + }
68610 + if (!gid_valid(effective)) {
68611 + effectiveok = 1;
68612 + globaleffective = (gid_t)-1;
68613 + } else {
68614 + globaleffective = GR_GLOBAL_GID(effective);
68615 + }
68616 + if (!gid_valid(fs)) {
68617 + fsok = 1;
68618 + globalfs = (gid_t)-1;
68619 + } else {
68620 + globalfs = GR_GLOBAL_GID(fs);
68621 + }
68622 +
68623 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
68624 + for (i = 0; i < num; i++) {
68625 + curgid = gidlist[i];
68626 + if (globalreal == curgid)
68627 + realok = 1;
68628 + if (globaleffective == curgid)
68629 + effectiveok = 1;
68630 + if (globalfs == curgid)
68631 + fsok = 1;
68632 + }
68633 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
68634 + for (i = 0; i < num; i++) {
68635 + curgid = gidlist[i];
68636 + if (globalreal == curgid)
68637 + break;
68638 + if (globaleffective == curgid)
68639 + break;
68640 + if (globalfs == curgid)
68641 + break;
68642 + }
68643 + /* not in deny list */
68644 + if (i == num) {
68645 + realok = 1;
68646 + effectiveok = 1;
68647 + fsok = 1;
68648 + }
68649 + }
68650 +
68651 + if (realok && effectiveok && fsok)
68652 + return 0;
68653 + else {
68654 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
68655 + return 1;
68656 + }
68657 +}
68658 +
68659 +extern int gr_acl_is_capable(const int cap);
68660 +
68661 +void
68662 +gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
68663 +{
68664 + struct acl_role_label *role = task->role;
68665 + struct acl_subject_label *subj = NULL;
68666 + struct acl_object_label *obj;
68667 + struct file *filp;
68668 + uid_t uid;
68669 + gid_t gid;
68670 +
68671 + if (unlikely(!(gr_status & GR_READY)))
68672 + return;
68673 +
68674 + uid = GR_GLOBAL_UID(kuid);
68675 + gid = GR_GLOBAL_GID(kgid);
68676 +
68677 + filp = task->exec_file;
68678 +
68679 + /* kernel process, we'll give them the kernel role */
68680 + if (unlikely(!filp)) {
68681 + task->role = running_polstate.kernel_role;
68682 + task->acl = running_polstate.kernel_role->root_label;
68683 + return;
68684 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
68685 + /* save the current ip at time of role lookup so that the proper
68686 + IP will be learned for role_allowed_ip */
68687 + task->signal->saved_ip = task->signal->curr_ip;
68688 + role = lookup_acl_role_label(task, uid, gid);
68689 + }
68690 +
68691 + /* don't change the role if we're not a privileged process */
68692 + if (role && task->role != role &&
68693 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
68694 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
68695 + return;
68696 +
68697 + /* perform subject lookup in possibly new role
68698 + we can use this result below in the case where role == task->role
68699 + */
68700 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
68701 +
68702 + /* if we changed uid/gid, but result in the same role
68703 + and are using inheritance, don't lose the inherited subject
68704 + if current subject is other than what normal lookup
68705 + would result in, we arrived via inheritance, don't
68706 + lose subject
68707 + */
68708 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
68709 + (subj == task->acl)))
68710 + task->acl = subj;
68711 +
68712 + /* leave task->inherited unaffected */
68713 +
68714 + task->role = role;
68715 +
68716 + task->is_writable = 0;
68717 +
68718 + /* ignore additional mmap checks for processes that are writable
68719 + by the default ACL */
68720 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
68721 + if (unlikely(obj->mode & GR_WRITE))
68722 + task->is_writable = 1;
68723 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
68724 + if (unlikely(obj->mode & GR_WRITE))
68725 + task->is_writable = 1;
68726 +
68727 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68728 + 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);
68729 +#endif
68730 +
68731 + gr_set_proc_res(task);
68732 +
68733 + return;
68734 +}
68735 +
68736 +int
68737 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
68738 + const int unsafe_flags)
68739 +{
68740 + struct task_struct *task = current;
68741 + struct acl_subject_label *newacl;
68742 + struct acl_object_label *obj;
68743 + __u32 retmode;
68744 +
68745 + if (unlikely(!(gr_status & GR_READY)))
68746 + return 0;
68747 +
68748 + newacl = chk_subj_label(dentry, mnt, task->role);
68749 +
68750 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
68751 + did an exec
68752 + */
68753 + rcu_read_lock();
68754 + read_lock(&tasklist_lock);
68755 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
68756 + (task->parent->acl->mode & GR_POVERRIDE))) {
68757 + read_unlock(&tasklist_lock);
68758 + rcu_read_unlock();
68759 + goto skip_check;
68760 + }
68761 + read_unlock(&tasklist_lock);
68762 + rcu_read_unlock();
68763 +
68764 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
68765 + !(task->role->roletype & GR_ROLE_GOD) &&
68766 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
68767 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
68768 + if (unsafe_flags & LSM_UNSAFE_SHARE)
68769 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
68770 + else
68771 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
68772 + return -EACCES;
68773 + }
68774 +
68775 +skip_check:
68776 +
68777 + obj = chk_obj_label(dentry, mnt, task->acl);
68778 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
68779 +
68780 + if (!(task->acl->mode & GR_INHERITLEARN) &&
68781 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
68782 + if (obj->nested)
68783 + task->acl = obj->nested;
68784 + else
68785 + task->acl = newacl;
68786 + task->inherited = 0;
68787 + } else {
68788 + task->inherited = 1;
68789 + if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
68790 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
68791 + }
68792 +
68793 + task->is_writable = 0;
68794 +
68795 + /* ignore additional mmap checks for processes that are writable
68796 + by the default ACL */
68797 + obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
68798 + if (unlikely(obj->mode & GR_WRITE))
68799 + task->is_writable = 1;
68800 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
68801 + if (unlikely(obj->mode & GR_WRITE))
68802 + task->is_writable = 1;
68803 +
68804 + gr_set_proc_res(task);
68805 +
68806 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
68807 + 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);
68808 +#endif
68809 + return 0;
68810 +}
68811 +
68812 +/* always called with valid inodev ptr */
68813 +static void
68814 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
68815 +{
68816 + struct acl_object_label *matchpo;
68817 + struct acl_subject_label *matchps;
68818 + struct acl_subject_label *subj;
68819 + struct acl_role_label *role;
68820 + unsigned int x;
68821 +
68822 + FOR_EACH_ROLE_START(role)
68823 + FOR_EACH_SUBJECT_START(role, subj, x)
68824 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
68825 + matchpo->mode |= GR_DELETED;
68826 + FOR_EACH_SUBJECT_END(subj,x)
68827 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
68828 + /* nested subjects aren't in the role's subj_hash table */
68829 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
68830 + matchpo->mode |= GR_DELETED;
68831 + FOR_EACH_NESTED_SUBJECT_END(subj)
68832 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
68833 + matchps->mode |= GR_DELETED;
68834 + FOR_EACH_ROLE_END(role)
68835 +
68836 + inodev->nentry->deleted = 1;
68837 +
68838 + return;
68839 +}
68840 +
68841 +void
68842 +gr_handle_delete(const ino_t ino, const dev_t dev)
68843 +{
68844 + struct inodev_entry *inodev;
68845 +
68846 + if (unlikely(!(gr_status & GR_READY)))
68847 + return;
68848 +
68849 + write_lock(&gr_inode_lock);
68850 + inodev = lookup_inodev_entry(ino, dev);
68851 + if (inodev != NULL)
68852 + do_handle_delete(inodev, ino, dev);
68853 + write_unlock(&gr_inode_lock);
68854 +
68855 + return;
68856 +}
68857 +
68858 +static void
68859 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
68860 + const ino_t newinode, const dev_t newdevice,
68861 + struct acl_subject_label *subj)
68862 +{
68863 + unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
68864 + struct acl_object_label *match;
68865 +
68866 + match = subj->obj_hash[index];
68867 +
68868 + while (match && (match->inode != oldinode ||
68869 + match->device != olddevice ||
68870 + !(match->mode & GR_DELETED)))
68871 + match = match->next;
68872 +
68873 + if (match && (match->inode == oldinode)
68874 + && (match->device == olddevice)
68875 + && (match->mode & GR_DELETED)) {
68876 + if (match->prev == NULL) {
68877 + subj->obj_hash[index] = match->next;
68878 + if (match->next != NULL)
68879 + match->next->prev = NULL;
68880 + } else {
68881 + match->prev->next = match->next;
68882 + if (match->next != NULL)
68883 + match->next->prev = match->prev;
68884 + }
68885 + match->prev = NULL;
68886 + match->next = NULL;
68887 + match->inode = newinode;
68888 + match->device = newdevice;
68889 + match->mode &= ~GR_DELETED;
68890 +
68891 + insert_acl_obj_label(match, subj);
68892 + }
68893 +
68894 + return;
68895 +}
68896 +
68897 +static void
68898 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
68899 + const ino_t newinode, const dev_t newdevice,
68900 + struct acl_role_label *role)
68901 +{
68902 + unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
68903 + struct acl_subject_label *match;
68904 +
68905 + match = role->subj_hash[index];
68906 +
68907 + while (match && (match->inode != oldinode ||
68908 + match->device != olddevice ||
68909 + !(match->mode & GR_DELETED)))
68910 + match = match->next;
68911 +
68912 + if (match && (match->inode == oldinode)
68913 + && (match->device == olddevice)
68914 + && (match->mode & GR_DELETED)) {
68915 + if (match->prev == NULL) {
68916 + role->subj_hash[index] = match->next;
68917 + if (match->next != NULL)
68918 + match->next->prev = NULL;
68919 + } else {
68920 + match->prev->next = match->next;
68921 + if (match->next != NULL)
68922 + match->next->prev = match->prev;
68923 + }
68924 + match->prev = NULL;
68925 + match->next = NULL;
68926 + match->inode = newinode;
68927 + match->device = newdevice;
68928 + match->mode &= ~GR_DELETED;
68929 +
68930 + insert_acl_subj_label(match, role);
68931 + }
68932 +
68933 + return;
68934 +}
68935 +
68936 +static void
68937 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
68938 + const ino_t newinode, const dev_t newdevice)
68939 +{
68940 + unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
68941 + struct inodev_entry *match;
68942 +
68943 + match = running_polstate.inodev_set.i_hash[index];
68944 +
68945 + while (match && (match->nentry->inode != oldinode ||
68946 + match->nentry->device != olddevice || !match->nentry->deleted))
68947 + match = match->next;
68948 +
68949 + if (match && (match->nentry->inode == oldinode)
68950 + && (match->nentry->device == olddevice) &&
68951 + match->nentry->deleted) {
68952 + if (match->prev == NULL) {
68953 + running_polstate.inodev_set.i_hash[index] = match->next;
68954 + if (match->next != NULL)
68955 + match->next->prev = NULL;
68956 + } else {
68957 + match->prev->next = match->next;
68958 + if (match->next != NULL)
68959 + match->next->prev = match->prev;
68960 + }
68961 + match->prev = NULL;
68962 + match->next = NULL;
68963 + match->nentry->inode = newinode;
68964 + match->nentry->device = newdevice;
68965 + match->nentry->deleted = 0;
68966 +
68967 + insert_inodev_entry(match);
68968 + }
68969 +
68970 + return;
68971 +}
68972 +
68973 +static void
68974 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
68975 +{
68976 + struct acl_subject_label *subj;
68977 + struct acl_role_label *role;
68978 + unsigned int x;
68979 +
68980 + FOR_EACH_ROLE_START(role)
68981 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
68982 +
68983 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
68984 + if ((subj->inode == ino) && (subj->device == dev)) {
68985 + subj->inode = ino;
68986 + subj->device = dev;
68987 + }
68988 + /* nested subjects aren't in the role's subj_hash table */
68989 + update_acl_obj_label(matchn->inode, matchn->device,
68990 + ino, dev, subj);
68991 + FOR_EACH_NESTED_SUBJECT_END(subj)
68992 + FOR_EACH_SUBJECT_START(role, subj, x)
68993 + update_acl_obj_label(matchn->inode, matchn->device,
68994 + ino, dev, subj);
68995 + FOR_EACH_SUBJECT_END(subj,x)
68996 + FOR_EACH_ROLE_END(role)
68997 +
68998 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
68999 +
69000 + return;
69001 +}
69002 +
69003 +static void
69004 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
69005 + const struct vfsmount *mnt)
69006 +{
69007 + ino_t ino = dentry->d_inode->i_ino;
69008 + dev_t dev = __get_dev(dentry);
69009 +
69010 + __do_handle_create(matchn, ino, dev);
69011 +
69012 + return;
69013 +}
69014 +
69015 +void
69016 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
69017 +{
69018 + struct name_entry *matchn;
69019 +
69020 + if (unlikely(!(gr_status & GR_READY)))
69021 + return;
69022 +
69023 + preempt_disable();
69024 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
69025 +
69026 + if (unlikely((unsigned long)matchn)) {
69027 + write_lock(&gr_inode_lock);
69028 + do_handle_create(matchn, dentry, mnt);
69029 + write_unlock(&gr_inode_lock);
69030 + }
69031 + preempt_enable();
69032 +
69033 + return;
69034 +}
69035 +
69036 +void
69037 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
69038 +{
69039 + struct name_entry *matchn;
69040 +
69041 + if (unlikely(!(gr_status & GR_READY)))
69042 + return;
69043 +
69044 + preempt_disable();
69045 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
69046 +
69047 + if (unlikely((unsigned long)matchn)) {
69048 + write_lock(&gr_inode_lock);
69049 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
69050 + write_unlock(&gr_inode_lock);
69051 + }
69052 + preempt_enable();
69053 +
69054 + return;
69055 +}
69056 +
69057 +void
69058 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
69059 + struct dentry *old_dentry,
69060 + struct dentry *new_dentry,
69061 + struct vfsmount *mnt, const __u8 replace, unsigned int flags)
69062 +{
69063 + struct name_entry *matchn;
69064 + struct name_entry *matchn2 = NULL;
69065 + struct inodev_entry *inodev;
69066 + struct inode *inode = new_dentry->d_inode;
69067 + ino_t old_ino = old_dentry->d_inode->i_ino;
69068 + dev_t old_dev = __get_dev(old_dentry);
69069 + unsigned int exchange = flags & RENAME_EXCHANGE;
69070 +
69071 + /* vfs_rename swaps the name and parent link for old_dentry and
69072 + new_dentry
69073 + at this point, old_dentry has the new name, parent link, and inode
69074 + for the renamed file
69075 + if a file is being replaced by a rename, new_dentry has the inode
69076 + and name for the replaced file
69077 + */
69078 +
69079 + if (unlikely(!(gr_status & GR_READY)))
69080 + return;
69081 +
69082 + preempt_disable();
69083 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
69084 +
69085 + /* exchange cases:
69086 + a filename exists for the source, but not dest
69087 + do a recreate on source
69088 + a filename exists for the dest, but not source
69089 + do a recreate on dest
69090 + a filename exists for both source and dest
69091 + delete source and dest, then create source and dest
69092 + a filename exists for neither source nor dest
69093 + no updates needed
69094 +
69095 + the name entry lookups get us the old inode/dev associated with
69096 + each name, so do the deletes first (if possible) so that when
69097 + we do the create, we pick up on the right entries
69098 + */
69099 +
69100 + if (exchange)
69101 + matchn2 = lookup_name_entry(gr_to_filename_rbac(new_dentry, mnt));
69102 +
69103 + /* we wouldn't have to check d_inode if it weren't for
69104 + NFS silly-renaming
69105 + */
69106 +
69107 + write_lock(&gr_inode_lock);
69108 + if (unlikely((replace || exchange) && inode)) {
69109 + ino_t new_ino = inode->i_ino;
69110 + dev_t new_dev = __get_dev(new_dentry);
69111 +
69112 + inodev = lookup_inodev_entry(new_ino, new_dev);
69113 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
69114 + do_handle_delete(inodev, new_ino, new_dev);
69115 + }
69116 +
69117 + inodev = lookup_inodev_entry(old_ino, old_dev);
69118 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
69119 + do_handle_delete(inodev, old_ino, old_dev);
69120 +
69121 + if (unlikely(matchn != NULL))
69122 + do_handle_create(matchn, old_dentry, mnt);
69123 +
69124 + if (unlikely(matchn2 != NULL))
69125 + do_handle_create(matchn2, new_dentry, mnt);
69126 +
69127 + write_unlock(&gr_inode_lock);
69128 + preempt_enable();
69129 +
69130 + return;
69131 +}
69132 +
69133 +#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
69134 +static const unsigned long res_learn_bumps[GR_NLIMITS] = {
69135 + [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
69136 + [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
69137 + [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
69138 + [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
69139 + [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
69140 + [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
69141 + [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
69142 + [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
69143 + [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
69144 + [RLIMIT_AS] = GR_RLIM_AS_BUMP,
69145 + [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
69146 + [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
69147 + [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
69148 + [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
69149 + [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
69150 + [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
69151 +};
69152 +
69153 +void
69154 +gr_learn_resource(const struct task_struct *task,
69155 + const int res, const unsigned long wanted, const int gt)
69156 +{
69157 + struct acl_subject_label *acl;
69158 + const struct cred *cred;
69159 +
69160 + if (unlikely((gr_status & GR_READY) &&
69161 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
69162 + goto skip_reslog;
69163 +
69164 + gr_log_resource(task, res, wanted, gt);
69165 +skip_reslog:
69166 +
69167 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
69168 + return;
69169 +
69170 + acl = task->acl;
69171 +
69172 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
69173 + !(acl->resmask & (1U << (unsigned short) res))))
69174 + return;
69175 +
69176 + if (wanted >= acl->res[res].rlim_cur) {
69177 + unsigned long res_add;
69178 +
69179 + res_add = wanted + res_learn_bumps[res];
69180 +
69181 + acl->res[res].rlim_cur = res_add;
69182 +
69183 + if (wanted > acl->res[res].rlim_max)
69184 + acl->res[res].rlim_max = res_add;
69185 +
69186 + /* only log the subject filename, since resource logging is supported for
69187 + single-subject learning only */
69188 + rcu_read_lock();
69189 + cred = __task_cred(task);
69190 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
69191 + task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
69192 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
69193 + "", (unsigned long) res, &task->signal->saved_ip);
69194 + rcu_read_unlock();
69195 + }
69196 +
69197 + return;
69198 +}
69199 +EXPORT_SYMBOL_GPL(gr_learn_resource);
69200 +#endif
69201 +
69202 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
69203 +void
69204 +pax_set_initial_flags(struct linux_binprm *bprm)
69205 +{
69206 + struct task_struct *task = current;
69207 + struct acl_subject_label *proc;
69208 + unsigned long flags;
69209 +
69210 + if (unlikely(!(gr_status & GR_READY)))
69211 + return;
69212 +
69213 + flags = pax_get_flags(task);
69214 +
69215 + proc = task->acl;
69216 +
69217 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
69218 + flags &= ~MF_PAX_PAGEEXEC;
69219 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
69220 + flags &= ~MF_PAX_SEGMEXEC;
69221 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
69222 + flags &= ~MF_PAX_RANDMMAP;
69223 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
69224 + flags &= ~MF_PAX_EMUTRAMP;
69225 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
69226 + flags &= ~MF_PAX_MPROTECT;
69227 +
69228 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
69229 + flags |= MF_PAX_PAGEEXEC;
69230 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
69231 + flags |= MF_PAX_SEGMEXEC;
69232 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
69233 + flags |= MF_PAX_RANDMMAP;
69234 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
69235 + flags |= MF_PAX_EMUTRAMP;
69236 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
69237 + flags |= MF_PAX_MPROTECT;
69238 +
69239 + pax_set_flags(task, flags);
69240 +
69241 + return;
69242 +}
69243 +#endif
69244 +
69245 +int
69246 +gr_handle_proc_ptrace(struct task_struct *task)
69247 +{
69248 + struct file *filp;
69249 + struct task_struct *tmp = task;
69250 + struct task_struct *curtemp = current;
69251 + __u32 retmode;
69252 +
69253 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
69254 + if (unlikely(!(gr_status & GR_READY)))
69255 + return 0;
69256 +#endif
69257 +
69258 + read_lock(&tasklist_lock);
69259 + read_lock(&grsec_exec_file_lock);
69260 + filp = task->exec_file;
69261 +
69262 + while (task_pid_nr(tmp) > 0) {
69263 + if (tmp == curtemp)
69264 + break;
69265 + tmp = tmp->real_parent;
69266 + }
69267 +
69268 + if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
69269 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
69270 + read_unlock(&grsec_exec_file_lock);
69271 + read_unlock(&tasklist_lock);
69272 + return 1;
69273 + }
69274 +
69275 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
69276 + if (!(gr_status & GR_READY)) {
69277 + read_unlock(&grsec_exec_file_lock);
69278 + read_unlock(&tasklist_lock);
69279 + return 0;
69280 + }
69281 +#endif
69282 +
69283 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
69284 + read_unlock(&grsec_exec_file_lock);
69285 + read_unlock(&tasklist_lock);
69286 +
69287 + if (retmode & GR_NOPTRACE)
69288 + return 1;
69289 +
69290 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
69291 + && (current->acl != task->acl || (current->acl != current->role->root_label
69292 + && task_pid_nr(current) != task_pid_nr(task))))
69293 + return 1;
69294 +
69295 + return 0;
69296 +}
69297 +
69298 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
69299 +{
69300 + if (unlikely(!(gr_status & GR_READY)))
69301 + return;
69302 +
69303 + if (!(current->role->roletype & GR_ROLE_GOD))
69304 + return;
69305 +
69306 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
69307 + p->role->rolename, gr_task_roletype_to_char(p),
69308 + p->acl->filename);
69309 +}
69310 +
69311 +int
69312 +gr_handle_ptrace(struct task_struct *task, const long request)
69313 +{
69314 + struct task_struct *tmp = task;
69315 + struct task_struct *curtemp = current;
69316 + __u32 retmode;
69317 +
69318 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
69319 + if (unlikely(!(gr_status & GR_READY)))
69320 + return 0;
69321 +#endif
69322 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69323 + read_lock(&tasklist_lock);
69324 + while (task_pid_nr(tmp) > 0) {
69325 + if (tmp == curtemp)
69326 + break;
69327 + tmp = tmp->real_parent;
69328 + }
69329 +
69330 + if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
69331 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
69332 + read_unlock(&tasklist_lock);
69333 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
69334 + return 1;
69335 + }
69336 + read_unlock(&tasklist_lock);
69337 + }
69338 +
69339 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
69340 + if (!(gr_status & GR_READY))
69341 + return 0;
69342 +#endif
69343 +
69344 + read_lock(&grsec_exec_file_lock);
69345 + if (unlikely(!task->exec_file)) {
69346 + read_unlock(&grsec_exec_file_lock);
69347 + return 0;
69348 + }
69349 +
69350 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
69351 + read_unlock(&grsec_exec_file_lock);
69352 +
69353 + if (retmode & GR_NOPTRACE) {
69354 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
69355 + return 1;
69356 + }
69357 +
69358 + if (retmode & GR_PTRACERD) {
69359 + switch (request) {
69360 + case PTRACE_SEIZE:
69361 + case PTRACE_POKETEXT:
69362 + case PTRACE_POKEDATA:
69363 + case PTRACE_POKEUSR:
69364 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
69365 + case PTRACE_SETREGS:
69366 + case PTRACE_SETFPREGS:
69367 +#endif
69368 +#ifdef CONFIG_X86
69369 + case PTRACE_SETFPXREGS:
69370 +#endif
69371 +#ifdef CONFIG_ALTIVEC
69372 + case PTRACE_SETVRREGS:
69373 +#endif
69374 + return 1;
69375 + default:
69376 + return 0;
69377 + }
69378 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
69379 + !(current->role->roletype & GR_ROLE_GOD) &&
69380 + (current->acl != task->acl)) {
69381 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
69382 + return 1;
69383 + }
69384 +
69385 + return 0;
69386 +}
69387 +
69388 +static int is_writable_mmap(const struct file *filp)
69389 +{
69390 + struct task_struct *task = current;
69391 + struct acl_object_label *obj, *obj2;
69392 +
69393 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
69394 + !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))) {
69395 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
69396 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
69397 + task->role->root_label);
69398 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
69399 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
69400 + return 1;
69401 + }
69402 + }
69403 + return 0;
69404 +}
69405 +
69406 +int
69407 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
69408 +{
69409 + __u32 mode;
69410 +
69411 + if (unlikely(!file || !(prot & PROT_EXEC)))
69412 + return 1;
69413 +
69414 + if (is_writable_mmap(file))
69415 + return 0;
69416 +
69417 + mode =
69418 + gr_search_file(file->f_path.dentry,
69419 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
69420 + file->f_path.mnt);
69421 +
69422 + if (!gr_tpe_allow(file))
69423 + return 0;
69424 +
69425 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
69426 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69427 + return 0;
69428 + } else if (unlikely(!(mode & GR_EXEC))) {
69429 + return 0;
69430 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
69431 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69432 + return 1;
69433 + }
69434 +
69435 + return 1;
69436 +}
69437 +
69438 +int
69439 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
69440 +{
69441 + __u32 mode;
69442 +
69443 + if (unlikely(!file || !(prot & PROT_EXEC)))
69444 + return 1;
69445 +
69446 + if (is_writable_mmap(file))
69447 + return 0;
69448 +
69449 + mode =
69450 + gr_search_file(file->f_path.dentry,
69451 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
69452 + file->f_path.mnt);
69453 +
69454 + if (!gr_tpe_allow(file))
69455 + return 0;
69456 +
69457 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
69458 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69459 + return 0;
69460 + } else if (unlikely(!(mode & GR_EXEC))) {
69461 + return 0;
69462 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
69463 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
69464 + return 1;
69465 + }
69466 +
69467 + return 1;
69468 +}
69469 +
69470 +void
69471 +gr_acl_handle_psacct(struct task_struct *task, const long code)
69472 +{
69473 + unsigned long runtime, cputime;
69474 + cputime_t utime, stime;
69475 + unsigned int wday, cday;
69476 + __u8 whr, chr;
69477 + __u8 wmin, cmin;
69478 + __u8 wsec, csec;
69479 + struct timespec timeval;
69480 +
69481 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
69482 + !(task->acl->mode & GR_PROCACCT)))
69483 + return;
69484 +
69485 + do_posix_clock_monotonic_gettime(&timeval);
69486 + runtime = timeval.tv_sec - task->start_time.tv_sec;
69487 + wday = runtime / (60 * 60 * 24);
69488 + runtime -= wday * (60 * 60 * 24);
69489 + whr = runtime / (60 * 60);
69490 + runtime -= whr * (60 * 60);
69491 + wmin = runtime / 60;
69492 + runtime -= wmin * 60;
69493 + wsec = runtime;
69494 +
69495 + task_cputime(task, &utime, &stime);
69496 + cputime = cputime_to_secs(utime + stime);
69497 + cday = cputime / (60 * 60 * 24);
69498 + cputime -= cday * (60 * 60 * 24);
69499 + chr = cputime / (60 * 60);
69500 + cputime -= chr * (60 * 60);
69501 + cmin = cputime / 60;
69502 + cputime -= cmin * 60;
69503 + csec = cputime;
69504 +
69505 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
69506 +
69507 + return;
69508 +}
69509 +
69510 +#ifdef CONFIG_TASKSTATS
69511 +int gr_is_taskstats_denied(int pid)
69512 +{
69513 + struct task_struct *task;
69514 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69515 + const struct cred *cred;
69516 +#endif
69517 + int ret = 0;
69518 +
69519 + /* restrict taskstats viewing to un-chrooted root users
69520 + who have the 'view' subject flag if the RBAC system is enabled
69521 + */
69522 +
69523 + rcu_read_lock();
69524 + read_lock(&tasklist_lock);
69525 + task = find_task_by_vpid(pid);
69526 + if (task) {
69527 +#ifdef CONFIG_GRKERNSEC_CHROOT
69528 + if (proc_is_chrooted(task))
69529 + ret = -EACCES;
69530 +#endif
69531 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69532 + cred = __task_cred(task);
69533 +#ifdef CONFIG_GRKERNSEC_PROC_USER
69534 + if (gr_is_global_nonroot(cred->uid))
69535 + ret = -EACCES;
69536 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69537 + if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
69538 + ret = -EACCES;
69539 +#endif
69540 +#endif
69541 + if (gr_status & GR_READY) {
69542 + if (!(task->acl->mode & GR_VIEW))
69543 + ret = -EACCES;
69544 + }
69545 + } else
69546 + ret = -ENOENT;
69547 +
69548 + read_unlock(&tasklist_lock);
69549 + rcu_read_unlock();
69550 +
69551 + return ret;
69552 +}
69553 +#endif
69554 +
69555 +/* AUXV entries are filled via a descendant of search_binary_handler
69556 + after we've already applied the subject for the target
69557 +*/
69558 +int gr_acl_enable_at_secure(void)
69559 +{
69560 + if (unlikely(!(gr_status & GR_READY)))
69561 + return 0;
69562 +
69563 + if (current->acl->mode & GR_ATSECURE)
69564 + return 1;
69565 +
69566 + return 0;
69567 +}
69568 +
69569 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
69570 +{
69571 + struct task_struct *task = current;
69572 + struct dentry *dentry = file->f_path.dentry;
69573 + struct vfsmount *mnt = file->f_path.mnt;
69574 + struct acl_object_label *obj, *tmp;
69575 + struct acl_subject_label *subj;
69576 + unsigned int bufsize;
69577 + int is_not_root;
69578 + char *path;
69579 + dev_t dev = __get_dev(dentry);
69580 +
69581 + if (unlikely(!(gr_status & GR_READY)))
69582 + return 1;
69583 +
69584 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
69585 + return 1;
69586 +
69587 + /* ignore Eric Biederman */
69588 + if (IS_PRIVATE(dentry->d_inode))
69589 + return 1;
69590 +
69591 + subj = task->acl;
69592 + read_lock(&gr_inode_lock);
69593 + do {
69594 + obj = lookup_acl_obj_label(ino, dev, subj);
69595 + if (obj != NULL) {
69596 + read_unlock(&gr_inode_lock);
69597 + return (obj->mode & GR_FIND) ? 1 : 0;
69598 + }
69599 + } while ((subj = subj->parent_subject));
69600 + read_unlock(&gr_inode_lock);
69601 +
69602 + /* this is purely an optimization since we're looking for an object
69603 + for the directory we're doing a readdir on
69604 + if it's possible for any globbed object to match the entry we're
69605 + filling into the directory, then the object we find here will be
69606 + an anchor point with attached globbed objects
69607 + */
69608 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
69609 + if (obj->globbed == NULL)
69610 + return (obj->mode & GR_FIND) ? 1 : 0;
69611 +
69612 + is_not_root = ((obj->filename[0] == '/') &&
69613 + (obj->filename[1] == '\0')) ? 0 : 1;
69614 + bufsize = PAGE_SIZE - namelen - is_not_root;
69615 +
69616 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
69617 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
69618 + return 1;
69619 +
69620 + preempt_disable();
69621 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
69622 + bufsize);
69623 +
69624 + bufsize = strlen(path);
69625 +
69626 + /* if base is "/", don't append an additional slash */
69627 + if (is_not_root)
69628 + *(path + bufsize) = '/';
69629 + memcpy(path + bufsize + is_not_root, name, namelen);
69630 + *(path + bufsize + namelen + is_not_root) = '\0';
69631 +
69632 + tmp = obj->globbed;
69633 + while (tmp) {
69634 + if (!glob_match(tmp->filename, path)) {
69635 + preempt_enable();
69636 + return (tmp->mode & GR_FIND) ? 1 : 0;
69637 + }
69638 + tmp = tmp->next;
69639 + }
69640 + preempt_enable();
69641 + return (obj->mode & GR_FIND) ? 1 : 0;
69642 +}
69643 +
69644 +void gr_put_exec_file(struct task_struct *task)
69645 +{
69646 + struct file *filp;
69647 +
69648 + write_lock(&grsec_exec_file_lock);
69649 + filp = task->exec_file;
69650 + task->exec_file = NULL;
69651 + write_unlock(&grsec_exec_file_lock);
69652 +
69653 + if (filp)
69654 + fput(filp);
69655 +
69656 + return;
69657 +}
69658 +
69659 +
69660 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
69661 +EXPORT_SYMBOL_GPL(gr_acl_is_enabled);
69662 +#endif
69663 +#ifdef CONFIG_SECURITY
69664 +EXPORT_SYMBOL_GPL(gr_check_user_change);
69665 +EXPORT_SYMBOL_GPL(gr_check_group_change);
69666 +#endif
69667 +
69668 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
69669 new file mode 100644
69670 index 0000000..18ffbbd
69671 --- /dev/null
69672 +++ b/grsecurity/gracl_alloc.c
69673 @@ -0,0 +1,105 @@
69674 +#include <linux/kernel.h>
69675 +#include <linux/mm.h>
69676 +#include <linux/slab.h>
69677 +#include <linux/vmalloc.h>
69678 +#include <linux/gracl.h>
69679 +#include <linux/grsecurity.h>
69680 +
69681 +static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
69682 +struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
69683 +
69684 +static __inline__ int
69685 +alloc_pop(void)
69686 +{
69687 + if (current_alloc_state->alloc_stack_next == 1)
69688 + return 0;
69689 +
69690 + kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
69691 +
69692 + current_alloc_state->alloc_stack_next--;
69693 +
69694 + return 1;
69695 +}
69696 +
69697 +static __inline__ int
69698 +alloc_push(void *buf)
69699 +{
69700 + if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
69701 + return 1;
69702 +
69703 + current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
69704 +
69705 + current_alloc_state->alloc_stack_next++;
69706 +
69707 + return 0;
69708 +}
69709 +
69710 +void *
69711 +acl_alloc(unsigned long len)
69712 +{
69713 + void *ret = NULL;
69714 +
69715 + if (!len || len > PAGE_SIZE)
69716 + goto out;
69717 +
69718 + ret = kmalloc(len, GFP_KERNEL);
69719 +
69720 + if (ret) {
69721 + if (alloc_push(ret)) {
69722 + kfree(ret);
69723 + ret = NULL;
69724 + }
69725 + }
69726 +
69727 +out:
69728 + return ret;
69729 +}
69730 +
69731 +void *
69732 +acl_alloc_num(unsigned long num, unsigned long len)
69733 +{
69734 + if (!len || (num > (PAGE_SIZE / len)))
69735 + return NULL;
69736 +
69737 + return acl_alloc(num * len);
69738 +}
69739 +
69740 +void
69741 +acl_free_all(void)
69742 +{
69743 + if (!current_alloc_state->alloc_stack)
69744 + return;
69745 +
69746 + while (alloc_pop()) ;
69747 +
69748 + if (current_alloc_state->alloc_stack) {
69749 + if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
69750 + kfree(current_alloc_state->alloc_stack);
69751 + else
69752 + vfree(current_alloc_state->alloc_stack);
69753 + }
69754 +
69755 + current_alloc_state->alloc_stack = NULL;
69756 + current_alloc_state->alloc_stack_size = 1;
69757 + current_alloc_state->alloc_stack_next = 1;
69758 +
69759 + return;
69760 +}
69761 +
69762 +int
69763 +acl_alloc_stack_init(unsigned long size)
69764 +{
69765 + if ((size * sizeof (void *)) <= PAGE_SIZE)
69766 + current_alloc_state->alloc_stack =
69767 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
69768 + else
69769 + current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
69770 +
69771 + current_alloc_state->alloc_stack_size = size;
69772 + current_alloc_state->alloc_stack_next = 1;
69773 +
69774 + if (!current_alloc_state->alloc_stack)
69775 + return 0;
69776 + else
69777 + return 1;
69778 +}
69779 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
69780 new file mode 100644
69781 index 0000000..bdd51ea
69782 --- /dev/null
69783 +++ b/grsecurity/gracl_cap.c
69784 @@ -0,0 +1,110 @@
69785 +#include <linux/kernel.h>
69786 +#include <linux/module.h>
69787 +#include <linux/sched.h>
69788 +#include <linux/gracl.h>
69789 +#include <linux/grsecurity.h>
69790 +#include <linux/grinternal.h>
69791 +
69792 +extern const char *captab_log[];
69793 +extern int captab_log_entries;
69794 +
69795 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
69796 +{
69797 + struct acl_subject_label *curracl;
69798 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
69799 + kernel_cap_t cap_audit = __cap_empty_set;
69800 +
69801 + if (!gr_acl_is_enabled())
69802 + return 1;
69803 +
69804 + curracl = task->acl;
69805 +
69806 + cap_drop = curracl->cap_lower;
69807 + cap_mask = curracl->cap_mask;
69808 + cap_audit = curracl->cap_invert_audit;
69809 +
69810 + while ((curracl = curracl->parent_subject)) {
69811 + /* if the cap isn't specified in the current computed mask but is specified in the
69812 + current level subject, and is lowered in the current level subject, then add
69813 + it to the set of dropped capabilities
69814 + otherwise, add the current level subject's mask to the current computed mask
69815 + */
69816 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
69817 + cap_raise(cap_mask, cap);
69818 + if (cap_raised(curracl->cap_lower, cap))
69819 + cap_raise(cap_drop, cap);
69820 + if (cap_raised(curracl->cap_invert_audit, cap))
69821 + cap_raise(cap_audit, cap);
69822 + }
69823 + }
69824 +
69825 + if (!cap_raised(cap_drop, cap)) {
69826 + if (cap_raised(cap_audit, cap))
69827 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
69828 + return 1;
69829 + }
69830 +
69831 + curracl = task->acl;
69832 +
69833 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
69834 + && cap_raised(cred->cap_effective, cap)) {
69835 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
69836 + task->role->roletype, GR_GLOBAL_UID(cred->uid),
69837 + GR_GLOBAL_GID(cred->gid), task->exec_file ?
69838 + gr_to_filename(task->exec_file->f_path.dentry,
69839 + task->exec_file->f_path.mnt) : curracl->filename,
69840 + curracl->filename, 0UL,
69841 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
69842 + return 1;
69843 + }
69844 +
69845 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
69846 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
69847 +
69848 + return 0;
69849 +}
69850 +
69851 +int
69852 +gr_acl_is_capable(const int cap)
69853 +{
69854 + return gr_task_acl_is_capable(current, current_cred(), cap);
69855 +}
69856 +
69857 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
69858 +{
69859 + struct acl_subject_label *curracl;
69860 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
69861 +
69862 + if (!gr_acl_is_enabled())
69863 + return 1;
69864 +
69865 + curracl = task->acl;
69866 +
69867 + cap_drop = curracl->cap_lower;
69868 + cap_mask = curracl->cap_mask;
69869 +
69870 + while ((curracl = curracl->parent_subject)) {
69871 + /* if the cap isn't specified in the current computed mask but is specified in the
69872 + current level subject, and is lowered in the current level subject, then add
69873 + it to the set of dropped capabilities
69874 + otherwise, add the current level subject's mask to the current computed mask
69875 + */
69876 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
69877 + cap_raise(cap_mask, cap);
69878 + if (cap_raised(curracl->cap_lower, cap))
69879 + cap_raise(cap_drop, cap);
69880 + }
69881 + }
69882 +
69883 + if (!cap_raised(cap_drop, cap))
69884 + return 1;
69885 +
69886 + return 0;
69887 +}
69888 +
69889 +int
69890 +gr_acl_is_capable_nolog(const int cap)
69891 +{
69892 + return gr_task_acl_is_capable_nolog(current, cap);
69893 +}
69894 +
69895 diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
69896 new file mode 100644
69897 index 0000000..ca25605
69898 --- /dev/null
69899 +++ b/grsecurity/gracl_compat.c
69900 @@ -0,0 +1,270 @@
69901 +#include <linux/kernel.h>
69902 +#include <linux/gracl.h>
69903 +#include <linux/compat.h>
69904 +#include <linux/gracl_compat.h>
69905 +
69906 +#include <asm/uaccess.h>
69907 +
69908 +int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
69909 +{
69910 + struct gr_arg_wrapper_compat uwrapcompat;
69911 +
69912 + if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
69913 + return -EFAULT;
69914 +
69915 + if (((uwrapcompat.version != GRSECURITY_VERSION) &&
69916 + (uwrapcompat.version != 0x2901)) ||
69917 + (uwrapcompat.size != sizeof(struct gr_arg_compat)))
69918 + return -EINVAL;
69919 +
69920 + uwrap->arg = compat_ptr(uwrapcompat.arg);
69921 + uwrap->version = uwrapcompat.version;
69922 + uwrap->size = sizeof(struct gr_arg);
69923 +
69924 + return 0;
69925 +}
69926 +
69927 +int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
69928 +{
69929 + struct gr_arg_compat argcompat;
69930 +
69931 + if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
69932 + return -EFAULT;
69933 +
69934 + arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
69935 + arg->role_db.num_pointers = argcompat.role_db.num_pointers;
69936 + arg->role_db.num_roles = argcompat.role_db.num_roles;
69937 + arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
69938 + arg->role_db.num_subjects = argcompat.role_db.num_subjects;
69939 + arg->role_db.num_objects = argcompat.role_db.num_objects;
69940 +
69941 + memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
69942 + memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
69943 + memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
69944 + memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
69945 + arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
69946 + arg->segv_device = argcompat.segv_device;
69947 + arg->segv_inode = argcompat.segv_inode;
69948 + arg->segv_uid = argcompat.segv_uid;
69949 + arg->num_sprole_pws = argcompat.num_sprole_pws;
69950 + arg->mode = argcompat.mode;
69951 +
69952 + return 0;
69953 +}
69954 +
69955 +int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
69956 +{
69957 + struct acl_object_label_compat objcompat;
69958 +
69959 + if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
69960 + return -EFAULT;
69961 +
69962 + obj->filename = compat_ptr(objcompat.filename);
69963 + obj->inode = objcompat.inode;
69964 + obj->device = objcompat.device;
69965 + obj->mode = objcompat.mode;
69966 +
69967 + obj->nested = compat_ptr(objcompat.nested);
69968 + obj->globbed = compat_ptr(objcompat.globbed);
69969 +
69970 + obj->prev = compat_ptr(objcompat.prev);
69971 + obj->next = compat_ptr(objcompat.next);
69972 +
69973 + return 0;
69974 +}
69975 +
69976 +int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
69977 +{
69978 + unsigned int i;
69979 + struct acl_subject_label_compat subjcompat;
69980 +
69981 + if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
69982 + return -EFAULT;
69983 +
69984 + subj->filename = compat_ptr(subjcompat.filename);
69985 + subj->inode = subjcompat.inode;
69986 + subj->device = subjcompat.device;
69987 + subj->mode = subjcompat.mode;
69988 + subj->cap_mask = subjcompat.cap_mask;
69989 + subj->cap_lower = subjcompat.cap_lower;
69990 + subj->cap_invert_audit = subjcompat.cap_invert_audit;
69991 +
69992 + for (i = 0; i < GR_NLIMITS; i++) {
69993 + if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
69994 + subj->res[i].rlim_cur = RLIM_INFINITY;
69995 + else
69996 + subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
69997 + if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
69998 + subj->res[i].rlim_max = RLIM_INFINITY;
69999 + else
70000 + subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
70001 + }
70002 + subj->resmask = subjcompat.resmask;
70003 +
70004 + subj->user_trans_type = subjcompat.user_trans_type;
70005 + subj->group_trans_type = subjcompat.group_trans_type;
70006 + subj->user_transitions = compat_ptr(subjcompat.user_transitions);
70007 + subj->group_transitions = compat_ptr(subjcompat.group_transitions);
70008 + subj->user_trans_num = subjcompat.user_trans_num;
70009 + subj->group_trans_num = subjcompat.group_trans_num;
70010 +
70011 + memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
70012 + memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
70013 + subj->ip_type = subjcompat.ip_type;
70014 + subj->ips = compat_ptr(subjcompat.ips);
70015 + subj->ip_num = subjcompat.ip_num;
70016 + subj->inaddr_any_override = subjcompat.inaddr_any_override;
70017 +
70018 + subj->crashes = subjcompat.crashes;
70019 + subj->expires = subjcompat.expires;
70020 +
70021 + subj->parent_subject = compat_ptr(subjcompat.parent_subject);
70022 + subj->hash = compat_ptr(subjcompat.hash);
70023 + subj->prev = compat_ptr(subjcompat.prev);
70024 + subj->next = compat_ptr(subjcompat.next);
70025 +
70026 + subj->obj_hash = compat_ptr(subjcompat.obj_hash);
70027 + subj->obj_hash_size = subjcompat.obj_hash_size;
70028 + subj->pax_flags = subjcompat.pax_flags;
70029 +
70030 + return 0;
70031 +}
70032 +
70033 +int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
70034 +{
70035 + struct acl_role_label_compat rolecompat;
70036 +
70037 + if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
70038 + return -EFAULT;
70039 +
70040 + role->rolename = compat_ptr(rolecompat.rolename);
70041 + role->uidgid = rolecompat.uidgid;
70042 + role->roletype = rolecompat.roletype;
70043 +
70044 + role->auth_attempts = rolecompat.auth_attempts;
70045 + role->expires = rolecompat.expires;
70046 +
70047 + role->root_label = compat_ptr(rolecompat.root_label);
70048 + role->hash = compat_ptr(rolecompat.hash);
70049 +
70050 + role->prev = compat_ptr(rolecompat.prev);
70051 + role->next = compat_ptr(rolecompat.next);
70052 +
70053 + role->transitions = compat_ptr(rolecompat.transitions);
70054 + role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
70055 + role->domain_children = compat_ptr(rolecompat.domain_children);
70056 + role->domain_child_num = rolecompat.domain_child_num;
70057 +
70058 + role->umask = rolecompat.umask;
70059 +
70060 + role->subj_hash = compat_ptr(rolecompat.subj_hash);
70061 + role->subj_hash_size = rolecompat.subj_hash_size;
70062 +
70063 + return 0;
70064 +}
70065 +
70066 +int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
70067 +{
70068 + struct role_allowed_ip_compat roleip_compat;
70069 +
70070 + if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
70071 + return -EFAULT;
70072 +
70073 + roleip->addr = roleip_compat.addr;
70074 + roleip->netmask = roleip_compat.netmask;
70075 +
70076 + roleip->prev = compat_ptr(roleip_compat.prev);
70077 + roleip->next = compat_ptr(roleip_compat.next);
70078 +
70079 + return 0;
70080 +}
70081 +
70082 +int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
70083 +{
70084 + struct role_transition_compat trans_compat;
70085 +
70086 + if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
70087 + return -EFAULT;
70088 +
70089 + trans->rolename = compat_ptr(trans_compat.rolename);
70090 +
70091 + trans->prev = compat_ptr(trans_compat.prev);
70092 + trans->next = compat_ptr(trans_compat.next);
70093 +
70094 + return 0;
70095 +
70096 +}
70097 +
70098 +int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
70099 +{
70100 + struct gr_hash_struct_compat hash_compat;
70101 +
70102 + if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
70103 + return -EFAULT;
70104 +
70105 + hash->table = compat_ptr(hash_compat.table);
70106 + hash->nametable = compat_ptr(hash_compat.nametable);
70107 + hash->first = compat_ptr(hash_compat.first);
70108 +
70109 + hash->table_size = hash_compat.table_size;
70110 + hash->used_size = hash_compat.used_size;
70111 +
70112 + hash->type = hash_compat.type;
70113 +
70114 + return 0;
70115 +}
70116 +
70117 +int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
70118 +{
70119 + compat_uptr_t ptrcompat;
70120 +
70121 + if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
70122 + return -EFAULT;
70123 +
70124 + *(void **)ptr = compat_ptr(ptrcompat);
70125 +
70126 + return 0;
70127 +}
70128 +
70129 +int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
70130 +{
70131 + struct acl_ip_label_compat ip_compat;
70132 +
70133 + if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
70134 + return -EFAULT;
70135 +
70136 + ip->iface = compat_ptr(ip_compat.iface);
70137 + ip->addr = ip_compat.addr;
70138 + ip->netmask = ip_compat.netmask;
70139 + ip->low = ip_compat.low;
70140 + ip->high = ip_compat.high;
70141 + ip->mode = ip_compat.mode;
70142 + ip->type = ip_compat.type;
70143 +
70144 + memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
70145 +
70146 + ip->prev = compat_ptr(ip_compat.prev);
70147 + ip->next = compat_ptr(ip_compat.next);
70148 +
70149 + return 0;
70150 +}
70151 +
70152 +int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
70153 +{
70154 + struct sprole_pw_compat pw_compat;
70155 +
70156 + if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
70157 + return -EFAULT;
70158 +
70159 + pw->rolename = compat_ptr(pw_compat.rolename);
70160 + memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
70161 + memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
70162 +
70163 + return 0;
70164 +}
70165 +
70166 +size_t get_gr_arg_wrapper_size_compat(void)
70167 +{
70168 + return sizeof(struct gr_arg_wrapper_compat);
70169 +}
70170 +
70171 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
70172 new file mode 100644
70173 index 0000000..4008fdc
70174 --- /dev/null
70175 +++ b/grsecurity/gracl_fs.c
70176 @@ -0,0 +1,445 @@
70177 +#include <linux/kernel.h>
70178 +#include <linux/sched.h>
70179 +#include <linux/types.h>
70180 +#include <linux/fs.h>
70181 +#include <linux/file.h>
70182 +#include <linux/stat.h>
70183 +#include <linux/grsecurity.h>
70184 +#include <linux/grinternal.h>
70185 +#include <linux/gracl.h>
70186 +
70187 +umode_t
70188 +gr_acl_umask(void)
70189 +{
70190 + if (unlikely(!gr_acl_is_enabled()))
70191 + return 0;
70192 +
70193 + return current->role->umask;
70194 +}
70195 +
70196 +__u32
70197 +gr_acl_handle_hidden_file(const struct dentry * dentry,
70198 + const struct vfsmount * mnt)
70199 +{
70200 + __u32 mode;
70201 +
70202 + if (unlikely(d_is_negative(dentry)))
70203 + return GR_FIND;
70204 +
70205 + mode =
70206 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
70207 +
70208 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
70209 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
70210 + return mode;
70211 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
70212 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
70213 + return 0;
70214 + } else if (unlikely(!(mode & GR_FIND)))
70215 + return 0;
70216 +
70217 + return GR_FIND;
70218 +}
70219 +
70220 +__u32
70221 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
70222 + int acc_mode)
70223 +{
70224 + __u32 reqmode = GR_FIND;
70225 + __u32 mode;
70226 +
70227 + if (unlikely(d_is_negative(dentry)))
70228 + return reqmode;
70229 +
70230 + if (acc_mode & MAY_APPEND)
70231 + reqmode |= GR_APPEND;
70232 + else if (acc_mode & MAY_WRITE)
70233 + reqmode |= GR_WRITE;
70234 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
70235 + reqmode |= GR_READ;
70236 +
70237 + mode =
70238 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
70239 + mnt);
70240 +
70241 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
70242 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
70243 + reqmode & GR_READ ? " reading" : "",
70244 + reqmode & GR_WRITE ? " writing" : reqmode &
70245 + GR_APPEND ? " appending" : "");
70246 + return reqmode;
70247 + } else
70248 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
70249 + {
70250 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
70251 + reqmode & GR_READ ? " reading" : "",
70252 + reqmode & GR_WRITE ? " writing" : reqmode &
70253 + GR_APPEND ? " appending" : "");
70254 + return 0;
70255 + } else if (unlikely((mode & reqmode) != reqmode))
70256 + return 0;
70257 +
70258 + return reqmode;
70259 +}
70260 +
70261 +__u32
70262 +gr_acl_handle_creat(const struct dentry * dentry,
70263 + const struct dentry * p_dentry,
70264 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
70265 + const int imode)
70266 +{
70267 + __u32 reqmode = GR_WRITE | GR_CREATE;
70268 + __u32 mode;
70269 +
70270 + if (acc_mode & MAY_APPEND)
70271 + reqmode |= GR_APPEND;
70272 + // if a directory was required or the directory already exists, then
70273 + // don't count this open as a read
70274 + if ((acc_mode & MAY_READ) &&
70275 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
70276 + reqmode |= GR_READ;
70277 + if ((open_flags & O_CREAT) &&
70278 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
70279 + reqmode |= GR_SETID;
70280 +
70281 + mode =
70282 + gr_check_create(dentry, p_dentry, p_mnt,
70283 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
70284 +
70285 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
70286 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
70287 + reqmode & GR_READ ? " reading" : "",
70288 + reqmode & GR_WRITE ? " writing" : reqmode &
70289 + GR_APPEND ? " appending" : "");
70290 + return reqmode;
70291 + } else
70292 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
70293 + {
70294 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
70295 + reqmode & GR_READ ? " reading" : "",
70296 + reqmode & GR_WRITE ? " writing" : reqmode &
70297 + GR_APPEND ? " appending" : "");
70298 + return 0;
70299 + } else if (unlikely((mode & reqmode) != reqmode))
70300 + return 0;
70301 +
70302 + return reqmode;
70303 +}
70304 +
70305 +__u32
70306 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
70307 + const int fmode)
70308 +{
70309 + __u32 mode, reqmode = GR_FIND;
70310 +
70311 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
70312 + reqmode |= GR_EXEC;
70313 + if (fmode & S_IWOTH)
70314 + reqmode |= GR_WRITE;
70315 + if (fmode & S_IROTH)
70316 + reqmode |= GR_READ;
70317 +
70318 + mode =
70319 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
70320 + mnt);
70321 +
70322 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
70323 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
70324 + reqmode & GR_READ ? " reading" : "",
70325 + reqmode & GR_WRITE ? " writing" : "",
70326 + reqmode & GR_EXEC ? " executing" : "");
70327 + return reqmode;
70328 + } else
70329 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
70330 + {
70331 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
70332 + reqmode & GR_READ ? " reading" : "",
70333 + reqmode & GR_WRITE ? " writing" : "",
70334 + reqmode & GR_EXEC ? " executing" : "");
70335 + return 0;
70336 + } else if (unlikely((mode & reqmode) != reqmode))
70337 + return 0;
70338 +
70339 + return reqmode;
70340 +}
70341 +
70342 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
70343 +{
70344 + __u32 mode;
70345 +
70346 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
70347 +
70348 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
70349 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
70350 + return mode;
70351 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
70352 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
70353 + return 0;
70354 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
70355 + return 0;
70356 +
70357 + return (reqmode);
70358 +}
70359 +
70360 +__u32
70361 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
70362 +{
70363 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
70364 +}
70365 +
70366 +__u32
70367 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
70368 +{
70369 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
70370 +}
70371 +
70372 +__u32
70373 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
70374 +{
70375 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
70376 +}
70377 +
70378 +__u32
70379 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
70380 +{
70381 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
70382 +}
70383 +
70384 +__u32
70385 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
70386 + umode_t *modeptr)
70387 +{
70388 + umode_t mode;
70389 +
70390 + *modeptr &= ~gr_acl_umask();
70391 + mode = *modeptr;
70392 +
70393 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
70394 + return 1;
70395 +
70396 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
70397 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
70398 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
70399 + GR_CHMOD_ACL_MSG);
70400 + } else {
70401 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
70402 + }
70403 +}
70404 +
70405 +__u32
70406 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
70407 +{
70408 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
70409 +}
70410 +
70411 +__u32
70412 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
70413 +{
70414 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
70415 +}
70416 +
70417 +__u32
70418 +gr_acl_handle_removexattr(const struct dentry *dentry, const struct vfsmount *mnt)
70419 +{
70420 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_REMOVEXATTR_ACL_MSG);
70421 +}
70422 +
70423 +__u32
70424 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
70425 +{
70426 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
70427 +}
70428 +
70429 +__u32
70430 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
70431 +{
70432 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
70433 + GR_UNIXCONNECT_ACL_MSG);
70434 +}
70435 +
70436 +/* hardlinks require at minimum create and link permission,
70437 + any additional privilege required is based on the
70438 + privilege of the file being linked to
70439 +*/
70440 +__u32
70441 +gr_acl_handle_link(const struct dentry * new_dentry,
70442 + const struct dentry * parent_dentry,
70443 + const struct vfsmount * parent_mnt,
70444 + const struct dentry * old_dentry,
70445 + const struct vfsmount * old_mnt, const struct filename *to)
70446 +{
70447 + __u32 mode;
70448 + __u32 needmode = GR_CREATE | GR_LINK;
70449 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
70450 +
70451 + mode =
70452 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
70453 + old_mnt);
70454 +
70455 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
70456 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
70457 + return mode;
70458 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
70459 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
70460 + return 0;
70461 + } else if (unlikely((mode & needmode) != needmode))
70462 + return 0;
70463 +
70464 + return 1;
70465 +}
70466 +
70467 +__u32
70468 +gr_acl_handle_symlink(const struct dentry * new_dentry,
70469 + const struct dentry * parent_dentry,
70470 + const struct vfsmount * parent_mnt, const struct filename *from)
70471 +{
70472 + __u32 needmode = GR_WRITE | GR_CREATE;
70473 + __u32 mode;
70474 +
70475 + mode =
70476 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
70477 + GR_CREATE | GR_AUDIT_CREATE |
70478 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
70479 +
70480 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
70481 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
70482 + return mode;
70483 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
70484 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
70485 + return 0;
70486 + } else if (unlikely((mode & needmode) != needmode))
70487 + return 0;
70488 +
70489 + return (GR_WRITE | GR_CREATE);
70490 +}
70491 +
70492 +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)
70493 +{
70494 + __u32 mode;
70495 +
70496 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
70497 +
70498 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
70499 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
70500 + return mode;
70501 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
70502 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
70503 + return 0;
70504 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
70505 + return 0;
70506 +
70507 + return (reqmode);
70508 +}
70509 +
70510 +__u32
70511 +gr_acl_handle_mknod(const struct dentry * new_dentry,
70512 + const struct dentry * parent_dentry,
70513 + const struct vfsmount * parent_mnt,
70514 + const int mode)
70515 +{
70516 + __u32 reqmode = GR_WRITE | GR_CREATE;
70517 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
70518 + reqmode |= GR_SETID;
70519 +
70520 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
70521 + reqmode, GR_MKNOD_ACL_MSG);
70522 +}
70523 +
70524 +__u32
70525 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
70526 + const struct dentry *parent_dentry,
70527 + const struct vfsmount *parent_mnt)
70528 +{
70529 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
70530 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
70531 +}
70532 +
70533 +#define RENAME_CHECK_SUCCESS(old, new) \
70534 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
70535 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
70536 +
70537 +int
70538 +gr_acl_handle_rename(struct dentry *new_dentry,
70539 + struct dentry *parent_dentry,
70540 + const struct vfsmount *parent_mnt,
70541 + struct dentry *old_dentry,
70542 + struct inode *old_parent_inode,
70543 + struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags)
70544 +{
70545 + __u32 comp1, comp2;
70546 + int error = 0;
70547 +
70548 + if (unlikely(!gr_acl_is_enabled()))
70549 + return 0;
70550 +
70551 + if (flags & RENAME_EXCHANGE) {
70552 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
70553 + GR_AUDIT_READ | GR_AUDIT_WRITE |
70554 + GR_SUPPRESS, parent_mnt);
70555 + comp2 =
70556 + gr_search_file(old_dentry,
70557 + GR_READ | GR_WRITE | GR_AUDIT_READ |
70558 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
70559 + } else if (d_is_negative(new_dentry)) {
70560 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
70561 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
70562 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
70563 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
70564 + GR_DELETE | GR_AUDIT_DELETE |
70565 + GR_AUDIT_READ | GR_AUDIT_WRITE |
70566 + GR_SUPPRESS, old_mnt);
70567 + } else {
70568 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
70569 + GR_CREATE | GR_DELETE |
70570 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
70571 + GR_AUDIT_READ | GR_AUDIT_WRITE |
70572 + GR_SUPPRESS, parent_mnt);
70573 + comp2 =
70574 + gr_search_file(old_dentry,
70575 + GR_READ | GR_WRITE | GR_AUDIT_READ |
70576 + GR_DELETE | GR_AUDIT_DELETE |
70577 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
70578 + }
70579 +
70580 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
70581 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
70582 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
70583 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
70584 + && !(comp2 & GR_SUPPRESS)) {
70585 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
70586 + error = -EACCES;
70587 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
70588 + error = -EACCES;
70589 +
70590 + return error;
70591 +}
70592 +
70593 +void
70594 +gr_acl_handle_exit(void)
70595 +{
70596 + u16 id;
70597 + char *rolename;
70598 +
70599 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
70600 + !(current->role->roletype & GR_ROLE_PERSIST))) {
70601 + id = current->acl_role_id;
70602 + rolename = current->role->rolename;
70603 + gr_set_acls(1);
70604 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
70605 + }
70606 +
70607 + gr_put_exec_file(current);
70608 + return;
70609 +}
70610 +
70611 +int
70612 +gr_acl_handle_procpidmem(const struct task_struct *task)
70613 +{
70614 + if (unlikely(!gr_acl_is_enabled()))
70615 + return 0;
70616 +
70617 + if (task != current && task->acl->mode & GR_PROTPROCFD)
70618 + return -EACCES;
70619 +
70620 + return 0;
70621 +}
70622 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
70623 new file mode 100644
70624 index 0000000..f056b81
70625 --- /dev/null
70626 +++ b/grsecurity/gracl_ip.c
70627 @@ -0,0 +1,386 @@
70628 +#include <linux/kernel.h>
70629 +#include <asm/uaccess.h>
70630 +#include <asm/errno.h>
70631 +#include <net/sock.h>
70632 +#include <linux/file.h>
70633 +#include <linux/fs.h>
70634 +#include <linux/net.h>
70635 +#include <linux/in.h>
70636 +#include <linux/skbuff.h>
70637 +#include <linux/ip.h>
70638 +#include <linux/udp.h>
70639 +#include <linux/types.h>
70640 +#include <linux/sched.h>
70641 +#include <linux/netdevice.h>
70642 +#include <linux/inetdevice.h>
70643 +#include <linux/gracl.h>
70644 +#include <linux/grsecurity.h>
70645 +#include <linux/grinternal.h>
70646 +
70647 +#define GR_BIND 0x01
70648 +#define GR_CONNECT 0x02
70649 +#define GR_INVERT 0x04
70650 +#define GR_BINDOVERRIDE 0x08
70651 +#define GR_CONNECTOVERRIDE 0x10
70652 +#define GR_SOCK_FAMILY 0x20
70653 +
70654 +static const char * gr_protocols[IPPROTO_MAX] = {
70655 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
70656 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
70657 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
70658 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
70659 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
70660 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
70661 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
70662 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
70663 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
70664 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
70665 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
70666 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
70667 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
70668 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
70669 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
70670 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
70671 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
70672 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
70673 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
70674 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
70675 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
70676 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
70677 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
70678 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
70679 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
70680 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
70681 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
70682 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
70683 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
70684 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
70685 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
70686 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
70687 + };
70688 +
70689 +static const char * gr_socktypes[SOCK_MAX] = {
70690 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
70691 + "unknown:7", "unknown:8", "unknown:9", "packet"
70692 + };
70693 +
70694 +static const char * gr_sockfamilies[AF_MAX+1] = {
70695 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
70696 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
70697 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
70698 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
70699 + };
70700 +
70701 +const char *
70702 +gr_proto_to_name(unsigned char proto)
70703 +{
70704 + return gr_protocols[proto];
70705 +}
70706 +
70707 +const char *
70708 +gr_socktype_to_name(unsigned char type)
70709 +{
70710 + return gr_socktypes[type];
70711 +}
70712 +
70713 +const char *
70714 +gr_sockfamily_to_name(unsigned char family)
70715 +{
70716 + return gr_sockfamilies[family];
70717 +}
70718 +
70719 +extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
70720 +
70721 +int
70722 +gr_search_socket(const int domain, const int type, const int protocol)
70723 +{
70724 + struct acl_subject_label *curr;
70725 + const struct cred *cred = current_cred();
70726 +
70727 + if (unlikely(!gr_acl_is_enabled()))
70728 + goto exit;
70729 +
70730 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
70731 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
70732 + goto exit; // let the kernel handle it
70733 +
70734 + curr = current->acl;
70735 +
70736 + if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
70737 + /* the family is allowed, if this is PF_INET allow it only if
70738 + the extra sock type/protocol checks pass */
70739 + if (domain == PF_INET)
70740 + goto inet_check;
70741 + goto exit;
70742 + } else {
70743 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70744 + __u32 fakeip = 0;
70745 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70746 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
70747 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
70748 + gr_to_filename(current->exec_file->f_path.dentry,
70749 + current->exec_file->f_path.mnt) :
70750 + curr->filename, curr->filename,
70751 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
70752 + &current->signal->saved_ip);
70753 + goto exit;
70754 + }
70755 + goto exit_fail;
70756 + }
70757 +
70758 +inet_check:
70759 + /* the rest of this checking is for IPv4 only */
70760 + if (!curr->ips)
70761 + goto exit;
70762 +
70763 + if ((curr->ip_type & (1U << type)) &&
70764 + (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
70765 + goto exit;
70766 +
70767 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70768 + /* we don't place acls on raw sockets , and sometimes
70769 + dgram/ip sockets are opened for ioctl and not
70770 + bind/connect, so we'll fake a bind learn log */
70771 + if (type == SOCK_RAW || type == SOCK_PACKET) {
70772 + __u32 fakeip = 0;
70773 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70774 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
70775 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
70776 + gr_to_filename(current->exec_file->f_path.dentry,
70777 + current->exec_file->f_path.mnt) :
70778 + curr->filename, curr->filename,
70779 + &fakeip, 0, type,
70780 + protocol, GR_CONNECT, &current->signal->saved_ip);
70781 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
70782 + __u32 fakeip = 0;
70783 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70784 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
70785 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
70786 + gr_to_filename(current->exec_file->f_path.dentry,
70787 + current->exec_file->f_path.mnt) :
70788 + curr->filename, curr->filename,
70789 + &fakeip, 0, type,
70790 + protocol, GR_BIND, &current->signal->saved_ip);
70791 + }
70792 + /* we'll log when they use connect or bind */
70793 + goto exit;
70794 + }
70795 +
70796 +exit_fail:
70797 + if (domain == PF_INET)
70798 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
70799 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
70800 + else if (rcu_access_pointer(net_families[domain]) != NULL)
70801 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
70802 + gr_socktype_to_name(type), protocol);
70803 +
70804 + return 0;
70805 +exit:
70806 + return 1;
70807 +}
70808 +
70809 +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)
70810 +{
70811 + if ((ip->mode & mode) &&
70812 + (ip_port >= ip->low) &&
70813 + (ip_port <= ip->high) &&
70814 + ((ntohl(ip_addr) & our_netmask) ==
70815 + (ntohl(our_addr) & our_netmask))
70816 + && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
70817 + && (ip->type & (1U << type))) {
70818 + if (ip->mode & GR_INVERT)
70819 + return 2; // specifically denied
70820 + else
70821 + return 1; // allowed
70822 + }
70823 +
70824 + return 0; // not specifically allowed, may continue parsing
70825 +}
70826 +
70827 +static int
70828 +gr_search_connectbind(const int full_mode, struct sock *sk,
70829 + struct sockaddr_in *addr, const int type)
70830 +{
70831 + char iface[IFNAMSIZ] = {0};
70832 + struct acl_subject_label *curr;
70833 + struct acl_ip_label *ip;
70834 + struct inet_sock *isk;
70835 + struct net_device *dev;
70836 + struct in_device *idev;
70837 + unsigned long i;
70838 + int ret;
70839 + int mode = full_mode & (GR_BIND | GR_CONNECT);
70840 + __u32 ip_addr = 0;
70841 + __u32 our_addr;
70842 + __u32 our_netmask;
70843 + char *p;
70844 + __u16 ip_port = 0;
70845 + const struct cred *cred = current_cred();
70846 +
70847 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
70848 + return 0;
70849 +
70850 + curr = current->acl;
70851 + isk = inet_sk(sk);
70852 +
70853 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
70854 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
70855 + addr->sin_addr.s_addr = curr->inaddr_any_override;
70856 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
70857 + struct sockaddr_in saddr;
70858 + int err;
70859 +
70860 + saddr.sin_family = AF_INET;
70861 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
70862 + saddr.sin_port = isk->inet_sport;
70863 +
70864 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
70865 + if (err)
70866 + return err;
70867 +
70868 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
70869 + if (err)
70870 + return err;
70871 + }
70872 +
70873 + if (!curr->ips)
70874 + return 0;
70875 +
70876 + ip_addr = addr->sin_addr.s_addr;
70877 + ip_port = ntohs(addr->sin_port);
70878 +
70879 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
70880 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
70881 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
70882 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
70883 + gr_to_filename(current->exec_file->f_path.dentry,
70884 + current->exec_file->f_path.mnt) :
70885 + curr->filename, curr->filename,
70886 + &ip_addr, ip_port, type,
70887 + sk->sk_protocol, mode, &current->signal->saved_ip);
70888 + return 0;
70889 + }
70890 +
70891 + for (i = 0; i < curr->ip_num; i++) {
70892 + ip = *(curr->ips + i);
70893 + if (ip->iface != NULL) {
70894 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
70895 + p = strchr(iface, ':');
70896 + if (p != NULL)
70897 + *p = '\0';
70898 + dev = dev_get_by_name(sock_net(sk), iface);
70899 + if (dev == NULL)
70900 + continue;
70901 + idev = in_dev_get(dev);
70902 + if (idev == NULL) {
70903 + dev_put(dev);
70904 + continue;
70905 + }
70906 + rcu_read_lock();
70907 + for_ifa(idev) {
70908 + if (!strcmp(ip->iface, ifa->ifa_label)) {
70909 + our_addr = ifa->ifa_address;
70910 + our_netmask = 0xffffffff;
70911 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
70912 + if (ret == 1) {
70913 + rcu_read_unlock();
70914 + in_dev_put(idev);
70915 + dev_put(dev);
70916 + return 0;
70917 + } else if (ret == 2) {
70918 + rcu_read_unlock();
70919 + in_dev_put(idev);
70920 + dev_put(dev);
70921 + goto denied;
70922 + }
70923 + }
70924 + } endfor_ifa(idev);
70925 + rcu_read_unlock();
70926 + in_dev_put(idev);
70927 + dev_put(dev);
70928 + } else {
70929 + our_addr = ip->addr;
70930 + our_netmask = ip->netmask;
70931 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
70932 + if (ret == 1)
70933 + return 0;
70934 + else if (ret == 2)
70935 + goto denied;
70936 + }
70937 + }
70938 +
70939 +denied:
70940 + if (mode == GR_BIND)
70941 + 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));
70942 + else if (mode == GR_CONNECT)
70943 + 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));
70944 +
70945 + return -EACCES;
70946 +}
70947 +
70948 +int
70949 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
70950 +{
70951 + /* always allow disconnection of dgram sockets with connect */
70952 + if (addr->sin_family == AF_UNSPEC)
70953 + return 0;
70954 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
70955 +}
70956 +
70957 +int
70958 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
70959 +{
70960 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
70961 +}
70962 +
70963 +int gr_search_listen(struct socket *sock)
70964 +{
70965 + struct sock *sk = sock->sk;
70966 + struct sockaddr_in addr;
70967 +
70968 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
70969 + addr.sin_port = inet_sk(sk)->inet_sport;
70970 +
70971 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
70972 +}
70973 +
70974 +int gr_search_accept(struct socket *sock)
70975 +{
70976 + struct sock *sk = sock->sk;
70977 + struct sockaddr_in addr;
70978 +
70979 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
70980 + addr.sin_port = inet_sk(sk)->inet_sport;
70981 +
70982 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
70983 +}
70984 +
70985 +int
70986 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
70987 +{
70988 + if (addr)
70989 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
70990 + else {
70991 + struct sockaddr_in sin;
70992 + const struct inet_sock *inet = inet_sk(sk);
70993 +
70994 + sin.sin_addr.s_addr = inet->inet_daddr;
70995 + sin.sin_port = inet->inet_dport;
70996 +
70997 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
70998 + }
70999 +}
71000 +
71001 +int
71002 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
71003 +{
71004 + struct sockaddr_in sin;
71005 +
71006 + if (unlikely(skb->len < sizeof (struct udphdr)))
71007 + return 0; // skip this packet
71008 +
71009 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
71010 + sin.sin_port = udp_hdr(skb)->source;
71011 +
71012 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
71013 +}
71014 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
71015 new file mode 100644
71016 index 0000000..25f54ef
71017 --- /dev/null
71018 +++ b/grsecurity/gracl_learn.c
71019 @@ -0,0 +1,207 @@
71020 +#include <linux/kernel.h>
71021 +#include <linux/mm.h>
71022 +#include <linux/sched.h>
71023 +#include <linux/poll.h>
71024 +#include <linux/string.h>
71025 +#include <linux/file.h>
71026 +#include <linux/types.h>
71027 +#include <linux/vmalloc.h>
71028 +#include <linux/grinternal.h>
71029 +
71030 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
71031 + size_t count, loff_t *ppos);
71032 +extern int gr_acl_is_enabled(void);
71033 +
71034 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
71035 +static int gr_learn_attached;
71036 +
71037 +/* use a 512k buffer */
71038 +#define LEARN_BUFFER_SIZE (512 * 1024)
71039 +
71040 +static DEFINE_SPINLOCK(gr_learn_lock);
71041 +static DEFINE_MUTEX(gr_learn_user_mutex);
71042 +
71043 +/* we need to maintain two buffers, so that the kernel context of grlearn
71044 + uses a semaphore around the userspace copying, and the other kernel contexts
71045 + use a spinlock when copying into the buffer, since they cannot sleep
71046 +*/
71047 +static char *learn_buffer;
71048 +static char *learn_buffer_user;
71049 +static int learn_buffer_len;
71050 +static int learn_buffer_user_len;
71051 +
71052 +static ssize_t
71053 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
71054 +{
71055 + DECLARE_WAITQUEUE(wait, current);
71056 + ssize_t retval = 0;
71057 +
71058 + add_wait_queue(&learn_wait, &wait);
71059 + set_current_state(TASK_INTERRUPTIBLE);
71060 + do {
71061 + mutex_lock(&gr_learn_user_mutex);
71062 + spin_lock(&gr_learn_lock);
71063 + if (learn_buffer_len)
71064 + break;
71065 + spin_unlock(&gr_learn_lock);
71066 + mutex_unlock(&gr_learn_user_mutex);
71067 + if (file->f_flags & O_NONBLOCK) {
71068 + retval = -EAGAIN;
71069 + goto out;
71070 + }
71071 + if (signal_pending(current)) {
71072 + retval = -ERESTARTSYS;
71073 + goto out;
71074 + }
71075 +
71076 + schedule();
71077 + } while (1);
71078 +
71079 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
71080 + learn_buffer_user_len = learn_buffer_len;
71081 + retval = learn_buffer_len;
71082 + learn_buffer_len = 0;
71083 +
71084 + spin_unlock(&gr_learn_lock);
71085 +
71086 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
71087 + retval = -EFAULT;
71088 +
71089 + mutex_unlock(&gr_learn_user_mutex);
71090 +out:
71091 + set_current_state(TASK_RUNNING);
71092 + remove_wait_queue(&learn_wait, &wait);
71093 + return retval;
71094 +}
71095 +
71096 +static unsigned int
71097 +poll_learn(struct file * file, poll_table * wait)
71098 +{
71099 + poll_wait(file, &learn_wait, wait);
71100 +
71101 + if (learn_buffer_len)
71102 + return (POLLIN | POLLRDNORM);
71103 +
71104 + return 0;
71105 +}
71106 +
71107 +void
71108 +gr_clear_learn_entries(void)
71109 +{
71110 + char *tmp;
71111 +
71112 + mutex_lock(&gr_learn_user_mutex);
71113 + spin_lock(&gr_learn_lock);
71114 + tmp = learn_buffer;
71115 + learn_buffer = NULL;
71116 + spin_unlock(&gr_learn_lock);
71117 + if (tmp)
71118 + vfree(tmp);
71119 + if (learn_buffer_user != NULL) {
71120 + vfree(learn_buffer_user);
71121 + learn_buffer_user = NULL;
71122 + }
71123 + learn_buffer_len = 0;
71124 + mutex_unlock(&gr_learn_user_mutex);
71125 +
71126 + return;
71127 +}
71128 +
71129 +void
71130 +gr_add_learn_entry(const char *fmt, ...)
71131 +{
71132 + va_list args;
71133 + unsigned int len;
71134 +
71135 + if (!gr_learn_attached)
71136 + return;
71137 +
71138 + spin_lock(&gr_learn_lock);
71139 +
71140 + /* leave a gap at the end so we know when it's "full" but don't have to
71141 + compute the exact length of the string we're trying to append
71142 + */
71143 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
71144 + spin_unlock(&gr_learn_lock);
71145 + wake_up_interruptible(&learn_wait);
71146 + return;
71147 + }
71148 + if (learn_buffer == NULL) {
71149 + spin_unlock(&gr_learn_lock);
71150 + return;
71151 + }
71152 +
71153 + va_start(args, fmt);
71154 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
71155 + va_end(args);
71156 +
71157 + learn_buffer_len += len + 1;
71158 +
71159 + spin_unlock(&gr_learn_lock);
71160 + wake_up_interruptible(&learn_wait);
71161 +
71162 + return;
71163 +}
71164 +
71165 +static int
71166 +open_learn(struct inode *inode, struct file *file)
71167 +{
71168 + if (file->f_mode & FMODE_READ && gr_learn_attached)
71169 + return -EBUSY;
71170 + if (file->f_mode & FMODE_READ) {
71171 + int retval = 0;
71172 + mutex_lock(&gr_learn_user_mutex);
71173 + if (learn_buffer == NULL)
71174 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
71175 + if (learn_buffer_user == NULL)
71176 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
71177 + if (learn_buffer == NULL) {
71178 + retval = -ENOMEM;
71179 + goto out_error;
71180 + }
71181 + if (learn_buffer_user == NULL) {
71182 + retval = -ENOMEM;
71183 + goto out_error;
71184 + }
71185 + learn_buffer_len = 0;
71186 + learn_buffer_user_len = 0;
71187 + gr_learn_attached = 1;
71188 +out_error:
71189 + mutex_unlock(&gr_learn_user_mutex);
71190 + return retval;
71191 + }
71192 + return 0;
71193 +}
71194 +
71195 +static int
71196 +close_learn(struct inode *inode, struct file *file)
71197 +{
71198 + if (file->f_mode & FMODE_READ) {
71199 + char *tmp = NULL;
71200 + mutex_lock(&gr_learn_user_mutex);
71201 + spin_lock(&gr_learn_lock);
71202 + tmp = learn_buffer;
71203 + learn_buffer = NULL;
71204 + spin_unlock(&gr_learn_lock);
71205 + if (tmp)
71206 + vfree(tmp);
71207 + if (learn_buffer_user != NULL) {
71208 + vfree(learn_buffer_user);
71209 + learn_buffer_user = NULL;
71210 + }
71211 + learn_buffer_len = 0;
71212 + learn_buffer_user_len = 0;
71213 + gr_learn_attached = 0;
71214 + mutex_unlock(&gr_learn_user_mutex);
71215 + }
71216 +
71217 + return 0;
71218 +}
71219 +
71220 +const struct file_operations grsec_fops = {
71221 + .read = read_learn,
71222 + .write = write_grsec_handler,
71223 + .open = open_learn,
71224 + .release = close_learn,
71225 + .poll = poll_learn,
71226 +};
71227 diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
71228 new file mode 100644
71229 index 0000000..361a099
71230 --- /dev/null
71231 +++ b/grsecurity/gracl_policy.c
71232 @@ -0,0 +1,1782 @@
71233 +#include <linux/kernel.h>
71234 +#include <linux/module.h>
71235 +#include <linux/sched.h>
71236 +#include <linux/mm.h>
71237 +#include <linux/file.h>
71238 +#include <linux/fs.h>
71239 +#include <linux/namei.h>
71240 +#include <linux/mount.h>
71241 +#include <linux/tty.h>
71242 +#include <linux/proc_fs.h>
71243 +#include <linux/lglock.h>
71244 +#include <linux/slab.h>
71245 +#include <linux/vmalloc.h>
71246 +#include <linux/types.h>
71247 +#include <linux/sysctl.h>
71248 +#include <linux/netdevice.h>
71249 +#include <linux/ptrace.h>
71250 +#include <linux/gracl.h>
71251 +#include <linux/gralloc.h>
71252 +#include <linux/security.h>
71253 +#include <linux/grinternal.h>
71254 +#include <linux/pid_namespace.h>
71255 +#include <linux/stop_machine.h>
71256 +#include <linux/fdtable.h>
71257 +#include <linux/percpu.h>
71258 +#include <linux/lglock.h>
71259 +#include <linux/hugetlb.h>
71260 +#include <linux/posix-timers.h>
71261 +#include "../fs/mount.h"
71262 +
71263 +#include <asm/uaccess.h>
71264 +#include <asm/errno.h>
71265 +#include <asm/mman.h>
71266 +
71267 +extern struct gr_policy_state *polstate;
71268 +
71269 +#define FOR_EACH_ROLE_START(role) \
71270 + role = polstate->role_list; \
71271 + while (role) {
71272 +
71273 +#define FOR_EACH_ROLE_END(role) \
71274 + role = role->prev; \
71275 + }
71276 +
71277 +struct path gr_real_root;
71278 +
71279 +extern struct gr_alloc_state *current_alloc_state;
71280 +
71281 +u16 acl_sp_role_value;
71282 +
71283 +static DEFINE_MUTEX(gr_dev_mutex);
71284 +
71285 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
71286 +extern void gr_clear_learn_entries(void);
71287 +
71288 +static struct gr_arg gr_usermode;
71289 +static unsigned char gr_system_salt[GR_SALT_LEN];
71290 +static unsigned char gr_system_sum[GR_SHA_LEN];
71291 +
71292 +static unsigned int gr_auth_attempts = 0;
71293 +static unsigned long gr_auth_expires = 0UL;
71294 +
71295 +struct acl_object_label *fakefs_obj_rw;
71296 +struct acl_object_label *fakefs_obj_rwx;
71297 +
71298 +extern int gr_init_uidset(void);
71299 +extern void gr_free_uidset(void);
71300 +extern void gr_remove_uid(uid_t uid);
71301 +extern int gr_find_uid(uid_t uid);
71302 +
71303 +extern struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename);
71304 +extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
71305 +extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
71306 +extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
71307 +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);
71308 +extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
71309 +extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
71310 +extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
71311 +extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
71312 +extern struct acl_subject_label *lookup_acl_subj_label(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
71313 +extern struct acl_subject_label *lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
71314 +extern void assign_special_role(const char *rolename);
71315 +extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
71316 +extern int gr_rbac_disable(void *unused);
71317 +extern void gr_enable_rbac_system(void);
71318 +
71319 +static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
71320 +{
71321 + if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
71322 + return -EFAULT;
71323 +
71324 + return 0;
71325 +}
71326 +
71327 +static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
71328 +{
71329 + if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
71330 + return -EFAULT;
71331 +
71332 + return 0;
71333 +}
71334 +
71335 +static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
71336 +{
71337 + if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
71338 + return -EFAULT;
71339 +
71340 + return 0;
71341 +}
71342 +
71343 +static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
71344 +{
71345 + if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
71346 + return -EFAULT;
71347 +
71348 + return 0;
71349 +}
71350 +
71351 +static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
71352 +{
71353 + if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
71354 + return -EFAULT;
71355 +
71356 + return 0;
71357 +}
71358 +
71359 +static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
71360 +{
71361 + if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
71362 + return -EFAULT;
71363 +
71364 + return 0;
71365 +}
71366 +
71367 +static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
71368 +{
71369 + if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
71370 + return -EFAULT;
71371 +
71372 + return 0;
71373 +}
71374 +
71375 +static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
71376 +{
71377 + if (copy_from_user(trans, userp, sizeof(struct role_transition)))
71378 + return -EFAULT;
71379 +
71380 + return 0;
71381 +}
71382 +
71383 +int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
71384 +{
71385 + if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
71386 + return -EFAULT;
71387 +
71388 + return 0;
71389 +}
71390 +
71391 +static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
71392 +{
71393 + if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
71394 + return -EFAULT;
71395 +
71396 + if (((uwrap->version != GRSECURITY_VERSION) &&
71397 + (uwrap->version != 0x2901)) ||
71398 + (uwrap->size != sizeof(struct gr_arg)))
71399 + return -EINVAL;
71400 +
71401 + return 0;
71402 +}
71403 +
71404 +static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
71405 +{
71406 + if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
71407 + return -EFAULT;
71408 +
71409 + return 0;
71410 +}
71411 +
71412 +static size_t get_gr_arg_wrapper_size_normal(void)
71413 +{
71414 + return sizeof(struct gr_arg_wrapper);
71415 +}
71416 +
71417 +#ifdef CONFIG_COMPAT
71418 +extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
71419 +extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
71420 +extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
71421 +extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
71422 +extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
71423 +extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
71424 +extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
71425 +extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
71426 +extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
71427 +extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
71428 +extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
71429 +extern size_t get_gr_arg_wrapper_size_compat(void);
71430 +
71431 +int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
71432 +int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
71433 +int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
71434 +int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
71435 +int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
71436 +int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
71437 +int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
71438 +int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
71439 +int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
71440 +int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
71441 +int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
71442 +size_t (* get_gr_arg_wrapper_size)(void) __read_only;
71443 +
71444 +#else
71445 +#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
71446 +#define copy_gr_arg copy_gr_arg_normal
71447 +#define copy_gr_hash_struct copy_gr_hash_struct_normal
71448 +#define copy_acl_object_label copy_acl_object_label_normal
71449 +#define copy_acl_subject_label copy_acl_subject_label_normal
71450 +#define copy_acl_role_label copy_acl_role_label_normal
71451 +#define copy_acl_ip_label copy_acl_ip_label_normal
71452 +#define copy_pointer_from_array copy_pointer_from_array_normal
71453 +#define copy_sprole_pw copy_sprole_pw_normal
71454 +#define copy_role_transition copy_role_transition_normal
71455 +#define copy_role_allowed_ip copy_role_allowed_ip_normal
71456 +#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
71457 +#endif
71458 +
71459 +static struct acl_subject_label *
71460 +lookup_subject_map(const struct acl_subject_label *userp)
71461 +{
71462 + unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
71463 + struct subject_map *match;
71464 +
71465 + match = polstate->subj_map_set.s_hash[index];
71466 +
71467 + while (match && match->user != userp)
71468 + match = match->next;
71469 +
71470 + if (match != NULL)
71471 + return match->kernel;
71472 + else
71473 + return NULL;
71474 +}
71475 +
71476 +static void
71477 +insert_subj_map_entry(struct subject_map *subjmap)
71478 +{
71479 + unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
71480 + struct subject_map **curr;
71481 +
71482 + subjmap->prev = NULL;
71483 +
71484 + curr = &polstate->subj_map_set.s_hash[index];
71485 + if (*curr != NULL)
71486 + (*curr)->prev = subjmap;
71487 +
71488 + subjmap->next = *curr;
71489 + *curr = subjmap;
71490 +
71491 + return;
71492 +}
71493 +
71494 +static void
71495 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
71496 +{
71497 + unsigned int index =
71498 + gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
71499 + struct acl_role_label **curr;
71500 + struct acl_role_label *tmp, *tmp2;
71501 +
71502 + curr = &polstate->acl_role_set.r_hash[index];
71503 +
71504 + /* simple case, slot is empty, just set it to our role */
71505 + if (*curr == NULL) {
71506 + *curr = role;
71507 + } else {
71508 + /* example:
71509 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
71510 + 2 -> 3
71511 + */
71512 + /* first check to see if we can already be reached via this slot */
71513 + tmp = *curr;
71514 + while (tmp && tmp != role)
71515 + tmp = tmp->next;
71516 + if (tmp == role) {
71517 + /* we don't need to add ourselves to this slot's chain */
71518 + return;
71519 + }
71520 + /* we need to add ourselves to this chain, two cases */
71521 + if (role->next == NULL) {
71522 + /* simple case, append the current chain to our role */
71523 + role->next = *curr;
71524 + *curr = role;
71525 + } else {
71526 + /* 1 -> 2 -> 3 -> 4
71527 + 2 -> 3 -> 4
71528 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
71529 + */
71530 + /* trickier case: walk our role's chain until we find
71531 + the role for the start of the current slot's chain */
71532 + tmp = role;
71533 + tmp2 = *curr;
71534 + while (tmp->next && tmp->next != tmp2)
71535 + tmp = tmp->next;
71536 + if (tmp->next == tmp2) {
71537 + /* from example above, we found 3, so just
71538 + replace this slot's chain with ours */
71539 + *curr = role;
71540 + } else {
71541 + /* we didn't find a subset of our role's chain
71542 + in the current slot's chain, so append their
71543 + chain to ours, and set us as the first role in
71544 + the slot's chain
71545 +
71546 + we could fold this case with the case above,
71547 + but making it explicit for clarity
71548 + */
71549 + tmp->next = tmp2;
71550 + *curr = role;
71551 + }
71552 + }
71553 + }
71554 +
71555 + return;
71556 +}
71557 +
71558 +static void
71559 +insert_acl_role_label(struct acl_role_label *role)
71560 +{
71561 + int i;
71562 +
71563 + if (polstate->role_list == NULL) {
71564 + polstate->role_list = role;
71565 + role->prev = NULL;
71566 + } else {
71567 + role->prev = polstate->role_list;
71568 + polstate->role_list = role;
71569 + }
71570 +
71571 + /* used for hash chains */
71572 + role->next = NULL;
71573 +
71574 + if (role->roletype & GR_ROLE_DOMAIN) {
71575 + for (i = 0; i < role->domain_child_num; i++)
71576 + __insert_acl_role_label(role, role->domain_children[i]);
71577 + } else
71578 + __insert_acl_role_label(role, role->uidgid);
71579 +}
71580 +
71581 +static int
71582 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
71583 +{
71584 + struct name_entry **curr, *nentry;
71585 + struct inodev_entry *ientry;
71586 + unsigned int len = strlen(name);
71587 + unsigned int key = full_name_hash(name, len);
71588 + unsigned int index = key % polstate->name_set.n_size;
71589 +
71590 + curr = &polstate->name_set.n_hash[index];
71591 +
71592 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
71593 + curr = &((*curr)->next);
71594 +
71595 + if (*curr != NULL)
71596 + return 1;
71597 +
71598 + nentry = acl_alloc(sizeof (struct name_entry));
71599 + if (nentry == NULL)
71600 + return 0;
71601 + ientry = acl_alloc(sizeof (struct inodev_entry));
71602 + if (ientry == NULL)
71603 + return 0;
71604 + ientry->nentry = nentry;
71605 +
71606 + nentry->key = key;
71607 + nentry->name = name;
71608 + nentry->inode = inode;
71609 + nentry->device = device;
71610 + nentry->len = len;
71611 + nentry->deleted = deleted;
71612 +
71613 + nentry->prev = NULL;
71614 + curr = &polstate->name_set.n_hash[index];
71615 + if (*curr != NULL)
71616 + (*curr)->prev = nentry;
71617 + nentry->next = *curr;
71618 + *curr = nentry;
71619 +
71620 + /* insert us into the table searchable by inode/dev */
71621 + __insert_inodev_entry(polstate, ientry);
71622 +
71623 + return 1;
71624 +}
71625 +
71626 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
71627 +
71628 +static void *
71629 +create_table(__u32 * len, int elementsize)
71630 +{
71631 + unsigned int table_sizes[] = {
71632 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
71633 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
71634 + 4194301, 8388593, 16777213, 33554393, 67108859
71635 + };
71636 + void *newtable = NULL;
71637 + unsigned int pwr = 0;
71638 +
71639 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
71640 + table_sizes[pwr] <= *len)
71641 + pwr++;
71642 +
71643 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
71644 + return newtable;
71645 +
71646 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
71647 + newtable =
71648 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
71649 + else
71650 + newtable = vmalloc(table_sizes[pwr] * elementsize);
71651 +
71652 + *len = table_sizes[pwr];
71653 +
71654 + return newtable;
71655 +}
71656 +
71657 +static int
71658 +init_variables(const struct gr_arg *arg, bool reload)
71659 +{
71660 + struct task_struct *reaper = init_pid_ns.child_reaper;
71661 + unsigned int stacksize;
71662 +
71663 + polstate->subj_map_set.s_size = arg->role_db.num_subjects;
71664 + polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
71665 + polstate->name_set.n_size = arg->role_db.num_objects;
71666 + polstate->inodev_set.i_size = arg->role_db.num_objects;
71667 +
71668 + if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
71669 + !polstate->name_set.n_size || !polstate->inodev_set.i_size)
71670 + return 1;
71671 +
71672 + if (!reload) {
71673 + if (!gr_init_uidset())
71674 + return 1;
71675 + }
71676 +
71677 + /* set up the stack that holds allocation info */
71678 +
71679 + stacksize = arg->role_db.num_pointers + 5;
71680 +
71681 + if (!acl_alloc_stack_init(stacksize))
71682 + return 1;
71683 +
71684 + if (!reload) {
71685 + /* grab reference for the real root dentry and vfsmount */
71686 + get_fs_root(reaper->fs, &gr_real_root);
71687 +
71688 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
71689 + 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);
71690 +#endif
71691 +
71692 + fakefs_obj_rw = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
71693 + if (fakefs_obj_rw == NULL)
71694 + return 1;
71695 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
71696 +
71697 + fakefs_obj_rwx = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
71698 + if (fakefs_obj_rwx == NULL)
71699 + return 1;
71700 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
71701 + }
71702 +
71703 + polstate->subj_map_set.s_hash =
71704 + (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
71705 + polstate->acl_role_set.r_hash =
71706 + (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
71707 + polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
71708 + polstate->inodev_set.i_hash =
71709 + (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
71710 +
71711 + if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
71712 + !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
71713 + return 1;
71714 +
71715 + memset(polstate->subj_map_set.s_hash, 0,
71716 + sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
71717 + memset(polstate->acl_role_set.r_hash, 0,
71718 + sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
71719 + memset(polstate->name_set.n_hash, 0,
71720 + sizeof (struct name_entry *) * polstate->name_set.n_size);
71721 + memset(polstate->inodev_set.i_hash, 0,
71722 + sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
71723 +
71724 + return 0;
71725 +}
71726 +
71727 +/* free information not needed after startup
71728 + currently contains user->kernel pointer mappings for subjects
71729 +*/
71730 +
71731 +static void
71732 +free_init_variables(void)
71733 +{
71734 + __u32 i;
71735 +
71736 + if (polstate->subj_map_set.s_hash) {
71737 + for (i = 0; i < polstate->subj_map_set.s_size; i++) {
71738 + if (polstate->subj_map_set.s_hash[i]) {
71739 + kfree(polstate->subj_map_set.s_hash[i]);
71740 + polstate->subj_map_set.s_hash[i] = NULL;
71741 + }
71742 + }
71743 +
71744 + if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
71745 + PAGE_SIZE)
71746 + kfree(polstate->subj_map_set.s_hash);
71747 + else
71748 + vfree(polstate->subj_map_set.s_hash);
71749 + }
71750 +
71751 + return;
71752 +}
71753 +
71754 +static void
71755 +free_variables(bool reload)
71756 +{
71757 + struct acl_subject_label *s;
71758 + struct acl_role_label *r;
71759 + struct task_struct *task, *task2;
71760 + unsigned int x;
71761 +
71762 + if (!reload) {
71763 + gr_clear_learn_entries();
71764 +
71765 + read_lock(&tasklist_lock);
71766 + do_each_thread(task2, task) {
71767 + task->acl_sp_role = 0;
71768 + task->acl_role_id = 0;
71769 + task->inherited = 0;
71770 + task->acl = NULL;
71771 + task->role = NULL;
71772 + } while_each_thread(task2, task);
71773 + read_unlock(&tasklist_lock);
71774 +
71775 + kfree(fakefs_obj_rw);
71776 + fakefs_obj_rw = NULL;
71777 + kfree(fakefs_obj_rwx);
71778 + fakefs_obj_rwx = NULL;
71779 +
71780 + /* release the reference to the real root dentry and vfsmount */
71781 + path_put(&gr_real_root);
71782 + memset(&gr_real_root, 0, sizeof(gr_real_root));
71783 + }
71784 +
71785 + /* free all object hash tables */
71786 +
71787 + FOR_EACH_ROLE_START(r)
71788 + if (r->subj_hash == NULL)
71789 + goto next_role;
71790 + FOR_EACH_SUBJECT_START(r, s, x)
71791 + if (s->obj_hash == NULL)
71792 + break;
71793 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
71794 + kfree(s->obj_hash);
71795 + else
71796 + vfree(s->obj_hash);
71797 + FOR_EACH_SUBJECT_END(s, x)
71798 + FOR_EACH_NESTED_SUBJECT_START(r, s)
71799 + if (s->obj_hash == NULL)
71800 + break;
71801 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
71802 + kfree(s->obj_hash);
71803 + else
71804 + vfree(s->obj_hash);
71805 + FOR_EACH_NESTED_SUBJECT_END(s)
71806 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
71807 + kfree(r->subj_hash);
71808 + else
71809 + vfree(r->subj_hash);
71810 + r->subj_hash = NULL;
71811 +next_role:
71812 + FOR_EACH_ROLE_END(r)
71813 +
71814 + acl_free_all();
71815 +
71816 + if (polstate->acl_role_set.r_hash) {
71817 + if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
71818 + PAGE_SIZE)
71819 + kfree(polstate->acl_role_set.r_hash);
71820 + else
71821 + vfree(polstate->acl_role_set.r_hash);
71822 + }
71823 + if (polstate->name_set.n_hash) {
71824 + if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
71825 + PAGE_SIZE)
71826 + kfree(polstate->name_set.n_hash);
71827 + else
71828 + vfree(polstate->name_set.n_hash);
71829 + }
71830 +
71831 + if (polstate->inodev_set.i_hash) {
71832 + if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
71833 + PAGE_SIZE)
71834 + kfree(polstate->inodev_set.i_hash);
71835 + else
71836 + vfree(polstate->inodev_set.i_hash);
71837 + }
71838 +
71839 + if (!reload)
71840 + gr_free_uidset();
71841 +
71842 + memset(&polstate->name_set, 0, sizeof (struct name_db));
71843 + memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
71844 + memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
71845 + memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
71846 +
71847 + polstate->default_role = NULL;
71848 + polstate->kernel_role = NULL;
71849 + polstate->role_list = NULL;
71850 +
71851 + return;
71852 +}
71853 +
71854 +static struct acl_subject_label *
71855 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
71856 +
71857 +static int alloc_and_copy_string(char **name, unsigned int maxlen)
71858 +{
71859 + unsigned int len = strnlen_user(*name, maxlen);
71860 + char *tmp;
71861 +
71862 + if (!len || len >= maxlen)
71863 + return -EINVAL;
71864 +
71865 + if ((tmp = (char *) acl_alloc(len)) == NULL)
71866 + return -ENOMEM;
71867 +
71868 + if (copy_from_user(tmp, *name, len))
71869 + return -EFAULT;
71870 +
71871 + tmp[len-1] = '\0';
71872 + *name = tmp;
71873 +
71874 + return 0;
71875 +}
71876 +
71877 +static int
71878 +copy_user_glob(struct acl_object_label *obj)
71879 +{
71880 + struct acl_object_label *g_tmp, **guser;
71881 + int error;
71882 +
71883 + if (obj->globbed == NULL)
71884 + return 0;
71885 +
71886 + guser = &obj->globbed;
71887 + while (*guser) {
71888 + g_tmp = (struct acl_object_label *)
71889 + acl_alloc(sizeof (struct acl_object_label));
71890 + if (g_tmp == NULL)
71891 + return -ENOMEM;
71892 +
71893 + if (copy_acl_object_label(g_tmp, *guser))
71894 + return -EFAULT;
71895 +
71896 + error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
71897 + if (error)
71898 + return error;
71899 +
71900 + *guser = g_tmp;
71901 + guser = &(g_tmp->next);
71902 + }
71903 +
71904 + return 0;
71905 +}
71906 +
71907 +static int
71908 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
71909 + struct acl_role_label *role)
71910 +{
71911 + struct acl_object_label *o_tmp;
71912 + int ret;
71913 +
71914 + while (userp) {
71915 + if ((o_tmp = (struct acl_object_label *)
71916 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
71917 + return -ENOMEM;
71918 +
71919 + if (copy_acl_object_label(o_tmp, userp))
71920 + return -EFAULT;
71921 +
71922 + userp = o_tmp->prev;
71923 +
71924 + ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
71925 + if (ret)
71926 + return ret;
71927 +
71928 + insert_acl_obj_label(o_tmp, subj);
71929 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
71930 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
71931 + return -ENOMEM;
71932 +
71933 + ret = copy_user_glob(o_tmp);
71934 + if (ret)
71935 + return ret;
71936 +
71937 + if (o_tmp->nested) {
71938 + int already_copied;
71939 +
71940 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
71941 + if (IS_ERR(o_tmp->nested))
71942 + return PTR_ERR(o_tmp->nested);
71943 +
71944 + /* insert into nested subject list if we haven't copied this one yet
71945 + to prevent duplicate entries */
71946 + if (!already_copied) {
71947 + o_tmp->nested->next = role->hash->first;
71948 + role->hash->first = o_tmp->nested;
71949 + }
71950 + }
71951 + }
71952 +
71953 + return 0;
71954 +}
71955 +
71956 +static __u32
71957 +count_user_subjs(struct acl_subject_label *userp)
71958 +{
71959 + struct acl_subject_label s_tmp;
71960 + __u32 num = 0;
71961 +
71962 + while (userp) {
71963 + if (copy_acl_subject_label(&s_tmp, userp))
71964 + break;
71965 +
71966 + userp = s_tmp.prev;
71967 + }
71968 +
71969 + return num;
71970 +}
71971 +
71972 +static int
71973 +copy_user_allowedips(struct acl_role_label *rolep)
71974 +{
71975 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
71976 +
71977 + ruserip = rolep->allowed_ips;
71978 +
71979 + while (ruserip) {
71980 + rlast = rtmp;
71981 +
71982 + if ((rtmp = (struct role_allowed_ip *)
71983 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
71984 + return -ENOMEM;
71985 +
71986 + if (copy_role_allowed_ip(rtmp, ruserip))
71987 + return -EFAULT;
71988 +
71989 + ruserip = rtmp->prev;
71990 +
71991 + if (!rlast) {
71992 + rtmp->prev = NULL;
71993 + rolep->allowed_ips = rtmp;
71994 + } else {
71995 + rlast->next = rtmp;
71996 + rtmp->prev = rlast;
71997 + }
71998 +
71999 + if (!ruserip)
72000 + rtmp->next = NULL;
72001 + }
72002 +
72003 + return 0;
72004 +}
72005 +
72006 +static int
72007 +copy_user_transitions(struct acl_role_label *rolep)
72008 +{
72009 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
72010 + int error;
72011 +
72012 + rusertp = rolep->transitions;
72013 +
72014 + while (rusertp) {
72015 + rlast = rtmp;
72016 +
72017 + if ((rtmp = (struct role_transition *)
72018 + acl_alloc(sizeof (struct role_transition))) == NULL)
72019 + return -ENOMEM;
72020 +
72021 + if (copy_role_transition(rtmp, rusertp))
72022 + return -EFAULT;
72023 +
72024 + rusertp = rtmp->prev;
72025 +
72026 + error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
72027 + if (error)
72028 + return error;
72029 +
72030 + if (!rlast) {
72031 + rtmp->prev = NULL;
72032 + rolep->transitions = rtmp;
72033 + } else {
72034 + rlast->next = rtmp;
72035 + rtmp->prev = rlast;
72036 + }
72037 +
72038 + if (!rusertp)
72039 + rtmp->next = NULL;
72040 + }
72041 +
72042 + return 0;
72043 +}
72044 +
72045 +static __u32 count_user_objs(const struct acl_object_label __user *userp)
72046 +{
72047 + struct acl_object_label o_tmp;
72048 + __u32 num = 0;
72049 +
72050 + while (userp) {
72051 + if (copy_acl_object_label(&o_tmp, userp))
72052 + break;
72053 +
72054 + userp = o_tmp.prev;
72055 + num++;
72056 + }
72057 +
72058 + return num;
72059 +}
72060 +
72061 +static struct acl_subject_label *
72062 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
72063 +{
72064 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
72065 + __u32 num_objs;
72066 + struct acl_ip_label **i_tmp, *i_utmp2;
72067 + struct gr_hash_struct ghash;
72068 + struct subject_map *subjmap;
72069 + unsigned int i_num;
72070 + int err;
72071 +
72072 + if (already_copied != NULL)
72073 + *already_copied = 0;
72074 +
72075 + s_tmp = lookup_subject_map(userp);
72076 +
72077 + /* we've already copied this subject into the kernel, just return
72078 + the reference to it, and don't copy it over again
72079 + */
72080 + if (s_tmp) {
72081 + if (already_copied != NULL)
72082 + *already_copied = 1;
72083 + return(s_tmp);
72084 + }
72085 +
72086 + if ((s_tmp = (struct acl_subject_label *)
72087 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
72088 + return ERR_PTR(-ENOMEM);
72089 +
72090 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
72091 + if (subjmap == NULL)
72092 + return ERR_PTR(-ENOMEM);
72093 +
72094 + subjmap->user = userp;
72095 + subjmap->kernel = s_tmp;
72096 + insert_subj_map_entry(subjmap);
72097 +
72098 + if (copy_acl_subject_label(s_tmp, userp))
72099 + return ERR_PTR(-EFAULT);
72100 +
72101 + err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
72102 + if (err)
72103 + return ERR_PTR(err);
72104 +
72105 + if (!strcmp(s_tmp->filename, "/"))
72106 + role->root_label = s_tmp;
72107 +
72108 + if (copy_gr_hash_struct(&ghash, s_tmp->hash))
72109 + return ERR_PTR(-EFAULT);
72110 +
72111 + /* copy user and group transition tables */
72112 +
72113 + if (s_tmp->user_trans_num) {
72114 + uid_t *uidlist;
72115 +
72116 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
72117 + if (uidlist == NULL)
72118 + return ERR_PTR(-ENOMEM);
72119 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
72120 + return ERR_PTR(-EFAULT);
72121 +
72122 + s_tmp->user_transitions = uidlist;
72123 + }
72124 +
72125 + if (s_tmp->group_trans_num) {
72126 + gid_t *gidlist;
72127 +
72128 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
72129 + if (gidlist == NULL)
72130 + return ERR_PTR(-ENOMEM);
72131 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
72132 + return ERR_PTR(-EFAULT);
72133 +
72134 + s_tmp->group_transitions = gidlist;
72135 + }
72136 +
72137 + /* set up object hash table */
72138 + num_objs = count_user_objs(ghash.first);
72139 +
72140 + s_tmp->obj_hash_size = num_objs;
72141 + s_tmp->obj_hash =
72142 + (struct acl_object_label **)
72143 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
72144 +
72145 + if (!s_tmp->obj_hash)
72146 + return ERR_PTR(-ENOMEM);
72147 +
72148 + memset(s_tmp->obj_hash, 0,
72149 + s_tmp->obj_hash_size *
72150 + sizeof (struct acl_object_label *));
72151 +
72152 + /* add in objects */
72153 + err = copy_user_objs(ghash.first, s_tmp, role);
72154 +
72155 + if (err)
72156 + return ERR_PTR(err);
72157 +
72158 + /* set pointer for parent subject */
72159 + if (s_tmp->parent_subject) {
72160 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
72161 +
72162 + if (IS_ERR(s_tmp2))
72163 + return s_tmp2;
72164 +
72165 + s_tmp->parent_subject = s_tmp2;
72166 + }
72167 +
72168 + /* add in ip acls */
72169 +
72170 + if (!s_tmp->ip_num) {
72171 + s_tmp->ips = NULL;
72172 + goto insert;
72173 + }
72174 +
72175 + i_tmp =
72176 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
72177 + sizeof (struct acl_ip_label *));
72178 +
72179 + if (!i_tmp)
72180 + return ERR_PTR(-ENOMEM);
72181 +
72182 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
72183 + *(i_tmp + i_num) =
72184 + (struct acl_ip_label *)
72185 + acl_alloc(sizeof (struct acl_ip_label));
72186 + if (!*(i_tmp + i_num))
72187 + return ERR_PTR(-ENOMEM);
72188 +
72189 + if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
72190 + return ERR_PTR(-EFAULT);
72191 +
72192 + if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
72193 + return ERR_PTR(-EFAULT);
72194 +
72195 + if ((*(i_tmp + i_num))->iface == NULL)
72196 + continue;
72197 +
72198 + err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
72199 + if (err)
72200 + return ERR_PTR(err);
72201 + }
72202 +
72203 + s_tmp->ips = i_tmp;
72204 +
72205 +insert:
72206 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
72207 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
72208 + return ERR_PTR(-ENOMEM);
72209 +
72210 + return s_tmp;
72211 +}
72212 +
72213 +static int
72214 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
72215 +{
72216 + struct acl_subject_label s_pre;
72217 + struct acl_subject_label * ret;
72218 + int err;
72219 +
72220 + while (userp) {
72221 + if (copy_acl_subject_label(&s_pre, userp))
72222 + return -EFAULT;
72223 +
72224 + ret = do_copy_user_subj(userp, role, NULL);
72225 +
72226 + err = PTR_ERR(ret);
72227 + if (IS_ERR(ret))
72228 + return err;
72229 +
72230 + insert_acl_subj_label(ret, role);
72231 +
72232 + userp = s_pre.prev;
72233 + }
72234 +
72235 + return 0;
72236 +}
72237 +
72238 +static int
72239 +copy_user_acl(struct gr_arg *arg)
72240 +{
72241 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
72242 + struct acl_subject_label *subj_list;
72243 + struct sprole_pw *sptmp;
72244 + struct gr_hash_struct *ghash;
72245 + uid_t *domainlist;
72246 + unsigned int r_num;
72247 + int err = 0;
72248 + __u16 i;
72249 + __u32 num_subjs;
72250 +
72251 + /* we need a default and kernel role */
72252 + if (arg->role_db.num_roles < 2)
72253 + return -EINVAL;
72254 +
72255 + /* copy special role authentication info from userspace */
72256 +
72257 + polstate->num_sprole_pws = arg->num_sprole_pws;
72258 + polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
72259 +
72260 + if (!polstate->acl_special_roles && polstate->num_sprole_pws)
72261 + return -ENOMEM;
72262 +
72263 + for (i = 0; i < polstate->num_sprole_pws; i++) {
72264 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
72265 + if (!sptmp)
72266 + return -ENOMEM;
72267 + if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
72268 + return -EFAULT;
72269 +
72270 + err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
72271 + if (err)
72272 + return err;
72273 +
72274 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
72275 + printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
72276 +#endif
72277 +
72278 + polstate->acl_special_roles[i] = sptmp;
72279 + }
72280 +
72281 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
72282 +
72283 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
72284 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
72285 +
72286 + if (!r_tmp)
72287 + return -ENOMEM;
72288 +
72289 + if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
72290 + return -EFAULT;
72291 +
72292 + if (copy_acl_role_label(r_tmp, r_utmp2))
72293 + return -EFAULT;
72294 +
72295 + err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
72296 + if (err)
72297 + return err;
72298 +
72299 + if (!strcmp(r_tmp->rolename, "default")
72300 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
72301 + polstate->default_role = r_tmp;
72302 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
72303 + polstate->kernel_role = r_tmp;
72304 + }
72305 +
72306 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
72307 + return -ENOMEM;
72308 +
72309 + if (copy_gr_hash_struct(ghash, r_tmp->hash))
72310 + return -EFAULT;
72311 +
72312 + r_tmp->hash = ghash;
72313 +
72314 + num_subjs = count_user_subjs(r_tmp->hash->first);
72315 +
72316 + r_tmp->subj_hash_size = num_subjs;
72317 + r_tmp->subj_hash =
72318 + (struct acl_subject_label **)
72319 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
72320 +
72321 + if (!r_tmp->subj_hash)
72322 + return -ENOMEM;
72323 +
72324 + err = copy_user_allowedips(r_tmp);
72325 + if (err)
72326 + return err;
72327 +
72328 + /* copy domain info */
72329 + if (r_tmp->domain_children != NULL) {
72330 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
72331 + if (domainlist == NULL)
72332 + return -ENOMEM;
72333 +
72334 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
72335 + return -EFAULT;
72336 +
72337 + r_tmp->domain_children = domainlist;
72338 + }
72339 +
72340 + err = copy_user_transitions(r_tmp);
72341 + if (err)
72342 + return err;
72343 +
72344 + memset(r_tmp->subj_hash, 0,
72345 + r_tmp->subj_hash_size *
72346 + sizeof (struct acl_subject_label *));
72347 +
72348 + /* acquire the list of subjects, then NULL out
72349 + the list prior to parsing the subjects for this role,
72350 + as during this parsing the list is replaced with a list
72351 + of *nested* subjects for the role
72352 + */
72353 + subj_list = r_tmp->hash->first;
72354 +
72355 + /* set nested subject list to null */
72356 + r_tmp->hash->first = NULL;
72357 +
72358 + err = copy_user_subjs(subj_list, r_tmp);
72359 +
72360 + if (err)
72361 + return err;
72362 +
72363 + insert_acl_role_label(r_tmp);
72364 + }
72365 +
72366 + if (polstate->default_role == NULL || polstate->kernel_role == NULL)
72367 + return -EINVAL;
72368 +
72369 + return err;
72370 +}
72371 +
72372 +static int gracl_reload_apply_policies(void *reload)
72373 +{
72374 + struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
72375 + struct task_struct *task, *task2;
72376 + struct acl_role_label *role, *rtmp;
72377 + struct acl_subject_label *subj;
72378 + const struct cred *cred;
72379 + int role_applied;
72380 + int ret = 0;
72381 +
72382 + memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_policy_state));
72383 + memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
72384 +
72385 + /* first make sure we'll be able to apply the new policy cleanly */
72386 + do_each_thread(task2, task) {
72387 + if (task->exec_file == NULL)
72388 + continue;
72389 + role_applied = 0;
72390 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
72391 + /* preserve special roles */
72392 + FOR_EACH_ROLE_START(role)
72393 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
72394 + rtmp = task->role;
72395 + task->role = role;
72396 + role_applied = 1;
72397 + break;
72398 + }
72399 + FOR_EACH_ROLE_END(role)
72400 + }
72401 + if (!role_applied) {
72402 + cred = __task_cred(task);
72403 + rtmp = task->role;
72404 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
72405 + }
72406 + /* this handles non-nested inherited subjects, nested subjects will still
72407 + be dropped currently */
72408 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
72409 + task->tmpacl = __gr_get_subject_for_task(polstate, task, NULL);
72410 + /* change the role back so that we've made no modifications to the policy */
72411 + task->role = rtmp;
72412 +
72413 + if (subj == NULL || task->tmpacl == NULL) {
72414 + ret = -EINVAL;
72415 + goto out;
72416 + }
72417 + } while_each_thread(task2, task);
72418 +
72419 + /* now actually apply the policy */
72420 +
72421 + do_each_thread(task2, task) {
72422 + if (task->exec_file) {
72423 + role_applied = 0;
72424 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
72425 + /* preserve special roles */
72426 + FOR_EACH_ROLE_START(role)
72427 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
72428 + task->role = role;
72429 + role_applied = 1;
72430 + break;
72431 + }
72432 + FOR_EACH_ROLE_END(role)
72433 + }
72434 + if (!role_applied) {
72435 + cred = __task_cred(task);
72436 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
72437 + }
72438 + /* this handles non-nested inherited subjects, nested subjects will still
72439 + be dropped currently */
72440 + if (!reload_state->oldmode && task->inherited)
72441 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
72442 + else {
72443 + /* looked up and tagged to the task previously */
72444 + subj = task->tmpacl;
72445 + }
72446 + /* subj will be non-null */
72447 + __gr_apply_subject_to_task(polstate, task, subj);
72448 + if (reload_state->oldmode) {
72449 + task->acl_role_id = 0;
72450 + task->acl_sp_role = 0;
72451 + task->inherited = 0;
72452 + }
72453 + } else {
72454 + // it's a kernel process
72455 + task->role = polstate->kernel_role;
72456 + task->acl = polstate->kernel_role->root_label;
72457 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
72458 + task->acl->mode &= ~GR_PROCFIND;
72459 +#endif
72460 + }
72461 + } while_each_thread(task2, task);
72462 +
72463 + memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
72464 + memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
72465 +
72466 +out:
72467 +
72468 + return ret;
72469 +}
72470 +
72471 +static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
72472 +{
72473 + struct gr_reload_state new_reload_state = { };
72474 + int err;
72475 +
72476 + new_reload_state.oldpolicy_ptr = polstate;
72477 + new_reload_state.oldalloc_ptr = current_alloc_state;
72478 + new_reload_state.oldmode = oldmode;
72479 +
72480 + current_alloc_state = &new_reload_state.newalloc;
72481 + polstate = &new_reload_state.newpolicy;
72482 +
72483 + /* everything relevant is now saved off, copy in the new policy */
72484 + if (init_variables(args, true)) {
72485 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
72486 + err = -ENOMEM;
72487 + goto error;
72488 + }
72489 +
72490 + err = copy_user_acl(args);
72491 + free_init_variables();
72492 + if (err)
72493 + goto error;
72494 + /* the new policy is copied in, with the old policy available via saved_state
72495 + first go through applying roles, making sure to preserve special roles
72496 + then apply new subjects, making sure to preserve inherited and nested subjects,
72497 + though currently only inherited subjects will be preserved
72498 + */
72499 + err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
72500 + if (err)
72501 + goto error;
72502 +
72503 + /* we've now applied the new policy, so restore the old policy state to free it */
72504 + polstate = &new_reload_state.oldpolicy;
72505 + current_alloc_state = &new_reload_state.oldalloc;
72506 + free_variables(true);
72507 +
72508 + /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
72509 + to running_polstate/current_alloc_state inside stop_machine
72510 + */
72511 + err = 0;
72512 + goto out;
72513 +error:
72514 + /* on error of loading the new policy, we'll just keep the previous
72515 + policy set around
72516 + */
72517 + free_variables(true);
72518 +
72519 + /* doesn't affect runtime, but maintains consistent state */
72520 +out:
72521 + polstate = new_reload_state.oldpolicy_ptr;
72522 + current_alloc_state = new_reload_state.oldalloc_ptr;
72523 +
72524 + return err;
72525 +}
72526 +
72527 +static int
72528 +gracl_init(struct gr_arg *args)
72529 +{
72530 + int error = 0;
72531 +
72532 + memcpy(&gr_system_salt, args->salt, sizeof(gr_system_salt));
72533 + memcpy(&gr_system_sum, args->sum, sizeof(gr_system_sum));
72534 +
72535 + if (init_variables(args, false)) {
72536 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
72537 + error = -ENOMEM;
72538 + goto out;
72539 + }
72540 +
72541 + error = copy_user_acl(args);
72542 + free_init_variables();
72543 + if (error)
72544 + goto out;
72545 +
72546 + error = gr_set_acls(0);
72547 + if (error)
72548 + goto out;
72549 +
72550 + gr_enable_rbac_system();
72551 +
72552 + return 0;
72553 +
72554 +out:
72555 + free_variables(false);
72556 + return error;
72557 +}
72558 +
72559 +static int
72560 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
72561 + unsigned char **sum)
72562 +{
72563 + struct acl_role_label *r;
72564 + struct role_allowed_ip *ipp;
72565 + struct role_transition *trans;
72566 + unsigned int i;
72567 + int found = 0;
72568 + u32 curr_ip = current->signal->curr_ip;
72569 +
72570 + current->signal->saved_ip = curr_ip;
72571 +
72572 + /* check transition table */
72573 +
72574 + for (trans = current->role->transitions; trans; trans = trans->next) {
72575 + if (!strcmp(rolename, trans->rolename)) {
72576 + found = 1;
72577 + break;
72578 + }
72579 + }
72580 +
72581 + if (!found)
72582 + return 0;
72583 +
72584 + /* handle special roles that do not require authentication
72585 + and check ip */
72586 +
72587 + FOR_EACH_ROLE_START(r)
72588 + if (!strcmp(rolename, r->rolename) &&
72589 + (r->roletype & GR_ROLE_SPECIAL)) {
72590 + found = 0;
72591 + if (r->allowed_ips != NULL) {
72592 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
72593 + if ((ntohl(curr_ip) & ipp->netmask) ==
72594 + (ntohl(ipp->addr) & ipp->netmask))
72595 + found = 1;
72596 + }
72597 + } else
72598 + found = 2;
72599 + if (!found)
72600 + return 0;
72601 +
72602 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
72603 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
72604 + *salt = NULL;
72605 + *sum = NULL;
72606 + return 1;
72607 + }
72608 + }
72609 + FOR_EACH_ROLE_END(r)
72610 +
72611 + for (i = 0; i < polstate->num_sprole_pws; i++) {
72612 + if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
72613 + *salt = polstate->acl_special_roles[i]->salt;
72614 + *sum = polstate->acl_special_roles[i]->sum;
72615 + return 1;
72616 + }
72617 + }
72618 +
72619 + return 0;
72620 +}
72621 +
72622 +int gr_check_secure_terminal(struct task_struct *task)
72623 +{
72624 + struct task_struct *p, *p2, *p3;
72625 + struct files_struct *files;
72626 + struct fdtable *fdt;
72627 + struct file *our_file = NULL, *file;
72628 + int i;
72629 +
72630 + if (task->signal->tty == NULL)
72631 + return 1;
72632 +
72633 + files = get_files_struct(task);
72634 + if (files != NULL) {
72635 + rcu_read_lock();
72636 + fdt = files_fdtable(files);
72637 + for (i=0; i < fdt->max_fds; i++) {
72638 + file = fcheck_files(files, i);
72639 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
72640 + get_file(file);
72641 + our_file = file;
72642 + }
72643 + }
72644 + rcu_read_unlock();
72645 + put_files_struct(files);
72646 + }
72647 +
72648 + if (our_file == NULL)
72649 + return 1;
72650 +
72651 + read_lock(&tasklist_lock);
72652 + do_each_thread(p2, p) {
72653 + files = get_files_struct(p);
72654 + if (files == NULL ||
72655 + (p->signal && p->signal->tty == task->signal->tty)) {
72656 + if (files != NULL)
72657 + put_files_struct(files);
72658 + continue;
72659 + }
72660 + rcu_read_lock();
72661 + fdt = files_fdtable(files);
72662 + for (i=0; i < fdt->max_fds; i++) {
72663 + file = fcheck_files(files, i);
72664 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
72665 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
72666 + p3 = task;
72667 + while (task_pid_nr(p3) > 0) {
72668 + if (p3 == p)
72669 + break;
72670 + p3 = p3->real_parent;
72671 + }
72672 + if (p3 == p)
72673 + break;
72674 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
72675 + gr_handle_alertkill(p);
72676 + rcu_read_unlock();
72677 + put_files_struct(files);
72678 + read_unlock(&tasklist_lock);
72679 + fput(our_file);
72680 + return 0;
72681 + }
72682 + }
72683 + rcu_read_unlock();
72684 + put_files_struct(files);
72685 + } while_each_thread(p2, p);
72686 + read_unlock(&tasklist_lock);
72687 +
72688 + fput(our_file);
72689 + return 1;
72690 +}
72691 +
72692 +ssize_t
72693 +write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
72694 +{
72695 + struct gr_arg_wrapper uwrap;
72696 + unsigned char *sprole_salt = NULL;
72697 + unsigned char *sprole_sum = NULL;
72698 + int error = 0;
72699 + int error2 = 0;
72700 + size_t req_count = 0;
72701 + unsigned char oldmode = 0;
72702 +
72703 + mutex_lock(&gr_dev_mutex);
72704 +
72705 + if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
72706 + error = -EPERM;
72707 + goto out;
72708 + }
72709 +
72710 +#ifdef CONFIG_COMPAT
72711 + pax_open_kernel();
72712 + if (is_compat_task()) {
72713 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
72714 + copy_gr_arg = &copy_gr_arg_compat;
72715 + copy_acl_object_label = &copy_acl_object_label_compat;
72716 + copy_acl_subject_label = &copy_acl_subject_label_compat;
72717 + copy_acl_role_label = &copy_acl_role_label_compat;
72718 + copy_acl_ip_label = &copy_acl_ip_label_compat;
72719 + copy_role_allowed_ip = &copy_role_allowed_ip_compat;
72720 + copy_role_transition = &copy_role_transition_compat;
72721 + copy_sprole_pw = &copy_sprole_pw_compat;
72722 + copy_gr_hash_struct = &copy_gr_hash_struct_compat;
72723 + copy_pointer_from_array = &copy_pointer_from_array_compat;
72724 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
72725 + } else {
72726 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
72727 + copy_gr_arg = &copy_gr_arg_normal;
72728 + copy_acl_object_label = &copy_acl_object_label_normal;
72729 + copy_acl_subject_label = &copy_acl_subject_label_normal;
72730 + copy_acl_role_label = &copy_acl_role_label_normal;
72731 + copy_acl_ip_label = &copy_acl_ip_label_normal;
72732 + copy_role_allowed_ip = &copy_role_allowed_ip_normal;
72733 + copy_role_transition = &copy_role_transition_normal;
72734 + copy_sprole_pw = &copy_sprole_pw_normal;
72735 + copy_gr_hash_struct = &copy_gr_hash_struct_normal;
72736 + copy_pointer_from_array = &copy_pointer_from_array_normal;
72737 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
72738 + }
72739 + pax_close_kernel();
72740 +#endif
72741 +
72742 + req_count = get_gr_arg_wrapper_size();
72743 +
72744 + if (count != req_count) {
72745 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
72746 + error = -EINVAL;
72747 + goto out;
72748 + }
72749 +
72750 +
72751 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
72752 + gr_auth_expires = 0;
72753 + gr_auth_attempts = 0;
72754 + }
72755 +
72756 + error = copy_gr_arg_wrapper(buf, &uwrap);
72757 + if (error)
72758 + goto out;
72759 +
72760 + error = copy_gr_arg(uwrap.arg, &gr_usermode);
72761 + if (error)
72762 + goto out;
72763 +
72764 + if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_SPROLEPAM &&
72765 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
72766 + time_after(gr_auth_expires, get_seconds())) {
72767 + error = -EBUSY;
72768 + goto out;
72769 + }
72770 +
72771 + /* if non-root trying to do anything other than use a special role,
72772 + do not attempt authentication, do not count towards authentication
72773 + locking
72774 + */
72775 +
72776 + if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_STATUS &&
72777 + gr_usermode.mode != GR_UNSPROLE && gr_usermode.mode != GR_SPROLEPAM &&
72778 + gr_is_global_nonroot(current_uid())) {
72779 + error = -EPERM;
72780 + goto out;
72781 + }
72782 +
72783 + /* ensure pw and special role name are null terminated */
72784 +
72785 + gr_usermode.pw[GR_PW_LEN - 1] = '\0';
72786 + gr_usermode.sp_role[GR_SPROLE_LEN - 1] = '\0';
72787 +
72788 + /* Okay.
72789 + * We have our enough of the argument structure..(we have yet
72790 + * to copy_from_user the tables themselves) . Copy the tables
72791 + * only if we need them, i.e. for loading operations. */
72792 +
72793 + switch (gr_usermode.mode) {
72794 + case GR_STATUS:
72795 + if (gr_acl_is_enabled()) {
72796 + error = 1;
72797 + if (!gr_check_secure_terminal(current))
72798 + error = 3;
72799 + } else
72800 + error = 2;
72801 + goto out;
72802 + case GR_SHUTDOWN:
72803 + if (gr_acl_is_enabled() && !(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72804 + stop_machine(gr_rbac_disable, NULL, NULL);
72805 + free_variables(false);
72806 + memset(&gr_usermode, 0, sizeof(gr_usermode));
72807 + memset(&gr_system_salt, 0, sizeof(gr_system_salt));
72808 + memset(&gr_system_sum, 0, sizeof(gr_system_sum));
72809 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
72810 + } else if (gr_acl_is_enabled()) {
72811 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
72812 + error = -EPERM;
72813 + } else {
72814 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
72815 + error = -EAGAIN;
72816 + }
72817 + break;
72818 + case GR_ENABLE:
72819 + if (!gr_acl_is_enabled() && !(error2 = gracl_init(&gr_usermode)))
72820 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
72821 + else {
72822 + if (gr_acl_is_enabled())
72823 + error = -EAGAIN;
72824 + else
72825 + error = error2;
72826 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
72827 + }
72828 + break;
72829 + case GR_OLDRELOAD:
72830 + oldmode = 1;
72831 + case GR_RELOAD:
72832 + if (!gr_acl_is_enabled()) {
72833 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
72834 + error = -EAGAIN;
72835 + } else if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72836 + error2 = gracl_reload(&gr_usermode, oldmode);
72837 + if (!error2)
72838 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
72839 + else {
72840 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
72841 + error = error2;
72842 + }
72843 + } else {
72844 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
72845 + error = -EPERM;
72846 + }
72847 + break;
72848 + case GR_SEGVMOD:
72849 + if (unlikely(!gr_acl_is_enabled())) {
72850 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
72851 + error = -EAGAIN;
72852 + break;
72853 + }
72854 +
72855 + if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
72856 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
72857 + if (gr_usermode.segv_device && gr_usermode.segv_inode) {
72858 + struct acl_subject_label *segvacl;
72859 + segvacl =
72860 + lookup_acl_subj_label(gr_usermode.segv_inode,
72861 + gr_usermode.segv_device,
72862 + current->role);
72863 + if (segvacl) {
72864 + segvacl->crashes = 0;
72865 + segvacl->expires = 0;
72866 + }
72867 + } else if (gr_find_uid(gr_usermode.segv_uid) >= 0) {
72868 + gr_remove_uid(gr_usermode.segv_uid);
72869 + }
72870 + } else {
72871 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
72872 + error = -EPERM;
72873 + }
72874 + break;
72875 + case GR_SPROLE:
72876 + case GR_SPROLEPAM:
72877 + if (unlikely(!gr_acl_is_enabled())) {
72878 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
72879 + error = -EAGAIN;
72880 + break;
72881 + }
72882 +
72883 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
72884 + current->role->expires = 0;
72885 + current->role->auth_attempts = 0;
72886 + }
72887 +
72888 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
72889 + time_after(current->role->expires, get_seconds())) {
72890 + error = -EBUSY;
72891 + goto out;
72892 + }
72893 +
72894 + if (lookup_special_role_auth
72895 + (gr_usermode.mode, gr_usermode.sp_role, &sprole_salt, &sprole_sum)
72896 + && ((!sprole_salt && !sprole_sum)
72897 + || !(chkpw(&gr_usermode, sprole_salt, sprole_sum)))) {
72898 + char *p = "";
72899 + assign_special_role(gr_usermode.sp_role);
72900 + read_lock(&tasklist_lock);
72901 + if (current->real_parent)
72902 + p = current->real_parent->role->rolename;
72903 + read_unlock(&tasklist_lock);
72904 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
72905 + p, acl_sp_role_value);
72906 + } else {
72907 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode.sp_role);
72908 + error = -EPERM;
72909 + if(!(current->role->auth_attempts++))
72910 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
72911 +
72912 + goto out;
72913 + }
72914 + break;
72915 + case GR_UNSPROLE:
72916 + if (unlikely(!gr_acl_is_enabled())) {
72917 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
72918 + error = -EAGAIN;
72919 + break;
72920 + }
72921 +
72922 + if (current->role->roletype & GR_ROLE_SPECIAL) {
72923 + char *p = "";
72924 + int i = 0;
72925 +
72926 + read_lock(&tasklist_lock);
72927 + if (current->real_parent) {
72928 + p = current->real_parent->role->rolename;
72929 + i = current->real_parent->acl_role_id;
72930 + }
72931 + read_unlock(&tasklist_lock);
72932 +
72933 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
72934 + gr_set_acls(1);
72935 + } else {
72936 + error = -EPERM;
72937 + goto out;
72938 + }
72939 + break;
72940 + default:
72941 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode.mode);
72942 + error = -EINVAL;
72943 + break;
72944 + }
72945 +
72946 + if (error != -EPERM)
72947 + goto out;
72948 +
72949 + if(!(gr_auth_attempts++))
72950 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
72951 +
72952 + out:
72953 + mutex_unlock(&gr_dev_mutex);
72954 +
72955 + if (!error)
72956 + error = req_count;
72957 +
72958 + return error;
72959 +}
72960 +
72961 +int
72962 +gr_set_acls(const int type)
72963 +{
72964 + struct task_struct *task, *task2;
72965 + struct acl_role_label *role = current->role;
72966 + struct acl_subject_label *subj;
72967 + __u16 acl_role_id = current->acl_role_id;
72968 + const struct cred *cred;
72969 + int ret;
72970 +
72971 + rcu_read_lock();
72972 + read_lock(&tasklist_lock);
72973 + read_lock(&grsec_exec_file_lock);
72974 + do_each_thread(task2, task) {
72975 + /* check to see if we're called from the exit handler,
72976 + if so, only replace ACLs that have inherited the admin
72977 + ACL */
72978 +
72979 + if (type && (task->role != role ||
72980 + task->acl_role_id != acl_role_id))
72981 + continue;
72982 +
72983 + task->acl_role_id = 0;
72984 + task->acl_sp_role = 0;
72985 + task->inherited = 0;
72986 +
72987 + if (task->exec_file) {
72988 + cred = __task_cred(task);
72989 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
72990 + subj = __gr_get_subject_for_task(polstate, task, NULL);
72991 + if (subj == NULL) {
72992 + ret = -EINVAL;
72993 + read_unlock(&grsec_exec_file_lock);
72994 + read_unlock(&tasklist_lock);
72995 + rcu_read_unlock();
72996 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
72997 + return ret;
72998 + }
72999 + __gr_apply_subject_to_task(polstate, task, subj);
73000 + } else {
73001 + // it's a kernel process
73002 + task->role = polstate->kernel_role;
73003 + task->acl = polstate->kernel_role->root_label;
73004 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
73005 + task->acl->mode &= ~GR_PROCFIND;
73006 +#endif
73007 + }
73008 + } while_each_thread(task2, task);
73009 + read_unlock(&grsec_exec_file_lock);
73010 + read_unlock(&tasklist_lock);
73011 + rcu_read_unlock();
73012 +
73013 + return 0;
73014 +}
73015 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
73016 new file mode 100644
73017 index 0000000..39645c9
73018 --- /dev/null
73019 +++ b/grsecurity/gracl_res.c
73020 @@ -0,0 +1,68 @@
73021 +#include <linux/kernel.h>
73022 +#include <linux/sched.h>
73023 +#include <linux/gracl.h>
73024 +#include <linux/grinternal.h>
73025 +
73026 +static const char *restab_log[] = {
73027 + [RLIMIT_CPU] = "RLIMIT_CPU",
73028 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
73029 + [RLIMIT_DATA] = "RLIMIT_DATA",
73030 + [RLIMIT_STACK] = "RLIMIT_STACK",
73031 + [RLIMIT_CORE] = "RLIMIT_CORE",
73032 + [RLIMIT_RSS] = "RLIMIT_RSS",
73033 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
73034 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
73035 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
73036 + [RLIMIT_AS] = "RLIMIT_AS",
73037 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
73038 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
73039 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
73040 + [RLIMIT_NICE] = "RLIMIT_NICE",
73041 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
73042 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
73043 + [GR_CRASH_RES] = "RLIMIT_CRASH"
73044 +};
73045 +
73046 +void
73047 +gr_log_resource(const struct task_struct *task,
73048 + const int res, const unsigned long wanted, const int gt)
73049 +{
73050 + const struct cred *cred;
73051 + unsigned long rlim;
73052 +
73053 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
73054 + return;
73055 +
73056 + // not yet supported resource
73057 + if (unlikely(!restab_log[res]))
73058 + return;
73059 +
73060 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
73061 + rlim = task_rlimit_max(task, res);
73062 + else
73063 + rlim = task_rlimit(task, res);
73064 +
73065 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
73066 + return;
73067 +
73068 + rcu_read_lock();
73069 + cred = __task_cred(task);
73070 +
73071 + if (res == RLIMIT_NPROC &&
73072 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
73073 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
73074 + goto out_rcu_unlock;
73075 + else if (res == RLIMIT_MEMLOCK &&
73076 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
73077 + goto out_rcu_unlock;
73078 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
73079 + goto out_rcu_unlock;
73080 + rcu_read_unlock();
73081 +
73082 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
73083 +
73084 + return;
73085 +out_rcu_unlock:
73086 + rcu_read_unlock();
73087 + return;
73088 +}
73089 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
73090 new file mode 100644
73091 index 0000000..2040e61
73092 --- /dev/null
73093 +++ b/grsecurity/gracl_segv.c
73094 @@ -0,0 +1,313 @@
73095 +#include <linux/kernel.h>
73096 +#include <linux/mm.h>
73097 +#include <asm/uaccess.h>
73098 +#include <asm/errno.h>
73099 +#include <asm/mman.h>
73100 +#include <net/sock.h>
73101 +#include <linux/file.h>
73102 +#include <linux/fs.h>
73103 +#include <linux/net.h>
73104 +#include <linux/in.h>
73105 +#include <linux/slab.h>
73106 +#include <linux/types.h>
73107 +#include <linux/sched.h>
73108 +#include <linux/timer.h>
73109 +#include <linux/gracl.h>
73110 +#include <linux/grsecurity.h>
73111 +#include <linux/grinternal.h>
73112 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
73113 +#include <linux/magic.h>
73114 +#include <linux/pagemap.h>
73115 +#include "../fs/btrfs/async-thread.h"
73116 +#include "../fs/btrfs/ctree.h"
73117 +#include "../fs/btrfs/btrfs_inode.h"
73118 +#endif
73119 +
73120 +static struct crash_uid *uid_set;
73121 +static unsigned short uid_used;
73122 +static DEFINE_SPINLOCK(gr_uid_lock);
73123 +extern rwlock_t gr_inode_lock;
73124 +extern struct acl_subject_label *
73125 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
73126 + struct acl_role_label *role);
73127 +
73128 +static inline dev_t __get_dev(const struct dentry *dentry)
73129 +{
73130 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
73131 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
73132 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
73133 + else
73134 +#endif
73135 + return dentry->d_sb->s_dev;
73136 +}
73137 +
73138 +int
73139 +gr_init_uidset(void)
73140 +{
73141 + uid_set =
73142 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
73143 + uid_used = 0;
73144 +
73145 + return uid_set ? 1 : 0;
73146 +}
73147 +
73148 +void
73149 +gr_free_uidset(void)
73150 +{
73151 + if (uid_set) {
73152 + struct crash_uid *tmpset;
73153 + spin_lock(&gr_uid_lock);
73154 + tmpset = uid_set;
73155 + uid_set = NULL;
73156 + uid_used = 0;
73157 + spin_unlock(&gr_uid_lock);
73158 + if (tmpset)
73159 + kfree(tmpset);
73160 + }
73161 +
73162 + return;
73163 +}
73164 +
73165 +int
73166 +gr_find_uid(const uid_t uid)
73167 +{
73168 + struct crash_uid *tmp = uid_set;
73169 + uid_t buid;
73170 + int low = 0, high = uid_used - 1, mid;
73171 +
73172 + while (high >= low) {
73173 + mid = (low + high) >> 1;
73174 + buid = tmp[mid].uid;
73175 + if (buid == uid)
73176 + return mid;
73177 + if (buid > uid)
73178 + high = mid - 1;
73179 + if (buid < uid)
73180 + low = mid + 1;
73181 + }
73182 +
73183 + return -1;
73184 +}
73185 +
73186 +static __inline__ void
73187 +gr_insertsort(void)
73188 +{
73189 + unsigned short i, j;
73190 + struct crash_uid index;
73191 +
73192 + for (i = 1; i < uid_used; i++) {
73193 + index = uid_set[i];
73194 + j = i;
73195 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
73196 + uid_set[j] = uid_set[j - 1];
73197 + j--;
73198 + }
73199 + uid_set[j] = index;
73200 + }
73201 +
73202 + return;
73203 +}
73204 +
73205 +static __inline__ void
73206 +gr_insert_uid(const kuid_t kuid, const unsigned long expires)
73207 +{
73208 + int loc;
73209 + uid_t uid = GR_GLOBAL_UID(kuid);
73210 +
73211 + if (uid_used == GR_UIDTABLE_MAX)
73212 + return;
73213 +
73214 + loc = gr_find_uid(uid);
73215 +
73216 + if (loc >= 0) {
73217 + uid_set[loc].expires = expires;
73218 + return;
73219 + }
73220 +
73221 + uid_set[uid_used].uid = uid;
73222 + uid_set[uid_used].expires = expires;
73223 + uid_used++;
73224 +
73225 + gr_insertsort();
73226 +
73227 + return;
73228 +}
73229 +
73230 +void
73231 +gr_remove_uid(const unsigned short loc)
73232 +{
73233 + unsigned short i;
73234 +
73235 + for (i = loc + 1; i < uid_used; i++)
73236 + uid_set[i - 1] = uid_set[i];
73237 +
73238 + uid_used--;
73239 +
73240 + return;
73241 +}
73242 +
73243 +int
73244 +gr_check_crash_uid(const kuid_t kuid)
73245 +{
73246 + int loc;
73247 + int ret = 0;
73248 + uid_t uid;
73249 +
73250 + if (unlikely(!gr_acl_is_enabled()))
73251 + return 0;
73252 +
73253 + uid = GR_GLOBAL_UID(kuid);
73254 +
73255 + spin_lock(&gr_uid_lock);
73256 + loc = gr_find_uid(uid);
73257 +
73258 + if (loc < 0)
73259 + goto out_unlock;
73260 +
73261 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
73262 + gr_remove_uid(loc);
73263 + else
73264 + ret = 1;
73265 +
73266 +out_unlock:
73267 + spin_unlock(&gr_uid_lock);
73268 + return ret;
73269 +}
73270 +
73271 +static __inline__ int
73272 +proc_is_setxid(const struct cred *cred)
73273 +{
73274 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
73275 + !uid_eq(cred->uid, cred->fsuid))
73276 + return 1;
73277 + if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
73278 + !gid_eq(cred->gid, cred->fsgid))
73279 + return 1;
73280 +
73281 + return 0;
73282 +}
73283 +
73284 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
73285 +
73286 +void
73287 +gr_handle_crash(struct task_struct *task, const int sig)
73288 +{
73289 + struct acl_subject_label *curr;
73290 + struct task_struct *tsk, *tsk2;
73291 + const struct cred *cred;
73292 + const struct cred *cred2;
73293 +
73294 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
73295 + return;
73296 +
73297 + if (unlikely(!gr_acl_is_enabled()))
73298 + return;
73299 +
73300 + curr = task->acl;
73301 +
73302 + if (!(curr->resmask & (1U << GR_CRASH_RES)))
73303 + return;
73304 +
73305 + if (time_before_eq(curr->expires, get_seconds())) {
73306 + curr->expires = 0;
73307 + curr->crashes = 0;
73308 + }
73309 +
73310 + curr->crashes++;
73311 +
73312 + if (!curr->expires)
73313 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
73314 +
73315 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
73316 + time_after(curr->expires, get_seconds())) {
73317 + rcu_read_lock();
73318 + cred = __task_cred(task);
73319 + if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
73320 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
73321 + spin_lock(&gr_uid_lock);
73322 + gr_insert_uid(cred->uid, curr->expires);
73323 + spin_unlock(&gr_uid_lock);
73324 + curr->expires = 0;
73325 + curr->crashes = 0;
73326 + read_lock(&tasklist_lock);
73327 + do_each_thread(tsk2, tsk) {
73328 + cred2 = __task_cred(tsk);
73329 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
73330 + gr_fake_force_sig(SIGKILL, tsk);
73331 + } while_each_thread(tsk2, tsk);
73332 + read_unlock(&tasklist_lock);
73333 + } else {
73334 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
73335 + read_lock(&tasklist_lock);
73336 + read_lock(&grsec_exec_file_lock);
73337 + do_each_thread(tsk2, tsk) {
73338 + if (likely(tsk != task)) {
73339 + // if this thread has the same subject as the one that triggered
73340 + // RES_CRASH and it's the same binary, kill it
73341 + if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
73342 + gr_fake_force_sig(SIGKILL, tsk);
73343 + }
73344 + } while_each_thread(tsk2, tsk);
73345 + read_unlock(&grsec_exec_file_lock);
73346 + read_unlock(&tasklist_lock);
73347 + }
73348 + rcu_read_unlock();
73349 + }
73350 +
73351 + return;
73352 +}
73353 +
73354 +int
73355 +gr_check_crash_exec(const struct file *filp)
73356 +{
73357 + struct acl_subject_label *curr;
73358 +
73359 + if (unlikely(!gr_acl_is_enabled()))
73360 + return 0;
73361 +
73362 + read_lock(&gr_inode_lock);
73363 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
73364 + __get_dev(filp->f_path.dentry),
73365 + current->role);
73366 + read_unlock(&gr_inode_lock);
73367 +
73368 + if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
73369 + (!curr->crashes && !curr->expires))
73370 + return 0;
73371 +
73372 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
73373 + time_after(curr->expires, get_seconds()))
73374 + return 1;
73375 + else if (time_before_eq(curr->expires, get_seconds())) {
73376 + curr->crashes = 0;
73377 + curr->expires = 0;
73378 + }
73379 +
73380 + return 0;
73381 +}
73382 +
73383 +void
73384 +gr_handle_alertkill(struct task_struct *task)
73385 +{
73386 + struct acl_subject_label *curracl;
73387 + __u32 curr_ip;
73388 + struct task_struct *p, *p2;
73389 +
73390 + if (unlikely(!gr_acl_is_enabled()))
73391 + return;
73392 +
73393 + curracl = task->acl;
73394 + curr_ip = task->signal->curr_ip;
73395 +
73396 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
73397 + read_lock(&tasklist_lock);
73398 + do_each_thread(p2, p) {
73399 + if (p->signal->curr_ip == curr_ip)
73400 + gr_fake_force_sig(SIGKILL, p);
73401 + } while_each_thread(p2, p);
73402 + read_unlock(&tasklist_lock);
73403 + } else if (curracl->mode & GR_KILLPROC)
73404 + gr_fake_force_sig(SIGKILL, task);
73405 +
73406 + return;
73407 +}
73408 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
73409 new file mode 100644
73410 index 0000000..98011b0
73411 --- /dev/null
73412 +++ b/grsecurity/gracl_shm.c
73413 @@ -0,0 +1,40 @@
73414 +#include <linux/kernel.h>
73415 +#include <linux/mm.h>
73416 +#include <linux/sched.h>
73417 +#include <linux/file.h>
73418 +#include <linux/ipc.h>
73419 +#include <linux/gracl.h>
73420 +#include <linux/grsecurity.h>
73421 +#include <linux/grinternal.h>
73422 +
73423 +int
73424 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73425 + const time_t shm_createtime, const kuid_t cuid, const int shmid)
73426 +{
73427 + struct task_struct *task;
73428 +
73429 + if (!gr_acl_is_enabled())
73430 + return 1;
73431 +
73432 + rcu_read_lock();
73433 + read_lock(&tasklist_lock);
73434 +
73435 + task = find_task_by_vpid(shm_cprid);
73436 +
73437 + if (unlikely(!task))
73438 + task = find_task_by_vpid(shm_lapid);
73439 +
73440 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
73441 + (task_pid_nr(task) == shm_lapid)) &&
73442 + (task->acl->mode & GR_PROTSHM) &&
73443 + (task->acl != current->acl))) {
73444 + read_unlock(&tasklist_lock);
73445 + rcu_read_unlock();
73446 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
73447 + return 0;
73448 + }
73449 + read_unlock(&tasklist_lock);
73450 + rcu_read_unlock();
73451 +
73452 + return 1;
73453 +}
73454 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
73455 new file mode 100644
73456 index 0000000..bc0be01
73457 --- /dev/null
73458 +++ b/grsecurity/grsec_chdir.c
73459 @@ -0,0 +1,19 @@
73460 +#include <linux/kernel.h>
73461 +#include <linux/sched.h>
73462 +#include <linux/fs.h>
73463 +#include <linux/file.h>
73464 +#include <linux/grsecurity.h>
73465 +#include <linux/grinternal.h>
73466 +
73467 +void
73468 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
73469 +{
73470 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
73471 + if ((grsec_enable_chdir && grsec_enable_group &&
73472 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
73473 + !grsec_enable_group)) {
73474 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
73475 + }
73476 +#endif
73477 + return;
73478 +}
73479 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
73480 new file mode 100644
73481 index 0000000..baa635c
73482 --- /dev/null
73483 +++ b/grsecurity/grsec_chroot.c
73484 @@ -0,0 +1,387 @@
73485 +#include <linux/kernel.h>
73486 +#include <linux/module.h>
73487 +#include <linux/sched.h>
73488 +#include <linux/file.h>
73489 +#include <linux/fs.h>
73490 +#include <linux/mount.h>
73491 +#include <linux/types.h>
73492 +#include "../fs/mount.h"
73493 +#include <linux/grsecurity.h>
73494 +#include <linux/grinternal.h>
73495 +
73496 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
73497 +int gr_init_ran;
73498 +#endif
73499 +
73500 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
73501 +{
73502 +#ifdef CONFIG_GRKERNSEC
73503 + if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
73504 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
73505 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
73506 + && gr_init_ran
73507 +#endif
73508 + )
73509 + task->gr_is_chrooted = 1;
73510 + else {
73511 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
73512 + if (task_pid_nr(task) == 1 && !gr_init_ran)
73513 + gr_init_ran = 1;
73514 +#endif
73515 + task->gr_is_chrooted = 0;
73516 + }
73517 +
73518 + task->gr_chroot_dentry = path->dentry;
73519 +#endif
73520 + return;
73521 +}
73522 +
73523 +void gr_clear_chroot_entries(struct task_struct *task)
73524 +{
73525 +#ifdef CONFIG_GRKERNSEC
73526 + task->gr_is_chrooted = 0;
73527 + task->gr_chroot_dentry = NULL;
73528 +#endif
73529 + return;
73530 +}
73531 +
73532 +int
73533 +gr_handle_chroot_unix(const pid_t pid)
73534 +{
73535 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
73536 + struct task_struct *p;
73537 +
73538 + if (unlikely(!grsec_enable_chroot_unix))
73539 + return 1;
73540 +
73541 + if (likely(!proc_is_chrooted(current)))
73542 + return 1;
73543 +
73544 + rcu_read_lock();
73545 + read_lock(&tasklist_lock);
73546 + p = find_task_by_vpid_unrestricted(pid);
73547 + if (unlikely(p && !have_same_root(current, p))) {
73548 + read_unlock(&tasklist_lock);
73549 + rcu_read_unlock();
73550 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
73551 + return 0;
73552 + }
73553 + read_unlock(&tasklist_lock);
73554 + rcu_read_unlock();
73555 +#endif
73556 + return 1;
73557 +}
73558 +
73559 +int
73560 +gr_handle_chroot_nice(void)
73561 +{
73562 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
73563 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
73564 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
73565 + return -EPERM;
73566 + }
73567 +#endif
73568 + return 0;
73569 +}
73570 +
73571 +int
73572 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
73573 +{
73574 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
73575 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
73576 + && proc_is_chrooted(current)) {
73577 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
73578 + return -EACCES;
73579 + }
73580 +#endif
73581 + return 0;
73582 +}
73583 +
73584 +int
73585 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
73586 +{
73587 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
73588 + struct task_struct *p;
73589 + int ret = 0;
73590 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
73591 + return ret;
73592 +
73593 + read_lock(&tasklist_lock);
73594 + do_each_pid_task(pid, type, p) {
73595 + if (!have_same_root(current, p)) {
73596 + ret = 1;
73597 + goto out;
73598 + }
73599 + } while_each_pid_task(pid, type, p);
73600 +out:
73601 + read_unlock(&tasklist_lock);
73602 + return ret;
73603 +#endif
73604 + return 0;
73605 +}
73606 +
73607 +int
73608 +gr_pid_is_chrooted(struct task_struct *p)
73609 +{
73610 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
73611 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
73612 + return 0;
73613 +
73614 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
73615 + !have_same_root(current, p)) {
73616 + return 1;
73617 + }
73618 +#endif
73619 + return 0;
73620 +}
73621 +
73622 +EXPORT_SYMBOL_GPL(gr_pid_is_chrooted);
73623 +
73624 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
73625 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
73626 +{
73627 + struct path path, currentroot;
73628 + int ret = 0;
73629 +
73630 + path.dentry = (struct dentry *)u_dentry;
73631 + path.mnt = (struct vfsmount *)u_mnt;
73632 + get_fs_root(current->fs, &currentroot);
73633 + if (path_is_under(&path, &currentroot))
73634 + ret = 1;
73635 + path_put(&currentroot);
73636 +
73637 + return ret;
73638 +}
73639 +#endif
73640 +
73641 +int
73642 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
73643 +{
73644 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
73645 + if (!grsec_enable_chroot_fchdir)
73646 + return 1;
73647 +
73648 + if (!proc_is_chrooted(current))
73649 + return 1;
73650 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
73651 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
73652 + return 0;
73653 + }
73654 +#endif
73655 + return 1;
73656 +}
73657 +
73658 +int
73659 +gr_chroot_fhandle(void)
73660 +{
73661 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
73662 + if (!grsec_enable_chroot_fchdir)
73663 + return 1;
73664 +
73665 + if (!proc_is_chrooted(current))
73666 + return 1;
73667 + else {
73668 + gr_log_noargs(GR_DONT_AUDIT, GR_CHROOT_FHANDLE_MSG);
73669 + return 0;
73670 + }
73671 +#endif
73672 + return 1;
73673 +}
73674 +
73675 +int
73676 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
73677 + const time_t shm_createtime)
73678 +{
73679 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
73680 + struct task_struct *p;
73681 + time_t starttime;
73682 +
73683 + if (unlikely(!grsec_enable_chroot_shmat))
73684 + return 1;
73685 +
73686 + if (likely(!proc_is_chrooted(current)))
73687 + return 1;
73688 +
73689 + rcu_read_lock();
73690 + read_lock(&tasklist_lock);
73691 +
73692 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
73693 + starttime = p->start_time.tv_sec;
73694 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
73695 + if (have_same_root(current, p)) {
73696 + goto allow;
73697 + } else {
73698 + read_unlock(&tasklist_lock);
73699 + rcu_read_unlock();
73700 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
73701 + return 0;
73702 + }
73703 + }
73704 + /* creator exited, pid reuse, fall through to next check */
73705 + }
73706 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
73707 + if (unlikely(!have_same_root(current, p))) {
73708 + read_unlock(&tasklist_lock);
73709 + rcu_read_unlock();
73710 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
73711 + return 0;
73712 + }
73713 + }
73714 +
73715 +allow:
73716 + read_unlock(&tasklist_lock);
73717 + rcu_read_unlock();
73718 +#endif
73719 + return 1;
73720 +}
73721 +
73722 +void
73723 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
73724 +{
73725 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
73726 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
73727 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
73728 +#endif
73729 + return;
73730 +}
73731 +
73732 +int
73733 +gr_handle_chroot_mknod(const struct dentry *dentry,
73734 + const struct vfsmount *mnt, const int mode)
73735 +{
73736 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
73737 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
73738 + proc_is_chrooted(current)) {
73739 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
73740 + return -EPERM;
73741 + }
73742 +#endif
73743 + return 0;
73744 +}
73745 +
73746 +int
73747 +gr_handle_chroot_mount(const struct dentry *dentry,
73748 + const struct vfsmount *mnt, const char *dev_name)
73749 +{
73750 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
73751 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
73752 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
73753 + return -EPERM;
73754 + }
73755 +#endif
73756 + return 0;
73757 +}
73758 +
73759 +int
73760 +gr_handle_chroot_pivot(void)
73761 +{
73762 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
73763 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
73764 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
73765 + return -EPERM;
73766 + }
73767 +#endif
73768 + return 0;
73769 +}
73770 +
73771 +int
73772 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
73773 +{
73774 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
73775 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
73776 + !gr_is_outside_chroot(dentry, mnt)) {
73777 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
73778 + return -EPERM;
73779 + }
73780 +#endif
73781 + return 0;
73782 +}
73783 +
73784 +extern const char *captab_log[];
73785 +extern int captab_log_entries;
73786 +
73787 +int
73788 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
73789 +{
73790 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73791 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
73792 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
73793 + if (cap_raised(chroot_caps, cap)) {
73794 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
73795 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
73796 + }
73797 + return 0;
73798 + }
73799 + }
73800 +#endif
73801 + return 1;
73802 +}
73803 +
73804 +int
73805 +gr_chroot_is_capable(const int cap)
73806 +{
73807 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73808 + return gr_task_chroot_is_capable(current, current_cred(), cap);
73809 +#endif
73810 + return 1;
73811 +}
73812 +
73813 +int
73814 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
73815 +{
73816 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73817 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
73818 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
73819 + if (cap_raised(chroot_caps, cap)) {
73820 + return 0;
73821 + }
73822 + }
73823 +#endif
73824 + return 1;
73825 +}
73826 +
73827 +int
73828 +gr_chroot_is_capable_nolog(const int cap)
73829 +{
73830 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73831 + return gr_task_chroot_is_capable_nolog(current, cap);
73832 +#endif
73833 + return 1;
73834 +}
73835 +
73836 +int
73837 +gr_handle_chroot_sysctl(const int op)
73838 +{
73839 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
73840 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
73841 + proc_is_chrooted(current))
73842 + return -EACCES;
73843 +#endif
73844 + return 0;
73845 +}
73846 +
73847 +void
73848 +gr_handle_chroot_chdir(const struct path *path)
73849 +{
73850 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
73851 + if (grsec_enable_chroot_chdir)
73852 + set_fs_pwd(current->fs, path);
73853 +#endif
73854 + return;
73855 +}
73856 +
73857 +int
73858 +gr_handle_chroot_chmod(const struct dentry *dentry,
73859 + const struct vfsmount *mnt, const int mode)
73860 +{
73861 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
73862 + /* allow chmod +s on directories, but not files */
73863 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
73864 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
73865 + proc_is_chrooted(current)) {
73866 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
73867 + return -EPERM;
73868 + }
73869 +#endif
73870 + return 0;
73871 +}
73872 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
73873 new file mode 100644
73874 index 0000000..de31e65
73875 --- /dev/null
73876 +++ b/grsecurity/grsec_disabled.c
73877 @@ -0,0 +1,434 @@
73878 +#include <linux/kernel.h>
73879 +#include <linux/module.h>
73880 +#include <linux/sched.h>
73881 +#include <linux/file.h>
73882 +#include <linux/fs.h>
73883 +#include <linux/kdev_t.h>
73884 +#include <linux/net.h>
73885 +#include <linux/in.h>
73886 +#include <linux/ip.h>
73887 +#include <linux/skbuff.h>
73888 +#include <linux/sysctl.h>
73889 +
73890 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
73891 +void
73892 +pax_set_initial_flags(struct linux_binprm *bprm)
73893 +{
73894 + return;
73895 +}
73896 +#endif
73897 +
73898 +#ifdef CONFIG_SYSCTL
73899 +__u32
73900 +gr_handle_sysctl(const struct ctl_table * table, const int op)
73901 +{
73902 + return 0;
73903 +}
73904 +#endif
73905 +
73906 +#ifdef CONFIG_TASKSTATS
73907 +int gr_is_taskstats_denied(int pid)
73908 +{
73909 + return 0;
73910 +}
73911 +#endif
73912 +
73913 +int
73914 +gr_acl_is_enabled(void)
73915 +{
73916 + return 0;
73917 +}
73918 +
73919 +void
73920 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
73921 +{
73922 + return;
73923 +}
73924 +
73925 +int
73926 +gr_handle_rawio(const struct inode *inode)
73927 +{
73928 + return 0;
73929 +}
73930 +
73931 +void
73932 +gr_acl_handle_psacct(struct task_struct *task, const long code)
73933 +{
73934 + return;
73935 +}
73936 +
73937 +int
73938 +gr_handle_ptrace(struct task_struct *task, const long request)
73939 +{
73940 + return 0;
73941 +}
73942 +
73943 +int
73944 +gr_handle_proc_ptrace(struct task_struct *task)
73945 +{
73946 + return 0;
73947 +}
73948 +
73949 +int
73950 +gr_set_acls(const int type)
73951 +{
73952 + return 0;
73953 +}
73954 +
73955 +int
73956 +gr_check_hidden_task(const struct task_struct *tsk)
73957 +{
73958 + return 0;
73959 +}
73960 +
73961 +int
73962 +gr_check_protected_task(const struct task_struct *task)
73963 +{
73964 + return 0;
73965 +}
73966 +
73967 +int
73968 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
73969 +{
73970 + return 0;
73971 +}
73972 +
73973 +void
73974 +gr_copy_label(struct task_struct *tsk)
73975 +{
73976 + return;
73977 +}
73978 +
73979 +void
73980 +gr_set_pax_flags(struct task_struct *task)
73981 +{
73982 + return;
73983 +}
73984 +
73985 +int
73986 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
73987 + const int unsafe_share)
73988 +{
73989 + return 0;
73990 +}
73991 +
73992 +void
73993 +gr_handle_delete(const ino_t ino, const dev_t dev)
73994 +{
73995 + return;
73996 +}
73997 +
73998 +void
73999 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
74000 +{
74001 + return;
74002 +}
74003 +
74004 +void
74005 +gr_handle_crash(struct task_struct *task, const int sig)
74006 +{
74007 + return;
74008 +}
74009 +
74010 +int
74011 +gr_check_crash_exec(const struct file *filp)
74012 +{
74013 + return 0;
74014 +}
74015 +
74016 +int
74017 +gr_check_crash_uid(const kuid_t uid)
74018 +{
74019 + return 0;
74020 +}
74021 +
74022 +void
74023 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
74024 + struct dentry *old_dentry,
74025 + struct dentry *new_dentry,
74026 + struct vfsmount *mnt, const __u8 replace, unsigned int flags)
74027 +{
74028 + return;
74029 +}
74030 +
74031 +int
74032 +gr_search_socket(const int family, const int type, const int protocol)
74033 +{
74034 + return 1;
74035 +}
74036 +
74037 +int
74038 +gr_search_connectbind(const int mode, const struct socket *sock,
74039 + const struct sockaddr_in *addr)
74040 +{
74041 + return 0;
74042 +}
74043 +
74044 +void
74045 +gr_handle_alertkill(struct task_struct *task)
74046 +{
74047 + return;
74048 +}
74049 +
74050 +__u32
74051 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
74052 +{
74053 + return 1;
74054 +}
74055 +
74056 +__u32
74057 +gr_acl_handle_hidden_file(const struct dentry * dentry,
74058 + const struct vfsmount * mnt)
74059 +{
74060 + return 1;
74061 +}
74062 +
74063 +__u32
74064 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
74065 + int acc_mode)
74066 +{
74067 + return 1;
74068 +}
74069 +
74070 +__u32
74071 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
74072 +{
74073 + return 1;
74074 +}
74075 +
74076 +__u32
74077 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
74078 +{
74079 + return 1;
74080 +}
74081 +
74082 +int
74083 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
74084 + unsigned int *vm_flags)
74085 +{
74086 + return 1;
74087 +}
74088 +
74089 +__u32
74090 +gr_acl_handle_truncate(const struct dentry * dentry,
74091 + const struct vfsmount * mnt)
74092 +{
74093 + return 1;
74094 +}
74095 +
74096 +__u32
74097 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
74098 +{
74099 + return 1;
74100 +}
74101 +
74102 +__u32
74103 +gr_acl_handle_access(const struct dentry * dentry,
74104 + const struct vfsmount * mnt, const int fmode)
74105 +{
74106 + return 1;
74107 +}
74108 +
74109 +__u32
74110 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
74111 + umode_t *mode)
74112 +{
74113 + return 1;
74114 +}
74115 +
74116 +__u32
74117 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
74118 +{
74119 + return 1;
74120 +}
74121 +
74122 +__u32
74123 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
74124 +{
74125 + return 1;
74126 +}
74127 +
74128 +__u32
74129 +gr_acl_handle_removexattr(const struct dentry * dentry, const struct vfsmount * mnt)
74130 +{
74131 + return 1;
74132 +}
74133 +
74134 +void
74135 +grsecurity_init(void)
74136 +{
74137 + return;
74138 +}
74139 +
74140 +umode_t gr_acl_umask(void)
74141 +{
74142 + return 0;
74143 +}
74144 +
74145 +__u32
74146 +gr_acl_handle_mknod(const struct dentry * new_dentry,
74147 + const struct dentry * parent_dentry,
74148 + const struct vfsmount * parent_mnt,
74149 + const int mode)
74150 +{
74151 + return 1;
74152 +}
74153 +
74154 +__u32
74155 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
74156 + const struct dentry * parent_dentry,
74157 + const struct vfsmount * parent_mnt)
74158 +{
74159 + return 1;
74160 +}
74161 +
74162 +__u32
74163 +gr_acl_handle_symlink(const struct dentry * new_dentry,
74164 + const struct dentry * parent_dentry,
74165 + const struct vfsmount * parent_mnt, const struct filename *from)
74166 +{
74167 + return 1;
74168 +}
74169 +
74170 +__u32
74171 +gr_acl_handle_link(const struct dentry * new_dentry,
74172 + const struct dentry * parent_dentry,
74173 + const struct vfsmount * parent_mnt,
74174 + const struct dentry * old_dentry,
74175 + const struct vfsmount * old_mnt, const struct filename *to)
74176 +{
74177 + return 1;
74178 +}
74179 +
74180 +int
74181 +gr_acl_handle_rename(const struct dentry *new_dentry,
74182 + const struct dentry *parent_dentry,
74183 + const struct vfsmount *parent_mnt,
74184 + const struct dentry *old_dentry,
74185 + const struct inode *old_parent_inode,
74186 + const struct vfsmount *old_mnt, const struct filename *newname,
74187 + unsigned int flags)
74188 +{
74189 + return 0;
74190 +}
74191 +
74192 +int
74193 +gr_acl_handle_filldir(const struct file *file, const char *name,
74194 + const int namelen, const ino_t ino)
74195 +{
74196 + return 1;
74197 +}
74198 +
74199 +int
74200 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
74201 + const time_t shm_createtime, const kuid_t cuid, const int shmid)
74202 +{
74203 + return 1;
74204 +}
74205 +
74206 +int
74207 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
74208 +{
74209 + return 0;
74210 +}
74211 +
74212 +int
74213 +gr_search_accept(const struct socket *sock)
74214 +{
74215 + return 0;
74216 +}
74217 +
74218 +int
74219 +gr_search_listen(const struct socket *sock)
74220 +{
74221 + return 0;
74222 +}
74223 +
74224 +int
74225 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
74226 +{
74227 + return 0;
74228 +}
74229 +
74230 +__u32
74231 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
74232 +{
74233 + return 1;
74234 +}
74235 +
74236 +__u32
74237 +gr_acl_handle_creat(const struct dentry * dentry,
74238 + const struct dentry * p_dentry,
74239 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
74240 + const int imode)
74241 +{
74242 + return 1;
74243 +}
74244 +
74245 +void
74246 +gr_acl_handle_exit(void)
74247 +{
74248 + return;
74249 +}
74250 +
74251 +int
74252 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
74253 +{
74254 + return 1;
74255 +}
74256 +
74257 +void
74258 +gr_set_role_label(const kuid_t uid, const kgid_t gid)
74259 +{
74260 + return;
74261 +}
74262 +
74263 +int
74264 +gr_acl_handle_procpidmem(const struct task_struct *task)
74265 +{
74266 + return 0;
74267 +}
74268 +
74269 +int
74270 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
74271 +{
74272 + return 0;
74273 +}
74274 +
74275 +int
74276 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
74277 +{
74278 + return 0;
74279 +}
74280 +
74281 +int
74282 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
74283 +{
74284 + return 0;
74285 +}
74286 +
74287 +int
74288 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
74289 +{
74290 + return 0;
74291 +}
74292 +
74293 +int gr_acl_enable_at_secure(void)
74294 +{
74295 + return 0;
74296 +}
74297 +
74298 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
74299 +{
74300 + return dentry->d_sb->s_dev;
74301 +}
74302 +
74303 +void gr_put_exec_file(struct task_struct *task)
74304 +{
74305 + return;
74306 +}
74307 +
74308 +#ifdef CONFIG_SECURITY
74309 +EXPORT_SYMBOL_GPL(gr_check_user_change);
74310 +EXPORT_SYMBOL_GPL(gr_check_group_change);
74311 +#endif
74312 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
74313 new file mode 100644
74314 index 0000000..f35f454
74315 --- /dev/null
74316 +++ b/grsecurity/grsec_exec.c
74317 @@ -0,0 +1,187 @@
74318 +#include <linux/kernel.h>
74319 +#include <linux/sched.h>
74320 +#include <linux/file.h>
74321 +#include <linux/binfmts.h>
74322 +#include <linux/fs.h>
74323 +#include <linux/types.h>
74324 +#include <linux/grdefs.h>
74325 +#include <linux/grsecurity.h>
74326 +#include <linux/grinternal.h>
74327 +#include <linux/capability.h>
74328 +#include <linux/module.h>
74329 +#include <linux/compat.h>
74330 +
74331 +#include <asm/uaccess.h>
74332 +
74333 +#ifdef CONFIG_GRKERNSEC_EXECLOG
74334 +static char gr_exec_arg_buf[132];
74335 +static DEFINE_MUTEX(gr_exec_arg_mutex);
74336 +#endif
74337 +
74338 +struct user_arg_ptr {
74339 +#ifdef CONFIG_COMPAT
74340 + bool is_compat;
74341 +#endif
74342 + union {
74343 + const char __user *const __user *native;
74344 +#ifdef CONFIG_COMPAT
74345 + const compat_uptr_t __user *compat;
74346 +#endif
74347 + } ptr;
74348 +};
74349 +
74350 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
74351 +
74352 +void
74353 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
74354 +{
74355 +#ifdef CONFIG_GRKERNSEC_EXECLOG
74356 + char *grarg = gr_exec_arg_buf;
74357 + unsigned int i, x, execlen = 0;
74358 + char c;
74359 +
74360 + if (!((grsec_enable_execlog && grsec_enable_group &&
74361 + in_group_p(grsec_audit_gid))
74362 + || (grsec_enable_execlog && !grsec_enable_group)))
74363 + return;
74364 +
74365 + mutex_lock(&gr_exec_arg_mutex);
74366 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
74367 +
74368 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
74369 + const char __user *p;
74370 + unsigned int len;
74371 +
74372 + p = get_user_arg_ptr(argv, i);
74373 + if (IS_ERR(p))
74374 + goto log;
74375 +
74376 + len = strnlen_user(p, 128 - execlen);
74377 + if (len > 128 - execlen)
74378 + len = 128 - execlen;
74379 + else if (len > 0)
74380 + len--;
74381 + if (copy_from_user(grarg + execlen, p, len))
74382 + goto log;
74383 +
74384 + /* rewrite unprintable characters */
74385 + for (x = 0; x < len; x++) {
74386 + c = *(grarg + execlen + x);
74387 + if (c < 32 || c > 126)
74388 + *(grarg + execlen + x) = ' ';
74389 + }
74390 +
74391 + execlen += len;
74392 + *(grarg + execlen) = ' ';
74393 + *(grarg + execlen + 1) = '\0';
74394 + execlen++;
74395 + }
74396 +
74397 + log:
74398 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
74399 + bprm->file->f_path.mnt, grarg);
74400 + mutex_unlock(&gr_exec_arg_mutex);
74401 +#endif
74402 + return;
74403 +}
74404 +
74405 +#ifdef CONFIG_GRKERNSEC
74406 +extern int gr_acl_is_capable(const int cap);
74407 +extern int gr_acl_is_capable_nolog(const int cap);
74408 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
74409 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
74410 +extern int gr_chroot_is_capable(const int cap);
74411 +extern int gr_chroot_is_capable_nolog(const int cap);
74412 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
74413 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
74414 +#endif
74415 +
74416 +const char *captab_log[] = {
74417 + "CAP_CHOWN",
74418 + "CAP_DAC_OVERRIDE",
74419 + "CAP_DAC_READ_SEARCH",
74420 + "CAP_FOWNER",
74421 + "CAP_FSETID",
74422 + "CAP_KILL",
74423 + "CAP_SETGID",
74424 + "CAP_SETUID",
74425 + "CAP_SETPCAP",
74426 + "CAP_LINUX_IMMUTABLE",
74427 + "CAP_NET_BIND_SERVICE",
74428 + "CAP_NET_BROADCAST",
74429 + "CAP_NET_ADMIN",
74430 + "CAP_NET_RAW",
74431 + "CAP_IPC_LOCK",
74432 + "CAP_IPC_OWNER",
74433 + "CAP_SYS_MODULE",
74434 + "CAP_SYS_RAWIO",
74435 + "CAP_SYS_CHROOT",
74436 + "CAP_SYS_PTRACE",
74437 + "CAP_SYS_PACCT",
74438 + "CAP_SYS_ADMIN",
74439 + "CAP_SYS_BOOT",
74440 + "CAP_SYS_NICE",
74441 + "CAP_SYS_RESOURCE",
74442 + "CAP_SYS_TIME",
74443 + "CAP_SYS_TTY_CONFIG",
74444 + "CAP_MKNOD",
74445 + "CAP_LEASE",
74446 + "CAP_AUDIT_WRITE",
74447 + "CAP_AUDIT_CONTROL",
74448 + "CAP_SETFCAP",
74449 + "CAP_MAC_OVERRIDE",
74450 + "CAP_MAC_ADMIN",
74451 + "CAP_SYSLOG",
74452 + "CAP_WAKE_ALARM"
74453 +};
74454 +
74455 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
74456 +
74457 +int gr_is_capable(const int cap)
74458 +{
74459 +#ifdef CONFIG_GRKERNSEC
74460 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
74461 + return 1;
74462 + return 0;
74463 +#else
74464 + return 1;
74465 +#endif
74466 +}
74467 +
74468 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
74469 +{
74470 +#ifdef CONFIG_GRKERNSEC
74471 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
74472 + return 1;
74473 + return 0;
74474 +#else
74475 + return 1;
74476 +#endif
74477 +}
74478 +
74479 +int gr_is_capable_nolog(const int cap)
74480 +{
74481 +#ifdef CONFIG_GRKERNSEC
74482 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
74483 + return 1;
74484 + return 0;
74485 +#else
74486 + return 1;
74487 +#endif
74488 +}
74489 +
74490 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
74491 +{
74492 +#ifdef CONFIG_GRKERNSEC
74493 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
74494 + return 1;
74495 + return 0;
74496 +#else
74497 + return 1;
74498 +#endif
74499 +}
74500 +
74501 +EXPORT_SYMBOL_GPL(gr_is_capable);
74502 +EXPORT_SYMBOL_GPL(gr_is_capable_nolog);
74503 +EXPORT_SYMBOL_GPL(gr_task_is_capable);
74504 +EXPORT_SYMBOL_GPL(gr_task_is_capable_nolog);
74505 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
74506 new file mode 100644
74507 index 0000000..06cc6ea
74508 --- /dev/null
74509 +++ b/grsecurity/grsec_fifo.c
74510 @@ -0,0 +1,24 @@
74511 +#include <linux/kernel.h>
74512 +#include <linux/sched.h>
74513 +#include <linux/fs.h>
74514 +#include <linux/file.h>
74515 +#include <linux/grinternal.h>
74516 +
74517 +int
74518 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
74519 + const struct dentry *dir, const int flag, const int acc_mode)
74520 +{
74521 +#ifdef CONFIG_GRKERNSEC_FIFO
74522 + const struct cred *cred = current_cred();
74523 +
74524 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
74525 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
74526 + !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
74527 + !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
74528 + if (!inode_permission(dentry->d_inode, acc_mode))
74529 + 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));
74530 + return -EACCES;
74531 + }
74532 +#endif
74533 + return 0;
74534 +}
74535 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
74536 new file mode 100644
74537 index 0000000..8ca18bf
74538 --- /dev/null
74539 +++ b/grsecurity/grsec_fork.c
74540 @@ -0,0 +1,23 @@
74541 +#include <linux/kernel.h>
74542 +#include <linux/sched.h>
74543 +#include <linux/grsecurity.h>
74544 +#include <linux/grinternal.h>
74545 +#include <linux/errno.h>
74546 +
74547 +void
74548 +gr_log_forkfail(const int retval)
74549 +{
74550 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
74551 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
74552 + switch (retval) {
74553 + case -EAGAIN:
74554 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
74555 + break;
74556 + case -ENOMEM:
74557 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
74558 + break;
74559 + }
74560 + }
74561 +#endif
74562 + return;
74563 +}
74564 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
74565 new file mode 100644
74566 index 0000000..ae6c028
74567 --- /dev/null
74568 +++ b/grsecurity/grsec_init.c
74569 @@ -0,0 +1,272 @@
74570 +#include <linux/kernel.h>
74571 +#include <linux/sched.h>
74572 +#include <linux/mm.h>
74573 +#include <linux/gracl.h>
74574 +#include <linux/slab.h>
74575 +#include <linux/vmalloc.h>
74576 +#include <linux/percpu.h>
74577 +#include <linux/module.h>
74578 +
74579 +int grsec_enable_ptrace_readexec;
74580 +int grsec_enable_setxid;
74581 +int grsec_enable_symlinkown;
74582 +kgid_t grsec_symlinkown_gid;
74583 +int grsec_enable_brute;
74584 +int grsec_enable_link;
74585 +int grsec_enable_dmesg;
74586 +int grsec_enable_harden_ptrace;
74587 +int grsec_enable_harden_ipc;
74588 +int grsec_enable_fifo;
74589 +int grsec_enable_execlog;
74590 +int grsec_enable_signal;
74591 +int grsec_enable_forkfail;
74592 +int grsec_enable_audit_ptrace;
74593 +int grsec_enable_time;
74594 +int grsec_enable_group;
74595 +kgid_t grsec_audit_gid;
74596 +int grsec_enable_chdir;
74597 +int grsec_enable_mount;
74598 +int grsec_enable_rofs;
74599 +int grsec_deny_new_usb;
74600 +int grsec_enable_chroot_findtask;
74601 +int grsec_enable_chroot_mount;
74602 +int grsec_enable_chroot_shmat;
74603 +int grsec_enable_chroot_fchdir;
74604 +int grsec_enable_chroot_double;
74605 +int grsec_enable_chroot_pivot;
74606 +int grsec_enable_chroot_chdir;
74607 +int grsec_enable_chroot_chmod;
74608 +int grsec_enable_chroot_mknod;
74609 +int grsec_enable_chroot_nice;
74610 +int grsec_enable_chroot_execlog;
74611 +int grsec_enable_chroot_caps;
74612 +int grsec_enable_chroot_sysctl;
74613 +int grsec_enable_chroot_unix;
74614 +int grsec_enable_tpe;
74615 +kgid_t grsec_tpe_gid;
74616 +int grsec_enable_blackhole;
74617 +#ifdef CONFIG_IPV6_MODULE
74618 +EXPORT_SYMBOL_GPL(grsec_enable_blackhole);
74619 +#endif
74620 +int grsec_lastack_retries;
74621 +int grsec_enable_tpe_all;
74622 +int grsec_enable_tpe_invert;
74623 +int grsec_enable_socket_all;
74624 +kgid_t grsec_socket_all_gid;
74625 +int grsec_enable_socket_client;
74626 +kgid_t grsec_socket_client_gid;
74627 +int grsec_enable_socket_server;
74628 +kgid_t grsec_socket_server_gid;
74629 +int grsec_resource_logging;
74630 +int grsec_disable_privio;
74631 +int grsec_enable_log_rwxmaps;
74632 +int grsec_lock;
74633 +
74634 +DEFINE_SPINLOCK(grsec_alert_lock);
74635 +unsigned long grsec_alert_wtime = 0;
74636 +unsigned long grsec_alert_fyet = 0;
74637 +
74638 +DEFINE_SPINLOCK(grsec_audit_lock);
74639 +
74640 +DEFINE_RWLOCK(grsec_exec_file_lock);
74641 +
74642 +char *gr_shared_page[4];
74643 +
74644 +char *gr_alert_log_fmt;
74645 +char *gr_audit_log_fmt;
74646 +char *gr_alert_log_buf;
74647 +char *gr_audit_log_buf;
74648 +
74649 +void __init
74650 +grsecurity_init(void)
74651 +{
74652 + int j;
74653 + /* create the per-cpu shared pages */
74654 +
74655 +#ifdef CONFIG_X86
74656 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
74657 +#endif
74658 +
74659 + for (j = 0; j < 4; j++) {
74660 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
74661 + if (gr_shared_page[j] == NULL) {
74662 + panic("Unable to allocate grsecurity shared page");
74663 + return;
74664 + }
74665 + }
74666 +
74667 + /* allocate log buffers */
74668 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
74669 + if (!gr_alert_log_fmt) {
74670 + panic("Unable to allocate grsecurity alert log format buffer");
74671 + return;
74672 + }
74673 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
74674 + if (!gr_audit_log_fmt) {
74675 + panic("Unable to allocate grsecurity audit log format buffer");
74676 + return;
74677 + }
74678 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
74679 + if (!gr_alert_log_buf) {
74680 + panic("Unable to allocate grsecurity alert log buffer");
74681 + return;
74682 + }
74683 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
74684 + if (!gr_audit_log_buf) {
74685 + panic("Unable to allocate grsecurity audit log buffer");
74686 + return;
74687 + }
74688 +
74689 +#ifdef CONFIG_GRKERNSEC_IO
74690 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
74691 + grsec_disable_privio = 1;
74692 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
74693 + grsec_disable_privio = 1;
74694 +#else
74695 + grsec_disable_privio = 0;
74696 +#endif
74697 +#endif
74698 +
74699 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
74700 + /* for backward compatibility, tpe_invert always defaults to on if
74701 + enabled in the kernel
74702 + */
74703 + grsec_enable_tpe_invert = 1;
74704 +#endif
74705 +
74706 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
74707 +#ifndef CONFIG_GRKERNSEC_SYSCTL
74708 + grsec_lock = 1;
74709 +#endif
74710 +
74711 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74712 + grsec_enable_log_rwxmaps = 1;
74713 +#endif
74714 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
74715 + grsec_enable_group = 1;
74716 + grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
74717 +#endif
74718 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
74719 + grsec_enable_ptrace_readexec = 1;
74720 +#endif
74721 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
74722 + grsec_enable_chdir = 1;
74723 +#endif
74724 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
74725 + grsec_enable_harden_ptrace = 1;
74726 +#endif
74727 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
74728 + grsec_enable_harden_ipc = 1;
74729 +#endif
74730 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
74731 + grsec_enable_mount = 1;
74732 +#endif
74733 +#ifdef CONFIG_GRKERNSEC_LINK
74734 + grsec_enable_link = 1;
74735 +#endif
74736 +#ifdef CONFIG_GRKERNSEC_BRUTE
74737 + grsec_enable_brute = 1;
74738 +#endif
74739 +#ifdef CONFIG_GRKERNSEC_DMESG
74740 + grsec_enable_dmesg = 1;
74741 +#endif
74742 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74743 + grsec_enable_blackhole = 1;
74744 + grsec_lastack_retries = 4;
74745 +#endif
74746 +#ifdef CONFIG_GRKERNSEC_FIFO
74747 + grsec_enable_fifo = 1;
74748 +#endif
74749 +#ifdef CONFIG_GRKERNSEC_EXECLOG
74750 + grsec_enable_execlog = 1;
74751 +#endif
74752 +#ifdef CONFIG_GRKERNSEC_SETXID
74753 + grsec_enable_setxid = 1;
74754 +#endif
74755 +#ifdef CONFIG_GRKERNSEC_SIGNAL
74756 + grsec_enable_signal = 1;
74757 +#endif
74758 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
74759 + grsec_enable_forkfail = 1;
74760 +#endif
74761 +#ifdef CONFIG_GRKERNSEC_TIME
74762 + grsec_enable_time = 1;
74763 +#endif
74764 +#ifdef CONFIG_GRKERNSEC_RESLOG
74765 + grsec_resource_logging = 1;
74766 +#endif
74767 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
74768 + grsec_enable_chroot_findtask = 1;
74769 +#endif
74770 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
74771 + grsec_enable_chroot_unix = 1;
74772 +#endif
74773 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
74774 + grsec_enable_chroot_mount = 1;
74775 +#endif
74776 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
74777 + grsec_enable_chroot_fchdir = 1;
74778 +#endif
74779 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
74780 + grsec_enable_chroot_shmat = 1;
74781 +#endif
74782 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
74783 + grsec_enable_audit_ptrace = 1;
74784 +#endif
74785 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
74786 + grsec_enable_chroot_double = 1;
74787 +#endif
74788 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
74789 + grsec_enable_chroot_pivot = 1;
74790 +#endif
74791 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
74792 + grsec_enable_chroot_chdir = 1;
74793 +#endif
74794 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
74795 + grsec_enable_chroot_chmod = 1;
74796 +#endif
74797 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
74798 + grsec_enable_chroot_mknod = 1;
74799 +#endif
74800 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
74801 + grsec_enable_chroot_nice = 1;
74802 +#endif
74803 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
74804 + grsec_enable_chroot_execlog = 1;
74805 +#endif
74806 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
74807 + grsec_enable_chroot_caps = 1;
74808 +#endif
74809 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
74810 + grsec_enable_chroot_sysctl = 1;
74811 +#endif
74812 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
74813 + grsec_enable_symlinkown = 1;
74814 + grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
74815 +#endif
74816 +#ifdef CONFIG_GRKERNSEC_TPE
74817 + grsec_enable_tpe = 1;
74818 + grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
74819 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
74820 + grsec_enable_tpe_all = 1;
74821 +#endif
74822 +#endif
74823 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
74824 + grsec_enable_socket_all = 1;
74825 + grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
74826 +#endif
74827 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
74828 + grsec_enable_socket_client = 1;
74829 + grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
74830 +#endif
74831 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
74832 + grsec_enable_socket_server = 1;
74833 + grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
74834 +#endif
74835 +#endif
74836 +#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
74837 + grsec_deny_new_usb = 1;
74838 +#endif
74839 +
74840 + return;
74841 +}
74842 diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
74843 new file mode 100644
74844 index 0000000..1773300
74845 --- /dev/null
74846 +++ b/grsecurity/grsec_ipc.c
74847 @@ -0,0 +1,48 @@
74848 +#include <linux/kernel.h>
74849 +#include <linux/mm.h>
74850 +#include <linux/sched.h>
74851 +#include <linux/file.h>
74852 +#include <linux/ipc.h>
74853 +#include <linux/ipc_namespace.h>
74854 +#include <linux/grsecurity.h>
74855 +#include <linux/grinternal.h>
74856 +
74857 +int
74858 +gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
74859 +{
74860 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
74861 + int write;
74862 + int orig_granted_mode;
74863 + kuid_t euid;
74864 + kgid_t egid;
74865 +
74866 + if (!grsec_enable_harden_ipc)
74867 + return 1;
74868 +
74869 + euid = current_euid();
74870 + egid = current_egid();
74871 +
74872 + write = requested_mode & 00002;
74873 + orig_granted_mode = ipcp->mode;
74874 +
74875 + if (uid_eq(euid, ipcp->cuid) || uid_eq(euid, ipcp->uid))
74876 + orig_granted_mode >>= 6;
74877 + else {
74878 + /* if likely wrong permissions, lock to user */
74879 + if (orig_granted_mode & 0007)
74880 + orig_granted_mode = 0;
74881 + /* otherwise do a egid-only check */
74882 + else if (gid_eq(egid, ipcp->cgid) || gid_eq(egid, ipcp->gid))
74883 + orig_granted_mode >>= 3;
74884 + /* otherwise, no access */
74885 + else
74886 + orig_granted_mode = 0;
74887 + }
74888 + if (!(requested_mode & ~granted_mode & 0007) && (requested_mode & ~orig_granted_mode & 0007) &&
74889 + !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
74890 + gr_log_str_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", GR_GLOBAL_UID(ipcp->cuid));
74891 + return 0;
74892 + }
74893 +#endif
74894 + return 1;
74895 +}
74896 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
74897 new file mode 100644
74898 index 0000000..5e05e20
74899 --- /dev/null
74900 +++ b/grsecurity/grsec_link.c
74901 @@ -0,0 +1,58 @@
74902 +#include <linux/kernel.h>
74903 +#include <linux/sched.h>
74904 +#include <linux/fs.h>
74905 +#include <linux/file.h>
74906 +#include <linux/grinternal.h>
74907 +
74908 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
74909 +{
74910 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
74911 + const struct inode *link_inode = link->dentry->d_inode;
74912 +
74913 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
74914 + /* ignore root-owned links, e.g. /proc/self */
74915 + gr_is_global_nonroot(link_inode->i_uid) && target &&
74916 + !uid_eq(link_inode->i_uid, target->i_uid)) {
74917 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
74918 + return 1;
74919 + }
74920 +#endif
74921 + return 0;
74922 +}
74923 +
74924 +int
74925 +gr_handle_follow_link(const struct inode *parent,
74926 + const struct inode *inode,
74927 + const struct dentry *dentry, const struct vfsmount *mnt)
74928 +{
74929 +#ifdef CONFIG_GRKERNSEC_LINK
74930 + const struct cred *cred = current_cred();
74931 +
74932 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
74933 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
74934 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
74935 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
74936 + return -EACCES;
74937 + }
74938 +#endif
74939 + return 0;
74940 +}
74941 +
74942 +int
74943 +gr_handle_hardlink(const struct dentry *dentry,
74944 + const struct vfsmount *mnt,
74945 + struct inode *inode, const int mode, const struct filename *to)
74946 +{
74947 +#ifdef CONFIG_GRKERNSEC_LINK
74948 + const struct cred *cred = current_cred();
74949 +
74950 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
74951 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
74952 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
74953 + !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
74954 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
74955 + return -EPERM;
74956 + }
74957 +#endif
74958 + return 0;
74959 +}
74960 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
74961 new file mode 100644
74962 index 0000000..dbe0a6b
74963 --- /dev/null
74964 +++ b/grsecurity/grsec_log.c
74965 @@ -0,0 +1,341 @@
74966 +#include <linux/kernel.h>
74967 +#include <linux/sched.h>
74968 +#include <linux/file.h>
74969 +#include <linux/tty.h>
74970 +#include <linux/fs.h>
74971 +#include <linux/mm.h>
74972 +#include <linux/grinternal.h>
74973 +
74974 +#ifdef CONFIG_TREE_PREEMPT_RCU
74975 +#define DISABLE_PREEMPT() preempt_disable()
74976 +#define ENABLE_PREEMPT() preempt_enable()
74977 +#else
74978 +#define DISABLE_PREEMPT()
74979 +#define ENABLE_PREEMPT()
74980 +#endif
74981 +
74982 +#define BEGIN_LOCKS(x) \
74983 + DISABLE_PREEMPT(); \
74984 + rcu_read_lock(); \
74985 + read_lock(&tasklist_lock); \
74986 + read_lock(&grsec_exec_file_lock); \
74987 + if (x != GR_DO_AUDIT) \
74988 + spin_lock(&grsec_alert_lock); \
74989 + else \
74990 + spin_lock(&grsec_audit_lock)
74991 +
74992 +#define END_LOCKS(x) \
74993 + if (x != GR_DO_AUDIT) \
74994 + spin_unlock(&grsec_alert_lock); \
74995 + else \
74996 + spin_unlock(&grsec_audit_lock); \
74997 + read_unlock(&grsec_exec_file_lock); \
74998 + read_unlock(&tasklist_lock); \
74999 + rcu_read_unlock(); \
75000 + ENABLE_PREEMPT(); \
75001 + if (x == GR_DONT_AUDIT) \
75002 + gr_handle_alertkill(current)
75003 +
75004 +enum {
75005 + FLOODING,
75006 + NO_FLOODING
75007 +};
75008 +
75009 +extern char *gr_alert_log_fmt;
75010 +extern char *gr_audit_log_fmt;
75011 +extern char *gr_alert_log_buf;
75012 +extern char *gr_audit_log_buf;
75013 +
75014 +static int gr_log_start(int audit)
75015 +{
75016 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
75017 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
75018 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
75019 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
75020 + unsigned long curr_secs = get_seconds();
75021 +
75022 + if (audit == GR_DO_AUDIT)
75023 + goto set_fmt;
75024 +
75025 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
75026 + grsec_alert_wtime = curr_secs;
75027 + grsec_alert_fyet = 0;
75028 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
75029 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
75030 + grsec_alert_fyet++;
75031 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
75032 + grsec_alert_wtime = curr_secs;
75033 + grsec_alert_fyet++;
75034 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
75035 + return FLOODING;
75036 + }
75037 + else return FLOODING;
75038 +
75039 +set_fmt:
75040 +#endif
75041 + memset(buf, 0, PAGE_SIZE);
75042 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
75043 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
75044 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
75045 + } else if (current->signal->curr_ip) {
75046 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
75047 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
75048 + } else if (gr_acl_is_enabled()) {
75049 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
75050 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
75051 + } else {
75052 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
75053 + strcpy(buf, fmt);
75054 + }
75055 +
75056 + return NO_FLOODING;
75057 +}
75058 +
75059 +static void gr_log_middle(int audit, const char *msg, va_list ap)
75060 + __attribute__ ((format (printf, 2, 0)));
75061 +
75062 +static void gr_log_middle(int audit, const char *msg, va_list ap)
75063 +{
75064 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
75065 + unsigned int len = strlen(buf);
75066 +
75067 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
75068 +
75069 + return;
75070 +}
75071 +
75072 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
75073 + __attribute__ ((format (printf, 2, 3)));
75074 +
75075 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
75076 +{
75077 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
75078 + unsigned int len = strlen(buf);
75079 + va_list ap;
75080 +
75081 + va_start(ap, msg);
75082 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
75083 + va_end(ap);
75084 +
75085 + return;
75086 +}
75087 +
75088 +static void gr_log_end(int audit, int append_default)
75089 +{
75090 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
75091 + if (append_default) {
75092 + struct task_struct *task = current;
75093 + struct task_struct *parent = task->real_parent;
75094 + const struct cred *cred = __task_cred(task);
75095 + const struct cred *pcred = __task_cred(parent);
75096 + unsigned int len = strlen(buf);
75097 +
75098 + 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));
75099 + }
75100 +
75101 + printk("%s\n", buf);
75102 +
75103 + return;
75104 +}
75105 +
75106 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
75107 +{
75108 + int logtype;
75109 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
75110 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
75111 + void *voidptr = NULL;
75112 + int num1 = 0, num2 = 0;
75113 + unsigned long ulong1 = 0, ulong2 = 0;
75114 + struct dentry *dentry = NULL;
75115 + struct vfsmount *mnt = NULL;
75116 + struct file *file = NULL;
75117 + struct task_struct *task = NULL;
75118 + struct vm_area_struct *vma = NULL;
75119 + const struct cred *cred, *pcred;
75120 + va_list ap;
75121 +
75122 + BEGIN_LOCKS(audit);
75123 + logtype = gr_log_start(audit);
75124 + if (logtype == FLOODING) {
75125 + END_LOCKS(audit);
75126 + return;
75127 + }
75128 + va_start(ap, argtypes);
75129 + switch (argtypes) {
75130 + case GR_TTYSNIFF:
75131 + task = va_arg(ap, struct task_struct *);
75132 + 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));
75133 + break;
75134 + case GR_SYSCTL_HIDDEN:
75135 + str1 = va_arg(ap, char *);
75136 + gr_log_middle_varargs(audit, msg, result, str1);
75137 + break;
75138 + case GR_RBAC:
75139 + dentry = va_arg(ap, struct dentry *);
75140 + mnt = va_arg(ap, struct vfsmount *);
75141 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
75142 + break;
75143 + case GR_RBAC_STR:
75144 + dentry = va_arg(ap, struct dentry *);
75145 + mnt = va_arg(ap, struct vfsmount *);
75146 + str1 = va_arg(ap, char *);
75147 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
75148 + break;
75149 + case GR_STR_RBAC:
75150 + str1 = va_arg(ap, char *);
75151 + dentry = va_arg(ap, struct dentry *);
75152 + mnt = va_arg(ap, struct vfsmount *);
75153 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
75154 + break;
75155 + case GR_RBAC_MODE2:
75156 + dentry = va_arg(ap, struct dentry *);
75157 + mnt = va_arg(ap, struct vfsmount *);
75158 + str1 = va_arg(ap, char *);
75159 + str2 = va_arg(ap, char *);
75160 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
75161 + break;
75162 + case GR_RBAC_MODE3:
75163 + dentry = va_arg(ap, struct dentry *);
75164 + mnt = va_arg(ap, struct vfsmount *);
75165 + str1 = va_arg(ap, char *);
75166 + str2 = va_arg(ap, char *);
75167 + str3 = va_arg(ap, char *);
75168 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
75169 + break;
75170 + case GR_FILENAME:
75171 + dentry = va_arg(ap, struct dentry *);
75172 + mnt = va_arg(ap, struct vfsmount *);
75173 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
75174 + break;
75175 + case GR_STR_FILENAME:
75176 + str1 = va_arg(ap, char *);
75177 + dentry = va_arg(ap, struct dentry *);
75178 + mnt = va_arg(ap, struct vfsmount *);
75179 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
75180 + break;
75181 + case GR_FILENAME_STR:
75182 + dentry = va_arg(ap, struct dentry *);
75183 + mnt = va_arg(ap, struct vfsmount *);
75184 + str1 = va_arg(ap, char *);
75185 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
75186 + break;
75187 + case GR_FILENAME_TWO_INT:
75188 + dentry = va_arg(ap, struct dentry *);
75189 + mnt = va_arg(ap, struct vfsmount *);
75190 + num1 = va_arg(ap, int);
75191 + num2 = va_arg(ap, int);
75192 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
75193 + break;
75194 + case GR_FILENAME_TWO_INT_STR:
75195 + dentry = va_arg(ap, struct dentry *);
75196 + mnt = va_arg(ap, struct vfsmount *);
75197 + num1 = va_arg(ap, int);
75198 + num2 = va_arg(ap, int);
75199 + str1 = va_arg(ap, char *);
75200 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
75201 + break;
75202 + case GR_TEXTREL:
75203 + file = va_arg(ap, struct file *);
75204 + ulong1 = va_arg(ap, unsigned long);
75205 + ulong2 = va_arg(ap, unsigned long);
75206 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
75207 + break;
75208 + case GR_PTRACE:
75209 + task = va_arg(ap, struct task_struct *);
75210 + 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));
75211 + break;
75212 + case GR_RESOURCE:
75213 + task = va_arg(ap, struct task_struct *);
75214 + cred = __task_cred(task);
75215 + pcred = __task_cred(task->real_parent);
75216 + ulong1 = va_arg(ap, unsigned long);
75217 + str1 = va_arg(ap, char *);
75218 + ulong2 = va_arg(ap, unsigned long);
75219 + 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));
75220 + break;
75221 + case GR_CAP:
75222 + task = va_arg(ap, struct task_struct *);
75223 + cred = __task_cred(task);
75224 + pcred = __task_cred(task->real_parent);
75225 + str1 = va_arg(ap, char *);
75226 + 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));
75227 + break;
75228 + case GR_SIG:
75229 + str1 = va_arg(ap, char *);
75230 + voidptr = va_arg(ap, void *);
75231 + gr_log_middle_varargs(audit, msg, str1, voidptr);
75232 + break;
75233 + case GR_SIG2:
75234 + task = va_arg(ap, struct task_struct *);
75235 + cred = __task_cred(task);
75236 + pcred = __task_cred(task->real_parent);
75237 + num1 = va_arg(ap, int);
75238 + 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));
75239 + break;
75240 + case GR_CRASH1:
75241 + task = va_arg(ap, struct task_struct *);
75242 + cred = __task_cred(task);
75243 + pcred = __task_cred(task->real_parent);
75244 + ulong1 = va_arg(ap, unsigned long);
75245 + 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);
75246 + break;
75247 + case GR_CRASH2:
75248 + task = va_arg(ap, struct task_struct *);
75249 + cred = __task_cred(task);
75250 + pcred = __task_cred(task->real_parent);
75251 + ulong1 = va_arg(ap, unsigned long);
75252 + 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);
75253 + break;
75254 + case GR_RWXMAP:
75255 + file = va_arg(ap, struct file *);
75256 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
75257 + break;
75258 + case GR_RWXMAPVMA:
75259 + vma = va_arg(ap, struct vm_area_struct *);
75260 + if (vma->vm_file)
75261 + str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
75262 + else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
75263 + str1 = "<stack>";
75264 + else if (vma->vm_start <= current->mm->brk &&
75265 + vma->vm_end >= current->mm->start_brk)
75266 + str1 = "<heap>";
75267 + else
75268 + str1 = "<anonymous mapping>";
75269 + gr_log_middle_varargs(audit, msg, str1);
75270 + break;
75271 + case GR_PSACCT:
75272 + {
75273 + unsigned int wday, cday;
75274 + __u8 whr, chr;
75275 + __u8 wmin, cmin;
75276 + __u8 wsec, csec;
75277 + char cur_tty[64] = { 0 };
75278 + char parent_tty[64] = { 0 };
75279 +
75280 + task = va_arg(ap, struct task_struct *);
75281 + wday = va_arg(ap, unsigned int);
75282 + cday = va_arg(ap, unsigned int);
75283 + whr = va_arg(ap, int);
75284 + chr = va_arg(ap, int);
75285 + wmin = va_arg(ap, int);
75286 + cmin = va_arg(ap, int);
75287 + wsec = va_arg(ap, int);
75288 + csec = va_arg(ap, int);
75289 + ulong1 = va_arg(ap, unsigned long);
75290 + cred = __task_cred(task);
75291 + pcred = __task_cred(task->real_parent);
75292 +
75293 + 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));
75294 + }
75295 + break;
75296 + default:
75297 + gr_log_middle(audit, msg, ap);
75298 + }
75299 + va_end(ap);
75300 + // these don't need DEFAULTSECARGS printed on the end
75301 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
75302 + gr_log_end(audit, 0);
75303 + else
75304 + gr_log_end(audit, 1);
75305 + END_LOCKS(audit);
75306 +}
75307 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
75308 new file mode 100644
75309 index 0000000..0e39d8c
75310 --- /dev/null
75311 +++ b/grsecurity/grsec_mem.c
75312 @@ -0,0 +1,48 @@
75313 +#include <linux/kernel.h>
75314 +#include <linux/sched.h>
75315 +#include <linux/mm.h>
75316 +#include <linux/mman.h>
75317 +#include <linux/module.h>
75318 +#include <linux/grinternal.h>
75319 +
75320 +void gr_handle_msr_write(void)
75321 +{
75322 + gr_log_noargs(GR_DONT_AUDIT, GR_MSRWRITE_MSG);
75323 + return;
75324 +}
75325 +EXPORT_SYMBOL_GPL(gr_handle_msr_write);
75326 +
75327 +void
75328 +gr_handle_ioperm(void)
75329 +{
75330 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
75331 + return;
75332 +}
75333 +
75334 +void
75335 +gr_handle_iopl(void)
75336 +{
75337 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
75338 + return;
75339 +}
75340 +
75341 +void
75342 +gr_handle_mem_readwrite(u64 from, u64 to)
75343 +{
75344 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
75345 + return;
75346 +}
75347 +
75348 +void
75349 +gr_handle_vm86(void)
75350 +{
75351 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
75352 + return;
75353 +}
75354 +
75355 +void
75356 +gr_log_badprocpid(const char *entry)
75357 +{
75358 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
75359 + return;
75360 +}
75361 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
75362 new file mode 100644
75363 index 0000000..cd9e124
75364 --- /dev/null
75365 +++ b/grsecurity/grsec_mount.c
75366 @@ -0,0 +1,65 @@
75367 +#include <linux/kernel.h>
75368 +#include <linux/sched.h>
75369 +#include <linux/mount.h>
75370 +#include <linux/major.h>
75371 +#include <linux/grsecurity.h>
75372 +#include <linux/grinternal.h>
75373 +
75374 +void
75375 +gr_log_remount(const char *devname, const int retval)
75376 +{
75377 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75378 + if (grsec_enable_mount && (retval >= 0))
75379 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
75380 +#endif
75381 + return;
75382 +}
75383 +
75384 +void
75385 +gr_log_unmount(const char *devname, const int retval)
75386 +{
75387 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75388 + if (grsec_enable_mount && (retval >= 0))
75389 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
75390 +#endif
75391 + return;
75392 +}
75393 +
75394 +void
75395 +gr_log_mount(const char *from, const char *to, const int retval)
75396 +{
75397 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
75398 + if (grsec_enable_mount && (retval >= 0))
75399 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
75400 +#endif
75401 + return;
75402 +}
75403 +
75404 +int
75405 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
75406 +{
75407 +#ifdef CONFIG_GRKERNSEC_ROFS
75408 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
75409 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
75410 + return -EPERM;
75411 + } else
75412 + return 0;
75413 +#endif
75414 + return 0;
75415 +}
75416 +
75417 +int
75418 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
75419 +{
75420 +#ifdef CONFIG_GRKERNSEC_ROFS
75421 + struct inode *inode = dentry->d_inode;
75422 +
75423 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
75424 + inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR))) {
75425 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
75426 + return -EPERM;
75427 + } else
75428 + return 0;
75429 +#endif
75430 + return 0;
75431 +}
75432 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
75433 new file mode 100644
75434 index 0000000..6ee9d50
75435 --- /dev/null
75436 +++ b/grsecurity/grsec_pax.c
75437 @@ -0,0 +1,45 @@
75438 +#include <linux/kernel.h>
75439 +#include <linux/sched.h>
75440 +#include <linux/mm.h>
75441 +#include <linux/file.h>
75442 +#include <linux/grinternal.h>
75443 +#include <linux/grsecurity.h>
75444 +
75445 +void
75446 +gr_log_textrel(struct vm_area_struct * vma)
75447 +{
75448 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75449 + if (grsec_enable_log_rwxmaps)
75450 + gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
75451 +#endif
75452 + return;
75453 +}
75454 +
75455 +void gr_log_ptgnustack(struct file *file)
75456 +{
75457 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75458 + if (grsec_enable_log_rwxmaps)
75459 + gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
75460 +#endif
75461 + return;
75462 +}
75463 +
75464 +void
75465 +gr_log_rwxmmap(struct file *file)
75466 +{
75467 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75468 + if (grsec_enable_log_rwxmaps)
75469 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
75470 +#endif
75471 + return;
75472 +}
75473 +
75474 +void
75475 +gr_log_rwxmprotect(struct vm_area_struct *vma)
75476 +{
75477 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
75478 + if (grsec_enable_log_rwxmaps)
75479 + gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
75480 +#endif
75481 + return;
75482 +}
75483 diff --git a/grsecurity/grsec_proc.c b/grsecurity/grsec_proc.c
75484 new file mode 100644
75485 index 0000000..2005a3a
75486 --- /dev/null
75487 +++ b/grsecurity/grsec_proc.c
75488 @@ -0,0 +1,20 @@
75489 +#include <linux/kernel.h>
75490 +#include <linux/sched.h>
75491 +#include <linux/grsecurity.h>
75492 +#include <linux/grinternal.h>
75493 +
75494 +int gr_proc_is_restricted(void)
75495 +{
75496 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75497 + const struct cred *cred = current_cred();
75498 +#endif
75499 +
75500 +#ifdef CONFIG_GRKERNSEC_PROC_USER
75501 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
75502 + return -EACCES;
75503 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75504 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
75505 + return -EACCES;
75506 +#endif
75507 + return 0;
75508 +}
75509 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
75510 new file mode 100644
75511 index 0000000..f7f29aa
75512 --- /dev/null
75513 +++ b/grsecurity/grsec_ptrace.c
75514 @@ -0,0 +1,30 @@
75515 +#include <linux/kernel.h>
75516 +#include <linux/sched.h>
75517 +#include <linux/grinternal.h>
75518 +#include <linux/security.h>
75519 +
75520 +void
75521 +gr_audit_ptrace(struct task_struct *task)
75522 +{
75523 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
75524 + if (grsec_enable_audit_ptrace)
75525 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
75526 +#endif
75527 + return;
75528 +}
75529 +
75530 +int
75531 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
75532 +{
75533 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
75534 + const struct dentry *dentry = file->f_path.dentry;
75535 + const struct vfsmount *mnt = file->f_path.mnt;
75536 +
75537 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
75538 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
75539 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
75540 + return -EACCES;
75541 + }
75542 +#endif
75543 + return 0;
75544 +}
75545 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
75546 new file mode 100644
75547 index 0000000..3860c7e
75548 --- /dev/null
75549 +++ b/grsecurity/grsec_sig.c
75550 @@ -0,0 +1,236 @@
75551 +#include <linux/kernel.h>
75552 +#include <linux/sched.h>
75553 +#include <linux/fs.h>
75554 +#include <linux/delay.h>
75555 +#include <linux/grsecurity.h>
75556 +#include <linux/grinternal.h>
75557 +#include <linux/hardirq.h>
75558 +
75559 +char *signames[] = {
75560 + [SIGSEGV] = "Segmentation fault",
75561 + [SIGILL] = "Illegal instruction",
75562 + [SIGABRT] = "Abort",
75563 + [SIGBUS] = "Invalid alignment/Bus error"
75564 +};
75565 +
75566 +void
75567 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
75568 +{
75569 +#ifdef CONFIG_GRKERNSEC_SIGNAL
75570 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
75571 + (sig == SIGABRT) || (sig == SIGBUS))) {
75572 + if (task_pid_nr(t) == task_pid_nr(current)) {
75573 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
75574 + } else {
75575 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
75576 + }
75577 + }
75578 +#endif
75579 + return;
75580 +}
75581 +
75582 +int
75583 +gr_handle_signal(const struct task_struct *p, const int sig)
75584 +{
75585 +#ifdef CONFIG_GRKERNSEC
75586 + /* ignore the 0 signal for protected task checks */
75587 + if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
75588 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
75589 + return -EPERM;
75590 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
75591 + return -EPERM;
75592 + }
75593 +#endif
75594 + return 0;
75595 +}
75596 +
75597 +#ifdef CONFIG_GRKERNSEC
75598 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
75599 +
75600 +int gr_fake_force_sig(int sig, struct task_struct *t)
75601 +{
75602 + unsigned long int flags;
75603 + int ret, blocked, ignored;
75604 + struct k_sigaction *action;
75605 +
75606 + spin_lock_irqsave(&t->sighand->siglock, flags);
75607 + action = &t->sighand->action[sig-1];
75608 + ignored = action->sa.sa_handler == SIG_IGN;
75609 + blocked = sigismember(&t->blocked, sig);
75610 + if (blocked || ignored) {
75611 + action->sa.sa_handler = SIG_DFL;
75612 + if (blocked) {
75613 + sigdelset(&t->blocked, sig);
75614 + recalc_sigpending_and_wake(t);
75615 + }
75616 + }
75617 + if (action->sa.sa_handler == SIG_DFL)
75618 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
75619 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
75620 +
75621 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
75622 +
75623 + return ret;
75624 +}
75625 +#endif
75626 +
75627 +#define GR_USER_BAN_TIME (15 * 60)
75628 +#define GR_DAEMON_BRUTE_TIME (30 * 60)
75629 +
75630 +void gr_handle_brute_attach(int dumpable)
75631 +{
75632 +#ifdef CONFIG_GRKERNSEC_BRUTE
75633 + struct task_struct *p = current;
75634 + kuid_t uid = GLOBAL_ROOT_UID;
75635 + int daemon = 0;
75636 +
75637 + if (!grsec_enable_brute)
75638 + return;
75639 +
75640 + rcu_read_lock();
75641 + read_lock(&tasklist_lock);
75642 + read_lock(&grsec_exec_file_lock);
75643 + if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
75644 + p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
75645 + p->real_parent->brute = 1;
75646 + daemon = 1;
75647 + } else {
75648 + const struct cred *cred = __task_cred(p), *cred2;
75649 + struct task_struct *tsk, *tsk2;
75650 +
75651 + if (dumpable != SUID_DUMP_USER && gr_is_global_nonroot(cred->uid)) {
75652 + struct user_struct *user;
75653 +
75654 + uid = cred->uid;
75655 +
75656 + /* this is put upon execution past expiration */
75657 + user = find_user(uid);
75658 + if (user == NULL)
75659 + goto unlock;
75660 + user->suid_banned = 1;
75661 + user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
75662 + if (user->suid_ban_expires == ~0UL)
75663 + user->suid_ban_expires--;
75664 +
75665 + /* only kill other threads of the same binary, from the same user */
75666 + do_each_thread(tsk2, tsk) {
75667 + cred2 = __task_cred(tsk);
75668 + if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
75669 + gr_fake_force_sig(SIGKILL, tsk);
75670 + } while_each_thread(tsk2, tsk);
75671 + }
75672 + }
75673 +unlock:
75674 + read_unlock(&grsec_exec_file_lock);
75675 + read_unlock(&tasklist_lock);
75676 + rcu_read_unlock();
75677 +
75678 + if (gr_is_global_nonroot(uid))
75679 + 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);
75680 + else if (daemon)
75681 + gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
75682 +
75683 +#endif
75684 + return;
75685 +}
75686 +
75687 +void gr_handle_brute_check(void)
75688 +{
75689 +#ifdef CONFIG_GRKERNSEC_BRUTE
75690 + struct task_struct *p = current;
75691 +
75692 + if (unlikely(p->brute)) {
75693 + if (!grsec_enable_brute)
75694 + p->brute = 0;
75695 + else if (time_before(get_seconds(), p->brute_expires))
75696 + msleep(30 * 1000);
75697 + }
75698 +#endif
75699 + return;
75700 +}
75701 +
75702 +void gr_handle_kernel_exploit(void)
75703 +{
75704 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75705 + const struct cred *cred;
75706 + struct task_struct *tsk, *tsk2;
75707 + struct user_struct *user;
75708 + kuid_t uid;
75709 +
75710 + if (in_irq() || in_serving_softirq() || in_nmi())
75711 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
75712 +
75713 + uid = current_uid();
75714 +
75715 + if (gr_is_global_root(uid))
75716 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
75717 + else {
75718 + /* kill all the processes of this user, hold a reference
75719 + to their creds struct, and prevent them from creating
75720 + another process until system reset
75721 + */
75722 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
75723 + GR_GLOBAL_UID(uid));
75724 + /* we intentionally leak this ref */
75725 + user = get_uid(current->cred->user);
75726 + if (user)
75727 + user->kernel_banned = 1;
75728 +
75729 + /* kill all processes of this user */
75730 + read_lock(&tasklist_lock);
75731 + do_each_thread(tsk2, tsk) {
75732 + cred = __task_cred(tsk);
75733 + if (uid_eq(cred->uid, uid))
75734 + gr_fake_force_sig(SIGKILL, tsk);
75735 + } while_each_thread(tsk2, tsk);
75736 + read_unlock(&tasklist_lock);
75737 + }
75738 +#endif
75739 +}
75740 +
75741 +#ifdef CONFIG_GRKERNSEC_BRUTE
75742 +static bool suid_ban_expired(struct user_struct *user)
75743 +{
75744 + if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
75745 + user->suid_banned = 0;
75746 + user->suid_ban_expires = 0;
75747 + free_uid(user);
75748 + return true;
75749 + }
75750 +
75751 + return false;
75752 +}
75753 +#endif
75754 +
75755 +int gr_process_kernel_exec_ban(void)
75756 +{
75757 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75758 + if (unlikely(current->cred->user->kernel_banned))
75759 + return -EPERM;
75760 +#endif
75761 + return 0;
75762 +}
75763 +
75764 +int gr_process_kernel_setuid_ban(struct user_struct *user)
75765 +{
75766 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
75767 + if (unlikely(user->kernel_banned))
75768 + gr_fake_force_sig(SIGKILL, current);
75769 +#endif
75770 + return 0;
75771 +}
75772 +
75773 +int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
75774 +{
75775 +#ifdef CONFIG_GRKERNSEC_BRUTE
75776 + struct user_struct *user = current->cred->user;
75777 + if (unlikely(user->suid_banned)) {
75778 + if (suid_ban_expired(user))
75779 + return 0;
75780 + /* disallow execution of suid binaries only */
75781 + else if (!uid_eq(bprm->cred->euid, current->cred->uid))
75782 + return -EPERM;
75783 + }
75784 +#endif
75785 + return 0;
75786 +}
75787 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
75788 new file mode 100644
75789 index 0000000..c0aef3a
75790 --- /dev/null
75791 +++ b/grsecurity/grsec_sock.c
75792 @@ -0,0 +1,244 @@
75793 +#include <linux/kernel.h>
75794 +#include <linux/module.h>
75795 +#include <linux/sched.h>
75796 +#include <linux/file.h>
75797 +#include <linux/net.h>
75798 +#include <linux/in.h>
75799 +#include <linux/ip.h>
75800 +#include <net/sock.h>
75801 +#include <net/inet_sock.h>
75802 +#include <linux/grsecurity.h>
75803 +#include <linux/grinternal.h>
75804 +#include <linux/gracl.h>
75805 +
75806 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
75807 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
75808 +
75809 +EXPORT_SYMBOL_GPL(gr_search_udp_recvmsg);
75810 +EXPORT_SYMBOL_GPL(gr_search_udp_sendmsg);
75811 +
75812 +#ifdef CONFIG_UNIX_MODULE
75813 +EXPORT_SYMBOL_GPL(gr_acl_handle_unix);
75814 +EXPORT_SYMBOL_GPL(gr_acl_handle_mknod);
75815 +EXPORT_SYMBOL_GPL(gr_handle_chroot_unix);
75816 +EXPORT_SYMBOL_GPL(gr_handle_create);
75817 +#endif
75818 +
75819 +#ifdef CONFIG_GRKERNSEC
75820 +#define gr_conn_table_size 32749
75821 +struct conn_table_entry {
75822 + struct conn_table_entry *next;
75823 + struct signal_struct *sig;
75824 +};
75825 +
75826 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
75827 +DEFINE_SPINLOCK(gr_conn_table_lock);
75828 +
75829 +extern const char * gr_socktype_to_name(unsigned char type);
75830 +extern const char * gr_proto_to_name(unsigned char proto);
75831 +extern const char * gr_sockfamily_to_name(unsigned char family);
75832 +
75833 +static __inline__ int
75834 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
75835 +{
75836 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
75837 +}
75838 +
75839 +static __inline__ int
75840 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
75841 + __u16 sport, __u16 dport)
75842 +{
75843 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
75844 + sig->gr_sport == sport && sig->gr_dport == dport))
75845 + return 1;
75846 + else
75847 + return 0;
75848 +}
75849 +
75850 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
75851 +{
75852 + struct conn_table_entry **match;
75853 + unsigned int index;
75854 +
75855 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
75856 + sig->gr_sport, sig->gr_dport,
75857 + gr_conn_table_size);
75858 +
75859 + newent->sig = sig;
75860 +
75861 + match = &gr_conn_table[index];
75862 + newent->next = *match;
75863 + *match = newent;
75864 +
75865 + return;
75866 +}
75867 +
75868 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
75869 +{
75870 + struct conn_table_entry *match, *last = NULL;
75871 + unsigned int index;
75872 +
75873 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
75874 + sig->gr_sport, sig->gr_dport,
75875 + gr_conn_table_size);
75876 +
75877 + match = gr_conn_table[index];
75878 + while (match && !conn_match(match->sig,
75879 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
75880 + sig->gr_dport)) {
75881 + last = match;
75882 + match = match->next;
75883 + }
75884 +
75885 + if (match) {
75886 + if (last)
75887 + last->next = match->next;
75888 + else
75889 + gr_conn_table[index] = NULL;
75890 + kfree(match);
75891 + }
75892 +
75893 + return;
75894 +}
75895 +
75896 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
75897 + __u16 sport, __u16 dport)
75898 +{
75899 + struct conn_table_entry *match;
75900 + unsigned int index;
75901 +
75902 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
75903 +
75904 + match = gr_conn_table[index];
75905 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
75906 + match = match->next;
75907 +
75908 + if (match)
75909 + return match->sig;
75910 + else
75911 + return NULL;
75912 +}
75913 +
75914 +#endif
75915 +
75916 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
75917 +{
75918 +#ifdef CONFIG_GRKERNSEC
75919 + struct signal_struct *sig = task->signal;
75920 + struct conn_table_entry *newent;
75921 +
75922 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
75923 + if (newent == NULL)
75924 + return;
75925 + /* no bh lock needed since we are called with bh disabled */
75926 + spin_lock(&gr_conn_table_lock);
75927 + gr_del_task_from_ip_table_nolock(sig);
75928 + sig->gr_saddr = inet->inet_rcv_saddr;
75929 + sig->gr_daddr = inet->inet_daddr;
75930 + sig->gr_sport = inet->inet_sport;
75931 + sig->gr_dport = inet->inet_dport;
75932 + gr_add_to_task_ip_table_nolock(sig, newent);
75933 + spin_unlock(&gr_conn_table_lock);
75934 +#endif
75935 + return;
75936 +}
75937 +
75938 +void gr_del_task_from_ip_table(struct task_struct *task)
75939 +{
75940 +#ifdef CONFIG_GRKERNSEC
75941 + spin_lock_bh(&gr_conn_table_lock);
75942 + gr_del_task_from_ip_table_nolock(task->signal);
75943 + spin_unlock_bh(&gr_conn_table_lock);
75944 +#endif
75945 + return;
75946 +}
75947 +
75948 +void
75949 +gr_attach_curr_ip(const struct sock *sk)
75950 +{
75951 +#ifdef CONFIG_GRKERNSEC
75952 + struct signal_struct *p, *set;
75953 + const struct inet_sock *inet = inet_sk(sk);
75954 +
75955 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
75956 + return;
75957 +
75958 + set = current->signal;
75959 +
75960 + spin_lock_bh(&gr_conn_table_lock);
75961 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
75962 + inet->inet_dport, inet->inet_sport);
75963 + if (unlikely(p != NULL)) {
75964 + set->curr_ip = p->curr_ip;
75965 + set->used_accept = 1;
75966 + gr_del_task_from_ip_table_nolock(p);
75967 + spin_unlock_bh(&gr_conn_table_lock);
75968 + return;
75969 + }
75970 + spin_unlock_bh(&gr_conn_table_lock);
75971 +
75972 + set->curr_ip = inet->inet_daddr;
75973 + set->used_accept = 1;
75974 +#endif
75975 + return;
75976 +}
75977 +
75978 +int
75979 +gr_handle_sock_all(const int family, const int type, const int protocol)
75980 +{
75981 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
75982 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
75983 + (family != AF_UNIX)) {
75984 + if (family == AF_INET)
75985 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
75986 + else
75987 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
75988 + return -EACCES;
75989 + }
75990 +#endif
75991 + return 0;
75992 +}
75993 +
75994 +int
75995 +gr_handle_sock_server(const struct sockaddr *sck)
75996 +{
75997 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
75998 + if (grsec_enable_socket_server &&
75999 + in_group_p(grsec_socket_server_gid) &&
76000 + sck && (sck->sa_family != AF_UNIX) &&
76001 + (sck->sa_family != AF_LOCAL)) {
76002 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
76003 + return -EACCES;
76004 + }
76005 +#endif
76006 + return 0;
76007 +}
76008 +
76009 +int
76010 +gr_handle_sock_server_other(const struct sock *sck)
76011 +{
76012 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
76013 + if (grsec_enable_socket_server &&
76014 + in_group_p(grsec_socket_server_gid) &&
76015 + sck && (sck->sk_family != AF_UNIX) &&
76016 + (sck->sk_family != AF_LOCAL)) {
76017 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
76018 + return -EACCES;
76019 + }
76020 +#endif
76021 + return 0;
76022 +}
76023 +
76024 +int
76025 +gr_handle_sock_client(const struct sockaddr *sck)
76026 +{
76027 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
76028 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
76029 + sck && (sck->sa_family != AF_UNIX) &&
76030 + (sck->sa_family != AF_LOCAL)) {
76031 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
76032 + return -EACCES;
76033 + }
76034 +#endif
76035 + return 0;
76036 +}
76037 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
76038 new file mode 100644
76039 index 0000000..8159888
76040 --- /dev/null
76041 +++ b/grsecurity/grsec_sysctl.c
76042 @@ -0,0 +1,479 @@
76043 +#include <linux/kernel.h>
76044 +#include <linux/sched.h>
76045 +#include <linux/sysctl.h>
76046 +#include <linux/grsecurity.h>
76047 +#include <linux/grinternal.h>
76048 +
76049 +int
76050 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
76051 +{
76052 +#ifdef CONFIG_GRKERNSEC_SYSCTL
76053 + if (dirname == NULL || name == NULL)
76054 + return 0;
76055 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
76056 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
76057 + return -EACCES;
76058 + }
76059 +#endif
76060 + return 0;
76061 +}
76062 +
76063 +#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
76064 +static int __maybe_unused __read_only one = 1;
76065 +#endif
76066 +
76067 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
76068 + defined(CONFIG_GRKERNSEC_DENYUSB)
76069 +struct ctl_table grsecurity_table[] = {
76070 +#ifdef CONFIG_GRKERNSEC_SYSCTL
76071 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
76072 +#ifdef CONFIG_GRKERNSEC_IO
76073 + {
76074 + .procname = "disable_priv_io",
76075 + .data = &grsec_disable_privio,
76076 + .maxlen = sizeof(int),
76077 + .mode = 0600,
76078 + .proc_handler = &proc_dointvec,
76079 + },
76080 +#endif
76081 +#endif
76082 +#ifdef CONFIG_GRKERNSEC_LINK
76083 + {
76084 + .procname = "linking_restrictions",
76085 + .data = &grsec_enable_link,
76086 + .maxlen = sizeof(int),
76087 + .mode = 0600,
76088 + .proc_handler = &proc_dointvec,
76089 + },
76090 +#endif
76091 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
76092 + {
76093 + .procname = "enforce_symlinksifowner",
76094 + .data = &grsec_enable_symlinkown,
76095 + .maxlen = sizeof(int),
76096 + .mode = 0600,
76097 + .proc_handler = &proc_dointvec,
76098 + },
76099 + {
76100 + .procname = "symlinkown_gid",
76101 + .data = &grsec_symlinkown_gid,
76102 + .maxlen = sizeof(int),
76103 + .mode = 0600,
76104 + .proc_handler = &proc_dointvec,
76105 + },
76106 +#endif
76107 +#ifdef CONFIG_GRKERNSEC_BRUTE
76108 + {
76109 + .procname = "deter_bruteforce",
76110 + .data = &grsec_enable_brute,
76111 + .maxlen = sizeof(int),
76112 + .mode = 0600,
76113 + .proc_handler = &proc_dointvec,
76114 + },
76115 +#endif
76116 +#ifdef CONFIG_GRKERNSEC_FIFO
76117 + {
76118 + .procname = "fifo_restrictions",
76119 + .data = &grsec_enable_fifo,
76120 + .maxlen = sizeof(int),
76121 + .mode = 0600,
76122 + .proc_handler = &proc_dointvec,
76123 + },
76124 +#endif
76125 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
76126 + {
76127 + .procname = "ptrace_readexec",
76128 + .data = &grsec_enable_ptrace_readexec,
76129 + .maxlen = sizeof(int),
76130 + .mode = 0600,
76131 + .proc_handler = &proc_dointvec,
76132 + },
76133 +#endif
76134 +#ifdef CONFIG_GRKERNSEC_SETXID
76135 + {
76136 + .procname = "consistent_setxid",
76137 + .data = &grsec_enable_setxid,
76138 + .maxlen = sizeof(int),
76139 + .mode = 0600,
76140 + .proc_handler = &proc_dointvec,
76141 + },
76142 +#endif
76143 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
76144 + {
76145 + .procname = "ip_blackhole",
76146 + .data = &grsec_enable_blackhole,
76147 + .maxlen = sizeof(int),
76148 + .mode = 0600,
76149 + .proc_handler = &proc_dointvec,
76150 + },
76151 + {
76152 + .procname = "lastack_retries",
76153 + .data = &grsec_lastack_retries,
76154 + .maxlen = sizeof(int),
76155 + .mode = 0600,
76156 + .proc_handler = &proc_dointvec,
76157 + },
76158 +#endif
76159 +#ifdef CONFIG_GRKERNSEC_EXECLOG
76160 + {
76161 + .procname = "exec_logging",
76162 + .data = &grsec_enable_execlog,
76163 + .maxlen = sizeof(int),
76164 + .mode = 0600,
76165 + .proc_handler = &proc_dointvec,
76166 + },
76167 +#endif
76168 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
76169 + {
76170 + .procname = "rwxmap_logging",
76171 + .data = &grsec_enable_log_rwxmaps,
76172 + .maxlen = sizeof(int),
76173 + .mode = 0600,
76174 + .proc_handler = &proc_dointvec,
76175 + },
76176 +#endif
76177 +#ifdef CONFIG_GRKERNSEC_SIGNAL
76178 + {
76179 + .procname = "signal_logging",
76180 + .data = &grsec_enable_signal,
76181 + .maxlen = sizeof(int),
76182 + .mode = 0600,
76183 + .proc_handler = &proc_dointvec,
76184 + },
76185 +#endif
76186 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
76187 + {
76188 + .procname = "forkfail_logging",
76189 + .data = &grsec_enable_forkfail,
76190 + .maxlen = sizeof(int),
76191 + .mode = 0600,
76192 + .proc_handler = &proc_dointvec,
76193 + },
76194 +#endif
76195 +#ifdef CONFIG_GRKERNSEC_TIME
76196 + {
76197 + .procname = "timechange_logging",
76198 + .data = &grsec_enable_time,
76199 + .maxlen = sizeof(int),
76200 + .mode = 0600,
76201 + .proc_handler = &proc_dointvec,
76202 + },
76203 +#endif
76204 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
76205 + {
76206 + .procname = "chroot_deny_shmat",
76207 + .data = &grsec_enable_chroot_shmat,
76208 + .maxlen = sizeof(int),
76209 + .mode = 0600,
76210 + .proc_handler = &proc_dointvec,
76211 + },
76212 +#endif
76213 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
76214 + {
76215 + .procname = "chroot_deny_unix",
76216 + .data = &grsec_enable_chroot_unix,
76217 + .maxlen = sizeof(int),
76218 + .mode = 0600,
76219 + .proc_handler = &proc_dointvec,
76220 + },
76221 +#endif
76222 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
76223 + {
76224 + .procname = "chroot_deny_mount",
76225 + .data = &grsec_enable_chroot_mount,
76226 + .maxlen = sizeof(int),
76227 + .mode = 0600,
76228 + .proc_handler = &proc_dointvec,
76229 + },
76230 +#endif
76231 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
76232 + {
76233 + .procname = "chroot_deny_fchdir",
76234 + .data = &grsec_enable_chroot_fchdir,
76235 + .maxlen = sizeof(int),
76236 + .mode = 0600,
76237 + .proc_handler = &proc_dointvec,
76238 + },
76239 +#endif
76240 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
76241 + {
76242 + .procname = "chroot_deny_chroot",
76243 + .data = &grsec_enable_chroot_double,
76244 + .maxlen = sizeof(int),
76245 + .mode = 0600,
76246 + .proc_handler = &proc_dointvec,
76247 + },
76248 +#endif
76249 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
76250 + {
76251 + .procname = "chroot_deny_pivot",
76252 + .data = &grsec_enable_chroot_pivot,
76253 + .maxlen = sizeof(int),
76254 + .mode = 0600,
76255 + .proc_handler = &proc_dointvec,
76256 + },
76257 +#endif
76258 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
76259 + {
76260 + .procname = "chroot_enforce_chdir",
76261 + .data = &grsec_enable_chroot_chdir,
76262 + .maxlen = sizeof(int),
76263 + .mode = 0600,
76264 + .proc_handler = &proc_dointvec,
76265 + },
76266 +#endif
76267 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
76268 + {
76269 + .procname = "chroot_deny_chmod",
76270 + .data = &grsec_enable_chroot_chmod,
76271 + .maxlen = sizeof(int),
76272 + .mode = 0600,
76273 + .proc_handler = &proc_dointvec,
76274 + },
76275 +#endif
76276 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
76277 + {
76278 + .procname = "chroot_deny_mknod",
76279 + .data = &grsec_enable_chroot_mknod,
76280 + .maxlen = sizeof(int),
76281 + .mode = 0600,
76282 + .proc_handler = &proc_dointvec,
76283 + },
76284 +#endif
76285 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
76286 + {
76287 + .procname = "chroot_restrict_nice",
76288 + .data = &grsec_enable_chroot_nice,
76289 + .maxlen = sizeof(int),
76290 + .mode = 0600,
76291 + .proc_handler = &proc_dointvec,
76292 + },
76293 +#endif
76294 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
76295 + {
76296 + .procname = "chroot_execlog",
76297 + .data = &grsec_enable_chroot_execlog,
76298 + .maxlen = sizeof(int),
76299 + .mode = 0600,
76300 + .proc_handler = &proc_dointvec,
76301 + },
76302 +#endif
76303 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
76304 + {
76305 + .procname = "chroot_caps",
76306 + .data = &grsec_enable_chroot_caps,
76307 + .maxlen = sizeof(int),
76308 + .mode = 0600,
76309 + .proc_handler = &proc_dointvec,
76310 + },
76311 +#endif
76312 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
76313 + {
76314 + .procname = "chroot_deny_sysctl",
76315 + .data = &grsec_enable_chroot_sysctl,
76316 + .maxlen = sizeof(int),
76317 + .mode = 0600,
76318 + .proc_handler = &proc_dointvec,
76319 + },
76320 +#endif
76321 +#ifdef CONFIG_GRKERNSEC_TPE
76322 + {
76323 + .procname = "tpe",
76324 + .data = &grsec_enable_tpe,
76325 + .maxlen = sizeof(int),
76326 + .mode = 0600,
76327 + .proc_handler = &proc_dointvec,
76328 + },
76329 + {
76330 + .procname = "tpe_gid",
76331 + .data = &grsec_tpe_gid,
76332 + .maxlen = sizeof(int),
76333 + .mode = 0600,
76334 + .proc_handler = &proc_dointvec,
76335 + },
76336 +#endif
76337 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
76338 + {
76339 + .procname = "tpe_invert",
76340 + .data = &grsec_enable_tpe_invert,
76341 + .maxlen = sizeof(int),
76342 + .mode = 0600,
76343 + .proc_handler = &proc_dointvec,
76344 + },
76345 +#endif
76346 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
76347 + {
76348 + .procname = "tpe_restrict_all",
76349 + .data = &grsec_enable_tpe_all,
76350 + .maxlen = sizeof(int),
76351 + .mode = 0600,
76352 + .proc_handler = &proc_dointvec,
76353 + },
76354 +#endif
76355 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
76356 + {
76357 + .procname = "socket_all",
76358 + .data = &grsec_enable_socket_all,
76359 + .maxlen = sizeof(int),
76360 + .mode = 0600,
76361 + .proc_handler = &proc_dointvec,
76362 + },
76363 + {
76364 + .procname = "socket_all_gid",
76365 + .data = &grsec_socket_all_gid,
76366 + .maxlen = sizeof(int),
76367 + .mode = 0600,
76368 + .proc_handler = &proc_dointvec,
76369 + },
76370 +#endif
76371 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
76372 + {
76373 + .procname = "socket_client",
76374 + .data = &grsec_enable_socket_client,
76375 + .maxlen = sizeof(int),
76376 + .mode = 0600,
76377 + .proc_handler = &proc_dointvec,
76378 + },
76379 + {
76380 + .procname = "socket_client_gid",
76381 + .data = &grsec_socket_client_gid,
76382 + .maxlen = sizeof(int),
76383 + .mode = 0600,
76384 + .proc_handler = &proc_dointvec,
76385 + },
76386 +#endif
76387 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
76388 + {
76389 + .procname = "socket_server",
76390 + .data = &grsec_enable_socket_server,
76391 + .maxlen = sizeof(int),
76392 + .mode = 0600,
76393 + .proc_handler = &proc_dointvec,
76394 + },
76395 + {
76396 + .procname = "socket_server_gid",
76397 + .data = &grsec_socket_server_gid,
76398 + .maxlen = sizeof(int),
76399 + .mode = 0600,
76400 + .proc_handler = &proc_dointvec,
76401 + },
76402 +#endif
76403 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
76404 + {
76405 + .procname = "audit_group",
76406 + .data = &grsec_enable_group,
76407 + .maxlen = sizeof(int),
76408 + .mode = 0600,
76409 + .proc_handler = &proc_dointvec,
76410 + },
76411 + {
76412 + .procname = "audit_gid",
76413 + .data = &grsec_audit_gid,
76414 + .maxlen = sizeof(int),
76415 + .mode = 0600,
76416 + .proc_handler = &proc_dointvec,
76417 + },
76418 +#endif
76419 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
76420 + {
76421 + .procname = "audit_chdir",
76422 + .data = &grsec_enable_chdir,
76423 + .maxlen = sizeof(int),
76424 + .mode = 0600,
76425 + .proc_handler = &proc_dointvec,
76426 + },
76427 +#endif
76428 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
76429 + {
76430 + .procname = "audit_mount",
76431 + .data = &grsec_enable_mount,
76432 + .maxlen = sizeof(int),
76433 + .mode = 0600,
76434 + .proc_handler = &proc_dointvec,
76435 + },
76436 +#endif
76437 +#ifdef CONFIG_GRKERNSEC_DMESG
76438 + {
76439 + .procname = "dmesg",
76440 + .data = &grsec_enable_dmesg,
76441 + .maxlen = sizeof(int),
76442 + .mode = 0600,
76443 + .proc_handler = &proc_dointvec,
76444 + },
76445 +#endif
76446 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
76447 + {
76448 + .procname = "chroot_findtask",
76449 + .data = &grsec_enable_chroot_findtask,
76450 + .maxlen = sizeof(int),
76451 + .mode = 0600,
76452 + .proc_handler = &proc_dointvec,
76453 + },
76454 +#endif
76455 +#ifdef CONFIG_GRKERNSEC_RESLOG
76456 + {
76457 + .procname = "resource_logging",
76458 + .data = &grsec_resource_logging,
76459 + .maxlen = sizeof(int),
76460 + .mode = 0600,
76461 + .proc_handler = &proc_dointvec,
76462 + },
76463 +#endif
76464 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
76465 + {
76466 + .procname = "audit_ptrace",
76467 + .data = &grsec_enable_audit_ptrace,
76468 + .maxlen = sizeof(int),
76469 + .mode = 0600,
76470 + .proc_handler = &proc_dointvec,
76471 + },
76472 +#endif
76473 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
76474 + {
76475 + .procname = "harden_ptrace",
76476 + .data = &grsec_enable_harden_ptrace,
76477 + .maxlen = sizeof(int),
76478 + .mode = 0600,
76479 + .proc_handler = &proc_dointvec,
76480 + },
76481 +#endif
76482 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
76483 + {
76484 + .procname = "harden_ipc",
76485 + .data = &grsec_enable_harden_ipc,
76486 + .maxlen = sizeof(int),
76487 + .mode = 0600,
76488 + .proc_handler = &proc_dointvec,
76489 + },
76490 +#endif
76491 + {
76492 + .procname = "grsec_lock",
76493 + .data = &grsec_lock,
76494 + .maxlen = sizeof(int),
76495 + .mode = 0600,
76496 + .proc_handler = &proc_dointvec,
76497 + },
76498 +#endif
76499 +#ifdef CONFIG_GRKERNSEC_ROFS
76500 + {
76501 + .procname = "romount_protect",
76502 + .data = &grsec_enable_rofs,
76503 + .maxlen = sizeof(int),
76504 + .mode = 0600,
76505 + .proc_handler = &proc_dointvec_minmax,
76506 + .extra1 = &one,
76507 + .extra2 = &one,
76508 + },
76509 +#endif
76510 +#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
76511 + {
76512 + .procname = "deny_new_usb",
76513 + .data = &grsec_deny_new_usb,
76514 + .maxlen = sizeof(int),
76515 + .mode = 0600,
76516 + .proc_handler = &proc_dointvec,
76517 + },
76518 +#endif
76519 + { }
76520 +};
76521 +#endif
76522 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
76523 new file mode 100644
76524 index 0000000..61b514e
76525 --- /dev/null
76526 +++ b/grsecurity/grsec_time.c
76527 @@ -0,0 +1,16 @@
76528 +#include <linux/kernel.h>
76529 +#include <linux/sched.h>
76530 +#include <linux/grinternal.h>
76531 +#include <linux/module.h>
76532 +
76533 +void
76534 +gr_log_timechange(void)
76535 +{
76536 +#ifdef CONFIG_GRKERNSEC_TIME
76537 + if (grsec_enable_time)
76538 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
76539 +#endif
76540 + return;
76541 +}
76542 +
76543 +EXPORT_SYMBOL_GPL(gr_log_timechange);
76544 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
76545 new file mode 100644
76546 index 0000000..d1953de
76547 --- /dev/null
76548 +++ b/grsecurity/grsec_tpe.c
76549 @@ -0,0 +1,78 @@
76550 +#include <linux/kernel.h>
76551 +#include <linux/sched.h>
76552 +#include <linux/file.h>
76553 +#include <linux/fs.h>
76554 +#include <linux/grinternal.h>
76555 +
76556 +extern int gr_acl_tpe_check(void);
76557 +
76558 +int
76559 +gr_tpe_allow(const struct file *file)
76560 +{
76561 +#ifdef CONFIG_GRKERNSEC
76562 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
76563 + struct inode *file_inode = file->f_path.dentry->d_inode;
76564 + const struct cred *cred = current_cred();
76565 + char *msg = NULL;
76566 + char *msg2 = NULL;
76567 +
76568 + // never restrict root
76569 + if (gr_is_global_root(cred->uid))
76570 + return 1;
76571 +
76572 + if (grsec_enable_tpe) {
76573 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
76574 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
76575 + msg = "not being in trusted group";
76576 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
76577 + msg = "being in untrusted group";
76578 +#else
76579 + if (in_group_p(grsec_tpe_gid))
76580 + msg = "being in untrusted group";
76581 +#endif
76582 + }
76583 + if (!msg && gr_acl_tpe_check())
76584 + msg = "being in untrusted role";
76585 +
76586 + // not in any affected group/role
76587 + if (!msg)
76588 + goto next_check;
76589 +
76590 + if (gr_is_global_nonroot(inode->i_uid))
76591 + msg2 = "file in non-root-owned directory";
76592 + else if (inode->i_mode & S_IWOTH)
76593 + msg2 = "file in world-writable directory";
76594 + else if (inode->i_mode & S_IWGRP)
76595 + msg2 = "file in group-writable directory";
76596 + else if (file_inode->i_mode & S_IWOTH)
76597 + msg2 = "file is world-writable";
76598 +
76599 + if (msg && msg2) {
76600 + char fullmsg[70] = {0};
76601 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
76602 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
76603 + return 0;
76604 + }
76605 + msg = NULL;
76606 +next_check:
76607 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
76608 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
76609 + return 1;
76610 +
76611 + if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
76612 + msg = "directory not owned by user";
76613 + else if (inode->i_mode & S_IWOTH)
76614 + msg = "file in world-writable directory";
76615 + else if (inode->i_mode & S_IWGRP)
76616 + msg = "file in group-writable directory";
76617 + else if (file_inode->i_mode & S_IWOTH)
76618 + msg = "file is world-writable";
76619 +
76620 + if (msg) {
76621 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
76622 + return 0;
76623 + }
76624 +#endif
76625 +#endif
76626 + return 1;
76627 +}
76628 diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
76629 new file mode 100644
76630 index 0000000..ae02d8e
76631 --- /dev/null
76632 +++ b/grsecurity/grsec_usb.c
76633 @@ -0,0 +1,15 @@
76634 +#include <linux/kernel.h>
76635 +#include <linux/grinternal.h>
76636 +#include <linux/module.h>
76637 +
76638 +int gr_handle_new_usb(void)
76639 +{
76640 +#ifdef CONFIG_GRKERNSEC_DENYUSB
76641 + if (grsec_deny_new_usb) {
76642 + printk(KERN_ALERT "grsec: denied insert of new USB device\n");
76643 + return 1;
76644 + }
76645 +#endif
76646 + return 0;
76647 +}
76648 +EXPORT_SYMBOL_GPL(gr_handle_new_usb);
76649 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
76650 new file mode 100644
76651 index 0000000..9f7b1ac
76652 --- /dev/null
76653 +++ b/grsecurity/grsum.c
76654 @@ -0,0 +1,61 @@
76655 +#include <linux/err.h>
76656 +#include <linux/kernel.h>
76657 +#include <linux/sched.h>
76658 +#include <linux/mm.h>
76659 +#include <linux/scatterlist.h>
76660 +#include <linux/crypto.h>
76661 +#include <linux/gracl.h>
76662 +
76663 +
76664 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
76665 +#error "crypto and sha256 must be built into the kernel"
76666 +#endif
76667 +
76668 +int
76669 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
76670 +{
76671 + char *p;
76672 + struct crypto_hash *tfm;
76673 + struct hash_desc desc;
76674 + struct scatterlist sg;
76675 + unsigned char temp_sum[GR_SHA_LEN];
76676 + volatile int retval = 0;
76677 + volatile int dummy = 0;
76678 + unsigned int i;
76679 +
76680 + sg_init_table(&sg, 1);
76681 +
76682 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
76683 + if (IS_ERR(tfm)) {
76684 + /* should never happen, since sha256 should be built in */
76685 + return 1;
76686 + }
76687 +
76688 + desc.tfm = tfm;
76689 + desc.flags = 0;
76690 +
76691 + crypto_hash_init(&desc);
76692 +
76693 + p = salt;
76694 + sg_set_buf(&sg, p, GR_SALT_LEN);
76695 + crypto_hash_update(&desc, &sg, sg.length);
76696 +
76697 + p = entry->pw;
76698 + sg_set_buf(&sg, p, strlen(p));
76699 +
76700 + crypto_hash_update(&desc, &sg, sg.length);
76701 +
76702 + crypto_hash_final(&desc, temp_sum);
76703 +
76704 + memset(entry->pw, 0, GR_PW_LEN);
76705 +
76706 + for (i = 0; i < GR_SHA_LEN; i++)
76707 + if (sum[i] != temp_sum[i])
76708 + retval = 1;
76709 + else
76710 + dummy = 1; // waste a cycle
76711 +
76712 + crypto_free_hash(tfm);
76713 +
76714 + return retval;
76715 +}
76716 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
76717 index 77ff547..181834f 100644
76718 --- a/include/asm-generic/4level-fixup.h
76719 +++ b/include/asm-generic/4level-fixup.h
76720 @@ -13,8 +13,10 @@
76721 #define pmd_alloc(mm, pud, address) \
76722 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
76723 NULL: pmd_offset(pud, address))
76724 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
76725
76726 #define pud_alloc(mm, pgd, address) (pgd)
76727 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
76728 #define pud_offset(pgd, start) (pgd)
76729 #define pud_none(pud) 0
76730 #define pud_bad(pud) 0
76731 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
76732 index b7babf0..97f4c4f 100644
76733 --- a/include/asm-generic/atomic-long.h
76734 +++ b/include/asm-generic/atomic-long.h
76735 @@ -22,6 +22,12 @@
76736
76737 typedef atomic64_t atomic_long_t;
76738
76739 +#ifdef CONFIG_PAX_REFCOUNT
76740 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
76741 +#else
76742 +typedef atomic64_t atomic_long_unchecked_t;
76743 +#endif
76744 +
76745 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
76746
76747 static inline long atomic_long_read(atomic_long_t *l)
76748 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
76749 return (long)atomic64_read(v);
76750 }
76751
76752 +#ifdef CONFIG_PAX_REFCOUNT
76753 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
76754 +{
76755 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76756 +
76757 + return (long)atomic64_read_unchecked(v);
76758 +}
76759 +#endif
76760 +
76761 static inline void atomic_long_set(atomic_long_t *l, long i)
76762 {
76763 atomic64_t *v = (atomic64_t *)l;
76764 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
76765 atomic64_set(v, i);
76766 }
76767
76768 +#ifdef CONFIG_PAX_REFCOUNT
76769 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
76770 +{
76771 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76772 +
76773 + atomic64_set_unchecked(v, i);
76774 +}
76775 +#endif
76776 +
76777 static inline void atomic_long_inc(atomic_long_t *l)
76778 {
76779 atomic64_t *v = (atomic64_t *)l;
76780 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
76781 atomic64_inc(v);
76782 }
76783
76784 +#ifdef CONFIG_PAX_REFCOUNT
76785 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
76786 +{
76787 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76788 +
76789 + atomic64_inc_unchecked(v);
76790 +}
76791 +#endif
76792 +
76793 static inline void atomic_long_dec(atomic_long_t *l)
76794 {
76795 atomic64_t *v = (atomic64_t *)l;
76796 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
76797 atomic64_dec(v);
76798 }
76799
76800 +#ifdef CONFIG_PAX_REFCOUNT
76801 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
76802 +{
76803 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76804 +
76805 + atomic64_dec_unchecked(v);
76806 +}
76807 +#endif
76808 +
76809 static inline void atomic_long_add(long i, atomic_long_t *l)
76810 {
76811 atomic64_t *v = (atomic64_t *)l;
76812 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
76813 atomic64_add(i, v);
76814 }
76815
76816 +#ifdef CONFIG_PAX_REFCOUNT
76817 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
76818 +{
76819 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76820 +
76821 + atomic64_add_unchecked(i, v);
76822 +}
76823 +#endif
76824 +
76825 static inline void atomic_long_sub(long i, atomic_long_t *l)
76826 {
76827 atomic64_t *v = (atomic64_t *)l;
76828 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
76829 atomic64_sub(i, v);
76830 }
76831
76832 +#ifdef CONFIG_PAX_REFCOUNT
76833 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
76834 +{
76835 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76836 +
76837 + atomic64_sub_unchecked(i, v);
76838 +}
76839 +#endif
76840 +
76841 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
76842 {
76843 atomic64_t *v = (atomic64_t *)l;
76844 @@ -94,13 +154,22 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
76845 return atomic64_add_negative(i, v);
76846 }
76847
76848 -static inline long atomic_long_add_return(long i, atomic_long_t *l)
76849 +static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
76850 {
76851 atomic64_t *v = (atomic64_t *)l;
76852
76853 return (long)atomic64_add_return(i, v);
76854 }
76855
76856 +#ifdef CONFIG_PAX_REFCOUNT
76857 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
76858 +{
76859 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76860 +
76861 + return (long)atomic64_add_return_unchecked(i, v);
76862 +}
76863 +#endif
76864 +
76865 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
76866 {
76867 atomic64_t *v = (atomic64_t *)l;
76868 @@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
76869 return (long)atomic64_inc_return(v);
76870 }
76871
76872 +#ifdef CONFIG_PAX_REFCOUNT
76873 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
76874 +{
76875 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
76876 +
76877 + return (long)atomic64_inc_return_unchecked(v);
76878 +}
76879 +#endif
76880 +
76881 static inline long atomic_long_dec_return(atomic_long_t *l)
76882 {
76883 atomic64_t *v = (atomic64_t *)l;
76884 @@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
76885
76886 typedef atomic_t atomic_long_t;
76887
76888 +#ifdef CONFIG_PAX_REFCOUNT
76889 +typedef atomic_unchecked_t atomic_long_unchecked_t;
76890 +#else
76891 +typedef atomic_t atomic_long_unchecked_t;
76892 +#endif
76893 +
76894 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
76895 static inline long atomic_long_read(atomic_long_t *l)
76896 {
76897 @@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
76898 return (long)atomic_read(v);
76899 }
76900
76901 +#ifdef CONFIG_PAX_REFCOUNT
76902 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
76903 +{
76904 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76905 +
76906 + return (long)atomic_read_unchecked(v);
76907 +}
76908 +#endif
76909 +
76910 static inline void atomic_long_set(atomic_long_t *l, long i)
76911 {
76912 atomic_t *v = (atomic_t *)l;
76913 @@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
76914 atomic_set(v, i);
76915 }
76916
76917 +#ifdef CONFIG_PAX_REFCOUNT
76918 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
76919 +{
76920 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76921 +
76922 + atomic_set_unchecked(v, i);
76923 +}
76924 +#endif
76925 +
76926 static inline void atomic_long_inc(atomic_long_t *l)
76927 {
76928 atomic_t *v = (atomic_t *)l;
76929 @@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
76930 atomic_inc(v);
76931 }
76932
76933 +#ifdef CONFIG_PAX_REFCOUNT
76934 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
76935 +{
76936 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76937 +
76938 + atomic_inc_unchecked(v);
76939 +}
76940 +#endif
76941 +
76942 static inline void atomic_long_dec(atomic_long_t *l)
76943 {
76944 atomic_t *v = (atomic_t *)l;
76945 @@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
76946 atomic_dec(v);
76947 }
76948
76949 +#ifdef CONFIG_PAX_REFCOUNT
76950 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
76951 +{
76952 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76953 +
76954 + atomic_dec_unchecked(v);
76955 +}
76956 +#endif
76957 +
76958 static inline void atomic_long_add(long i, atomic_long_t *l)
76959 {
76960 atomic_t *v = (atomic_t *)l;
76961 @@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
76962 atomic_add(i, v);
76963 }
76964
76965 +#ifdef CONFIG_PAX_REFCOUNT
76966 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
76967 +{
76968 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76969 +
76970 + atomic_add_unchecked(i, v);
76971 +}
76972 +#endif
76973 +
76974 static inline void atomic_long_sub(long i, atomic_long_t *l)
76975 {
76976 atomic_t *v = (atomic_t *)l;
76977 @@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
76978 atomic_sub(i, v);
76979 }
76980
76981 +#ifdef CONFIG_PAX_REFCOUNT
76982 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
76983 +{
76984 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
76985 +
76986 + atomic_sub_unchecked(i, v);
76987 +}
76988 +#endif
76989 +
76990 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
76991 {
76992 atomic_t *v = (atomic_t *)l;
76993 @@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
76994 return (long)atomic_add_return(i, v);
76995 }
76996
76997 +#ifdef CONFIG_PAX_REFCOUNT
76998 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
76999 +{
77000 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77001 +
77002 + return (long)atomic_add_return_unchecked(i, v);
77003 +}
77004 +
77005 +#endif
77006 +
77007 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
77008 {
77009 atomic_t *v = (atomic_t *)l;
77010 @@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
77011 return (long)atomic_inc_return(v);
77012 }
77013
77014 +#ifdef CONFIG_PAX_REFCOUNT
77015 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
77016 +{
77017 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
77018 +
77019 + return (long)atomic_inc_return_unchecked(v);
77020 +}
77021 +#endif
77022 +
77023 static inline long atomic_long_dec_return(atomic_long_t *l)
77024 {
77025 atomic_t *v = (atomic_t *)l;
77026 @@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
77027
77028 #endif /* BITS_PER_LONG == 64 */
77029
77030 +#ifdef CONFIG_PAX_REFCOUNT
77031 +static inline void pax_refcount_needs_these_functions(void)
77032 +{
77033 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
77034 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
77035 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
77036 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
77037 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
77038 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
77039 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
77040 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
77041 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
77042 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
77043 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
77044 +#ifdef CONFIG_X86
77045 + atomic_clear_mask_unchecked(0, NULL);
77046 + atomic_set_mask_unchecked(0, NULL);
77047 +#endif
77048 +
77049 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
77050 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
77051 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
77052 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
77053 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
77054 + atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
77055 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
77056 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
77057 +}
77058 +#else
77059 +#define atomic_read_unchecked(v) atomic_read(v)
77060 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
77061 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
77062 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
77063 +#define atomic_inc_unchecked(v) atomic_inc(v)
77064 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
77065 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
77066 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
77067 +#define atomic_dec_unchecked(v) atomic_dec(v)
77068 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
77069 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
77070 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
77071 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
77072 +
77073 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
77074 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
77075 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
77076 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
77077 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
77078 +#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
77079 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
77080 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
77081 +#endif
77082 +
77083 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
77084 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
77085 index 33bd2de..f31bff97 100644
77086 --- a/include/asm-generic/atomic.h
77087 +++ b/include/asm-generic/atomic.h
77088 @@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
77089 * Atomically clears the bits set in @mask from @v
77090 */
77091 #ifndef atomic_clear_mask
77092 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
77093 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
77094 {
77095 unsigned long flags;
77096
77097 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
77098 index b18ce4f..2ee2843 100644
77099 --- a/include/asm-generic/atomic64.h
77100 +++ b/include/asm-generic/atomic64.h
77101 @@ -16,6 +16,8 @@ typedef struct {
77102 long long counter;
77103 } atomic64_t;
77104
77105 +typedef atomic64_t atomic64_unchecked_t;
77106 +
77107 #define ATOMIC64_INIT(i) { (i) }
77108
77109 extern long long atomic64_read(const atomic64_t *v);
77110 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
77111 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
77112 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
77113
77114 +#define atomic64_read_unchecked(v) atomic64_read(v)
77115 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
77116 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
77117 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
77118 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
77119 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
77120 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
77121 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
77122 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
77123 +
77124 #endif /* _ASM_GENERIC_ATOMIC64_H */
77125 diff --git a/include/asm-generic/barrier.h b/include/asm-generic/barrier.h
77126 index 6f692f8..2ad9dd2 100644
77127 --- a/include/asm-generic/barrier.h
77128 +++ b/include/asm-generic/barrier.h
77129 @@ -66,7 +66,7 @@
77130 do { \
77131 compiletime_assert_atomic_type(*p); \
77132 smp_mb(); \
77133 - ACCESS_ONCE(*p) = (v); \
77134 + ACCESS_ONCE_RW(*p) = (v); \
77135 } while (0)
77136
77137 #define smp_load_acquire(p) \
77138 diff --git a/include/asm-generic/bitops/__fls.h b/include/asm-generic/bitops/__fls.h
77139 index a60a7cc..0fe12f2 100644
77140 --- a/include/asm-generic/bitops/__fls.h
77141 +++ b/include/asm-generic/bitops/__fls.h
77142 @@ -9,7 +9,7 @@
77143 *
77144 * Undefined if no set bit exists, so code should check against 0 first.
77145 */
77146 -static __always_inline unsigned long __fls(unsigned long word)
77147 +static __always_inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
77148 {
77149 int num = BITS_PER_LONG - 1;
77150
77151 diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h
77152 index 0576d1f..dad6c71 100644
77153 --- a/include/asm-generic/bitops/fls.h
77154 +++ b/include/asm-generic/bitops/fls.h
77155 @@ -9,7 +9,7 @@
77156 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
77157 */
77158
77159 -static __always_inline int fls(int x)
77160 +static __always_inline int __intentional_overflow(-1) fls(int x)
77161 {
77162 int r = 32;
77163
77164 diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitops/fls64.h
77165 index b097cf8..3d40e14 100644
77166 --- a/include/asm-generic/bitops/fls64.h
77167 +++ b/include/asm-generic/bitops/fls64.h
77168 @@ -15,7 +15,7 @@
77169 * at position 64.
77170 */
77171 #if BITS_PER_LONG == 32
77172 -static __always_inline int fls64(__u64 x)
77173 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
77174 {
77175 __u32 h = x >> 32;
77176 if (h)
77177 @@ -23,7 +23,7 @@ static __always_inline int fls64(__u64 x)
77178 return fls(x);
77179 }
77180 #elif BITS_PER_LONG == 64
77181 -static __always_inline int fls64(__u64 x)
77182 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
77183 {
77184 if (x == 0)
77185 return 0;
77186 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
77187 index 1bfcfe5..e04c5c9 100644
77188 --- a/include/asm-generic/cache.h
77189 +++ b/include/asm-generic/cache.h
77190 @@ -6,7 +6,7 @@
77191 * cache lines need to provide their own cache.h.
77192 */
77193
77194 -#define L1_CACHE_SHIFT 5
77195 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
77196 +#define L1_CACHE_SHIFT 5UL
77197 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
77198
77199 #endif /* __ASM_GENERIC_CACHE_H */
77200 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
77201 index 0d68a1e..b74a761 100644
77202 --- a/include/asm-generic/emergency-restart.h
77203 +++ b/include/asm-generic/emergency-restart.h
77204 @@ -1,7 +1,7 @@
77205 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
77206 #define _ASM_GENERIC_EMERGENCY_RESTART_H
77207
77208 -static inline void machine_emergency_restart(void)
77209 +static inline __noreturn void machine_emergency_restart(void)
77210 {
77211 machine_restart(NULL);
77212 }
77213 diff --git a/include/asm-generic/io.h b/include/asm-generic/io.h
77214 index 975e1cc..0b8a083 100644
77215 --- a/include/asm-generic/io.h
77216 +++ b/include/asm-generic/io.h
77217 @@ -289,7 +289,7 @@ static inline void pci_iounmap(struct pci_dev *dev, void __iomem *p)
77218 * These are pretty trivial
77219 */
77220 #ifndef virt_to_phys
77221 -static inline unsigned long virt_to_phys(volatile void *address)
77222 +static inline unsigned long __intentional_overflow(-1) virt_to_phys(volatile void *address)
77223 {
77224 return __pa((unsigned long)address);
77225 }
77226 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
77227 index 90f99c7..00ce236 100644
77228 --- a/include/asm-generic/kmap_types.h
77229 +++ b/include/asm-generic/kmap_types.h
77230 @@ -2,9 +2,9 @@
77231 #define _ASM_GENERIC_KMAP_TYPES_H
77232
77233 #ifdef __WITH_KM_FENCE
77234 -# define KM_TYPE_NR 41
77235 +# define KM_TYPE_NR 42
77236 #else
77237 -# define KM_TYPE_NR 20
77238 +# define KM_TYPE_NR 21
77239 #endif
77240
77241 #endif
77242 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
77243 index 9ceb03b..62b0b8f 100644
77244 --- a/include/asm-generic/local.h
77245 +++ b/include/asm-generic/local.h
77246 @@ -23,24 +23,37 @@ typedef struct
77247 atomic_long_t a;
77248 } local_t;
77249
77250 +typedef struct {
77251 + atomic_long_unchecked_t a;
77252 +} local_unchecked_t;
77253 +
77254 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
77255
77256 #define local_read(l) atomic_long_read(&(l)->a)
77257 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
77258 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
77259 +#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
77260 #define local_inc(l) atomic_long_inc(&(l)->a)
77261 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
77262 #define local_dec(l) atomic_long_dec(&(l)->a)
77263 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
77264 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
77265 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
77266 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
77267 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
77268
77269 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
77270 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
77271 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
77272 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
77273 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
77274 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
77275 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
77276 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
77277 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
77278
77279 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
77280 +#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
77281 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
77282 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
77283 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
77284 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
77285 index 725612b..9cc513a 100644
77286 --- a/include/asm-generic/pgtable-nopmd.h
77287 +++ b/include/asm-generic/pgtable-nopmd.h
77288 @@ -1,14 +1,19 @@
77289 #ifndef _PGTABLE_NOPMD_H
77290 #define _PGTABLE_NOPMD_H
77291
77292 -#ifndef __ASSEMBLY__
77293 -
77294 #include <asm-generic/pgtable-nopud.h>
77295
77296 -struct mm_struct;
77297 -
77298 #define __PAGETABLE_PMD_FOLDED
77299
77300 +#define PMD_SHIFT PUD_SHIFT
77301 +#define PTRS_PER_PMD 1
77302 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
77303 +#define PMD_MASK (~(PMD_SIZE-1))
77304 +
77305 +#ifndef __ASSEMBLY__
77306 +
77307 +struct mm_struct;
77308 +
77309 /*
77310 * Having the pmd type consist of a pud gets the size right, and allows
77311 * us to conceptually access the pud entry that this pmd is folded into
77312 @@ -16,11 +21,6 @@ struct mm_struct;
77313 */
77314 typedef struct { pud_t pud; } pmd_t;
77315
77316 -#define PMD_SHIFT PUD_SHIFT
77317 -#define PTRS_PER_PMD 1
77318 -#define PMD_SIZE (1UL << PMD_SHIFT)
77319 -#define PMD_MASK (~(PMD_SIZE-1))
77320 -
77321 /*
77322 * The "pud_xxx()" functions here are trivial for a folded two-level
77323 * setup: the pmd is never bad, and a pmd always exists (as it's folded
77324 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
77325 index 810431d..0ec4804f 100644
77326 --- a/include/asm-generic/pgtable-nopud.h
77327 +++ b/include/asm-generic/pgtable-nopud.h
77328 @@ -1,10 +1,15 @@
77329 #ifndef _PGTABLE_NOPUD_H
77330 #define _PGTABLE_NOPUD_H
77331
77332 -#ifndef __ASSEMBLY__
77333 -
77334 #define __PAGETABLE_PUD_FOLDED
77335
77336 +#define PUD_SHIFT PGDIR_SHIFT
77337 +#define PTRS_PER_PUD 1
77338 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
77339 +#define PUD_MASK (~(PUD_SIZE-1))
77340 +
77341 +#ifndef __ASSEMBLY__
77342 +
77343 /*
77344 * Having the pud type consist of a pgd gets the size right, and allows
77345 * us to conceptually access the pgd entry that this pud is folded into
77346 @@ -12,11 +17,6 @@
77347 */
77348 typedef struct { pgd_t pgd; } pud_t;
77349
77350 -#define PUD_SHIFT PGDIR_SHIFT
77351 -#define PTRS_PER_PUD 1
77352 -#define PUD_SIZE (1UL << PUD_SHIFT)
77353 -#define PUD_MASK (~(PUD_SIZE-1))
77354 -
77355 /*
77356 * The "pgd_xxx()" functions here are trivial for a folded two-level
77357 * setup: the pud is never bad, and a pud always exists (as it's folded
77358 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
77359 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
77360
77361 #define pgd_populate(mm, pgd, pud) do { } while (0)
77362 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
77363 /*
77364 * (puds are folded into pgds so this doesn't get actually called,
77365 * but the define is needed for a generic inline function.)
77366 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
77367 index a8015a7..7a4407b 100644
77368 --- a/include/asm-generic/pgtable.h
77369 +++ b/include/asm-generic/pgtable.h
77370 @@ -815,6 +815,22 @@ static inline void pmdp_set_numa(struct mm_struct *mm, unsigned long addr,
77371 }
77372 #endif /* CONFIG_NUMA_BALANCING */
77373
77374 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
77375 +#ifdef CONFIG_PAX_KERNEXEC
77376 +#error KERNEXEC requires pax_open_kernel
77377 +#else
77378 +static inline unsigned long pax_open_kernel(void) { return 0; }
77379 +#endif
77380 +#endif
77381 +
77382 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
77383 +#ifdef CONFIG_PAX_KERNEXEC
77384 +#error KERNEXEC requires pax_close_kernel
77385 +#else
77386 +static inline unsigned long pax_close_kernel(void) { return 0; }
77387 +#endif
77388 +#endif
77389 +
77390 #endif /* CONFIG_MMU */
77391
77392 #endif /* !__ASSEMBLY__ */
77393 diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
77394 index 72d8803..cb9749c 100644
77395 --- a/include/asm-generic/uaccess.h
77396 +++ b/include/asm-generic/uaccess.h
77397 @@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
77398 return __clear_user(to, n);
77399 }
77400
77401 +#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
77402 +#ifdef CONFIG_PAX_MEMORY_UDEREF
77403 +#error UDEREF requires pax_open_userland
77404 +#else
77405 +static inline unsigned long pax_open_userland(void) { return 0; }
77406 +#endif
77407 +#endif
77408 +
77409 +#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
77410 +#ifdef CONFIG_PAX_MEMORY_UDEREF
77411 +#error UDEREF requires pax_close_userland
77412 +#else
77413 +static inline unsigned long pax_close_userland(void) { return 0; }
77414 +#endif
77415 +#endif
77416 +
77417 #endif /* __ASM_GENERIC_UACCESS_H */
77418 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
77419 index 146e4ff..f4f9609 100644
77420 --- a/include/asm-generic/vmlinux.lds.h
77421 +++ b/include/asm-generic/vmlinux.lds.h
77422 @@ -251,6 +251,7 @@
77423 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
77424 VMLINUX_SYMBOL(__start_rodata) = .; \
77425 *(.rodata) *(.rodata.*) \
77426 + *(.data..read_only) \
77427 *(__vermagic) /* Kernel version magic */ \
77428 . = ALIGN(8); \
77429 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
77430 @@ -737,17 +738,18 @@
77431 * section in the linker script will go there too. @phdr should have
77432 * a leading colon.
77433 *
77434 - * Note that this macros defines __per_cpu_load as an absolute symbol.
77435 + * Note that this macros defines per_cpu_load as an absolute symbol.
77436 * If there is no need to put the percpu section at a predetermined
77437 * address, use PERCPU_SECTION.
77438 */
77439 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
77440 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
77441 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
77442 + per_cpu_load = .; \
77443 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
77444 - LOAD_OFFSET) { \
77445 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
77446 PERCPU_INPUT(cacheline) \
77447 } phdr \
77448 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
77449 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
77450
77451 /**
77452 * PERCPU_SECTION - define output section for percpu area, simple version
77453 diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
77454 index 016c2f1..c4baa98 100644
77455 --- a/include/crypto/algapi.h
77456 +++ b/include/crypto/algapi.h
77457 @@ -34,7 +34,7 @@ struct crypto_type {
77458 unsigned int maskclear;
77459 unsigned int maskset;
77460 unsigned int tfmsize;
77461 -};
77462 +} __do_const;
77463
77464 struct crypto_instance {
77465 struct crypto_alg alg;
77466 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
77467 index a7c2a86..078f1b6 100644
77468 --- a/include/drm/drmP.h
77469 +++ b/include/drm/drmP.h
77470 @@ -68,6 +68,7 @@
77471 #include <linux/workqueue.h>
77472 #include <linux/poll.h>
77473 #include <asm/pgalloc.h>
77474 +#include <asm/local.h>
77475 #include <drm/drm.h>
77476 #include <drm/drm_sarea.h>
77477 #include <drm/drm_vma_manager.h>
77478 @@ -268,10 +269,12 @@ do { \
77479 * \param cmd command.
77480 * \param arg argument.
77481 */
77482 -typedef int drm_ioctl_t(struct drm_device *dev, void *data,
77483 +typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
77484 + struct drm_file *file_priv);
77485 +typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
77486 struct drm_file *file_priv);
77487
77488 -typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
77489 +typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
77490 unsigned long arg);
77491
77492 #define DRM_IOCTL_NR(n) _IOC_NR(n)
77493 @@ -287,10 +290,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
77494 struct drm_ioctl_desc {
77495 unsigned int cmd;
77496 int flags;
77497 - drm_ioctl_t *func;
77498 + drm_ioctl_t func;
77499 unsigned int cmd_drv;
77500 const char *name;
77501 -};
77502 +} __do_const;
77503
77504 /**
77505 * Creates a driver or general drm_ioctl_desc array entry for the given
77506 @@ -1001,7 +1004,8 @@ struct drm_info_list {
77507 int (*show)(struct seq_file*, void*); /** show callback */
77508 u32 driver_features; /**< Required driver features for this entry */
77509 void *data;
77510 -};
77511 +} __do_const;
77512 +typedef struct drm_info_list __no_const drm_info_list_no_const;
77513
77514 /**
77515 * debugfs node structure. This structure represents a debugfs file.
77516 @@ -1083,7 +1087,7 @@ struct drm_device {
77517
77518 /** \name Usage Counters */
77519 /*@{ */
77520 - int open_count; /**< Outstanding files open */
77521 + local_t open_count; /**< Outstanding files open */
77522 int buf_use; /**< Buffers in use -- cannot alloc */
77523 atomic_t buf_alloc; /**< Buffer allocation in progress */
77524 /*@} */
77525 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
77526 index 36a5feb..d9f01aa 100644
77527 --- a/include/drm/drm_crtc_helper.h
77528 +++ b/include/drm/drm_crtc_helper.h
77529 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
77530 struct drm_connector *connector);
77531 /* disable encoder when not in use - more explicit than dpms off */
77532 void (*disable)(struct drm_encoder *encoder);
77533 -};
77534 +} __no_const;
77535
77536 /**
77537 * drm_connector_helper_funcs - helper operations for connectors
77538 diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
77539 index 012d58f..d0a0642 100644
77540 --- a/include/drm/i915_pciids.h
77541 +++ b/include/drm/i915_pciids.h
77542 @@ -37,7 +37,7 @@
77543 */
77544 #define INTEL_VGA_DEVICE(id, info) { \
77545 0x8086, id, \
77546 - ~0, ~0, \
77547 + PCI_ANY_ID, PCI_ANY_ID, \
77548 0x030000, 0xff0000, \
77549 (unsigned long) info }
77550
77551 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
77552 index 72dcbe8..8db58d7 100644
77553 --- a/include/drm/ttm/ttm_memory.h
77554 +++ b/include/drm/ttm/ttm_memory.h
77555 @@ -48,7 +48,7 @@
77556
77557 struct ttm_mem_shrink {
77558 int (*do_shrink) (struct ttm_mem_shrink *);
77559 -};
77560 +} __no_const;
77561
77562 /**
77563 * struct ttm_mem_global - Global memory accounting structure.
77564 diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
77565 index 49a8284..9643967 100644
77566 --- a/include/drm/ttm/ttm_page_alloc.h
77567 +++ b/include/drm/ttm/ttm_page_alloc.h
77568 @@ -80,6 +80,7 @@ void ttm_dma_page_alloc_fini(void);
77569 */
77570 extern int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data);
77571
77572 +struct device;
77573 extern int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev);
77574 extern void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
77575
77576 diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
77577 index 4b840e8..155d235 100644
77578 --- a/include/keys/asymmetric-subtype.h
77579 +++ b/include/keys/asymmetric-subtype.h
77580 @@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
77581 /* Verify the signature on a key of this subtype (optional) */
77582 int (*verify_signature)(const struct key *key,
77583 const struct public_key_signature *sig);
77584 -};
77585 +} __do_const;
77586
77587 /**
77588 * asymmetric_key_subtype - Get the subtype from an asymmetric key
77589 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
77590 index c1da539..1dcec55 100644
77591 --- a/include/linux/atmdev.h
77592 +++ b/include/linux/atmdev.h
77593 @@ -28,7 +28,7 @@ struct compat_atm_iobuf {
77594 #endif
77595
77596 struct k_atm_aal_stats {
77597 -#define __HANDLE_ITEM(i) atomic_t i
77598 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
77599 __AAL_STAT_ITEMS
77600 #undef __HANDLE_ITEM
77601 };
77602 @@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
77603 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
77604 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
77605 struct module *owner;
77606 -};
77607 +} __do_const ;
77608
77609 struct atmphy_ops {
77610 int (*start)(struct atm_dev *dev);
77611 diff --git a/include/linux/audit.h b/include/linux/audit.h
77612 index 22cfddb..ab759e8 100644
77613 --- a/include/linux/audit.h
77614 +++ b/include/linux/audit.h
77615 @@ -210,7 +210,7 @@ static inline void audit_ptrace(struct task_struct *t)
77616 extern unsigned int audit_serial(void);
77617 extern int auditsc_get_stamp(struct audit_context *ctx,
77618 struct timespec *t, unsigned int *serial);
77619 -extern int audit_set_loginuid(kuid_t loginuid);
77620 +extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
77621
77622 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
77623 {
77624 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
77625 index 61f29e5..e67c658 100644
77626 --- a/include/linux/binfmts.h
77627 +++ b/include/linux/binfmts.h
77628 @@ -44,7 +44,7 @@ struct linux_binprm {
77629 unsigned interp_flags;
77630 unsigned interp_data;
77631 unsigned long loader, exec;
77632 -};
77633 +} __randomize_layout;
77634
77635 #define BINPRM_FLAGS_ENFORCE_NONDUMP_BIT 0
77636 #define BINPRM_FLAGS_ENFORCE_NONDUMP (1 << BINPRM_FLAGS_ENFORCE_NONDUMP_BIT)
77637 @@ -73,8 +73,10 @@ struct linux_binfmt {
77638 int (*load_binary)(struct linux_binprm *);
77639 int (*load_shlib)(struct file *);
77640 int (*core_dump)(struct coredump_params *cprm);
77641 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
77642 + void (*handle_mmap)(struct file *);
77643 unsigned long min_coredump; /* minimal dump size */
77644 -};
77645 +} __do_const __randomize_layout;
77646
77647 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
77648
77649 diff --git a/include/linux/bitops.h b/include/linux/bitops.h
77650 index be5fd38..d71192a 100644
77651 --- a/include/linux/bitops.h
77652 +++ b/include/linux/bitops.h
77653 @@ -102,7 +102,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
77654 * @word: value to rotate
77655 * @shift: bits to roll
77656 */
77657 -static inline __u32 rol32(__u32 word, unsigned int shift)
77658 +static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
77659 {
77660 return (word << shift) | (word >> (32 - shift));
77661 }
77662 @@ -112,7 +112,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
77663 * @word: value to rotate
77664 * @shift: bits to roll
77665 */
77666 -static inline __u32 ror32(__u32 word, unsigned int shift)
77667 +static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
77668 {
77669 return (word >> shift) | (word << (32 - shift));
77670 }
77671 @@ -168,7 +168,7 @@ static inline __s32 sign_extend32(__u32 value, int index)
77672 return (__s32)(value << shift) >> shift;
77673 }
77674
77675 -static inline unsigned fls_long(unsigned long l)
77676 +static inline unsigned __intentional_overflow(-1) fls_long(unsigned long l)
77677 {
77678 if (sizeof(l) == 4)
77679 return fls(l);
77680 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
77681 index 0d84981..bb741c0 100644
77682 --- a/include/linux/blkdev.h
77683 +++ b/include/linux/blkdev.h
77684 @@ -1584,7 +1584,7 @@ struct block_device_operations {
77685 /* this callback is with swap_lock and sometimes page table lock held */
77686 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
77687 struct module *owner;
77688 -};
77689 +} __do_const;
77690
77691 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
77692 unsigned long);
77693 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
77694 index afc1343..9735539 100644
77695 --- a/include/linux/blktrace_api.h
77696 +++ b/include/linux/blktrace_api.h
77697 @@ -25,7 +25,7 @@ struct blk_trace {
77698 struct dentry *dropped_file;
77699 struct dentry *msg_file;
77700 struct list_head running_list;
77701 - atomic_t dropped;
77702 + atomic_unchecked_t dropped;
77703 };
77704
77705 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
77706 diff --git a/include/linux/cache.h b/include/linux/cache.h
77707 index 17e7e82..1d7da26 100644
77708 --- a/include/linux/cache.h
77709 +++ b/include/linux/cache.h
77710 @@ -16,6 +16,14 @@
77711 #define __read_mostly
77712 #endif
77713
77714 +#ifndef __read_only
77715 +#ifdef CONFIG_PAX_KERNEXEC
77716 +#error KERNEXEC requires __read_only
77717 +#else
77718 +#define __read_only __read_mostly
77719 +#endif
77720 +#endif
77721 +
77722 #ifndef ____cacheline_aligned
77723 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
77724 #endif
77725 diff --git a/include/linux/capability.h b/include/linux/capability.h
77726 index 84b13ad..172cdee 100644
77727 --- a/include/linux/capability.h
77728 +++ b/include/linux/capability.h
77729 @@ -211,9 +211,14 @@ extern bool has_ns_capability_noaudit(struct task_struct *t,
77730 extern bool capable(int cap);
77731 extern bool ns_capable(struct user_namespace *ns, int cap);
77732 extern bool capable_wrt_inode_uidgid(const struct inode *inode, int cap);
77733 +extern bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap);
77734 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
77735 +extern bool capable_nolog(int cap);
77736 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
77737
77738 /* audit system wants to get cap info from files as well */
77739 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
77740
77741 +extern int is_privileged_binary(const struct dentry *dentry);
77742 +
77743 #endif /* !_LINUX_CAPABILITY_H */
77744 diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
77745 index 8609d57..86e4d79 100644
77746 --- a/include/linux/cdrom.h
77747 +++ b/include/linux/cdrom.h
77748 @@ -87,7 +87,6 @@ struct cdrom_device_ops {
77749
77750 /* driver specifications */
77751 const int capability; /* capability flags */
77752 - int n_minors; /* number of active minor devices */
77753 /* handle uniform packets for scsi type devices (scsi,atapi) */
77754 int (*generic_packet) (struct cdrom_device_info *,
77755 struct packet_command *);
77756 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
77757 index 4ce9056..86caac6 100644
77758 --- a/include/linux/cleancache.h
77759 +++ b/include/linux/cleancache.h
77760 @@ -31,7 +31,7 @@ struct cleancache_ops {
77761 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
77762 void (*invalidate_inode)(int, struct cleancache_filekey);
77763 void (*invalidate_fs)(int);
77764 -};
77765 +} __no_const;
77766
77767 extern struct cleancache_ops *
77768 cleancache_register_ops(struct cleancache_ops *ops);
77769 diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
77770 index 5119174..8e264f8 100644
77771 --- a/include/linux/clk-provider.h
77772 +++ b/include/linux/clk-provider.h
77773 @@ -174,6 +174,7 @@ struct clk_ops {
77774 void (*init)(struct clk_hw *hw);
77775 int (*debug_init)(struct clk_hw *hw, struct dentry *dentry);
77776 };
77777 +typedef struct clk_ops __no_const clk_ops_no_const;
77778
77779 /**
77780 * struct clk_init_data - holds init data that's common to all clocks and is
77781 diff --git a/include/linux/compat.h b/include/linux/compat.h
77782 index e649426..a74047b 100644
77783 --- a/include/linux/compat.h
77784 +++ b/include/linux/compat.h
77785 @@ -316,7 +316,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
77786 compat_size_t __user *len_ptr);
77787
77788 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
77789 -asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
77790 +asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
77791 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
77792 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
77793 compat_ssize_t msgsz, int msgflg);
77794 @@ -436,7 +436,7 @@ extern int compat_ptrace_request(struct task_struct *child,
77795 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
77796 compat_ulong_t addr, compat_ulong_t data);
77797 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
77798 - compat_long_t addr, compat_long_t data);
77799 + compat_ulong_t addr, compat_ulong_t data);
77800
77801 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, compat_size_t);
77802 /*
77803 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
77804 index 2507fd2..55203f8 100644
77805 --- a/include/linux/compiler-gcc4.h
77806 +++ b/include/linux/compiler-gcc4.h
77807 @@ -39,9 +39,34 @@
77808 # define __compiletime_warning(message) __attribute__((warning(message)))
77809 # define __compiletime_error(message) __attribute__((error(message)))
77810 #endif /* __CHECKER__ */
77811 +
77812 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
77813 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
77814 +#define __bos0(ptr) __bos((ptr), 0)
77815 +#define __bos1(ptr) __bos((ptr), 1)
77816 #endif /* GCC_VERSION >= 40300 */
77817
77818 #if GCC_VERSION >= 40500
77819 +
77820 +#ifdef RANDSTRUCT_PLUGIN
77821 +#define __randomize_layout __attribute__((randomize_layout))
77822 +#define __no_randomize_layout __attribute__((no_randomize_layout))
77823 +#endif
77824 +
77825 +#ifdef CONSTIFY_PLUGIN
77826 +#define __no_const __attribute__((no_const))
77827 +#define __do_const __attribute__((do_const))
77828 +#endif
77829 +
77830 +#ifdef SIZE_OVERFLOW_PLUGIN
77831 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
77832 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
77833 +#endif
77834 +
77835 +#ifdef LATENT_ENTROPY_PLUGIN
77836 +#define __latent_entropy __attribute__((latent_entropy))
77837 +#endif
77838 +
77839 /*
77840 * Mark a position in code as unreachable. This can be used to
77841 * suppress control flow warnings after asm blocks that transfer
77842 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
77843 index ee7239e..7c11769 100644
77844 --- a/include/linux/compiler.h
77845 +++ b/include/linux/compiler.h
77846 @@ -5,11 +5,14 @@
77847
77848 #ifdef __CHECKER__
77849 # define __user __attribute__((noderef, address_space(1)))
77850 +# define __force_user __force __user
77851 # define __kernel __attribute__((address_space(0)))
77852 +# define __force_kernel __force __kernel
77853 # define __safe __attribute__((safe))
77854 # define __force __attribute__((force))
77855 # define __nocast __attribute__((nocast))
77856 # define __iomem __attribute__((noderef, address_space(2)))
77857 +# define __force_iomem __force __iomem
77858 # define __must_hold(x) __attribute__((context(x,1,1)))
77859 # define __acquires(x) __attribute__((context(x,0,1)))
77860 # define __releases(x) __attribute__((context(x,1,0)))
77861 @@ -17,20 +20,37 @@
77862 # define __release(x) __context__(x,-1)
77863 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
77864 # define __percpu __attribute__((noderef, address_space(3)))
77865 +# define __force_percpu __force __percpu
77866 #ifdef CONFIG_SPARSE_RCU_POINTER
77867 # define __rcu __attribute__((noderef, address_space(4)))
77868 +# define __force_rcu __force __rcu
77869 #else
77870 # define __rcu
77871 +# define __force_rcu
77872 #endif
77873 extern void __chk_user_ptr(const volatile void __user *);
77874 extern void __chk_io_ptr(const volatile void __iomem *);
77875 #else
77876 -# define __user
77877 -# define __kernel
77878 +# ifdef CHECKER_PLUGIN
77879 +//# define __user
77880 +//# define __force_user
77881 +//# define __kernel
77882 +//# define __force_kernel
77883 +# else
77884 +# ifdef STRUCTLEAK_PLUGIN
77885 +# define __user __attribute__((user))
77886 +# else
77887 +# define __user
77888 +# endif
77889 +# define __force_user
77890 +# define __kernel
77891 +# define __force_kernel
77892 +# endif
77893 # define __safe
77894 # define __force
77895 # define __nocast
77896 # define __iomem
77897 +# define __force_iomem
77898 # define __chk_user_ptr(x) (void)0
77899 # define __chk_io_ptr(x) (void)0
77900 # define __builtin_warning(x, y...) (1)
77901 @@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
77902 # define __release(x) (void)0
77903 # define __cond_lock(x,c) (c)
77904 # define __percpu
77905 +# define __force_percpu
77906 # define __rcu
77907 +# define __force_rcu
77908 #endif
77909
77910 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
77911 @@ -286,6 +308,34 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
77912 # define __attribute_const__ /* unimplemented */
77913 #endif
77914
77915 +#ifndef __randomize_layout
77916 +# define __randomize_layout
77917 +#endif
77918 +
77919 +#ifndef __no_randomize_layout
77920 +# define __no_randomize_layout
77921 +#endif
77922 +
77923 +#ifndef __no_const
77924 +# define __no_const
77925 +#endif
77926 +
77927 +#ifndef __do_const
77928 +# define __do_const
77929 +#endif
77930 +
77931 +#ifndef __size_overflow
77932 +# define __size_overflow(...)
77933 +#endif
77934 +
77935 +#ifndef __intentional_overflow
77936 +# define __intentional_overflow(...)
77937 +#endif
77938 +
77939 +#ifndef __latent_entropy
77940 +# define __latent_entropy
77941 +#endif
77942 +
77943 /*
77944 * Tell gcc if a function is cold. The compiler will assume any path
77945 * directly leading to the call is unlikely.
77946 @@ -295,6 +345,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
77947 #define __cold
77948 #endif
77949
77950 +#ifndef __alloc_size
77951 +#define __alloc_size(...)
77952 +#endif
77953 +
77954 +#ifndef __bos
77955 +#define __bos(ptr, arg)
77956 +#endif
77957 +
77958 +#ifndef __bos0
77959 +#define __bos0(ptr)
77960 +#endif
77961 +
77962 +#ifndef __bos1
77963 +#define __bos1(ptr)
77964 +#endif
77965 +
77966 /* Simple shorthand for a section definition */
77967 #ifndef __section
77968 # define __section(S) __attribute__ ((__section__(#S)))
77969 @@ -369,7 +435,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
77970 * use is to mediate communication between process-level code and irq/NMI
77971 * handlers, all running on the same CPU.
77972 */
77973 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
77974 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
77975 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
77976
77977 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
77978 #ifdef CONFIG_KPROBES
77979 diff --git a/include/linux/completion.h b/include/linux/completion.h
77980 index 5d5aaae..0ea9b84 100644
77981 --- a/include/linux/completion.h
77982 +++ b/include/linux/completion.h
77983 @@ -90,16 +90,16 @@ static inline void reinit_completion(struct completion *x)
77984
77985 extern void wait_for_completion(struct completion *);
77986 extern void wait_for_completion_io(struct completion *);
77987 -extern int wait_for_completion_interruptible(struct completion *x);
77988 -extern int wait_for_completion_killable(struct completion *x);
77989 +extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
77990 +extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
77991 extern unsigned long wait_for_completion_timeout(struct completion *x,
77992 - unsigned long timeout);
77993 + unsigned long timeout) __intentional_overflow(-1);
77994 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
77995 - unsigned long timeout);
77996 + unsigned long timeout) __intentional_overflow(-1);
77997 extern long wait_for_completion_interruptible_timeout(
77998 - struct completion *x, unsigned long timeout);
77999 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
78000 extern long wait_for_completion_killable_timeout(
78001 - struct completion *x, unsigned long timeout);
78002 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
78003 extern bool try_wait_for_completion(struct completion *x);
78004 extern bool completion_done(struct completion *x);
78005
78006 diff --git a/include/linux/configfs.h b/include/linux/configfs.h
78007 index 34025df..d94bbbc 100644
78008 --- a/include/linux/configfs.h
78009 +++ b/include/linux/configfs.h
78010 @@ -125,7 +125,7 @@ struct configfs_attribute {
78011 const char *ca_name;
78012 struct module *ca_owner;
78013 umode_t ca_mode;
78014 -};
78015 +} __do_const;
78016
78017 /*
78018 * Users often need to create attribute structures for their configurable
78019 diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
78020 index 5ae5100..b809662 100644
78021 --- a/include/linux/cpufreq.h
78022 +++ b/include/linux/cpufreq.h
78023 @@ -200,6 +200,7 @@ struct global_attr {
78024 ssize_t (*store)(struct kobject *a, struct attribute *b,
78025 const char *c, size_t count);
78026 };
78027 +typedef struct global_attr __no_const global_attr_no_const;
78028
78029 #define define_one_global_ro(_name) \
78030 static struct global_attr _name = \
78031 @@ -242,7 +243,7 @@ struct cpufreq_driver {
78032 bool boost_supported;
78033 bool boost_enabled;
78034 int (*set_boost) (int state);
78035 -};
78036 +} __do_const;
78037
78038 /* flags */
78039 #define CPUFREQ_STICKY (1 << 0) /* driver isn't removed even if
78040 diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
78041 index b0238cb..db89e1e 100644
78042 --- a/include/linux/cpuidle.h
78043 +++ b/include/linux/cpuidle.h
78044 @@ -50,7 +50,8 @@ struct cpuidle_state {
78045 int index);
78046
78047 int (*enter_dead) (struct cpuidle_device *dev, int index);
78048 -};
78049 +} __do_const;
78050 +typedef struct cpuidle_state __no_const cpuidle_state_no_const;
78051
78052 /* Idle State Flags */
78053 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
78054 @@ -211,7 +212,7 @@ struct cpuidle_governor {
78055 void (*reflect) (struct cpuidle_device *dev, int index);
78056
78057 struct module *owner;
78058 -};
78059 +} __do_const;
78060
78061 #ifdef CONFIG_CPU_IDLE
78062 extern int cpuidle_register_governor(struct cpuidle_governor *gov);
78063 diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
78064 index d08e4d2..95fad61 100644
78065 --- a/include/linux/cpumask.h
78066 +++ b/include/linux/cpumask.h
78067 @@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
78068 }
78069
78070 /* Valid inputs for n are -1 and 0. */
78071 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
78072 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
78073 {
78074 return n+1;
78075 }
78076
78077 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
78078 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
78079 {
78080 return n+1;
78081 }
78082
78083 -static inline unsigned int cpumask_next_and(int n,
78084 +static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
78085 const struct cpumask *srcp,
78086 const struct cpumask *andp)
78087 {
78088 @@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
78089 *
78090 * Returns >= nr_cpu_ids if no further cpus set.
78091 */
78092 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
78093 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
78094 {
78095 /* -1 is a legal arg here. */
78096 if (n != -1)
78097 @@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
78098 *
78099 * Returns >= nr_cpu_ids if no further cpus unset.
78100 */
78101 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
78102 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
78103 {
78104 /* -1 is a legal arg here. */
78105 if (n != -1)
78106 @@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
78107 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
78108 }
78109
78110 -int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
78111 +int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
78112 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
78113
78114 /**
78115 diff --git a/include/linux/cred.h b/include/linux/cred.h
78116 index f61d6c8..d372d95 100644
78117 --- a/include/linux/cred.h
78118 +++ b/include/linux/cred.h
78119 @@ -35,7 +35,7 @@ struct group_info {
78120 int nblocks;
78121 kgid_t small_block[NGROUPS_SMALL];
78122 kgid_t *blocks[0];
78123 -};
78124 +} __randomize_layout;
78125
78126 /**
78127 * get_group_info - Get a reference to a group info structure
78128 @@ -136,7 +136,7 @@ struct cred {
78129 struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
78130 struct group_info *group_info; /* supplementary groups for euid/fsgid */
78131 struct rcu_head rcu; /* RCU deletion hook */
78132 -};
78133 +} __randomize_layout;
78134
78135 extern void __put_cred(struct cred *);
78136 extern void exit_creds(struct task_struct *);
78137 @@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
78138 static inline void validate_process_creds(void)
78139 {
78140 }
78141 +static inline void validate_task_creds(struct task_struct *task)
78142 +{
78143 +}
78144 #endif
78145
78146 /**
78147 @@ -322,6 +325,7 @@ static inline void put_cred(const struct cred *_cred)
78148
78149 #define task_uid(task) (task_cred_xxx((task), uid))
78150 #define task_euid(task) (task_cred_xxx((task), euid))
78151 +#define task_securebits(task) (task_cred_xxx((task), securebits))
78152
78153 #define current_cred_xxx(xxx) \
78154 ({ \
78155 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
78156 index b92eadf..b4ecdc1 100644
78157 --- a/include/linux/crypto.h
78158 +++ b/include/linux/crypto.h
78159 @@ -373,7 +373,7 @@ struct cipher_tfm {
78160 const u8 *key, unsigned int keylen);
78161 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
78162 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
78163 -};
78164 +} __no_const;
78165
78166 struct hash_tfm {
78167 int (*init)(struct hash_desc *desc);
78168 @@ -394,13 +394,13 @@ struct compress_tfm {
78169 int (*cot_decompress)(struct crypto_tfm *tfm,
78170 const u8 *src, unsigned int slen,
78171 u8 *dst, unsigned int *dlen);
78172 -};
78173 +} __no_const;
78174
78175 struct rng_tfm {
78176 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
78177 unsigned int dlen);
78178 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
78179 -};
78180 +} __no_const;
78181
78182 #define crt_ablkcipher crt_u.ablkcipher
78183 #define crt_aead crt_u.aead
78184 diff --git a/include/linux/ctype.h b/include/linux/ctype.h
78185 index 653589e..4ef254a 100644
78186 --- a/include/linux/ctype.h
78187 +++ b/include/linux/ctype.h
78188 @@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
78189 * Fast implementation of tolower() for internal usage. Do not use in your
78190 * code.
78191 */
78192 -static inline char _tolower(const char c)
78193 +static inline unsigned char _tolower(const unsigned char c)
78194 {
78195 return c | 0x20;
78196 }
78197 diff --git a/include/linux/dcache.h b/include/linux/dcache.h
78198 index 3c7ec32..4ca97cc 100644
78199 --- a/include/linux/dcache.h
78200 +++ b/include/linux/dcache.h
78201 @@ -133,7 +133,7 @@ struct dentry {
78202 } d_u;
78203 struct list_head d_subdirs; /* our children */
78204 struct hlist_node d_alias; /* inode alias list */
78205 -};
78206 +} __randomize_layout;
78207
78208 /*
78209 * dentry->d_lock spinlock nesting subclasses:
78210 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
78211 index 7925bf0..d5143d2 100644
78212 --- a/include/linux/decompress/mm.h
78213 +++ b/include/linux/decompress/mm.h
78214 @@ -77,7 +77,7 @@ static void free(void *where)
78215 * warnings when not needed (indeed large_malloc / large_free are not
78216 * needed by inflate */
78217
78218 -#define malloc(a) kmalloc(a, GFP_KERNEL)
78219 +#define malloc(a) kmalloc((a), GFP_KERNEL)
78220 #define free(a) kfree(a)
78221
78222 #define large_malloc(a) vmalloc(a)
78223 diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
78224 index d48dc00..211ee54 100644
78225 --- a/include/linux/devfreq.h
78226 +++ b/include/linux/devfreq.h
78227 @@ -114,7 +114,7 @@ struct devfreq_governor {
78228 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
78229 int (*event_handler)(struct devfreq *devfreq,
78230 unsigned int event, void *data);
78231 -};
78232 +} __do_const;
78233
78234 /**
78235 * struct devfreq - Device devfreq structure
78236 diff --git a/include/linux/device.h b/include/linux/device.h
78237 index d1d1c05..a90fdb0 100644
78238 --- a/include/linux/device.h
78239 +++ b/include/linux/device.h
78240 @@ -310,7 +310,7 @@ struct subsys_interface {
78241 struct list_head node;
78242 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
78243 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
78244 -};
78245 +} __do_const;
78246
78247 int subsys_interface_register(struct subsys_interface *sif);
78248 void subsys_interface_unregister(struct subsys_interface *sif);
78249 @@ -506,7 +506,7 @@ struct device_type {
78250 void (*release)(struct device *dev);
78251
78252 const struct dev_pm_ops *pm;
78253 -};
78254 +} __do_const;
78255
78256 /* interface for exporting device attributes */
78257 struct device_attribute {
78258 @@ -516,11 +516,12 @@ struct device_attribute {
78259 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
78260 const char *buf, size_t count);
78261 };
78262 +typedef struct device_attribute __no_const device_attribute_no_const;
78263
78264 struct dev_ext_attribute {
78265 struct device_attribute attr;
78266 void *var;
78267 -};
78268 +} __do_const;
78269
78270 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
78271 char *buf);
78272 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
78273 index fd4aee2..1f28db9 100644
78274 --- a/include/linux/dma-mapping.h
78275 +++ b/include/linux/dma-mapping.h
78276 @@ -54,7 +54,7 @@ struct dma_map_ops {
78277 u64 (*get_required_mask)(struct device *dev);
78278 #endif
78279 int is_phys;
78280 -};
78281 +} __do_const;
78282
78283 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
78284
78285 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
78286 index 72cb0dd..7fe9a4b 100644
78287 --- a/include/linux/dmaengine.h
78288 +++ b/include/linux/dmaengine.h
78289 @@ -1147,9 +1147,9 @@ struct dma_pinned_list {
78290 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
78291 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
78292
78293 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
78294 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
78295 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
78296 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
78297 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
78298 struct dma_pinned_list *pinned_list, struct page *page,
78299 unsigned int offset, size_t len);
78300
78301 diff --git a/include/linux/efi.h b/include/linux/efi.h
78302 index 6c100ff..e3289b4 100644
78303 --- a/include/linux/efi.h
78304 +++ b/include/linux/efi.h
78305 @@ -1009,6 +1009,7 @@ struct efivar_operations {
78306 efi_set_variable_t *set_variable;
78307 efi_query_variable_store_t *query_variable_store;
78308 };
78309 +typedef struct efivar_operations __no_const efivar_operations_no_const;
78310
78311 struct efivars {
78312 /*
78313 diff --git a/include/linux/elf.h b/include/linux/elf.h
78314 index 67a5fa7..b817372 100644
78315 --- a/include/linux/elf.h
78316 +++ b/include/linux/elf.h
78317 @@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
78318 #define elf_note elf32_note
78319 #define elf_addr_t Elf32_Off
78320 #define Elf_Half Elf32_Half
78321 +#define elf_dyn Elf32_Dyn
78322
78323 #else
78324
78325 @@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
78326 #define elf_note elf64_note
78327 #define elf_addr_t Elf64_Off
78328 #define Elf_Half Elf64_Half
78329 +#define elf_dyn Elf64_Dyn
78330
78331 #endif
78332
78333 diff --git a/include/linux/err.h b/include/linux/err.h
78334 index a729120..6ede2c9 100644
78335 --- a/include/linux/err.h
78336 +++ b/include/linux/err.h
78337 @@ -20,12 +20,12 @@
78338
78339 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
78340
78341 -static inline void * __must_check ERR_PTR(long error)
78342 +static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
78343 {
78344 return (void *) error;
78345 }
78346
78347 -static inline long __must_check PTR_ERR(__force const void *ptr)
78348 +static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
78349 {
78350 return (long) ptr;
78351 }
78352 diff --git a/include/linux/extcon.h b/include/linux/extcon.h
78353 index f488145..3b6b04e 100644
78354 --- a/include/linux/extcon.h
78355 +++ b/include/linux/extcon.h
78356 @@ -135,7 +135,7 @@ struct extcon_dev {
78357 /* /sys/class/extcon/.../mutually_exclusive/... */
78358 struct attribute_group attr_g_muex;
78359 struct attribute **attrs_muex;
78360 - struct device_attribute *d_attrs_muex;
78361 + device_attribute_no_const *d_attrs_muex;
78362 };
78363
78364 /**
78365 diff --git a/include/linux/fb.h b/include/linux/fb.h
78366 index fe6ac95..898d41d 100644
78367 --- a/include/linux/fb.h
78368 +++ b/include/linux/fb.h
78369 @@ -304,7 +304,7 @@ struct fb_ops {
78370 /* called at KDB enter and leave time to prepare the console */
78371 int (*fb_debug_enter)(struct fb_info *info);
78372 int (*fb_debug_leave)(struct fb_info *info);
78373 -};
78374 +} __do_const;
78375
78376 #ifdef CONFIG_FB_TILEBLITTING
78377 #define FB_TILE_CURSOR_NONE 0
78378 diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
78379 index 230f87b..1fd0485 100644
78380 --- a/include/linux/fdtable.h
78381 +++ b/include/linux/fdtable.h
78382 @@ -100,7 +100,7 @@ struct files_struct *get_files_struct(struct task_struct *);
78383 void put_files_struct(struct files_struct *fs);
78384 void reset_files_struct(struct files_struct *);
78385 int unshare_files(struct files_struct **);
78386 -struct files_struct *dup_fd(struct files_struct *, int *);
78387 +struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
78388 void do_close_on_exec(struct files_struct *);
78389 int iterate_fd(struct files_struct *, unsigned,
78390 int (*)(const void *, struct file *, unsigned),
78391 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
78392 index 8293262..2b3b8bd 100644
78393 --- a/include/linux/frontswap.h
78394 +++ b/include/linux/frontswap.h
78395 @@ -11,7 +11,7 @@ struct frontswap_ops {
78396 int (*load)(unsigned, pgoff_t, struct page *);
78397 void (*invalidate_page)(unsigned, pgoff_t);
78398 void (*invalidate_area)(unsigned);
78399 -};
78400 +} __no_const;
78401
78402 extern bool frontswap_enabled;
78403 extern struct frontswap_ops *
78404 diff --git a/include/linux/fs.h b/include/linux/fs.h
78405 index 8780312..425cc22 100644
78406 --- a/include/linux/fs.h
78407 +++ b/include/linux/fs.h
78408 @@ -398,7 +398,7 @@ struct address_space {
78409 spinlock_t private_lock; /* for use by the address_space */
78410 struct list_head private_list; /* ditto */
78411 void *private_data; /* ditto */
78412 -} __attribute__((aligned(sizeof(long))));
78413 +} __attribute__((aligned(sizeof(long)))) __randomize_layout;
78414 /*
78415 * On most architectures that alignment is already the case; but
78416 * must be enforced here for CRIS, to let the least significant bit
78417 @@ -441,7 +441,7 @@ struct block_device {
78418 int bd_fsfreeze_count;
78419 /* Mutex for freeze */
78420 struct mutex bd_fsfreeze_mutex;
78421 -};
78422 +} __randomize_layout;
78423
78424 /*
78425 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
78426 @@ -585,7 +585,7 @@ struct inode {
78427 #endif
78428
78429 void *i_private; /* fs or device private pointer */
78430 -};
78431 +} __randomize_layout;
78432
78433 static inline int inode_unhashed(struct inode *inode)
78434 {
78435 @@ -778,7 +778,7 @@ struct file {
78436 struct list_head f_tfile_llink;
78437 #endif /* #ifdef CONFIG_EPOLL */
78438 struct address_space *f_mapping;
78439 -} __attribute__((aligned(4))); /* lest something weird decides that 2 is OK */
78440 +} __attribute__((aligned(4))) __randomize_layout; /* lest something weird decides that 2 is OK */
78441
78442 struct file_handle {
78443 __u32 handle_bytes;
78444 @@ -906,7 +906,7 @@ struct file_lock {
78445 int state; /* state of grant or error if -ve */
78446 } afs;
78447 } fl_u;
78448 -};
78449 +} __randomize_layout;
78450
78451 /* The following constant reflects the upper bound of the file/locking space */
78452 #ifndef OFFSET_MAX
78453 @@ -1255,7 +1255,7 @@ struct super_block {
78454 struct list_lru s_dentry_lru ____cacheline_aligned_in_smp;
78455 struct list_lru s_inode_lru ____cacheline_aligned_in_smp;
78456 struct rcu_head rcu;
78457 -};
78458 +} __randomize_layout;
78459
78460 extern struct timespec current_fs_time(struct super_block *sb);
78461
78462 @@ -1477,7 +1477,8 @@ struct file_operations {
78463 long (*fallocate)(struct file *file, int mode, loff_t offset,
78464 loff_t len);
78465 int (*show_fdinfo)(struct seq_file *m, struct file *f);
78466 -};
78467 +} __do_const __randomize_layout;
78468 +typedef struct file_operations __no_const file_operations_no_const;
78469
78470 struct inode_operations {
78471 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
78472 @@ -2757,4 +2758,14 @@ static inline bool dir_relax(struct inode *inode)
78473 return !IS_DEADDIR(inode);
78474 }
78475
78476 +static inline bool is_sidechannel_device(const struct inode *inode)
78477 +{
78478 +#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
78479 + umode_t mode = inode->i_mode;
78480 + return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
78481 +#else
78482 + return false;
78483 +#endif
78484 +}
78485 +
78486 #endif /* _LINUX_FS_H */
78487 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
78488 index 0efc3e6..fd23610 100644
78489 --- a/include/linux/fs_struct.h
78490 +++ b/include/linux/fs_struct.h
78491 @@ -6,13 +6,13 @@
78492 #include <linux/seqlock.h>
78493
78494 struct fs_struct {
78495 - int users;
78496 + atomic_t users;
78497 spinlock_t lock;
78498 seqcount_t seq;
78499 int umask;
78500 int in_exec;
78501 struct path root, pwd;
78502 -};
78503 +} __randomize_layout;
78504
78505 extern struct kmem_cache *fs_cachep;
78506
78507 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
78508 index 7714849..a4a5c7a 100644
78509 --- a/include/linux/fscache-cache.h
78510 +++ b/include/linux/fscache-cache.h
78511 @@ -113,7 +113,7 @@ struct fscache_operation {
78512 fscache_operation_release_t release;
78513 };
78514
78515 -extern atomic_t fscache_op_debug_id;
78516 +extern atomic_unchecked_t fscache_op_debug_id;
78517 extern void fscache_op_work_func(struct work_struct *work);
78518
78519 extern void fscache_enqueue_operation(struct fscache_operation *);
78520 @@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
78521 INIT_WORK(&op->work, fscache_op_work_func);
78522 atomic_set(&op->usage, 1);
78523 op->state = FSCACHE_OP_ST_INITIALISED;
78524 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
78525 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
78526 op->processor = processor;
78527 op->release = release;
78528 INIT_LIST_HEAD(&op->pend_link);
78529 diff --git a/include/linux/fscache.h b/include/linux/fscache.h
78530 index 115bb81..e7b812b 100644
78531 --- a/include/linux/fscache.h
78532 +++ b/include/linux/fscache.h
78533 @@ -152,7 +152,7 @@ struct fscache_cookie_def {
78534 * - this is mandatory for any object that may have data
78535 */
78536 void (*now_uncached)(void *cookie_netfs_data);
78537 -};
78538 +} __do_const;
78539
78540 /*
78541 * fscache cached network filesystem type
78542 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
78543 index 1c804b0..1432c2b 100644
78544 --- a/include/linux/fsnotify.h
78545 +++ b/include/linux/fsnotify.h
78546 @@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
78547 struct inode *inode = file_inode(file);
78548 __u32 mask = FS_ACCESS;
78549
78550 + if (is_sidechannel_device(inode))
78551 + return;
78552 +
78553 if (S_ISDIR(inode->i_mode))
78554 mask |= FS_ISDIR;
78555
78556 @@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
78557 struct inode *inode = file_inode(file);
78558 __u32 mask = FS_MODIFY;
78559
78560 + if (is_sidechannel_device(inode))
78561 + return;
78562 +
78563 if (S_ISDIR(inode->i_mode))
78564 mask |= FS_ISDIR;
78565
78566 @@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
78567 */
78568 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
78569 {
78570 - return kstrdup(name, GFP_KERNEL);
78571 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
78572 }
78573
78574 /*
78575 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
78576 index 9f3c275..8bdff5d 100644
78577 --- a/include/linux/genhd.h
78578 +++ b/include/linux/genhd.h
78579 @@ -194,7 +194,7 @@ struct gendisk {
78580 struct kobject *slave_dir;
78581
78582 struct timer_rand_state *random;
78583 - atomic_t sync_io; /* RAID */
78584 + atomic_unchecked_t sync_io; /* RAID */
78585 struct disk_events *ev;
78586 #ifdef CONFIG_BLK_DEV_INTEGRITY
78587 struct blk_integrity *integrity;
78588 @@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
78589 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
78590
78591 /* drivers/char/random.c */
78592 -extern void add_disk_randomness(struct gendisk *disk);
78593 +extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
78594 extern void rand_initialize_disk(struct gendisk *disk);
78595
78596 static inline sector_t get_start_sect(struct block_device *bdev)
78597 diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
78598 index c0894dd..2fbf10c 100644
78599 --- a/include/linux/genl_magic_func.h
78600 +++ b/include/linux/genl_magic_func.h
78601 @@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
78602 },
78603
78604 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
78605 -static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
78606 +static struct genl_ops ZZZ_genl_ops[] = {
78607 #include GENL_MAGIC_INCLUDE_FILE
78608 };
78609
78610 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
78611 index 39b81dc..819dc51 100644
78612 --- a/include/linux/gfp.h
78613 +++ b/include/linux/gfp.h
78614 @@ -36,6 +36,13 @@ struct vm_area_struct;
78615 #define ___GFP_NO_KSWAPD 0x400000u
78616 #define ___GFP_OTHER_NODE 0x800000u
78617 #define ___GFP_WRITE 0x1000000u
78618 +
78619 +#ifdef CONFIG_PAX_USERCOPY_SLABS
78620 +#define ___GFP_USERCOPY 0x2000000u
78621 +#else
78622 +#define ___GFP_USERCOPY 0
78623 +#endif
78624 +
78625 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
78626
78627 /*
78628 @@ -93,6 +100,7 @@ struct vm_area_struct;
78629 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
78630 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
78631 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
78632 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
78633
78634 /*
78635 * This may seem redundant, but it's a way of annotating false positives vs.
78636 @@ -100,7 +108,7 @@ struct vm_area_struct;
78637 */
78638 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
78639
78640 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
78641 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
78642 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
78643
78644 /* This equals 0, but use constants in case they ever change */
78645 @@ -158,6 +166,8 @@ struct vm_area_struct;
78646 /* 4GB DMA on some platforms */
78647 #define GFP_DMA32 __GFP_DMA32
78648
78649 +#define GFP_USERCOPY __GFP_USERCOPY
78650 +
78651 /* Convert GFP flags to their corresponding migrate type */
78652 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
78653 {
78654 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
78655 new file mode 100644
78656 index 0000000..edb2cb6
78657 --- /dev/null
78658 +++ b/include/linux/gracl.h
78659 @@ -0,0 +1,340 @@
78660 +#ifndef GR_ACL_H
78661 +#define GR_ACL_H
78662 +
78663 +#include <linux/grdefs.h>
78664 +#include <linux/resource.h>
78665 +#include <linux/capability.h>
78666 +#include <linux/dcache.h>
78667 +#include <asm/resource.h>
78668 +
78669 +/* Major status information */
78670 +
78671 +#define GR_VERSION "grsecurity 3.0"
78672 +#define GRSECURITY_VERSION 0x3000
78673 +
78674 +enum {
78675 + GR_SHUTDOWN = 0,
78676 + GR_ENABLE = 1,
78677 + GR_SPROLE = 2,
78678 + GR_OLDRELOAD = 3,
78679 + GR_SEGVMOD = 4,
78680 + GR_STATUS = 5,
78681 + GR_UNSPROLE = 6,
78682 + GR_PASSSET = 7,
78683 + GR_SPROLEPAM = 8,
78684 + GR_RELOAD = 9,
78685 +};
78686 +
78687 +/* Password setup definitions
78688 + * kernel/grhash.c */
78689 +enum {
78690 + GR_PW_LEN = 128,
78691 + GR_SALT_LEN = 16,
78692 + GR_SHA_LEN = 32,
78693 +};
78694 +
78695 +enum {
78696 + GR_SPROLE_LEN = 64,
78697 +};
78698 +
78699 +enum {
78700 + GR_NO_GLOB = 0,
78701 + GR_REG_GLOB,
78702 + GR_CREATE_GLOB
78703 +};
78704 +
78705 +#define GR_NLIMITS 32
78706 +
78707 +/* Begin Data Structures */
78708 +
78709 +struct sprole_pw {
78710 + unsigned char *rolename;
78711 + unsigned char salt[GR_SALT_LEN];
78712 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
78713 +};
78714 +
78715 +struct name_entry {
78716 + __u32 key;
78717 + ino_t inode;
78718 + dev_t device;
78719 + char *name;
78720 + __u16 len;
78721 + __u8 deleted;
78722 + struct name_entry *prev;
78723 + struct name_entry *next;
78724 +};
78725 +
78726 +struct inodev_entry {
78727 + struct name_entry *nentry;
78728 + struct inodev_entry *prev;
78729 + struct inodev_entry *next;
78730 +};
78731 +
78732 +struct acl_role_db {
78733 + struct acl_role_label **r_hash;
78734 + __u32 r_size;
78735 +};
78736 +
78737 +struct inodev_db {
78738 + struct inodev_entry **i_hash;
78739 + __u32 i_size;
78740 +};
78741 +
78742 +struct name_db {
78743 + struct name_entry **n_hash;
78744 + __u32 n_size;
78745 +};
78746 +
78747 +struct crash_uid {
78748 + uid_t uid;
78749 + unsigned long expires;
78750 +};
78751 +
78752 +struct gr_hash_struct {
78753 + void **table;
78754 + void **nametable;
78755 + void *first;
78756 + __u32 table_size;
78757 + __u32 used_size;
78758 + int type;
78759 +};
78760 +
78761 +/* Userspace Grsecurity ACL data structures */
78762 +
78763 +struct acl_subject_label {
78764 + char *filename;
78765 + ino_t inode;
78766 + dev_t device;
78767 + __u32 mode;
78768 + kernel_cap_t cap_mask;
78769 + kernel_cap_t cap_lower;
78770 + kernel_cap_t cap_invert_audit;
78771 +
78772 + struct rlimit res[GR_NLIMITS];
78773 + __u32 resmask;
78774 +
78775 + __u8 user_trans_type;
78776 + __u8 group_trans_type;
78777 + uid_t *user_transitions;
78778 + gid_t *group_transitions;
78779 + __u16 user_trans_num;
78780 + __u16 group_trans_num;
78781 +
78782 + __u32 sock_families[2];
78783 + __u32 ip_proto[8];
78784 + __u32 ip_type;
78785 + struct acl_ip_label **ips;
78786 + __u32 ip_num;
78787 + __u32 inaddr_any_override;
78788 +
78789 + __u32 crashes;
78790 + unsigned long expires;
78791 +
78792 + struct acl_subject_label *parent_subject;
78793 + struct gr_hash_struct *hash;
78794 + struct acl_subject_label *prev;
78795 + struct acl_subject_label *next;
78796 +
78797 + struct acl_object_label **obj_hash;
78798 + __u32 obj_hash_size;
78799 + __u16 pax_flags;
78800 +};
78801 +
78802 +struct role_allowed_ip {
78803 + __u32 addr;
78804 + __u32 netmask;
78805 +
78806 + struct role_allowed_ip *prev;
78807 + struct role_allowed_ip *next;
78808 +};
78809 +
78810 +struct role_transition {
78811 + char *rolename;
78812 +
78813 + struct role_transition *prev;
78814 + struct role_transition *next;
78815 +};
78816 +
78817 +struct acl_role_label {
78818 + char *rolename;
78819 + uid_t uidgid;
78820 + __u16 roletype;
78821 +
78822 + __u16 auth_attempts;
78823 + unsigned long expires;
78824 +
78825 + struct acl_subject_label *root_label;
78826 + struct gr_hash_struct *hash;
78827 +
78828 + struct acl_role_label *prev;
78829 + struct acl_role_label *next;
78830 +
78831 + struct role_transition *transitions;
78832 + struct role_allowed_ip *allowed_ips;
78833 + uid_t *domain_children;
78834 + __u16 domain_child_num;
78835 +
78836 + umode_t umask;
78837 +
78838 + struct acl_subject_label **subj_hash;
78839 + __u32 subj_hash_size;
78840 +};
78841 +
78842 +struct user_acl_role_db {
78843 + struct acl_role_label **r_table;
78844 + __u32 num_pointers; /* Number of allocations to track */
78845 + __u32 num_roles; /* Number of roles */
78846 + __u32 num_domain_children; /* Number of domain children */
78847 + __u32 num_subjects; /* Number of subjects */
78848 + __u32 num_objects; /* Number of objects */
78849 +};
78850 +
78851 +struct acl_object_label {
78852 + char *filename;
78853 + ino_t inode;
78854 + dev_t device;
78855 + __u32 mode;
78856 +
78857 + struct acl_subject_label *nested;
78858 + struct acl_object_label *globbed;
78859 +
78860 + /* next two structures not used */
78861 +
78862 + struct acl_object_label *prev;
78863 + struct acl_object_label *next;
78864 +};
78865 +
78866 +struct acl_ip_label {
78867 + char *iface;
78868 + __u32 addr;
78869 + __u32 netmask;
78870 + __u16 low, high;
78871 + __u8 mode;
78872 + __u32 type;
78873 + __u32 proto[8];
78874 +
78875 + /* next two structures not used */
78876 +
78877 + struct acl_ip_label *prev;
78878 + struct acl_ip_label *next;
78879 +};
78880 +
78881 +struct gr_arg {
78882 + struct user_acl_role_db role_db;
78883 + unsigned char pw[GR_PW_LEN];
78884 + unsigned char salt[GR_SALT_LEN];
78885 + unsigned char sum[GR_SHA_LEN];
78886 + unsigned char sp_role[GR_SPROLE_LEN];
78887 + struct sprole_pw *sprole_pws;
78888 + dev_t segv_device;
78889 + ino_t segv_inode;
78890 + uid_t segv_uid;
78891 + __u16 num_sprole_pws;
78892 + __u16 mode;
78893 +};
78894 +
78895 +struct gr_arg_wrapper {
78896 + struct gr_arg *arg;
78897 + __u32 version;
78898 + __u32 size;
78899 +};
78900 +
78901 +struct subject_map {
78902 + struct acl_subject_label *user;
78903 + struct acl_subject_label *kernel;
78904 + struct subject_map *prev;
78905 + struct subject_map *next;
78906 +};
78907 +
78908 +struct acl_subj_map_db {
78909 + struct subject_map **s_hash;
78910 + __u32 s_size;
78911 +};
78912 +
78913 +struct gr_policy_state {
78914 + struct sprole_pw **acl_special_roles;
78915 + __u16 num_sprole_pws;
78916 + struct acl_role_label *kernel_role;
78917 + struct acl_role_label *role_list;
78918 + struct acl_role_label *default_role;
78919 + struct acl_role_db acl_role_set;
78920 + struct acl_subj_map_db subj_map_set;
78921 + struct name_db name_set;
78922 + struct inodev_db inodev_set;
78923 +};
78924 +
78925 +struct gr_alloc_state {
78926 + unsigned long alloc_stack_next;
78927 + unsigned long alloc_stack_size;
78928 + void **alloc_stack;
78929 +};
78930 +
78931 +struct gr_reload_state {
78932 + struct gr_policy_state oldpolicy;
78933 + struct gr_alloc_state oldalloc;
78934 + struct gr_policy_state newpolicy;
78935 + struct gr_alloc_state newalloc;
78936 + struct gr_policy_state *oldpolicy_ptr;
78937 + struct gr_alloc_state *oldalloc_ptr;
78938 + unsigned char oldmode;
78939 +};
78940 +
78941 +/* End Data Structures Section */
78942 +
78943 +/* Hash functions generated by empirical testing by Brad Spengler
78944 + Makes good use of the low bits of the inode. Generally 0-1 times
78945 + in loop for successful match. 0-3 for unsuccessful match.
78946 + Shift/add algorithm with modulus of table size and an XOR*/
78947 +
78948 +static __inline__ unsigned int
78949 +gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
78950 +{
78951 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
78952 +}
78953 +
78954 + static __inline__ unsigned int
78955 +gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
78956 +{
78957 + return ((const unsigned long)userp % sz);
78958 +}
78959 +
78960 +static __inline__ unsigned int
78961 +gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
78962 +{
78963 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
78964 +}
78965 +
78966 +static __inline__ unsigned int
78967 +gr_nhash(const char *name, const __u16 len, const unsigned int sz)
78968 +{
78969 + return full_name_hash((const unsigned char *)name, len) % sz;
78970 +}
78971 +
78972 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
78973 + subj = NULL; \
78974 + iter = 0; \
78975 + while (iter < role->subj_hash_size) { \
78976 + if (subj == NULL) \
78977 + subj = role->subj_hash[iter]; \
78978 + if (subj == NULL) { \
78979 + iter++; \
78980 + continue; \
78981 + }
78982 +
78983 +#define FOR_EACH_SUBJECT_END(subj,iter) \
78984 + subj = subj->next; \
78985 + if (subj == NULL) \
78986 + iter++; \
78987 + }
78988 +
78989 +
78990 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
78991 + subj = role->hash->first; \
78992 + while (subj != NULL) {
78993 +
78994 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
78995 + subj = subj->next; \
78996 + }
78997 +
78998 +#endif
78999 +
79000 diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
79001 new file mode 100644
79002 index 0000000..33ebd1f
79003 --- /dev/null
79004 +++ b/include/linux/gracl_compat.h
79005 @@ -0,0 +1,156 @@
79006 +#ifndef GR_ACL_COMPAT_H
79007 +#define GR_ACL_COMPAT_H
79008 +
79009 +#include <linux/resource.h>
79010 +#include <asm/resource.h>
79011 +
79012 +struct sprole_pw_compat {
79013 + compat_uptr_t rolename;
79014 + unsigned char salt[GR_SALT_LEN];
79015 + unsigned char sum[GR_SHA_LEN];
79016 +};
79017 +
79018 +struct gr_hash_struct_compat {
79019 + compat_uptr_t table;
79020 + compat_uptr_t nametable;
79021 + compat_uptr_t first;
79022 + __u32 table_size;
79023 + __u32 used_size;
79024 + int type;
79025 +};
79026 +
79027 +struct acl_subject_label_compat {
79028 + compat_uptr_t filename;
79029 + compat_ino_t inode;
79030 + __u32 device;
79031 + __u32 mode;
79032 + kernel_cap_t cap_mask;
79033 + kernel_cap_t cap_lower;
79034 + kernel_cap_t cap_invert_audit;
79035 +
79036 + struct compat_rlimit res[GR_NLIMITS];
79037 + __u32 resmask;
79038 +
79039 + __u8 user_trans_type;
79040 + __u8 group_trans_type;
79041 + compat_uptr_t user_transitions;
79042 + compat_uptr_t group_transitions;
79043 + __u16 user_trans_num;
79044 + __u16 group_trans_num;
79045 +
79046 + __u32 sock_families[2];
79047 + __u32 ip_proto[8];
79048 + __u32 ip_type;
79049 + compat_uptr_t ips;
79050 + __u32 ip_num;
79051 + __u32 inaddr_any_override;
79052 +
79053 + __u32 crashes;
79054 + compat_ulong_t expires;
79055 +
79056 + compat_uptr_t parent_subject;
79057 + compat_uptr_t hash;
79058 + compat_uptr_t prev;
79059 + compat_uptr_t next;
79060 +
79061 + compat_uptr_t obj_hash;
79062 + __u32 obj_hash_size;
79063 + __u16 pax_flags;
79064 +};
79065 +
79066 +struct role_allowed_ip_compat {
79067 + __u32 addr;
79068 + __u32 netmask;
79069 +
79070 + compat_uptr_t prev;
79071 + compat_uptr_t next;
79072 +};
79073 +
79074 +struct role_transition_compat {
79075 + compat_uptr_t rolename;
79076 +
79077 + compat_uptr_t prev;
79078 + compat_uptr_t next;
79079 +};
79080 +
79081 +struct acl_role_label_compat {
79082 + compat_uptr_t rolename;
79083 + uid_t uidgid;
79084 + __u16 roletype;
79085 +
79086 + __u16 auth_attempts;
79087 + compat_ulong_t expires;
79088 +
79089 + compat_uptr_t root_label;
79090 + compat_uptr_t hash;
79091 +
79092 + compat_uptr_t prev;
79093 + compat_uptr_t next;
79094 +
79095 + compat_uptr_t transitions;
79096 + compat_uptr_t allowed_ips;
79097 + compat_uptr_t domain_children;
79098 + __u16 domain_child_num;
79099 +
79100 + umode_t umask;
79101 +
79102 + compat_uptr_t subj_hash;
79103 + __u32 subj_hash_size;
79104 +};
79105 +
79106 +struct user_acl_role_db_compat {
79107 + compat_uptr_t r_table;
79108 + __u32 num_pointers;
79109 + __u32 num_roles;
79110 + __u32 num_domain_children;
79111 + __u32 num_subjects;
79112 + __u32 num_objects;
79113 +};
79114 +
79115 +struct acl_object_label_compat {
79116 + compat_uptr_t filename;
79117 + compat_ino_t inode;
79118 + __u32 device;
79119 + __u32 mode;
79120 +
79121 + compat_uptr_t nested;
79122 + compat_uptr_t globbed;
79123 +
79124 + compat_uptr_t prev;
79125 + compat_uptr_t next;
79126 +};
79127 +
79128 +struct acl_ip_label_compat {
79129 + compat_uptr_t iface;
79130 + __u32 addr;
79131 + __u32 netmask;
79132 + __u16 low, high;
79133 + __u8 mode;
79134 + __u32 type;
79135 + __u32 proto[8];
79136 +
79137 + compat_uptr_t prev;
79138 + compat_uptr_t next;
79139 +};
79140 +
79141 +struct gr_arg_compat {
79142 + struct user_acl_role_db_compat role_db;
79143 + unsigned char pw[GR_PW_LEN];
79144 + unsigned char salt[GR_SALT_LEN];
79145 + unsigned char sum[GR_SHA_LEN];
79146 + unsigned char sp_role[GR_SPROLE_LEN];
79147 + compat_uptr_t sprole_pws;
79148 + __u32 segv_device;
79149 + compat_ino_t segv_inode;
79150 + uid_t segv_uid;
79151 + __u16 num_sprole_pws;
79152 + __u16 mode;
79153 +};
79154 +
79155 +struct gr_arg_wrapper_compat {
79156 + compat_uptr_t arg;
79157 + __u32 version;
79158 + __u32 size;
79159 +};
79160 +
79161 +#endif
79162 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
79163 new file mode 100644
79164 index 0000000..323ecf2
79165 --- /dev/null
79166 +++ b/include/linux/gralloc.h
79167 @@ -0,0 +1,9 @@
79168 +#ifndef __GRALLOC_H
79169 +#define __GRALLOC_H
79170 +
79171 +void acl_free_all(void);
79172 +int acl_alloc_stack_init(unsigned long size);
79173 +void *acl_alloc(unsigned long len);
79174 +void *acl_alloc_num(unsigned long num, unsigned long len);
79175 +
79176 +#endif
79177 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
79178 new file mode 100644
79179 index 0000000..be66033
79180 --- /dev/null
79181 +++ b/include/linux/grdefs.h
79182 @@ -0,0 +1,140 @@
79183 +#ifndef GRDEFS_H
79184 +#define GRDEFS_H
79185 +
79186 +/* Begin grsecurity status declarations */
79187 +
79188 +enum {
79189 + GR_READY = 0x01,
79190 + GR_STATUS_INIT = 0x00 // disabled state
79191 +};
79192 +
79193 +/* Begin ACL declarations */
79194 +
79195 +/* Role flags */
79196 +
79197 +enum {
79198 + GR_ROLE_USER = 0x0001,
79199 + GR_ROLE_GROUP = 0x0002,
79200 + GR_ROLE_DEFAULT = 0x0004,
79201 + GR_ROLE_SPECIAL = 0x0008,
79202 + GR_ROLE_AUTH = 0x0010,
79203 + GR_ROLE_NOPW = 0x0020,
79204 + GR_ROLE_GOD = 0x0040,
79205 + GR_ROLE_LEARN = 0x0080,
79206 + GR_ROLE_TPE = 0x0100,
79207 + GR_ROLE_DOMAIN = 0x0200,
79208 + GR_ROLE_PAM = 0x0400,
79209 + GR_ROLE_PERSIST = 0x0800
79210 +};
79211 +
79212 +/* ACL Subject and Object mode flags */
79213 +enum {
79214 + GR_DELETED = 0x80000000
79215 +};
79216 +
79217 +/* ACL Object-only mode flags */
79218 +enum {
79219 + GR_READ = 0x00000001,
79220 + GR_APPEND = 0x00000002,
79221 + GR_WRITE = 0x00000004,
79222 + GR_EXEC = 0x00000008,
79223 + GR_FIND = 0x00000010,
79224 + GR_INHERIT = 0x00000020,
79225 + GR_SETID = 0x00000040,
79226 + GR_CREATE = 0x00000080,
79227 + GR_DELETE = 0x00000100,
79228 + GR_LINK = 0x00000200,
79229 + GR_AUDIT_READ = 0x00000400,
79230 + GR_AUDIT_APPEND = 0x00000800,
79231 + GR_AUDIT_WRITE = 0x00001000,
79232 + GR_AUDIT_EXEC = 0x00002000,
79233 + GR_AUDIT_FIND = 0x00004000,
79234 + GR_AUDIT_INHERIT= 0x00008000,
79235 + GR_AUDIT_SETID = 0x00010000,
79236 + GR_AUDIT_CREATE = 0x00020000,
79237 + GR_AUDIT_DELETE = 0x00040000,
79238 + GR_AUDIT_LINK = 0x00080000,
79239 + GR_PTRACERD = 0x00100000,
79240 + GR_NOPTRACE = 0x00200000,
79241 + GR_SUPPRESS = 0x00400000,
79242 + GR_NOLEARN = 0x00800000,
79243 + GR_INIT_TRANSFER= 0x01000000
79244 +};
79245 +
79246 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
79247 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
79248 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
79249 +
79250 +/* ACL subject-only mode flags */
79251 +enum {
79252 + GR_KILL = 0x00000001,
79253 + GR_VIEW = 0x00000002,
79254 + GR_PROTECTED = 0x00000004,
79255 + GR_LEARN = 0x00000008,
79256 + GR_OVERRIDE = 0x00000010,
79257 + /* just a placeholder, this mode is only used in userspace */
79258 + GR_DUMMY = 0x00000020,
79259 + GR_PROTSHM = 0x00000040,
79260 + GR_KILLPROC = 0x00000080,
79261 + GR_KILLIPPROC = 0x00000100,
79262 + /* just a placeholder, this mode is only used in userspace */
79263 + GR_NOTROJAN = 0x00000200,
79264 + GR_PROTPROCFD = 0x00000400,
79265 + GR_PROCACCT = 0x00000800,
79266 + GR_RELAXPTRACE = 0x00001000,
79267 + //GR_NESTED = 0x00002000,
79268 + GR_INHERITLEARN = 0x00004000,
79269 + GR_PROCFIND = 0x00008000,
79270 + GR_POVERRIDE = 0x00010000,
79271 + GR_KERNELAUTH = 0x00020000,
79272 + GR_ATSECURE = 0x00040000,
79273 + GR_SHMEXEC = 0x00080000
79274 +};
79275 +
79276 +enum {
79277 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
79278 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
79279 + GR_PAX_ENABLE_MPROTECT = 0x0004,
79280 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
79281 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
79282 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
79283 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
79284 + GR_PAX_DISABLE_MPROTECT = 0x0400,
79285 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
79286 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
79287 +};
79288 +
79289 +enum {
79290 + GR_ID_USER = 0x01,
79291 + GR_ID_GROUP = 0x02,
79292 +};
79293 +
79294 +enum {
79295 + GR_ID_ALLOW = 0x01,
79296 + GR_ID_DENY = 0x02,
79297 +};
79298 +
79299 +#define GR_CRASH_RES 31
79300 +#define GR_UIDTABLE_MAX 500
79301 +
79302 +/* begin resource learning section */
79303 +enum {
79304 + GR_RLIM_CPU_BUMP = 60,
79305 + GR_RLIM_FSIZE_BUMP = 50000,
79306 + GR_RLIM_DATA_BUMP = 10000,
79307 + GR_RLIM_STACK_BUMP = 1000,
79308 + GR_RLIM_CORE_BUMP = 10000,
79309 + GR_RLIM_RSS_BUMP = 500000,
79310 + GR_RLIM_NPROC_BUMP = 1,
79311 + GR_RLIM_NOFILE_BUMP = 5,
79312 + GR_RLIM_MEMLOCK_BUMP = 50000,
79313 + GR_RLIM_AS_BUMP = 500000,
79314 + GR_RLIM_LOCKS_BUMP = 2,
79315 + GR_RLIM_SIGPENDING_BUMP = 5,
79316 + GR_RLIM_MSGQUEUE_BUMP = 10000,
79317 + GR_RLIM_NICE_BUMP = 1,
79318 + GR_RLIM_RTPRIO_BUMP = 1,
79319 + GR_RLIM_RTTIME_BUMP = 1000000
79320 +};
79321 +
79322 +#endif
79323 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
79324 new file mode 100644
79325 index 0000000..d25522e
79326 --- /dev/null
79327 +++ b/include/linux/grinternal.h
79328 @@ -0,0 +1,229 @@
79329 +#ifndef __GRINTERNAL_H
79330 +#define __GRINTERNAL_H
79331 +
79332 +#ifdef CONFIG_GRKERNSEC
79333 +
79334 +#include <linux/fs.h>
79335 +#include <linux/mnt_namespace.h>
79336 +#include <linux/nsproxy.h>
79337 +#include <linux/gracl.h>
79338 +#include <linux/grdefs.h>
79339 +#include <linux/grmsg.h>
79340 +
79341 +void gr_add_learn_entry(const char *fmt, ...)
79342 + __attribute__ ((format (printf, 1, 2)));
79343 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
79344 + const struct vfsmount *mnt);
79345 +__u32 gr_check_create(const struct dentry *new_dentry,
79346 + const struct dentry *parent,
79347 + const struct vfsmount *mnt, const __u32 mode);
79348 +int gr_check_protected_task(const struct task_struct *task);
79349 +__u32 to_gr_audit(const __u32 reqmode);
79350 +int gr_set_acls(const int type);
79351 +int gr_acl_is_enabled(void);
79352 +char gr_roletype_to_char(void);
79353 +
79354 +void gr_handle_alertkill(struct task_struct *task);
79355 +char *gr_to_filename(const struct dentry *dentry,
79356 + const struct vfsmount *mnt);
79357 +char *gr_to_filename1(const struct dentry *dentry,
79358 + const struct vfsmount *mnt);
79359 +char *gr_to_filename2(const struct dentry *dentry,
79360 + const struct vfsmount *mnt);
79361 +char *gr_to_filename3(const struct dentry *dentry,
79362 + const struct vfsmount *mnt);
79363 +
79364 +extern int grsec_enable_ptrace_readexec;
79365 +extern int grsec_enable_harden_ptrace;
79366 +extern int grsec_enable_link;
79367 +extern int grsec_enable_fifo;
79368 +extern int grsec_enable_execve;
79369 +extern int grsec_enable_shm;
79370 +extern int grsec_enable_execlog;
79371 +extern int grsec_enable_signal;
79372 +extern int grsec_enable_audit_ptrace;
79373 +extern int grsec_enable_forkfail;
79374 +extern int grsec_enable_time;
79375 +extern int grsec_enable_rofs;
79376 +extern int grsec_deny_new_usb;
79377 +extern int grsec_enable_chroot_shmat;
79378 +extern int grsec_enable_chroot_mount;
79379 +extern int grsec_enable_chroot_double;
79380 +extern int grsec_enable_chroot_pivot;
79381 +extern int grsec_enable_chroot_chdir;
79382 +extern int grsec_enable_chroot_chmod;
79383 +extern int grsec_enable_chroot_mknod;
79384 +extern int grsec_enable_chroot_fchdir;
79385 +extern int grsec_enable_chroot_nice;
79386 +extern int grsec_enable_chroot_execlog;
79387 +extern int grsec_enable_chroot_caps;
79388 +extern int grsec_enable_chroot_sysctl;
79389 +extern int grsec_enable_chroot_unix;
79390 +extern int grsec_enable_symlinkown;
79391 +extern kgid_t grsec_symlinkown_gid;
79392 +extern int grsec_enable_tpe;
79393 +extern kgid_t grsec_tpe_gid;
79394 +extern int grsec_enable_tpe_all;
79395 +extern int grsec_enable_tpe_invert;
79396 +extern int grsec_enable_socket_all;
79397 +extern kgid_t grsec_socket_all_gid;
79398 +extern int grsec_enable_socket_client;
79399 +extern kgid_t grsec_socket_client_gid;
79400 +extern int grsec_enable_socket_server;
79401 +extern kgid_t grsec_socket_server_gid;
79402 +extern kgid_t grsec_audit_gid;
79403 +extern int grsec_enable_group;
79404 +extern int grsec_enable_log_rwxmaps;
79405 +extern int grsec_enable_mount;
79406 +extern int grsec_enable_chdir;
79407 +extern int grsec_resource_logging;
79408 +extern int grsec_enable_blackhole;
79409 +extern int grsec_lastack_retries;
79410 +extern int grsec_enable_brute;
79411 +extern int grsec_enable_harden_ipc;
79412 +extern int grsec_lock;
79413 +
79414 +extern spinlock_t grsec_alert_lock;
79415 +extern unsigned long grsec_alert_wtime;
79416 +extern unsigned long grsec_alert_fyet;
79417 +
79418 +extern spinlock_t grsec_audit_lock;
79419 +
79420 +extern rwlock_t grsec_exec_file_lock;
79421 +
79422 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
79423 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
79424 + (tsk)->exec_file->f_path.mnt) : "/")
79425 +
79426 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
79427 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
79428 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
79429 +
79430 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
79431 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
79432 + (tsk)->exec_file->f_path.mnt) : "/")
79433 +
79434 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
79435 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
79436 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
79437 +
79438 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
79439 +
79440 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
79441 +
79442 +static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
79443 +{
79444 + if (file1 && file2) {
79445 + const struct inode *inode1 = file1->f_path.dentry->d_inode;
79446 + const struct inode *inode2 = file2->f_path.dentry->d_inode;
79447 + if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
79448 + return true;
79449 + }
79450 +
79451 + return false;
79452 +}
79453 +
79454 +#define GR_CHROOT_CAPS {{ \
79455 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
79456 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
79457 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
79458 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
79459 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
79460 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
79461 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
79462 +
79463 +#define security_learn(normal_msg,args...) \
79464 +({ \
79465 + read_lock(&grsec_exec_file_lock); \
79466 + gr_add_learn_entry(normal_msg "\n", ## args); \
79467 + read_unlock(&grsec_exec_file_lock); \
79468 +})
79469 +
79470 +enum {
79471 + GR_DO_AUDIT,
79472 + GR_DONT_AUDIT,
79473 + /* used for non-audit messages that we shouldn't kill the task on */
79474 + GR_DONT_AUDIT_GOOD
79475 +};
79476 +
79477 +enum {
79478 + GR_TTYSNIFF,
79479 + GR_RBAC,
79480 + GR_RBAC_STR,
79481 + GR_STR_RBAC,
79482 + GR_RBAC_MODE2,
79483 + GR_RBAC_MODE3,
79484 + GR_FILENAME,
79485 + GR_SYSCTL_HIDDEN,
79486 + GR_NOARGS,
79487 + GR_ONE_INT,
79488 + GR_ONE_INT_TWO_STR,
79489 + GR_ONE_STR,
79490 + GR_STR_INT,
79491 + GR_TWO_STR_INT,
79492 + GR_TWO_INT,
79493 + GR_TWO_U64,
79494 + GR_THREE_INT,
79495 + GR_FIVE_INT_TWO_STR,
79496 + GR_TWO_STR,
79497 + GR_THREE_STR,
79498 + GR_FOUR_STR,
79499 + GR_STR_FILENAME,
79500 + GR_FILENAME_STR,
79501 + GR_FILENAME_TWO_INT,
79502 + GR_FILENAME_TWO_INT_STR,
79503 + GR_TEXTREL,
79504 + GR_PTRACE,
79505 + GR_RESOURCE,
79506 + GR_CAP,
79507 + GR_SIG,
79508 + GR_SIG2,
79509 + GR_CRASH1,
79510 + GR_CRASH2,
79511 + GR_PSACCT,
79512 + GR_RWXMAP,
79513 + GR_RWXMAPVMA
79514 +};
79515 +
79516 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
79517 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
79518 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
79519 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
79520 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
79521 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
79522 +#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)
79523 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
79524 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
79525 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
79526 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
79527 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
79528 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
79529 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
79530 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
79531 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
79532 +#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)
79533 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
79534 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
79535 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
79536 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
79537 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
79538 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
79539 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
79540 +#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)
79541 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
79542 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
79543 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
79544 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
79545 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
79546 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
79547 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
79548 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
79549 +#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)
79550 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
79551 +#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
79552 +
79553 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
79554 +
79555 +#endif
79556 +
79557 +#endif
79558 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
79559 new file mode 100644
79560 index 0000000..b02ba9d
79561 --- /dev/null
79562 +++ b/include/linux/grmsg.h
79563 @@ -0,0 +1,117 @@
79564 +#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"
79565 +#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"
79566 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
79567 +#define GR_STOPMOD_MSG "denied modification of module state by "
79568 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
79569 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
79570 +#define GR_IOPERM_MSG "denied use of ioperm() by "
79571 +#define GR_IOPL_MSG "denied use of iopl() by "
79572 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
79573 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
79574 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
79575 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
79576 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
79577 +#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"
79578 +#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"
79579 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
79580 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
79581 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
79582 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
79583 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
79584 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
79585 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
79586 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
79587 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
79588 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
79589 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
79590 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
79591 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
79592 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
79593 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
79594 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
79595 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
79596 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
79597 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
79598 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
79599 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
79600 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
79601 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
79602 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
79603 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
79604 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
79605 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
79606 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
79607 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
79608 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
79609 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
79610 +#define GR_CHROOT_FHANDLE_MSG "denied use of file handles inside chroot by "
79611 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
79612 +#define GR_SETXATTR_ACL_MSG "%s setting extended attribute of %.950s by "
79613 +#define GR_REMOVEXATTR_ACL_MSG "%s removing extended attribute of %.950s by "
79614 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
79615 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
79616 +#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"
79617 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
79618 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
79619 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
79620 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
79621 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
79622 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
79623 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
79624 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
79625 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
79626 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
79627 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
79628 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
79629 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
79630 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
79631 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
79632 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
79633 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
79634 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
79635 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
79636 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
79637 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
79638 +#define GR_NICE_CHROOT_MSG "denied priority change by "
79639 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
79640 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
79641 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
79642 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
79643 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
79644 +#define GR_TIME_MSG "time set by "
79645 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
79646 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
79647 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
79648 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
79649 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
79650 +#define GR_BIND_MSG "denied bind() by "
79651 +#define GR_CONNECT_MSG "denied connect() by "
79652 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
79653 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
79654 +#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"
79655 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
79656 +#define GR_CAP_ACL_MSG "use of %s denied for "
79657 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
79658 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
79659 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
79660 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
79661 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
79662 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
79663 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
79664 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
79665 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
79666 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
79667 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
79668 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
79669 +#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
79670 +#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
79671 +#define GR_VM86_MSG "denied use of vm86 by "
79672 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
79673 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
79674 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
79675 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
79676 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
79677 +#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 "
79678 +#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 "
79679 +#define GR_IPC_DENIED_MSG "denied %s of overly-permissive IPC object with creator uid %u by "
79680 +#define GR_MSRWRITE_MSG "denied write to CPU MSR by "
79681 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
79682 new file mode 100644
79683 index 0000000..13ac2e2
79684 --- /dev/null
79685 +++ b/include/linux/grsecurity.h
79686 @@ -0,0 +1,249 @@
79687 +#ifndef GR_SECURITY_H
79688 +#define GR_SECURITY_H
79689 +#include <linux/fs.h>
79690 +#include <linux/fs_struct.h>
79691 +#include <linux/binfmts.h>
79692 +#include <linux/gracl.h>
79693 +
79694 +/* notify of brain-dead configs */
79695 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
79696 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
79697 +#endif
79698 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
79699 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
79700 +#endif
79701 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
79702 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
79703 +#endif
79704 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
79705 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
79706 +#endif
79707 +
79708 +int gr_handle_new_usb(void);
79709 +
79710 +void gr_handle_brute_attach(int dumpable);
79711 +void gr_handle_brute_check(void);
79712 +void gr_handle_kernel_exploit(void);
79713 +
79714 +char gr_roletype_to_char(void);
79715 +
79716 +int gr_proc_is_restricted(void);
79717 +
79718 +int gr_acl_enable_at_secure(void);
79719 +
79720 +int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
79721 +int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
79722 +
79723 +void gr_del_task_from_ip_table(struct task_struct *p);
79724 +
79725 +int gr_pid_is_chrooted(struct task_struct *p);
79726 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
79727 +int gr_handle_chroot_nice(void);
79728 +int gr_handle_chroot_sysctl(const int op);
79729 +int gr_handle_chroot_setpriority(struct task_struct *p,
79730 + const int niceval);
79731 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
79732 +int gr_chroot_fhandle(void);
79733 +int gr_handle_chroot_chroot(const struct dentry *dentry,
79734 + const struct vfsmount *mnt);
79735 +void gr_handle_chroot_chdir(const struct path *path);
79736 +int gr_handle_chroot_chmod(const struct dentry *dentry,
79737 + const struct vfsmount *mnt, const int mode);
79738 +int gr_handle_chroot_mknod(const struct dentry *dentry,
79739 + const struct vfsmount *mnt, const int mode);
79740 +int gr_handle_chroot_mount(const struct dentry *dentry,
79741 + const struct vfsmount *mnt,
79742 + const char *dev_name);
79743 +int gr_handle_chroot_pivot(void);
79744 +int gr_handle_chroot_unix(const pid_t pid);
79745 +
79746 +int gr_handle_rawio(const struct inode *inode);
79747 +
79748 +void gr_handle_ioperm(void);
79749 +void gr_handle_iopl(void);
79750 +void gr_handle_msr_write(void);
79751 +
79752 +umode_t gr_acl_umask(void);
79753 +
79754 +int gr_tpe_allow(const struct file *file);
79755 +
79756 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
79757 +void gr_clear_chroot_entries(struct task_struct *task);
79758 +
79759 +void gr_log_forkfail(const int retval);
79760 +void gr_log_timechange(void);
79761 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
79762 +void gr_log_chdir(const struct dentry *dentry,
79763 + const struct vfsmount *mnt);
79764 +void gr_log_chroot_exec(const struct dentry *dentry,
79765 + const struct vfsmount *mnt);
79766 +void gr_log_remount(const char *devname, const int retval);
79767 +void gr_log_unmount(const char *devname, const int retval);
79768 +void gr_log_mount(const char *from, const char *to, const int retval);
79769 +void gr_log_textrel(struct vm_area_struct *vma);
79770 +void gr_log_ptgnustack(struct file *file);
79771 +void gr_log_rwxmmap(struct file *file);
79772 +void gr_log_rwxmprotect(struct vm_area_struct *vma);
79773 +
79774 +int gr_handle_follow_link(const struct inode *parent,
79775 + const struct inode *inode,
79776 + const struct dentry *dentry,
79777 + const struct vfsmount *mnt);
79778 +int gr_handle_fifo(const struct dentry *dentry,
79779 + const struct vfsmount *mnt,
79780 + const struct dentry *dir, const int flag,
79781 + const int acc_mode);
79782 +int gr_handle_hardlink(const struct dentry *dentry,
79783 + const struct vfsmount *mnt,
79784 + struct inode *inode,
79785 + const int mode, const struct filename *to);
79786 +
79787 +int gr_is_capable(const int cap);
79788 +int gr_is_capable_nolog(const int cap);
79789 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
79790 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
79791 +
79792 +void gr_copy_label(struct task_struct *tsk);
79793 +void gr_handle_crash(struct task_struct *task, const int sig);
79794 +int gr_handle_signal(const struct task_struct *p, const int sig);
79795 +int gr_check_crash_uid(const kuid_t uid);
79796 +int gr_check_protected_task(const struct task_struct *task);
79797 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
79798 +int gr_acl_handle_mmap(const struct file *file,
79799 + const unsigned long prot);
79800 +int gr_acl_handle_mprotect(const struct file *file,
79801 + const unsigned long prot);
79802 +int gr_check_hidden_task(const struct task_struct *tsk);
79803 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
79804 + const struct vfsmount *mnt);
79805 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
79806 + const struct vfsmount *mnt);
79807 +__u32 gr_acl_handle_access(const struct dentry *dentry,
79808 + const struct vfsmount *mnt, const int fmode);
79809 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
79810 + const struct vfsmount *mnt, umode_t *mode);
79811 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
79812 + const struct vfsmount *mnt);
79813 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
79814 + const struct vfsmount *mnt);
79815 +__u32 gr_acl_handle_removexattr(const struct dentry *dentry,
79816 + const struct vfsmount *mnt);
79817 +int gr_handle_ptrace(struct task_struct *task, const long request);
79818 +int gr_handle_proc_ptrace(struct task_struct *task);
79819 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
79820 + const struct vfsmount *mnt);
79821 +int gr_check_crash_exec(const struct file *filp);
79822 +int gr_acl_is_enabled(void);
79823 +void gr_set_role_label(struct task_struct *task, const kuid_t uid,
79824 + const kgid_t gid);
79825 +int gr_set_proc_label(const struct dentry *dentry,
79826 + const struct vfsmount *mnt,
79827 + const int unsafe_flags);
79828 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
79829 + const struct vfsmount *mnt);
79830 +__u32 gr_acl_handle_open(const struct dentry *dentry,
79831 + const struct vfsmount *mnt, int acc_mode);
79832 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
79833 + const struct dentry *p_dentry,
79834 + const struct vfsmount *p_mnt,
79835 + int open_flags, int acc_mode, const int imode);
79836 +void gr_handle_create(const struct dentry *dentry,
79837 + const struct vfsmount *mnt);
79838 +void gr_handle_proc_create(const struct dentry *dentry,
79839 + const struct inode *inode);
79840 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
79841 + const struct dentry *parent_dentry,
79842 + const struct vfsmount *parent_mnt,
79843 + const int mode);
79844 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
79845 + const struct dentry *parent_dentry,
79846 + const struct vfsmount *parent_mnt);
79847 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
79848 + const struct vfsmount *mnt);
79849 +void gr_handle_delete(const ino_t ino, const dev_t dev);
79850 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
79851 + const struct vfsmount *mnt);
79852 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
79853 + const struct dentry *parent_dentry,
79854 + const struct vfsmount *parent_mnt,
79855 + const struct filename *from);
79856 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
79857 + const struct dentry *parent_dentry,
79858 + const struct vfsmount *parent_mnt,
79859 + const struct dentry *old_dentry,
79860 + const struct vfsmount *old_mnt, const struct filename *to);
79861 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
79862 +int gr_acl_handle_rename(struct dentry *new_dentry,
79863 + struct dentry *parent_dentry,
79864 + const struct vfsmount *parent_mnt,
79865 + struct dentry *old_dentry,
79866 + struct inode *old_parent_inode,
79867 + struct vfsmount *old_mnt, const struct filename *newname, unsigned int flags);
79868 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
79869 + struct dentry *old_dentry,
79870 + struct dentry *new_dentry,
79871 + struct vfsmount *mnt, const __u8 replace, unsigned int flags);
79872 +__u32 gr_check_link(const struct dentry *new_dentry,
79873 + const struct dentry *parent_dentry,
79874 + const struct vfsmount *parent_mnt,
79875 + const struct dentry *old_dentry,
79876 + const struct vfsmount *old_mnt);
79877 +int gr_acl_handle_filldir(const struct file *file, const char *name,
79878 + const unsigned int namelen, const ino_t ino);
79879 +
79880 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
79881 + const struct vfsmount *mnt);
79882 +void gr_acl_handle_exit(void);
79883 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
79884 +int gr_acl_handle_procpidmem(const struct task_struct *task);
79885 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
79886 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
79887 +void gr_audit_ptrace(struct task_struct *task);
79888 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
79889 +void gr_put_exec_file(struct task_struct *task);
79890 +
79891 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
79892 +
79893 +#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
79894 +extern void gr_learn_resource(const struct task_struct *task, const int res,
79895 + const unsigned long wanted, const int gt);
79896 +#else
79897 +static inline void gr_learn_resource(const struct task_struct *task, const int res,
79898 + const unsigned long wanted, const int gt)
79899 +{
79900 +}
79901 +#endif
79902 +
79903 +#ifdef CONFIG_GRKERNSEC_RESLOG
79904 +extern void gr_log_resource(const struct task_struct *task, const int res,
79905 + const unsigned long wanted, const int gt);
79906 +#else
79907 +static inline void gr_log_resource(const struct task_struct *task, const int res,
79908 + const unsigned long wanted, const int gt)
79909 +{
79910 +}
79911 +#endif
79912 +
79913 +#ifdef CONFIG_GRKERNSEC
79914 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
79915 +void gr_handle_vm86(void);
79916 +void gr_handle_mem_readwrite(u64 from, u64 to);
79917 +
79918 +void gr_log_badprocpid(const char *entry);
79919 +
79920 +extern int grsec_enable_dmesg;
79921 +extern int grsec_disable_privio;
79922 +
79923 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
79924 +extern kgid_t grsec_proc_gid;
79925 +#endif
79926 +
79927 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
79928 +extern int grsec_enable_chroot_findtask;
79929 +#endif
79930 +#ifdef CONFIG_GRKERNSEC_SETXID
79931 +extern int grsec_enable_setxid;
79932 +#endif
79933 +#endif
79934 +
79935 +#endif
79936 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
79937 new file mode 100644
79938 index 0000000..e7ffaaf
79939 --- /dev/null
79940 +++ b/include/linux/grsock.h
79941 @@ -0,0 +1,19 @@
79942 +#ifndef __GRSOCK_H
79943 +#define __GRSOCK_H
79944 +
79945 +extern void gr_attach_curr_ip(const struct sock *sk);
79946 +extern int gr_handle_sock_all(const int family, const int type,
79947 + const int protocol);
79948 +extern int gr_handle_sock_server(const struct sockaddr *sck);
79949 +extern int gr_handle_sock_server_other(const struct sock *sck);
79950 +extern int gr_handle_sock_client(const struct sockaddr *sck);
79951 +extern int gr_search_connect(struct socket * sock,
79952 + struct sockaddr_in * addr);
79953 +extern int gr_search_bind(struct socket * sock,
79954 + struct sockaddr_in * addr);
79955 +extern int gr_search_listen(struct socket * sock);
79956 +extern int gr_search_accept(struct socket * sock);
79957 +extern int gr_search_socket(const int domain, const int type,
79958 + const int protocol);
79959 +
79960 +#endif
79961 diff --git a/include/linux/hash.h b/include/linux/hash.h
79962 index bd1754c..8240892 100644
79963 --- a/include/linux/hash.h
79964 +++ b/include/linux/hash.h
79965 @@ -83,7 +83,7 @@ static inline u32 hash32_ptr(const void *ptr)
79966 struct fast_hash_ops {
79967 u32 (*hash)(const void *data, u32 len, u32 seed);
79968 u32 (*hash2)(const u32 *data, u32 len, u32 seed);
79969 -};
79970 +} __no_const;
79971
79972 /**
79973 * arch_fast_hash - Caclulates a hash over a given buffer that can have
79974 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
79975 index 7fb31da..08b5114 100644
79976 --- a/include/linux/highmem.h
79977 +++ b/include/linux/highmem.h
79978 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
79979 kunmap_atomic(kaddr);
79980 }
79981
79982 +static inline void sanitize_highpage(struct page *page)
79983 +{
79984 + void *kaddr;
79985 + unsigned long flags;
79986 +
79987 + local_irq_save(flags);
79988 + kaddr = kmap_atomic(page);
79989 + clear_page(kaddr);
79990 + kunmap_atomic(kaddr);
79991 + local_irq_restore(flags);
79992 +}
79993 +
79994 static inline void zero_user_segments(struct page *page,
79995 unsigned start1, unsigned end1,
79996 unsigned start2, unsigned end2)
79997 diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
79998 index 1c7b89a..7dda400 100644
79999 --- a/include/linux/hwmon-sysfs.h
80000 +++ b/include/linux/hwmon-sysfs.h
80001 @@ -25,7 +25,8 @@
80002 struct sensor_device_attribute{
80003 struct device_attribute dev_attr;
80004 int index;
80005 -};
80006 +} __do_const;
80007 +typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
80008 #define to_sensor_dev_attr(_dev_attr) \
80009 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
80010
80011 @@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
80012 struct device_attribute dev_attr;
80013 u8 index;
80014 u8 nr;
80015 -};
80016 +} __do_const;
80017 +typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
80018 #define to_sensor_dev_attr_2(_dev_attr) \
80019 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
80020
80021 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
80022 index b556e0a..c10a515 100644
80023 --- a/include/linux/i2c.h
80024 +++ b/include/linux/i2c.h
80025 @@ -378,6 +378,7 @@ struct i2c_algorithm {
80026 /* To determine what the adapter supports */
80027 u32 (*functionality) (struct i2c_adapter *);
80028 };
80029 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
80030
80031 /**
80032 * struct i2c_bus_recovery_info - I2C bus recovery information
80033 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
80034 index d23c3c2..eb63c81 100644
80035 --- a/include/linux/i2o.h
80036 +++ b/include/linux/i2o.h
80037 @@ -565,7 +565,7 @@ struct i2o_controller {
80038 struct i2o_device *exec; /* Executive */
80039 #if BITS_PER_LONG == 64
80040 spinlock_t context_list_lock; /* lock for context_list */
80041 - atomic_t context_list_counter; /* needed for unique contexts */
80042 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
80043 struct list_head context_list; /* list of context id's
80044 and pointers */
80045 #endif
80046 diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
80047 index aff7ad8..3942bbd 100644
80048 --- a/include/linux/if_pppox.h
80049 +++ b/include/linux/if_pppox.h
80050 @@ -76,7 +76,7 @@ struct pppox_proto {
80051 int (*ioctl)(struct socket *sock, unsigned int cmd,
80052 unsigned long arg);
80053 struct module *owner;
80054 -};
80055 +} __do_const;
80056
80057 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
80058 extern void unregister_pppox_proto(int proto_num);
80059 diff --git a/include/linux/init.h b/include/linux/init.h
80060 index a3ba270..a1b6604 100644
80061 --- a/include/linux/init.h
80062 +++ b/include/linux/init.h
80063 @@ -37,9 +37,17 @@
80064 * section.
80065 */
80066
80067 +#define add_init_latent_entropy __latent_entropy
80068 +
80069 +#ifdef CONFIG_MEMORY_HOTPLUG
80070 +#define add_meminit_latent_entropy
80071 +#else
80072 +#define add_meminit_latent_entropy __latent_entropy
80073 +#endif
80074 +
80075 /* These are for everybody (although not all archs will actually
80076 discard it in modules) */
80077 -#define __init __section(.init.text) __cold notrace
80078 +#define __init __section(.init.text) __cold notrace add_init_latent_entropy
80079 #define __initdata __section(.init.data)
80080 #define __initconst __constsection(.init.rodata)
80081 #define __exitdata __section(.exit.data)
80082 @@ -100,7 +108,7 @@
80083 #define __cpuexitconst
80084
80085 /* Used for MEMORY_HOTPLUG */
80086 -#define __meminit __section(.meminit.text) __cold notrace
80087 +#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
80088 #define __meminitdata __section(.meminit.data)
80089 #define __meminitconst __constsection(.meminit.rodata)
80090 #define __memexit __section(.memexit.text) __exitused __cold notrace
80091 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
80092 index 6df7f9f..d0bf699 100644
80093 --- a/include/linux/init_task.h
80094 +++ b/include/linux/init_task.h
80095 @@ -156,6 +156,12 @@ extern struct task_group root_task_group;
80096
80097 #define INIT_TASK_COMM "swapper"
80098
80099 +#ifdef CONFIG_X86
80100 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
80101 +#else
80102 +#define INIT_TASK_THREAD_INFO
80103 +#endif
80104 +
80105 #ifdef CONFIG_RT_MUTEXES
80106 # define INIT_RT_MUTEXES(tsk) \
80107 .pi_waiters = RB_ROOT, \
80108 @@ -203,6 +209,7 @@ extern struct task_group root_task_group;
80109 RCU_POINTER_INITIALIZER(cred, &init_cred), \
80110 .comm = INIT_TASK_COMM, \
80111 .thread = INIT_THREAD, \
80112 + INIT_TASK_THREAD_INFO \
80113 .fs = &init_fs, \
80114 .files = &init_files, \
80115 .signal = &init_signals, \
80116 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
80117 index 051c850..431f83a 100644
80118 --- a/include/linux/interrupt.h
80119 +++ b/include/linux/interrupt.h
80120 @@ -412,8 +412,8 @@ extern const char * const softirq_to_name[NR_SOFTIRQS];
80121
80122 struct softirq_action
80123 {
80124 - void (*action)(struct softirq_action *);
80125 -};
80126 + void (*action)(void);
80127 +} __no_const;
80128
80129 asmlinkage void do_softirq(void);
80130 asmlinkage void __do_softirq(void);
80131 @@ -427,7 +427,7 @@ static inline void do_softirq_own_stack(void)
80132 }
80133 #endif
80134
80135 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
80136 +extern void open_softirq(int nr, void (*action)(void));
80137 extern void softirq_init(void);
80138 extern void __raise_softirq_irqoff(unsigned int nr);
80139
80140 diff --git a/include/linux/iommu.h b/include/linux/iommu.h
80141 index b96a5b2..2732d1c 100644
80142 --- a/include/linux/iommu.h
80143 +++ b/include/linux/iommu.h
80144 @@ -131,7 +131,7 @@ struct iommu_ops {
80145 u32 (*domain_get_windows)(struct iommu_domain *domain);
80146
80147 unsigned long pgsize_bitmap;
80148 -};
80149 +} __do_const;
80150
80151 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
80152 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
80153 diff --git a/include/linux/ioport.h b/include/linux/ioport.h
80154 index 5e3a906..3131d0f 100644
80155 --- a/include/linux/ioport.h
80156 +++ b/include/linux/ioport.h
80157 @@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
80158 int adjust_resource(struct resource *res, resource_size_t start,
80159 resource_size_t size);
80160 resource_size_t resource_alignment(struct resource *res);
80161 -static inline resource_size_t resource_size(const struct resource *res)
80162 +static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
80163 {
80164 return res->end - res->start + 1;
80165 }
80166 diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
80167 index 35e7eca..6afb7ad 100644
80168 --- a/include/linux/ipc_namespace.h
80169 +++ b/include/linux/ipc_namespace.h
80170 @@ -69,7 +69,7 @@ struct ipc_namespace {
80171 struct user_namespace *user_ns;
80172
80173 unsigned int proc_inum;
80174 -};
80175 +} __randomize_layout;
80176
80177 extern struct ipc_namespace init_ipc_ns;
80178 extern atomic_t nr_ipc_ns;
80179 diff --git a/include/linux/irq.h b/include/linux/irq.h
80180 index 5c57efb..965a62b 100644
80181 --- a/include/linux/irq.h
80182 +++ b/include/linux/irq.h
80183 @@ -344,7 +344,8 @@ struct irq_chip {
80184 void (*irq_release_resources)(struct irq_data *data);
80185
80186 unsigned long flags;
80187 -};
80188 +} __do_const;
80189 +typedef struct irq_chip __no_const irq_chip_no_const;
80190
80191 /*
80192 * irq_chip specific flags
80193 diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
80194 index 7ed92d0..589abf5 100644
80195 --- a/include/linux/irqchip/arm-gic.h
80196 +++ b/include/linux/irqchip/arm-gic.h
80197 @@ -73,9 +73,11 @@
80198
80199 #ifndef __ASSEMBLY__
80200
80201 +#include <linux/irq.h>
80202 +
80203 struct device_node;
80204
80205 -extern struct irq_chip gic_arch_extn;
80206 +extern irq_chip_no_const gic_arch_extn;
80207
80208 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
80209 u32 offset, struct device_node *);
80210 diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
80211 index 1f44466..b481806 100644
80212 --- a/include/linux/jiffies.h
80213 +++ b/include/linux/jiffies.h
80214 @@ -292,20 +292,20 @@ extern unsigned long preset_lpj;
80215 /*
80216 * Convert various time units to each other:
80217 */
80218 -extern unsigned int jiffies_to_msecs(const unsigned long j);
80219 -extern unsigned int jiffies_to_usecs(const unsigned long j);
80220 +extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
80221 +extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
80222
80223 -static inline u64 jiffies_to_nsecs(const unsigned long j)
80224 +static inline u64 __intentional_overflow(-1) jiffies_to_nsecs(const unsigned long j)
80225 {
80226 return (u64)jiffies_to_usecs(j) * NSEC_PER_USEC;
80227 }
80228
80229 -extern unsigned long msecs_to_jiffies(const unsigned int m);
80230 -extern unsigned long usecs_to_jiffies(const unsigned int u);
80231 +extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
80232 +extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
80233 extern unsigned long timespec_to_jiffies(const struct timespec *value);
80234 extern void jiffies_to_timespec(const unsigned long jiffies,
80235 - struct timespec *value);
80236 -extern unsigned long timeval_to_jiffies(const struct timeval *value);
80237 + struct timespec *value) __intentional_overflow(-1);
80238 +extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
80239 extern void jiffies_to_timeval(const unsigned long jiffies,
80240 struct timeval *value);
80241
80242 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
80243 index 6883e19..e854fcb 100644
80244 --- a/include/linux/kallsyms.h
80245 +++ b/include/linux/kallsyms.h
80246 @@ -15,7 +15,8 @@
80247
80248 struct module;
80249
80250 -#ifdef CONFIG_KALLSYMS
80251 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
80252 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
80253 /* Lookup the address for a symbol. Returns 0 if not found. */
80254 unsigned long kallsyms_lookup_name(const char *name);
80255
80256 @@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
80257 /* Stupid that this does nothing, but I didn't create this mess. */
80258 #define __print_symbol(fmt, addr)
80259 #endif /*CONFIG_KALLSYMS*/
80260 +#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
80261 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
80262 +extern unsigned long kallsyms_lookup_name(const char *name);
80263 +extern void __print_symbol(const char *fmt, unsigned long address);
80264 +extern int sprint_backtrace(char *buffer, unsigned long address);
80265 +extern int sprint_symbol(char *buffer, unsigned long address);
80266 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
80267 +const char *kallsyms_lookup(unsigned long addr,
80268 + unsigned long *symbolsize,
80269 + unsigned long *offset,
80270 + char **modname, char *namebuf);
80271 +extern int kallsyms_lookup_size_offset(unsigned long addr,
80272 + unsigned long *symbolsize,
80273 + unsigned long *offset);
80274 +#endif
80275
80276 /* This macro allows us to keep printk typechecking */
80277 static __printf(1, 2)
80278 diff --git a/include/linux/key-type.h b/include/linux/key-type.h
80279 index a74c3a8..28d3f21 100644
80280 --- a/include/linux/key-type.h
80281 +++ b/include/linux/key-type.h
80282 @@ -131,7 +131,7 @@ struct key_type {
80283 /* internal fields */
80284 struct list_head link; /* link in types list */
80285 struct lock_class_key lock_class; /* key->sem lock class */
80286 -};
80287 +} __do_const;
80288
80289 extern struct key_type key_type_keyring;
80290
80291 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
80292 index 6b06d37..c134867 100644
80293 --- a/include/linux/kgdb.h
80294 +++ b/include/linux/kgdb.h
80295 @@ -52,7 +52,7 @@ extern int kgdb_connected;
80296 extern int kgdb_io_module_registered;
80297
80298 extern atomic_t kgdb_setting_breakpoint;
80299 -extern atomic_t kgdb_cpu_doing_single_step;
80300 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
80301
80302 extern struct task_struct *kgdb_usethread;
80303 extern struct task_struct *kgdb_contthread;
80304 @@ -254,7 +254,7 @@ struct kgdb_arch {
80305 void (*correct_hw_break)(void);
80306
80307 void (*enable_nmi)(bool on);
80308 -};
80309 +} __do_const;
80310
80311 /**
80312 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
80313 @@ -279,7 +279,7 @@ struct kgdb_io {
80314 void (*pre_exception) (void);
80315 void (*post_exception) (void);
80316 int is_console;
80317 -};
80318 +} __do_const;
80319
80320 extern struct kgdb_arch arch_kgdb_ops;
80321
80322 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
80323 index 0555cc6..40116ce 100644
80324 --- a/include/linux/kmod.h
80325 +++ b/include/linux/kmod.h
80326 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
80327 * usually useless though. */
80328 extern __printf(2, 3)
80329 int __request_module(bool wait, const char *name, ...);
80330 +extern __printf(3, 4)
80331 +int ___request_module(bool wait, char *param_name, const char *name, ...);
80332 #define request_module(mod...) __request_module(true, mod)
80333 #define request_module_nowait(mod...) __request_module(false, mod)
80334 #define try_then_request_module(x, mod...) \
80335 @@ -57,6 +59,9 @@ struct subprocess_info {
80336 struct work_struct work;
80337 struct completion *complete;
80338 char *path;
80339 +#ifdef CONFIG_GRKERNSEC
80340 + char *origpath;
80341 +#endif
80342 char **argv;
80343 char **envp;
80344 int wait;
80345 diff --git a/include/linux/kobject.h b/include/linux/kobject.h
80346 index f896a33..f2eb10f 100644
80347 --- a/include/linux/kobject.h
80348 +++ b/include/linux/kobject.h
80349 @@ -116,7 +116,7 @@ struct kobj_type {
80350 struct attribute **default_attrs;
80351 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
80352 const void *(*namespace)(struct kobject *kobj);
80353 -};
80354 +} __do_const;
80355
80356 struct kobj_uevent_env {
80357 char *argv[3];
80358 @@ -140,6 +140,7 @@ struct kobj_attribute {
80359 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
80360 const char *buf, size_t count);
80361 };
80362 +typedef struct kobj_attribute __no_const kobj_attribute_no_const;
80363
80364 extern const struct sysfs_ops kobj_sysfs_ops;
80365
80366 @@ -167,7 +168,7 @@ struct kset {
80367 spinlock_t list_lock;
80368 struct kobject kobj;
80369 const struct kset_uevent_ops *uevent_ops;
80370 -};
80371 +} __randomize_layout;
80372
80373 extern void kset_init(struct kset *kset);
80374 extern int __must_check kset_register(struct kset *kset);
80375 diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
80376 index df32d25..fb52e27 100644
80377 --- a/include/linux/kobject_ns.h
80378 +++ b/include/linux/kobject_ns.h
80379 @@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
80380 const void *(*netlink_ns)(struct sock *sk);
80381 const void *(*initial_ns)(void);
80382 void (*drop_ns)(void *);
80383 -};
80384 +} __do_const;
80385
80386 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
80387 int kobj_ns_type_registered(enum kobj_ns_type type);
80388 diff --git a/include/linux/kref.h b/include/linux/kref.h
80389 index 484604d..0f6c5b6 100644
80390 --- a/include/linux/kref.h
80391 +++ b/include/linux/kref.h
80392 @@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
80393 static inline int kref_sub(struct kref *kref, unsigned int count,
80394 void (*release)(struct kref *kref))
80395 {
80396 - WARN_ON(release == NULL);
80397 + BUG_ON(release == NULL);
80398
80399 if (atomic_sub_and_test((int) count, &kref->refcount)) {
80400 release(kref);
80401 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
80402 index 7d21cf9..bc0c81f 100644
80403 --- a/include/linux/kvm_host.h
80404 +++ b/include/linux/kvm_host.h
80405 @@ -466,7 +466,7 @@ static inline void kvm_irqfd_exit(void)
80406 {
80407 }
80408 #endif
80409 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
80410 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
80411 struct module *module);
80412 void kvm_exit(void);
80413
80414 @@ -632,7 +632,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
80415 struct kvm_guest_debug *dbg);
80416 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
80417
80418 -int kvm_arch_init(void *opaque);
80419 +int kvm_arch_init(const void *opaque);
80420 void kvm_arch_exit(void);
80421
80422 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
80423 diff --git a/include/linux/libata.h b/include/linux/libata.h
80424 index 5ab4e3a..2fe237b 100644
80425 --- a/include/linux/libata.h
80426 +++ b/include/linux/libata.h
80427 @@ -975,7 +975,7 @@ struct ata_port_operations {
80428 * fields must be pointers.
80429 */
80430 const struct ata_port_operations *inherits;
80431 -};
80432 +} __do_const;
80433
80434 struct ata_port_info {
80435 unsigned long flags;
80436 diff --git a/include/linux/linkage.h b/include/linux/linkage.h
80437 index a6a42dd..6c5ebce 100644
80438 --- a/include/linux/linkage.h
80439 +++ b/include/linux/linkage.h
80440 @@ -36,6 +36,7 @@
80441 #endif
80442
80443 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
80444 +#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
80445 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
80446
80447 /*
80448 diff --git a/include/linux/list.h b/include/linux/list.h
80449 index ef95941..82db65a 100644
80450 --- a/include/linux/list.h
80451 +++ b/include/linux/list.h
80452 @@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
80453 extern void list_del(struct list_head *entry);
80454 #endif
80455
80456 +extern void __pax_list_add(struct list_head *new,
80457 + struct list_head *prev,
80458 + struct list_head *next);
80459 +static inline void pax_list_add(struct list_head *new, struct list_head *head)
80460 +{
80461 + __pax_list_add(new, head, head->next);
80462 +}
80463 +static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
80464 +{
80465 + __pax_list_add(new, head->prev, head);
80466 +}
80467 +extern void pax_list_del(struct list_head *entry);
80468 +
80469 /**
80470 * list_replace - replace old entry by new one
80471 * @old : the element to be replaced
80472 @@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
80473 INIT_LIST_HEAD(entry);
80474 }
80475
80476 +extern void pax_list_del_init(struct list_head *entry);
80477 +
80478 /**
80479 * list_move - delete from one list and add as another's head
80480 * @list: the entry to move
80481 diff --git a/include/linux/math64.h b/include/linux/math64.h
80482 index c45c089..298841c 100644
80483 --- a/include/linux/math64.h
80484 +++ b/include/linux/math64.h
80485 @@ -15,7 +15,7 @@
80486 * This is commonly provided by 32bit archs to provide an optimized 64bit
80487 * divide.
80488 */
80489 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80490 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80491 {
80492 *remainder = dividend % divisor;
80493 return dividend / divisor;
80494 @@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
80495 /**
80496 * div64_u64 - unsigned 64bit divide with 64bit divisor
80497 */
80498 -static inline u64 div64_u64(u64 dividend, u64 divisor)
80499 +static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
80500 {
80501 return dividend / divisor;
80502 }
80503 @@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
80504 #define div64_ul(x, y) div_u64((x), (y))
80505
80506 #ifndef div_u64_rem
80507 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80508 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
80509 {
80510 *remainder = do_div(dividend, divisor);
80511 return dividend;
80512 @@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
80513 #endif
80514
80515 #ifndef div64_u64
80516 -extern u64 div64_u64(u64 dividend, u64 divisor);
80517 +extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
80518 #endif
80519
80520 #ifndef div64_s64
80521 @@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
80522 * divide.
80523 */
80524 #ifndef div_u64
80525 -static inline u64 div_u64(u64 dividend, u32 divisor)
80526 +static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
80527 {
80528 u32 remainder;
80529 return div_u64_rem(dividend, divisor, &remainder);
80530 diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
80531 index f230a97..714c006 100644
80532 --- a/include/linux/mempolicy.h
80533 +++ b/include/linux/mempolicy.h
80534 @@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
80535 }
80536
80537 #define vma_policy(vma) ((vma)->vm_policy)
80538 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
80539 +{
80540 + vma->vm_policy = pol;
80541 +}
80542
80543 static inline void mpol_get(struct mempolicy *pol)
80544 {
80545 @@ -228,6 +232,9 @@ static inline void mpol_free_shared_policy(struct shared_policy *p)
80546 }
80547
80548 #define vma_policy(vma) NULL
80549 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
80550 +{
80551 +}
80552
80553 static inline int
80554 vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
80555 diff --git a/include/linux/mm.h b/include/linux/mm.h
80556 index d677706..673408c 100644
80557 --- a/include/linux/mm.h
80558 +++ b/include/linux/mm.h
80559 @@ -127,6 +127,11 @@ extern unsigned int kobjsize(const void *objp);
80560 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
80561 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
80562 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
80563 +
80564 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
80565 +#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
80566 +#endif
80567 +
80568 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
80569
80570 #ifdef CONFIG_MEM_SOFT_DIRTY
80571 @@ -237,8 +242,8 @@ struct vm_operations_struct {
80572 /* called by access_process_vm when get_user_pages() fails, typically
80573 * for use by special VMAs that can switch between memory and hardware
80574 */
80575 - int (*access)(struct vm_area_struct *vma, unsigned long addr,
80576 - void *buf, int len, int write);
80577 + ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
80578 + void *buf, size_t len, int write);
80579 #ifdef CONFIG_NUMA
80580 /*
80581 * set_policy() op must add a reference to any non-NULL @new mempolicy
80582 @@ -268,6 +273,7 @@ struct vm_operations_struct {
80583 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
80584 unsigned long size, pgoff_t pgoff);
80585 };
80586 +typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
80587
80588 struct mmu_gather;
80589 struct inode;
80590 @@ -1133,8 +1139,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
80591 unsigned long *pfn);
80592 int follow_phys(struct vm_area_struct *vma, unsigned long address,
80593 unsigned int flags, unsigned long *prot, resource_size_t *phys);
80594 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
80595 - void *buf, int len, int write);
80596 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
80597 + void *buf, size_t len, int write);
80598
80599 static inline void unmap_shared_mapping_range(struct address_space *mapping,
80600 loff_t const holebegin, loff_t const holelen)
80601 @@ -1173,9 +1179,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
80602 }
80603 #endif
80604
80605 -extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
80606 -extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
80607 - void *buf, int len, int write);
80608 +extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
80609 +extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
80610 + void *buf, size_t len, int write);
80611
80612 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
80613 unsigned long start, unsigned long nr_pages,
80614 @@ -1208,34 +1214,6 @@ int set_page_dirty_lock(struct page *page);
80615 int clear_page_dirty_for_io(struct page *page);
80616 int get_cmdline(struct task_struct *task, char *buffer, int buflen);
80617
80618 -/* Is the vma a continuation of the stack vma above it? */
80619 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
80620 -{
80621 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
80622 -}
80623 -
80624 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
80625 - unsigned long addr)
80626 -{
80627 - return (vma->vm_flags & VM_GROWSDOWN) &&
80628 - (vma->vm_start == addr) &&
80629 - !vma_growsdown(vma->vm_prev, addr);
80630 -}
80631 -
80632 -/* Is the vma a continuation of the stack vma below it? */
80633 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
80634 -{
80635 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
80636 -}
80637 -
80638 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
80639 - unsigned long addr)
80640 -{
80641 - return (vma->vm_flags & VM_GROWSUP) &&
80642 - (vma->vm_end == addr) &&
80643 - !vma_growsup(vma->vm_next, addr);
80644 -}
80645 -
80646 extern pid_t
80647 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
80648
80649 @@ -1335,6 +1313,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
80650 }
80651 #endif
80652
80653 +#ifdef CONFIG_MMU
80654 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
80655 +#else
80656 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
80657 +{
80658 + return __pgprot(0);
80659 +}
80660 +#endif
80661 +
80662 int vma_wants_writenotify(struct vm_area_struct *vma);
80663
80664 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
80665 @@ -1353,8 +1340,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
80666 {
80667 return 0;
80668 }
80669 +
80670 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
80671 + unsigned long address)
80672 +{
80673 + return 0;
80674 +}
80675 #else
80676 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
80677 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
80678 #endif
80679
80680 #ifdef __PAGETABLE_PMD_FOLDED
80681 @@ -1363,8 +1357,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
80682 {
80683 return 0;
80684 }
80685 +
80686 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
80687 + unsigned long address)
80688 +{
80689 + return 0;
80690 +}
80691 #else
80692 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
80693 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
80694 #endif
80695
80696 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
80697 @@ -1382,11 +1383,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
80698 NULL: pud_offset(pgd, address);
80699 }
80700
80701 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
80702 +{
80703 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
80704 + NULL: pud_offset(pgd, address);
80705 +}
80706 +
80707 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
80708 {
80709 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
80710 NULL: pmd_offset(pud, address);
80711 }
80712 +
80713 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
80714 +{
80715 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
80716 + NULL: pmd_offset(pud, address);
80717 +}
80718 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
80719
80720 #if USE_SPLIT_PTE_PTLOCKS
80721 @@ -1783,7 +1796,7 @@ extern int install_special_mapping(struct mm_struct *mm,
80722 unsigned long addr, unsigned long len,
80723 unsigned long flags, struct page **pages);
80724
80725 -extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
80726 +extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
80727
80728 extern unsigned long mmap_region(struct file *file, unsigned long addr,
80729 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
80730 @@ -1791,6 +1804,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
80731 unsigned long len, unsigned long prot, unsigned long flags,
80732 unsigned long pgoff, unsigned long *populate);
80733 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
80734 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
80735
80736 #ifdef CONFIG_MMU
80737 extern int __mm_populate(unsigned long addr, unsigned long len,
80738 @@ -1819,10 +1833,11 @@ struct vm_unmapped_area_info {
80739 unsigned long high_limit;
80740 unsigned long align_mask;
80741 unsigned long align_offset;
80742 + unsigned long threadstack_offset;
80743 };
80744
80745 -extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
80746 -extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
80747 +extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
80748 +extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
80749
80750 /*
80751 * Search for an unmapped address range.
80752 @@ -1834,7 +1849,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
80753 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
80754 */
80755 static inline unsigned long
80756 -vm_unmapped_area(struct vm_unmapped_area_info *info)
80757 +vm_unmapped_area(const struct vm_unmapped_area_info *info)
80758 {
80759 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
80760 return unmapped_area(info);
80761 @@ -1896,6 +1911,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
80762 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
80763 struct vm_area_struct **pprev);
80764
80765 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
80766 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
80767 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
80768 +
80769 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
80770 NULL if none. Assume start_addr < end_addr. */
80771 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
80772 @@ -1924,15 +1943,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
80773 return vma;
80774 }
80775
80776 -#ifdef CONFIG_MMU
80777 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
80778 -#else
80779 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
80780 -{
80781 - return __pgprot(0);
80782 -}
80783 -#endif
80784 -
80785 #ifdef CONFIG_NUMA_BALANCING
80786 unsigned long change_prot_numa(struct vm_area_struct *vma,
80787 unsigned long start, unsigned long end);
80788 @@ -1984,6 +1994,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
80789 static inline void vm_stat_account(struct mm_struct *mm,
80790 unsigned long flags, struct file *file, long pages)
80791 {
80792 +
80793 +#ifdef CONFIG_PAX_RANDMMAP
80794 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
80795 +#endif
80796 +
80797 mm->total_vm += pages;
80798 }
80799 #endif /* CONFIG_PROC_FS */
80800 @@ -2065,7 +2080,7 @@ extern int unpoison_memory(unsigned long pfn);
80801 extern int sysctl_memory_failure_early_kill;
80802 extern int sysctl_memory_failure_recovery;
80803 extern void shake_page(struct page *p, int access);
80804 -extern atomic_long_t num_poisoned_pages;
80805 +extern atomic_long_unchecked_t num_poisoned_pages;
80806 extern int soft_offline_page(struct page *page, int flags);
80807
80808 #if defined(CONFIG_TRANSPARENT_HUGEPAGE) || defined(CONFIG_HUGETLBFS)
80809 @@ -2100,5 +2115,11 @@ void __init setup_nr_node_ids(void);
80810 static inline void setup_nr_node_ids(void) {}
80811 #endif
80812
80813 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
80814 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
80815 +#else
80816 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
80817 +#endif
80818 +
80819 #endif /* __KERNEL__ */
80820 #endif /* _LINUX_MM_H */
80821 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
80822 index 8967e20..61f7900 100644
80823 --- a/include/linux/mm_types.h
80824 +++ b/include/linux/mm_types.h
80825 @@ -308,7 +308,9 @@ struct vm_area_struct {
80826 #ifdef CONFIG_NUMA
80827 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
80828 #endif
80829 -};
80830 +
80831 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
80832 +} __randomize_layout;
80833
80834 struct core_thread {
80835 struct task_struct *task;
80836 @@ -454,7 +456,25 @@ struct mm_struct {
80837 bool tlb_flush_pending;
80838 #endif
80839 struct uprobes_state uprobes_state;
80840 -};
80841 +
80842 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
80843 + unsigned long pax_flags;
80844 +#endif
80845 +
80846 +#ifdef CONFIG_PAX_DLRESOLVE
80847 + unsigned long call_dl_resolve;
80848 +#endif
80849 +
80850 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
80851 + unsigned long call_syscall;
80852 +#endif
80853 +
80854 +#ifdef CONFIG_PAX_ASLR
80855 + unsigned long delta_mmap; /* randomized offset */
80856 + unsigned long delta_stack; /* randomized offset */
80857 +#endif
80858 +
80859 +} __randomize_layout;
80860
80861 static inline void mm_init_cpumask(struct mm_struct *mm)
80862 {
80863 diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
80864 index c5d5278..f0b68c8 100644
80865 --- a/include/linux/mmiotrace.h
80866 +++ b/include/linux/mmiotrace.h
80867 @@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
80868 /* Called from ioremap.c */
80869 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
80870 void __iomem *addr);
80871 -extern void mmiotrace_iounmap(volatile void __iomem *addr);
80872 +extern void mmiotrace_iounmap(const volatile void __iomem *addr);
80873
80874 /* For anyone to insert markers. Remember trailing newline. */
80875 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
80876 @@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
80877 {
80878 }
80879
80880 -static inline void mmiotrace_iounmap(volatile void __iomem *addr)
80881 +static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
80882 {
80883 }
80884
80885 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
80886 index 835aa3d..676b387 100644
80887 --- a/include/linux/mmzone.h
80888 +++ b/include/linux/mmzone.h
80889 @@ -406,7 +406,7 @@ struct zone {
80890 unsigned long flags; /* zone flags, see below */
80891
80892 /* Zone statistics */
80893 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
80894 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
80895
80896 /*
80897 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
80898 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
80899 index 44eeef0..a92d3f9 100644
80900 --- a/include/linux/mod_devicetable.h
80901 +++ b/include/linux/mod_devicetable.h
80902 @@ -139,7 +139,7 @@ struct usb_device_id {
80903 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
80904 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
80905
80906 -#define HID_ANY_ID (~0)
80907 +#define HID_ANY_ID (~0U)
80908 #define HID_BUS_ANY 0xffff
80909 #define HID_GROUP_ANY 0x0000
80910
80911 @@ -475,7 +475,7 @@ struct dmi_system_id {
80912 const char *ident;
80913 struct dmi_strmatch matches[4];
80914 void *driver_data;
80915 -};
80916 +} __do_const;
80917 /*
80918 * struct dmi_device_id appears during expansion of
80919 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
80920 diff --git a/include/linux/module.h b/include/linux/module.h
80921 index f520a76..5f898ef 100644
80922 --- a/include/linux/module.h
80923 +++ b/include/linux/module.h
80924 @@ -17,9 +17,11 @@
80925 #include <linux/moduleparam.h>
80926 #include <linux/jump_label.h>
80927 #include <linux/export.h>
80928 +#include <linux/fs.h>
80929
80930 #include <linux/percpu.h>
80931 #include <asm/module.h>
80932 +#include <asm/pgtable.h>
80933
80934 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
80935 #define MODULE_SIG_STRING "~Module signature appended~\n"
80936 @@ -42,7 +44,7 @@ struct module_kobject {
80937 struct kobject *drivers_dir;
80938 struct module_param_attrs *mp;
80939 struct completion *kobj_completion;
80940 -};
80941 +} __randomize_layout;
80942
80943 struct module_attribute {
80944 struct attribute attr;
80945 @@ -54,12 +56,13 @@ struct module_attribute {
80946 int (*test)(struct module *);
80947 void (*free)(struct module *);
80948 };
80949 +typedef struct module_attribute __no_const module_attribute_no_const;
80950
80951 struct module_version_attribute {
80952 struct module_attribute mattr;
80953 const char *module_name;
80954 const char *version;
80955 -} __attribute__ ((__aligned__(sizeof(void *))));
80956 +} __do_const __attribute__ ((__aligned__(sizeof(void *))));
80957
80958 extern ssize_t __modver_version_show(struct module_attribute *,
80959 struct module_kobject *, char *);
80960 @@ -235,7 +238,7 @@ struct module {
80961
80962 /* Sysfs stuff. */
80963 struct module_kobject mkobj;
80964 - struct module_attribute *modinfo_attrs;
80965 + module_attribute_no_const *modinfo_attrs;
80966 const char *version;
80967 const char *srcversion;
80968 struct kobject *holders_dir;
80969 @@ -284,19 +287,16 @@ struct module {
80970 int (*init)(void);
80971
80972 /* If this is non-NULL, vfree after init() returns */
80973 - void *module_init;
80974 + void *module_init_rx, *module_init_rw;
80975
80976 /* Here is the actual code + data, vfree'd on unload. */
80977 - void *module_core;
80978 + void *module_core_rx, *module_core_rw;
80979
80980 /* Here are the sizes of the init and core sections */
80981 - unsigned int init_size, core_size;
80982 + unsigned int init_size_rw, core_size_rw;
80983
80984 /* The size of the executable code in each section. */
80985 - unsigned int init_text_size, core_text_size;
80986 -
80987 - /* Size of RO sections of the module (text+rodata) */
80988 - unsigned int init_ro_size, core_ro_size;
80989 + unsigned int init_size_rx, core_size_rx;
80990
80991 /* Arch-specific module values */
80992 struct mod_arch_specific arch;
80993 @@ -352,6 +352,10 @@ struct module {
80994 #ifdef CONFIG_EVENT_TRACING
80995 struct ftrace_event_call **trace_events;
80996 unsigned int num_trace_events;
80997 + struct file_operations trace_id;
80998 + struct file_operations trace_enable;
80999 + struct file_operations trace_format;
81000 + struct file_operations trace_filter;
81001 #endif
81002 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
81003 unsigned int num_ftrace_callsites;
81004 @@ -375,7 +379,7 @@ struct module {
81005 ctor_fn_t *ctors;
81006 unsigned int num_ctors;
81007 #endif
81008 -};
81009 +} __randomize_layout;
81010 #ifndef MODULE_ARCH_INIT
81011 #define MODULE_ARCH_INIT {}
81012 #endif
81013 @@ -396,16 +400,46 @@ bool is_module_address(unsigned long addr);
81014 bool is_module_percpu_address(unsigned long addr);
81015 bool is_module_text_address(unsigned long addr);
81016
81017 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
81018 +{
81019 +
81020 +#ifdef CONFIG_PAX_KERNEXEC
81021 + if (ktla_ktva(addr) >= (unsigned long)start &&
81022 + ktla_ktva(addr) < (unsigned long)start + size)
81023 + return 1;
81024 +#endif
81025 +
81026 + return ((void *)addr >= start && (void *)addr < start + size);
81027 +}
81028 +
81029 +static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
81030 +{
81031 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
81032 +}
81033 +
81034 +static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
81035 +{
81036 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
81037 +}
81038 +
81039 +static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
81040 +{
81041 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
81042 +}
81043 +
81044 +static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
81045 +{
81046 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
81047 +}
81048 +
81049 static inline int within_module_core(unsigned long addr, const struct module *mod)
81050 {
81051 - return (unsigned long)mod->module_core <= addr &&
81052 - addr < (unsigned long)mod->module_core + mod->core_size;
81053 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
81054 }
81055
81056 static inline int within_module_init(unsigned long addr, const struct module *mod)
81057 {
81058 - return (unsigned long)mod->module_init <= addr &&
81059 - addr < (unsigned long)mod->module_init + mod->init_size;
81060 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
81061 }
81062
81063 /* Search for module by name: must hold module_mutex. */
81064 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
81065 index 560ca53..ef621ef 100644
81066 --- a/include/linux/moduleloader.h
81067 +++ b/include/linux/moduleloader.h
81068 @@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
81069 sections. Returns NULL on failure. */
81070 void *module_alloc(unsigned long size);
81071
81072 +#ifdef CONFIG_PAX_KERNEXEC
81073 +void *module_alloc_exec(unsigned long size);
81074 +#else
81075 +#define module_alloc_exec(x) module_alloc(x)
81076 +#endif
81077 +
81078 /* Free memory returned from module_alloc. */
81079 void module_free(struct module *mod, void *module_region);
81080
81081 +#ifdef CONFIG_PAX_KERNEXEC
81082 +void module_free_exec(struct module *mod, void *module_region);
81083 +#else
81084 +#define module_free_exec(x, y) module_free((x), (y))
81085 +#endif
81086 +
81087 /*
81088 * Apply the given relocation to the (simplified) ELF. Return -error
81089 * or 0.
81090 @@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
81091 unsigned int relsec,
81092 struct module *me)
81093 {
81094 +#ifdef CONFIG_MODULES
81095 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
81096 +#endif
81097 return -ENOEXEC;
81098 }
81099 #endif
81100 @@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
81101 unsigned int relsec,
81102 struct module *me)
81103 {
81104 +#ifdef CONFIG_MODULES
81105 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
81106 +#endif
81107 return -ENOEXEC;
81108 }
81109 #endif
81110 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
81111 index 204a677..e9b486a 100644
81112 --- a/include/linux/moduleparam.h
81113 +++ b/include/linux/moduleparam.h
81114 @@ -293,7 +293,7 @@ static inline void __kernel_param_unlock(void)
81115 * @len is usually just sizeof(string).
81116 */
81117 #define module_param_string(name, string, len, perm) \
81118 - static const struct kparam_string __param_string_##name \
81119 + static const struct kparam_string __param_string_##name __used \
81120 = { len, string }; \
81121 __module_param_call(MODULE_PARAM_PREFIX, name, \
81122 &param_ops_string, \
81123 @@ -432,7 +432,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
81124 */
81125 #define module_param_array_named(name, array, type, nump, perm) \
81126 param_check_##type(name, &(array)[0]); \
81127 - static const struct kparam_array __param_arr_##name \
81128 + static const struct kparam_array __param_arr_##name __used \
81129 = { .max = ARRAY_SIZE(array), .num = nump, \
81130 .ops = &param_ops_##type, \
81131 .elemsize = sizeof(array[0]), .elem = array }; \
81132 diff --git a/include/linux/mount.h b/include/linux/mount.h
81133 index 839bac2..a96b37c 100644
81134 --- a/include/linux/mount.h
81135 +++ b/include/linux/mount.h
81136 @@ -59,7 +59,7 @@ struct vfsmount {
81137 struct dentry *mnt_root; /* root of the mounted tree */
81138 struct super_block *mnt_sb; /* pointer to superblock */
81139 int mnt_flags;
81140 -};
81141 +} __randomize_layout;
81142
81143 struct file; /* forward dec */
81144
81145 diff --git a/include/linux/namei.h b/include/linux/namei.h
81146 index 492de72..1bddcd4 100644
81147 --- a/include/linux/namei.h
81148 +++ b/include/linux/namei.h
81149 @@ -19,7 +19,7 @@ struct nameidata {
81150 unsigned seq, m_seq;
81151 int last_type;
81152 unsigned depth;
81153 - char *saved_names[MAX_NESTED_LINKS + 1];
81154 + const char *saved_names[MAX_NESTED_LINKS + 1];
81155 };
81156
81157 /*
81158 @@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
81159
81160 extern void nd_jump_link(struct nameidata *nd, struct path *path);
81161
81162 -static inline void nd_set_link(struct nameidata *nd, char *path)
81163 +static inline void nd_set_link(struct nameidata *nd, const char *path)
81164 {
81165 nd->saved_names[nd->depth] = path;
81166 }
81167
81168 -static inline char *nd_get_link(struct nameidata *nd)
81169 +static inline const char *nd_get_link(const struct nameidata *nd)
81170 {
81171 return nd->saved_names[nd->depth];
81172 }
81173 diff --git a/include/linux/net.h b/include/linux/net.h
81174 index 17d8339..81656c0 100644
81175 --- a/include/linux/net.h
81176 +++ b/include/linux/net.h
81177 @@ -192,7 +192,7 @@ struct net_proto_family {
81178 int (*create)(struct net *net, struct socket *sock,
81179 int protocol, int kern);
81180 struct module *owner;
81181 -};
81182 +} __do_const;
81183
81184 struct iovec;
81185 struct kvec;
81186 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
81187 index b42d07b..7f45ae2 100644
81188 --- a/include/linux/netdevice.h
81189 +++ b/include/linux/netdevice.h
81190 @@ -1146,6 +1146,7 @@ struct net_device_ops {
81191 void *priv);
81192 int (*ndo_get_lock_subclass)(struct net_device *dev);
81193 };
81194 +typedef struct net_device_ops __no_const net_device_ops_no_const;
81195
81196 /**
81197 * enum net_device_priv_flags - &struct net_device priv_flags
81198 @@ -1313,11 +1314,11 @@ struct net_device {
81199 struct net_device_stats stats;
81200
81201 /* dropped packets by core network, Do not use this in drivers */
81202 - atomic_long_t rx_dropped;
81203 - atomic_long_t tx_dropped;
81204 + atomic_long_unchecked_t rx_dropped;
81205 + atomic_long_unchecked_t tx_dropped;
81206
81207 /* Stats to monitor carrier on<->off transitions */
81208 - atomic_t carrier_changes;
81209 + atomic_unchecked_t carrier_changes;
81210
81211 #ifdef CONFIG_WIRELESS_EXT
81212 /* List of functions to handle Wireless Extensions (instead of ioctl).
81213 diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
81214 index 2077489..a15e561 100644
81215 --- a/include/linux/netfilter.h
81216 +++ b/include/linux/netfilter.h
81217 @@ -84,7 +84,7 @@ struct nf_sockopt_ops {
81218 #endif
81219 /* Use the module struct to lock set/get code in place */
81220 struct module *owner;
81221 -};
81222 +} __do_const;
81223
81224 /* Function to register/unregister hook points. */
81225 int nf_register_hook(struct nf_hook_ops *reg);
81226 diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
81227 index e955d47..04a5338 100644
81228 --- a/include/linux/netfilter/nfnetlink.h
81229 +++ b/include/linux/netfilter/nfnetlink.h
81230 @@ -19,7 +19,7 @@ struct nfnl_callback {
81231 const struct nlattr * const cda[]);
81232 const struct nla_policy *policy; /* netlink attribute policy */
81233 const u_int16_t attr_count; /* number of nlattr's */
81234 -};
81235 +} __do_const;
81236
81237 struct nfnetlink_subsystem {
81238 const char *name;
81239 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
81240 new file mode 100644
81241 index 0000000..33f4af8
81242 --- /dev/null
81243 +++ b/include/linux/netfilter/xt_gradm.h
81244 @@ -0,0 +1,9 @@
81245 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
81246 +#define _LINUX_NETFILTER_XT_GRADM_H 1
81247 +
81248 +struct xt_gradm_mtinfo {
81249 + __u16 flags;
81250 + __u16 invflags;
81251 +};
81252 +
81253 +#endif
81254 diff --git a/include/linux/nls.h b/include/linux/nls.h
81255 index 520681b..1d67ed2 100644
81256 --- a/include/linux/nls.h
81257 +++ b/include/linux/nls.h
81258 @@ -31,7 +31,7 @@ struct nls_table {
81259 const unsigned char *charset2upper;
81260 struct module *owner;
81261 struct nls_table *next;
81262 -};
81263 +} __do_const;
81264
81265 /* this value hold the maximum octet of charset */
81266 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
81267 diff --git a/include/linux/notifier.h b/include/linux/notifier.h
81268 index d14a4c3..a078786 100644
81269 --- a/include/linux/notifier.h
81270 +++ b/include/linux/notifier.h
81271 @@ -54,7 +54,8 @@ struct notifier_block {
81272 notifier_fn_t notifier_call;
81273 struct notifier_block __rcu *next;
81274 int priority;
81275 -};
81276 +} __do_const;
81277 +typedef struct notifier_block __no_const notifier_block_no_const;
81278
81279 struct atomic_notifier_head {
81280 spinlock_t lock;
81281 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
81282 index b2a0f15..4d7da32 100644
81283 --- a/include/linux/oprofile.h
81284 +++ b/include/linux/oprofile.h
81285 @@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
81286 int oprofilefs_create_ro_ulong(struct dentry * root,
81287 char const * name, ulong * val);
81288
81289 -/** Create a file for read-only access to an atomic_t. */
81290 +/** Create a file for read-only access to an atomic_unchecked_t. */
81291 int oprofilefs_create_ro_atomic(struct dentry * root,
81292 - char const * name, atomic_t * val);
81293 + char const * name, atomic_unchecked_t * val);
81294
81295 /** create a directory */
81296 struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
81297 diff --git a/include/linux/padata.h b/include/linux/padata.h
81298 index 4386946..f50c615 100644
81299 --- a/include/linux/padata.h
81300 +++ b/include/linux/padata.h
81301 @@ -129,7 +129,7 @@ struct parallel_data {
81302 struct padata_serial_queue __percpu *squeue;
81303 atomic_t reorder_objects;
81304 atomic_t refcnt;
81305 - atomic_t seq_nr;
81306 + atomic_unchecked_t seq_nr;
81307 struct padata_cpumask cpumask;
81308 spinlock_t lock ____cacheline_aligned;
81309 unsigned int processed;
81310 diff --git a/include/linux/path.h b/include/linux/path.h
81311 index d137218..be0c176 100644
81312 --- a/include/linux/path.h
81313 +++ b/include/linux/path.h
81314 @@ -1,13 +1,15 @@
81315 #ifndef _LINUX_PATH_H
81316 #define _LINUX_PATH_H
81317
81318 +#include <linux/compiler.h>
81319 +
81320 struct dentry;
81321 struct vfsmount;
81322
81323 struct path {
81324 struct vfsmount *mnt;
81325 struct dentry *dentry;
81326 -};
81327 +} __randomize_layout;
81328
81329 extern void path_get(const struct path *);
81330 extern void path_put(const struct path *);
81331 diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
81332 index 5f2e559..7d59314 100644
81333 --- a/include/linux/pci_hotplug.h
81334 +++ b/include/linux/pci_hotplug.h
81335 @@ -71,7 +71,8 @@ struct hotplug_slot_ops {
81336 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
81337 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
81338 int (*reset_slot) (struct hotplug_slot *slot, int probe);
81339 -};
81340 +} __do_const;
81341 +typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
81342
81343 /**
81344 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
81345 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
81346 index 3ef6ea1..ed1a248 100644
81347 --- a/include/linux/perf_event.h
81348 +++ b/include/linux/perf_event.h
81349 @@ -328,8 +328,8 @@ struct perf_event {
81350
81351 enum perf_event_active_state state;
81352 unsigned int attach_state;
81353 - local64_t count;
81354 - atomic64_t child_count;
81355 + local64_t count; /* PaX: fix it one day */
81356 + atomic64_unchecked_t child_count;
81357
81358 /*
81359 * These are the total time in nanoseconds that the event
81360 @@ -380,8 +380,8 @@ struct perf_event {
81361 * These accumulate total time (in nanoseconds) that children
81362 * events have been enabled and running, respectively.
81363 */
81364 - atomic64_t child_total_time_enabled;
81365 - atomic64_t child_total_time_running;
81366 + atomic64_unchecked_t child_total_time_enabled;
81367 + atomic64_unchecked_t child_total_time_running;
81368
81369 /*
81370 * Protect attach/detach and child_list:
81371 @@ -710,7 +710,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
81372 entry->ip[entry->nr++] = ip;
81373 }
81374
81375 -extern int sysctl_perf_event_paranoid;
81376 +extern int sysctl_perf_event_legitimately_concerned;
81377 extern int sysctl_perf_event_mlock;
81378 extern int sysctl_perf_event_sample_rate;
81379 extern int sysctl_perf_cpu_time_max_percent;
81380 @@ -725,19 +725,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
81381 loff_t *ppos);
81382
81383
81384 +static inline bool perf_paranoid_any(void)
81385 +{
81386 + return sysctl_perf_event_legitimately_concerned > 2;
81387 +}
81388 +
81389 static inline bool perf_paranoid_tracepoint_raw(void)
81390 {
81391 - return sysctl_perf_event_paranoid > -1;
81392 + return sysctl_perf_event_legitimately_concerned > -1;
81393 }
81394
81395 static inline bool perf_paranoid_cpu(void)
81396 {
81397 - return sysctl_perf_event_paranoid > 0;
81398 + return sysctl_perf_event_legitimately_concerned > 0;
81399 }
81400
81401 static inline bool perf_paranoid_kernel(void)
81402 {
81403 - return sysctl_perf_event_paranoid > 1;
81404 + return sysctl_perf_event_legitimately_concerned > 1;
81405 }
81406
81407 extern void perf_event_init(void);
81408 @@ -867,7 +872,7 @@ struct perf_pmu_events_attr {
81409 struct device_attribute attr;
81410 u64 id;
81411 const char *event_str;
81412 -};
81413 +} __do_const;
81414
81415 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
81416 static struct perf_pmu_events_attr _var = { \
81417 diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
81418 index 7246ef3..1539ea4 100644
81419 --- a/include/linux/pid_namespace.h
81420 +++ b/include/linux/pid_namespace.h
81421 @@ -43,7 +43,7 @@ struct pid_namespace {
81422 int hide_pid;
81423 int reboot; /* group exit code if this pidns was rebooted */
81424 unsigned int proc_inum;
81425 -};
81426 +} __randomize_layout;
81427
81428 extern struct pid_namespace init_pid_ns;
81429
81430 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
81431 index eb8b8ac..62649e1 100644
81432 --- a/include/linux/pipe_fs_i.h
81433 +++ b/include/linux/pipe_fs_i.h
81434 @@ -47,10 +47,10 @@ struct pipe_inode_info {
81435 struct mutex mutex;
81436 wait_queue_head_t wait;
81437 unsigned int nrbufs, curbuf, buffers;
81438 - unsigned int readers;
81439 - unsigned int writers;
81440 - unsigned int files;
81441 - unsigned int waiting_writers;
81442 + atomic_t readers;
81443 + atomic_t writers;
81444 + atomic_t files;
81445 + atomic_t waiting_writers;
81446 unsigned int r_counter;
81447 unsigned int w_counter;
81448 struct page *tmp_page;
81449 diff --git a/include/linux/pm.h b/include/linux/pm.h
81450 index d915d03..0531037 100644
81451 --- a/include/linux/pm.h
81452 +++ b/include/linux/pm.h
81453 @@ -600,6 +600,7 @@ extern int dev_pm_put_subsys_data(struct device *dev);
81454 struct dev_pm_domain {
81455 struct dev_pm_ops ops;
81456 };
81457 +typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
81458
81459 /*
81460 * The PM_EVENT_ messages are also used by drivers implementing the legacy
81461 diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
81462 index 7c1d252..0e7061d 100644
81463 --- a/include/linux/pm_domain.h
81464 +++ b/include/linux/pm_domain.h
81465 @@ -44,11 +44,11 @@ struct gpd_dev_ops {
81466 int (*thaw_early)(struct device *dev);
81467 int (*thaw)(struct device *dev);
81468 bool (*active_wakeup)(struct device *dev);
81469 -};
81470 +} __no_const;
81471
81472 struct gpd_cpu_data {
81473 unsigned int saved_exit_latency;
81474 - struct cpuidle_state *idle_state;
81475 + cpuidle_state_no_const *idle_state;
81476 };
81477
81478 struct generic_pm_domain {
81479 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
81480 index 2a5897a..4f9af63 100644
81481 --- a/include/linux/pm_runtime.h
81482 +++ b/include/linux/pm_runtime.h
81483 @@ -113,7 +113,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
81484
81485 static inline void pm_runtime_mark_last_busy(struct device *dev)
81486 {
81487 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
81488 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
81489 }
81490
81491 #else /* !CONFIG_PM_RUNTIME */
81492 diff --git a/include/linux/pnp.h b/include/linux/pnp.h
81493 index 195aafc..49a7bc2 100644
81494 --- a/include/linux/pnp.h
81495 +++ b/include/linux/pnp.h
81496 @@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
81497 struct pnp_fixup {
81498 char id[7];
81499 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
81500 -};
81501 +} __do_const;
81502
81503 /* config parameters */
81504 #define PNP_CONFIG_NORMAL 0x0001
81505 diff --git a/include/linux/poison.h b/include/linux/poison.h
81506 index 2110a81..13a11bb 100644
81507 --- a/include/linux/poison.h
81508 +++ b/include/linux/poison.h
81509 @@ -19,8 +19,8 @@
81510 * under normal circumstances, used to verify that nobody uses
81511 * non-initialized list entries.
81512 */
81513 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
81514 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
81515 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
81516 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
81517
81518 /********** include/linux/timer.h **********/
81519 /*
81520 diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
81521 index d8b187c3..9a9257a 100644
81522 --- a/include/linux/power/smartreflex.h
81523 +++ b/include/linux/power/smartreflex.h
81524 @@ -238,7 +238,7 @@ struct omap_sr_class_data {
81525 int (*notify)(struct omap_sr *sr, u32 status);
81526 u8 notify_flags;
81527 u8 class_type;
81528 -};
81529 +} __do_const;
81530
81531 /**
81532 * struct omap_sr_nvalue_table - Smartreflex n-target value info
81533 diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
81534 index 4ea1d37..80f4b33 100644
81535 --- a/include/linux/ppp-comp.h
81536 +++ b/include/linux/ppp-comp.h
81537 @@ -84,7 +84,7 @@ struct compressor {
81538 struct module *owner;
81539 /* Extra skb space needed by the compressor algorithm */
81540 unsigned int comp_extra;
81541 -};
81542 +} __do_const;
81543
81544 /*
81545 * The return value from decompress routine is the length of the
81546 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
81547 index de83b4e..c4b997d 100644
81548 --- a/include/linux/preempt.h
81549 +++ b/include/linux/preempt.h
81550 @@ -27,11 +27,16 @@ extern void preempt_count_sub(int val);
81551 #define preempt_count_dec_and_test() __preempt_count_dec_and_test()
81552 #endif
81553
81554 +#define raw_preempt_count_add(val) __preempt_count_add(val)
81555 +#define raw_preempt_count_sub(val) __preempt_count_sub(val)
81556 +
81557 #define __preempt_count_inc() __preempt_count_add(1)
81558 #define __preempt_count_dec() __preempt_count_sub(1)
81559
81560 #define preempt_count_inc() preempt_count_add(1)
81561 +#define raw_preempt_count_inc() raw_preempt_count_add(1)
81562 #define preempt_count_dec() preempt_count_sub(1)
81563 +#define raw_preempt_count_dec() raw_preempt_count_sub(1)
81564
81565 #ifdef CONFIG_PREEMPT_COUNT
81566
81567 @@ -41,6 +46,12 @@ do { \
81568 barrier(); \
81569 } while (0)
81570
81571 +#define raw_preempt_disable() \
81572 +do { \
81573 + raw_preempt_count_inc(); \
81574 + barrier(); \
81575 +} while (0)
81576 +
81577 #define sched_preempt_enable_no_resched() \
81578 do { \
81579 barrier(); \
81580 @@ -49,6 +60,12 @@ do { \
81581
81582 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
81583
81584 +#define raw_preempt_enable_no_resched() \
81585 +do { \
81586 + barrier(); \
81587 + raw_preempt_count_dec(); \
81588 +} while (0)
81589 +
81590 #ifdef CONFIG_PREEMPT
81591 #define preempt_enable() \
81592 do { \
81593 @@ -113,8 +130,10 @@ do { \
81594 * region.
81595 */
81596 #define preempt_disable() barrier()
81597 +#define raw_preempt_disable() barrier()
81598 #define sched_preempt_enable_no_resched() barrier()
81599 #define preempt_enable_no_resched() barrier()
81600 +#define raw_preempt_enable_no_resched() barrier()
81601 #define preempt_enable() barrier()
81602 #define preempt_check_resched() do { } while (0)
81603
81604 @@ -128,11 +147,13 @@ do { \
81605 /*
81606 * Modules have no business playing preemption tricks.
81607 */
81608 +#ifndef CONFIG_PAX_KERNEXEC
81609 #undef sched_preempt_enable_no_resched
81610 #undef preempt_enable_no_resched
81611 #undef preempt_enable_no_resched_notrace
81612 #undef preempt_check_resched
81613 #endif
81614 +#endif
81615
81616 #define preempt_set_need_resched() \
81617 do { \
81618 diff --git a/include/linux/printk.h b/include/linux/printk.h
81619 index 8752f75..2b80c0f 100644
81620 --- a/include/linux/printk.h
81621 +++ b/include/linux/printk.h
81622 @@ -110,6 +110,8 @@ static inline __printf(1, 2) __cold
81623 void early_printk(const char *s, ...) { }
81624 #endif
81625
81626 +extern int kptr_restrict;
81627 +
81628 #ifdef CONFIG_PRINTK
81629 asmlinkage __printf(5, 0)
81630 int vprintk_emit(int facility, int level,
81631 @@ -144,7 +146,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
81632
81633 extern int printk_delay_msec;
81634 extern int dmesg_restrict;
81635 -extern int kptr_restrict;
81636
81637 extern void wake_up_klogd(void);
81638
81639 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
81640 index 608e60a..79cfb18 100644
81641 --- a/include/linux/proc_fs.h
81642 +++ b/include/linux/proc_fs.h
81643 @@ -17,8 +17,11 @@ extern void proc_flush_task(struct task_struct *);
81644 extern struct proc_dir_entry *proc_symlink(const char *,
81645 struct proc_dir_entry *, const char *);
81646 extern struct proc_dir_entry *proc_mkdir(const char *, struct proc_dir_entry *);
81647 +extern struct proc_dir_entry *proc_mkdir_restrict(const char *, struct proc_dir_entry *);
81648 extern struct proc_dir_entry *proc_mkdir_data(const char *, umode_t,
81649 struct proc_dir_entry *, void *);
81650 +extern struct proc_dir_entry *proc_mkdir_data_restrict(const char *, umode_t,
81651 + struct proc_dir_entry *, void *);
81652 extern struct proc_dir_entry *proc_mkdir_mode(const char *, umode_t,
81653 struct proc_dir_entry *);
81654
81655 @@ -34,6 +37,19 @@ static inline struct proc_dir_entry *proc_create(
81656 return proc_create_data(name, mode, parent, proc_fops, NULL);
81657 }
81658
81659 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
81660 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
81661 +{
81662 +#ifdef CONFIG_GRKERNSEC_PROC_USER
81663 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
81664 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
81665 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
81666 +#else
81667 + return proc_create_data(name, mode, parent, proc_fops, NULL);
81668 +#endif
81669 +}
81670 +
81671 +
81672 extern void proc_set_size(struct proc_dir_entry *, loff_t);
81673 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
81674 extern void *PDE_DATA(const struct inode *);
81675 @@ -52,8 +68,12 @@ static inline struct proc_dir_entry *proc_symlink(const char *name,
81676 struct proc_dir_entry *parent,const char *dest) { return NULL;}
81677 static inline struct proc_dir_entry *proc_mkdir(const char *name,
81678 struct proc_dir_entry *parent) {return NULL;}
81679 +static inline struct proc_dir_entry *proc_mkdir_restrict(const char *name,
81680 + struct proc_dir_entry *parent) { return NULL; }
81681 static inline struct proc_dir_entry *proc_mkdir_data(const char *name,
81682 umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
81683 +static inline struct proc_dir_entry *proc_mkdir_data_restrict(const char *name,
81684 + umode_t mode, struct proc_dir_entry *parent, void *data) { return NULL; }
81685 static inline struct proc_dir_entry *proc_mkdir_mode(const char *name,
81686 umode_t mode, struct proc_dir_entry *parent) { return NULL; }
81687 #define proc_create(name, mode, parent, proc_fops) ({NULL;})
81688 @@ -73,7 +93,7 @@ static inline int remove_proc_subtree(const char *name, struct proc_dir_entry *p
81689 static inline struct proc_dir_entry *proc_net_mkdir(
81690 struct net *net, const char *name, struct proc_dir_entry *parent)
81691 {
81692 - return proc_mkdir_data(name, 0, parent, net);
81693 + return proc_mkdir_data_restrict(name, 0, parent, net);
81694 }
81695
81696 #endif /* _LINUX_PROC_FS_H */
81697 diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
81698 index 34a1e10..70f6bde 100644
81699 --- a/include/linux/proc_ns.h
81700 +++ b/include/linux/proc_ns.h
81701 @@ -14,7 +14,7 @@ struct proc_ns_operations {
81702 void (*put)(void *ns);
81703 int (*install)(struct nsproxy *nsproxy, void *ns);
81704 unsigned int (*inum)(void *ns);
81705 -};
81706 +} __do_const __randomize_layout;
81707
81708 struct proc_ns {
81709 void *ns;
81710 diff --git a/include/linux/quota.h b/include/linux/quota.h
81711 index cc7494a..1e27036 100644
81712 --- a/include/linux/quota.h
81713 +++ b/include/linux/quota.h
81714 @@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
81715
81716 extern bool qid_eq(struct kqid left, struct kqid right);
81717 extern bool qid_lt(struct kqid left, struct kqid right);
81718 -extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
81719 +extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
81720 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
81721 extern bool qid_valid(struct kqid qid);
81722
81723 diff --git a/include/linux/random.h b/include/linux/random.h
81724 index 57fbbff..2331f3f 100644
81725 --- a/include/linux/random.h
81726 +++ b/include/linux/random.h
81727 @@ -9,9 +9,19 @@
81728 #include <uapi/linux/random.h>
81729
81730 extern void add_device_randomness(const void *, unsigned int);
81731 +
81732 +static inline void add_latent_entropy(void)
81733 +{
81734 +
81735 +#ifdef LATENT_ENTROPY_PLUGIN
81736 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
81737 +#endif
81738 +
81739 +}
81740 +
81741 extern void add_input_randomness(unsigned int type, unsigned int code,
81742 - unsigned int value);
81743 -extern void add_interrupt_randomness(int irq, int irq_flags);
81744 + unsigned int value) __latent_entropy;
81745 +extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
81746
81747 extern void get_random_bytes(void *buf, int nbytes);
81748 extern void get_random_bytes_arch(void *buf, int nbytes);
81749 @@ -22,10 +32,10 @@ extern int random_int_secret_init(void);
81750 extern const struct file_operations random_fops, urandom_fops;
81751 #endif
81752
81753 -unsigned int get_random_int(void);
81754 +unsigned int __intentional_overflow(-1) get_random_int(void);
81755 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
81756
81757 -u32 prandom_u32(void);
81758 +u32 prandom_u32(void) __intentional_overflow(-1);
81759 void prandom_bytes(void *buf, int nbytes);
81760 void prandom_seed(u32 seed);
81761 void prandom_reseed_late(void);
81762 @@ -37,6 +47,11 @@ struct rnd_state {
81763 u32 prandom_u32_state(struct rnd_state *state);
81764 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
81765
81766 +static inline unsigned long __intentional_overflow(-1) pax_get_random_long(void)
81767 +{
81768 + return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
81769 +}
81770 +
81771 /**
81772 * prandom_u32_max - returns a pseudo-random number in interval [0, ep_ro)
81773 * @ep_ro: right open interval endpoint
81774 diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h
81775 index fea49b5..2ac22bb 100644
81776 --- a/include/linux/rbtree_augmented.h
81777 +++ b/include/linux/rbtree_augmented.h
81778 @@ -80,7 +80,9 @@ rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \
81779 old->rbaugmented = rbcompute(old); \
81780 } \
81781 rbstatic const struct rb_augment_callbacks rbname = { \
81782 - rbname ## _propagate, rbname ## _copy, rbname ## _rotate \
81783 + .propagate = rbname ## _propagate, \
81784 + .copy = rbname ## _copy, \
81785 + .rotate = rbname ## _rotate \
81786 };
81787
81788
81789 diff --git a/include/linux/rculist.h b/include/linux/rculist.h
81790 index 8183b46..a388711 100644
81791 --- a/include/linux/rculist.h
81792 +++ b/include/linux/rculist.h
81793 @@ -29,8 +29,8 @@
81794 */
81795 static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
81796 {
81797 - ACCESS_ONCE(list->next) = list;
81798 - ACCESS_ONCE(list->prev) = list;
81799 + ACCESS_ONCE_RW(list->next) = list;
81800 + ACCESS_ONCE_RW(list->prev) = list;
81801 }
81802
81803 /*
81804 @@ -59,6 +59,9 @@ void __list_add_rcu(struct list_head *new,
81805 struct list_head *prev, struct list_head *next);
81806 #endif
81807
81808 +void __pax_list_add_rcu(struct list_head *new,
81809 + struct list_head *prev, struct list_head *next);
81810 +
81811 /**
81812 * list_add_rcu - add a new entry to rcu-protected list
81813 * @new: new entry to be added
81814 @@ -80,6 +83,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
81815 __list_add_rcu(new, head, head->next);
81816 }
81817
81818 +static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
81819 +{
81820 + __pax_list_add_rcu(new, head, head->next);
81821 +}
81822 +
81823 /**
81824 * list_add_tail_rcu - add a new entry to rcu-protected list
81825 * @new: new entry to be added
81826 @@ -102,6 +110,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
81827 __list_add_rcu(new, head->prev, head);
81828 }
81829
81830 +static inline void pax_list_add_tail_rcu(struct list_head *new,
81831 + struct list_head *head)
81832 +{
81833 + __pax_list_add_rcu(new, head->prev, head);
81834 +}
81835 +
81836 /**
81837 * list_del_rcu - deletes entry from list without re-initialization
81838 * @entry: the element to delete from the list.
81839 @@ -132,6 +146,8 @@ static inline void list_del_rcu(struct list_head *entry)
81840 entry->prev = LIST_POISON2;
81841 }
81842
81843 +extern void pax_list_del_rcu(struct list_head *entry);
81844 +
81845 /**
81846 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
81847 * @n: the element to delete from the hash list.
81848 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
81849 index 48bf152..d38b785 100644
81850 --- a/include/linux/reboot.h
81851 +++ b/include/linux/reboot.h
81852 @@ -44,9 +44,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
81853 */
81854
81855 extern void migrate_to_reboot_cpu(void);
81856 -extern void machine_restart(char *cmd);
81857 -extern void machine_halt(void);
81858 -extern void machine_power_off(void);
81859 +extern void machine_restart(char *cmd) __noreturn;
81860 +extern void machine_halt(void) __noreturn;
81861 +extern void machine_power_off(void) __noreturn;
81862
81863 extern void machine_shutdown(void);
81864 struct pt_regs;
81865 @@ -57,9 +57,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
81866 */
81867
81868 extern void kernel_restart_prepare(char *cmd);
81869 -extern void kernel_restart(char *cmd);
81870 -extern void kernel_halt(void);
81871 -extern void kernel_power_off(void);
81872 +extern void kernel_restart(char *cmd) __noreturn;
81873 +extern void kernel_halt(void) __noreturn;
81874 +extern void kernel_power_off(void) __noreturn;
81875
81876 extern int C_A_D; /* for sysctl */
81877 void ctrl_alt_del(void);
81878 @@ -73,7 +73,7 @@ extern int orderly_poweroff(bool force);
81879 * Emergency restart, callable from an interrupt handler.
81880 */
81881
81882 -extern void emergency_restart(void);
81883 +extern void emergency_restart(void) __noreturn;
81884 #include <asm/emergency-restart.h>
81885
81886 #endif /* _LINUX_REBOOT_H */
81887 diff --git a/include/linux/regset.h b/include/linux/regset.h
81888 index 8e0c9fe..ac4d221 100644
81889 --- a/include/linux/regset.h
81890 +++ b/include/linux/regset.h
81891 @@ -161,7 +161,8 @@ struct user_regset {
81892 unsigned int align;
81893 unsigned int bias;
81894 unsigned int core_note_type;
81895 -};
81896 +} __do_const;
81897 +typedef struct user_regset __no_const user_regset_no_const;
81898
81899 /**
81900 * struct user_regset_view - available regsets
81901 diff --git a/include/linux/relay.h b/include/linux/relay.h
81902 index d7c8359..818daf5 100644
81903 --- a/include/linux/relay.h
81904 +++ b/include/linux/relay.h
81905 @@ -157,7 +157,7 @@ struct rchan_callbacks
81906 * The callback should return 0 if successful, negative if not.
81907 */
81908 int (*remove_buf_file)(struct dentry *dentry);
81909 -};
81910 +} __no_const;
81911
81912 /*
81913 * CONFIG_RELAY kernel API, kernel/relay.c
81914 diff --git a/include/linux/rio.h b/include/linux/rio.h
81915 index 6bda06f..bf39a9b 100644
81916 --- a/include/linux/rio.h
81917 +++ b/include/linux/rio.h
81918 @@ -358,7 +358,7 @@ struct rio_ops {
81919 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
81920 u64 rstart, u32 size, u32 flags);
81921 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
81922 -};
81923 +} __no_const;
81924
81925 #define RIO_RESOURCE_MEM 0x00000100
81926 #define RIO_RESOURCE_DOORBELL 0x00000200
81927 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
81928 index b66c211..13d2915 100644
81929 --- a/include/linux/rmap.h
81930 +++ b/include/linux/rmap.h
81931 @@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
81932 void anon_vma_init(void); /* create anon_vma_cachep */
81933 int anon_vma_prepare(struct vm_area_struct *);
81934 void unlink_anon_vmas(struct vm_area_struct *);
81935 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
81936 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
81937 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
81938 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
81939
81940 static inline void anon_vma_merge(struct vm_area_struct *vma,
81941 struct vm_area_struct *next)
81942 diff --git a/include/linux/scatterlist.h b/include/linux/scatterlist.h
81943 index a964f72..b475afb 100644
81944 --- a/include/linux/scatterlist.h
81945 +++ b/include/linux/scatterlist.h
81946 @@ -1,6 +1,7 @@
81947 #ifndef _LINUX_SCATTERLIST_H
81948 #define _LINUX_SCATTERLIST_H
81949
81950 +#include <linux/sched.h>
81951 #include <linux/string.h>
81952 #include <linux/bug.h>
81953 #include <linux/mm.h>
81954 @@ -114,6 +115,12 @@ static inline void sg_set_buf(struct scatterlist *sg, const void *buf,
81955 #ifdef CONFIG_DEBUG_SG
81956 BUG_ON(!virt_addr_valid(buf));
81957 #endif
81958 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
81959 + if (object_starts_on_stack(buf)) {
81960 + void *adjbuf = buf - current->stack + current->lowmem_stack;
81961 + sg_set_page(sg, virt_to_page(adjbuf), buflen, offset_in_page(adjbuf));
81962 + } else
81963 +#endif
81964 sg_set_page(sg, virt_to_page(buf), buflen, offset_in_page(buf));
81965 }
81966
81967 diff --git a/include/linux/sched.h b/include/linux/sched.h
81968 index 221b2bd..e2e5f82 100644
81969 --- a/include/linux/sched.h
81970 +++ b/include/linux/sched.h
81971 @@ -131,6 +131,7 @@ struct fs_struct;
81972 struct perf_event_context;
81973 struct blk_plug;
81974 struct filename;
81975 +struct linux_binprm;
81976
81977 #define VMACACHE_BITS 2
81978 #define VMACACHE_SIZE (1U << VMACACHE_BITS)
81979 @@ -380,7 +381,7 @@ extern char __sched_text_start[], __sched_text_end[];
81980 extern int in_sched_functions(unsigned long addr);
81981
81982 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
81983 -extern signed long schedule_timeout(signed long timeout);
81984 +extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
81985 extern signed long schedule_timeout_interruptible(signed long timeout);
81986 extern signed long schedule_timeout_killable(signed long timeout);
81987 extern signed long schedule_timeout_uninterruptible(signed long timeout);
81988 @@ -391,6 +392,19 @@ struct nsproxy;
81989 struct user_namespace;
81990
81991 #ifdef CONFIG_MMU
81992 +
81993 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
81994 +extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
81995 +#else
81996 +static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
81997 +{
81998 + return 0;
81999 +}
82000 +#endif
82001 +
82002 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
82003 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
82004 +
82005 extern void arch_pick_mmap_layout(struct mm_struct *mm);
82006 extern unsigned long
82007 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
82008 @@ -688,6 +702,17 @@ struct signal_struct {
82009 #ifdef CONFIG_TASKSTATS
82010 struct taskstats *stats;
82011 #endif
82012 +
82013 +#ifdef CONFIG_GRKERNSEC
82014 + u32 curr_ip;
82015 + u32 saved_ip;
82016 + u32 gr_saddr;
82017 + u32 gr_daddr;
82018 + u16 gr_sport;
82019 + u16 gr_dport;
82020 + u8 used_accept:1;
82021 +#endif
82022 +
82023 #ifdef CONFIG_AUDIT
82024 unsigned audit_tty;
82025 unsigned audit_tty_log_passwd;
82026 @@ -714,7 +739,7 @@ struct signal_struct {
82027 struct mutex cred_guard_mutex; /* guard against foreign influences on
82028 * credential calculations
82029 * (notably. ptrace) */
82030 -};
82031 +} __randomize_layout;
82032
82033 /*
82034 * Bits in flags field of signal_struct.
82035 @@ -768,6 +793,14 @@ struct user_struct {
82036 struct key *session_keyring; /* UID's default session keyring */
82037 #endif
82038
82039 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
82040 + unsigned char kernel_banned;
82041 +#endif
82042 +#ifdef CONFIG_GRKERNSEC_BRUTE
82043 + unsigned char suid_banned;
82044 + unsigned long suid_ban_expires;
82045 +#endif
82046 +
82047 /* Hash table maintenance information */
82048 struct hlist_node uidhash_node;
82049 kuid_t uid;
82050 @@ -775,7 +808,7 @@ struct user_struct {
82051 #ifdef CONFIG_PERF_EVENTS
82052 atomic_long_t locked_vm;
82053 #endif
82054 -};
82055 +} __randomize_layout;
82056
82057 extern int uids_sysfs_init(void);
82058
82059 @@ -1179,6 +1212,9 @@ enum perf_event_task_context {
82060 struct task_struct {
82061 volatile long state; /* -1 unrunnable, 0 runnable, >0 stopped */
82062 void *stack;
82063 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
82064 + void *lowmem_stack;
82065 +#endif
82066 atomic_t usage;
82067 unsigned int flags; /* per process flags, defined below */
82068 unsigned int ptrace;
82069 @@ -1304,8 +1340,8 @@ struct task_struct {
82070 struct list_head thread_node;
82071
82072 struct completion *vfork_done; /* for vfork() */
82073 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
82074 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
82075 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
82076 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
82077
82078 cputime_t utime, stime, utimescaled, stimescaled;
82079 cputime_t gtime;
82080 @@ -1330,11 +1366,6 @@ struct task_struct {
82081 struct task_cputime cputime_expires;
82082 struct list_head cpu_timers[3];
82083
82084 -/* process credentials */
82085 - const struct cred __rcu *real_cred; /* objective and real subjective task
82086 - * credentials (COW) */
82087 - const struct cred __rcu *cred; /* effective (overridable) subjective task
82088 - * credentials (COW) */
82089 char comm[TASK_COMM_LEN]; /* executable name excluding path
82090 - access with [gs]et_task_comm (which lock
82091 it with task_lock())
82092 @@ -1351,6 +1382,10 @@ struct task_struct {
82093 #endif
82094 /* CPU-specific state of this task */
82095 struct thread_struct thread;
82096 +/* thread_info moved to task_struct */
82097 +#ifdef CONFIG_X86
82098 + struct thread_info tinfo;
82099 +#endif
82100 /* filesystem information */
82101 struct fs_struct *fs;
82102 /* open file information */
82103 @@ -1427,6 +1462,10 @@ struct task_struct {
82104 gfp_t lockdep_reclaim_gfp;
82105 #endif
82106
82107 +/* process credentials */
82108 + const struct cred __rcu *real_cred; /* objective and real subjective task
82109 + * credentials (COW) */
82110 +
82111 /* journalling filesystem info */
82112 void *journal_info;
82113
82114 @@ -1465,6 +1504,10 @@ struct task_struct {
82115 /* cg_list protected by css_set_lock and tsk->alloc_lock */
82116 struct list_head cg_list;
82117 #endif
82118 +
82119 + const struct cred __rcu *cred; /* effective (overridable) subjective task
82120 + * credentials (COW) */
82121 +
82122 #ifdef CONFIG_FUTEX
82123 struct robust_list_head __user *robust_list;
82124 #ifdef CONFIG_COMPAT
82125 @@ -1610,7 +1653,78 @@ struct task_struct {
82126 unsigned int sequential_io;
82127 unsigned int sequential_io_avg;
82128 #endif
82129 -};
82130 +
82131 +#ifdef CONFIG_GRKERNSEC
82132 + /* grsecurity */
82133 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
82134 + u64 exec_id;
82135 +#endif
82136 +#ifdef CONFIG_GRKERNSEC_SETXID
82137 + const struct cred *delayed_cred;
82138 +#endif
82139 + struct dentry *gr_chroot_dentry;
82140 + struct acl_subject_label *acl;
82141 + struct acl_subject_label *tmpacl;
82142 + struct acl_role_label *role;
82143 + struct file *exec_file;
82144 + unsigned long brute_expires;
82145 + u16 acl_role_id;
82146 + u8 inherited;
82147 + /* is this the task that authenticated to the special role */
82148 + u8 acl_sp_role;
82149 + u8 is_writable;
82150 + u8 brute;
82151 + u8 gr_is_chrooted;
82152 +#endif
82153 +
82154 +} __randomize_layout;
82155 +
82156 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
82157 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
82158 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
82159 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
82160 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
82161 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
82162 +
82163 +#ifdef CONFIG_PAX_SOFTMODE
82164 +extern int pax_softmode;
82165 +#endif
82166 +
82167 +extern int pax_check_flags(unsigned long *);
82168 +#define PAX_PARSE_FLAGS_FALLBACK (~0UL)
82169 +
82170 +/* if tsk != current then task_lock must be held on it */
82171 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
82172 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
82173 +{
82174 + if (likely(tsk->mm))
82175 + return tsk->mm->pax_flags;
82176 + else
82177 + return 0UL;
82178 +}
82179 +
82180 +/* if tsk != current then task_lock must be held on it */
82181 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
82182 +{
82183 + if (likely(tsk->mm)) {
82184 + tsk->mm->pax_flags = flags;
82185 + return 0;
82186 + }
82187 + return -EINVAL;
82188 +}
82189 +#endif
82190 +
82191 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
82192 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
82193 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
82194 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
82195 +#endif
82196 +
82197 +struct path;
82198 +extern char *pax_get_path(const struct path *path, char *buf, int buflen);
82199 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
82200 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
82201 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
82202
82203 /* Future-safe accessor for struct task_struct's cpus_allowed. */
82204 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
82205 @@ -1692,7 +1806,7 @@ struct pid_namespace;
82206 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
82207 struct pid_namespace *ns);
82208
82209 -static inline pid_t task_pid_nr(struct task_struct *tsk)
82210 +static inline pid_t task_pid_nr(const struct task_struct *tsk)
82211 {
82212 return tsk->pid;
82213 }
82214 @@ -2039,6 +2153,25 @@ extern u64 sched_clock_cpu(int cpu);
82215
82216 extern void sched_clock_init(void);
82217
82218 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
82219 +static inline void populate_stack(void)
82220 +{
82221 + struct task_struct *curtask = current;
82222 + int c;
82223 + int *ptr = curtask->stack;
82224 + int *end = curtask->stack + THREAD_SIZE;
82225 +
82226 + while (ptr < end) {
82227 + c = *(volatile int *)ptr;
82228 + ptr += PAGE_SIZE/sizeof(int);
82229 + }
82230 +}
82231 +#else
82232 +static inline void populate_stack(void)
82233 +{
82234 +}
82235 +#endif
82236 +
82237 #ifndef CONFIG_HAVE_UNSTABLE_SCHED_CLOCK
82238 static inline void sched_clock_tick(void)
82239 {
82240 @@ -2172,7 +2305,9 @@ void yield(void);
82241 extern struct exec_domain default_exec_domain;
82242
82243 union thread_union {
82244 +#ifndef CONFIG_X86
82245 struct thread_info thread_info;
82246 +#endif
82247 unsigned long stack[THREAD_SIZE/sizeof(long)];
82248 };
82249
82250 @@ -2205,6 +2340,7 @@ extern struct pid_namespace init_pid_ns;
82251 */
82252
82253 extern struct task_struct *find_task_by_vpid(pid_t nr);
82254 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
82255 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
82256 struct pid_namespace *ns);
82257
82258 @@ -2367,7 +2503,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
82259 extern void exit_itimers(struct signal_struct *);
82260 extern void flush_itimer_signals(void);
82261
82262 -extern void do_group_exit(int);
82263 +extern __noreturn void do_group_exit(int);
82264
82265 extern int allow_signal(int);
82266 extern int disallow_signal(int);
82267 @@ -2568,9 +2704,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
82268
82269 #endif
82270
82271 -static inline int object_is_on_stack(void *obj)
82272 +static inline int object_starts_on_stack(const void *obj)
82273 {
82274 - void *stack = task_stack_page(current);
82275 + const void *stack = task_stack_page(current);
82276
82277 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
82278 }
82279 diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
82280 index 8045a55..c959cd5 100644
82281 --- a/include/linux/sched/sysctl.h
82282 +++ b/include/linux/sched/sysctl.h
82283 @@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
82284 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
82285
82286 extern int sysctl_max_map_count;
82287 +extern unsigned long sysctl_heap_stack_gap;
82288
82289 extern unsigned int sysctl_sched_latency;
82290 extern unsigned int sysctl_sched_min_granularity;
82291 diff --git a/include/linux/security.h b/include/linux/security.h
82292 index 6478ce3..5e6ad6e 100644
82293 --- a/include/linux/security.h
82294 +++ b/include/linux/security.h
82295 @@ -27,6 +27,7 @@
82296 #include <linux/slab.h>
82297 #include <linux/err.h>
82298 #include <linux/string.h>
82299 +#include <linux/grsecurity.h>
82300
82301 struct linux_binprm;
82302 struct cred;
82303 @@ -116,8 +117,6 @@ struct seq_file;
82304
82305 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
82306
82307 -void reset_security_ops(void);
82308 -
82309 #ifdef CONFIG_MMU
82310 extern unsigned long mmap_min_addr;
82311 extern unsigned long dac_mmap_min_addr;
82312 @@ -1719,7 +1718,7 @@ struct security_operations {
82313 struct audit_context *actx);
82314 void (*audit_rule_free) (void *lsmrule);
82315 #endif /* CONFIG_AUDIT */
82316 -};
82317 +} __randomize_layout;
82318
82319 /* prototypes */
82320 extern int security_init(void);
82321 diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
82322 index dc368b8..e895209 100644
82323 --- a/include/linux/semaphore.h
82324 +++ b/include/linux/semaphore.h
82325 @@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
82326 }
82327
82328 extern void down(struct semaphore *sem);
82329 -extern int __must_check down_interruptible(struct semaphore *sem);
82330 +extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
82331 extern int __must_check down_killable(struct semaphore *sem);
82332 extern int __must_check down_trylock(struct semaphore *sem);
82333 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
82334 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
82335 index 52e0097..383f21d 100644
82336 --- a/include/linux/seq_file.h
82337 +++ b/include/linux/seq_file.h
82338 @@ -27,6 +27,9 @@ struct seq_file {
82339 struct mutex lock;
82340 const struct seq_operations *op;
82341 int poll_event;
82342 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
82343 + u64 exec_id;
82344 +#endif
82345 #ifdef CONFIG_USER_NS
82346 struct user_namespace *user_ns;
82347 #endif
82348 @@ -39,6 +42,7 @@ struct seq_operations {
82349 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
82350 int (*show) (struct seq_file *m, void *v);
82351 };
82352 +typedef struct seq_operations __no_const seq_operations_no_const;
82353
82354 #define SEQ_SKIP 1
82355
82356 @@ -96,6 +100,7 @@ void seq_pad(struct seq_file *m, char c);
82357
82358 char *mangle_path(char *s, const char *p, const char *esc);
82359 int seq_open(struct file *, const struct seq_operations *);
82360 +int seq_open_restrict(struct file *, const struct seq_operations *);
82361 ssize_t seq_read(struct file *, char __user *, size_t, loff_t *);
82362 loff_t seq_lseek(struct file *, loff_t, int);
82363 int seq_release(struct inode *, struct file *);
82364 @@ -138,6 +143,7 @@ static inline int seq_nodemask_list(struct seq_file *m, nodemask_t *mask)
82365 }
82366
82367 int single_open(struct file *, int (*)(struct seq_file *, void *), void *);
82368 +int single_open_restrict(struct file *, int (*)(struct seq_file *, void *), void *);
82369 int single_open_size(struct file *, int (*)(struct seq_file *, void *), void *, size_t);
82370 int single_release(struct inode *, struct file *);
82371 void *__seq_open_private(struct file *, const struct seq_operations *, int);
82372 diff --git a/include/linux/shm.h b/include/linux/shm.h
82373 index 1e2cd2e..0288750 100644
82374 --- a/include/linux/shm.h
82375 +++ b/include/linux/shm.h
82376 @@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
82377
82378 /* The task created the shm object. NULL if the task is dead. */
82379 struct task_struct *shm_creator;
82380 +#ifdef CONFIG_GRKERNSEC
82381 + time_t shm_createtime;
82382 + pid_t shm_lapid;
82383 +#endif
82384 };
82385
82386 /* shm_mode upper byte flags */
82387 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
82388 index 08074a8..e2ae280 100644
82389 --- a/include/linux/skbuff.h
82390 +++ b/include/linux/skbuff.h
82391 @@ -717,7 +717,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
82392 struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags,
82393 int node);
82394 struct sk_buff *build_skb(void *data, unsigned int frag_size);
82395 -static inline struct sk_buff *alloc_skb(unsigned int size,
82396 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
82397 gfp_t priority)
82398 {
82399 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
82400 @@ -1825,7 +1825,7 @@ static inline u32 skb_inner_network_header_len(const struct sk_buff *skb)
82401 return skb->inner_transport_header - skb->inner_network_header;
82402 }
82403
82404 -static inline int skb_network_offset(const struct sk_buff *skb)
82405 +static inline int __intentional_overflow(0) skb_network_offset(const struct sk_buff *skb)
82406 {
82407 return skb_network_header(skb) - skb->data;
82408 }
82409 @@ -1885,7 +1885,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
82410 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
82411 */
82412 #ifndef NET_SKB_PAD
82413 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
82414 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
82415 #endif
82416
82417 int ___pskb_trim(struct sk_buff *skb, unsigned int len);
82418 @@ -2484,7 +2484,7 @@ struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags, int noblock,
82419 int *err);
82420 unsigned int datagram_poll(struct file *file, struct socket *sock,
82421 struct poll_table_struct *wait);
82422 -int skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
82423 +int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
82424 struct iovec *to, int size);
82425 int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb, int hlen,
82426 struct iovec *iov);
82427 @@ -2776,6 +2776,9 @@ static inline void nf_reset(struct sk_buff *skb)
82428 nf_bridge_put(skb->nf_bridge);
82429 skb->nf_bridge = NULL;
82430 #endif
82431 +#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
82432 + skb->nf_trace = 0;
82433 +#endif
82434 }
82435
82436 static inline void nf_reset_trace(struct sk_buff *skb)
82437 diff --git a/include/linux/slab.h b/include/linux/slab.h
82438 index 307bfbe..a999cf3 100644
82439 --- a/include/linux/slab.h
82440 +++ b/include/linux/slab.h
82441 @@ -14,15 +14,29 @@
82442 #include <linux/gfp.h>
82443 #include <linux/types.h>
82444 #include <linux/workqueue.h>
82445 -
82446 +#include <linux/err.h>
82447
82448 /*
82449 * Flags to pass to kmem_cache_create().
82450 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
82451 */
82452 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
82453 +
82454 +#ifdef CONFIG_PAX_USERCOPY_SLABS
82455 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
82456 +#else
82457 +#define SLAB_USERCOPY 0x00000000UL
82458 +#endif
82459 +
82460 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
82461 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
82462 +
82463 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
82464 +#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
82465 +#else
82466 +#define SLAB_NO_SANITIZE 0x00000000UL
82467 +#endif
82468 +
82469 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
82470 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
82471 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
82472 @@ -98,10 +112,13 @@
82473 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
82474 * Both make kfree a no-op.
82475 */
82476 -#define ZERO_SIZE_PTR ((void *)16)
82477 +#define ZERO_SIZE_PTR \
82478 +({ \
82479 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
82480 + (void *)(-MAX_ERRNO-1L); \
82481 +})
82482
82483 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
82484 - (unsigned long)ZERO_SIZE_PTR)
82485 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
82486
82487 #include <linux/kmemleak.h>
82488
82489 @@ -142,6 +159,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
82490 void kfree(const void *);
82491 void kzfree(const void *);
82492 size_t ksize(const void *);
82493 +const char *check_heap_object(const void *ptr, unsigned long n);
82494 +bool is_usercopy_object(const void *ptr);
82495
82496 /*
82497 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
82498 @@ -174,7 +193,7 @@ struct kmem_cache {
82499 unsigned int align; /* Alignment as calculated */
82500 unsigned long flags; /* Active flags on the slab */
82501 const char *name; /* Slab name for sysfs */
82502 - int refcount; /* Use counter */
82503 + atomic_t refcount; /* Use counter */
82504 void (*ctor)(void *); /* Called on object slot creation */
82505 struct list_head list; /* List of all slab caches on the system */
82506 };
82507 @@ -259,6 +278,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
82508 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
82509 #endif
82510
82511 +#ifdef CONFIG_PAX_USERCOPY_SLABS
82512 +extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
82513 +#endif
82514 +
82515 /*
82516 * Figure out which kmalloc slab an allocation of a certain size
82517 * belongs to.
82518 @@ -267,7 +290,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
82519 * 2 = 120 .. 192 bytes
82520 * n = 2^(n-1) .. 2^n -1
82521 */
82522 -static __always_inline int kmalloc_index(size_t size)
82523 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
82524 {
82525 if (!size)
82526 return 0;
82527 @@ -310,11 +333,11 @@ static __always_inline int kmalloc_index(size_t size)
82528 }
82529 #endif /* !CONFIG_SLOB */
82530
82531 -void *__kmalloc(size_t size, gfp_t flags);
82532 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
82533 void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
82534
82535 #ifdef CONFIG_NUMA
82536 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
82537 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
82538 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
82539 #else
82540 static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
82541 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
82542 index 8235dfb..47ce586 100644
82543 --- a/include/linux/slab_def.h
82544 +++ b/include/linux/slab_def.h
82545 @@ -38,7 +38,7 @@ struct kmem_cache {
82546 /* 4) cache creation/removal */
82547 const char *name;
82548 struct list_head list;
82549 - int refcount;
82550 + atomic_t refcount;
82551 int object_size;
82552 int align;
82553
82554 @@ -54,10 +54,14 @@ struct kmem_cache {
82555 unsigned long node_allocs;
82556 unsigned long node_frees;
82557 unsigned long node_overflow;
82558 - atomic_t allochit;
82559 - atomic_t allocmiss;
82560 - atomic_t freehit;
82561 - atomic_t freemiss;
82562 + atomic_unchecked_t allochit;
82563 + atomic_unchecked_t allocmiss;
82564 + atomic_unchecked_t freehit;
82565 + atomic_unchecked_t freemiss;
82566 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
82567 + atomic_unchecked_t sanitized;
82568 + atomic_unchecked_t not_sanitized;
82569 +#endif
82570
82571 /*
82572 * If debugging is enabled, then the allocator can add additional
82573 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
82574 index d82abd4..408c3a0 100644
82575 --- a/include/linux/slub_def.h
82576 +++ b/include/linux/slub_def.h
82577 @@ -74,7 +74,7 @@ struct kmem_cache {
82578 struct kmem_cache_order_objects max;
82579 struct kmem_cache_order_objects min;
82580 gfp_t allocflags; /* gfp flags to use on each alloc */
82581 - int refcount; /* Refcount for slab cache destroy */
82582 + atomic_t refcount; /* Refcount for slab cache destroy */
82583 void (*ctor)(void *);
82584 int inuse; /* Offset to metadata */
82585 int align; /* Alignment */
82586 diff --git a/include/linux/smp.h b/include/linux/smp.h
82587 index 633f5ed..6c3dc3f 100644
82588 --- a/include/linux/smp.h
82589 +++ b/include/linux/smp.h
82590 @@ -176,7 +176,9 @@ static inline void kick_all_cpus_sync(void) { }
82591 #endif
82592
82593 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
82594 +#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
82595 #define put_cpu() preempt_enable()
82596 +#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
82597
82598 /*
82599 * Callback to arch code if there's nosmp or maxcpus=0 on the
82600 diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
82601 index 46cca4c..3323536 100644
82602 --- a/include/linux/sock_diag.h
82603 +++ b/include/linux/sock_diag.h
82604 @@ -11,7 +11,7 @@ struct sock;
82605 struct sock_diag_handler {
82606 __u8 family;
82607 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
82608 -};
82609 +} __do_const;
82610
82611 int sock_diag_register(const struct sock_diag_handler *h);
82612 void sock_diag_unregister(const struct sock_diag_handler *h);
82613 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
82614 index 680f9a3..f13aeb0 100644
82615 --- a/include/linux/sonet.h
82616 +++ b/include/linux/sonet.h
82617 @@ -7,7 +7,7 @@
82618 #include <uapi/linux/sonet.h>
82619
82620 struct k_sonet_stats {
82621 -#define __HANDLE_ITEM(i) atomic_t i
82622 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
82623 __SONET_ITEMS
82624 #undef __HANDLE_ITEM
82625 };
82626 diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
82627 index 07d8e53..dc934c9 100644
82628 --- a/include/linux/sunrpc/addr.h
82629 +++ b/include/linux/sunrpc/addr.h
82630 @@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
82631 {
82632 switch (sap->sa_family) {
82633 case AF_INET:
82634 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
82635 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
82636 case AF_INET6:
82637 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
82638 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
82639 }
82640 return 0;
82641 }
82642 @@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
82643 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
82644 const struct sockaddr *src)
82645 {
82646 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
82647 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
82648 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
82649
82650 dsin->sin_family = ssin->sin_family;
82651 @@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
82652 if (sa->sa_family != AF_INET6)
82653 return 0;
82654
82655 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
82656 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
82657 }
82658
82659 #endif /* _LINUX_SUNRPC_ADDR_H */
82660 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
82661 index 70736b9..37f33db 100644
82662 --- a/include/linux/sunrpc/clnt.h
82663 +++ b/include/linux/sunrpc/clnt.h
82664 @@ -97,7 +97,7 @@ struct rpc_procinfo {
82665 unsigned int p_timer; /* Which RTT timer to use */
82666 u32 p_statidx; /* Which procedure to account */
82667 const char * p_name; /* name of procedure */
82668 -};
82669 +} __do_const;
82670
82671 #ifdef __KERNEL__
82672
82673 diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
82674 index 04e7632..2e2a8a3 100644
82675 --- a/include/linux/sunrpc/svc.h
82676 +++ b/include/linux/sunrpc/svc.h
82677 @@ -412,7 +412,7 @@ struct svc_procedure {
82678 unsigned int pc_count; /* call count */
82679 unsigned int pc_cachetype; /* cache info (NFS) */
82680 unsigned int pc_xdrressize; /* maximum size of XDR reply */
82681 -};
82682 +} __do_const;
82683
82684 /*
82685 * Function prototypes.
82686 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
82687 index 0b8e3e6..33e0a01 100644
82688 --- a/include/linux/sunrpc/svc_rdma.h
82689 +++ b/include/linux/sunrpc/svc_rdma.h
82690 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
82691 extern unsigned int svcrdma_max_requests;
82692 extern unsigned int svcrdma_max_req_size;
82693
82694 -extern atomic_t rdma_stat_recv;
82695 -extern atomic_t rdma_stat_read;
82696 -extern atomic_t rdma_stat_write;
82697 -extern atomic_t rdma_stat_sq_starve;
82698 -extern atomic_t rdma_stat_rq_starve;
82699 -extern atomic_t rdma_stat_rq_poll;
82700 -extern atomic_t rdma_stat_rq_prod;
82701 -extern atomic_t rdma_stat_sq_poll;
82702 -extern atomic_t rdma_stat_sq_prod;
82703 +extern atomic_unchecked_t rdma_stat_recv;
82704 +extern atomic_unchecked_t rdma_stat_read;
82705 +extern atomic_unchecked_t rdma_stat_write;
82706 +extern atomic_unchecked_t rdma_stat_sq_starve;
82707 +extern atomic_unchecked_t rdma_stat_rq_starve;
82708 +extern atomic_unchecked_t rdma_stat_rq_poll;
82709 +extern atomic_unchecked_t rdma_stat_rq_prod;
82710 +extern atomic_unchecked_t rdma_stat_sq_poll;
82711 +extern atomic_unchecked_t rdma_stat_sq_prod;
82712
82713 #define RPCRDMA_VERSION 1
82714
82715 diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
82716 index 8d71d65..f79586e 100644
82717 --- a/include/linux/sunrpc/svcauth.h
82718 +++ b/include/linux/sunrpc/svcauth.h
82719 @@ -120,7 +120,7 @@ struct auth_ops {
82720 int (*release)(struct svc_rqst *rq);
82721 void (*domain_release)(struct auth_domain *);
82722 int (*set_client)(struct svc_rqst *rq);
82723 -};
82724 +} __do_const;
82725
82726 #define SVC_GARBAGE 1
82727 #define SVC_SYSERR 2
82728 diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
82729 index a5ffd32..0935dea 100644
82730 --- a/include/linux/swiotlb.h
82731 +++ b/include/linux/swiotlb.h
82732 @@ -60,7 +60,8 @@ extern void
82733
82734 extern void
82735 swiotlb_free_coherent(struct device *hwdev, size_t size,
82736 - void *vaddr, dma_addr_t dma_handle);
82737 + void *vaddr, dma_addr_t dma_handle,
82738 + struct dma_attrs *attrs);
82739
82740 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
82741 unsigned long offset, size_t size,
82742 diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
82743 index a4a0588..752870e 100644
82744 --- a/include/linux/syscalls.h
82745 +++ b/include/linux/syscalls.h
82746 @@ -98,10 +98,16 @@ struct sigaltstack;
82747 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
82748
82749 #define __SC_DECL(t, a) t a
82750 +#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))
82751 #define __TYPE_IS_L(t) (__same_type((t)0, 0L))
82752 #define __TYPE_IS_UL(t) (__same_type((t)0, 0UL))
82753 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
82754 -#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
82755 +#define __SC_LONG(t, a) __typeof( \
82756 + __builtin_choose_expr( \
82757 + sizeof(t) > sizeof(int), \
82758 + (t) 0, \
82759 + __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
82760 + )) a
82761 #define __SC_CAST(t, a) (t) a
82762 #define __SC_ARGS(t, a) a
82763 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
82764 @@ -379,11 +385,11 @@ asmlinkage long sys_sync(void);
82765 asmlinkage long sys_fsync(unsigned int fd);
82766 asmlinkage long sys_fdatasync(unsigned int fd);
82767 asmlinkage long sys_bdflush(int func, long data);
82768 -asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
82769 - char __user *type, unsigned long flags,
82770 +asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
82771 + const char __user *type, unsigned long flags,
82772 void __user *data);
82773 -asmlinkage long sys_umount(char __user *name, int flags);
82774 -asmlinkage long sys_oldumount(char __user *name);
82775 +asmlinkage long sys_umount(const char __user *name, int flags);
82776 +asmlinkage long sys_oldumount(const char __user *name);
82777 asmlinkage long sys_truncate(const char __user *path, long length);
82778 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
82779 asmlinkage long sys_stat(const char __user *filename,
82780 @@ -595,7 +601,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
82781 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
82782 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
82783 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
82784 - struct sockaddr __user *, int);
82785 + struct sockaddr __user *, int) __intentional_overflow(0);
82786 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
82787 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
82788 unsigned int vlen, unsigned flags);
82789 diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
82790 index 27b3b0b..e093dd9 100644
82791 --- a/include/linux/syscore_ops.h
82792 +++ b/include/linux/syscore_ops.h
82793 @@ -16,7 +16,7 @@ struct syscore_ops {
82794 int (*suspend)(void);
82795 void (*resume)(void);
82796 void (*shutdown)(void);
82797 -};
82798 +} __do_const;
82799
82800 extern void register_syscore_ops(struct syscore_ops *ops);
82801 extern void unregister_syscore_ops(struct syscore_ops *ops);
82802 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
82803 index 14a8ff2..fa95f3a 100644
82804 --- a/include/linux/sysctl.h
82805 +++ b/include/linux/sysctl.h
82806 @@ -34,13 +34,13 @@ struct ctl_table_root;
82807 struct ctl_table_header;
82808 struct ctl_dir;
82809
82810 -typedef struct ctl_table ctl_table;
82811 -
82812 typedef int proc_handler (struct ctl_table *ctl, int write,
82813 void __user *buffer, size_t *lenp, loff_t *ppos);
82814
82815 extern int proc_dostring(struct ctl_table *, int,
82816 void __user *, size_t *, loff_t *);
82817 +extern int proc_dostring_modpriv(struct ctl_table *, int,
82818 + void __user *, size_t *, loff_t *);
82819 extern int proc_dointvec(struct ctl_table *, int,
82820 void __user *, size_t *, loff_t *);
82821 extern int proc_dointvec_minmax(struct ctl_table *, int,
82822 @@ -115,7 +115,9 @@ struct ctl_table
82823 struct ctl_table_poll *poll;
82824 void *extra1;
82825 void *extra2;
82826 -};
82827 +} __do_const __randomize_layout;
82828 +typedef struct ctl_table __no_const ctl_table_no_const;
82829 +typedef struct ctl_table ctl_table;
82830
82831 struct ctl_node {
82832 struct rb_node node;
82833 diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
82834 index 5ffaa34..fe3e31c 100644
82835 --- a/include/linux/sysfs.h
82836 +++ b/include/linux/sysfs.h
82837 @@ -34,7 +34,8 @@ struct attribute {
82838 struct lock_class_key *key;
82839 struct lock_class_key skey;
82840 #endif
82841 -};
82842 +} __do_const;
82843 +typedef struct attribute __no_const attribute_no_const;
82844
82845 /**
82846 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
82847 @@ -63,7 +64,8 @@ struct attribute_group {
82848 struct attribute *, int);
82849 struct attribute **attrs;
82850 struct bin_attribute **bin_attrs;
82851 -};
82852 +} __do_const;
82853 +typedef struct attribute_group __no_const attribute_group_no_const;
82854
82855 /**
82856 * Use these macros to make defining attributes easier. See include/linux/device.h
82857 @@ -128,7 +130,8 @@ struct bin_attribute {
82858 char *, loff_t, size_t);
82859 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
82860 struct vm_area_struct *vma);
82861 -};
82862 +} __do_const;
82863 +typedef struct bin_attribute __no_const bin_attribute_no_const;
82864
82865 /**
82866 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
82867 diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
82868 index 387fa7d..3fcde6b 100644
82869 --- a/include/linux/sysrq.h
82870 +++ b/include/linux/sysrq.h
82871 @@ -16,6 +16,7 @@
82872
82873 #include <linux/errno.h>
82874 #include <linux/types.h>
82875 +#include <linux/compiler.h>
82876
82877 /* Possible values of bitmask for enabling sysrq functions */
82878 /* 0x0001 is reserved for enable everything */
82879 @@ -33,7 +34,7 @@ struct sysrq_key_op {
82880 char *help_msg;
82881 char *action_msg;
82882 int enable_mask;
82883 -};
82884 +} __do_const;
82885
82886 #ifdef CONFIG_MAGIC_SYSRQ
82887
82888 diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
82889 index fddbe20..a0e76ab 100644
82890 --- a/include/linux/thread_info.h
82891 +++ b/include/linux/thread_info.h
82892 @@ -161,6 +161,13 @@ static inline bool test_and_clear_restore_sigmask(void)
82893 #error "no set_restore_sigmask() provided and default one won't work"
82894 #endif
82895
82896 +extern void __check_object_size(const void *ptr, unsigned long n, bool to_user, bool const_size);
82897 +
82898 +static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
82899 +{
82900 + __check_object_size(ptr, n, to_user, __builtin_constant_p(n));
82901 +}
82902 +
82903 #endif /* __KERNEL__ */
82904
82905 #endif /* _LINUX_THREAD_INFO_H */
82906 diff --git a/include/linux/tty.h b/include/linux/tty.h
82907 index 1c3316a..ae83b9f 100644
82908 --- a/include/linux/tty.h
82909 +++ b/include/linux/tty.h
82910 @@ -202,7 +202,7 @@ struct tty_port {
82911 const struct tty_port_operations *ops; /* Port operations */
82912 spinlock_t lock; /* Lock protecting tty field */
82913 int blocked_open; /* Waiting to open */
82914 - int count; /* Usage count */
82915 + atomic_t count; /* Usage count */
82916 wait_queue_head_t open_wait; /* Open waiters */
82917 wait_queue_head_t close_wait; /* Close waiters */
82918 wait_queue_head_t delta_msr_wait; /* Modem status change */
82919 @@ -284,7 +284,7 @@ struct tty_struct {
82920 /* If the tty has a pending do_SAK, queue it here - akpm */
82921 struct work_struct SAK_work;
82922 struct tty_port *port;
82923 -};
82924 +} __randomize_layout;
82925
82926 /* Each of a tty's open files has private_data pointing to tty_file_private */
82927 struct tty_file_private {
82928 @@ -550,7 +550,7 @@ extern int tty_port_open(struct tty_port *port,
82929 struct tty_struct *tty, struct file *filp);
82930 static inline int tty_port_users(struct tty_port *port)
82931 {
82932 - return port->count + port->blocked_open;
82933 + return atomic_read(&port->count) + port->blocked_open;
82934 }
82935
82936 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
82937 diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
82938 index 756a609..89db85e 100644
82939 --- a/include/linux/tty_driver.h
82940 +++ b/include/linux/tty_driver.h
82941 @@ -285,7 +285,7 @@ struct tty_operations {
82942 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
82943 #endif
82944 const struct file_operations *proc_fops;
82945 -};
82946 +} __do_const __randomize_layout;
82947
82948 struct tty_driver {
82949 int magic; /* magic number for this structure */
82950 @@ -319,7 +319,7 @@ struct tty_driver {
82951
82952 const struct tty_operations *ops;
82953 struct list_head tty_drivers;
82954 -};
82955 +} __randomize_layout;
82956
82957 extern struct list_head tty_drivers;
82958
82959 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
82960 index add26da..22c00bef 100644
82961 --- a/include/linux/tty_ldisc.h
82962 +++ b/include/linux/tty_ldisc.h
82963 @@ -212,7 +212,7 @@ struct tty_ldisc_ops {
82964
82965 struct module *owner;
82966
82967 - int refcount;
82968 + atomic_t refcount;
82969 };
82970
82971 struct tty_ldisc {
82972 diff --git a/include/linux/types.h b/include/linux/types.h
82973 index 4d118ba..c3ee9bf 100644
82974 --- a/include/linux/types.h
82975 +++ b/include/linux/types.h
82976 @@ -176,10 +176,26 @@ typedef struct {
82977 int counter;
82978 } atomic_t;
82979
82980 +#ifdef CONFIG_PAX_REFCOUNT
82981 +typedef struct {
82982 + int counter;
82983 +} atomic_unchecked_t;
82984 +#else
82985 +typedef atomic_t atomic_unchecked_t;
82986 +#endif
82987 +
82988 #ifdef CONFIG_64BIT
82989 typedef struct {
82990 long counter;
82991 } atomic64_t;
82992 +
82993 +#ifdef CONFIG_PAX_REFCOUNT
82994 +typedef struct {
82995 + long counter;
82996 +} atomic64_unchecked_t;
82997 +#else
82998 +typedef atomic64_t atomic64_unchecked_t;
82999 +#endif
83000 #endif
83001
83002 struct list_head {
83003 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
83004 index ecd3319..8a36ded 100644
83005 --- a/include/linux/uaccess.h
83006 +++ b/include/linux/uaccess.h
83007 @@ -75,11 +75,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
83008 long ret; \
83009 mm_segment_t old_fs = get_fs(); \
83010 \
83011 - set_fs(KERNEL_DS); \
83012 pagefault_disable(); \
83013 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
83014 - pagefault_enable(); \
83015 + set_fs(KERNEL_DS); \
83016 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
83017 set_fs(old_fs); \
83018 + pagefault_enable(); \
83019 ret; \
83020 })
83021
83022 diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
83023 index 2d1f9b6..d7a9fce 100644
83024 --- a/include/linux/uidgid.h
83025 +++ b/include/linux/uidgid.h
83026 @@ -175,4 +175,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
83027
83028 #endif /* CONFIG_USER_NS */
83029
83030 +#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
83031 +#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
83032 +#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
83033 +#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
83034 +
83035 #endif /* _LINUX_UIDGID_H */
83036 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
83037 index 99c1b4d..562e6f3 100644
83038 --- a/include/linux/unaligned/access_ok.h
83039 +++ b/include/linux/unaligned/access_ok.h
83040 @@ -4,34 +4,34 @@
83041 #include <linux/kernel.h>
83042 #include <asm/byteorder.h>
83043
83044 -static inline u16 get_unaligned_le16(const void *p)
83045 +static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
83046 {
83047 - return le16_to_cpup((__le16 *)p);
83048 + return le16_to_cpup((const __le16 *)p);
83049 }
83050
83051 -static inline u32 get_unaligned_le32(const void *p)
83052 +static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
83053 {
83054 - return le32_to_cpup((__le32 *)p);
83055 + return le32_to_cpup((const __le32 *)p);
83056 }
83057
83058 -static inline u64 get_unaligned_le64(const void *p)
83059 +static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
83060 {
83061 - return le64_to_cpup((__le64 *)p);
83062 + return le64_to_cpup((const __le64 *)p);
83063 }
83064
83065 -static inline u16 get_unaligned_be16(const void *p)
83066 +static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
83067 {
83068 - return be16_to_cpup((__be16 *)p);
83069 + return be16_to_cpup((const __be16 *)p);
83070 }
83071
83072 -static inline u32 get_unaligned_be32(const void *p)
83073 +static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
83074 {
83075 - return be32_to_cpup((__be32 *)p);
83076 + return be32_to_cpup((const __be32 *)p);
83077 }
83078
83079 -static inline u64 get_unaligned_be64(const void *p)
83080 +static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
83081 {
83082 - return be64_to_cpup((__be64 *)p);
83083 + return be64_to_cpup((const __be64 *)p);
83084 }
83085
83086 static inline void put_unaligned_le16(u16 val, void *p)
83087 diff --git a/include/linux/usb.h b/include/linux/usb.h
83088 index 6b7ec37..4428419 100644
83089 --- a/include/linux/usb.h
83090 +++ b/include/linux/usb.h
83091 @@ -569,7 +569,7 @@ struct usb_device {
83092 int maxchild;
83093
83094 u32 quirks;
83095 - atomic_t urbnum;
83096 + atomic_unchecked_t urbnum;
83097
83098 unsigned long active_duration;
83099
83100 @@ -1653,7 +1653,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
83101
83102 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
83103 __u8 request, __u8 requesttype, __u16 value, __u16 index,
83104 - void *data, __u16 size, int timeout);
83105 + void *data, __u16 size, int timeout) __intentional_overflow(-1);
83106 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
83107 void *data, int len, int *actual_length, int timeout);
83108 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
83109 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
83110 index e452ba6..78f8e80 100644
83111 --- a/include/linux/usb/renesas_usbhs.h
83112 +++ b/include/linux/usb/renesas_usbhs.h
83113 @@ -39,7 +39,7 @@ enum {
83114 */
83115 struct renesas_usbhs_driver_callback {
83116 int (*notify_hotplug)(struct platform_device *pdev);
83117 -};
83118 +} __no_const;
83119
83120 /*
83121 * callback functions for platform
83122 diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
83123 index 4836ba3..603f6ee 100644
83124 --- a/include/linux/user_namespace.h
83125 +++ b/include/linux/user_namespace.h
83126 @@ -33,7 +33,7 @@ struct user_namespace {
83127 struct key *persistent_keyring_register;
83128 struct rw_semaphore persistent_keyring_register_sem;
83129 #endif
83130 -};
83131 +} __randomize_layout;
83132
83133 extern struct user_namespace init_user_ns;
83134
83135 diff --git a/include/linux/utsname.h b/include/linux/utsname.h
83136 index 239e277..22a5cf5 100644
83137 --- a/include/linux/utsname.h
83138 +++ b/include/linux/utsname.h
83139 @@ -24,7 +24,7 @@ struct uts_namespace {
83140 struct new_utsname name;
83141 struct user_namespace *user_ns;
83142 unsigned int proc_inum;
83143 -};
83144 +} __randomize_layout;
83145 extern struct uts_namespace init_uts_ns;
83146
83147 #ifdef CONFIG_UTS_NS
83148 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
83149 index 6f8fbcf..4efc177 100644
83150 --- a/include/linux/vermagic.h
83151 +++ b/include/linux/vermagic.h
83152 @@ -25,9 +25,42 @@
83153 #define MODULE_ARCH_VERMAGIC ""
83154 #endif
83155
83156 +#ifdef CONFIG_PAX_REFCOUNT
83157 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
83158 +#else
83159 +#define MODULE_PAX_REFCOUNT ""
83160 +#endif
83161 +
83162 +#ifdef CONSTIFY_PLUGIN
83163 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
83164 +#else
83165 +#define MODULE_CONSTIFY_PLUGIN ""
83166 +#endif
83167 +
83168 +#ifdef STACKLEAK_PLUGIN
83169 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
83170 +#else
83171 +#define MODULE_STACKLEAK_PLUGIN ""
83172 +#endif
83173 +
83174 +#ifdef RANDSTRUCT_PLUGIN
83175 +#include <generated/randomize_layout_hash.h>
83176 +#define MODULE_RANDSTRUCT_PLUGIN "RANDSTRUCT_PLUGIN_" RANDSTRUCT_HASHED_SEED
83177 +#else
83178 +#define MODULE_RANDSTRUCT_PLUGIN
83179 +#endif
83180 +
83181 +#ifdef CONFIG_GRKERNSEC
83182 +#define MODULE_GRSEC "GRSEC "
83183 +#else
83184 +#define MODULE_GRSEC ""
83185 +#endif
83186 +
83187 #define VERMAGIC_STRING \
83188 UTS_RELEASE " " \
83189 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
83190 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
83191 - MODULE_ARCH_VERMAGIC
83192 + MODULE_ARCH_VERMAGIC \
83193 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
83194 + MODULE_GRSEC MODULE_RANDSTRUCT_PLUGIN
83195
83196 diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
83197 index 502073a..a7de024 100644
83198 --- a/include/linux/vga_switcheroo.h
83199 +++ b/include/linux/vga_switcheroo.h
83200 @@ -63,8 +63,8 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
83201
83202 void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
83203
83204 -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
83205 -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
83206 +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
83207 +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
83208 #else
83209
83210 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
83211 @@ -81,8 +81,8 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
83212
83213 static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
83214
83215 -static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
83216 -static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
83217 +static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
83218 +static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
83219
83220 #endif
83221 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
83222 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
83223 index 4b8a891..e9a2863 100644
83224 --- a/include/linux/vmalloc.h
83225 +++ b/include/linux/vmalloc.h
83226 @@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
83227 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
83228 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
83229 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
83230 +
83231 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
83232 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
83233 +#endif
83234 +
83235 /* bits [20..32] reserved for arch specific ioremap internals */
83236
83237 /*
83238 @@ -82,6 +87,10 @@ extern void *vmap(struct page **pages, unsigned int count,
83239 unsigned long flags, pgprot_t prot);
83240 extern void vunmap(const void *addr);
83241
83242 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
83243 +extern void unmap_process_stacks(struct task_struct *task);
83244 +#endif
83245 +
83246 extern int remap_vmalloc_range_partial(struct vm_area_struct *vma,
83247 unsigned long uaddr, void *kaddr,
83248 unsigned long size);
83249 @@ -142,7 +151,7 @@ extern void free_vm_area(struct vm_struct *area);
83250
83251 /* for /dev/kmem */
83252 extern long vread(char *buf, char *addr, unsigned long count);
83253 -extern long vwrite(char *buf, char *addr, unsigned long count);
83254 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
83255
83256 /*
83257 * Internals. Dont't use..
83258 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
83259 index 45c9cd1..20bd0bf 100644
83260 --- a/include/linux/vmstat.h
83261 +++ b/include/linux/vmstat.h
83262 @@ -102,18 +102,18 @@ static inline void vm_events_fold_cpu(int cpu)
83263 /*
83264 * Zone based page accounting with per cpu differentials.
83265 */
83266 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83267 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
83268
83269 static inline void zone_page_state_add(long x, struct zone *zone,
83270 enum zone_stat_item item)
83271 {
83272 - atomic_long_add(x, &zone->vm_stat[item]);
83273 - atomic_long_add(x, &vm_stat[item]);
83274 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
83275 + atomic_long_add_unchecked(x, &vm_stat[item]);
83276 }
83277
83278 -static inline unsigned long global_page_state(enum zone_stat_item item)
83279 +static inline unsigned long __intentional_overflow(-1) global_page_state(enum zone_stat_item item)
83280 {
83281 - long x = atomic_long_read(&vm_stat[item]);
83282 + long x = atomic_long_read_unchecked(&vm_stat[item]);
83283 #ifdef CONFIG_SMP
83284 if (x < 0)
83285 x = 0;
83286 @@ -121,10 +121,10 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
83287 return x;
83288 }
83289
83290 -static inline unsigned long zone_page_state(struct zone *zone,
83291 +static inline unsigned long __intentional_overflow(-1) zone_page_state(struct zone *zone,
83292 enum zone_stat_item item)
83293 {
83294 - long x = atomic_long_read(&zone->vm_stat[item]);
83295 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
83296 #ifdef CONFIG_SMP
83297 if (x < 0)
83298 x = 0;
83299 @@ -141,7 +141,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
83300 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
83301 enum zone_stat_item item)
83302 {
83303 - long x = atomic_long_read(&zone->vm_stat[item]);
83304 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
83305
83306 #ifdef CONFIG_SMP
83307 int cpu;
83308 @@ -228,14 +228,14 @@ static inline void __mod_zone_page_state(struct zone *zone,
83309
83310 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
83311 {
83312 - atomic_long_inc(&zone->vm_stat[item]);
83313 - atomic_long_inc(&vm_stat[item]);
83314 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
83315 + atomic_long_inc_unchecked(&vm_stat[item]);
83316 }
83317
83318 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
83319 {
83320 - atomic_long_dec(&zone->vm_stat[item]);
83321 - atomic_long_dec(&vm_stat[item]);
83322 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
83323 + atomic_long_dec_unchecked(&vm_stat[item]);
83324 }
83325
83326 static inline void __inc_zone_page_state(struct page *page,
83327 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
83328 index 91b0a68..0e9adf6 100644
83329 --- a/include/linux/xattr.h
83330 +++ b/include/linux/xattr.h
83331 @@ -28,7 +28,7 @@ struct xattr_handler {
83332 size_t size, int handler_flags);
83333 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
83334 size_t size, int flags, int handler_flags);
83335 -};
83336 +} __do_const;
83337
83338 struct xattr {
83339 const char *name;
83340 @@ -37,6 +37,9 @@ struct xattr {
83341 };
83342
83343 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
83344 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
83345 +ssize_t pax_getxattr(struct dentry *, void *, size_t);
83346 +#endif
83347 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
83348 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
83349 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
83350 diff --git a/include/linux/zlib.h b/include/linux/zlib.h
83351 index 9c5a6b4..09c9438 100644
83352 --- a/include/linux/zlib.h
83353 +++ b/include/linux/zlib.h
83354 @@ -31,6 +31,7 @@
83355 #define _ZLIB_H
83356
83357 #include <linux/zconf.h>
83358 +#include <linux/compiler.h>
83359
83360 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
83361 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
83362 @@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
83363
83364 /* basic functions */
83365
83366 -extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
83367 +extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
83368 /*
83369 Returns the number of bytes that needs to be allocated for a per-
83370 stream workspace with the specified parameters. A pointer to this
83371 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
83372 index eec6e46..82d5641 100644
83373 --- a/include/media/v4l2-dev.h
83374 +++ b/include/media/v4l2-dev.h
83375 @@ -77,7 +77,7 @@ struct v4l2_file_operations {
83376 int (*mmap) (struct file *, struct vm_area_struct *);
83377 int (*open) (struct file *);
83378 int (*release) (struct file *);
83379 -};
83380 +} __do_const;
83381
83382 /*
83383 * Newer version of video_device, handled by videodev2.c
83384 diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
83385 index c9b1593..a572459 100644
83386 --- a/include/media/v4l2-device.h
83387 +++ b/include/media/v4l2-device.h
83388 @@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
83389 this function returns 0. If the name ends with a digit (e.g. cx18),
83390 then the name will be set to cx18-0 since cx180 looks really odd. */
83391 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
83392 - atomic_t *instance);
83393 + atomic_unchecked_t *instance);
83394
83395 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
83396 Since the parent disappears this ensures that v4l2_dev doesn't have an
83397 diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
83398 index d9fa68f..45c88d1 100644
83399 --- a/include/net/9p/transport.h
83400 +++ b/include/net/9p/transport.h
83401 @@ -63,7 +63,7 @@ struct p9_trans_module {
83402 int (*cancelled)(struct p9_client *, struct p9_req_t *req);
83403 int (*zc_request)(struct p9_client *, struct p9_req_t *,
83404 char *, char *, int , int, int, int);
83405 -};
83406 +} __do_const;
83407
83408 void v9fs_register_trans(struct p9_trans_module *m);
83409 void v9fs_unregister_trans(struct p9_trans_module *m);
83410 diff --git a/include/net/af_unix.h b/include/net/af_unix.h
83411 index a175ba4..196eb82 100644
83412 --- a/include/net/af_unix.h
83413 +++ b/include/net/af_unix.h
83414 @@ -36,7 +36,7 @@ struct unix_skb_parms {
83415 u32 secid; /* Security ID */
83416 #endif
83417 u32 consumed;
83418 -};
83419 +} __randomize_layout;
83420
83421 #define UNIXCB(skb) (*(struct unix_skb_parms *)&((skb)->cb))
83422 #define UNIXSID(skb) (&UNIXCB((skb)).secid)
83423 diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
83424 index 4abdcb2..945c5cc 100644
83425 --- a/include/net/bluetooth/l2cap.h
83426 +++ b/include/net/bluetooth/l2cap.h
83427 @@ -601,7 +601,7 @@ struct l2cap_ops {
83428 long (*get_sndtimeo) (struct l2cap_chan *chan);
83429 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
83430 unsigned long len, int nb);
83431 -};
83432 +} __do_const;
83433
83434 struct l2cap_conn {
83435 struct hci_conn *hcon;
83436 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
83437 index f2ae33d..c457cf0 100644
83438 --- a/include/net/caif/cfctrl.h
83439 +++ b/include/net/caif/cfctrl.h
83440 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
83441 void (*radioset_rsp)(void);
83442 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
83443 struct cflayer *client_layer);
83444 -};
83445 +} __no_const;
83446
83447 /* Link Setup Parameters for CAIF-Links. */
83448 struct cfctrl_link_param {
83449 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
83450 struct cfctrl {
83451 struct cfsrvl serv;
83452 struct cfctrl_rsp res;
83453 - atomic_t req_seq_no;
83454 - atomic_t rsp_seq_no;
83455 + atomic_unchecked_t req_seq_no;
83456 + atomic_unchecked_t rsp_seq_no;
83457 struct list_head list;
83458 /* Protects from simultaneous access to first_req list */
83459 spinlock_t info_list_lock;
83460 diff --git a/include/net/flow.h b/include/net/flow.h
83461 index 8109a15..504466d 100644
83462 --- a/include/net/flow.h
83463 +++ b/include/net/flow.h
83464 @@ -231,6 +231,6 @@ void flow_cache_fini(struct net *net);
83465
83466 void flow_cache_flush(struct net *net);
83467 void flow_cache_flush_deferred(struct net *net);
83468 -extern atomic_t flow_cache_genid;
83469 +extern atomic_unchecked_t flow_cache_genid;
83470
83471 #endif
83472 diff --git a/include/net/genetlink.h b/include/net/genetlink.h
83473 index 93695f0..766d71c 100644
83474 --- a/include/net/genetlink.h
83475 +++ b/include/net/genetlink.h
83476 @@ -120,7 +120,7 @@ struct genl_ops {
83477 u8 cmd;
83478 u8 internal_flags;
83479 u8 flags;
83480 -};
83481 +} __do_const;
83482
83483 int __genl_register_family(struct genl_family *family);
83484
83485 diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
83486 index 734d9b5..48a9a4b 100644
83487 --- a/include/net/gro_cells.h
83488 +++ b/include/net/gro_cells.h
83489 @@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
83490 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
83491
83492 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
83493 - atomic_long_inc(&dev->rx_dropped);
83494 + atomic_long_inc_unchecked(&dev->rx_dropped);
83495 kfree_skb(skb);
83496 return;
83497 }
83498 diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
83499 index 7a43138..bc76865 100644
83500 --- a/include/net/inet_connection_sock.h
83501 +++ b/include/net/inet_connection_sock.h
83502 @@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
83503 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
83504 int (*bind_conflict)(const struct sock *sk,
83505 const struct inet_bind_bucket *tb, bool relax);
83506 -};
83507 +} __do_const;
83508
83509 /** inet_connection_sock - INET connection oriented sock
83510 *
83511 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
83512 index 058271b..1a44af7 100644
83513 --- a/include/net/inetpeer.h
83514 +++ b/include/net/inetpeer.h
83515 @@ -47,8 +47,8 @@ struct inet_peer {
83516 */
83517 union {
83518 struct {
83519 - atomic_t rid; /* Frag reception counter */
83520 - atomic_t ip_id_count; /* IP ID for the next packet */
83521 + atomic_unchecked_t rid; /* Frag reception counter */
83522 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
83523 };
83524 struct rcu_head rcu;
83525 struct inet_peer *gc_next;
83526 @@ -179,7 +179,7 @@ static inline int inet_getid(struct inet_peer *p, int more)
83527 {
83528 more++;
83529 inet_peer_refcheck(p);
83530 - return atomic_add_return(more, &p->ip_id_count) - more;
83531 + return atomic_add_return_unchecked(more, &p->ip_id_count) - more;
83532 }
83533
83534 #endif /* _NET_INETPEER_H */
83535 diff --git a/include/net/ip.h b/include/net/ip.h
83536 index 3ec2b0f..72435b6 100644
83537 --- a/include/net/ip.h
83538 +++ b/include/net/ip.h
83539 @@ -220,7 +220,7 @@ static inline void snmp_mib_free(void __percpu *ptr[SNMP_ARRAY_SZ])
83540
83541 void inet_get_local_port_range(struct net *net, int *low, int *high);
83542
83543 -extern unsigned long *sysctl_local_reserved_ports;
83544 +extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
83545 static inline int inet_is_reserved_local_port(int port)
83546 {
83547 return test_bit(port, sysctl_local_reserved_ports);
83548 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
83549 index 9922093..a1755d6 100644
83550 --- a/include/net/ip_fib.h
83551 +++ b/include/net/ip_fib.h
83552 @@ -169,7 +169,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
83553
83554 #define FIB_RES_SADDR(net, res) \
83555 ((FIB_RES_NH(res).nh_saddr_genid == \
83556 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
83557 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
83558 FIB_RES_NH(res).nh_saddr : \
83559 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
83560 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
83561 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
83562 index 5679d92..2e7a690 100644
83563 --- a/include/net/ip_vs.h
83564 +++ b/include/net/ip_vs.h
83565 @@ -558,7 +558,7 @@ struct ip_vs_conn {
83566 struct ip_vs_conn *control; /* Master control connection */
83567 atomic_t n_control; /* Number of controlled ones */
83568 struct ip_vs_dest *dest; /* real server */
83569 - atomic_t in_pkts; /* incoming packet counter */
83570 + atomic_unchecked_t in_pkts; /* incoming packet counter */
83571
83572 /* packet transmitter for different forwarding methods. If it
83573 mangles the packet, it must return NF_DROP or better NF_STOLEN,
83574 @@ -705,7 +705,7 @@ struct ip_vs_dest {
83575 __be16 port; /* port number of the server */
83576 union nf_inet_addr addr; /* IP address of the server */
83577 volatile unsigned int flags; /* dest status flags */
83578 - atomic_t conn_flags; /* flags to copy to conn */
83579 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
83580 atomic_t weight; /* server weight */
83581
83582 atomic_t refcnt; /* reference counter */
83583 @@ -960,11 +960,11 @@ struct netns_ipvs {
83584 /* ip_vs_lblc */
83585 int sysctl_lblc_expiration;
83586 struct ctl_table_header *lblc_ctl_header;
83587 - struct ctl_table *lblc_ctl_table;
83588 + ctl_table_no_const *lblc_ctl_table;
83589 /* ip_vs_lblcr */
83590 int sysctl_lblcr_expiration;
83591 struct ctl_table_header *lblcr_ctl_header;
83592 - struct ctl_table *lblcr_ctl_table;
83593 + ctl_table_no_const *lblcr_ctl_table;
83594 /* ip_vs_est */
83595 struct list_head est_list; /* estimator list */
83596 spinlock_t est_lock;
83597 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
83598 index 8d4f588..2e37ad2 100644
83599 --- a/include/net/irda/ircomm_tty.h
83600 +++ b/include/net/irda/ircomm_tty.h
83601 @@ -33,6 +33,7 @@
83602 #include <linux/termios.h>
83603 #include <linux/timer.h>
83604 #include <linux/tty.h> /* struct tty_struct */
83605 +#include <asm/local.h>
83606
83607 #include <net/irda/irias_object.h>
83608 #include <net/irda/ircomm_core.h>
83609 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
83610 index 714cc9a..ea05f3e 100644
83611 --- a/include/net/iucv/af_iucv.h
83612 +++ b/include/net/iucv/af_iucv.h
83613 @@ -149,7 +149,7 @@ struct iucv_skb_cb {
83614 struct iucv_sock_list {
83615 struct hlist_head head;
83616 rwlock_t lock;
83617 - atomic_t autobind_name;
83618 + atomic_unchecked_t autobind_name;
83619 };
83620
83621 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
83622 diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
83623 index f3be818..bf46196 100644
83624 --- a/include/net/llc_c_ac.h
83625 +++ b/include/net/llc_c_ac.h
83626 @@ -87,7 +87,7 @@
83627 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
83628 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
83629
83630 -typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
83631 +typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
83632
83633 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
83634 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
83635 diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
83636 index 3948cf1..83b28c4 100644
83637 --- a/include/net/llc_c_ev.h
83638 +++ b/include/net/llc_c_ev.h
83639 @@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
83640 return (struct llc_conn_state_ev *)skb->cb;
83641 }
83642
83643 -typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
83644 -typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
83645 +typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
83646 +typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
83647
83648 int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
83649 int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
83650 diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
83651 index 0e79cfb..f46db31 100644
83652 --- a/include/net/llc_c_st.h
83653 +++ b/include/net/llc_c_st.h
83654 @@ -37,7 +37,7 @@ struct llc_conn_state_trans {
83655 u8 next_state;
83656 llc_conn_ev_qfyr_t *ev_qualifiers;
83657 llc_conn_action_t *ev_actions;
83658 -};
83659 +} __do_const;
83660
83661 struct llc_conn_state {
83662 u8 current_state;
83663 diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
83664 index a61b98c..aade1eb 100644
83665 --- a/include/net/llc_s_ac.h
83666 +++ b/include/net/llc_s_ac.h
83667 @@ -23,7 +23,7 @@
83668 #define SAP_ACT_TEST_IND 9
83669
83670 /* All action functions must look like this */
83671 -typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
83672 +typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
83673
83674 int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb);
83675 int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb);
83676 diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
83677 index 567c681..cd73ac02 100644
83678 --- a/include/net/llc_s_st.h
83679 +++ b/include/net/llc_s_st.h
83680 @@ -20,7 +20,7 @@ struct llc_sap_state_trans {
83681 llc_sap_ev_t ev;
83682 u8 next_state;
83683 llc_sap_action_t *ev_actions;
83684 -};
83685 +} __do_const;
83686
83687 struct llc_sap_state {
83688 u8 curr_state;
83689 diff --git a/include/net/mac80211.h b/include/net/mac80211.h
83690 index 8248e39..7610eec 100644
83691 --- a/include/net/mac80211.h
83692 +++ b/include/net/mac80211.h
83693 @@ -4467,7 +4467,7 @@ struct rate_control_ops {
83694 void (*add_sta_debugfs)(void *priv, void *priv_sta,
83695 struct dentry *dir);
83696 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
83697 -};
83698 +} __do_const;
83699
83700 static inline int rate_supported(struct ieee80211_sta *sta,
83701 enum ieee80211_band band,
83702 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
83703 index 7277caf..fd095bc 100644
83704 --- a/include/net/neighbour.h
83705 +++ b/include/net/neighbour.h
83706 @@ -163,7 +163,7 @@ struct neigh_ops {
83707 void (*error_report)(struct neighbour *, struct sk_buff *);
83708 int (*output)(struct neighbour *, struct sk_buff *);
83709 int (*connected_output)(struct neighbour *, struct sk_buff *);
83710 -};
83711 +} __do_const;
83712
83713 struct pneigh_entry {
83714 struct pneigh_entry *next;
83715 @@ -203,7 +203,6 @@ struct neigh_table {
83716 void (*proxy_redo)(struct sk_buff *skb);
83717 char *id;
83718 struct neigh_parms parms;
83719 - /* HACK. gc_* should follow parms without a gap! */
83720 int gc_interval;
83721 int gc_thresh1;
83722 int gc_thresh2;
83723 @@ -218,7 +217,7 @@ struct neigh_table {
83724 struct neigh_statistics __percpu *stats;
83725 struct neigh_hash_table __rcu *nht;
83726 struct pneigh_entry **phash_buckets;
83727 -};
83728 +} __randomize_layout;
83729
83730 static inline int neigh_parms_family(struct neigh_parms *p)
83731 {
83732 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
83733 index 5f9eb26..85699c4 100644
83734 --- a/include/net/net_namespace.h
83735 +++ b/include/net/net_namespace.h
83736 @@ -129,8 +129,8 @@ struct net {
83737 struct netns_ipvs *ipvs;
83738 #endif
83739 struct sock *diag_nlsk;
83740 - atomic_t fnhe_genid;
83741 -};
83742 + atomic_unchecked_t fnhe_genid;
83743 +} __randomize_layout;
83744
83745 #include <linux/seq_file_net.h>
83746
83747 @@ -286,7 +286,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
83748 #define __net_init __init
83749 #define __net_exit __exit_refok
83750 #define __net_initdata __initdata
83751 +#ifdef CONSTIFY_PLUGIN
83752 #define __net_initconst __initconst
83753 +#else
83754 +#define __net_initconst __initdata
83755 +#endif
83756 #endif
83757
83758 struct pernet_operations {
83759 @@ -296,7 +300,7 @@ struct pernet_operations {
83760 void (*exit_batch)(struct list_head *net_exit_list);
83761 int *id;
83762 size_t size;
83763 -};
83764 +} __do_const;
83765
83766 /*
83767 * Use these carefully. If you implement a network device and it
83768 @@ -344,23 +348,23 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
83769
83770 static inline int rt_genid_ipv4(struct net *net)
83771 {
83772 - return atomic_read(&net->ipv4.rt_genid);
83773 + return atomic_read_unchecked(&net->ipv4.rt_genid);
83774 }
83775
83776 static inline void rt_genid_bump_ipv4(struct net *net)
83777 {
83778 - atomic_inc(&net->ipv4.rt_genid);
83779 + atomic_inc_unchecked(&net->ipv4.rt_genid);
83780 }
83781
83782 #if IS_ENABLED(CONFIG_IPV6)
83783 static inline int rt_genid_ipv6(struct net *net)
83784 {
83785 - return atomic_read(&net->ipv6.rt_genid);
83786 + return atomic_read_unchecked(&net->ipv6.rt_genid);
83787 }
83788
83789 static inline void rt_genid_bump_ipv6(struct net *net)
83790 {
83791 - atomic_inc(&net->ipv6.rt_genid);
83792 + atomic_inc_unchecked(&net->ipv6.rt_genid);
83793 }
83794 #else
83795 static inline int rt_genid_ipv6(struct net *net)
83796 @@ -382,12 +386,12 @@ static inline void rt_genid_bump_all(struct net *net)
83797
83798 static inline int fnhe_genid(struct net *net)
83799 {
83800 - return atomic_read(&net->fnhe_genid);
83801 + return atomic_read_unchecked(&net->fnhe_genid);
83802 }
83803
83804 static inline void fnhe_genid_bump(struct net *net)
83805 {
83806 - atomic_inc(&net->fnhe_genid);
83807 + atomic_inc_unchecked(&net->fnhe_genid);
83808 }
83809
83810 #endif /* __NET_NET_NAMESPACE_H */
83811 diff --git a/include/net/netdma.h b/include/net/netdma.h
83812 index 8ba8ce2..99b7fff 100644
83813 --- a/include/net/netdma.h
83814 +++ b/include/net/netdma.h
83815 @@ -24,7 +24,7 @@
83816 #include <linux/dmaengine.h>
83817 #include <linux/skbuff.h>
83818
83819 -int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
83820 +int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
83821 struct sk_buff *skb, int offset, struct iovec *to,
83822 size_t len, struct dma_pinned_list *pinned_list);
83823
83824 diff --git a/include/net/netlink.h b/include/net/netlink.h
83825 index 2b47eaa..6d5bcc2 100644
83826 --- a/include/net/netlink.h
83827 +++ b/include/net/netlink.h
83828 @@ -521,7 +521,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
83829 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
83830 {
83831 if (mark)
83832 - skb_trim(skb, (unsigned char *) mark - skb->data);
83833 + skb_trim(skb, (const unsigned char *) mark - skb->data);
83834 }
83835
83836 /**
83837 diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
83838 index 773cce3..6a11852 100644
83839 --- a/include/net/netns/conntrack.h
83840 +++ b/include/net/netns/conntrack.h
83841 @@ -13,10 +13,10 @@ struct nf_conntrack_ecache;
83842 struct nf_proto_net {
83843 #ifdef CONFIG_SYSCTL
83844 struct ctl_table_header *ctl_table_header;
83845 - struct ctl_table *ctl_table;
83846 + ctl_table_no_const *ctl_table;
83847 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
83848 struct ctl_table_header *ctl_compat_header;
83849 - struct ctl_table *ctl_compat_table;
83850 + ctl_table_no_const *ctl_compat_table;
83851 #endif
83852 #endif
83853 unsigned int users;
83854 @@ -59,7 +59,7 @@ struct nf_ip_net {
83855 struct nf_icmp_net icmpv6;
83856 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
83857 struct ctl_table_header *ctl_table_header;
83858 - struct ctl_table *ctl_table;
83859 + ctl_table_no_const *ctl_table;
83860 #endif
83861 };
83862
83863 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
83864 index b2704fd0..421d717 100644
83865 --- a/include/net/netns/ipv4.h
83866 +++ b/include/net/netns/ipv4.h
83867 @@ -79,7 +79,7 @@ struct netns_ipv4 {
83868
83869 struct ping_group_range ping_group_range;
83870
83871 - atomic_t dev_addr_genid;
83872 + atomic_unchecked_t dev_addr_genid;
83873
83874 #ifdef CONFIG_IP_MROUTE
83875 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
83876 @@ -89,6 +89,6 @@ struct netns_ipv4 {
83877 struct fib_rules_ops *mr_rules_ops;
83878 #endif
83879 #endif
83880 - atomic_t rt_genid;
83881 + atomic_unchecked_t rt_genid;
83882 };
83883 #endif
83884 diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
83885 index 21edaf1..4c5faae 100644
83886 --- a/include/net/netns/ipv6.h
83887 +++ b/include/net/netns/ipv6.h
83888 @@ -73,8 +73,8 @@ struct netns_ipv6 {
83889 struct fib_rules_ops *mr6_rules_ops;
83890 #endif
83891 #endif
83892 - atomic_t dev_addr_genid;
83893 - atomic_t rt_genid;
83894 + atomic_unchecked_t dev_addr_genid;
83895 + atomic_unchecked_t rt_genid;
83896 };
83897
83898 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
83899 diff --git a/include/net/netns/xfrm.h b/include/net/netns/xfrm.h
83900 index 3492434..209f58c 100644
83901 --- a/include/net/netns/xfrm.h
83902 +++ b/include/net/netns/xfrm.h
83903 @@ -64,7 +64,7 @@ struct netns_xfrm {
83904
83905 /* flow cache part */
83906 struct flow_cache flow_cache_global;
83907 - atomic_t flow_cache_genid;
83908 + atomic_unchecked_t flow_cache_genid;
83909 struct list_head flow_cache_gc_list;
83910 spinlock_t flow_cache_gc_lock;
83911 struct work_struct flow_cache_gc_work;
83912 diff --git a/include/net/ping.h b/include/net/ping.h
83913 index 026479b..d9b2829 100644
83914 --- a/include/net/ping.h
83915 +++ b/include/net/ping.h
83916 @@ -54,7 +54,7 @@ struct ping_iter_state {
83917
83918 extern struct proto ping_prot;
83919 #if IS_ENABLED(CONFIG_IPV6)
83920 -extern struct pingv6_ops pingv6_ops;
83921 +extern struct pingv6_ops *pingv6_ops;
83922 #endif
83923
83924 struct pingfakehdr {
83925 diff --git a/include/net/protocol.h b/include/net/protocol.h
83926 index a7e986b..dc67bce 100644
83927 --- a/include/net/protocol.h
83928 +++ b/include/net/protocol.h
83929 @@ -49,7 +49,7 @@ struct net_protocol {
83930 * socket lookup?
83931 */
83932 icmp_strict_tag_validation:1;
83933 -};
83934 +} __do_const;
83935
83936 #if IS_ENABLED(CONFIG_IPV6)
83937 struct inet6_protocol {
83938 @@ -62,7 +62,7 @@ struct inet6_protocol {
83939 u8 type, u8 code, int offset,
83940 __be32 info);
83941 unsigned int flags; /* INET6_PROTO_xxx */
83942 -};
83943 +} __do_const;
83944
83945 #define INET6_PROTO_NOPOLICY 0x1
83946 #define INET6_PROTO_FINAL 0x2
83947 diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
83948 index 72240e5..8c14bef 100644
83949 --- a/include/net/rtnetlink.h
83950 +++ b/include/net/rtnetlink.h
83951 @@ -93,7 +93,7 @@ struct rtnl_link_ops {
83952 int (*fill_slave_info)(struct sk_buff *skb,
83953 const struct net_device *dev,
83954 const struct net_device *slave_dev);
83955 -};
83956 +} __do_const;
83957
83958 int __rtnl_link_register(struct rtnl_link_ops *ops);
83959 void __rtnl_link_unregister(struct rtnl_link_ops *ops);
83960 diff --git a/include/net/sctp/checksum.h b/include/net/sctp/checksum.h
83961 index 4a5b9a3..ca27d73 100644
83962 --- a/include/net/sctp/checksum.h
83963 +++ b/include/net/sctp/checksum.h
83964 @@ -61,8 +61,8 @@ static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
83965 unsigned int offset)
83966 {
83967 struct sctphdr *sh = sctp_hdr(skb);
83968 - __le32 ret, old = sh->checksum;
83969 - const struct skb_checksum_ops ops = {
83970 + __le32 ret, old = sh->checksum;
83971 + static const struct skb_checksum_ops ops = {
83972 .update = sctp_csum_update,
83973 .combine = sctp_csum_combine,
83974 };
83975 diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
83976 index 7f4eeb3..37e8fe1 100644
83977 --- a/include/net/sctp/sm.h
83978 +++ b/include/net/sctp/sm.h
83979 @@ -80,7 +80,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
83980 typedef struct {
83981 sctp_state_fn_t *fn;
83982 const char *name;
83983 -} sctp_sm_table_entry_t;
83984 +} __do_const sctp_sm_table_entry_t;
83985
83986 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
83987 * currently in use.
83988 @@ -292,7 +292,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
83989 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
83990
83991 /* Extern declarations for major data structures. */
83992 -extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
83993 +extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
83994
83995
83996 /* Get the size of a DATA chunk payload. */
83997 diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
83998 index 0dfcc92..7967849 100644
83999 --- a/include/net/sctp/structs.h
84000 +++ b/include/net/sctp/structs.h
84001 @@ -507,7 +507,7 @@ struct sctp_pf {
84002 struct sctp_association *asoc);
84003 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
84004 struct sctp_af *af;
84005 -};
84006 +} __do_const;
84007
84008
84009 /* Structure to track chunk fragments that have been acked, but peer
84010 diff --git a/include/net/sock.h b/include/net/sock.h
84011 index 21569cf..dd60300 100644
84012 --- a/include/net/sock.h
84013 +++ b/include/net/sock.h
84014 @@ -348,7 +348,7 @@ struct sock {
84015 unsigned int sk_napi_id;
84016 unsigned int sk_ll_usec;
84017 #endif
84018 - atomic_t sk_drops;
84019 + atomic_unchecked_t sk_drops;
84020 int sk_rcvbuf;
84021
84022 struct sk_filter __rcu *sk_filter;
84023 @@ -1036,7 +1036,7 @@ struct proto {
84024 void (*destroy_cgroup)(struct mem_cgroup *memcg);
84025 struct cg_proto *(*proto_cgroup)(struct mem_cgroup *memcg);
84026 #endif
84027 -};
84028 +} __randomize_layout;
84029
84030 /*
84031 * Bits in struct cg_proto.flags
84032 @@ -1223,7 +1223,7 @@ static inline u64 memcg_memory_allocated_read(struct cg_proto *prot)
84033 return ret >> PAGE_SHIFT;
84034 }
84035
84036 -static inline long
84037 +static inline long __intentional_overflow(-1)
84038 sk_memory_allocated(const struct sock *sk)
84039 {
84040 struct proto *prot = sk->sk_prot;
84041 @@ -1368,7 +1368,7 @@ struct sock_iocb {
84042 struct scm_cookie *scm;
84043 struct msghdr *msg, async_msg;
84044 struct kiocb *kiocb;
84045 -};
84046 +} __randomize_layout;
84047
84048 static inline struct sock_iocb *kiocb_to_siocb(struct kiocb *iocb)
84049 {
84050 @@ -1728,8 +1728,8 @@ sk_dst_get(struct sock *sk)
84051
84052 rcu_read_lock();
84053 dst = rcu_dereference(sk->sk_dst_cache);
84054 - if (dst)
84055 - dst_hold(dst);
84056 + if (dst && !atomic_inc_not_zero(&dst->__refcnt))
84057 + dst = NULL;
84058 rcu_read_unlock();
84059 return dst;
84060 }
84061 @@ -1803,7 +1803,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
84062 }
84063
84064 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
84065 - char __user *from, char *to,
84066 + char __user *from, unsigned char *to,
84067 int copy, int offset)
84068 {
84069 if (skb->ip_summed == CHECKSUM_NONE) {
84070 @@ -2065,7 +2065,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
84071 }
84072 }
84073
84074 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
84075 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
84076
84077 /**
84078 * sk_page_frag - return an appropriate page_frag
84079 diff --git a/include/net/tcp.h b/include/net/tcp.h
84080 index 87d8774..cf214f8 100644
84081 --- a/include/net/tcp.h
84082 +++ b/include/net/tcp.h
84083 @@ -541,7 +541,7 @@ void tcp_retransmit_timer(struct sock *sk);
84084 void tcp_xmit_retransmit_queue(struct sock *);
84085 void tcp_simple_retransmit(struct sock *);
84086 int tcp_trim_head(struct sock *, struct sk_buff *, u32);
84087 -int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
84088 +int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
84089
84090 void tcp_send_probe0(struct sock *);
84091 void tcp_send_partial(struct sock *);
84092 @@ -715,8 +715,8 @@ struct tcp_skb_cb {
84093 struct inet6_skb_parm h6;
84094 #endif
84095 } header; /* For incoming frames */
84096 - __u32 seq; /* Starting sequence number */
84097 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
84098 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
84099 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
84100 __u32 when; /* used to compute rtt's */
84101 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
84102
84103 @@ -730,7 +730,7 @@ struct tcp_skb_cb {
84104
84105 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
84106 /* 1 byte hole */
84107 - __u32 ack_seq; /* Sequence number ACK'd */
84108 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
84109 };
84110
84111 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
84112 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
84113 index 116e9c7..3070537 100644
84114 --- a/include/net/xfrm.h
84115 +++ b/include/net/xfrm.h
84116 @@ -285,7 +285,6 @@ struct xfrm_dst;
84117 struct xfrm_policy_afinfo {
84118 unsigned short family;
84119 struct dst_ops *dst_ops;
84120 - void (*garbage_collect)(struct net *net);
84121 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
84122 const xfrm_address_t *saddr,
84123 const xfrm_address_t *daddr);
84124 @@ -303,7 +302,7 @@ struct xfrm_policy_afinfo {
84125 struct net_device *dev,
84126 const struct flowi *fl);
84127 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
84128 -};
84129 +} __do_const;
84130
84131 int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
84132 int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
84133 @@ -342,7 +341,7 @@ struct xfrm_state_afinfo {
84134 int (*transport_finish)(struct sk_buff *skb,
84135 int async);
84136 void (*local_error)(struct sk_buff *skb, u32 mtu);
84137 -};
84138 +} __do_const;
84139
84140 int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
84141 int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
84142 @@ -437,7 +436,7 @@ struct xfrm_mode {
84143 struct module *owner;
84144 unsigned int encap;
84145 int flags;
84146 -};
84147 +} __do_const;
84148
84149 /* Flags for xfrm_mode. */
84150 enum {
84151 @@ -534,7 +533,7 @@ struct xfrm_policy {
84152 struct timer_list timer;
84153
84154 struct flow_cache_object flo;
84155 - atomic_t genid;
84156 + atomic_unchecked_t genid;
84157 u32 priority;
84158 u32 index;
84159 struct xfrm_mark mark;
84160 @@ -1180,6 +1179,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
84161 }
84162
84163 void xfrm_garbage_collect(struct net *net);
84164 +void xfrm_garbage_collect_deferred(struct net *net);
84165
84166 #else
84167
84168 @@ -1218,6 +1218,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
84169 static inline void xfrm_garbage_collect(struct net *net)
84170 {
84171 }
84172 +static inline void xfrm_garbage_collect_deferred(struct net *net)
84173 +{
84174 +}
84175 #endif
84176
84177 static __inline__
84178 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
84179 index 1017e0b..227aa4d 100644
84180 --- a/include/rdma/iw_cm.h
84181 +++ b/include/rdma/iw_cm.h
84182 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
84183 int backlog);
84184
84185 int (*destroy_listen)(struct iw_cm_id *cm_id);
84186 -};
84187 +} __no_const;
84188
84189 /**
84190 * iw_create_cm_id - Create an IW CM identifier.
84191 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
84192 index 52beadf..598734c 100644
84193 --- a/include/scsi/libfc.h
84194 +++ b/include/scsi/libfc.h
84195 @@ -771,6 +771,7 @@ struct libfc_function_template {
84196 */
84197 void (*disc_stop_final) (struct fc_lport *);
84198 };
84199 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
84200
84201 /**
84202 * struct fc_disc - Discovery context
84203 @@ -875,7 +876,7 @@ struct fc_lport {
84204 struct fc_vport *vport;
84205
84206 /* Operational Information */
84207 - struct libfc_function_template tt;
84208 + libfc_function_template_no_const tt;
84209 u8 link_up;
84210 u8 qfull;
84211 enum fc_lport_state state;
84212 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
84213 index 27ab310..60dc245 100644
84214 --- a/include/scsi/scsi_device.h
84215 +++ b/include/scsi/scsi_device.h
84216 @@ -187,9 +187,9 @@ struct scsi_device {
84217 unsigned int max_device_blocked; /* what device_blocked counts down from */
84218 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
84219
84220 - atomic_t iorequest_cnt;
84221 - atomic_t iodone_cnt;
84222 - atomic_t ioerr_cnt;
84223 + atomic_unchecked_t iorequest_cnt;
84224 + atomic_unchecked_t iodone_cnt;
84225 + atomic_unchecked_t ioerr_cnt;
84226
84227 struct device sdev_gendev,
84228 sdev_dev;
84229 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
84230 index 8c79980..723f6f9 100644
84231 --- a/include/scsi/scsi_transport_fc.h
84232 +++ b/include/scsi/scsi_transport_fc.h
84233 @@ -752,7 +752,8 @@ struct fc_function_template {
84234 unsigned long show_host_system_hostname:1;
84235
84236 unsigned long disable_target_scan:1;
84237 -};
84238 +} __do_const;
84239 +typedef struct fc_function_template __no_const fc_function_template_no_const;
84240
84241
84242 /**
84243 diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
84244 index ae6c3b8..fd748ac 100644
84245 --- a/include/sound/compress_driver.h
84246 +++ b/include/sound/compress_driver.h
84247 @@ -128,7 +128,7 @@ struct snd_compr_ops {
84248 struct snd_compr_caps *caps);
84249 int (*get_codec_caps) (struct snd_compr_stream *stream,
84250 struct snd_compr_codec_caps *codec);
84251 -};
84252 +} __no_const;
84253
84254 /**
84255 * struct snd_compr: Compressed device
84256 diff --git a/include/sound/soc.h b/include/sound/soc.h
84257 index 0b83168..d67280a 100644
84258 --- a/include/sound/soc.h
84259 +++ b/include/sound/soc.h
84260 @@ -782,7 +782,7 @@ struct snd_soc_codec_driver {
84261 /* probe ordering - for components with runtime dependencies */
84262 int probe_order;
84263 int remove_order;
84264 -};
84265 +} __do_const;
84266
84267 /* SoC platform interface */
84268 struct snd_soc_platform_driver {
84269 @@ -828,7 +828,7 @@ struct snd_soc_platform_driver {
84270 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
84271 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
84272 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
84273 -};
84274 +} __do_const;
84275
84276 struct snd_soc_platform {
84277 const char *name;
84278 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
84279 index 9ec9864..e2ee1ee 100644
84280 --- a/include/target/target_core_base.h
84281 +++ b/include/target/target_core_base.h
84282 @@ -761,7 +761,7 @@ struct se_device {
84283 atomic_long_t write_bytes;
84284 /* Active commands on this virtual SE device */
84285 atomic_t simple_cmds;
84286 - atomic_t dev_ordered_id;
84287 + atomic_unchecked_t dev_ordered_id;
84288 atomic_t dev_ordered_sync;
84289 atomic_t dev_qf_count;
84290 int export_count;
84291 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
84292 new file mode 100644
84293 index 0000000..fb634b7
84294 --- /dev/null
84295 +++ b/include/trace/events/fs.h
84296 @@ -0,0 +1,53 @@
84297 +#undef TRACE_SYSTEM
84298 +#define TRACE_SYSTEM fs
84299 +
84300 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
84301 +#define _TRACE_FS_H
84302 +
84303 +#include <linux/fs.h>
84304 +#include <linux/tracepoint.h>
84305 +
84306 +TRACE_EVENT(do_sys_open,
84307 +
84308 + TP_PROTO(const char *filename, int flags, int mode),
84309 +
84310 + TP_ARGS(filename, flags, mode),
84311 +
84312 + TP_STRUCT__entry(
84313 + __string( filename, filename )
84314 + __field( int, flags )
84315 + __field( int, mode )
84316 + ),
84317 +
84318 + TP_fast_assign(
84319 + __assign_str(filename, filename);
84320 + __entry->flags = flags;
84321 + __entry->mode = mode;
84322 + ),
84323 +
84324 + TP_printk("\"%s\" %x %o",
84325 + __get_str(filename), __entry->flags, __entry->mode)
84326 +);
84327 +
84328 +TRACE_EVENT(open_exec,
84329 +
84330 + TP_PROTO(const char *filename),
84331 +
84332 + TP_ARGS(filename),
84333 +
84334 + TP_STRUCT__entry(
84335 + __string( filename, filename )
84336 + ),
84337 +
84338 + TP_fast_assign(
84339 + __assign_str(filename, filename);
84340 + ),
84341 +
84342 + TP_printk("\"%s\"",
84343 + __get_str(filename))
84344 +);
84345 +
84346 +#endif /* _TRACE_FS_H */
84347 +
84348 +/* This part must be outside protection */
84349 +#include <trace/define_trace.h>
84350 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
84351 index 1c09820..7f5ec79 100644
84352 --- a/include/trace/events/irq.h
84353 +++ b/include/trace/events/irq.h
84354 @@ -36,7 +36,7 @@ struct softirq_action;
84355 */
84356 TRACE_EVENT(irq_handler_entry,
84357
84358 - TP_PROTO(int irq, struct irqaction *action),
84359 + TP_PROTO(int irq, const struct irqaction *action),
84360
84361 TP_ARGS(irq, action),
84362
84363 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
84364 */
84365 TRACE_EVENT(irq_handler_exit,
84366
84367 - TP_PROTO(int irq, struct irqaction *action, int ret),
84368 + TP_PROTO(int irq, const struct irqaction *action, int ret),
84369
84370 TP_ARGS(irq, action, ret),
84371
84372 diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
84373 index 7caf44c..23c6f27 100644
84374 --- a/include/uapi/linux/a.out.h
84375 +++ b/include/uapi/linux/a.out.h
84376 @@ -39,6 +39,14 @@ enum machine_type {
84377 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
84378 };
84379
84380 +/* Constants for the N_FLAGS field */
84381 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
84382 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
84383 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
84384 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
84385 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
84386 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
84387 +
84388 #if !defined (N_MAGIC)
84389 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
84390 #endif
84391 diff --git a/include/uapi/linux/bcache.h b/include/uapi/linux/bcache.h
84392 index 22b6ad3..aeba37e 100644
84393 --- a/include/uapi/linux/bcache.h
84394 +++ b/include/uapi/linux/bcache.h
84395 @@ -5,6 +5,7 @@
84396 * Bcache on disk data structures
84397 */
84398
84399 +#include <linux/compiler.h>
84400 #include <asm/types.h>
84401
84402 #define BITMASK(name, type, field, offset, size) \
84403 @@ -20,8 +21,8 @@ static inline void SET_##name(type *k, __u64 v) \
84404 /* Btree keys - all units are in sectors */
84405
84406 struct bkey {
84407 - __u64 high;
84408 - __u64 low;
84409 + __u64 high __intentional_overflow(-1);
84410 + __u64 low __intentional_overflow(-1);
84411 __u64 ptr[];
84412 };
84413
84414 diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
84415 index d876736..ccce5c0 100644
84416 --- a/include/uapi/linux/byteorder/little_endian.h
84417 +++ b/include/uapi/linux/byteorder/little_endian.h
84418 @@ -42,51 +42,51 @@
84419
84420 static inline __le64 __cpu_to_le64p(const __u64 *p)
84421 {
84422 - return (__force __le64)*p;
84423 + return (__force const __le64)*p;
84424 }
84425 -static inline __u64 __le64_to_cpup(const __le64 *p)
84426 +static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
84427 {
84428 - return (__force __u64)*p;
84429 + return (__force const __u64)*p;
84430 }
84431 static inline __le32 __cpu_to_le32p(const __u32 *p)
84432 {
84433 - return (__force __le32)*p;
84434 + return (__force const __le32)*p;
84435 }
84436 static inline __u32 __le32_to_cpup(const __le32 *p)
84437 {
84438 - return (__force __u32)*p;
84439 + return (__force const __u32)*p;
84440 }
84441 static inline __le16 __cpu_to_le16p(const __u16 *p)
84442 {
84443 - return (__force __le16)*p;
84444 + return (__force const __le16)*p;
84445 }
84446 static inline __u16 __le16_to_cpup(const __le16 *p)
84447 {
84448 - return (__force __u16)*p;
84449 + return (__force const __u16)*p;
84450 }
84451 static inline __be64 __cpu_to_be64p(const __u64 *p)
84452 {
84453 - return (__force __be64)__swab64p(p);
84454 + return (__force const __be64)__swab64p(p);
84455 }
84456 static inline __u64 __be64_to_cpup(const __be64 *p)
84457 {
84458 - return __swab64p((__u64 *)p);
84459 + return __swab64p((const __u64 *)p);
84460 }
84461 static inline __be32 __cpu_to_be32p(const __u32 *p)
84462 {
84463 - return (__force __be32)__swab32p(p);
84464 + return (__force const __be32)__swab32p(p);
84465 }
84466 -static inline __u32 __be32_to_cpup(const __be32 *p)
84467 +static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
84468 {
84469 - return __swab32p((__u32 *)p);
84470 + return __swab32p((const __u32 *)p);
84471 }
84472 static inline __be16 __cpu_to_be16p(const __u16 *p)
84473 {
84474 - return (__force __be16)__swab16p(p);
84475 + return (__force const __be16)__swab16p(p);
84476 }
84477 static inline __u16 __be16_to_cpup(const __be16 *p)
84478 {
84479 - return __swab16p((__u16 *)p);
84480 + return __swab16p((const __u16 *)p);
84481 }
84482 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
84483 #define __le64_to_cpus(x) do { (void)(x); } while (0)
84484 diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
84485 index ef6103b..d4e65dd 100644
84486 --- a/include/uapi/linux/elf.h
84487 +++ b/include/uapi/linux/elf.h
84488 @@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
84489 #define PT_GNU_EH_FRAME 0x6474e550
84490
84491 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
84492 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
84493 +
84494 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
84495 +
84496 +/* Constants for the e_flags field */
84497 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
84498 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
84499 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
84500 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
84501 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
84502 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
84503
84504 /*
84505 * Extended Numbering
84506 @@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
84507 #define DT_DEBUG 21
84508 #define DT_TEXTREL 22
84509 #define DT_JMPREL 23
84510 +#define DT_FLAGS 30
84511 + #define DF_TEXTREL 0x00000004
84512 #define DT_ENCODING 32
84513 #define OLD_DT_LOOS 0x60000000
84514 #define DT_LOOS 0x6000000d
84515 @@ -240,6 +253,19 @@ typedef struct elf64_hdr {
84516 #define PF_W 0x2
84517 #define PF_X 0x1
84518
84519 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
84520 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
84521 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
84522 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
84523 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
84524 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
84525 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
84526 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
84527 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
84528 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
84529 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
84530 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
84531 +
84532 typedef struct elf32_phdr{
84533 Elf32_Word p_type;
84534 Elf32_Off p_offset;
84535 @@ -332,6 +358,8 @@ typedef struct elf64_shdr {
84536 #define EI_OSABI 7
84537 #define EI_PAD 8
84538
84539 +#define EI_PAX 14
84540 +
84541 #define ELFMAG0 0x7f /* EI_MAG */
84542 #define ELFMAG1 'E'
84543 #define ELFMAG2 'L'
84544 diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
84545 index aa169c4..6a2771d 100644
84546 --- a/include/uapi/linux/personality.h
84547 +++ b/include/uapi/linux/personality.h
84548 @@ -30,6 +30,7 @@ enum {
84549 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
84550 ADDR_NO_RANDOMIZE | \
84551 ADDR_COMPAT_LAYOUT | \
84552 + ADDR_LIMIT_3GB | \
84553 MMAP_PAGE_ZERO)
84554
84555 /*
84556 diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
84557 index 7530e74..e714828 100644
84558 --- a/include/uapi/linux/screen_info.h
84559 +++ b/include/uapi/linux/screen_info.h
84560 @@ -43,7 +43,8 @@ struct screen_info {
84561 __u16 pages; /* 0x32 */
84562 __u16 vesa_attributes; /* 0x34 */
84563 __u32 capabilities; /* 0x36 */
84564 - __u8 _reserved[6]; /* 0x3a */
84565 + __u16 vesapm_size; /* 0x3a */
84566 + __u8 _reserved[4]; /* 0x3c */
84567 } __attribute__((packed));
84568
84569 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
84570 diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
84571 index 0e011eb..82681b1 100644
84572 --- a/include/uapi/linux/swab.h
84573 +++ b/include/uapi/linux/swab.h
84574 @@ -43,7 +43,7 @@
84575 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
84576 */
84577
84578 -static inline __attribute_const__ __u16 __fswab16(__u16 val)
84579 +static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
84580 {
84581 #ifdef __HAVE_BUILTIN_BSWAP16__
84582 return __builtin_bswap16(val);
84583 @@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
84584 #endif
84585 }
84586
84587 -static inline __attribute_const__ __u32 __fswab32(__u32 val)
84588 +static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
84589 {
84590 #ifdef __HAVE_BUILTIN_BSWAP32__
84591 return __builtin_bswap32(val);
84592 @@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
84593 #endif
84594 }
84595
84596 -static inline __attribute_const__ __u64 __fswab64(__u64 val)
84597 +static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
84598 {
84599 #ifdef __HAVE_BUILTIN_BSWAP64__
84600 return __builtin_bswap64(val);
84601 diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
84602 index 6d67213..552fdd9 100644
84603 --- a/include/uapi/linux/sysctl.h
84604 +++ b/include/uapi/linux/sysctl.h
84605 @@ -155,8 +155,6 @@ enum
84606 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
84607 };
84608
84609 -
84610 -
84611 /* CTL_VM names: */
84612 enum
84613 {
84614 diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
84615 index ea468ee..4d367a5 100644
84616 --- a/include/uapi/linux/videodev2.h
84617 +++ b/include/uapi/linux/videodev2.h
84618 @@ -1248,7 +1248,7 @@ struct v4l2_ext_control {
84619 union {
84620 __s32 value;
84621 __s64 value64;
84622 - char *string;
84623 + char __user *string;
84624 };
84625 } __attribute__ ((packed));
84626
84627 diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
84628 index c38355c..17a57bc 100644
84629 --- a/include/uapi/linux/xattr.h
84630 +++ b/include/uapi/linux/xattr.h
84631 @@ -73,5 +73,9 @@
84632 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
84633 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
84634
84635 +/* User namespace */
84636 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
84637 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
84638 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
84639
84640 #endif /* _UAPI_LINUX_XATTR_H */
84641 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
84642 index f9466fa..f4e2b81 100644
84643 --- a/include/video/udlfb.h
84644 +++ b/include/video/udlfb.h
84645 @@ -53,10 +53,10 @@ struct dlfb_data {
84646 u32 pseudo_palette[256];
84647 int blank_mode; /*one of FB_BLANK_ */
84648 /* blit-only rendering path metrics, exposed through sysfs */
84649 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
84650 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
84651 - atomic_t bytes_sent; /* to usb, after compression including overhead */
84652 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
84653 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
84654 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
84655 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
84656 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
84657 };
84658
84659 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
84660 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
84661 index 30f5362..8ed8ac9 100644
84662 --- a/include/video/uvesafb.h
84663 +++ b/include/video/uvesafb.h
84664 @@ -122,6 +122,7 @@ struct uvesafb_par {
84665 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
84666 u8 pmi_setpal; /* PMI for palette changes */
84667 u16 *pmi_base; /* protected mode interface location */
84668 + u8 *pmi_code; /* protected mode code location */
84669 void *pmi_start;
84670 void *pmi_pal;
84671 u8 *vbe_state_orig; /*
84672 diff --git a/init/Kconfig b/init/Kconfig
84673 index 9d3585b..ad45d34 100644
84674 --- a/init/Kconfig
84675 +++ b/init/Kconfig
84676 @@ -1093,6 +1093,7 @@ endif # CGROUPS
84677
84678 config CHECKPOINT_RESTORE
84679 bool "Checkpoint/restore support" if EXPERT
84680 + depends on !GRKERNSEC
84681 default n
84682 help
84683 Enables additional kernel features in a sake of checkpoint/restore.
84684 @@ -1570,7 +1571,7 @@ config SLUB_DEBUG
84685
84686 config COMPAT_BRK
84687 bool "Disable heap randomization"
84688 - default y
84689 + default n
84690 help
84691 Randomizing heap placement makes heap exploits harder, but it
84692 also breaks ancient binaries (including anything libc5 based).
84693 @@ -1858,7 +1859,7 @@ config INIT_ALL_POSSIBLE
84694 config STOP_MACHINE
84695 bool
84696 default y
84697 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
84698 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
84699 help
84700 Need stop_machine() primitive.
84701
84702 diff --git a/init/Makefile b/init/Makefile
84703 index 7bc47ee..6da2dc7 100644
84704 --- a/init/Makefile
84705 +++ b/init/Makefile
84706 @@ -2,6 +2,9 @@
84707 # Makefile for the linux kernel.
84708 #
84709
84710 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
84711 +asflags-y := $(GCC_PLUGINS_AFLAGS)
84712 +
84713 obj-y := main.o version.o mounts.o
84714 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
84715 obj-y += noinitramfs.o
84716 diff --git a/init/do_mounts.c b/init/do_mounts.c
84717 index 82f2288..ea1430a 100644
84718 --- a/init/do_mounts.c
84719 +++ b/init/do_mounts.c
84720 @@ -359,11 +359,11 @@ static void __init get_fs_names(char *page)
84721 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
84722 {
84723 struct super_block *s;
84724 - int err = sys_mount(name, "/root", fs, flags, data);
84725 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
84726 if (err)
84727 return err;
84728
84729 - sys_chdir("/root");
84730 + sys_chdir((const char __force_user *)"/root");
84731 s = current->fs->pwd.dentry->d_sb;
84732 ROOT_DEV = s->s_dev;
84733 printk(KERN_INFO
84734 @@ -484,18 +484,18 @@ void __init change_floppy(char *fmt, ...)
84735 va_start(args, fmt);
84736 vsprintf(buf, fmt, args);
84737 va_end(args);
84738 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
84739 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
84740 if (fd >= 0) {
84741 sys_ioctl(fd, FDEJECT, 0);
84742 sys_close(fd);
84743 }
84744 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
84745 - fd = sys_open("/dev/console", O_RDWR, 0);
84746 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
84747 if (fd >= 0) {
84748 sys_ioctl(fd, TCGETS, (long)&termios);
84749 termios.c_lflag &= ~ICANON;
84750 sys_ioctl(fd, TCSETSF, (long)&termios);
84751 - sys_read(fd, &c, 1);
84752 + sys_read(fd, (char __user *)&c, 1);
84753 termios.c_lflag |= ICANON;
84754 sys_ioctl(fd, TCSETSF, (long)&termios);
84755 sys_close(fd);
84756 @@ -589,8 +589,8 @@ void __init prepare_namespace(void)
84757 mount_root();
84758 out:
84759 devtmpfs_mount("dev");
84760 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
84761 - sys_chroot(".");
84762 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
84763 + sys_chroot((const char __force_user *)".");
84764 }
84765
84766 static bool is_tmpfs;
84767 diff --git a/init/do_mounts.h b/init/do_mounts.h
84768 index f5b978a..69dbfe8 100644
84769 --- a/init/do_mounts.h
84770 +++ b/init/do_mounts.h
84771 @@ -15,15 +15,15 @@ extern int root_mountflags;
84772
84773 static inline int create_dev(char *name, dev_t dev)
84774 {
84775 - sys_unlink(name);
84776 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
84777 + sys_unlink((char __force_user *)name);
84778 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
84779 }
84780
84781 #if BITS_PER_LONG == 32
84782 static inline u32 bstat(char *name)
84783 {
84784 struct stat64 stat;
84785 - if (sys_stat64(name, &stat) != 0)
84786 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
84787 return 0;
84788 if (!S_ISBLK(stat.st_mode))
84789 return 0;
84790 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
84791 static inline u32 bstat(char *name)
84792 {
84793 struct stat stat;
84794 - if (sys_newstat(name, &stat) != 0)
84795 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
84796 return 0;
84797 if (!S_ISBLK(stat.st_mode))
84798 return 0;
84799 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
84800 index 3e0878e..8a9d7a0 100644
84801 --- a/init/do_mounts_initrd.c
84802 +++ b/init/do_mounts_initrd.c
84803 @@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
84804 {
84805 sys_unshare(CLONE_FS | CLONE_FILES);
84806 /* stdin/stdout/stderr for /linuxrc */
84807 - sys_open("/dev/console", O_RDWR, 0);
84808 + sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
84809 sys_dup(0);
84810 sys_dup(0);
84811 /* move initrd over / and chdir/chroot in initrd root */
84812 - sys_chdir("/root");
84813 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
84814 - sys_chroot(".");
84815 + sys_chdir((const char __force_user *)"/root");
84816 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
84817 + sys_chroot((const char __force_user *)".");
84818 sys_setsid();
84819 return 0;
84820 }
84821 @@ -59,8 +59,8 @@ static void __init handle_initrd(void)
84822 create_dev("/dev/root.old", Root_RAM0);
84823 /* mount initrd on rootfs' /root */
84824 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
84825 - sys_mkdir("/old", 0700);
84826 - sys_chdir("/old");
84827 + sys_mkdir((const char __force_user *)"/old", 0700);
84828 + sys_chdir((const char __force_user *)"/old");
84829
84830 /* try loading default modules from initrd */
84831 load_default_modules();
84832 @@ -80,31 +80,31 @@ static void __init handle_initrd(void)
84833 current->flags &= ~PF_FREEZER_SKIP;
84834
84835 /* move initrd to rootfs' /old */
84836 - sys_mount("..", ".", NULL, MS_MOVE, NULL);
84837 + sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
84838 /* switch root and cwd back to / of rootfs */
84839 - sys_chroot("..");
84840 + sys_chroot((const char __force_user *)"..");
84841
84842 if (new_decode_dev(real_root_dev) == Root_RAM0) {
84843 - sys_chdir("/old");
84844 + sys_chdir((const char __force_user *)"/old");
84845 return;
84846 }
84847
84848 - sys_chdir("/");
84849 + sys_chdir((const char __force_user *)"/");
84850 ROOT_DEV = new_decode_dev(real_root_dev);
84851 mount_root();
84852
84853 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
84854 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
84855 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
84856 if (!error)
84857 printk("okay\n");
84858 else {
84859 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
84860 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
84861 if (error == -ENOENT)
84862 printk("/initrd does not exist. Ignored.\n");
84863 else
84864 printk("failed\n");
84865 printk(KERN_NOTICE "Unmounting old root\n");
84866 - sys_umount("/old", MNT_DETACH);
84867 + sys_umount((char __force_user *)"/old", MNT_DETACH);
84868 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
84869 if (fd < 0) {
84870 error = fd;
84871 @@ -127,11 +127,11 @@ int __init initrd_load(void)
84872 * mounted in the normal path.
84873 */
84874 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
84875 - sys_unlink("/initrd.image");
84876 + sys_unlink((const char __force_user *)"/initrd.image");
84877 handle_initrd();
84878 return 1;
84879 }
84880 }
84881 - sys_unlink("/initrd.image");
84882 + sys_unlink((const char __force_user *)"/initrd.image");
84883 return 0;
84884 }
84885 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
84886 index 8cb6db5..d729f50 100644
84887 --- a/init/do_mounts_md.c
84888 +++ b/init/do_mounts_md.c
84889 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
84890 partitioned ? "_d" : "", minor,
84891 md_setup_args[ent].device_names);
84892
84893 - fd = sys_open(name, 0, 0);
84894 + fd = sys_open((char __force_user *)name, 0, 0);
84895 if (fd < 0) {
84896 printk(KERN_ERR "md: open failed - cannot start "
84897 "array %s\n", name);
84898 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
84899 * array without it
84900 */
84901 sys_close(fd);
84902 - fd = sys_open(name, 0, 0);
84903 + fd = sys_open((char __force_user *)name, 0, 0);
84904 sys_ioctl(fd, BLKRRPART, 0);
84905 }
84906 sys_close(fd);
84907 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
84908
84909 wait_for_device_probe();
84910
84911 - fd = sys_open("/dev/md0", 0, 0);
84912 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
84913 if (fd >= 0) {
84914 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
84915 sys_close(fd);
84916 diff --git a/init/init_task.c b/init/init_task.c
84917 index ba0a7f36..2bcf1d5 100644
84918 --- a/init/init_task.c
84919 +++ b/init/init_task.c
84920 @@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
84921 * Initial thread structure. Alignment of this is handled by a special
84922 * linker map entry.
84923 */
84924 +#ifdef CONFIG_X86
84925 +union thread_union init_thread_union __init_task_data;
84926 +#else
84927 union thread_union init_thread_union __init_task_data =
84928 { INIT_THREAD_INFO(init_task) };
84929 +#endif
84930 diff --git a/init/initramfs.c b/init/initramfs.c
84931 index a8497fa..35b3c90 100644
84932 --- a/init/initramfs.c
84933 +++ b/init/initramfs.c
84934 @@ -84,7 +84,7 @@ static void __init free_hash(void)
84935 }
84936 }
84937
84938 -static long __init do_utime(char *filename, time_t mtime)
84939 +static long __init do_utime(char __force_user *filename, time_t mtime)
84940 {
84941 struct timespec t[2];
84942
84943 @@ -119,7 +119,7 @@ static void __init dir_utime(void)
84944 struct dir_entry *de, *tmp;
84945 list_for_each_entry_safe(de, tmp, &dir_list, list) {
84946 list_del(&de->list);
84947 - do_utime(de->name, de->mtime);
84948 + do_utime((char __force_user *)de->name, de->mtime);
84949 kfree(de->name);
84950 kfree(de);
84951 }
84952 @@ -281,7 +281,7 @@ static int __init maybe_link(void)
84953 if (nlink >= 2) {
84954 char *old = find_link(major, minor, ino, mode, collected);
84955 if (old)
84956 - return (sys_link(old, collected) < 0) ? -1 : 1;
84957 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
84958 }
84959 return 0;
84960 }
84961 @@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
84962 {
84963 struct stat st;
84964
84965 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
84966 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
84967 if (S_ISDIR(st.st_mode))
84968 - sys_rmdir(path);
84969 + sys_rmdir((char __force_user *)path);
84970 else
84971 - sys_unlink(path);
84972 + sys_unlink((char __force_user *)path);
84973 }
84974 }
84975
84976 @@ -315,7 +315,7 @@ static int __init do_name(void)
84977 int openflags = O_WRONLY|O_CREAT;
84978 if (ml != 1)
84979 openflags |= O_TRUNC;
84980 - wfd = sys_open(collected, openflags, mode);
84981 + wfd = sys_open((char __force_user *)collected, openflags, mode);
84982
84983 if (wfd >= 0) {
84984 sys_fchown(wfd, uid, gid);
84985 @@ -327,17 +327,17 @@ static int __init do_name(void)
84986 }
84987 }
84988 } else if (S_ISDIR(mode)) {
84989 - sys_mkdir(collected, mode);
84990 - sys_chown(collected, uid, gid);
84991 - sys_chmod(collected, mode);
84992 + sys_mkdir((char __force_user *)collected, mode);
84993 + sys_chown((char __force_user *)collected, uid, gid);
84994 + sys_chmod((char __force_user *)collected, mode);
84995 dir_add(collected, mtime);
84996 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
84997 S_ISFIFO(mode) || S_ISSOCK(mode)) {
84998 if (maybe_link() == 0) {
84999 - sys_mknod(collected, mode, rdev);
85000 - sys_chown(collected, uid, gid);
85001 - sys_chmod(collected, mode);
85002 - do_utime(collected, mtime);
85003 + sys_mknod((char __force_user *)collected, mode, rdev);
85004 + sys_chown((char __force_user *)collected, uid, gid);
85005 + sys_chmod((char __force_user *)collected, mode);
85006 + do_utime((char __force_user *)collected, mtime);
85007 }
85008 }
85009 return 0;
85010 @@ -346,15 +346,15 @@ static int __init do_name(void)
85011 static int __init do_copy(void)
85012 {
85013 if (count >= body_len) {
85014 - sys_write(wfd, victim, body_len);
85015 + sys_write(wfd, (char __force_user *)victim, body_len);
85016 sys_close(wfd);
85017 - do_utime(vcollected, mtime);
85018 + do_utime((char __force_user *)vcollected, mtime);
85019 kfree(vcollected);
85020 eat(body_len);
85021 state = SkipIt;
85022 return 0;
85023 } else {
85024 - sys_write(wfd, victim, count);
85025 + sys_write(wfd, (char __force_user *)victim, count);
85026 body_len -= count;
85027 eat(count);
85028 return 1;
85029 @@ -365,9 +365,9 @@ static int __init do_symlink(void)
85030 {
85031 collected[N_ALIGN(name_len) + body_len] = '\0';
85032 clean_path(collected, 0);
85033 - sys_symlink(collected + N_ALIGN(name_len), collected);
85034 - sys_lchown(collected, uid, gid);
85035 - do_utime(collected, mtime);
85036 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
85037 + sys_lchown((char __force_user *)collected, uid, gid);
85038 + do_utime((char __force_user *)collected, mtime);
85039 state = SkipIt;
85040 next_state = Reset;
85041 return 0;
85042 diff --git a/init/main.c b/init/main.c
85043 index 48655ce..d0113e4 100644
85044 --- a/init/main.c
85045 +++ b/init/main.c
85046 @@ -97,6 +97,8 @@ extern void radix_tree_init(void);
85047 static inline void mark_rodata_ro(void) { }
85048 #endif
85049
85050 +extern void grsecurity_init(void);
85051 +
85052 /*
85053 * Debug helper: via this flag we know that we are in 'early bootup code'
85054 * where only the boot processor is running with IRQ disabled. This means
85055 @@ -158,6 +160,75 @@ static int __init set_reset_devices(char *str)
85056
85057 __setup("reset_devices", set_reset_devices);
85058
85059 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
85060 +kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
85061 +static int __init setup_grsec_proc_gid(char *str)
85062 +{
85063 + grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
85064 + return 1;
85065 +}
85066 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
85067 +#endif
85068 +
85069 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
85070 +unsigned long pax_user_shadow_base __read_only;
85071 +EXPORT_SYMBOL(pax_user_shadow_base);
85072 +extern char pax_enter_kernel_user[];
85073 +extern char pax_exit_kernel_user[];
85074 +#endif
85075 +
85076 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
85077 +static int __init setup_pax_nouderef(char *str)
85078 +{
85079 +#ifdef CONFIG_X86_32
85080 + unsigned int cpu;
85081 + struct desc_struct *gdt;
85082 +
85083 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
85084 + gdt = get_cpu_gdt_table(cpu);
85085 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
85086 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
85087 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
85088 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
85089 + }
85090 + loadsegment(ds, __KERNEL_DS);
85091 + loadsegment(es, __KERNEL_DS);
85092 + loadsegment(ss, __KERNEL_DS);
85093 +#else
85094 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
85095 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
85096 + clone_pgd_mask = ~(pgdval_t)0UL;
85097 + pax_user_shadow_base = 0UL;
85098 + setup_clear_cpu_cap(X86_FEATURE_PCID);
85099 + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
85100 +#endif
85101 +
85102 + return 0;
85103 +}
85104 +early_param("pax_nouderef", setup_pax_nouderef);
85105 +
85106 +#ifdef CONFIG_X86_64
85107 +static int __init setup_pax_weakuderef(char *str)
85108 +{
85109 + if (clone_pgd_mask != ~(pgdval_t)0UL)
85110 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
85111 + return 1;
85112 +}
85113 +__setup("pax_weakuderef", setup_pax_weakuderef);
85114 +#endif
85115 +#endif
85116 +
85117 +#ifdef CONFIG_PAX_SOFTMODE
85118 +int pax_softmode;
85119 +
85120 +static int __init setup_pax_softmode(char *str)
85121 +{
85122 + get_option(&str, &pax_softmode);
85123 + return 1;
85124 +}
85125 +__setup("pax_softmode=", setup_pax_softmode);
85126 +#endif
85127 +
85128 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
85129 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
85130 static const char *panic_later, *panic_param;
85131 @@ -688,25 +759,24 @@ int __init_or_module do_one_initcall(initcall_t fn)
85132 {
85133 int count = preempt_count();
85134 int ret;
85135 - char msgbuf[64];
85136 + const char *msg1 = "", *msg2 = "";
85137
85138 if (initcall_debug)
85139 ret = do_one_initcall_debug(fn);
85140 else
85141 ret = fn();
85142
85143 - msgbuf[0] = 0;
85144 -
85145 if (preempt_count() != count) {
85146 - sprintf(msgbuf, "preemption imbalance ");
85147 + msg1 = " preemption imbalance";
85148 preempt_count_set(count);
85149 }
85150 if (irqs_disabled()) {
85151 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
85152 + msg2 = " disabled interrupts";
85153 local_irq_enable();
85154 }
85155 - WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
85156 + WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
85157
85158 + add_latent_entropy();
85159 return ret;
85160 }
85161
85162 @@ -813,8 +883,8 @@ static int run_init_process(const char *init_filename)
85163 {
85164 argv_init[0] = init_filename;
85165 return do_execve(getname_kernel(init_filename),
85166 - (const char __user *const __user *)argv_init,
85167 - (const char __user *const __user *)envp_init);
85168 + (const char __user *const __force_user *)argv_init,
85169 + (const char __user *const __force_user *)envp_init);
85170 }
85171
85172 static int try_to_run_init_process(const char *init_filename)
85173 @@ -831,6 +901,10 @@ static int try_to_run_init_process(const char *init_filename)
85174 return ret;
85175 }
85176
85177 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
85178 +extern int gr_init_ran;
85179 +#endif
85180 +
85181 static noinline void __init kernel_init_freeable(void);
85182
85183 static int __ref kernel_init(void *unused)
85184 @@ -855,6 +929,11 @@ static int __ref kernel_init(void *unused)
85185 ramdisk_execute_command, ret);
85186 }
85187
85188 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
85189 + /* if no initrd was used, be extra sure we enforce chroot restrictions */
85190 + gr_init_ran = 1;
85191 +#endif
85192 +
85193 /*
85194 * We try each of these until one succeeds.
85195 *
85196 @@ -910,7 +989,7 @@ static noinline void __init kernel_init_freeable(void)
85197 do_basic_setup();
85198
85199 /* Open the /dev/console on the rootfs, this should never fail */
85200 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
85201 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
85202 pr_err("Warning: unable to open an initial console.\n");
85203
85204 (void) sys_dup(0);
85205 @@ -923,11 +1002,13 @@ static noinline void __init kernel_init_freeable(void)
85206 if (!ramdisk_execute_command)
85207 ramdisk_execute_command = "/init";
85208
85209 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
85210 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
85211 ramdisk_execute_command = NULL;
85212 prepare_namespace();
85213 }
85214
85215 + grsecurity_init();
85216 +
85217 /*
85218 * Ok, we have completed the initial bootup, and
85219 * we're essentially up and running. Get rid of the
85220 diff --git a/ipc/compat.c b/ipc/compat.c
85221 index 45d035d..e4a7f99 100644
85222 --- a/ipc/compat.c
85223 +++ b/ipc/compat.c
85224 @@ -396,7 +396,7 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
85225 COMPAT_SHMLBA);
85226 if (err < 0)
85227 return err;
85228 - return put_user(raddr, (compat_ulong_t *)compat_ptr(third));
85229 + return put_user(raddr, (compat_ulong_t __user *)compat_ptr(third));
85230 }
85231 case SHMDT:
85232 return sys_shmdt(compat_ptr(ptr));
85233 diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
85234 index 998d31b..30c24df 100644
85235 --- a/ipc/ipc_sysctl.c
85236 +++ b/ipc/ipc_sysctl.c
85237 @@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
85238 static int proc_ipc_dointvec(ctl_table *table, int write,
85239 void __user *buffer, size_t *lenp, loff_t *ppos)
85240 {
85241 - struct ctl_table ipc_table;
85242 + ctl_table_no_const ipc_table;
85243
85244 memcpy(&ipc_table, table, sizeof(ipc_table));
85245 ipc_table.data = get_ipc(table);
85246 @@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
85247 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
85248 void __user *buffer, size_t *lenp, loff_t *ppos)
85249 {
85250 - struct ctl_table ipc_table;
85251 + ctl_table_no_const ipc_table;
85252
85253 memcpy(&ipc_table, table, sizeof(ipc_table));
85254 ipc_table.data = get_ipc(table);
85255 @@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
85256 static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
85257 void __user *buffer, size_t *lenp, loff_t *ppos)
85258 {
85259 - struct ctl_table ipc_table;
85260 + ctl_table_no_const ipc_table;
85261 size_t lenp_bef = *lenp;
85262 int rc;
85263
85264 @@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
85265 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
85266 void __user *buffer, size_t *lenp, loff_t *ppos)
85267 {
85268 - struct ctl_table ipc_table;
85269 + ctl_table_no_const ipc_table;
85270 memcpy(&ipc_table, table, sizeof(ipc_table));
85271 ipc_table.data = get_ipc(table);
85272
85273 @@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
85274 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
85275 void __user *buffer, size_t *lenp, loff_t *ppos)
85276 {
85277 - struct ctl_table ipc_table;
85278 + ctl_table_no_const ipc_table;
85279 size_t lenp_bef = *lenp;
85280 int oldval;
85281 int rc;
85282 diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
85283 index 5bb8bfe..a38ec05 100644
85284 --- a/ipc/mq_sysctl.c
85285 +++ b/ipc/mq_sysctl.c
85286 @@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
85287 static int proc_mq_dointvec(ctl_table *table, int write,
85288 void __user *buffer, size_t *lenp, loff_t *ppos)
85289 {
85290 - struct ctl_table mq_table;
85291 + ctl_table_no_const mq_table;
85292 memcpy(&mq_table, table, sizeof(mq_table));
85293 mq_table.data = get_mq(table);
85294
85295 @@ -35,7 +35,7 @@ static int proc_mq_dointvec(ctl_table *table, int write,
85296 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
85297 void __user *buffer, size_t *lenp, loff_t *ppos)
85298 {
85299 - struct ctl_table mq_table;
85300 + ctl_table_no_const mq_table;
85301 memcpy(&mq_table, table, sizeof(mq_table));
85302 mq_table.data = get_mq(table);
85303
85304 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
85305 index 4fcf39a..d3cc2ec 100644
85306 --- a/ipc/mqueue.c
85307 +++ b/ipc/mqueue.c
85308 @@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
85309 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
85310 info->attr.mq_msgsize);
85311
85312 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
85313 spin_lock(&mq_lock);
85314 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
85315 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
85316 diff --git a/ipc/msg.c b/ipc/msg.c
85317 index 6498531..b0ff3c8 100644
85318 --- a/ipc/msg.c
85319 +++ b/ipc/msg.c
85320 @@ -303,18 +303,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
85321 return security_msg_queue_associate(msq, msgflg);
85322 }
85323
85324 +static struct ipc_ops msg_ops = {
85325 + .getnew = newque,
85326 + .associate = msg_security,
85327 + .more_checks = NULL
85328 +};
85329 +
85330 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
85331 {
85332 struct ipc_namespace *ns;
85333 - struct ipc_ops msg_ops;
85334 struct ipc_params msg_params;
85335
85336 ns = current->nsproxy->ipc_ns;
85337
85338 - msg_ops.getnew = newque;
85339 - msg_ops.associate = msg_security;
85340 - msg_ops.more_checks = NULL;
85341 -
85342 msg_params.key = key;
85343 msg_params.flg = msgflg;
85344
85345 diff --git a/ipc/sem.c b/ipc/sem.c
85346 index bee5554..e9af81dd 100644
85347 --- a/ipc/sem.c
85348 +++ b/ipc/sem.c
85349 @@ -561,10 +561,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
85350 return 0;
85351 }
85352
85353 +static struct ipc_ops sem_ops = {
85354 + .getnew = newary,
85355 + .associate = sem_security,
85356 + .more_checks = sem_more_checks
85357 +};
85358 +
85359 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
85360 {
85361 struct ipc_namespace *ns;
85362 - struct ipc_ops sem_ops;
85363 struct ipc_params sem_params;
85364
85365 ns = current->nsproxy->ipc_ns;
85366 @@ -572,10 +577,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
85367 if (nsems < 0 || nsems > ns->sc_semmsl)
85368 return -EINVAL;
85369
85370 - sem_ops.getnew = newary;
85371 - sem_ops.associate = sem_security;
85372 - sem_ops.more_checks = sem_more_checks;
85373 -
85374 sem_params.key = key;
85375 sem_params.flg = semflg;
85376 sem_params.u.nsems = nsems;
85377 diff --git a/ipc/shm.c b/ipc/shm.c
85378 index 7645961..afc7f02 100644
85379 --- a/ipc/shm.c
85380 +++ b/ipc/shm.c
85381 @@ -72,6 +72,14 @@ static void shm_destroy(struct ipc_namespace *ns, struct shmid_kernel *shp);
85382 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
85383 #endif
85384
85385 +#ifdef CONFIG_GRKERNSEC
85386 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
85387 + const time_t shm_createtime, const kuid_t cuid,
85388 + const int shmid);
85389 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
85390 + const time_t shm_createtime);
85391 +#endif
85392 +
85393 void shm_init_ns(struct ipc_namespace *ns)
85394 {
85395 ns->shm_ctlmax = SHMMAX;
85396 @@ -553,6 +561,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
85397 shp->shm_lprid = 0;
85398 shp->shm_atim = shp->shm_dtim = 0;
85399 shp->shm_ctim = get_seconds();
85400 +#ifdef CONFIG_GRKERNSEC
85401 + {
85402 + struct timespec timeval;
85403 + do_posix_clock_monotonic_gettime(&timeval);
85404 +
85405 + shp->shm_createtime = timeval.tv_sec;
85406 + }
85407 +#endif
85408 shp->shm_segsz = size;
85409 shp->shm_nattch = 0;
85410 shp->shm_file = file;
85411 @@ -606,18 +622,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
85412 return 0;
85413 }
85414
85415 +static struct ipc_ops shm_ops = {
85416 + .getnew = newseg,
85417 + .associate = shm_security,
85418 + .more_checks = shm_more_checks
85419 +};
85420 +
85421 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
85422 {
85423 struct ipc_namespace *ns;
85424 - struct ipc_ops shm_ops;
85425 struct ipc_params shm_params;
85426
85427 ns = current->nsproxy->ipc_ns;
85428
85429 - shm_ops.getnew = newseg;
85430 - shm_ops.associate = shm_security;
85431 - shm_ops.more_checks = shm_more_checks;
85432 -
85433 shm_params.key = key;
85434 shm_params.flg = shmflg;
85435 shm_params.u.size = size;
85436 @@ -1088,6 +1105,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
85437 f_mode = FMODE_READ | FMODE_WRITE;
85438 }
85439 if (shmflg & SHM_EXEC) {
85440 +
85441 +#ifdef CONFIG_PAX_MPROTECT
85442 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
85443 + goto out;
85444 +#endif
85445 +
85446 prot |= PROT_EXEC;
85447 acc_mode |= S_IXUGO;
85448 }
85449 @@ -1112,6 +1135,15 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
85450 if (err)
85451 goto out_unlock;
85452
85453 +#ifdef CONFIG_GRKERNSEC
85454 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
85455 + shp->shm_perm.cuid, shmid) ||
85456 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
85457 + err = -EACCES;
85458 + goto out_unlock;
85459 + }
85460 +#endif
85461 +
85462 ipc_lock_object(&shp->shm_perm);
85463
85464 /* check if shm_destroy() is tearing down shp */
85465 @@ -1124,6 +1156,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
85466 path = shp->shm_file->f_path;
85467 path_get(&path);
85468 shp->shm_nattch++;
85469 +#ifdef CONFIG_GRKERNSEC
85470 + shp->shm_lapid = current->pid;
85471 +#endif
85472 size = i_size_read(path.dentry->d_inode);
85473 ipc_unlock_object(&shp->shm_perm);
85474 rcu_read_unlock();
85475 diff --git a/ipc/util.c b/ipc/util.c
85476 index 2eb0d1e..0308564 100644
85477 --- a/ipc/util.c
85478 +++ b/ipc/util.c
85479 @@ -71,6 +71,8 @@ struct ipc_proc_iface {
85480 int (*show)(struct seq_file *, void *);
85481 };
85482
85483 +extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
85484 +
85485 static void ipc_memory_notifier(struct work_struct *work)
85486 {
85487 ipcns_notify(IPCNS_MEMCHANGED);
85488 @@ -537,6 +539,10 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
85489 granted_mode >>= 6;
85490 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
85491 granted_mode >>= 3;
85492 +
85493 + if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
85494 + return -1;
85495 +
85496 /* is there some bit set in requested_mode but not in granted_mode? */
85497 if ((requested_mode & ~granted_mode & 0007) &&
85498 !ns_capable(ns->user_ns, CAP_IPC_OWNER))
85499 diff --git a/kernel/acct.c b/kernel/acct.c
85500 index 8d6e145..33e0b1e 100644
85501 --- a/kernel/acct.c
85502 +++ b/kernel/acct.c
85503 @@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
85504 */
85505 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
85506 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
85507 - file->f_op->write(file, (char *)&ac,
85508 + file->f_op->write(file, (char __force_user *)&ac,
85509 sizeof(acct_t), &file->f_pos);
85510 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
85511 set_fs(fs);
85512 diff --git a/kernel/audit.c b/kernel/audit.c
85513 index 47845c5..bd9dd5b 100644
85514 --- a/kernel/audit.c
85515 +++ b/kernel/audit.c
85516 @@ -122,7 +122,7 @@ u32 audit_sig_sid = 0;
85517 3) suppressed due to audit_rate_limit
85518 4) suppressed due to audit_backlog_limit
85519 */
85520 -static atomic_t audit_lost = ATOMIC_INIT(0);
85521 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
85522
85523 /* The netlink socket. */
85524 static struct sock *audit_sock;
85525 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
85526 unsigned long now;
85527 int print;
85528
85529 - atomic_inc(&audit_lost);
85530 + atomic_inc_unchecked(&audit_lost);
85531
85532 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
85533
85534 @@ -273,7 +273,7 @@ void audit_log_lost(const char *message)
85535 if (print) {
85536 if (printk_ratelimit())
85537 pr_warn("audit_lost=%u audit_rate_limit=%u audit_backlog_limit=%u\n",
85538 - atomic_read(&audit_lost),
85539 + atomic_read_unchecked(&audit_lost),
85540 audit_rate_limit,
85541 audit_backlog_limit);
85542 audit_panic(message);
85543 @@ -808,7 +808,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
85544 s.pid = audit_pid;
85545 s.rate_limit = audit_rate_limit;
85546 s.backlog_limit = audit_backlog_limit;
85547 - s.lost = atomic_read(&audit_lost);
85548 + s.lost = atomic_read_unchecked(&audit_lost);
85549 s.backlog = skb_queue_len(&audit_skb_queue);
85550 s.version = AUDIT_VERSION_LATEST;
85551 s.backlog_wait_time = audit_backlog_wait_time;
85552 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
85553 index 21eae3c..66db239 100644
85554 --- a/kernel/auditsc.c
85555 +++ b/kernel/auditsc.c
85556 @@ -2023,7 +2023,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
85557 }
85558
85559 /* global counter which is incremented every time something logs in */
85560 -static atomic_t session_id = ATOMIC_INIT(0);
85561 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
85562
85563 static int audit_set_loginuid_perm(kuid_t loginuid)
85564 {
85565 @@ -2090,7 +2090,7 @@ int audit_set_loginuid(kuid_t loginuid)
85566
85567 /* are we setting or clearing? */
85568 if (uid_valid(loginuid))
85569 - sessionid = (unsigned int)atomic_inc_return(&session_id);
85570 + sessionid = (unsigned int)atomic_inc_return_unchecked(&session_id);
85571
85572 task->sessionid = sessionid;
85573 task->loginuid = loginuid;
85574 diff --git a/kernel/capability.c b/kernel/capability.c
85575 index 24663b3..b926ae1 100644
85576 --- a/kernel/capability.c
85577 +++ b/kernel/capability.c
85578 @@ -193,6 +193,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
85579 * before modification is attempted and the application
85580 * fails.
85581 */
85582 + if (tocopy > ARRAY_SIZE(kdata))
85583 + return -EFAULT;
85584 +
85585 if (copy_to_user(dataptr, kdata, tocopy
85586 * sizeof(struct __user_cap_data_struct))) {
85587 return -EFAULT;
85588 @@ -294,10 +297,11 @@ bool has_ns_capability(struct task_struct *t,
85589 int ret;
85590
85591 rcu_read_lock();
85592 - ret = security_capable(__task_cred(t), ns, cap);
85593 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
85594 + gr_task_is_capable(t, __task_cred(t), cap);
85595 rcu_read_unlock();
85596
85597 - return (ret == 0);
85598 + return ret;
85599 }
85600
85601 /**
85602 @@ -334,10 +338,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
85603 int ret;
85604
85605 rcu_read_lock();
85606 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
85607 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
85608 rcu_read_unlock();
85609
85610 - return (ret == 0);
85611 + return ret;
85612 }
85613
85614 /**
85615 @@ -375,7 +379,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
85616 BUG();
85617 }
85618
85619 - if (security_capable(current_cred(), ns, cap) == 0) {
85620 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
85621 current->flags |= PF_SUPERPRIV;
85622 return true;
85623 }
85624 @@ -383,6 +387,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
85625 }
85626 EXPORT_SYMBOL(ns_capable);
85627
85628 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
85629 +{
85630 + if (unlikely(!cap_valid(cap))) {
85631 + printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
85632 + BUG();
85633 + }
85634 +
85635 + if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
85636 + current->flags |= PF_SUPERPRIV;
85637 + return true;
85638 + }
85639 + return false;
85640 +}
85641 +EXPORT_SYMBOL(ns_capable_nolog);
85642 +
85643 /**
85644 * file_ns_capable - Determine if the file's opener had a capability in effect
85645 * @file: The file we want to check
85646 @@ -423,6 +442,12 @@ bool capable(int cap)
85647 }
85648 EXPORT_SYMBOL(capable);
85649
85650 +bool capable_nolog(int cap)
85651 +{
85652 + return ns_capable_nolog(&init_user_ns, cap);
85653 +}
85654 +EXPORT_SYMBOL(capable_nolog);
85655 +
85656 /**
85657 * capable_wrt_inode_uidgid - Check nsown_capable and uid and gid mapped
85658 * @inode: The inode in question
85659 @@ -440,3 +465,12 @@ bool capable_wrt_inode_uidgid(const struct inode *inode, int cap)
85660 kgid_has_mapping(ns, inode->i_gid);
85661 }
85662 EXPORT_SYMBOL(capable_wrt_inode_uidgid);
85663 +
85664 +bool capable_wrt_inode_uidgid_nolog(const struct inode *inode, int cap)
85665 +{
85666 + struct user_namespace *ns = current_user_ns();
85667 +
85668 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid) &&
85669 + kgid_has_mapping(ns, inode->i_gid);
85670 +}
85671 +EXPORT_SYMBOL(capable_wrt_inode_uidgid_nolog);
85672 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
85673 index ceee0c5..d6f81dd 100644
85674 --- a/kernel/cgroup.c
85675 +++ b/kernel/cgroup.c
85676 @@ -4757,7 +4757,7 @@ static int cgroup_css_links_read(struct seq_file *seq, void *v)
85677 struct task_struct *task;
85678 int count = 0;
85679
85680 - seq_printf(seq, "css_set %p\n", cset);
85681 + seq_printf(seq, "css_set %pK\n", cset);
85682
85683 list_for_each_entry(task, &cset->tasks, cg_list) {
85684 if (count++ > MAX_TASKS_SHOWN_PER_CSS)
85685 diff --git a/kernel/compat.c b/kernel/compat.c
85686 index e40b043..3da8f51 100644
85687 --- a/kernel/compat.c
85688 +++ b/kernel/compat.c
85689 @@ -13,6 +13,7 @@
85690
85691 #include <linux/linkage.h>
85692 #include <linux/compat.h>
85693 +#include <linux/module.h>
85694 #include <linux/errno.h>
85695 #include <linux/time.h>
85696 #include <linux/signal.h>
85697 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
85698 mm_segment_t oldfs;
85699 long ret;
85700
85701 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
85702 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
85703 oldfs = get_fs();
85704 set_fs(KERNEL_DS);
85705 ret = hrtimer_nanosleep_restart(restart);
85706 @@ -252,7 +253,7 @@ COMPAT_SYSCALL_DEFINE2(nanosleep, struct compat_timespec __user *, rqtp,
85707 oldfs = get_fs();
85708 set_fs(KERNEL_DS);
85709 ret = hrtimer_nanosleep(&tu,
85710 - rmtp ? (struct timespec __user *)&rmt : NULL,
85711 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
85712 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
85713 set_fs(oldfs);
85714
85715 @@ -361,7 +362,7 @@ COMPAT_SYSCALL_DEFINE1(sigpending, compat_old_sigset_t __user *, set)
85716 mm_segment_t old_fs = get_fs();
85717
85718 set_fs(KERNEL_DS);
85719 - ret = sys_sigpending((old_sigset_t __user *) &s);
85720 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
85721 set_fs(old_fs);
85722 if (ret == 0)
85723 ret = put_user(s, set);
85724 @@ -451,7 +452,7 @@ COMPAT_SYSCALL_DEFINE2(old_getrlimit, unsigned int, resource,
85725 mm_segment_t old_fs = get_fs();
85726
85727 set_fs(KERNEL_DS);
85728 - ret = sys_old_getrlimit(resource, (struct rlimit __user *)&r);
85729 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
85730 set_fs(old_fs);
85731
85732 if (!ret) {
85733 @@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
85734 set_fs (KERNEL_DS);
85735 ret = sys_wait4(pid,
85736 (stat_addr ?
85737 - (unsigned int __user *) &status : NULL),
85738 - options, (struct rusage __user *) &r);
85739 + (unsigned int __force_user *) &status : NULL),
85740 + options, (struct rusage __force_user *) &r);
85741 set_fs (old_fs);
85742
85743 if (ret > 0) {
85744 @@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
85745 memset(&info, 0, sizeof(info));
85746
85747 set_fs(KERNEL_DS);
85748 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
85749 - uru ? (struct rusage __user *)&ru : NULL);
85750 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
85751 + uru ? (struct rusage __force_user *)&ru : NULL);
85752 set_fs(old_fs);
85753
85754 if ((ret < 0) || (info.si_signo == 0))
85755 @@ -695,8 +696,8 @@ COMPAT_SYSCALL_DEFINE4(timer_settime, timer_t, timer_id, int, flags,
85756 oldfs = get_fs();
85757 set_fs(KERNEL_DS);
85758 err = sys_timer_settime(timer_id, flags,
85759 - (struct itimerspec __user *) &newts,
85760 - (struct itimerspec __user *) &oldts);
85761 + (struct itimerspec __force_user *) &newts,
85762 + (struct itimerspec __force_user *) &oldts);
85763 set_fs(oldfs);
85764 if (!err && old && put_compat_itimerspec(old, &oldts))
85765 return -EFAULT;
85766 @@ -713,7 +714,7 @@ COMPAT_SYSCALL_DEFINE2(timer_gettime, timer_t, timer_id,
85767 oldfs = get_fs();
85768 set_fs(KERNEL_DS);
85769 err = sys_timer_gettime(timer_id,
85770 - (struct itimerspec __user *) &ts);
85771 + (struct itimerspec __force_user *) &ts);
85772 set_fs(oldfs);
85773 if (!err && put_compat_itimerspec(setting, &ts))
85774 return -EFAULT;
85775 @@ -732,7 +733,7 @@ COMPAT_SYSCALL_DEFINE2(clock_settime, clockid_t, which_clock,
85776 oldfs = get_fs();
85777 set_fs(KERNEL_DS);
85778 err = sys_clock_settime(which_clock,
85779 - (struct timespec __user *) &ts);
85780 + (struct timespec __force_user *) &ts);
85781 set_fs(oldfs);
85782 return err;
85783 }
85784 @@ -747,7 +748,7 @@ COMPAT_SYSCALL_DEFINE2(clock_gettime, clockid_t, which_clock,
85785 oldfs = get_fs();
85786 set_fs(KERNEL_DS);
85787 err = sys_clock_gettime(which_clock,
85788 - (struct timespec __user *) &ts);
85789 + (struct timespec __force_user *) &ts);
85790 set_fs(oldfs);
85791 if (!err && compat_put_timespec(&ts, tp))
85792 return -EFAULT;
85793 @@ -767,7 +768,7 @@ COMPAT_SYSCALL_DEFINE2(clock_adjtime, clockid_t, which_clock,
85794
85795 oldfs = get_fs();
85796 set_fs(KERNEL_DS);
85797 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
85798 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
85799 set_fs(oldfs);
85800
85801 err = compat_put_timex(utp, &txc);
85802 @@ -787,7 +788,7 @@ COMPAT_SYSCALL_DEFINE2(clock_getres, clockid_t, which_clock,
85803 oldfs = get_fs();
85804 set_fs(KERNEL_DS);
85805 err = sys_clock_getres(which_clock,
85806 - (struct timespec __user *) &ts);
85807 + (struct timespec __force_user *) &ts);
85808 set_fs(oldfs);
85809 if (!err && tp && compat_put_timespec(&ts, tp))
85810 return -EFAULT;
85811 @@ -801,7 +802,7 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
85812 struct timespec tu;
85813 struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
85814
85815 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
85816 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
85817 oldfs = get_fs();
85818 set_fs(KERNEL_DS);
85819 err = clock_nanosleep_restart(restart);
85820 @@ -833,8 +834,8 @@ COMPAT_SYSCALL_DEFINE4(clock_nanosleep, clockid_t, which_clock, int, flags,
85821 oldfs = get_fs();
85822 set_fs(KERNEL_DS);
85823 err = sys_clock_nanosleep(which_clock, flags,
85824 - (struct timespec __user *) &in,
85825 - (struct timespec __user *) &out);
85826 + (struct timespec __force_user *) &in,
85827 + (struct timespec __force_user *) &out);
85828 set_fs(oldfs);
85829
85830 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
85831 @@ -1128,7 +1129,7 @@ COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
85832 mm_segment_t old_fs = get_fs();
85833
85834 set_fs(KERNEL_DS);
85835 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
85836 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
85837 set_fs(old_fs);
85838 if (compat_put_timespec(&t, interval))
85839 return -EFAULT;
85840 diff --git a/kernel/configs.c b/kernel/configs.c
85841 index c18b1f1..b9a0132 100644
85842 --- a/kernel/configs.c
85843 +++ b/kernel/configs.c
85844 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
85845 struct proc_dir_entry *entry;
85846
85847 /* create the current config file */
85848 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
85849 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
85850 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
85851 + &ikconfig_file_ops);
85852 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
85853 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
85854 + &ikconfig_file_ops);
85855 +#endif
85856 +#else
85857 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
85858 &ikconfig_file_ops);
85859 +#endif
85860 +
85861 if (!entry)
85862 return -ENOMEM;
85863
85864 diff --git a/kernel/cred.c b/kernel/cred.c
85865 index e0573a4..26c0fd3 100644
85866 --- a/kernel/cred.c
85867 +++ b/kernel/cred.c
85868 @@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
85869 validate_creds(cred);
85870 alter_cred_subscribers(cred, -1);
85871 put_cred(cred);
85872 +
85873 +#ifdef CONFIG_GRKERNSEC_SETXID
85874 + cred = (struct cred *) tsk->delayed_cred;
85875 + if (cred != NULL) {
85876 + tsk->delayed_cred = NULL;
85877 + validate_creds(cred);
85878 + alter_cred_subscribers(cred, -1);
85879 + put_cred(cred);
85880 + }
85881 +#endif
85882 }
85883
85884 /**
85885 @@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
85886 * Always returns 0 thus allowing this function to be tail-called at the end
85887 * of, say, sys_setgid().
85888 */
85889 -int commit_creds(struct cred *new)
85890 +static int __commit_creds(struct cred *new)
85891 {
85892 struct task_struct *task = current;
85893 const struct cred *old = task->real_cred;
85894 @@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
85895
85896 get_cred(new); /* we will require a ref for the subj creds too */
85897
85898 + gr_set_role_label(task, new->uid, new->gid);
85899 +
85900 /* dumpability changes */
85901 if (!uid_eq(old->euid, new->euid) ||
85902 !gid_eq(old->egid, new->egid) ||
85903 @@ -479,6 +491,105 @@ int commit_creds(struct cred *new)
85904 put_cred(old);
85905 return 0;
85906 }
85907 +#ifdef CONFIG_GRKERNSEC_SETXID
85908 +extern int set_user(struct cred *new);
85909 +
85910 +void gr_delayed_cred_worker(void)
85911 +{
85912 + const struct cred *new = current->delayed_cred;
85913 + struct cred *ncred;
85914 +
85915 + current->delayed_cred = NULL;
85916 +
85917 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
85918 + // from doing get_cred on it when queueing this
85919 + put_cred(new);
85920 + return;
85921 + } else if (new == NULL)
85922 + return;
85923 +
85924 + ncred = prepare_creds();
85925 + if (!ncred)
85926 + goto die;
85927 + // uids
85928 + ncred->uid = new->uid;
85929 + ncred->euid = new->euid;
85930 + ncred->suid = new->suid;
85931 + ncred->fsuid = new->fsuid;
85932 + // gids
85933 + ncred->gid = new->gid;
85934 + ncred->egid = new->egid;
85935 + ncred->sgid = new->sgid;
85936 + ncred->fsgid = new->fsgid;
85937 + // groups
85938 + set_groups(ncred, new->group_info);
85939 + // caps
85940 + ncred->securebits = new->securebits;
85941 + ncred->cap_inheritable = new->cap_inheritable;
85942 + ncred->cap_permitted = new->cap_permitted;
85943 + ncred->cap_effective = new->cap_effective;
85944 + ncred->cap_bset = new->cap_bset;
85945 +
85946 + if (set_user(ncred)) {
85947 + abort_creds(ncred);
85948 + goto die;
85949 + }
85950 +
85951 + // from doing get_cred on it when queueing this
85952 + put_cred(new);
85953 +
85954 + __commit_creds(ncred);
85955 + return;
85956 +die:
85957 + // from doing get_cred on it when queueing this
85958 + put_cred(new);
85959 + do_group_exit(SIGKILL);
85960 +}
85961 +#endif
85962 +
85963 +int commit_creds(struct cred *new)
85964 +{
85965 +#ifdef CONFIG_GRKERNSEC_SETXID
85966 + int ret;
85967 + int schedule_it = 0;
85968 + struct task_struct *t;
85969 + unsigned oldsecurebits = current_cred()->securebits;
85970 +
85971 + /* we won't get called with tasklist_lock held for writing
85972 + and interrupts disabled as the cred struct in that case is
85973 + init_cred
85974 + */
85975 + if (grsec_enable_setxid && !current_is_single_threaded() &&
85976 + uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
85977 + !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
85978 + schedule_it = 1;
85979 + }
85980 + ret = __commit_creds(new);
85981 + if (schedule_it) {
85982 + rcu_read_lock();
85983 + read_lock(&tasklist_lock);
85984 + for (t = next_thread(current); t != current;
85985 + t = next_thread(t)) {
85986 + /* we'll check if the thread has uid 0 in
85987 + * the delayed worker routine
85988 + */
85989 + if (task_securebits(t) == oldsecurebits &&
85990 + t->delayed_cred == NULL) {
85991 + t->delayed_cred = get_cred(new);
85992 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
85993 + set_tsk_need_resched(t);
85994 + }
85995 + }
85996 + read_unlock(&tasklist_lock);
85997 + rcu_read_unlock();
85998 + }
85999 +
86000 + return ret;
86001 +#else
86002 + return __commit_creds(new);
86003 +#endif
86004 +}
86005 +
86006 EXPORT_SYMBOL(commit_creds);
86007
86008 /**
86009 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
86010 index 2956c8d..cfe1e2e 100644
86011 --- a/kernel/debug/debug_core.c
86012 +++ b/kernel/debug/debug_core.c
86013 @@ -124,7 +124,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
86014 */
86015 static atomic_t masters_in_kgdb;
86016 static atomic_t slaves_in_kgdb;
86017 -static atomic_t kgdb_break_tasklet_var;
86018 +static atomic_unchecked_t kgdb_break_tasklet_var;
86019 atomic_t kgdb_setting_breakpoint;
86020
86021 struct task_struct *kgdb_usethread;
86022 @@ -134,7 +134,7 @@ int kgdb_single_step;
86023 static pid_t kgdb_sstep_pid;
86024
86025 /* to keep track of the CPU which is doing the single stepping*/
86026 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
86027 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
86028
86029 /*
86030 * If you are debugging a problem where roundup (the collection of
86031 @@ -549,7 +549,7 @@ return_normal:
86032 * kernel will only try for the value of sstep_tries before
86033 * giving up and continuing on.
86034 */
86035 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
86036 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
86037 (kgdb_info[cpu].task &&
86038 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
86039 atomic_set(&kgdb_active, -1);
86040 @@ -647,8 +647,8 @@ cpu_master_loop:
86041 }
86042
86043 kgdb_restore:
86044 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
86045 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
86046 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
86047 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
86048 if (kgdb_info[sstep_cpu].task)
86049 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
86050 else
86051 @@ -925,18 +925,18 @@ static void kgdb_unregister_callbacks(void)
86052 static void kgdb_tasklet_bpt(unsigned long ing)
86053 {
86054 kgdb_breakpoint();
86055 - atomic_set(&kgdb_break_tasklet_var, 0);
86056 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
86057 }
86058
86059 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
86060
86061 void kgdb_schedule_breakpoint(void)
86062 {
86063 - if (atomic_read(&kgdb_break_tasklet_var) ||
86064 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
86065 atomic_read(&kgdb_active) != -1 ||
86066 atomic_read(&kgdb_setting_breakpoint))
86067 return;
86068 - atomic_inc(&kgdb_break_tasklet_var);
86069 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
86070 tasklet_schedule(&kgdb_tasklet_breakpoint);
86071 }
86072 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
86073 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
86074 index 0b097c8..11dd5c5 100644
86075 --- a/kernel/debug/kdb/kdb_main.c
86076 +++ b/kernel/debug/kdb/kdb_main.c
86077 @@ -1977,7 +1977,7 @@ static int kdb_lsmod(int argc, const char **argv)
86078 continue;
86079
86080 kdb_printf("%-20s%8u 0x%p ", mod->name,
86081 - mod->core_size, (void *)mod);
86082 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
86083 #ifdef CONFIG_MODULE_UNLOAD
86084 kdb_printf("%4ld ", module_refcount(mod));
86085 #endif
86086 @@ -1987,7 +1987,7 @@ static int kdb_lsmod(int argc, const char **argv)
86087 kdb_printf(" (Loading)");
86088 else
86089 kdb_printf(" (Live)");
86090 - kdb_printf(" 0x%p", mod->module_core);
86091 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
86092
86093 #ifdef CONFIG_MODULE_UNLOAD
86094 {
86095 diff --git a/kernel/events/core.c b/kernel/events/core.c
86096 index 440eefc..0909f02 100644
86097 --- a/kernel/events/core.c
86098 +++ b/kernel/events/core.c
86099 @@ -158,8 +158,15 @@ static struct srcu_struct pmus_srcu;
86100 * 0 - disallow raw tracepoint access for unpriv
86101 * 1 - disallow cpu events for unpriv
86102 * 2 - disallow kernel profiling for unpriv
86103 + * 3 - disallow all unpriv perf event use
86104 */
86105 -int sysctl_perf_event_paranoid __read_mostly = 1;
86106 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
86107 +int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
86108 +#elif defined(CONFIG_GRKERNSEC_HIDESYM)
86109 +int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
86110 +#else
86111 +int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
86112 +#endif
86113
86114 /* Minimum for 512 kiB + 1 user control page */
86115 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
86116 @@ -185,7 +192,7 @@ void update_perf_cpu_limits(void)
86117
86118 tmp *= sysctl_perf_cpu_time_max_percent;
86119 do_div(tmp, 100);
86120 - ACCESS_ONCE(perf_sample_allowed_ns) = tmp;
86121 + ACCESS_ONCE_RW(perf_sample_allowed_ns) = tmp;
86122 }
86123
86124 static int perf_rotate_context(struct perf_cpu_context *cpuctx);
86125 @@ -291,7 +298,7 @@ void perf_sample_event_took(u64 sample_len_ns)
86126 }
86127 }
86128
86129 -static atomic64_t perf_event_id;
86130 +static atomic64_unchecked_t perf_event_id;
86131
86132 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
86133 enum event_type_t event_type);
86134 @@ -3002,7 +3009,7 @@ static void __perf_event_read(void *info)
86135
86136 static inline u64 perf_event_count(struct perf_event *event)
86137 {
86138 - return local64_read(&event->count) + atomic64_read(&event->child_count);
86139 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
86140 }
86141
86142 static u64 perf_event_read(struct perf_event *event)
86143 @@ -3361,9 +3368,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
86144 mutex_lock(&event->child_mutex);
86145 total += perf_event_read(event);
86146 *enabled += event->total_time_enabled +
86147 - atomic64_read(&event->child_total_time_enabled);
86148 + atomic64_read_unchecked(&event->child_total_time_enabled);
86149 *running += event->total_time_running +
86150 - atomic64_read(&event->child_total_time_running);
86151 + atomic64_read_unchecked(&event->child_total_time_running);
86152
86153 list_for_each_entry(child, &event->child_list, child_list) {
86154 total += perf_event_read(child);
86155 @@ -3792,10 +3799,10 @@ void perf_event_update_userpage(struct perf_event *event)
86156 userpg->offset -= local64_read(&event->hw.prev_count);
86157
86158 userpg->time_enabled = enabled +
86159 - atomic64_read(&event->child_total_time_enabled);
86160 + atomic64_read_unchecked(&event->child_total_time_enabled);
86161
86162 userpg->time_running = running +
86163 - atomic64_read(&event->child_total_time_running);
86164 + atomic64_read_unchecked(&event->child_total_time_running);
86165
86166 arch_perf_update_userpage(userpg, now);
86167
86168 @@ -4359,7 +4366,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
86169
86170 /* Data. */
86171 sp = perf_user_stack_pointer(regs);
86172 - rem = __output_copy_user(handle, (void *) sp, dump_size);
86173 + rem = __output_copy_user(handle, (void __user *) sp, dump_size);
86174 dyn_size = dump_size - rem;
86175
86176 perf_output_skip(handle, rem);
86177 @@ -4450,11 +4457,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
86178 values[n++] = perf_event_count(event);
86179 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
86180 values[n++] = enabled +
86181 - atomic64_read(&event->child_total_time_enabled);
86182 + atomic64_read_unchecked(&event->child_total_time_enabled);
86183 }
86184 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
86185 values[n++] = running +
86186 - atomic64_read(&event->child_total_time_running);
86187 + atomic64_read_unchecked(&event->child_total_time_running);
86188 }
86189 if (read_format & PERF_FORMAT_ID)
86190 values[n++] = primary_event_id(event);
86191 @@ -6733,7 +6740,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
86192 event->parent = parent_event;
86193
86194 event->ns = get_pid_ns(task_active_pid_ns(current));
86195 - event->id = atomic64_inc_return(&perf_event_id);
86196 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
86197
86198 event->state = PERF_EVENT_STATE_INACTIVE;
86199
86200 @@ -7015,6 +7022,11 @@ SYSCALL_DEFINE5(perf_event_open,
86201 if (flags & ~PERF_FLAG_ALL)
86202 return -EINVAL;
86203
86204 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
86205 + if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
86206 + return -EACCES;
86207 +#endif
86208 +
86209 err = perf_copy_attr(attr_uptr, &attr);
86210 if (err)
86211 return err;
86212 @@ -7353,10 +7365,10 @@ static void sync_child_event(struct perf_event *child_event,
86213 /*
86214 * Add back the child's count to the parent's count:
86215 */
86216 - atomic64_add(child_val, &parent_event->child_count);
86217 - atomic64_add(child_event->total_time_enabled,
86218 + atomic64_add_unchecked(child_val, &parent_event->child_count);
86219 + atomic64_add_unchecked(child_event->total_time_enabled,
86220 &parent_event->child_total_time_enabled);
86221 - atomic64_add(child_event->total_time_running,
86222 + atomic64_add_unchecked(child_event->total_time_running,
86223 &parent_event->child_total_time_running);
86224
86225 /*
86226 diff --git a/kernel/events/internal.h b/kernel/events/internal.h
86227 index 569b2187..19940d9 100644
86228 --- a/kernel/events/internal.h
86229 +++ b/kernel/events/internal.h
86230 @@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
86231 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
86232 }
86233
86234 -#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
86235 +#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
86236 static inline unsigned long \
86237 func_name(struct perf_output_handle *handle, \
86238 - const void *buf, unsigned long len) \
86239 + const void user *buf, unsigned long len) \
86240 { \
86241 unsigned long size, written; \
86242 \
86243 @@ -117,7 +117,7 @@ memcpy_common(void *dst, const void *src, unsigned long n)
86244 return 0;
86245 }
86246
86247 -DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
86248 +DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
86249
86250 static inline unsigned long
86251 memcpy_skip(void *dst, const void *src, unsigned long n)
86252 @@ -125,7 +125,7 @@ memcpy_skip(void *dst, const void *src, unsigned long n)
86253 return 0;
86254 }
86255
86256 -DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
86257 +DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip, )
86258
86259 #ifndef arch_perf_out_copy_user
86260 #define arch_perf_out_copy_user arch_perf_out_copy_user
86261 @@ -143,7 +143,7 @@ arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
86262 }
86263 #endif
86264
86265 -DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
86266 +DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
86267
86268 /* Callchain handling */
86269 extern struct perf_callchain_entry *
86270 diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
86271 index 04709b6..d330828 100644
86272 --- a/kernel/events/uprobes.c
86273 +++ b/kernel/events/uprobes.c
86274 @@ -1666,7 +1666,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
86275 {
86276 struct page *page;
86277 uprobe_opcode_t opcode;
86278 - int result;
86279 + long result;
86280
86281 pagefault_disable();
86282 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
86283 diff --git a/kernel/exit.c b/kernel/exit.c
86284 index 6ed6a1d..edecb0e 100644
86285 --- a/kernel/exit.c
86286 +++ b/kernel/exit.c
86287 @@ -173,6 +173,10 @@ void release_task(struct task_struct * p)
86288 struct task_struct *leader;
86289 int zap_leader;
86290 repeat:
86291 +#ifdef CONFIG_NET
86292 + gr_del_task_from_ip_table(p);
86293 +#endif
86294 +
86295 /* don't need to get the RCU readlock here - the process is dead and
86296 * can't be modifying its own credentials. But shut RCU-lockdep up */
86297 rcu_read_lock();
86298 @@ -330,7 +334,7 @@ int allow_signal(int sig)
86299 * know it'll be handled, so that they don't get converted to
86300 * SIGKILL or just silently dropped.
86301 */
86302 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
86303 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
86304 recalc_sigpending();
86305 spin_unlock_irq(&current->sighand->siglock);
86306 return 0;
86307 @@ -699,6 +703,8 @@ void do_exit(long code)
86308 struct task_struct *tsk = current;
86309 int group_dead;
86310
86311 + set_fs(USER_DS);
86312 +
86313 profile_task_exit(tsk);
86314
86315 WARN_ON(blk_needs_flush_plug(tsk));
86316 @@ -715,7 +721,6 @@ void do_exit(long code)
86317 * mm_release()->clear_child_tid() from writing to a user-controlled
86318 * kernel address.
86319 */
86320 - set_fs(USER_DS);
86321
86322 ptrace_event(PTRACE_EVENT_EXIT, code);
86323
86324 @@ -774,6 +779,9 @@ void do_exit(long code)
86325 tsk->exit_code = code;
86326 taskstats_exit(tsk, group_dead);
86327
86328 + gr_acl_handle_psacct(tsk, code);
86329 + gr_acl_handle_exit();
86330 +
86331 exit_mm(tsk);
86332
86333 if (group_dead)
86334 @@ -893,7 +901,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
86335 * Take down every thread in the group. This is called by fatal signals
86336 * as well as by sys_exit_group (below).
86337 */
86338 -void
86339 +__noreturn void
86340 do_group_exit(int exit_code)
86341 {
86342 struct signal_struct *sig = current->signal;
86343 diff --git a/kernel/fork.c b/kernel/fork.c
86344 index 68b9226..0700bf6 100644
86345 --- a/kernel/fork.c
86346 +++ b/kernel/fork.c
86347 @@ -183,6 +183,48 @@ void thread_info_cache_init(void)
86348 # endif
86349 #endif
86350
86351 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
86352 +static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
86353 + int node, void **lowmem_stack)
86354 +{
86355 + struct page *pages[THREAD_SIZE / PAGE_SIZE];
86356 + void *ret = NULL;
86357 + unsigned int i;
86358 +
86359 + *lowmem_stack = alloc_thread_info_node(tsk, node);
86360 + if (*lowmem_stack == NULL)
86361 + goto out;
86362 +
86363 + for (i = 0; i < THREAD_SIZE / PAGE_SIZE; i++)
86364 + pages[i] = virt_to_page(*lowmem_stack + (i * PAGE_SIZE));
86365 +
86366 + /* use VM_IOREMAP to gain THREAD_SIZE alignment */
86367 + ret = vmap(pages, THREAD_SIZE / PAGE_SIZE, VM_IOREMAP, PAGE_KERNEL);
86368 + if (ret == NULL) {
86369 + free_thread_info(*lowmem_stack);
86370 + *lowmem_stack = NULL;
86371 + }
86372 +
86373 +out:
86374 + return ret;
86375 +}
86376 +
86377 +static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
86378 +{
86379 + unmap_process_stacks(tsk);
86380 +}
86381 +#else
86382 +static inline struct thread_info *gr_alloc_thread_info_node(struct task_struct *tsk,
86383 + int node, void **lowmem_stack)
86384 +{
86385 + return alloc_thread_info_node(tsk, node);
86386 +}
86387 +static inline void gr_free_thread_info(struct task_struct *tsk, struct thread_info *ti)
86388 +{
86389 + free_thread_info(ti);
86390 +}
86391 +#endif
86392 +
86393 /* SLAB cache for signal_struct structures (tsk->signal) */
86394 static struct kmem_cache *signal_cachep;
86395
86396 @@ -201,18 +243,22 @@ struct kmem_cache *vm_area_cachep;
86397 /* SLAB cache for mm_struct structures (tsk->mm) */
86398 static struct kmem_cache *mm_cachep;
86399
86400 -static void account_kernel_stack(struct thread_info *ti, int account)
86401 +static void account_kernel_stack(struct task_struct *tsk, struct thread_info *ti, int account)
86402 {
86403 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
86404 + struct zone *zone = page_zone(virt_to_page(tsk->lowmem_stack));
86405 +#else
86406 struct zone *zone = page_zone(virt_to_page(ti));
86407 +#endif
86408
86409 mod_zone_page_state(zone, NR_KERNEL_STACK, account);
86410 }
86411
86412 void free_task(struct task_struct *tsk)
86413 {
86414 - account_kernel_stack(tsk->stack, -1);
86415 + account_kernel_stack(tsk, tsk->stack, -1);
86416 arch_release_thread_info(tsk->stack);
86417 - free_thread_info(tsk->stack);
86418 + gr_free_thread_info(tsk, tsk->stack);
86419 rt_mutex_debug_task_free(tsk);
86420 ftrace_graph_exit_task(tsk);
86421 put_seccomp_filter(tsk);
86422 @@ -299,6 +345,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
86423 struct task_struct *tsk;
86424 struct thread_info *ti;
86425 unsigned long *stackend;
86426 + void *lowmem_stack;
86427 int node = tsk_fork_get_node(orig);
86428 int err;
86429
86430 @@ -306,7 +353,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
86431 if (!tsk)
86432 return NULL;
86433
86434 - ti = alloc_thread_info_node(tsk, node);
86435 + ti = gr_alloc_thread_info_node(tsk, node, &lowmem_stack);
86436 if (!ti)
86437 goto free_tsk;
86438
86439 @@ -315,6 +362,9 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
86440 goto free_ti;
86441
86442 tsk->stack = ti;
86443 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
86444 + tsk->lowmem_stack = lowmem_stack;
86445 +#endif
86446
86447 setup_thread_stack(tsk, orig);
86448 clear_user_return_notifier(tsk);
86449 @@ -323,7 +373,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
86450 *stackend = STACK_END_MAGIC; /* for overflow detection */
86451
86452 #ifdef CONFIG_CC_STACKPROTECTOR
86453 - tsk->stack_canary = get_random_int();
86454 + tsk->stack_canary = pax_get_random_long();
86455 #endif
86456
86457 /*
86458 @@ -337,24 +387,92 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
86459 tsk->splice_pipe = NULL;
86460 tsk->task_frag.page = NULL;
86461
86462 - account_kernel_stack(ti, 1);
86463 + account_kernel_stack(tsk, ti, 1);
86464
86465 return tsk;
86466
86467 free_ti:
86468 - free_thread_info(ti);
86469 + gr_free_thread_info(tsk, ti);
86470 free_tsk:
86471 free_task_struct(tsk);
86472 return NULL;
86473 }
86474
86475 #ifdef CONFIG_MMU
86476 -static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86477 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
86478 +{
86479 + struct vm_area_struct *tmp;
86480 + unsigned long charge;
86481 + struct file *file;
86482 + int retval;
86483 +
86484 + charge = 0;
86485 + if (mpnt->vm_flags & VM_ACCOUNT) {
86486 + unsigned long len = vma_pages(mpnt);
86487 +
86488 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
86489 + goto fail_nomem;
86490 + charge = len;
86491 + }
86492 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
86493 + if (!tmp)
86494 + goto fail_nomem;
86495 + *tmp = *mpnt;
86496 + tmp->vm_mm = mm;
86497 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
86498 + retval = vma_dup_policy(mpnt, tmp);
86499 + if (retval)
86500 + goto fail_nomem_policy;
86501 + if (anon_vma_fork(tmp, mpnt))
86502 + goto fail_nomem_anon_vma_fork;
86503 + tmp->vm_flags &= ~VM_LOCKED;
86504 + tmp->vm_next = tmp->vm_prev = NULL;
86505 + tmp->vm_mirror = NULL;
86506 + file = tmp->vm_file;
86507 + if (file) {
86508 + struct inode *inode = file_inode(file);
86509 + struct address_space *mapping = file->f_mapping;
86510 +
86511 + get_file(file);
86512 + if (tmp->vm_flags & VM_DENYWRITE)
86513 + atomic_dec(&inode->i_writecount);
86514 + mutex_lock(&mapping->i_mmap_mutex);
86515 + if (tmp->vm_flags & VM_SHARED)
86516 + mapping->i_mmap_writable++;
86517 + flush_dcache_mmap_lock(mapping);
86518 + /* insert tmp into the share list, just after mpnt */
86519 + if (unlikely(tmp->vm_flags & VM_NONLINEAR))
86520 + vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
86521 + else
86522 + vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
86523 + flush_dcache_mmap_unlock(mapping);
86524 + mutex_unlock(&mapping->i_mmap_mutex);
86525 + }
86526 +
86527 + /*
86528 + * Clear hugetlb-related page reserves for children. This only
86529 + * affects MAP_PRIVATE mappings. Faults generated by the child
86530 + * are not guaranteed to succeed, even if read-only
86531 + */
86532 + if (is_vm_hugetlb_page(tmp))
86533 + reset_vma_resv_huge_pages(tmp);
86534 +
86535 + return tmp;
86536 +
86537 +fail_nomem_anon_vma_fork:
86538 + mpol_put(vma_policy(tmp));
86539 +fail_nomem_policy:
86540 + kmem_cache_free(vm_area_cachep, tmp);
86541 +fail_nomem:
86542 + vm_unacct_memory(charge);
86543 + return NULL;
86544 +}
86545 +
86546 +static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86547 {
86548 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
86549 struct rb_node **rb_link, *rb_parent;
86550 int retval;
86551 - unsigned long charge;
86552
86553 uprobe_start_dup_mmap();
86554 down_write(&oldmm->mmap_sem);
86555 @@ -383,55 +501,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86556
86557 prev = NULL;
86558 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
86559 - struct file *file;
86560 -
86561 if (mpnt->vm_flags & VM_DONTCOPY) {
86562 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
86563 -vma_pages(mpnt));
86564 continue;
86565 }
86566 - charge = 0;
86567 - if (mpnt->vm_flags & VM_ACCOUNT) {
86568 - unsigned long len = vma_pages(mpnt);
86569 -
86570 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
86571 - goto fail_nomem;
86572 - charge = len;
86573 - }
86574 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
86575 - if (!tmp)
86576 - goto fail_nomem;
86577 - *tmp = *mpnt;
86578 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
86579 - retval = vma_dup_policy(mpnt, tmp);
86580 - if (retval)
86581 - goto fail_nomem_policy;
86582 - tmp->vm_mm = mm;
86583 - if (anon_vma_fork(tmp, mpnt))
86584 - goto fail_nomem_anon_vma_fork;
86585 - tmp->vm_flags &= ~VM_LOCKED;
86586 - tmp->vm_next = tmp->vm_prev = NULL;
86587 - file = tmp->vm_file;
86588 - if (file) {
86589 - struct inode *inode = file_inode(file);
86590 - struct address_space *mapping = file->f_mapping;
86591 -
86592 - get_file(file);
86593 - if (tmp->vm_flags & VM_DENYWRITE)
86594 - atomic_dec(&inode->i_writecount);
86595 - mutex_lock(&mapping->i_mmap_mutex);
86596 - if (tmp->vm_flags & VM_SHARED)
86597 - mapping->i_mmap_writable++;
86598 - flush_dcache_mmap_lock(mapping);
86599 - /* insert tmp into the share list, just after mpnt */
86600 - if (unlikely(tmp->vm_flags & VM_NONLINEAR))
86601 - vma_nonlinear_insert(tmp,
86602 - &mapping->i_mmap_nonlinear);
86603 - else
86604 - vma_interval_tree_insert_after(tmp, mpnt,
86605 - &mapping->i_mmap);
86606 - flush_dcache_mmap_unlock(mapping);
86607 - mutex_unlock(&mapping->i_mmap_mutex);
86608 + tmp = dup_vma(mm, oldmm, mpnt);
86609 + if (!tmp) {
86610 + retval = -ENOMEM;
86611 + goto out;
86612 }
86613
86614 /*
86615 @@ -463,6 +541,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
86616 if (retval)
86617 goto out;
86618 }
86619 +
86620 +#ifdef CONFIG_PAX_SEGMEXEC
86621 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
86622 + struct vm_area_struct *mpnt_m;
86623 +
86624 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
86625 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
86626 +
86627 + if (!mpnt->vm_mirror)
86628 + continue;
86629 +
86630 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
86631 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
86632 + mpnt->vm_mirror = mpnt_m;
86633 + } else {
86634 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
86635 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
86636 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
86637 + mpnt->vm_mirror->vm_mirror = mpnt;
86638 + }
86639 + }
86640 + BUG_ON(mpnt_m);
86641 + }
86642 +#endif
86643 +
86644 /* a new mm has just been created */
86645 arch_dup_mmap(oldmm, mm);
86646 retval = 0;
86647 @@ -472,14 +575,6 @@ out:
86648 up_write(&oldmm->mmap_sem);
86649 uprobe_end_dup_mmap();
86650 return retval;
86651 -fail_nomem_anon_vma_fork:
86652 - mpol_put(vma_policy(tmp));
86653 -fail_nomem_policy:
86654 - kmem_cache_free(vm_area_cachep, tmp);
86655 -fail_nomem:
86656 - retval = -ENOMEM;
86657 - vm_unacct_memory(charge);
86658 - goto out;
86659 }
86660
86661 static inline int mm_alloc_pgd(struct mm_struct *mm)
86662 @@ -698,8 +793,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
86663 return ERR_PTR(err);
86664
86665 mm = get_task_mm(task);
86666 - if (mm && mm != current->mm &&
86667 - !ptrace_may_access(task, mode)) {
86668 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
86669 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
86670 mmput(mm);
86671 mm = ERR_PTR(-EACCES);
86672 }
86673 @@ -918,13 +1013,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
86674 spin_unlock(&fs->lock);
86675 return -EAGAIN;
86676 }
86677 - fs->users++;
86678 + atomic_inc(&fs->users);
86679 spin_unlock(&fs->lock);
86680 return 0;
86681 }
86682 tsk->fs = copy_fs_struct(fs);
86683 if (!tsk->fs)
86684 return -ENOMEM;
86685 + /* Carry through gr_chroot_dentry and is_chrooted instead
86686 + of recomputing it here. Already copied when the task struct
86687 + is duplicated. This allows pivot_root to not be treated as
86688 + a chroot
86689 + */
86690 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
86691 +
86692 return 0;
86693 }
86694
86695 @@ -1133,7 +1235,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
86696 * parts of the process environment (as per the clone
86697 * flags). The actual kick-off is left to the caller.
86698 */
86699 -static struct task_struct *copy_process(unsigned long clone_flags,
86700 +static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
86701 unsigned long stack_start,
86702 unsigned long stack_size,
86703 int __user *child_tidptr,
86704 @@ -1205,6 +1307,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
86705 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
86706 #endif
86707 retval = -EAGAIN;
86708 +
86709 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
86710 +
86711 if (atomic_read(&p->real_cred->user->processes) >=
86712 task_rlimit(p, RLIMIT_NPROC)) {
86713 if (p->real_cred->user != INIT_USER &&
86714 @@ -1452,6 +1557,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
86715 goto bad_fork_free_pid;
86716 }
86717
86718 + /* synchronizes with gr_set_acls()
86719 + we need to call this past the point of no return for fork()
86720 + */
86721 + gr_copy_label(p);
86722 +
86723 if (likely(p->pid)) {
86724 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
86725
86726 @@ -1541,6 +1651,8 @@ bad_fork_cleanup_count:
86727 bad_fork_free:
86728 free_task(p);
86729 fork_out:
86730 + gr_log_forkfail(retval);
86731 +
86732 return ERR_PTR(retval);
86733 }
86734
86735 @@ -1602,6 +1714,7 @@ long do_fork(unsigned long clone_flags,
86736
86737 p = copy_process(clone_flags, stack_start, stack_size,
86738 child_tidptr, NULL, trace);
86739 + add_latent_entropy();
86740 /*
86741 * Do this prior waking up the new thread - the thread pointer
86742 * might get invalid after that point, if the thread exits quickly.
86743 @@ -1618,6 +1731,8 @@ long do_fork(unsigned long clone_flags,
86744 if (clone_flags & CLONE_PARENT_SETTID)
86745 put_user(nr, parent_tidptr);
86746
86747 + gr_handle_brute_check();
86748 +
86749 if (clone_flags & CLONE_VFORK) {
86750 p->vfork_done = &vfork;
86751 init_completion(&vfork);
86752 @@ -1736,7 +1851,7 @@ void __init proc_caches_init(void)
86753 mm_cachep = kmem_cache_create("mm_struct",
86754 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
86755 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
86756 - vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
86757 + vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
86758 mmap_init();
86759 nsproxy_cache_init();
86760 }
86761 @@ -1776,7 +1891,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
86762 return 0;
86763
86764 /* don't need lock here; in the worst case we'll do useless copy */
86765 - if (fs->users == 1)
86766 + if (atomic_read(&fs->users) == 1)
86767 return 0;
86768
86769 *new_fsp = copy_fs_struct(fs);
86770 @@ -1883,7 +1998,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
86771 fs = current->fs;
86772 spin_lock(&fs->lock);
86773 current->fs = new_fs;
86774 - if (--fs->users)
86775 + gr_set_chroot_entries(current, &current->fs->root);
86776 + if (atomic_dec_return(&fs->users))
86777 new_fs = NULL;
86778 else
86779 new_fs = fs;
86780 diff --git a/kernel/futex.c b/kernel/futex.c
86781 index de938d2..c566038 100644
86782 --- a/kernel/futex.c
86783 +++ b/kernel/futex.c
86784 @@ -202,7 +202,7 @@ struct futex_pi_state {
86785 atomic_t refcount;
86786
86787 union futex_key key;
86788 -};
86789 +} __randomize_layout;
86790
86791 /**
86792 * struct futex_q - The hashed futex queue entry, one per waiting task
86793 @@ -236,7 +236,7 @@ struct futex_q {
86794 struct rt_mutex_waiter *rt_waiter;
86795 union futex_key *requeue_pi_key;
86796 u32 bitset;
86797 -};
86798 +} __randomize_layout;
86799
86800 static const struct futex_q futex_q_init = {
86801 /* list gets initialized in queue_me()*/
86802 @@ -394,6 +394,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
86803 struct page *page, *page_head;
86804 int err, ro = 0;
86805
86806 +#ifdef CONFIG_PAX_SEGMEXEC
86807 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
86808 + return -EFAULT;
86809 +#endif
86810 +
86811 /*
86812 * The futex address must be "naturally" aligned.
86813 */
86814 @@ -593,7 +598,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
86815
86816 static int get_futex_value_locked(u32 *dest, u32 __user *from)
86817 {
86818 - int ret;
86819 + unsigned long ret;
86820
86821 pagefault_disable();
86822 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
86823 @@ -3033,6 +3038,7 @@ static void __init futex_detect_cmpxchg(void)
86824 {
86825 #ifndef CONFIG_HAVE_FUTEX_CMPXCHG
86826 u32 curval;
86827 + mm_segment_t oldfs;
86828
86829 /*
86830 * This will fail and we want it. Some arch implementations do
86831 @@ -3044,8 +3050,11 @@ static void __init futex_detect_cmpxchg(void)
86832 * implementation, the non-functional ones will return
86833 * -ENOSYS.
86834 */
86835 + oldfs = get_fs();
86836 + set_fs(USER_DS);
86837 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
86838 futex_cmpxchg_enabled = 1;
86839 + set_fs(oldfs);
86840 #endif
86841 }
86842
86843 diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
86844 index 55c8c93..9ba7ad6 100644
86845 --- a/kernel/futex_compat.c
86846 +++ b/kernel/futex_compat.c
86847 @@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
86848 return 0;
86849 }
86850
86851 -static void __user *futex_uaddr(struct robust_list __user *entry,
86852 +static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
86853 compat_long_t futex_offset)
86854 {
86855 compat_uptr_t base = ptr_to_compat(entry);
86856 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
86857 index f45b75b..bfac6d5 100644
86858 --- a/kernel/gcov/base.c
86859 +++ b/kernel/gcov/base.c
86860 @@ -108,11 +108,6 @@ void gcov_enable_events(void)
86861 }
86862
86863 #ifdef CONFIG_MODULES
86864 -static inline int within(void *addr, void *start, unsigned long size)
86865 -{
86866 - return ((addr >= start) && (addr < start + size));
86867 -}
86868 -
86869 /* Update list and generate events when modules are unloaded. */
86870 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
86871 void *data)
86872 @@ -127,7 +122,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
86873
86874 /* Remove entries located in module from linked list. */
86875 while ((info = gcov_info_next(info))) {
86876 - if (within(info, mod->module_core, mod->core_size)) {
86877 + if (within_module_core_rw((unsigned long)info, mod)) {
86878 gcov_info_unlink(prev, info);
86879 if (gcov_events_enabled)
86880 gcov_event(GCOV_REMOVE, info);
86881 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
86882 index e0501fe..312edd6 100644
86883 --- a/kernel/hrtimer.c
86884 +++ b/kernel/hrtimer.c
86885 @@ -1448,7 +1448,7 @@ void hrtimer_peek_ahead_timers(void)
86886 local_irq_restore(flags);
86887 }
86888
86889 -static void run_hrtimer_softirq(struct softirq_action *h)
86890 +static __latent_entropy void run_hrtimer_softirq(void)
86891 {
86892 hrtimer_peek_ahead_timers();
86893 }
86894 diff --git a/kernel/irq_work.c b/kernel/irq_work.c
86895 index a82170e..5b01e7f 100644
86896 --- a/kernel/irq_work.c
86897 +++ b/kernel/irq_work.c
86898 @@ -191,12 +191,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
86899 return NOTIFY_OK;
86900 }
86901
86902 -static struct notifier_block cpu_notify;
86903 +static struct notifier_block cpu_notify = {
86904 + .notifier_call = irq_work_cpu_notify,
86905 + .priority = 0,
86906 +};
86907
86908 static __init int irq_work_init_cpu_notifier(void)
86909 {
86910 - cpu_notify.notifier_call = irq_work_cpu_notify;
86911 - cpu_notify.priority = 0;
86912 register_cpu_notifier(&cpu_notify);
86913 return 0;
86914 }
86915 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
86916 index 9019f15..9a3c42e 100644
86917 --- a/kernel/jump_label.c
86918 +++ b/kernel/jump_label.c
86919 @@ -14,6 +14,7 @@
86920 #include <linux/err.h>
86921 #include <linux/static_key.h>
86922 #include <linux/jump_label_ratelimit.h>
86923 +#include <linux/mm.h>
86924
86925 #ifdef HAVE_JUMP_LABEL
86926
86927 @@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
86928
86929 size = (((unsigned long)stop - (unsigned long)start)
86930 / sizeof(struct jump_entry));
86931 + pax_open_kernel();
86932 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
86933 + pax_close_kernel();
86934 }
86935
86936 static void jump_label_update(struct static_key *key, int enable);
86937 @@ -363,10 +366,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
86938 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
86939 struct jump_entry *iter;
86940
86941 + pax_open_kernel();
86942 for (iter = iter_start; iter < iter_stop; iter++) {
86943 if (within_module_init(iter->code, mod))
86944 iter->code = 0;
86945 }
86946 + pax_close_kernel();
86947 }
86948
86949 static int
86950 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
86951 index cb0cf37..b69e161 100644
86952 --- a/kernel/kallsyms.c
86953 +++ b/kernel/kallsyms.c
86954 @@ -11,6 +11,9 @@
86955 * Changed the compression method from stem compression to "table lookup"
86956 * compression (see scripts/kallsyms.c for a more complete description)
86957 */
86958 +#ifdef CONFIG_GRKERNSEC_HIDESYM
86959 +#define __INCLUDED_BY_HIDESYM 1
86960 +#endif
86961 #include <linux/kallsyms.h>
86962 #include <linux/module.h>
86963 #include <linux/init.h>
86964 @@ -54,12 +57,33 @@ extern const unsigned long kallsyms_markers[] __weak;
86965
86966 static inline int is_kernel_inittext(unsigned long addr)
86967 {
86968 + if (system_state != SYSTEM_BOOTING)
86969 + return 0;
86970 +
86971 if (addr >= (unsigned long)_sinittext
86972 && addr <= (unsigned long)_einittext)
86973 return 1;
86974 return 0;
86975 }
86976
86977 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
86978 +#ifdef CONFIG_MODULES
86979 +static inline int is_module_text(unsigned long addr)
86980 +{
86981 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
86982 + return 1;
86983 +
86984 + addr = ktla_ktva(addr);
86985 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
86986 +}
86987 +#else
86988 +static inline int is_module_text(unsigned long addr)
86989 +{
86990 + return 0;
86991 +}
86992 +#endif
86993 +#endif
86994 +
86995 static inline int is_kernel_text(unsigned long addr)
86996 {
86997 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
86998 @@ -70,13 +94,28 @@ static inline int is_kernel_text(unsigned long addr)
86999
87000 static inline int is_kernel(unsigned long addr)
87001 {
87002 +
87003 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
87004 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
87005 + return 1;
87006 +
87007 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
87008 +#else
87009 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
87010 +#endif
87011 +
87012 return 1;
87013 return in_gate_area_no_mm(addr);
87014 }
87015
87016 static int is_ksym_addr(unsigned long addr)
87017 {
87018 +
87019 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
87020 + if (is_module_text(addr))
87021 + return 0;
87022 +#endif
87023 +
87024 if (all_var)
87025 return is_kernel(addr);
87026
87027 @@ -481,7 +520,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
87028
87029 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
87030 {
87031 - iter->name[0] = '\0';
87032 iter->nameoff = get_symbol_offset(new_pos);
87033 iter->pos = new_pos;
87034 }
87035 @@ -529,6 +567,11 @@ static int s_show(struct seq_file *m, void *p)
87036 {
87037 struct kallsym_iter *iter = m->private;
87038
87039 +#ifdef CONFIG_GRKERNSEC_HIDESYM
87040 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
87041 + return 0;
87042 +#endif
87043 +
87044 /* Some debugging symbols have no name. Ignore them. */
87045 if (!iter->name[0])
87046 return 0;
87047 @@ -542,6 +585,7 @@ static int s_show(struct seq_file *m, void *p)
87048 */
87049 type = iter->exported ? toupper(iter->type) :
87050 tolower(iter->type);
87051 +
87052 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
87053 type, iter->name, iter->module_name);
87054 } else
87055 @@ -567,7 +611,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
87056 struct kallsym_iter *iter;
87057 int ret;
87058
87059 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
87060 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
87061 if (!iter)
87062 return -ENOMEM;
87063 reset_iter(iter, 0);
87064 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
87065 index e30ac0f..3528cac 100644
87066 --- a/kernel/kcmp.c
87067 +++ b/kernel/kcmp.c
87068 @@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
87069 struct task_struct *task1, *task2;
87070 int ret;
87071
87072 +#ifdef CONFIG_GRKERNSEC
87073 + return -ENOSYS;
87074 +#endif
87075 +
87076 rcu_read_lock();
87077
87078 /*
87079 diff --git a/kernel/kexec.c b/kernel/kexec.c
87080 index 28c5706..bfc8388 100644
87081 --- a/kernel/kexec.c
87082 +++ b/kernel/kexec.c
87083 @@ -1046,7 +1046,8 @@ COMPAT_SYSCALL_DEFINE4(kexec_load, compat_ulong_t, entry,
87084 compat_ulong_t, flags)
87085 {
87086 struct compat_kexec_segment in;
87087 - struct kexec_segment out, __user *ksegments;
87088 + struct kexec_segment out;
87089 + struct kexec_segment __user *ksegments;
87090 unsigned long i, result;
87091
87092 /* Don't allow clients that don't understand the native
87093 diff --git a/kernel/kmod.c b/kernel/kmod.c
87094 index 6b375af..eaff670 100644
87095 --- a/kernel/kmod.c
87096 +++ b/kernel/kmod.c
87097 @@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
87098 kfree(info->argv);
87099 }
87100
87101 -static int call_modprobe(char *module_name, int wait)
87102 +static int call_modprobe(char *module_name, char *module_param, int wait)
87103 {
87104 struct subprocess_info *info;
87105 static char *envp[] = {
87106 @@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
87107 NULL
87108 };
87109
87110 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
87111 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
87112 if (!argv)
87113 goto out;
87114
87115 @@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
87116 argv[1] = "-q";
87117 argv[2] = "--";
87118 argv[3] = module_name; /* check free_modprobe_argv() */
87119 - argv[4] = NULL;
87120 + argv[4] = module_param;
87121 + argv[5] = NULL;
87122
87123 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
87124 NULL, free_modprobe_argv, NULL);
87125 @@ -129,9 +130,8 @@ out:
87126 * If module auto-loading support is disabled then this function
87127 * becomes a no-operation.
87128 */
87129 -int __request_module(bool wait, const char *fmt, ...)
87130 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
87131 {
87132 - va_list args;
87133 char module_name[MODULE_NAME_LEN];
87134 unsigned int max_modprobes;
87135 int ret;
87136 @@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
87137 if (!modprobe_path[0])
87138 return 0;
87139
87140 - va_start(args, fmt);
87141 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
87142 - va_end(args);
87143 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
87144 if (ret >= MODULE_NAME_LEN)
87145 return -ENAMETOOLONG;
87146
87147 @@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
87148 if (ret)
87149 return ret;
87150
87151 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
87152 + if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
87153 + /* hack to workaround consolekit/udisks stupidity */
87154 + read_lock(&tasklist_lock);
87155 + if (!strcmp(current->comm, "mount") &&
87156 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
87157 + read_unlock(&tasklist_lock);
87158 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
87159 + return -EPERM;
87160 + }
87161 + read_unlock(&tasklist_lock);
87162 + }
87163 +#endif
87164 +
87165 /* If modprobe needs a service that is in a module, we get a recursive
87166 * loop. Limit the number of running kmod threads to max_threads/2 or
87167 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
87168 @@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
87169
87170 trace_module_request(module_name, wait, _RET_IP_);
87171
87172 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
87173 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
87174
87175 atomic_dec(&kmod_concurrent);
87176 return ret;
87177 }
87178 +
87179 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
87180 +{
87181 + va_list args;
87182 + int ret;
87183 +
87184 + va_start(args, fmt);
87185 + ret = ____request_module(wait, module_param, fmt, args);
87186 + va_end(args);
87187 +
87188 + return ret;
87189 +}
87190 +
87191 +int __request_module(bool wait, const char *fmt, ...)
87192 +{
87193 + va_list args;
87194 + int ret;
87195 +
87196 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
87197 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
87198 + char module_param[MODULE_NAME_LEN];
87199 +
87200 + memset(module_param, 0, sizeof(module_param));
87201 +
87202 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
87203 +
87204 + va_start(args, fmt);
87205 + ret = ____request_module(wait, module_param, fmt, args);
87206 + va_end(args);
87207 +
87208 + return ret;
87209 + }
87210 +#endif
87211 +
87212 + va_start(args, fmt);
87213 + ret = ____request_module(wait, NULL, fmt, args);
87214 + va_end(args);
87215 +
87216 + return ret;
87217 +}
87218 +
87219 EXPORT_SYMBOL(__request_module);
87220 #endif /* CONFIG_MODULES */
87221
87222 @@ -218,6 +271,20 @@ static int ____call_usermodehelper(void *data)
87223 */
87224 set_user_nice(current, 0);
87225
87226 +#ifdef CONFIG_GRKERNSEC
87227 + /* this is race-free as far as userland is concerned as we copied
87228 + out the path to be used prior to this point and are now operating
87229 + on that copy
87230 + */
87231 + if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
87232 + strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7) &&
87233 + strcmp(sub_info->path, "/usr/share/apport/apport")) || strstr(sub_info->path, "..")) {
87234 + printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
87235 + retval = -EPERM;
87236 + goto fail;
87237 + }
87238 +#endif
87239 +
87240 retval = -ENOMEM;
87241 new = prepare_kernel_cred(current);
87242 if (!new)
87243 @@ -240,8 +307,8 @@ static int ____call_usermodehelper(void *data)
87244 commit_creds(new);
87245
87246 retval = do_execve(getname_kernel(sub_info->path),
87247 - (const char __user *const __user *)sub_info->argv,
87248 - (const char __user *const __user *)sub_info->envp);
87249 + (const char __user *const __force_user *)sub_info->argv,
87250 + (const char __user *const __force_user *)sub_info->envp);
87251 if (!retval)
87252 return 0;
87253
87254 @@ -260,6 +327,10 @@ static int call_helper(void *data)
87255
87256 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
87257 {
87258 +#ifdef CONFIG_GRKERNSEC
87259 + kfree(info->path);
87260 + info->path = info->origpath;
87261 +#endif
87262 if (info->cleanup)
87263 (*info->cleanup)(info);
87264 kfree(info);
87265 @@ -303,7 +374,7 @@ static int wait_for_helper(void *data)
87266 *
87267 * Thus the __user pointer cast is valid here.
87268 */
87269 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
87270 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
87271
87272 /*
87273 * If ret is 0, either ____call_usermodehelper failed and the
87274 @@ -542,7 +613,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
87275 goto out;
87276
87277 INIT_WORK(&sub_info->work, __call_usermodehelper);
87278 +#ifdef CONFIG_GRKERNSEC
87279 + sub_info->origpath = path;
87280 + sub_info->path = kstrdup(path, gfp_mask);
87281 +#else
87282 sub_info->path = path;
87283 +#endif
87284 sub_info->argv = argv;
87285 sub_info->envp = envp;
87286
87287 @@ -650,7 +726,7 @@ EXPORT_SYMBOL(call_usermodehelper);
87288 static int proc_cap_handler(struct ctl_table *table, int write,
87289 void __user *buffer, size_t *lenp, loff_t *ppos)
87290 {
87291 - struct ctl_table t;
87292 + ctl_table_no_const t;
87293 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
87294 kernel_cap_t new_cap;
87295 int err, i;
87296 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
87297 index ceeadfc..11c18b6 100644
87298 --- a/kernel/kprobes.c
87299 +++ b/kernel/kprobes.c
87300 @@ -31,6 +31,9 @@
87301 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
87302 * <prasanna@in.ibm.com> added function-return probes.
87303 */
87304 +#ifdef CONFIG_GRKERNSEC_HIDESYM
87305 +#define __INCLUDED_BY_HIDESYM 1
87306 +#endif
87307 #include <linux/kprobes.h>
87308 #include <linux/hash.h>
87309 #include <linux/init.h>
87310 @@ -135,12 +138,12 @@ enum kprobe_slot_state {
87311
87312 static void *alloc_insn_page(void)
87313 {
87314 - return module_alloc(PAGE_SIZE);
87315 + return module_alloc_exec(PAGE_SIZE);
87316 }
87317
87318 static void free_insn_page(void *page)
87319 {
87320 - module_free(NULL, page);
87321 + module_free_exec(NULL, page);
87322 }
87323
87324 struct kprobe_insn_cache kprobe_insn_slots = {
87325 @@ -2151,11 +2154,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
87326 kprobe_type = "k";
87327
87328 if (sym)
87329 - seq_printf(pi, "%p %s %s+0x%x %s ",
87330 + seq_printf(pi, "%pK %s %s+0x%x %s ",
87331 p->addr, kprobe_type, sym, offset,
87332 (modname ? modname : " "));
87333 else
87334 - seq_printf(pi, "%p %s %p ",
87335 + seq_printf(pi, "%pK %s %pK ",
87336 p->addr, kprobe_type, p->addr);
87337
87338 if (!pp)
87339 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
87340 index 2495a9b..071b906 100644
87341 --- a/kernel/ksysfs.c
87342 +++ b/kernel/ksysfs.c
87343 @@ -49,6 +49,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
87344 {
87345 if (count+1 > UEVENT_HELPER_PATH_LEN)
87346 return -ENOENT;
87347 + if (!capable(CAP_SYS_ADMIN))
87348 + return -EPERM;
87349 memcpy(uevent_helper, buf, count);
87350 uevent_helper[count] = '\0';
87351 if (count && uevent_helper[count-1] == '\n')
87352 @@ -175,7 +177,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
87353 return count;
87354 }
87355
87356 -static struct bin_attribute notes_attr = {
87357 +static bin_attribute_no_const notes_attr __read_only = {
87358 .attr = {
87359 .name = "notes",
87360 .mode = S_IRUGO,
87361 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
87362 index d24e433..fa04fb8 100644
87363 --- a/kernel/locking/lockdep.c
87364 +++ b/kernel/locking/lockdep.c
87365 @@ -597,6 +597,10 @@ static int static_obj(void *obj)
87366 end = (unsigned long) &_end,
87367 addr = (unsigned long) obj;
87368
87369 +#ifdef CONFIG_PAX_KERNEXEC
87370 + start = ktla_ktva(start);
87371 +#endif
87372 +
87373 /*
87374 * static variable?
87375 */
87376 @@ -738,6 +742,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
87377 if (!static_obj(lock->key)) {
87378 debug_locks_off();
87379 printk("INFO: trying to register non-static key.\n");
87380 + printk("lock:%pS key:%pS.\n", lock, lock->key);
87381 printk("the code is fine but needs lockdep annotation.\n");
87382 printk("turning off the locking correctness validator.\n");
87383 dump_stack();
87384 @@ -3079,7 +3084,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
87385 if (!class)
87386 return 0;
87387 }
87388 - atomic_inc((atomic_t *)&class->ops);
87389 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)&class->ops);
87390 if (very_verbose(class)) {
87391 printk("\nacquire class [%p] %s", class->key, class->name);
87392 if (class->name_version > 1)
87393 diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
87394 index ef43ac4..2720dfa 100644
87395 --- a/kernel/locking/lockdep_proc.c
87396 +++ b/kernel/locking/lockdep_proc.c
87397 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
87398 return 0;
87399 }
87400
87401 - seq_printf(m, "%p", class->key);
87402 + seq_printf(m, "%pK", class->key);
87403 #ifdef CONFIG_DEBUG_LOCKDEP
87404 seq_printf(m, " OPS:%8ld", class->ops);
87405 #endif
87406 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
87407
87408 list_for_each_entry(entry, &class->locks_after, entry) {
87409 if (entry->distance == 1) {
87410 - seq_printf(m, " -> [%p] ", entry->class->key);
87411 + seq_printf(m, " -> [%pK] ", entry->class->key);
87412 print_name(m, entry->class);
87413 seq_puts(m, "\n");
87414 }
87415 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
87416 if (!class->key)
87417 continue;
87418
87419 - seq_printf(m, "[%p] ", class->key);
87420 + seq_printf(m, "[%pK] ", class->key);
87421 print_name(m, class);
87422 seq_puts(m, "\n");
87423 }
87424 @@ -496,7 +496,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
87425 if (!i)
87426 seq_line(m, '-', 40-namelen, namelen);
87427
87428 - snprintf(ip, sizeof(ip), "[<%p>]",
87429 + snprintf(ip, sizeof(ip), "[<%pK>]",
87430 (void *)class->contention_point[i]);
87431 seq_printf(m, "%40s %14lu %29s %pS\n",
87432 name, stats->contention_point[i],
87433 @@ -511,7 +511,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
87434 if (!i)
87435 seq_line(m, '-', 40-namelen, namelen);
87436
87437 - snprintf(ip, sizeof(ip), "[<%p>]",
87438 + snprintf(ip, sizeof(ip), "[<%pK>]",
87439 (void *)class->contending_point[i]);
87440 seq_printf(m, "%40s %14lu %29s %pS\n",
87441 name, stats->contending_point[i],
87442 diff --git a/kernel/locking/mcs_spinlock.c b/kernel/locking/mcs_spinlock.c
87443 index 838dc9e..760e158 100644
87444 --- a/kernel/locking/mcs_spinlock.c
87445 +++ b/kernel/locking/mcs_spinlock.c
87446 @@ -71,7 +71,7 @@ bool osq_lock(struct optimistic_spin_queue **lock)
87447 if (likely(prev == NULL))
87448 return true;
87449
87450 - ACCESS_ONCE(prev->next) = node;
87451 + ACCESS_ONCE_RW(prev->next) = node;
87452
87453 /*
87454 * Normally @prev is untouchable after the above store; because at that
87455 @@ -143,8 +143,8 @@ unqueue:
87456 * it will wait in Step-A.
87457 */
87458
87459 - ACCESS_ONCE(next->prev) = prev;
87460 - ACCESS_ONCE(prev->next) = next;
87461 + ACCESS_ONCE_RW(next->prev) = prev;
87462 + ACCESS_ONCE_RW(prev->next) = next;
87463
87464 return false;
87465 }
87466 @@ -165,13 +165,13 @@ void osq_unlock(struct optimistic_spin_queue **lock)
87467 */
87468 next = xchg(&node->next, NULL);
87469 if (next) {
87470 - ACCESS_ONCE(next->locked) = 1;
87471 + ACCESS_ONCE_RW(next->locked) = 1;
87472 return;
87473 }
87474
87475 next = osq_wait_next(lock, node, NULL);
87476 if (next)
87477 - ACCESS_ONCE(next->locked) = 1;
87478 + ACCESS_ONCE_RW(next->locked) = 1;
87479 }
87480
87481 #endif
87482 diff --git a/kernel/locking/mcs_spinlock.h b/kernel/locking/mcs_spinlock.h
87483 index a2dbac4..e02a34a 100644
87484 --- a/kernel/locking/mcs_spinlock.h
87485 +++ b/kernel/locking/mcs_spinlock.h
87486 @@ -81,7 +81,7 @@ void mcs_spin_lock(struct mcs_spinlock **lock, struct mcs_spinlock *node)
87487 */
87488 return;
87489 }
87490 - ACCESS_ONCE(prev->next) = node;
87491 + ACCESS_ONCE_RW(prev->next) = node;
87492
87493 /* Wait until the lock holder passes the lock down. */
87494 arch_mcs_spin_lock_contended(&node->locked);
87495 diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c
87496 index 5cf6731..ce3bc5a 100644
87497 --- a/kernel/locking/mutex-debug.c
87498 +++ b/kernel/locking/mutex-debug.c
87499 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
87500 }
87501
87502 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
87503 - struct thread_info *ti)
87504 + struct task_struct *task)
87505 {
87506 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
87507
87508 /* Mark the current thread as blocked on the lock: */
87509 - ti->task->blocked_on = waiter;
87510 + task->blocked_on = waiter;
87511 }
87512
87513 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
87514 - struct thread_info *ti)
87515 + struct task_struct *task)
87516 {
87517 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
87518 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
87519 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
87520 - ti->task->blocked_on = NULL;
87521 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
87522 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
87523 + task->blocked_on = NULL;
87524
87525 list_del_init(&waiter->list);
87526 waiter->task = NULL;
87527 diff --git a/kernel/locking/mutex-debug.h b/kernel/locking/mutex-debug.h
87528 index 0799fd3..d06ae3b 100644
87529 --- a/kernel/locking/mutex-debug.h
87530 +++ b/kernel/locking/mutex-debug.h
87531 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
87532 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
87533 extern void debug_mutex_add_waiter(struct mutex *lock,
87534 struct mutex_waiter *waiter,
87535 - struct thread_info *ti);
87536 + struct task_struct *task);
87537 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
87538 - struct thread_info *ti);
87539 + struct task_struct *task);
87540 extern void debug_mutex_unlock(struct mutex *lock);
87541 extern void debug_mutex_init(struct mutex *lock, const char *name,
87542 struct lock_class_key *key);
87543 diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
87544 index bc73d33..6f308aa 100644
87545 --- a/kernel/locking/mutex.c
87546 +++ b/kernel/locking/mutex.c
87547 @@ -490,7 +490,7 @@ slowpath:
87548 goto skip_wait;
87549
87550 debug_mutex_lock_common(lock, &waiter);
87551 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
87552 + debug_mutex_add_waiter(lock, &waiter, task);
87553
87554 /* add waiting tasks to the end of the waitqueue (FIFO): */
87555 list_add_tail(&waiter.list, &lock->wait_list);
87556 @@ -534,7 +534,7 @@ slowpath:
87557 schedule_preempt_disabled();
87558 spin_lock_mutex(&lock->wait_lock, flags);
87559 }
87560 - mutex_remove_waiter(lock, &waiter, current_thread_info());
87561 + mutex_remove_waiter(lock, &waiter, task);
87562 /* set it to 0 if there are no waiters left: */
87563 if (likely(list_empty(&lock->wait_list)))
87564 atomic_set(&lock->count, 0);
87565 @@ -571,7 +571,7 @@ skip_wait:
87566 return 0;
87567
87568 err:
87569 - mutex_remove_waiter(lock, &waiter, task_thread_info(task));
87570 + mutex_remove_waiter(lock, &waiter, task);
87571 spin_unlock_mutex(&lock->wait_lock, flags);
87572 debug_mutex_free_waiter(&waiter);
87573 mutex_release(&lock->dep_map, 1, ip);
87574 diff --git a/kernel/locking/rtmutex-tester.c b/kernel/locking/rtmutex-tester.c
87575 index 1d96dd0..994ff19 100644
87576 --- a/kernel/locking/rtmutex-tester.c
87577 +++ b/kernel/locking/rtmutex-tester.c
87578 @@ -22,7 +22,7 @@
87579 #define MAX_RT_TEST_MUTEXES 8
87580
87581 static spinlock_t rttest_lock;
87582 -static atomic_t rttest_event;
87583 +static atomic_unchecked_t rttest_event;
87584
87585 struct test_thread_data {
87586 int opcode;
87587 @@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87588
87589 case RTTEST_LOCKCONT:
87590 td->mutexes[td->opdata] = 1;
87591 - td->event = atomic_add_return(1, &rttest_event);
87592 + td->event = atomic_add_return_unchecked(1, &rttest_event);
87593 return 0;
87594
87595 case RTTEST_RESET:
87596 @@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87597 return 0;
87598
87599 case RTTEST_RESETEVENT:
87600 - atomic_set(&rttest_event, 0);
87601 + atomic_set_unchecked(&rttest_event, 0);
87602 return 0;
87603
87604 default:
87605 @@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87606 return ret;
87607
87608 td->mutexes[id] = 1;
87609 - td->event = atomic_add_return(1, &rttest_event);
87610 + td->event = atomic_add_return_unchecked(1, &rttest_event);
87611 rt_mutex_lock(&mutexes[id]);
87612 - td->event = atomic_add_return(1, &rttest_event);
87613 + td->event = atomic_add_return_unchecked(1, &rttest_event);
87614 td->mutexes[id] = 4;
87615 return 0;
87616
87617 @@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87618 return ret;
87619
87620 td->mutexes[id] = 1;
87621 - td->event = atomic_add_return(1, &rttest_event);
87622 + td->event = atomic_add_return_unchecked(1, &rttest_event);
87623 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
87624 - td->event = atomic_add_return(1, &rttest_event);
87625 + td->event = atomic_add_return_unchecked(1, &rttest_event);
87626 td->mutexes[id] = ret ? 0 : 4;
87627 return ret ? -EINTR : 0;
87628
87629 @@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
87630 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
87631 return ret;
87632
87633 - td->event = atomic_add_return(1, &rttest_event);
87634 + td->event = atomic_add_return_unchecked(1, &rttest_event);
87635 rt_mutex_unlock(&mutexes[id]);
87636 - td->event = atomic_add_return(1, &rttest_event);
87637 + td->event = atomic_add_return_unchecked(1, &rttest_event);
87638 td->mutexes[id] = 0;
87639 return 0;
87640
87641 @@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
87642 break;
87643
87644 td->mutexes[dat] = 2;
87645 - td->event = atomic_add_return(1, &rttest_event);
87646 + td->event = atomic_add_return_unchecked(1, &rttest_event);
87647 break;
87648
87649 default:
87650 @@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
87651 return;
87652
87653 td->mutexes[dat] = 3;
87654 - td->event = atomic_add_return(1, &rttest_event);
87655 + td->event = atomic_add_return_unchecked(1, &rttest_event);
87656 break;
87657
87658 case RTTEST_LOCKNOWAIT:
87659 @@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
87660 return;
87661
87662 td->mutexes[dat] = 1;
87663 - td->event = atomic_add_return(1, &rttest_event);
87664 + td->event = atomic_add_return_unchecked(1, &rttest_event);
87665 return;
87666
87667 default:
87668 diff --git a/kernel/module.c b/kernel/module.c
87669 index 079c461..741f79c 100644
87670 --- a/kernel/module.c
87671 +++ b/kernel/module.c
87672 @@ -61,6 +61,7 @@
87673 #include <linux/pfn.h>
87674 #include <linux/bsearch.h>
87675 #include <linux/fips.h>
87676 +#include <linux/grsecurity.h>
87677 #include <uapi/linux/module.h>
87678 #include "module-internal.h"
87679
87680 @@ -157,7 +158,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
87681
87682 /* Bounds of module allocation, for speeding __module_address.
87683 * Protected by module_mutex. */
87684 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
87685 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
87686 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
87687
87688 int register_module_notifier(struct notifier_block * nb)
87689 {
87690 @@ -324,7 +326,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
87691 return true;
87692
87693 list_for_each_entry_rcu(mod, &modules, list) {
87694 - struct symsearch arr[] = {
87695 + struct symsearch modarr[] = {
87696 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
87697 NOT_GPL_ONLY, false },
87698 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
87699 @@ -349,7 +351,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
87700 if (mod->state == MODULE_STATE_UNFORMED)
87701 continue;
87702
87703 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
87704 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
87705 return true;
87706 }
87707 return false;
87708 @@ -489,7 +491,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
87709 if (!pcpusec->sh_size)
87710 return 0;
87711
87712 - if (align > PAGE_SIZE) {
87713 + if (align-1 >= PAGE_SIZE) {
87714 pr_warn("%s: per-cpu alignment %li > %li\n",
87715 mod->name, align, PAGE_SIZE);
87716 align = PAGE_SIZE;
87717 @@ -1061,7 +1063,7 @@ struct module_attribute module_uevent =
87718 static ssize_t show_coresize(struct module_attribute *mattr,
87719 struct module_kobject *mk, char *buffer)
87720 {
87721 - return sprintf(buffer, "%u\n", mk->mod->core_size);
87722 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
87723 }
87724
87725 static struct module_attribute modinfo_coresize =
87726 @@ -1070,7 +1072,7 @@ static struct module_attribute modinfo_coresize =
87727 static ssize_t show_initsize(struct module_attribute *mattr,
87728 struct module_kobject *mk, char *buffer)
87729 {
87730 - return sprintf(buffer, "%u\n", mk->mod->init_size);
87731 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
87732 }
87733
87734 static struct module_attribute modinfo_initsize =
87735 @@ -1162,12 +1164,29 @@ static int check_version(Elf_Shdr *sechdrs,
87736 goto bad_version;
87737 }
87738
87739 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
87740 + /*
87741 + * avoid potentially printing jibberish on attempted load
87742 + * of a module randomized with a different seed
87743 + */
87744 + pr_warn("no symbol version for %s\n", symname);
87745 +#else
87746 pr_warn("%s: no symbol version for %s\n", mod->name, symname);
87747 +#endif
87748 return 0;
87749
87750 bad_version:
87751 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
87752 + /*
87753 + * avoid potentially printing jibberish on attempted load
87754 + * of a module randomized with a different seed
87755 + */
87756 + printk("attempted module disagrees about version of symbol %s\n",
87757 + symname);
87758 +#else
87759 printk("%s: disagrees about version of symbol %s\n",
87760 mod->name, symname);
87761 +#endif
87762 return 0;
87763 }
87764
87765 @@ -1283,7 +1302,7 @@ resolve_symbol_wait(struct module *mod,
87766 */
87767 #ifdef CONFIG_SYSFS
87768
87769 -#ifdef CONFIG_KALLSYMS
87770 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
87771 static inline bool sect_empty(const Elf_Shdr *sect)
87772 {
87773 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
87774 @@ -1423,7 +1442,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
87775 {
87776 unsigned int notes, loaded, i;
87777 struct module_notes_attrs *notes_attrs;
87778 - struct bin_attribute *nattr;
87779 + bin_attribute_no_const *nattr;
87780
87781 /* failed to create section attributes, so can't create notes */
87782 if (!mod->sect_attrs)
87783 @@ -1535,7 +1554,7 @@ static void del_usage_links(struct module *mod)
87784 static int module_add_modinfo_attrs(struct module *mod)
87785 {
87786 struct module_attribute *attr;
87787 - struct module_attribute *temp_attr;
87788 + module_attribute_no_const *temp_attr;
87789 int error = 0;
87790 int i;
87791
87792 @@ -1756,21 +1775,21 @@ static void set_section_ro_nx(void *base,
87793
87794 static void unset_module_core_ro_nx(struct module *mod)
87795 {
87796 - set_page_attributes(mod->module_core + mod->core_text_size,
87797 - mod->module_core + mod->core_size,
87798 + set_page_attributes(mod->module_core_rw,
87799 + mod->module_core_rw + mod->core_size_rw,
87800 set_memory_x);
87801 - set_page_attributes(mod->module_core,
87802 - mod->module_core + mod->core_ro_size,
87803 + set_page_attributes(mod->module_core_rx,
87804 + mod->module_core_rx + mod->core_size_rx,
87805 set_memory_rw);
87806 }
87807
87808 static void unset_module_init_ro_nx(struct module *mod)
87809 {
87810 - set_page_attributes(mod->module_init + mod->init_text_size,
87811 - mod->module_init + mod->init_size,
87812 + set_page_attributes(mod->module_init_rw,
87813 + mod->module_init_rw + mod->init_size_rw,
87814 set_memory_x);
87815 - set_page_attributes(mod->module_init,
87816 - mod->module_init + mod->init_ro_size,
87817 + set_page_attributes(mod->module_init_rx,
87818 + mod->module_init_rx + mod->init_size_rx,
87819 set_memory_rw);
87820 }
87821
87822 @@ -1783,14 +1802,14 @@ void set_all_modules_text_rw(void)
87823 list_for_each_entry_rcu(mod, &modules, list) {
87824 if (mod->state == MODULE_STATE_UNFORMED)
87825 continue;
87826 - if ((mod->module_core) && (mod->core_text_size)) {
87827 - set_page_attributes(mod->module_core,
87828 - mod->module_core + mod->core_text_size,
87829 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
87830 + set_page_attributes(mod->module_core_rx,
87831 + mod->module_core_rx + mod->core_size_rx,
87832 set_memory_rw);
87833 }
87834 - if ((mod->module_init) && (mod->init_text_size)) {
87835 - set_page_attributes(mod->module_init,
87836 - mod->module_init + mod->init_text_size,
87837 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
87838 + set_page_attributes(mod->module_init_rx,
87839 + mod->module_init_rx + mod->init_size_rx,
87840 set_memory_rw);
87841 }
87842 }
87843 @@ -1806,14 +1825,14 @@ void set_all_modules_text_ro(void)
87844 list_for_each_entry_rcu(mod, &modules, list) {
87845 if (mod->state == MODULE_STATE_UNFORMED)
87846 continue;
87847 - if ((mod->module_core) && (mod->core_text_size)) {
87848 - set_page_attributes(mod->module_core,
87849 - mod->module_core + mod->core_text_size,
87850 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
87851 + set_page_attributes(mod->module_core_rx,
87852 + mod->module_core_rx + mod->core_size_rx,
87853 set_memory_ro);
87854 }
87855 - if ((mod->module_init) && (mod->init_text_size)) {
87856 - set_page_attributes(mod->module_init,
87857 - mod->module_init + mod->init_text_size,
87858 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
87859 + set_page_attributes(mod->module_init_rx,
87860 + mod->module_init_rx + mod->init_size_rx,
87861 set_memory_ro);
87862 }
87863 }
87864 @@ -1864,16 +1883,19 @@ static void free_module(struct module *mod)
87865
87866 /* This may be NULL, but that's OK */
87867 unset_module_init_ro_nx(mod);
87868 - module_free(mod, mod->module_init);
87869 + module_free(mod, mod->module_init_rw);
87870 + module_free_exec(mod, mod->module_init_rx);
87871 kfree(mod->args);
87872 percpu_modfree(mod);
87873
87874 /* Free lock-classes: */
87875 - lockdep_free_key_range(mod->module_core, mod->core_size);
87876 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
87877 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
87878
87879 /* Finally, free the core (containing the module structure) */
87880 unset_module_core_ro_nx(mod);
87881 - module_free(mod, mod->module_core);
87882 + module_free_exec(mod, mod->module_core_rx);
87883 + module_free(mod, mod->module_core_rw);
87884
87885 #ifdef CONFIG_MPU
87886 update_protections(current->mm);
87887 @@ -1942,9 +1964,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
87888 int ret = 0;
87889 const struct kernel_symbol *ksym;
87890
87891 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
87892 + int is_fs_load = 0;
87893 + int register_filesystem_found = 0;
87894 + char *p;
87895 +
87896 + p = strstr(mod->args, "grsec_modharden_fs");
87897 + if (p) {
87898 + char *endptr = p + sizeof("grsec_modharden_fs") - 1;
87899 + /* copy \0 as well */
87900 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
87901 + is_fs_load = 1;
87902 + }
87903 +#endif
87904 +
87905 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
87906 const char *name = info->strtab + sym[i].st_name;
87907
87908 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
87909 + /* it's a real shame this will never get ripped and copied
87910 + upstream! ;(
87911 + */
87912 + if (is_fs_load && !strcmp(name, "register_filesystem"))
87913 + register_filesystem_found = 1;
87914 +#endif
87915 +
87916 switch (sym[i].st_shndx) {
87917 case SHN_COMMON:
87918 /* Ignore common symbols */
87919 @@ -1969,7 +2013,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
87920 ksym = resolve_symbol_wait(mod, info, name);
87921 /* Ok if resolved. */
87922 if (ksym && !IS_ERR(ksym)) {
87923 + pax_open_kernel();
87924 sym[i].st_value = ksym->value;
87925 + pax_close_kernel();
87926 break;
87927 }
87928
87929 @@ -1988,11 +2034,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
87930 secbase = (unsigned long)mod_percpu(mod);
87931 else
87932 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
87933 + pax_open_kernel();
87934 sym[i].st_value += secbase;
87935 + pax_close_kernel();
87936 break;
87937 }
87938 }
87939
87940 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
87941 + if (is_fs_load && !register_filesystem_found) {
87942 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
87943 + ret = -EPERM;
87944 + }
87945 +#endif
87946 +
87947 return ret;
87948 }
87949
87950 @@ -2076,22 +2131,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
87951 || s->sh_entsize != ~0UL
87952 || strstarts(sname, ".init"))
87953 continue;
87954 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
87955 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
87956 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
87957 + else
87958 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
87959 pr_debug("\t%s\n", sname);
87960 }
87961 - switch (m) {
87962 - case 0: /* executable */
87963 - mod->core_size = debug_align(mod->core_size);
87964 - mod->core_text_size = mod->core_size;
87965 - break;
87966 - case 1: /* RO: text and ro-data */
87967 - mod->core_size = debug_align(mod->core_size);
87968 - mod->core_ro_size = mod->core_size;
87969 - break;
87970 - case 3: /* whole core */
87971 - mod->core_size = debug_align(mod->core_size);
87972 - break;
87973 - }
87974 }
87975
87976 pr_debug("Init section allocation order:\n");
87977 @@ -2105,23 +2150,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
87978 || s->sh_entsize != ~0UL
87979 || !strstarts(sname, ".init"))
87980 continue;
87981 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
87982 - | INIT_OFFSET_MASK);
87983 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
87984 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
87985 + else
87986 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
87987 + s->sh_entsize |= INIT_OFFSET_MASK;
87988 pr_debug("\t%s\n", sname);
87989 }
87990 - switch (m) {
87991 - case 0: /* executable */
87992 - mod->init_size = debug_align(mod->init_size);
87993 - mod->init_text_size = mod->init_size;
87994 - break;
87995 - case 1: /* RO: text and ro-data */
87996 - mod->init_size = debug_align(mod->init_size);
87997 - mod->init_ro_size = mod->init_size;
87998 - break;
87999 - case 3: /* whole init */
88000 - mod->init_size = debug_align(mod->init_size);
88001 - break;
88002 - }
88003 }
88004 }
88005
88006 @@ -2294,7 +2329,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
88007
88008 /* Put symbol section at end of init part of module. */
88009 symsect->sh_flags |= SHF_ALLOC;
88010 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
88011 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
88012 info->index.sym) | INIT_OFFSET_MASK;
88013 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
88014
88015 @@ -2311,13 +2346,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
88016 }
88017
88018 /* Append room for core symbols at end of core part. */
88019 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
88020 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
88021 - mod->core_size += strtab_size;
88022 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
88023 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
88024 + mod->core_size_rx += strtab_size;
88025
88026 /* Put string table section at end of init part of module. */
88027 strsect->sh_flags |= SHF_ALLOC;
88028 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
88029 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
88030 info->index.str) | INIT_OFFSET_MASK;
88031 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
88032 }
88033 @@ -2335,12 +2370,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
88034 /* Make sure we get permanent strtab: don't use info->strtab. */
88035 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
88036
88037 + pax_open_kernel();
88038 +
88039 /* Set types up while we still have access to sections. */
88040 for (i = 0; i < mod->num_symtab; i++)
88041 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
88042
88043 - mod->core_symtab = dst = mod->module_core + info->symoffs;
88044 - mod->core_strtab = s = mod->module_core + info->stroffs;
88045 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
88046 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
88047 src = mod->symtab;
88048 for (ndst = i = 0; i < mod->num_symtab; i++) {
88049 if (i == 0 ||
88050 @@ -2352,6 +2389,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
88051 }
88052 }
88053 mod->core_num_syms = ndst;
88054 +
88055 + pax_close_kernel();
88056 }
88057 #else
88058 static inline void layout_symtab(struct module *mod, struct load_info *info)
88059 @@ -2385,17 +2424,33 @@ void * __weak module_alloc(unsigned long size)
88060 return vmalloc_exec(size);
88061 }
88062
88063 -static void *module_alloc_update_bounds(unsigned long size)
88064 +static void *module_alloc_update_bounds_rw(unsigned long size)
88065 {
88066 void *ret = module_alloc(size);
88067
88068 if (ret) {
88069 mutex_lock(&module_mutex);
88070 /* Update module bounds. */
88071 - if ((unsigned long)ret < module_addr_min)
88072 - module_addr_min = (unsigned long)ret;
88073 - if ((unsigned long)ret + size > module_addr_max)
88074 - module_addr_max = (unsigned long)ret + size;
88075 + if ((unsigned long)ret < module_addr_min_rw)
88076 + module_addr_min_rw = (unsigned long)ret;
88077 + if ((unsigned long)ret + size > module_addr_max_rw)
88078 + module_addr_max_rw = (unsigned long)ret + size;
88079 + mutex_unlock(&module_mutex);
88080 + }
88081 + return ret;
88082 +}
88083 +
88084 +static void *module_alloc_update_bounds_rx(unsigned long size)
88085 +{
88086 + void *ret = module_alloc_exec(size);
88087 +
88088 + if (ret) {
88089 + mutex_lock(&module_mutex);
88090 + /* Update module bounds. */
88091 + if ((unsigned long)ret < module_addr_min_rx)
88092 + module_addr_min_rx = (unsigned long)ret;
88093 + if ((unsigned long)ret + size > module_addr_max_rx)
88094 + module_addr_max_rx = (unsigned long)ret + size;
88095 mutex_unlock(&module_mutex);
88096 }
88097 return ret;
88098 @@ -2652,7 +2707,15 @@ static struct module *setup_load_info(struct load_info *info, int flags)
88099 mod = (void *)info->sechdrs[info->index.mod].sh_addr;
88100
88101 if (info->index.sym == 0) {
88102 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
88103 + /*
88104 + * avoid potentially printing jibberish on attempted load
88105 + * of a module randomized with a different seed
88106 + */
88107 + pr_warn("module has no symbols (stripped?)\n");
88108 +#else
88109 pr_warn("%s: module has no symbols (stripped?)\n", mod->name);
88110 +#endif
88111 return ERR_PTR(-ENOEXEC);
88112 }
88113
88114 @@ -2668,8 +2731,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
88115 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
88116 {
88117 const char *modmagic = get_modinfo(info, "vermagic");
88118 + const char *license = get_modinfo(info, "license");
88119 int err;
88120
88121 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
88122 + if (!license || !license_is_gpl_compatible(license))
88123 + return -ENOEXEC;
88124 +#endif
88125 +
88126 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
88127 modmagic = NULL;
88128
88129 @@ -2694,7 +2763,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
88130 }
88131
88132 /* Set up license info based on the info section */
88133 - set_license(mod, get_modinfo(info, "license"));
88134 + set_license(mod, license);
88135
88136 return 0;
88137 }
88138 @@ -2788,7 +2857,7 @@ static int move_module(struct module *mod, struct load_info *info)
88139 void *ptr;
88140
88141 /* Do the allocs. */
88142 - ptr = module_alloc_update_bounds(mod->core_size);
88143 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
88144 /*
88145 * The pointer to this block is stored in the module structure
88146 * which is inside the block. Just mark it as not being a
88147 @@ -2798,11 +2867,11 @@ static int move_module(struct module *mod, struct load_info *info)
88148 if (!ptr)
88149 return -ENOMEM;
88150
88151 - memset(ptr, 0, mod->core_size);
88152 - mod->module_core = ptr;
88153 + memset(ptr, 0, mod->core_size_rw);
88154 + mod->module_core_rw = ptr;
88155
88156 - if (mod->init_size) {
88157 - ptr = module_alloc_update_bounds(mod->init_size);
88158 + if (mod->init_size_rw) {
88159 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
88160 /*
88161 * The pointer to this block is stored in the module structure
88162 * which is inside the block. This block doesn't need to be
88163 @@ -2811,13 +2880,45 @@ static int move_module(struct module *mod, struct load_info *info)
88164 */
88165 kmemleak_ignore(ptr);
88166 if (!ptr) {
88167 - module_free(mod, mod->module_core);
88168 + module_free(mod, mod->module_core_rw);
88169 return -ENOMEM;
88170 }
88171 - memset(ptr, 0, mod->init_size);
88172 - mod->module_init = ptr;
88173 + memset(ptr, 0, mod->init_size_rw);
88174 + mod->module_init_rw = ptr;
88175 } else
88176 - mod->module_init = NULL;
88177 + mod->module_init_rw = NULL;
88178 +
88179 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
88180 + kmemleak_not_leak(ptr);
88181 + if (!ptr) {
88182 + if (mod->module_init_rw)
88183 + module_free(mod, mod->module_init_rw);
88184 + module_free(mod, mod->module_core_rw);
88185 + return -ENOMEM;
88186 + }
88187 +
88188 + pax_open_kernel();
88189 + memset(ptr, 0, mod->core_size_rx);
88190 + pax_close_kernel();
88191 + mod->module_core_rx = ptr;
88192 +
88193 + if (mod->init_size_rx) {
88194 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
88195 + kmemleak_ignore(ptr);
88196 + if (!ptr && mod->init_size_rx) {
88197 + module_free_exec(mod, mod->module_core_rx);
88198 + if (mod->module_init_rw)
88199 + module_free(mod, mod->module_init_rw);
88200 + module_free(mod, mod->module_core_rw);
88201 + return -ENOMEM;
88202 + }
88203 +
88204 + pax_open_kernel();
88205 + memset(ptr, 0, mod->init_size_rx);
88206 + pax_close_kernel();
88207 + mod->module_init_rx = ptr;
88208 + } else
88209 + mod->module_init_rx = NULL;
88210
88211 /* Transfer each section which specifies SHF_ALLOC */
88212 pr_debug("final section addresses:\n");
88213 @@ -2828,16 +2929,45 @@ static int move_module(struct module *mod, struct load_info *info)
88214 if (!(shdr->sh_flags & SHF_ALLOC))
88215 continue;
88216
88217 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
88218 - dest = mod->module_init
88219 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
88220 - else
88221 - dest = mod->module_core + shdr->sh_entsize;
88222 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
88223 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
88224 + dest = mod->module_init_rw
88225 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
88226 + else
88227 + dest = mod->module_init_rx
88228 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
88229 + } else {
88230 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
88231 + dest = mod->module_core_rw + shdr->sh_entsize;
88232 + else
88233 + dest = mod->module_core_rx + shdr->sh_entsize;
88234 + }
88235 +
88236 + if (shdr->sh_type != SHT_NOBITS) {
88237 +
88238 +#ifdef CONFIG_PAX_KERNEXEC
88239 +#ifdef CONFIG_X86_64
88240 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
88241 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
88242 +#endif
88243 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
88244 + pax_open_kernel();
88245 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
88246 + pax_close_kernel();
88247 + } else
88248 +#endif
88249
88250 - if (shdr->sh_type != SHT_NOBITS)
88251 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
88252 + }
88253 /* Update sh_addr to point to copy in image. */
88254 - shdr->sh_addr = (unsigned long)dest;
88255 +
88256 +#ifdef CONFIG_PAX_KERNEXEC
88257 + if (shdr->sh_flags & SHF_EXECINSTR)
88258 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
88259 + else
88260 +#endif
88261 +
88262 + shdr->sh_addr = (unsigned long)dest;
88263 pr_debug("\t0x%lx %s\n",
88264 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
88265 }
88266 @@ -2894,12 +3024,12 @@ static void flush_module_icache(const struct module *mod)
88267 * Do it before processing of module parameters, so the module
88268 * can provide parameter accessor functions of its own.
88269 */
88270 - if (mod->module_init)
88271 - flush_icache_range((unsigned long)mod->module_init,
88272 - (unsigned long)mod->module_init
88273 - + mod->init_size);
88274 - flush_icache_range((unsigned long)mod->module_core,
88275 - (unsigned long)mod->module_core + mod->core_size);
88276 + if (mod->module_init_rx)
88277 + flush_icache_range((unsigned long)mod->module_init_rx,
88278 + (unsigned long)mod->module_init_rx
88279 + + mod->init_size_rx);
88280 + flush_icache_range((unsigned long)mod->module_core_rx,
88281 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
88282
88283 set_fs(old_fs);
88284 }
88285 @@ -2956,8 +3086,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
88286 static void module_deallocate(struct module *mod, struct load_info *info)
88287 {
88288 percpu_modfree(mod);
88289 - module_free(mod, mod->module_init);
88290 - module_free(mod, mod->module_core);
88291 + module_free_exec(mod, mod->module_init_rx);
88292 + module_free_exec(mod, mod->module_core_rx);
88293 + module_free(mod, mod->module_init_rw);
88294 + module_free(mod, mod->module_core_rw);
88295 }
88296
88297 int __weak module_finalize(const Elf_Ehdr *hdr,
88298 @@ -2970,7 +3102,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
88299 static int post_relocation(struct module *mod, const struct load_info *info)
88300 {
88301 /* Sort exception table now relocations are done. */
88302 + pax_open_kernel();
88303 sort_extable(mod->extable, mod->extable + mod->num_exentries);
88304 + pax_close_kernel();
88305
88306 /* Copy relocated percpu area over. */
88307 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
88308 @@ -3024,16 +3158,16 @@ static int do_init_module(struct module *mod)
88309 MODULE_STATE_COMING, mod);
88310
88311 /* Set RO and NX regions for core */
88312 - set_section_ro_nx(mod->module_core,
88313 - mod->core_text_size,
88314 - mod->core_ro_size,
88315 - mod->core_size);
88316 + set_section_ro_nx(mod->module_core_rx,
88317 + mod->core_size_rx,
88318 + mod->core_size_rx,
88319 + mod->core_size_rx);
88320
88321 /* Set RO and NX regions for init */
88322 - set_section_ro_nx(mod->module_init,
88323 - mod->init_text_size,
88324 - mod->init_ro_size,
88325 - mod->init_size);
88326 + set_section_ro_nx(mod->module_init_rx,
88327 + mod->init_size_rx,
88328 + mod->init_size_rx,
88329 + mod->init_size_rx);
88330
88331 do_mod_ctors(mod);
88332 /* Start the module */
88333 @@ -3094,11 +3228,12 @@ static int do_init_module(struct module *mod)
88334 mod->strtab = mod->core_strtab;
88335 #endif
88336 unset_module_init_ro_nx(mod);
88337 - module_free(mod, mod->module_init);
88338 - mod->module_init = NULL;
88339 - mod->init_size = 0;
88340 - mod->init_ro_size = 0;
88341 - mod->init_text_size = 0;
88342 + module_free(mod, mod->module_init_rw);
88343 + module_free_exec(mod, mod->module_init_rx);
88344 + mod->module_init_rw = NULL;
88345 + mod->module_init_rx = NULL;
88346 + mod->init_size_rw = 0;
88347 + mod->init_size_rx = 0;
88348 mutex_unlock(&module_mutex);
88349 wake_up_all(&module_wq);
88350
88351 @@ -3241,9 +3376,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
88352 if (err)
88353 goto free_unload;
88354
88355 + /* Now copy in args */
88356 + mod->args = strndup_user(uargs, ~0UL >> 1);
88357 + if (IS_ERR(mod->args)) {
88358 + err = PTR_ERR(mod->args);
88359 + goto free_unload;
88360 + }
88361 +
88362 /* Set up MODINFO_ATTR fields */
88363 setup_modinfo(mod, info);
88364
88365 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
88366 + {
88367 + char *p, *p2;
88368 +
88369 + if (strstr(mod->args, "grsec_modharden_netdev")) {
88370 + 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);
88371 + err = -EPERM;
88372 + goto free_modinfo;
88373 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
88374 + p += sizeof("grsec_modharden_normal") - 1;
88375 + p2 = strstr(p, "_");
88376 + if (p2) {
88377 + *p2 = '\0';
88378 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
88379 + *p2 = '_';
88380 + }
88381 + err = -EPERM;
88382 + goto free_modinfo;
88383 + }
88384 + }
88385 +#endif
88386 +
88387 /* Fix up syms, so that st_value is a pointer to location. */
88388 err = simplify_symbols(mod, info);
88389 if (err < 0)
88390 @@ -3259,13 +3423,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
88391
88392 flush_module_icache(mod);
88393
88394 - /* Now copy in args */
88395 - mod->args = strndup_user(uargs, ~0UL >> 1);
88396 - if (IS_ERR(mod->args)) {
88397 - err = PTR_ERR(mod->args);
88398 - goto free_arch_cleanup;
88399 - }
88400 -
88401 dynamic_debug_setup(info->debug, info->num_debug);
88402
88403 /* Ftrace init must be called in the MODULE_STATE_UNFORMED state */
88404 @@ -3303,11 +3460,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
88405 ddebug_cleanup:
88406 dynamic_debug_remove(info->debug);
88407 synchronize_sched();
88408 - kfree(mod->args);
88409 - free_arch_cleanup:
88410 module_arch_cleanup(mod);
88411 free_modinfo:
88412 free_modinfo(mod);
88413 + kfree(mod->args);
88414 free_unload:
88415 module_unload_free(mod);
88416 unlink_mod:
88417 @@ -3390,10 +3546,16 @@ static const char *get_ksymbol(struct module *mod,
88418 unsigned long nextval;
88419
88420 /* At worse, next value is at end of module */
88421 - if (within_module_init(addr, mod))
88422 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
88423 + if (within_module_init_rx(addr, mod))
88424 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
88425 + else if (within_module_init_rw(addr, mod))
88426 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
88427 + else if (within_module_core_rx(addr, mod))
88428 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
88429 + else if (within_module_core_rw(addr, mod))
88430 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
88431 else
88432 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
88433 + return NULL;
88434
88435 /* Scan for closest preceding symbol, and next symbol. (ELF
88436 starts real symbols at 1). */
88437 @@ -3644,7 +3806,7 @@ static int m_show(struct seq_file *m, void *p)
88438 return 0;
88439
88440 seq_printf(m, "%s %u",
88441 - mod->name, mod->init_size + mod->core_size);
88442 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
88443 print_unload_info(m, mod);
88444
88445 /* Informative for users. */
88446 @@ -3653,7 +3815,7 @@ static int m_show(struct seq_file *m, void *p)
88447 mod->state == MODULE_STATE_COMING ? "Loading":
88448 "Live");
88449 /* Used by oprofile and other similar tools. */
88450 - seq_printf(m, " 0x%pK", mod->module_core);
88451 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
88452
88453 /* Taints info */
88454 if (mod->taints)
88455 @@ -3689,7 +3851,17 @@ static const struct file_operations proc_modules_operations = {
88456
88457 static int __init proc_modules_init(void)
88458 {
88459 +#ifndef CONFIG_GRKERNSEC_HIDESYM
88460 +#ifdef CONFIG_GRKERNSEC_PROC_USER
88461 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
88462 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
88463 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
88464 +#else
88465 proc_create("modules", 0, NULL, &proc_modules_operations);
88466 +#endif
88467 +#else
88468 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
88469 +#endif
88470 return 0;
88471 }
88472 module_init(proc_modules_init);
88473 @@ -3750,14 +3922,14 @@ struct module *__module_address(unsigned long addr)
88474 {
88475 struct module *mod;
88476
88477 - if (addr < module_addr_min || addr > module_addr_max)
88478 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
88479 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
88480 return NULL;
88481
88482 list_for_each_entry_rcu(mod, &modules, list) {
88483 if (mod->state == MODULE_STATE_UNFORMED)
88484 continue;
88485 - if (within_module_core(addr, mod)
88486 - || within_module_init(addr, mod))
88487 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
88488 return mod;
88489 }
88490 return NULL;
88491 @@ -3792,11 +3964,20 @@ bool is_module_text_address(unsigned long addr)
88492 */
88493 struct module *__module_text_address(unsigned long addr)
88494 {
88495 - struct module *mod = __module_address(addr);
88496 + struct module *mod;
88497 +
88498 +#ifdef CONFIG_X86_32
88499 + addr = ktla_ktva(addr);
88500 +#endif
88501 +
88502 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
88503 + return NULL;
88504 +
88505 + mod = __module_address(addr);
88506 +
88507 if (mod) {
88508 /* Make sure it's within the text section. */
88509 - if (!within(addr, mod->module_init, mod->init_text_size)
88510 - && !within(addr, mod->module_core, mod->core_text_size))
88511 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
88512 mod = NULL;
88513 }
88514 return mod;
88515 diff --git a/kernel/notifier.c b/kernel/notifier.c
88516 index db4c8b0..ad011c5 100644
88517 --- a/kernel/notifier.c
88518 +++ b/kernel/notifier.c
88519 @@ -5,6 +5,7 @@
88520 #include <linux/rcupdate.h>
88521 #include <linux/vmalloc.h>
88522 #include <linux/reboot.h>
88523 +#include <linux/mm.h>
88524
88525 /*
88526 * Notifier list for kernel code which wants to be called
88527 @@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
88528 while ((*nl) != NULL) {
88529 if (n->priority > (*nl)->priority)
88530 break;
88531 - nl = &((*nl)->next);
88532 + nl = (struct notifier_block **)&((*nl)->next);
88533 }
88534 - n->next = *nl;
88535 + pax_open_kernel();
88536 + *(const void **)&n->next = *nl;
88537 rcu_assign_pointer(*nl, n);
88538 + pax_close_kernel();
88539 return 0;
88540 }
88541
88542 @@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
88543 return 0;
88544 if (n->priority > (*nl)->priority)
88545 break;
88546 - nl = &((*nl)->next);
88547 + nl = (struct notifier_block **)&((*nl)->next);
88548 }
88549 - n->next = *nl;
88550 + pax_open_kernel();
88551 + *(const void **)&n->next = *nl;
88552 rcu_assign_pointer(*nl, n);
88553 + pax_close_kernel();
88554 return 0;
88555 }
88556
88557 @@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
88558 {
88559 while ((*nl) != NULL) {
88560 if ((*nl) == n) {
88561 + pax_open_kernel();
88562 rcu_assign_pointer(*nl, n->next);
88563 + pax_close_kernel();
88564 return 0;
88565 }
88566 - nl = &((*nl)->next);
88567 + nl = (struct notifier_block **)&((*nl)->next);
88568 }
88569 return -ENOENT;
88570 }
88571 diff --git a/kernel/padata.c b/kernel/padata.c
88572 index 161402f..598814c 100644
88573 --- a/kernel/padata.c
88574 +++ b/kernel/padata.c
88575 @@ -54,7 +54,7 @@ static int padata_cpu_hash(struct parallel_data *pd)
88576 * seq_nr mod. number of cpus in use.
88577 */
88578
88579 - seq_nr = atomic_inc_return(&pd->seq_nr);
88580 + seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
88581 cpu_index = seq_nr % cpumask_weight(pd->cpumask.pcpu);
88582
88583 return padata_index_to_cpu(pd, cpu_index);
88584 @@ -428,7 +428,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
88585 padata_init_pqueues(pd);
88586 padata_init_squeues(pd);
88587 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
88588 - atomic_set(&pd->seq_nr, -1);
88589 + atomic_set_unchecked(&pd->seq_nr, -1);
88590 atomic_set(&pd->reorder_objects, 0);
88591 atomic_set(&pd->refcnt, 0);
88592 pd->pinst = pinst;
88593 diff --git a/kernel/panic.c b/kernel/panic.c
88594 index d02fa9f..9faec0a 100644
88595 --- a/kernel/panic.c
88596 +++ b/kernel/panic.c
88597 @@ -52,7 +52,7 @@ EXPORT_SYMBOL(panic_blink);
88598 /*
88599 * Stop ourself in panic -- architecture code may override this
88600 */
88601 -void __weak panic_smp_self_stop(void)
88602 +void __weak __noreturn panic_smp_self_stop(void)
88603 {
88604 while (1)
88605 cpu_relax();
88606 @@ -408,7 +408,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
88607 disable_trace_on_warning();
88608
88609 pr_warn("------------[ cut here ]------------\n");
88610 - pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
88611 + pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
88612 raw_smp_processor_id(), current->pid, file, line, caller);
88613
88614 if (args)
88615 @@ -462,7 +462,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
88616 */
88617 __visible void __stack_chk_fail(void)
88618 {
88619 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
88620 + dump_stack();
88621 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
88622 __builtin_return_address(0));
88623 }
88624 EXPORT_SYMBOL(__stack_chk_fail);
88625 diff --git a/kernel/pid.c b/kernel/pid.c
88626 index 9b9a266..c20ef80 100644
88627 --- a/kernel/pid.c
88628 +++ b/kernel/pid.c
88629 @@ -33,6 +33,7 @@
88630 #include <linux/rculist.h>
88631 #include <linux/bootmem.h>
88632 #include <linux/hash.h>
88633 +#include <linux/security.h>
88634 #include <linux/pid_namespace.h>
88635 #include <linux/init_task.h>
88636 #include <linux/syscalls.h>
88637 @@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
88638
88639 int pid_max = PID_MAX_DEFAULT;
88640
88641 -#define RESERVED_PIDS 300
88642 +#define RESERVED_PIDS 500
88643
88644 int pid_max_min = RESERVED_PIDS + 1;
88645 int pid_max_max = PID_MAX_LIMIT;
88646 @@ -445,10 +446,18 @@ EXPORT_SYMBOL(pid_task);
88647 */
88648 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
88649 {
88650 + struct task_struct *task;
88651 +
88652 rcu_lockdep_assert(rcu_read_lock_held(),
88653 "find_task_by_pid_ns() needs rcu_read_lock()"
88654 " protection");
88655 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
88656 +
88657 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
88658 +
88659 + if (gr_pid_is_chrooted(task))
88660 + return NULL;
88661 +
88662 + return task;
88663 }
88664
88665 struct task_struct *find_task_by_vpid(pid_t vnr)
88666 @@ -456,6 +465,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
88667 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
88668 }
88669
88670 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
88671 +{
88672 + rcu_lockdep_assert(rcu_read_lock_held(),
88673 + "find_task_by_pid_ns() needs rcu_read_lock()"
88674 + " protection");
88675 + return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
88676 +}
88677 +
88678 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
88679 {
88680 struct pid *pid;
88681 diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
88682 index db95d8e..a0ca23f 100644
88683 --- a/kernel/pid_namespace.c
88684 +++ b/kernel/pid_namespace.c
88685 @@ -253,7 +253,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
88686 void __user *buffer, size_t *lenp, loff_t *ppos)
88687 {
88688 struct pid_namespace *pid_ns = task_active_pid_ns(current);
88689 - struct ctl_table tmp = *table;
88690 + ctl_table_no_const tmp = *table;
88691
88692 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
88693 return -EPERM;
88694 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
88695 index 3b89464..5e38379 100644
88696 --- a/kernel/posix-cpu-timers.c
88697 +++ b/kernel/posix-cpu-timers.c
88698 @@ -1464,14 +1464,14 @@ struct k_clock clock_posix_cpu = {
88699
88700 static __init int init_posix_cpu_timers(void)
88701 {
88702 - struct k_clock process = {
88703 + static struct k_clock process = {
88704 .clock_getres = process_cpu_clock_getres,
88705 .clock_get = process_cpu_clock_get,
88706 .timer_create = process_cpu_timer_create,
88707 .nsleep = process_cpu_nsleep,
88708 .nsleep_restart = process_cpu_nsleep_restart,
88709 };
88710 - struct k_clock thread = {
88711 + static struct k_clock thread = {
88712 .clock_getres = thread_cpu_clock_getres,
88713 .clock_get = thread_cpu_clock_get,
88714 .timer_create = thread_cpu_timer_create,
88715 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
88716 index 424c2d4..679242f 100644
88717 --- a/kernel/posix-timers.c
88718 +++ b/kernel/posix-timers.c
88719 @@ -43,6 +43,7 @@
88720 #include <linux/hash.h>
88721 #include <linux/posix-clock.h>
88722 #include <linux/posix-timers.h>
88723 +#include <linux/grsecurity.h>
88724 #include <linux/syscalls.h>
88725 #include <linux/wait.h>
88726 #include <linux/workqueue.h>
88727 @@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
88728 * which we beg off on and pass to do_sys_settimeofday().
88729 */
88730
88731 -static struct k_clock posix_clocks[MAX_CLOCKS];
88732 +static struct k_clock *posix_clocks[MAX_CLOCKS];
88733
88734 /*
88735 * These ones are defined below.
88736 @@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
88737 */
88738 static __init int init_posix_timers(void)
88739 {
88740 - struct k_clock clock_realtime = {
88741 + static struct k_clock clock_realtime = {
88742 .clock_getres = hrtimer_get_res,
88743 .clock_get = posix_clock_realtime_get,
88744 .clock_set = posix_clock_realtime_set,
88745 @@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
88746 .timer_get = common_timer_get,
88747 .timer_del = common_timer_del,
88748 };
88749 - struct k_clock clock_monotonic = {
88750 + static struct k_clock clock_monotonic = {
88751 .clock_getres = hrtimer_get_res,
88752 .clock_get = posix_ktime_get_ts,
88753 .nsleep = common_nsleep,
88754 @@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
88755 .timer_get = common_timer_get,
88756 .timer_del = common_timer_del,
88757 };
88758 - struct k_clock clock_monotonic_raw = {
88759 + static struct k_clock clock_monotonic_raw = {
88760 .clock_getres = hrtimer_get_res,
88761 .clock_get = posix_get_monotonic_raw,
88762 };
88763 - struct k_clock clock_realtime_coarse = {
88764 + static struct k_clock clock_realtime_coarse = {
88765 .clock_getres = posix_get_coarse_res,
88766 .clock_get = posix_get_realtime_coarse,
88767 };
88768 - struct k_clock clock_monotonic_coarse = {
88769 + static struct k_clock clock_monotonic_coarse = {
88770 .clock_getres = posix_get_coarse_res,
88771 .clock_get = posix_get_monotonic_coarse,
88772 };
88773 - struct k_clock clock_tai = {
88774 + static struct k_clock clock_tai = {
88775 .clock_getres = hrtimer_get_res,
88776 .clock_get = posix_get_tai,
88777 .nsleep = common_nsleep,
88778 @@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
88779 .timer_get = common_timer_get,
88780 .timer_del = common_timer_del,
88781 };
88782 - struct k_clock clock_boottime = {
88783 + static struct k_clock clock_boottime = {
88784 .clock_getres = hrtimer_get_res,
88785 .clock_get = posix_get_boottime,
88786 .nsleep = common_nsleep,
88787 @@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
88788 return;
88789 }
88790
88791 - posix_clocks[clock_id] = *new_clock;
88792 + posix_clocks[clock_id] = new_clock;
88793 }
88794 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
88795
88796 @@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
88797 return (id & CLOCKFD_MASK) == CLOCKFD ?
88798 &clock_posix_dynamic : &clock_posix_cpu;
88799
88800 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
88801 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
88802 return NULL;
88803 - return &posix_clocks[id];
88804 + return posix_clocks[id];
88805 }
88806
88807 static int common_timer_create(struct k_itimer *new_timer)
88808 @@ -597,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
88809 struct k_clock *kc = clockid_to_kclock(which_clock);
88810 struct k_itimer *new_timer;
88811 int error, new_timer_id;
88812 - sigevent_t event;
88813 + sigevent_t event = { };
88814 int it_id_set = IT_ID_NOT_SET;
88815
88816 if (!kc)
88817 @@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
88818 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
88819 return -EFAULT;
88820
88821 + /* only the CLOCK_REALTIME clock can be set, all other clocks
88822 + have their clock_set fptr set to a nosettime dummy function
88823 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
88824 + call common_clock_set, which calls do_sys_settimeofday, which
88825 + we hook
88826 + */
88827 +
88828 return kc->clock_set(which_clock, &new_tp);
88829 }
88830
88831 diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
88832 index 2fac9cc..56fef29 100644
88833 --- a/kernel/power/Kconfig
88834 +++ b/kernel/power/Kconfig
88835 @@ -24,6 +24,8 @@ config HIBERNATE_CALLBACKS
88836 config HIBERNATION
88837 bool "Hibernation (aka 'suspend to disk')"
88838 depends on SWAP && ARCH_HIBERNATION_POSSIBLE
88839 + depends on !GRKERNSEC_KMEM
88840 + depends on !PAX_MEMORY_SANITIZE
88841 select HIBERNATE_CALLBACKS
88842 select LZO_COMPRESS
88843 select LZO_DECOMPRESS
88844 diff --git a/kernel/power/process.c b/kernel/power/process.c
88845 index 06ec886..9dba35e 100644
88846 --- a/kernel/power/process.c
88847 +++ b/kernel/power/process.c
88848 @@ -34,6 +34,7 @@ static int try_to_freeze_tasks(bool user_only)
88849 unsigned int elapsed_msecs;
88850 bool wakeup = false;
88851 int sleep_usecs = USEC_PER_MSEC;
88852 + bool timedout = false;
88853
88854 do_gettimeofday(&start);
88855
88856 @@ -44,13 +45,20 @@ static int try_to_freeze_tasks(bool user_only)
88857
88858 while (true) {
88859 todo = 0;
88860 + if (time_after(jiffies, end_time))
88861 + timedout = true;
88862 read_lock(&tasklist_lock);
88863 do_each_thread(g, p) {
88864 if (p == current || !freeze_task(p))
88865 continue;
88866
88867 - if (!freezer_should_skip(p))
88868 + if (!freezer_should_skip(p)) {
88869 todo++;
88870 + if (timedout) {
88871 + printk(KERN_ERR "Task refusing to freeze:\n");
88872 + sched_show_task(p);
88873 + }
88874 + }
88875 } while_each_thread(g, p);
88876 read_unlock(&tasklist_lock);
88877
88878 @@ -59,7 +67,7 @@ static int try_to_freeze_tasks(bool user_only)
88879 todo += wq_busy;
88880 }
88881
88882 - if (!todo || time_after(jiffies, end_time))
88883 + if (!todo || timedout)
88884 break;
88885
88886 if (pm_wakeup_pending()) {
88887 diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
88888 index 221229c..c76ca0a 100644
88889 --- a/kernel/printk/printk.c
88890 +++ b/kernel/printk/printk.c
88891 @@ -385,6 +385,11 @@ static int check_syslog_permissions(int type, bool from_file)
88892 if (from_file && type != SYSLOG_ACTION_OPEN)
88893 return 0;
88894
88895 +#ifdef CONFIG_GRKERNSEC_DMESG
88896 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
88897 + return -EPERM;
88898 +#endif
88899 +
88900 if (syslog_action_restricted(type)) {
88901 if (capable(CAP_SYSLOG))
88902 return 0;
88903 diff --git a/kernel/profile.c b/kernel/profile.c
88904 index cb980f0..ccd8782 100644
88905 --- a/kernel/profile.c
88906 +++ b/kernel/profile.c
88907 @@ -37,7 +37,7 @@ struct profile_hit {
88908 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
88909 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
88910
88911 -static atomic_t *prof_buffer;
88912 +static atomic_unchecked_t *prof_buffer;
88913 static unsigned long prof_len, prof_shift;
88914
88915 int prof_on __read_mostly;
88916 @@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
88917 hits[i].pc = 0;
88918 continue;
88919 }
88920 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
88921 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
88922 hits[i].hits = hits[i].pc = 0;
88923 }
88924 }
88925 @@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
88926 * Add the current hit(s) and flush the write-queue out
88927 * to the global buffer:
88928 */
88929 - atomic_add(nr_hits, &prof_buffer[pc]);
88930 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
88931 for (i = 0; i < NR_PROFILE_HIT; ++i) {
88932 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
88933 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
88934 hits[i].pc = hits[i].hits = 0;
88935 }
88936 out:
88937 @@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
88938 {
88939 unsigned long pc;
88940 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
88941 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
88942 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
88943 }
88944 #endif /* !CONFIG_SMP */
88945
88946 @@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
88947 return -EFAULT;
88948 buf++; p++; count--; read++;
88949 }
88950 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
88951 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
88952 if (copy_to_user(buf, (void *)pnt, count))
88953 return -EFAULT;
88954 read += count;
88955 @@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
88956 }
88957 #endif
88958 profile_discard_flip_buffers();
88959 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
88960 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
88961 return count;
88962 }
88963
88964 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
88965 index adf9862..9d86345 100644
88966 --- a/kernel/ptrace.c
88967 +++ b/kernel/ptrace.c
88968 @@ -327,7 +327,7 @@ static int ptrace_attach(struct task_struct *task, long request,
88969 if (seize)
88970 flags |= PT_SEIZED;
88971 rcu_read_lock();
88972 - if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
88973 + if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
88974 flags |= PT_PTRACE_CAP;
88975 rcu_read_unlock();
88976 task->ptrace = flags;
88977 @@ -538,7 +538,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
88978 break;
88979 return -EIO;
88980 }
88981 - if (copy_to_user(dst, buf, retval))
88982 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
88983 return -EFAULT;
88984 copied += retval;
88985 src += retval;
88986 @@ -806,7 +806,7 @@ int ptrace_request(struct task_struct *child, long request,
88987 bool seized = child->ptrace & PT_SEIZED;
88988 int ret = -EIO;
88989 siginfo_t siginfo, *si;
88990 - void __user *datavp = (void __user *) data;
88991 + void __user *datavp = (__force void __user *) data;
88992 unsigned long __user *datalp = datavp;
88993 unsigned long flags;
88994
88995 @@ -1052,14 +1052,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
88996 goto out;
88997 }
88998
88999 + if (gr_handle_ptrace(child, request)) {
89000 + ret = -EPERM;
89001 + goto out_put_task_struct;
89002 + }
89003 +
89004 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
89005 ret = ptrace_attach(child, request, addr, data);
89006 /*
89007 * Some architectures need to do book-keeping after
89008 * a ptrace attach.
89009 */
89010 - if (!ret)
89011 + if (!ret) {
89012 arch_ptrace_attach(child);
89013 + gr_audit_ptrace(child);
89014 + }
89015 goto out_put_task_struct;
89016 }
89017
89018 @@ -1087,7 +1094,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
89019 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
89020 if (copied != sizeof(tmp))
89021 return -EIO;
89022 - return put_user(tmp, (unsigned long __user *)data);
89023 + return put_user(tmp, (__force unsigned long __user *)data);
89024 }
89025
89026 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
89027 @@ -1181,7 +1188,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
89028 }
89029
89030 COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
89031 - compat_long_t, addr, compat_long_t, data)
89032 + compat_ulong_t, addr, compat_ulong_t, data)
89033 {
89034 struct task_struct *child;
89035 long ret;
89036 @@ -1197,14 +1204,21 @@ COMPAT_SYSCALL_DEFINE4(ptrace, compat_long_t, request, compat_long_t, pid,
89037 goto out;
89038 }
89039
89040 + if (gr_handle_ptrace(child, request)) {
89041 + ret = -EPERM;
89042 + goto out_put_task_struct;
89043 + }
89044 +
89045 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
89046 ret = ptrace_attach(child, request, addr, data);
89047 /*
89048 * Some architectures need to do book-keeping after
89049 * a ptrace attach.
89050 */
89051 - if (!ret)
89052 + if (!ret) {
89053 arch_ptrace_attach(child);
89054 + gr_audit_ptrace(child);
89055 + }
89056 goto out_put_task_struct;
89057 }
89058
89059 diff --git a/kernel/rcu/rcutorture.c b/kernel/rcu/rcutorture.c
89060 index bd30bc6..dce23da 100644
89061 --- a/kernel/rcu/rcutorture.c
89062 +++ b/kernel/rcu/rcutorture.c
89063 @@ -122,12 +122,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
89064 rcu_torture_count) = { 0 };
89065 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1],
89066 rcu_torture_batch) = { 0 };
89067 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
89068 -static atomic_t n_rcu_torture_alloc;
89069 -static atomic_t n_rcu_torture_alloc_fail;
89070 -static atomic_t n_rcu_torture_free;
89071 -static atomic_t n_rcu_torture_mberror;
89072 -static atomic_t n_rcu_torture_error;
89073 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
89074 +static atomic_unchecked_t n_rcu_torture_alloc;
89075 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
89076 +static atomic_unchecked_t n_rcu_torture_free;
89077 +static atomic_unchecked_t n_rcu_torture_mberror;
89078 +static atomic_unchecked_t n_rcu_torture_error;
89079 static long n_rcu_torture_barrier_error;
89080 static long n_rcu_torture_boost_ktrerror;
89081 static long n_rcu_torture_boost_rterror;
89082 @@ -186,11 +186,11 @@ rcu_torture_alloc(void)
89083
89084 spin_lock_bh(&rcu_torture_lock);
89085 if (list_empty(&rcu_torture_freelist)) {
89086 - atomic_inc(&n_rcu_torture_alloc_fail);
89087 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
89088 spin_unlock_bh(&rcu_torture_lock);
89089 return NULL;
89090 }
89091 - atomic_inc(&n_rcu_torture_alloc);
89092 + atomic_inc_unchecked(&n_rcu_torture_alloc);
89093 p = rcu_torture_freelist.next;
89094 list_del_init(p);
89095 spin_unlock_bh(&rcu_torture_lock);
89096 @@ -203,7 +203,7 @@ rcu_torture_alloc(void)
89097 static void
89098 rcu_torture_free(struct rcu_torture *p)
89099 {
89100 - atomic_inc(&n_rcu_torture_free);
89101 + atomic_inc_unchecked(&n_rcu_torture_free);
89102 spin_lock_bh(&rcu_torture_lock);
89103 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
89104 spin_unlock_bh(&rcu_torture_lock);
89105 @@ -287,7 +287,7 @@ rcu_torture_cb(struct rcu_head *p)
89106 i = rp->rtort_pipe_count;
89107 if (i > RCU_TORTURE_PIPE_LEN)
89108 i = RCU_TORTURE_PIPE_LEN;
89109 - atomic_inc(&rcu_torture_wcount[i]);
89110 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
89111 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
89112 rp->rtort_mbtest = 0;
89113 rcu_torture_free(rp);
89114 @@ -714,7 +714,7 @@ rcu_torture_writer(void *arg)
89115 i = old_rp->rtort_pipe_count;
89116 if (i > RCU_TORTURE_PIPE_LEN)
89117 i = RCU_TORTURE_PIPE_LEN;
89118 - atomic_inc(&rcu_torture_wcount[i]);
89119 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
89120 old_rp->rtort_pipe_count++;
89121 if (gp_normal == gp_exp)
89122 exp = !!(torture_random(&rand) & 0x80);
89123 @@ -732,7 +732,7 @@ rcu_torture_writer(void *arg)
89124 i = rp->rtort_pipe_count;
89125 if (i > RCU_TORTURE_PIPE_LEN)
89126 i = RCU_TORTURE_PIPE_LEN;
89127 - atomic_inc(&rcu_torture_wcount[i]);
89128 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
89129 if (++rp->rtort_pipe_count >=
89130 RCU_TORTURE_PIPE_LEN) {
89131 rp->rtort_mbtest = 0;
89132 @@ -825,7 +825,7 @@ static void rcu_torture_timer(unsigned long unused)
89133 return;
89134 }
89135 if (p->rtort_mbtest == 0)
89136 - atomic_inc(&n_rcu_torture_mberror);
89137 + atomic_inc_unchecked(&n_rcu_torture_mberror);
89138 spin_lock(&rand_lock);
89139 cur_ops->read_delay(&rand);
89140 n_rcu_torture_timers++;
89141 @@ -895,7 +895,7 @@ rcu_torture_reader(void *arg)
89142 continue;
89143 }
89144 if (p->rtort_mbtest == 0)
89145 - atomic_inc(&n_rcu_torture_mberror);
89146 + atomic_inc_unchecked(&n_rcu_torture_mberror);
89147 cur_ops->read_delay(&rand);
89148 preempt_disable();
89149 pipe_count = p->rtort_pipe_count;
89150 @@ -950,15 +950,15 @@ rcu_torture_printk(char *page)
89151 }
89152 page += sprintf(page, "%s%s ", torture_type, TORTURE_FLAG);
89153 page += sprintf(page,
89154 - "rtc: %p ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
89155 + "rtc: %pP ver: %lu tfle: %d rta: %d rtaf: %d rtf: %d ",
89156 rcu_torture_current,
89157 rcu_torture_current_version,
89158 list_empty(&rcu_torture_freelist),
89159 - atomic_read(&n_rcu_torture_alloc),
89160 - atomic_read(&n_rcu_torture_alloc_fail),
89161 - atomic_read(&n_rcu_torture_free));
89162 + atomic_read_unchecked(&n_rcu_torture_alloc),
89163 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
89164 + atomic_read_unchecked(&n_rcu_torture_free));
89165 page += sprintf(page, "rtmbe: %d rtbke: %ld rtbre: %ld ",
89166 - atomic_read(&n_rcu_torture_mberror),
89167 + atomic_read_unchecked(&n_rcu_torture_mberror),
89168 n_rcu_torture_boost_ktrerror,
89169 n_rcu_torture_boost_rterror);
89170 page += sprintf(page, "rtbf: %ld rtb: %ld nt: %ld ",
89171 @@ -971,14 +971,14 @@ rcu_torture_printk(char *page)
89172 n_barrier_attempts,
89173 n_rcu_torture_barrier_error);
89174 page += sprintf(page, "\n%s%s ", torture_type, TORTURE_FLAG);
89175 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
89176 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
89177 n_rcu_torture_barrier_error != 0 ||
89178 n_rcu_torture_boost_ktrerror != 0 ||
89179 n_rcu_torture_boost_rterror != 0 ||
89180 n_rcu_torture_boost_failure != 0 ||
89181 i > 1) {
89182 page += sprintf(page, "!!! ");
89183 - atomic_inc(&n_rcu_torture_error);
89184 + atomic_inc_unchecked(&n_rcu_torture_error);
89185 WARN_ON_ONCE(1);
89186 }
89187 page += sprintf(page, "Reader Pipe: ");
89188 @@ -992,7 +992,7 @@ rcu_torture_printk(char *page)
89189 page += sprintf(page, "Free-Block Circulation: ");
89190 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
89191 page += sprintf(page, " %d",
89192 - atomic_read(&rcu_torture_wcount[i]));
89193 + atomic_read_unchecked(&rcu_torture_wcount[i]));
89194 }
89195 page += sprintf(page, "\n");
89196 if (cur_ops->stats)
89197 @@ -1341,7 +1341,7 @@ rcu_torture_cleanup(void)
89198
89199 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
89200
89201 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
89202 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
89203 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
89204 else if (torture_onoff_failures())
89205 rcu_torture_print_module_parms(cur_ops,
89206 @@ -1460,18 +1460,18 @@ rcu_torture_init(void)
89207
89208 rcu_torture_current = NULL;
89209 rcu_torture_current_version = 0;
89210 - atomic_set(&n_rcu_torture_alloc, 0);
89211 - atomic_set(&n_rcu_torture_alloc_fail, 0);
89212 - atomic_set(&n_rcu_torture_free, 0);
89213 - atomic_set(&n_rcu_torture_mberror, 0);
89214 - atomic_set(&n_rcu_torture_error, 0);
89215 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
89216 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
89217 + atomic_set_unchecked(&n_rcu_torture_free, 0);
89218 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
89219 + atomic_set_unchecked(&n_rcu_torture_error, 0);
89220 n_rcu_torture_barrier_error = 0;
89221 n_rcu_torture_boost_ktrerror = 0;
89222 n_rcu_torture_boost_rterror = 0;
89223 n_rcu_torture_boost_failure = 0;
89224 n_rcu_torture_boosts = 0;
89225 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
89226 - atomic_set(&rcu_torture_wcount[i], 0);
89227 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
89228 for_each_possible_cpu(cpu) {
89229 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
89230 per_cpu(rcu_torture_count, cpu)[i] = 0;
89231 diff --git a/kernel/rcu/srcu.c b/kernel/rcu/srcu.c
89232 index c639556..cf0a0d5 100644
89233 --- a/kernel/rcu/srcu.c
89234 +++ b/kernel/rcu/srcu.c
89235 @@ -298,9 +298,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
89236
89237 idx = ACCESS_ONCE(sp->completed) & 0x1;
89238 preempt_disable();
89239 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
89240 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
89241 smp_mb(); /* B */ /* Avoid leaking the critical section. */
89242 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
89243 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
89244 preempt_enable();
89245 return idx;
89246 }
89247 diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
89248 index d9efcc1..ea543e9 100644
89249 --- a/kernel/rcu/tiny.c
89250 +++ b/kernel/rcu/tiny.c
89251 @@ -42,7 +42,7 @@
89252 /* Forward declarations for tiny_plugin.h. */
89253 struct rcu_ctrlblk;
89254 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
89255 -static void rcu_process_callbacks(struct softirq_action *unused);
89256 +static void rcu_process_callbacks(void);
89257 static void __call_rcu(struct rcu_head *head,
89258 void (*func)(struct rcu_head *rcu),
89259 struct rcu_ctrlblk *rcp);
89260 @@ -308,7 +308,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
89261 false));
89262 }
89263
89264 -static void rcu_process_callbacks(struct softirq_action *unused)
89265 +static __latent_entropy void rcu_process_callbacks(void)
89266 {
89267 __rcu_process_callbacks(&rcu_sched_ctrlblk);
89268 __rcu_process_callbacks(&rcu_bh_ctrlblk);
89269 diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
89270 index 0c47e30..a084591 100644
89271 --- a/kernel/rcu/tree.c
89272 +++ b/kernel/rcu/tree.c
89273 @@ -388,9 +388,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
89274 rcu_prepare_for_idle(smp_processor_id());
89275 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
89276 smp_mb__before_atomic_inc(); /* See above. */
89277 - atomic_inc(&rdtp->dynticks);
89278 + atomic_inc_unchecked(&rdtp->dynticks);
89279 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
89280 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
89281 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
89282
89283 /*
89284 * It is illegal to enter an extended quiescent state while
89285 @@ -508,10 +508,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
89286 int user)
89287 {
89288 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
89289 - atomic_inc(&rdtp->dynticks);
89290 + atomic_inc_unchecked(&rdtp->dynticks);
89291 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
89292 smp_mb__after_atomic_inc(); /* See above. */
89293 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
89294 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
89295 rcu_cleanup_after_idle(smp_processor_id());
89296 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
89297 if (!user && !is_idle_task(current)) {
89298 @@ -632,14 +632,14 @@ void rcu_nmi_enter(void)
89299 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
89300
89301 if (rdtp->dynticks_nmi_nesting == 0 &&
89302 - (atomic_read(&rdtp->dynticks) & 0x1))
89303 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
89304 return;
89305 rdtp->dynticks_nmi_nesting++;
89306 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
89307 - atomic_inc(&rdtp->dynticks);
89308 + atomic_inc_unchecked(&rdtp->dynticks);
89309 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
89310 smp_mb__after_atomic_inc(); /* See above. */
89311 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
89312 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
89313 }
89314
89315 /**
89316 @@ -658,9 +658,9 @@ void rcu_nmi_exit(void)
89317 return;
89318 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
89319 smp_mb__before_atomic_inc(); /* See above. */
89320 - atomic_inc(&rdtp->dynticks);
89321 + atomic_inc_unchecked(&rdtp->dynticks);
89322 smp_mb__after_atomic_inc(); /* Force delay to next write. */
89323 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
89324 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
89325 }
89326
89327 /**
89328 @@ -673,7 +673,7 @@ void rcu_nmi_exit(void)
89329 */
89330 bool notrace __rcu_is_watching(void)
89331 {
89332 - return atomic_read(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
89333 + return atomic_read_unchecked(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
89334 }
89335
89336 /**
89337 @@ -756,7 +756,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
89338 static int dyntick_save_progress_counter(struct rcu_data *rdp,
89339 bool *isidle, unsigned long *maxj)
89340 {
89341 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
89342 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
89343 rcu_sysidle_check_cpu(rdp, isidle, maxj);
89344 return (rdp->dynticks_snap & 0x1) == 0;
89345 }
89346 @@ -779,7 +779,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
89347 unsigned int curr;
89348 unsigned int snap;
89349
89350 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
89351 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
89352 snap = (unsigned int)rdp->dynticks_snap;
89353
89354 /*
89355 @@ -1449,9 +1449,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
89356 rdp = this_cpu_ptr(rsp->rda);
89357 rcu_preempt_check_blocked_tasks(rnp);
89358 rnp->qsmask = rnp->qsmaskinit;
89359 - ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
89360 + ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
89361 WARN_ON_ONCE(rnp->completed != rsp->completed);
89362 - ACCESS_ONCE(rnp->completed) = rsp->completed;
89363 + ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
89364 if (rnp == rdp->mynode)
89365 __note_gp_changes(rsp, rnp, rdp);
89366 rcu_preempt_boost_start_gp(rnp);
89367 @@ -1545,7 +1545,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
89368 rcu_for_each_node_breadth_first(rsp, rnp) {
89369 raw_spin_lock_irq(&rnp->lock);
89370 smp_mb__after_unlock_lock();
89371 - ACCESS_ONCE(rnp->completed) = rsp->gpnum;
89372 + ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
89373 rdp = this_cpu_ptr(rsp->rda);
89374 if (rnp == rdp->mynode)
89375 __note_gp_changes(rsp, rnp, rdp);
89376 @@ -1560,7 +1560,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
89377 rcu_nocb_gp_set(rnp, nocb);
89378
89379 /* Declare grace period done. */
89380 - ACCESS_ONCE(rsp->completed) = rsp->gpnum;
89381 + ACCESS_ONCE_RW(rsp->completed) = rsp->gpnum;
89382 trace_rcu_grace_period(rsp->name, rsp->completed, TPS("end"));
89383 rsp->fqs_state = RCU_GP_IDLE;
89384 rdp = this_cpu_ptr(rsp->rda);
89385 @@ -1912,7 +1912,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
89386 rsp->qlen += rdp->qlen;
89387 rdp->n_cbs_orphaned += rdp->qlen;
89388 rdp->qlen_lazy = 0;
89389 - ACCESS_ONCE(rdp->qlen) = 0;
89390 + ACCESS_ONCE_RW(rdp->qlen) = 0;
89391 }
89392
89393 /*
89394 @@ -2159,7 +2159,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
89395 }
89396 smp_mb(); /* List handling before counting for rcu_barrier(). */
89397 rdp->qlen_lazy -= count_lazy;
89398 - ACCESS_ONCE(rdp->qlen) -= count;
89399 + ACCESS_ONCE_RW(rdp->qlen) -= count;
89400 rdp->n_cbs_invoked += count;
89401
89402 /* Reinstate batch limit if we have worked down the excess. */
89403 @@ -2304,7 +2304,7 @@ static void force_quiescent_state(struct rcu_state *rsp)
89404 if (rnp_old != NULL)
89405 raw_spin_unlock(&rnp_old->fqslock);
89406 if (ret) {
89407 - ACCESS_ONCE(rsp->n_force_qs_lh)++;
89408 + ACCESS_ONCE_RW(rsp->n_force_qs_lh)++;
89409 return;
89410 }
89411 rnp_old = rnp;
89412 @@ -2316,7 +2316,7 @@ static void force_quiescent_state(struct rcu_state *rsp)
89413 smp_mb__after_unlock_lock();
89414 raw_spin_unlock(&rnp_old->fqslock);
89415 if (ACCESS_ONCE(rsp->gp_flags) & RCU_GP_FLAG_FQS) {
89416 - ACCESS_ONCE(rsp->n_force_qs_lh)++;
89417 + ACCESS_ONCE_RW(rsp->n_force_qs_lh)++;
89418 raw_spin_unlock_irqrestore(&rnp_old->lock, flags);
89419 return; /* Someone beat us to it. */
89420 }
89421 @@ -2362,7 +2362,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
89422 /*
89423 * Do RCU core processing for the current CPU.
89424 */
89425 -static void rcu_process_callbacks(struct softirq_action *unused)
89426 +static void rcu_process_callbacks(void)
89427 {
89428 struct rcu_state *rsp;
89429
89430 @@ -2470,7 +2470,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
89431 WARN_ON_ONCE((unsigned long)head & 0x3); /* Misaligned rcu_head! */
89432 if (debug_rcu_head_queue(head)) {
89433 /* Probable double call_rcu(), so leak the callback. */
89434 - ACCESS_ONCE(head->func) = rcu_leak_callback;
89435 + ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
89436 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
89437 return;
89438 }
89439 @@ -2498,7 +2498,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
89440 local_irq_restore(flags);
89441 return;
89442 }
89443 - ACCESS_ONCE(rdp->qlen)++;
89444 + ACCESS_ONCE_RW(rdp->qlen)++;
89445 if (lazy)
89446 rdp->qlen_lazy++;
89447 else
89448 @@ -2759,11 +2759,11 @@ void synchronize_sched_expedited(void)
89449 * counter wrap on a 32-bit system. Quite a few more CPUs would of
89450 * course be required on a 64-bit system.
89451 */
89452 - if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
89453 + if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
89454 (ulong)atomic_long_read(&rsp->expedited_done) +
89455 ULONG_MAX / 8)) {
89456 synchronize_sched();
89457 - atomic_long_inc(&rsp->expedited_wrap);
89458 + atomic_long_inc_unchecked(&rsp->expedited_wrap);
89459 return;
89460 }
89461
89462 @@ -2771,7 +2771,7 @@ void synchronize_sched_expedited(void)
89463 * Take a ticket. Note that atomic_inc_return() implies a
89464 * full memory barrier.
89465 */
89466 - snap = atomic_long_inc_return(&rsp->expedited_start);
89467 + snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
89468 firstsnap = snap;
89469 get_online_cpus();
89470 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
89471 @@ -2784,14 +2784,14 @@ void synchronize_sched_expedited(void)
89472 synchronize_sched_expedited_cpu_stop,
89473 NULL) == -EAGAIN) {
89474 put_online_cpus();
89475 - atomic_long_inc(&rsp->expedited_tryfail);
89476 + atomic_long_inc_unchecked(&rsp->expedited_tryfail);
89477
89478 /* Check to see if someone else did our work for us. */
89479 s = atomic_long_read(&rsp->expedited_done);
89480 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
89481 /* ensure test happens before caller kfree */
89482 smp_mb__before_atomic_inc(); /* ^^^ */
89483 - atomic_long_inc(&rsp->expedited_workdone1);
89484 + atomic_long_inc_unchecked(&rsp->expedited_workdone1);
89485 return;
89486 }
89487
89488 @@ -2800,7 +2800,7 @@ void synchronize_sched_expedited(void)
89489 udelay(trycount * num_online_cpus());
89490 } else {
89491 wait_rcu_gp(call_rcu_sched);
89492 - atomic_long_inc(&rsp->expedited_normal);
89493 + atomic_long_inc_unchecked(&rsp->expedited_normal);
89494 return;
89495 }
89496
89497 @@ -2809,7 +2809,7 @@ void synchronize_sched_expedited(void)
89498 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
89499 /* ensure test happens before caller kfree */
89500 smp_mb__before_atomic_inc(); /* ^^^ */
89501 - atomic_long_inc(&rsp->expedited_workdone2);
89502 + atomic_long_inc_unchecked(&rsp->expedited_workdone2);
89503 return;
89504 }
89505
89506 @@ -2821,10 +2821,10 @@ void synchronize_sched_expedited(void)
89507 * period works for us.
89508 */
89509 get_online_cpus();
89510 - snap = atomic_long_read(&rsp->expedited_start);
89511 + snap = atomic_long_read_unchecked(&rsp->expedited_start);
89512 smp_mb(); /* ensure read is before try_stop_cpus(). */
89513 }
89514 - atomic_long_inc(&rsp->expedited_stoppedcpus);
89515 + atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
89516
89517 /*
89518 * Everyone up to our most recent fetch is covered by our grace
89519 @@ -2833,16 +2833,16 @@ void synchronize_sched_expedited(void)
89520 * than we did already did their update.
89521 */
89522 do {
89523 - atomic_long_inc(&rsp->expedited_done_tries);
89524 + atomic_long_inc_unchecked(&rsp->expedited_done_tries);
89525 s = atomic_long_read(&rsp->expedited_done);
89526 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
89527 /* ensure test happens before caller kfree */
89528 smp_mb__before_atomic_inc(); /* ^^^ */
89529 - atomic_long_inc(&rsp->expedited_done_lost);
89530 + atomic_long_inc_unchecked(&rsp->expedited_done_lost);
89531 break;
89532 }
89533 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
89534 - atomic_long_inc(&rsp->expedited_done_exit);
89535 + atomic_long_inc_unchecked(&rsp->expedited_done_exit);
89536
89537 put_online_cpus();
89538 }
89539 @@ -3048,7 +3048,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
89540 * ACCESS_ONCE() to prevent the compiler from speculating
89541 * the increment to precede the early-exit check.
89542 */
89543 - ACCESS_ONCE(rsp->n_barrier_done)++;
89544 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
89545 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
89546 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
89547 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
89548 @@ -3098,7 +3098,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
89549
89550 /* Increment ->n_barrier_done to prevent duplicate work. */
89551 smp_mb(); /* Keep increment after above mechanism. */
89552 - ACCESS_ONCE(rsp->n_barrier_done)++;
89553 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
89554 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
89555 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
89556 smp_mb(); /* Keep increment before caller's subsequent code. */
89557 @@ -3143,10 +3143,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
89558 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
89559 init_callback_list(rdp);
89560 rdp->qlen_lazy = 0;
89561 - ACCESS_ONCE(rdp->qlen) = 0;
89562 + ACCESS_ONCE_RW(rdp->qlen) = 0;
89563 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
89564 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
89565 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
89566 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
89567 rdp->cpu = cpu;
89568 rdp->rsp = rsp;
89569 rcu_boot_init_nocb_percpu_data(rdp);
89570 @@ -3180,8 +3180,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
89571 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
89572 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
89573 rcu_sysidle_init_percpu_data(rdp->dynticks);
89574 - atomic_set(&rdp->dynticks->dynticks,
89575 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
89576 + atomic_set_unchecked(&rdp->dynticks->dynticks,
89577 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
89578 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
89579
89580 /* Add CPU to rcu_node bitmasks. */
89581 diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
89582 index 75dc3c3..b95d624 100644
89583 --- a/kernel/rcu/tree.h
89584 +++ b/kernel/rcu/tree.h
89585 @@ -87,11 +87,11 @@ struct rcu_dynticks {
89586 long long dynticks_nesting; /* Track irq/process nesting level. */
89587 /* Process level is worth LLONG_MAX/2. */
89588 int dynticks_nmi_nesting; /* Track NMI nesting level. */
89589 - atomic_t dynticks; /* Even value for idle, else odd. */
89590 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
89591 #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
89592 long long dynticks_idle_nesting;
89593 /* irq/process nesting level from idle. */
89594 - atomic_t dynticks_idle; /* Even value for idle, else odd. */
89595 + atomic_unchecked_t dynticks_idle;/* Even value for idle, else odd. */
89596 /* "Idle" excludes userspace execution. */
89597 unsigned long dynticks_idle_jiffies;
89598 /* End of last non-NMI non-idle period. */
89599 @@ -431,17 +431,17 @@ struct rcu_state {
89600 /* _rcu_barrier(). */
89601 /* End of fields guarded by barrier_mutex. */
89602
89603 - atomic_long_t expedited_start; /* Starting ticket. */
89604 - atomic_long_t expedited_done; /* Done ticket. */
89605 - atomic_long_t expedited_wrap; /* # near-wrap incidents. */
89606 - atomic_long_t expedited_tryfail; /* # acquisition failures. */
89607 - atomic_long_t expedited_workdone1; /* # done by others #1. */
89608 - atomic_long_t expedited_workdone2; /* # done by others #2. */
89609 - atomic_long_t expedited_normal; /* # fallbacks to normal. */
89610 - atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
89611 - atomic_long_t expedited_done_tries; /* # tries to update _done. */
89612 - atomic_long_t expedited_done_lost; /* # times beaten to _done. */
89613 - atomic_long_t expedited_done_exit; /* # times exited _done loop. */
89614 + atomic_long_unchecked_t expedited_start; /* Starting ticket. */
89615 + atomic_long_t expedited_done; /* Done ticket. */
89616 + atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
89617 + atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
89618 + atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
89619 + atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
89620 + atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
89621 + atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
89622 + atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
89623 + atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
89624 + atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
89625
89626 unsigned long jiffies_force_qs; /* Time at which to invoke */
89627 /* force_quiescent_state(). */
89628 diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
89629 index 962d1d5..c6c62d12d 100644
89630 --- a/kernel/rcu/tree_plugin.h
89631 +++ b/kernel/rcu/tree_plugin.h
89632 @@ -758,7 +758,7 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp)
89633 static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
89634 {
89635 return !rcu_preempted_readers_exp(rnp) &&
89636 - ACCESS_ONCE(rnp->expmask) == 0;
89637 + ACCESS_ONCE_RW(rnp->expmask) == 0;
89638 }
89639
89640 /*
89641 @@ -920,7 +920,7 @@ void synchronize_rcu_expedited(void)
89642
89643 /* Clean up and exit. */
89644 smp_mb(); /* ensure expedited GP seen before counter increment. */
89645 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
89646 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
89647 unlock_mb_ret:
89648 mutex_unlock(&sync_rcu_preempt_exp_mutex);
89649 mb_ret:
89650 @@ -1496,7 +1496,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
89651 free_cpumask_var(cm);
89652 }
89653
89654 -static struct smp_hotplug_thread rcu_cpu_thread_spec = {
89655 +static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
89656 .store = &rcu_cpu_kthread_task,
89657 .thread_should_run = rcu_cpu_kthread_should_run,
89658 .thread_fn = rcu_cpu_kthread,
89659 @@ -1972,7 +1972,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
89660 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
89661 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
89662 cpu, ticks_value, ticks_title,
89663 - atomic_read(&rdtp->dynticks) & 0xfff,
89664 + atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
89665 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
89666 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
89667 fast_no_hz);
89668 @@ -2138,7 +2138,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
89669
89670 /* Enqueue the callback on the nocb list and update counts. */
89671 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
89672 - ACCESS_ONCE(*old_rhpp) = rhp;
89673 + ACCESS_ONCE_RW(*old_rhpp) = rhp;
89674 atomic_long_add(rhcount, &rdp->nocb_q_count);
89675 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
89676
89677 @@ -2311,12 +2311,12 @@ static int rcu_nocb_kthread(void *arg)
89678 * Extract queued callbacks, update counts, and wait
89679 * for a grace period to elapse.
89680 */
89681 - ACCESS_ONCE(rdp->nocb_head) = NULL;
89682 + ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
89683 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
89684 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
89685 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
89686 - ACCESS_ONCE(rdp->nocb_p_count) += c;
89687 - ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
89688 + ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
89689 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
89690 rcu_nocb_wait_gp(rdp);
89691
89692 /* Each pass through the following loop invokes a callback. */
89693 @@ -2342,8 +2342,8 @@ static int rcu_nocb_kthread(void *arg)
89694 list = next;
89695 }
89696 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
89697 - ACCESS_ONCE(rdp->nocb_p_count) -= c;
89698 - ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
89699 + ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
89700 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
89701 rdp->n_nocbs_invoked += c;
89702 }
89703 return 0;
89704 @@ -2360,7 +2360,7 @@ static void do_nocb_deferred_wakeup(struct rcu_data *rdp)
89705 {
89706 if (!rcu_nocb_need_deferred_wakeup(rdp))
89707 return;
89708 - ACCESS_ONCE(rdp->nocb_defer_wakeup) = false;
89709 + ACCESS_ONCE_RW(rdp->nocb_defer_wakeup) = false;
89710 wake_up(&rdp->nocb_wq);
89711 trace_rcu_nocb_wake(rdp->rsp->name, rdp->cpu, TPS("DeferredWakeEmpty"));
89712 }
89713 @@ -2386,7 +2386,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
89714 t = kthread_run(rcu_nocb_kthread, rdp,
89715 "rcuo%c/%d", rsp->abbr, cpu);
89716 BUG_ON(IS_ERR(t));
89717 - ACCESS_ONCE(rdp->nocb_kthread) = t;
89718 + ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
89719 }
89720 }
89721
89722 @@ -2522,11 +2522,11 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
89723
89724 /* Record start of fully idle period. */
89725 j = jiffies;
89726 - ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
89727 + ACCESS_ONCE_RW(rdtp->dynticks_idle_jiffies) = j;
89728 smp_mb__before_atomic_inc();
89729 - atomic_inc(&rdtp->dynticks_idle);
89730 + atomic_inc_unchecked(&rdtp->dynticks_idle);
89731 smp_mb__after_atomic_inc();
89732 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
89733 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
89734 }
89735
89736 /*
89737 @@ -2591,9 +2591,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
89738
89739 /* Record end of idle period. */
89740 smp_mb__before_atomic_inc();
89741 - atomic_inc(&rdtp->dynticks_idle);
89742 + atomic_inc_unchecked(&rdtp->dynticks_idle);
89743 smp_mb__after_atomic_inc();
89744 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
89745 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
89746
89747 /*
89748 * If we are the timekeeping CPU, we are permitted to be non-idle
89749 @@ -2634,7 +2634,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
89750 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
89751
89752 /* Pick up current idle and NMI-nesting counter and check. */
89753 - cur = atomic_read(&rdtp->dynticks_idle);
89754 + cur = atomic_read_unchecked(&rdtp->dynticks_idle);
89755 if (cur & 0x1) {
89756 *isidle = false; /* We are not idle! */
89757 return;
89758 @@ -2697,7 +2697,7 @@ static void rcu_sysidle(unsigned long j)
89759 case RCU_SYSIDLE_NOT:
89760
89761 /* First time all are idle, so note a short idle period. */
89762 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT;
89763 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_SHORT;
89764 break;
89765
89766 case RCU_SYSIDLE_SHORT:
89767 @@ -2734,7 +2734,7 @@ static void rcu_sysidle(unsigned long j)
89768 static void rcu_sysidle_cancel(void)
89769 {
89770 smp_mb();
89771 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT;
89772 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_NOT;
89773 }
89774
89775 /*
89776 @@ -2782,7 +2782,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
89777 smp_mb(); /* grace period precedes setting inuse. */
89778
89779 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
89780 - ACCESS_ONCE(rshp->inuse) = 0;
89781 + ACCESS_ONCE_RW(rshp->inuse) = 0;
89782 }
89783
89784 /*
89785 diff --git a/kernel/rcu/tree_trace.c b/kernel/rcu/tree_trace.c
89786 index 5cdc62e..cc52e88 100644
89787 --- a/kernel/rcu/tree_trace.c
89788 +++ b/kernel/rcu/tree_trace.c
89789 @@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
89790 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
89791 rdp->passed_quiesce, rdp->qs_pending);
89792 seq_printf(m, " dt=%d/%llx/%d df=%lu",
89793 - atomic_read(&rdp->dynticks->dynticks),
89794 + atomic_read_unchecked(&rdp->dynticks->dynticks),
89795 rdp->dynticks->dynticks_nesting,
89796 rdp->dynticks->dynticks_nmi_nesting,
89797 rdp->dynticks_fqs);
89798 @@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
89799 struct rcu_state *rsp = (struct rcu_state *)m->private;
89800
89801 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",
89802 - atomic_long_read(&rsp->expedited_start),
89803 + atomic_long_read_unchecked(&rsp->expedited_start),
89804 atomic_long_read(&rsp->expedited_done),
89805 - atomic_long_read(&rsp->expedited_wrap),
89806 - atomic_long_read(&rsp->expedited_tryfail),
89807 - atomic_long_read(&rsp->expedited_workdone1),
89808 - atomic_long_read(&rsp->expedited_workdone2),
89809 - atomic_long_read(&rsp->expedited_normal),
89810 - atomic_long_read(&rsp->expedited_stoppedcpus),
89811 - atomic_long_read(&rsp->expedited_done_tries),
89812 - atomic_long_read(&rsp->expedited_done_lost),
89813 - atomic_long_read(&rsp->expedited_done_exit));
89814 + atomic_long_read_unchecked(&rsp->expedited_wrap),
89815 + atomic_long_read_unchecked(&rsp->expedited_tryfail),
89816 + atomic_long_read_unchecked(&rsp->expedited_workdone1),
89817 + atomic_long_read_unchecked(&rsp->expedited_workdone2),
89818 + atomic_long_read_unchecked(&rsp->expedited_normal),
89819 + atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
89820 + atomic_long_read_unchecked(&rsp->expedited_done_tries),
89821 + atomic_long_read_unchecked(&rsp->expedited_done_lost),
89822 + atomic_long_read_unchecked(&rsp->expedited_done_exit));
89823 return 0;
89824 }
89825
89826 diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
89827 index 4c0a9b0..7e81362 100644
89828 --- a/kernel/rcu/update.c
89829 +++ b/kernel/rcu/update.c
89830 @@ -311,10 +311,10 @@ int rcu_jiffies_till_stall_check(void)
89831 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
89832 */
89833 if (till_stall_check < 3) {
89834 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
89835 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
89836 till_stall_check = 3;
89837 } else if (till_stall_check > 300) {
89838 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
89839 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
89840 till_stall_check = 300;
89841 }
89842 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
89843 diff --git a/kernel/resource.c b/kernel/resource.c
89844 index 8957d68..770cbe4 100644
89845 --- a/kernel/resource.c
89846 +++ b/kernel/resource.c
89847 @@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
89848
89849 static int __init ioresources_init(void)
89850 {
89851 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
89852 +#ifdef CONFIG_GRKERNSEC_PROC_USER
89853 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
89854 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
89855 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
89856 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
89857 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
89858 +#endif
89859 +#else
89860 proc_create("ioports", 0, NULL, &proc_ioports_operations);
89861 proc_create("iomem", 0, NULL, &proc_iomem_operations);
89862 +#endif
89863 return 0;
89864 }
89865 __initcall(ioresources_init);
89866 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
89867 index e73efba..c9bfbd4 100644
89868 --- a/kernel/sched/auto_group.c
89869 +++ b/kernel/sched/auto_group.c
89870 @@ -11,7 +11,7 @@
89871
89872 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
89873 static struct autogroup autogroup_default;
89874 -static atomic_t autogroup_seq_nr;
89875 +static atomic_unchecked_t autogroup_seq_nr;
89876
89877 void __init autogroup_init(struct task_struct *init_task)
89878 {
89879 @@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
89880
89881 kref_init(&ag->kref);
89882 init_rwsem(&ag->lock);
89883 - ag->id = atomic_inc_return(&autogroup_seq_nr);
89884 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
89885 ag->tg = tg;
89886 #ifdef CONFIG_RT_GROUP_SCHED
89887 /*
89888 diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c
89889 index a63f4dc..349bbb0 100644
89890 --- a/kernel/sched/completion.c
89891 +++ b/kernel/sched/completion.c
89892 @@ -204,7 +204,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
89893 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
89894 * or number of jiffies left till timeout) if completed.
89895 */
89896 -long __sched
89897 +long __sched __intentional_overflow(-1)
89898 wait_for_completion_interruptible_timeout(struct completion *x,
89899 unsigned long timeout)
89900 {
89901 @@ -221,7 +221,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
89902 *
89903 * Return: -ERESTARTSYS if interrupted, 0 if completed.
89904 */
89905 -int __sched wait_for_completion_killable(struct completion *x)
89906 +int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
89907 {
89908 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
89909 if (t == -ERESTARTSYS)
89910 @@ -242,7 +242,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
89911 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
89912 * or number of jiffies left till timeout) if completed.
89913 */
89914 -long __sched
89915 +long __sched __intentional_overflow(-1)
89916 wait_for_completion_killable_timeout(struct completion *x,
89917 unsigned long timeout)
89918 {
89919 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
89920 index 084d17f..e416b9f 100644
89921 --- a/kernel/sched/core.c
89922 +++ b/kernel/sched/core.c
89923 @@ -1775,7 +1775,7 @@ void set_numabalancing_state(bool enabled)
89924 int sysctl_numa_balancing(struct ctl_table *table, int write,
89925 void __user *buffer, size_t *lenp, loff_t *ppos)
89926 {
89927 - struct ctl_table t;
89928 + ctl_table_no_const t;
89929 int err;
89930 int state = numabalancing_enabled;
89931
89932 @@ -2238,8 +2238,10 @@ context_switch(struct rq *rq, struct task_struct *prev,
89933 next->active_mm = oldmm;
89934 atomic_inc(&oldmm->mm_count);
89935 enter_lazy_tlb(oldmm, next);
89936 - } else
89937 + } else {
89938 switch_mm(oldmm, mm, next);
89939 + populate_stack();
89940 + }
89941
89942 if (!prev->mm) {
89943 prev->active_mm = NULL;
89944 @@ -3004,6 +3006,8 @@ int can_nice(const struct task_struct *p, const int nice)
89945 /* convert nice value [19,-20] to rlimit style value [1,40] */
89946 int nice_rlim = 20 - nice;
89947
89948 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
89949 +
89950 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
89951 capable(CAP_SYS_NICE));
89952 }
89953 @@ -3037,7 +3041,8 @@ SYSCALL_DEFINE1(nice, int, increment)
89954 if (nice > MAX_NICE)
89955 nice = MAX_NICE;
89956
89957 - if (increment < 0 && !can_nice(current, nice))
89958 + if (increment < 0 && (!can_nice(current, nice) ||
89959 + gr_handle_chroot_nice()))
89960 return -EPERM;
89961
89962 retval = security_task_setnice(current, nice);
89963 @@ -3310,6 +3315,7 @@ recheck:
89964 if (policy != p->policy && !rlim_rtprio)
89965 return -EPERM;
89966
89967 + gr_learn_resource(p, RLIMIT_RTPRIO, attr->sched_priority, 1);
89968 /* can't increase priority */
89969 if (attr->sched_priority > p->rt_priority &&
89970 attr->sched_priority > rlim_rtprio)
89971 @@ -4708,6 +4714,7 @@ void idle_task_exit(void)
89972
89973 if (mm != &init_mm) {
89974 switch_mm(mm, &init_mm, current);
89975 + populate_stack();
89976 finish_arch_post_lock_switch();
89977 }
89978 mmdrop(mm);
89979 @@ -4803,7 +4810,7 @@ static void migrate_tasks(unsigned int dead_cpu)
89980
89981 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
89982
89983 -static struct ctl_table sd_ctl_dir[] = {
89984 +static ctl_table_no_const sd_ctl_dir[] __read_only = {
89985 {
89986 .procname = "sched_domain",
89987 .mode = 0555,
89988 @@ -4820,17 +4827,17 @@ static struct ctl_table sd_ctl_root[] = {
89989 {}
89990 };
89991
89992 -static struct ctl_table *sd_alloc_ctl_entry(int n)
89993 +static ctl_table_no_const *sd_alloc_ctl_entry(int n)
89994 {
89995 - struct ctl_table *entry =
89996 + ctl_table_no_const *entry =
89997 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
89998
89999 return entry;
90000 }
90001
90002 -static void sd_free_ctl_entry(struct ctl_table **tablep)
90003 +static void sd_free_ctl_entry(ctl_table_no_const *tablep)
90004 {
90005 - struct ctl_table *entry;
90006 + ctl_table_no_const *entry;
90007
90008 /*
90009 * In the intermediate directories, both the child directory and
90010 @@ -4838,22 +4845,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
90011 * will always be set. In the lowest directory the names are
90012 * static strings and all have proc handlers.
90013 */
90014 - for (entry = *tablep; entry->mode; entry++) {
90015 - if (entry->child)
90016 - sd_free_ctl_entry(&entry->child);
90017 + for (entry = tablep; entry->mode; entry++) {
90018 + if (entry->child) {
90019 + sd_free_ctl_entry(entry->child);
90020 + pax_open_kernel();
90021 + entry->child = NULL;
90022 + pax_close_kernel();
90023 + }
90024 if (entry->proc_handler == NULL)
90025 kfree(entry->procname);
90026 }
90027
90028 - kfree(*tablep);
90029 - *tablep = NULL;
90030 + kfree(tablep);
90031 }
90032
90033 static int min_load_idx = 0;
90034 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
90035
90036 static void
90037 -set_table_entry(struct ctl_table *entry,
90038 +set_table_entry(ctl_table_no_const *entry,
90039 const char *procname, void *data, int maxlen,
90040 umode_t mode, proc_handler *proc_handler,
90041 bool load_idx)
90042 @@ -4873,7 +4883,7 @@ set_table_entry(struct ctl_table *entry,
90043 static struct ctl_table *
90044 sd_alloc_ctl_domain_table(struct sched_domain *sd)
90045 {
90046 - struct ctl_table *table = sd_alloc_ctl_entry(14);
90047 + ctl_table_no_const *table = sd_alloc_ctl_entry(14);
90048
90049 if (table == NULL)
90050 return NULL;
90051 @@ -4911,9 +4921,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
90052 return table;
90053 }
90054
90055 -static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
90056 +static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
90057 {
90058 - struct ctl_table *entry, *table;
90059 + ctl_table_no_const *entry, *table;
90060 struct sched_domain *sd;
90061 int domain_num = 0, i;
90062 char buf[32];
90063 @@ -4940,11 +4950,13 @@ static struct ctl_table_header *sd_sysctl_header;
90064 static void register_sched_domain_sysctl(void)
90065 {
90066 int i, cpu_num = num_possible_cpus();
90067 - struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
90068 + ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
90069 char buf[32];
90070
90071 WARN_ON(sd_ctl_dir[0].child);
90072 + pax_open_kernel();
90073 sd_ctl_dir[0].child = entry;
90074 + pax_close_kernel();
90075
90076 if (entry == NULL)
90077 return;
90078 @@ -4967,8 +4979,12 @@ static void unregister_sched_domain_sysctl(void)
90079 if (sd_sysctl_header)
90080 unregister_sysctl_table(sd_sysctl_header);
90081 sd_sysctl_header = NULL;
90082 - if (sd_ctl_dir[0].child)
90083 - sd_free_ctl_entry(&sd_ctl_dir[0].child);
90084 + if (sd_ctl_dir[0].child) {
90085 + sd_free_ctl_entry(sd_ctl_dir[0].child);
90086 + pax_open_kernel();
90087 + sd_ctl_dir[0].child = NULL;
90088 + pax_close_kernel();
90089 + }
90090 }
90091 #else
90092 static void register_sched_domain_sysctl(void)
90093 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
90094 index 8cbe2d2..61f20a1 100644
90095 --- a/kernel/sched/fair.c
90096 +++ b/kernel/sched/fair.c
90097 @@ -1806,7 +1806,7 @@ void task_numa_fault(int last_cpupid, int mem_node, int pages, int flags)
90098
90099 static void reset_ptenuma_scan(struct task_struct *p)
90100 {
90101 - ACCESS_ONCE(p->mm->numa_scan_seq)++;
90102 + ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
90103 p->mm->numa_scan_offset = 0;
90104 }
90105
90106 @@ -7181,7 +7181,7 @@ static void nohz_idle_balance(struct rq *this_rq, enum cpu_idle_type idle) { }
90107 * run_rebalance_domains is triggered when needed from the scheduler tick.
90108 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
90109 */
90110 -static void run_rebalance_domains(struct softirq_action *h)
90111 +static __latent_entropy void run_rebalance_domains(void)
90112 {
90113 struct rq *this_rq = this_rq();
90114 enum cpu_idle_type idle = this_rq->idle_balance ?
90115 diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
90116 index 369b4d6..fa4eb3b 100644
90117 --- a/kernel/sched/sched.h
90118 +++ b/kernel/sched/sched.h
90119 @@ -1157,7 +1157,7 @@ struct sched_class {
90120 #ifdef CONFIG_FAIR_GROUP_SCHED
90121 void (*task_move_group) (struct task_struct *p, int on_rq);
90122 #endif
90123 -};
90124 +} __do_const;
90125
90126 static inline void put_prev_task(struct rq *rq, struct task_struct *prev)
90127 {
90128 diff --git a/kernel/signal.c b/kernel/signal.c
90129 index 6ea13c0..31e3b25 100644
90130 --- a/kernel/signal.c
90131 +++ b/kernel/signal.c
90132 @@ -53,12 +53,12 @@ static struct kmem_cache *sigqueue_cachep;
90133
90134 int print_fatal_signals __read_mostly;
90135
90136 -static void __user *sig_handler(struct task_struct *t, int sig)
90137 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
90138 {
90139 return t->sighand->action[sig - 1].sa.sa_handler;
90140 }
90141
90142 -static int sig_handler_ignored(void __user *handler, int sig)
90143 +static int sig_handler_ignored(__sighandler_t handler, int sig)
90144 {
90145 /* Is it explicitly or implicitly ignored? */
90146 return handler == SIG_IGN ||
90147 @@ -67,7 +67,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
90148
90149 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
90150 {
90151 - void __user *handler;
90152 + __sighandler_t handler;
90153
90154 handler = sig_handler(t, sig);
90155
90156 @@ -371,6 +371,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
90157 atomic_inc(&user->sigpending);
90158 rcu_read_unlock();
90159
90160 + if (!override_rlimit)
90161 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
90162 +
90163 if (override_rlimit ||
90164 atomic_read(&user->sigpending) <=
90165 task_rlimit(t, RLIMIT_SIGPENDING)) {
90166 @@ -498,7 +501,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
90167
90168 int unhandled_signal(struct task_struct *tsk, int sig)
90169 {
90170 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
90171 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
90172 if (is_global_init(tsk))
90173 return 1;
90174 if (handler != SIG_IGN && handler != SIG_DFL)
90175 @@ -818,6 +821,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
90176 }
90177 }
90178
90179 + /* allow glibc communication via tgkill to other threads in our
90180 + thread group */
90181 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
90182 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
90183 + && gr_handle_signal(t, sig))
90184 + return -EPERM;
90185 +
90186 return security_task_kill(t, info, sig, 0);
90187 }
90188
90189 @@ -1201,7 +1211,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
90190 return send_signal(sig, info, p, 1);
90191 }
90192
90193 -static int
90194 +int
90195 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
90196 {
90197 return send_signal(sig, info, t, 0);
90198 @@ -1238,6 +1248,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
90199 unsigned long int flags;
90200 int ret, blocked, ignored;
90201 struct k_sigaction *action;
90202 + int is_unhandled = 0;
90203
90204 spin_lock_irqsave(&t->sighand->siglock, flags);
90205 action = &t->sighand->action[sig-1];
90206 @@ -1252,9 +1263,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
90207 }
90208 if (action->sa.sa_handler == SIG_DFL)
90209 t->signal->flags &= ~SIGNAL_UNKILLABLE;
90210 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
90211 + is_unhandled = 1;
90212 ret = specific_send_sig_info(sig, info, t);
90213 spin_unlock_irqrestore(&t->sighand->siglock, flags);
90214
90215 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
90216 + normal operation */
90217 + if (is_unhandled) {
90218 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
90219 + gr_handle_crash(t, sig);
90220 + }
90221 +
90222 return ret;
90223 }
90224
90225 @@ -1321,8 +1341,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
90226 ret = check_kill_permission(sig, info, p);
90227 rcu_read_unlock();
90228
90229 - if (!ret && sig)
90230 + if (!ret && sig) {
90231 ret = do_send_sig_info(sig, info, p, true);
90232 + if (!ret)
90233 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
90234 + }
90235
90236 return ret;
90237 }
90238 @@ -2928,7 +2951,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
90239 int error = -ESRCH;
90240
90241 rcu_read_lock();
90242 - p = find_task_by_vpid(pid);
90243 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
90244 + /* allow glibc communication via tgkill to other threads in our
90245 + thread group */
90246 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
90247 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
90248 + p = find_task_by_vpid_unrestricted(pid);
90249 + else
90250 +#endif
90251 + p = find_task_by_vpid(pid);
90252 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
90253 error = check_kill_permission(sig, info, p);
90254 /*
90255 @@ -3241,8 +3272,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
90256 }
90257 seg = get_fs();
90258 set_fs(KERNEL_DS);
90259 - ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
90260 - (stack_t __force __user *) &uoss,
90261 + ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
90262 + (stack_t __force_user *) &uoss,
90263 compat_user_stack_pointer());
90264 set_fs(seg);
90265 if (ret >= 0 && uoss_ptr) {
90266 diff --git a/kernel/smpboot.c b/kernel/smpboot.c
90267 index eb89e18..a4e6792 100644
90268 --- a/kernel/smpboot.c
90269 +++ b/kernel/smpboot.c
90270 @@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
90271 }
90272 smpboot_unpark_thread(plug_thread, cpu);
90273 }
90274 - list_add(&plug_thread->list, &hotplug_threads);
90275 + pax_list_add(&plug_thread->list, &hotplug_threads);
90276 out:
90277 mutex_unlock(&smpboot_threads_lock);
90278 return ret;
90279 @@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
90280 {
90281 get_online_cpus();
90282 mutex_lock(&smpboot_threads_lock);
90283 - list_del(&plug_thread->list);
90284 + pax_list_del(&plug_thread->list);
90285 smpboot_destroy_threads(plug_thread);
90286 mutex_unlock(&smpboot_threads_lock);
90287 put_online_cpus();
90288 diff --git a/kernel/softirq.c b/kernel/softirq.c
90289 index 92f24f5..db41501 100644
90290 --- a/kernel/softirq.c
90291 +++ b/kernel/softirq.c
90292 @@ -53,7 +53,7 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
90293 EXPORT_SYMBOL(irq_stat);
90294 #endif
90295
90296 -static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
90297 +static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
90298
90299 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
90300
90301 @@ -268,7 +268,7 @@ restart:
90302 kstat_incr_softirqs_this_cpu(vec_nr);
90303
90304 trace_softirq_entry(vec_nr);
90305 - h->action(h);
90306 + h->action();
90307 trace_softirq_exit(vec_nr);
90308 if (unlikely(prev_count != preempt_count())) {
90309 pr_err("huh, entered softirq %u %s %p with preempt_count %08x, exited with %08x?\n",
90310 @@ -428,7 +428,7 @@ void __raise_softirq_irqoff(unsigned int nr)
90311 or_softirq_pending(1UL << nr);
90312 }
90313
90314 -void open_softirq(int nr, void (*action)(struct softirq_action *))
90315 +void __init open_softirq(int nr, void (*action)(void))
90316 {
90317 softirq_vec[nr].action = action;
90318 }
90319 @@ -480,7 +480,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
90320 }
90321 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
90322
90323 -static void tasklet_action(struct softirq_action *a)
90324 +static void tasklet_action(void)
90325 {
90326 struct tasklet_struct *list;
90327
90328 @@ -516,7 +516,7 @@ static void tasklet_action(struct softirq_action *a)
90329 }
90330 }
90331
90332 -static void tasklet_hi_action(struct softirq_action *a)
90333 +static __latent_entropy void tasklet_hi_action(void)
90334 {
90335 struct tasklet_struct *list;
90336
90337 @@ -743,7 +743,7 @@ static struct notifier_block cpu_nfb = {
90338 .notifier_call = cpu_callback
90339 };
90340
90341 -static struct smp_hotplug_thread softirq_threads = {
90342 +static struct smp_hotplug_thread softirq_threads __read_only = {
90343 .store = &ksoftirqd,
90344 .thread_should_run = ksoftirqd_should_run,
90345 .thread_fn = run_ksoftirqd,
90346 diff --git a/kernel/sys.c b/kernel/sys.c
90347 index fba0f29..84400e2 100644
90348 --- a/kernel/sys.c
90349 +++ b/kernel/sys.c
90350 @@ -148,6 +148,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
90351 error = -EACCES;
90352 goto out;
90353 }
90354 +
90355 + if (gr_handle_chroot_setpriority(p, niceval)) {
90356 + error = -EACCES;
90357 + goto out;
90358 + }
90359 +
90360 no_nice = security_task_setnice(p, niceval);
90361 if (no_nice) {
90362 error = no_nice;
90363 @@ -351,6 +357,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
90364 goto error;
90365 }
90366
90367 + if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
90368 + goto error;
90369 +
90370 if (rgid != (gid_t) -1 ||
90371 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
90372 new->sgid = new->egid;
90373 @@ -386,6 +395,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
90374 old = current_cred();
90375
90376 retval = -EPERM;
90377 +
90378 + if (gr_check_group_change(kgid, kgid, kgid))
90379 + goto error;
90380 +
90381 if (ns_capable(old->user_ns, CAP_SETGID))
90382 new->gid = new->egid = new->sgid = new->fsgid = kgid;
90383 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
90384 @@ -403,7 +416,7 @@ error:
90385 /*
90386 * change the user struct in a credentials set to match the new UID
90387 */
90388 -static int set_user(struct cred *new)
90389 +int set_user(struct cred *new)
90390 {
90391 struct user_struct *new_user;
90392
90393 @@ -483,6 +496,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
90394 goto error;
90395 }
90396
90397 + if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
90398 + goto error;
90399 +
90400 if (!uid_eq(new->uid, old->uid)) {
90401 retval = set_user(new);
90402 if (retval < 0)
90403 @@ -533,6 +549,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
90404 old = current_cred();
90405
90406 retval = -EPERM;
90407 +
90408 + if (gr_check_crash_uid(kuid))
90409 + goto error;
90410 + if (gr_check_user_change(kuid, kuid, kuid))
90411 + goto error;
90412 +
90413 if (ns_capable(old->user_ns, CAP_SETUID)) {
90414 new->suid = new->uid = kuid;
90415 if (!uid_eq(kuid, old->uid)) {
90416 @@ -602,6 +624,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
90417 goto error;
90418 }
90419
90420 + if (gr_check_user_change(kruid, keuid, INVALID_UID))
90421 + goto error;
90422 +
90423 if (ruid != (uid_t) -1) {
90424 new->uid = kruid;
90425 if (!uid_eq(kruid, old->uid)) {
90426 @@ -684,6 +709,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
90427 goto error;
90428 }
90429
90430 + if (gr_check_group_change(krgid, kegid, INVALID_GID))
90431 + goto error;
90432 +
90433 if (rgid != (gid_t) -1)
90434 new->gid = krgid;
90435 if (egid != (gid_t) -1)
90436 @@ -745,12 +773,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
90437 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
90438 ns_capable(old->user_ns, CAP_SETUID)) {
90439 if (!uid_eq(kuid, old->fsuid)) {
90440 + if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
90441 + goto error;
90442 +
90443 new->fsuid = kuid;
90444 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
90445 goto change_okay;
90446 }
90447 }
90448
90449 +error:
90450 abort_creds(new);
90451 return old_fsuid;
90452
90453 @@ -783,12 +815,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
90454 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
90455 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
90456 ns_capable(old->user_ns, CAP_SETGID)) {
90457 + if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
90458 + goto error;
90459 +
90460 if (!gid_eq(kgid, old->fsgid)) {
90461 new->fsgid = kgid;
90462 goto change_okay;
90463 }
90464 }
90465
90466 +error:
90467 abort_creds(new);
90468 return old_fsgid;
90469
90470 @@ -1167,19 +1203,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
90471 return -EFAULT;
90472
90473 down_read(&uts_sem);
90474 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
90475 + error = __copy_to_user(name->sysname, &utsname()->sysname,
90476 __OLD_UTS_LEN);
90477 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
90478 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
90479 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
90480 __OLD_UTS_LEN);
90481 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
90482 - error |= __copy_to_user(&name->release, &utsname()->release,
90483 + error |= __copy_to_user(name->release, &utsname()->release,
90484 __OLD_UTS_LEN);
90485 error |= __put_user(0, name->release + __OLD_UTS_LEN);
90486 - error |= __copy_to_user(&name->version, &utsname()->version,
90487 + error |= __copy_to_user(name->version, &utsname()->version,
90488 __OLD_UTS_LEN);
90489 error |= __put_user(0, name->version + __OLD_UTS_LEN);
90490 - error |= __copy_to_user(&name->machine, &utsname()->machine,
90491 + error |= __copy_to_user(name->machine, &utsname()->machine,
90492 __OLD_UTS_LEN);
90493 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
90494 up_read(&uts_sem);
90495 @@ -1381,6 +1417,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
90496 */
90497 new_rlim->rlim_cur = 1;
90498 }
90499 + /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
90500 + is changed to a lower value. Since tasks can be created by the same
90501 + user in between this limit change and an execve by this task, force
90502 + a recheck only for this task by setting PF_NPROC_EXCEEDED
90503 + */
90504 + if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
90505 + tsk->flags |= PF_NPROC_EXCEEDED;
90506 }
90507 if (!retval) {
90508 if (old_rlim)
90509 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
90510 index 0e0373f..69f5181 100644
90511 --- a/kernel/sysctl.c
90512 +++ b/kernel/sysctl.c
90513 @@ -94,7 +94,6 @@
90514
90515
90516 #if defined(CONFIG_SYSCTL)
90517 -
90518 /* External variables not in a header file. */
90519 extern int max_threads;
90520 extern int suid_dumpable;
90521 @@ -115,19 +114,20 @@ extern int sysctl_nr_trim_pages;
90522
90523 /* Constants used for minimum and maximum */
90524 #ifdef CONFIG_LOCKUP_DETECTOR
90525 -static int sixty = 60;
90526 +static int sixty __read_only = 60;
90527 #endif
90528
90529 -static int __maybe_unused neg_one = -1;
90530 +static int __maybe_unused neg_one __read_only = -1;
90531
90532 -static int zero;
90533 -static int __maybe_unused one = 1;
90534 -static int __maybe_unused two = 2;
90535 -static int __maybe_unused four = 4;
90536 -static unsigned long one_ul = 1;
90537 -static int one_hundred = 100;
90538 +static int zero __read_only = 0;
90539 +static int __maybe_unused one __read_only = 1;
90540 +static int __maybe_unused two __read_only = 2;
90541 +static int __maybe_unused three __read_only = 3;
90542 +static int __maybe_unused four __read_only = 4;
90543 +static unsigned long one_ul __read_only = 1;
90544 +static int one_hundred __read_only = 100;
90545 #ifdef CONFIG_PRINTK
90546 -static int ten_thousand = 10000;
90547 +static int ten_thousand __read_only = 10000;
90548 #endif
90549
90550 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
90551 @@ -178,10 +178,8 @@ static int proc_taint(struct ctl_table *table, int write,
90552 void __user *buffer, size_t *lenp, loff_t *ppos);
90553 #endif
90554
90555 -#ifdef CONFIG_PRINTK
90556 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
90557 void __user *buffer, size_t *lenp, loff_t *ppos);
90558 -#endif
90559
90560 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
90561 void __user *buffer, size_t *lenp, loff_t *ppos);
90562 @@ -212,6 +210,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
90563
90564 #endif
90565
90566 +extern struct ctl_table grsecurity_table[];
90567 +
90568 static struct ctl_table kern_table[];
90569 static struct ctl_table vm_table[];
90570 static struct ctl_table fs_table[];
90571 @@ -226,6 +226,20 @@ extern struct ctl_table epoll_table[];
90572 int sysctl_legacy_va_layout;
90573 #endif
90574
90575 +#ifdef CONFIG_PAX_SOFTMODE
90576 +static ctl_table pax_table[] = {
90577 + {
90578 + .procname = "softmode",
90579 + .data = &pax_softmode,
90580 + .maxlen = sizeof(unsigned int),
90581 + .mode = 0600,
90582 + .proc_handler = &proc_dointvec,
90583 + },
90584 +
90585 + { }
90586 +};
90587 +#endif
90588 +
90589 /* The default sysctl tables: */
90590
90591 static struct ctl_table sysctl_base_table[] = {
90592 @@ -274,6 +288,22 @@ static int max_extfrag_threshold = 1000;
90593 #endif
90594
90595 static struct ctl_table kern_table[] = {
90596 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
90597 + {
90598 + .procname = "grsecurity",
90599 + .mode = 0500,
90600 + .child = grsecurity_table,
90601 + },
90602 +#endif
90603 +
90604 +#ifdef CONFIG_PAX_SOFTMODE
90605 + {
90606 + .procname = "pax",
90607 + .mode = 0500,
90608 + .child = pax_table,
90609 + },
90610 +#endif
90611 +
90612 {
90613 .procname = "sched_child_runs_first",
90614 .data = &sysctl_sched_child_runs_first,
90615 @@ -629,7 +659,7 @@ static struct ctl_table kern_table[] = {
90616 .data = &modprobe_path,
90617 .maxlen = KMOD_PATH_LEN,
90618 .mode = 0644,
90619 - .proc_handler = proc_dostring,
90620 + .proc_handler = proc_dostring_modpriv,
90621 },
90622 {
90623 .procname = "modules_disabled",
90624 @@ -796,16 +826,20 @@ static struct ctl_table kern_table[] = {
90625 .extra1 = &zero,
90626 .extra2 = &one,
90627 },
90628 +#endif
90629 {
90630 .procname = "kptr_restrict",
90631 .data = &kptr_restrict,
90632 .maxlen = sizeof(int),
90633 .mode = 0644,
90634 .proc_handler = proc_dointvec_minmax_sysadmin,
90635 +#ifdef CONFIG_GRKERNSEC_HIDESYM
90636 + .extra1 = &two,
90637 +#else
90638 .extra1 = &zero,
90639 +#endif
90640 .extra2 = &two,
90641 },
90642 -#endif
90643 {
90644 .procname = "ngroups_max",
90645 .data = &ngroups_max,
90646 @@ -1050,10 +1084,17 @@ static struct ctl_table kern_table[] = {
90647 */
90648 {
90649 .procname = "perf_event_paranoid",
90650 - .data = &sysctl_perf_event_paranoid,
90651 - .maxlen = sizeof(sysctl_perf_event_paranoid),
90652 + .data = &sysctl_perf_event_legitimately_concerned,
90653 + .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
90654 .mode = 0644,
90655 - .proc_handler = proc_dointvec,
90656 + /* go ahead, be a hero */
90657 + .proc_handler = proc_dointvec_minmax_sysadmin,
90658 + .extra1 = &neg_one,
90659 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
90660 + .extra2 = &three,
90661 +#else
90662 + .extra2 = &two,
90663 +#endif
90664 },
90665 {
90666 .procname = "perf_event_mlock_kb",
90667 @@ -1315,6 +1356,13 @@ static struct ctl_table vm_table[] = {
90668 .proc_handler = proc_dointvec_minmax,
90669 .extra1 = &zero,
90670 },
90671 + {
90672 + .procname = "heap_stack_gap",
90673 + .data = &sysctl_heap_stack_gap,
90674 + .maxlen = sizeof(sysctl_heap_stack_gap),
90675 + .mode = 0644,
90676 + .proc_handler = proc_doulongvec_minmax,
90677 + },
90678 #else
90679 {
90680 .procname = "nr_trim_pages",
90681 @@ -1779,6 +1827,16 @@ int proc_dostring(struct ctl_table *table, int write,
90682 buffer, lenp, ppos);
90683 }
90684
90685 +int proc_dostring_modpriv(struct ctl_table *table, int write,
90686 + void __user *buffer, size_t *lenp, loff_t *ppos)
90687 +{
90688 + if (write && !capable(CAP_SYS_MODULE))
90689 + return -EPERM;
90690 +
90691 + return _proc_do_string(table->data, table->maxlen, write,
90692 + buffer, lenp, ppos);
90693 +}
90694 +
90695 static size_t proc_skip_spaces(char **buf)
90696 {
90697 size_t ret;
90698 @@ -1884,6 +1942,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
90699 len = strlen(tmp);
90700 if (len > *size)
90701 len = *size;
90702 + if (len > sizeof(tmp))
90703 + len = sizeof(tmp);
90704 if (copy_to_user(*buf, tmp, len))
90705 return -EFAULT;
90706 *size -= len;
90707 @@ -2048,7 +2108,7 @@ int proc_dointvec(struct ctl_table *table, int write,
90708 static int proc_taint(struct ctl_table *table, int write,
90709 void __user *buffer, size_t *lenp, loff_t *ppos)
90710 {
90711 - struct ctl_table t;
90712 + ctl_table_no_const t;
90713 unsigned long tmptaint = get_taint();
90714 int err;
90715
90716 @@ -2076,7 +2136,6 @@ static int proc_taint(struct ctl_table *table, int write,
90717 return err;
90718 }
90719
90720 -#ifdef CONFIG_PRINTK
90721 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
90722 void __user *buffer, size_t *lenp, loff_t *ppos)
90723 {
90724 @@ -2085,7 +2144,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
90725
90726 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
90727 }
90728 -#endif
90729
90730 struct do_proc_dointvec_minmax_conv_param {
90731 int *min;
90732 @@ -2632,6 +2690,12 @@ int proc_dostring(struct ctl_table *table, int write,
90733 return -ENOSYS;
90734 }
90735
90736 +int proc_dostring_modpriv(struct ctl_table *table, int write,
90737 + void __user *buffer, size_t *lenp, loff_t *ppos)
90738 +{
90739 + return -ENOSYS;
90740 +}
90741 +
90742 int proc_dointvec(struct ctl_table *table, int write,
90743 void __user *buffer, size_t *lenp, loff_t *ppos)
90744 {
90745 @@ -2688,5 +2752,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
90746 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
90747 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
90748 EXPORT_SYMBOL(proc_dostring);
90749 +EXPORT_SYMBOL(proc_dostring_modpriv);
90750 EXPORT_SYMBOL(proc_doulongvec_minmax);
90751 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
90752 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
90753 index 13d2f7c..c93d0b0 100644
90754 --- a/kernel/taskstats.c
90755 +++ b/kernel/taskstats.c
90756 @@ -28,9 +28,12 @@
90757 #include <linux/fs.h>
90758 #include <linux/file.h>
90759 #include <linux/pid_namespace.h>
90760 +#include <linux/grsecurity.h>
90761 #include <net/genetlink.h>
90762 #include <linux/atomic.h>
90763
90764 +extern int gr_is_taskstats_denied(int pid);
90765 +
90766 /*
90767 * Maximum length of a cpumask that can be specified in
90768 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
90769 @@ -576,6 +579,9 @@ err:
90770
90771 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
90772 {
90773 + if (gr_is_taskstats_denied(current->pid))
90774 + return -EACCES;
90775 +
90776 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
90777 return cmd_attr_register_cpumask(info);
90778 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
90779 diff --git a/kernel/time.c b/kernel/time.c
90780 index 7c7964c..2a0d412 100644
90781 --- a/kernel/time.c
90782 +++ b/kernel/time.c
90783 @@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
90784 return error;
90785
90786 if (tz) {
90787 + /* we log in do_settimeofday called below, so don't log twice
90788 + */
90789 + if (!tv)
90790 + gr_log_timechange();
90791 +
90792 sys_tz = *tz;
90793 update_vsyscall_tz();
90794 if (firsttime) {
90795 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
90796 index 88c9c65..7497ebc 100644
90797 --- a/kernel/time/alarmtimer.c
90798 +++ b/kernel/time/alarmtimer.c
90799 @@ -795,7 +795,7 @@ static int __init alarmtimer_init(void)
90800 struct platform_device *pdev;
90801 int error = 0;
90802 int i;
90803 - struct k_clock alarm_clock = {
90804 + static struct k_clock alarm_clock = {
90805 .clock_getres = alarm_clock_getres,
90806 .clock_get = alarm_clock_get,
90807 .timer_create = alarm_timer_create,
90808 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
90809 index f7df8ea..0810193 100644
90810 --- a/kernel/time/timekeeping.c
90811 +++ b/kernel/time/timekeeping.c
90812 @@ -15,6 +15,7 @@
90813 #include <linux/init.h>
90814 #include <linux/mm.h>
90815 #include <linux/sched.h>
90816 +#include <linux/grsecurity.h>
90817 #include <linux/syscore_ops.h>
90818 #include <linux/clocksource.h>
90819 #include <linux/jiffies.h>
90820 @@ -502,6 +503,8 @@ int do_settimeofday(const struct timespec *tv)
90821 if (!timespec_valid_strict(tv))
90822 return -EINVAL;
90823
90824 + gr_log_timechange();
90825 +
90826 raw_spin_lock_irqsave(&timekeeper_lock, flags);
90827 write_seqcount_begin(&timekeeper_seq);
90828
90829 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
90830 index 61ed862..3b52c65 100644
90831 --- a/kernel/time/timer_list.c
90832 +++ b/kernel/time/timer_list.c
90833 @@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
90834
90835 static void print_name_offset(struct seq_file *m, void *sym)
90836 {
90837 +#ifdef CONFIG_GRKERNSEC_HIDESYM
90838 + SEQ_printf(m, "<%p>", NULL);
90839 +#else
90840 char symname[KSYM_NAME_LEN];
90841
90842 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
90843 SEQ_printf(m, "<%pK>", sym);
90844 else
90845 SEQ_printf(m, "%s", symname);
90846 +#endif
90847 }
90848
90849 static void
90850 @@ -119,7 +123,11 @@ next_one:
90851 static void
90852 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
90853 {
90854 +#ifdef CONFIG_GRKERNSEC_HIDESYM
90855 + SEQ_printf(m, " .base: %p\n", NULL);
90856 +#else
90857 SEQ_printf(m, " .base: %pK\n", base);
90858 +#endif
90859 SEQ_printf(m, " .index: %d\n",
90860 base->index);
90861 SEQ_printf(m, " .resolution: %Lu nsecs\n",
90862 @@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
90863 {
90864 struct proc_dir_entry *pe;
90865
90866 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
90867 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
90868 +#else
90869 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
90870 +#endif
90871 if (!pe)
90872 return -ENOMEM;
90873 return 0;
90874 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
90875 index 1fb08f2..ca4bb1e 100644
90876 --- a/kernel/time/timer_stats.c
90877 +++ b/kernel/time/timer_stats.c
90878 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
90879 static unsigned long nr_entries;
90880 static struct entry entries[MAX_ENTRIES];
90881
90882 -static atomic_t overflow_count;
90883 +static atomic_unchecked_t overflow_count;
90884
90885 /*
90886 * The entries are in a hash-table, for fast lookup:
90887 @@ -140,7 +140,7 @@ static void reset_entries(void)
90888 nr_entries = 0;
90889 memset(entries, 0, sizeof(entries));
90890 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
90891 - atomic_set(&overflow_count, 0);
90892 + atomic_set_unchecked(&overflow_count, 0);
90893 }
90894
90895 static struct entry *alloc_entry(void)
90896 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
90897 if (likely(entry))
90898 entry->count++;
90899 else
90900 - atomic_inc(&overflow_count);
90901 + atomic_inc_unchecked(&overflow_count);
90902
90903 out_unlock:
90904 raw_spin_unlock_irqrestore(lock, flags);
90905 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
90906
90907 static void print_name_offset(struct seq_file *m, unsigned long addr)
90908 {
90909 +#ifdef CONFIG_GRKERNSEC_HIDESYM
90910 + seq_printf(m, "<%p>", NULL);
90911 +#else
90912 char symname[KSYM_NAME_LEN];
90913
90914 if (lookup_symbol_name(addr, symname) < 0)
90915 - seq_printf(m, "<%p>", (void *)addr);
90916 + seq_printf(m, "<%pK>", (void *)addr);
90917 else
90918 seq_printf(m, "%s", symname);
90919 +#endif
90920 }
90921
90922 static int tstats_show(struct seq_file *m, void *v)
90923 @@ -300,8 +304,8 @@ static int tstats_show(struct seq_file *m, void *v)
90924
90925 seq_puts(m, "Timer Stats Version: v0.3\n");
90926 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
90927 - if (atomic_read(&overflow_count))
90928 - seq_printf(m, "Overflow: %d entries\n", atomic_read(&overflow_count));
90929 + if (atomic_read_unchecked(&overflow_count))
90930 + seq_printf(m, "Overflow: %d entries\n", atomic_read_unchecked(&overflow_count));
90931 seq_printf(m, "Collection: %s\n", timer_stats_active ? "active" : "inactive");
90932
90933 for (i = 0; i < nr_entries; i++) {
90934 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
90935 {
90936 struct proc_dir_entry *pe;
90937
90938 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
90939 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
90940 +#else
90941 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
90942 +#endif
90943 if (!pe)
90944 return -ENOMEM;
90945 return 0;
90946 diff --git a/kernel/timer.c b/kernel/timer.c
90947 index 3bb01a3..0e7760e 100644
90948 --- a/kernel/timer.c
90949 +++ b/kernel/timer.c
90950 @@ -1393,7 +1393,7 @@ void update_process_times(int user_tick)
90951 /*
90952 * This function runs timers and the timer-tq in bottom half context.
90953 */
90954 -static void run_timer_softirq(struct softirq_action *h)
90955 +static __latent_entropy void run_timer_softirq(void)
90956 {
90957 struct tvec_base *base = __this_cpu_read(tvec_bases);
90958
90959 @@ -1456,7 +1456,7 @@ static void process_timeout(unsigned long __data)
90960 *
90961 * In all cases the return value is guaranteed to be non-negative.
90962 */
90963 -signed long __sched schedule_timeout(signed long timeout)
90964 +signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
90965 {
90966 struct timer_list timer;
90967 unsigned long expire;
90968 diff --git a/kernel/torture.c b/kernel/torture.c
90969 index acc9afc..4f9eb49 100644
90970 --- a/kernel/torture.c
90971 +++ b/kernel/torture.c
90972 @@ -489,7 +489,7 @@ static int torture_shutdown_notify(struct notifier_block *unused1,
90973 mutex_lock(&fullstop_mutex);
90974 if (ACCESS_ONCE(fullstop) == FULLSTOP_DONTSTOP) {
90975 VERBOSE_TOROUT_STRING("Unscheduled system shutdown detected");
90976 - ACCESS_ONCE(fullstop) = FULLSTOP_SHUTDOWN;
90977 + ACCESS_ONCE_RW(fullstop) = FULLSTOP_SHUTDOWN;
90978 } else {
90979 pr_warn("Concurrent rmmod and shutdown illegal!\n");
90980 }
90981 @@ -551,11 +551,11 @@ static int torture_stutter(void *arg)
90982 do {
90983 if (!torture_must_stop()) {
90984 schedule_timeout_interruptible(stutter);
90985 - ACCESS_ONCE(stutter_pause_test) = 1;
90986 + ACCESS_ONCE_RW(stutter_pause_test) = 1;
90987 }
90988 if (!torture_must_stop())
90989 schedule_timeout_interruptible(stutter);
90990 - ACCESS_ONCE(stutter_pause_test) = 0;
90991 + ACCESS_ONCE_RW(stutter_pause_test) = 0;
90992 torture_shutdown_absorb("torture_stutter");
90993 } while (!torture_must_stop());
90994 torture_kthread_stopping("torture_stutter");
90995 @@ -636,7 +636,7 @@ bool torture_cleanup(void)
90996 schedule_timeout_uninterruptible(10);
90997 return true;
90998 }
90999 - ACCESS_ONCE(fullstop) = FULLSTOP_RMMOD;
91000 + ACCESS_ONCE_RW(fullstop) = FULLSTOP_RMMOD;
91001 mutex_unlock(&fullstop_mutex);
91002 torture_shutdown_cleanup();
91003 torture_shuffle_cleanup();
91004 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
91005 index c1bd4ad..4b861dc 100644
91006 --- a/kernel/trace/blktrace.c
91007 +++ b/kernel/trace/blktrace.c
91008 @@ -328,7 +328,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
91009 struct blk_trace *bt = filp->private_data;
91010 char buf[16];
91011
91012 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
91013 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
91014
91015 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
91016 }
91017 @@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
91018 return 1;
91019
91020 bt = buf->chan->private_data;
91021 - atomic_inc(&bt->dropped);
91022 + atomic_inc_unchecked(&bt->dropped);
91023 return 0;
91024 }
91025
91026 @@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
91027
91028 bt->dir = dir;
91029 bt->dev = dev;
91030 - atomic_set(&bt->dropped, 0);
91031 + atomic_set_unchecked(&bt->dropped, 0);
91032 INIT_LIST_HEAD(&bt->running_list);
91033
91034 ret = -EIO;
91035 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
91036 index 4a54a25..7ca9c89 100644
91037 --- a/kernel/trace/ftrace.c
91038 +++ b/kernel/trace/ftrace.c
91039 @@ -1960,12 +1960,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
91040 if (unlikely(ftrace_disabled))
91041 return 0;
91042
91043 + ret = ftrace_arch_code_modify_prepare();
91044 + FTRACE_WARN_ON(ret);
91045 + if (ret)
91046 + return 0;
91047 +
91048 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
91049 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
91050 if (ret) {
91051 ftrace_bug(ret, ip);
91052 - return 0;
91053 }
91054 - return 1;
91055 + return ret ? 0 : 1;
91056 }
91057
91058 /*
91059 @@ -4195,8 +4200,10 @@ static int ftrace_process_locs(struct module *mod,
91060 if (!count)
91061 return 0;
91062
91063 + pax_open_kernel();
91064 sort(start, count, sizeof(*start),
91065 ftrace_cmp_ips, ftrace_swap_ips);
91066 + pax_close_kernel();
91067
91068 start_pg = ftrace_allocate_pages(count);
91069 if (!start_pg)
91070 @@ -4908,8 +4915,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
91071 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
91072
91073 static int ftrace_graph_active;
91074 -static struct notifier_block ftrace_suspend_notifier;
91075 -
91076 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
91077 {
91078 return 0;
91079 @@ -5085,6 +5090,10 @@ static void update_function_graph_func(void)
91080 ftrace_graph_entry = ftrace_graph_entry_test;
91081 }
91082
91083 +static struct notifier_block ftrace_suspend_notifier = {
91084 + .notifier_call = ftrace_suspend_notifier_call
91085 +};
91086 +
91087 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
91088 trace_func_graph_ent_t entryfunc)
91089 {
91090 @@ -5098,7 +5107,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
91091 goto out;
91092 }
91093
91094 - ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
91095 register_pm_notifier(&ftrace_suspend_notifier);
91096
91097 ftrace_graph_active++;
91098 diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
91099 index c634868..00d0d19 100644
91100 --- a/kernel/trace/ring_buffer.c
91101 +++ b/kernel/trace/ring_buffer.c
91102 @@ -352,9 +352,9 @@ struct buffer_data_page {
91103 */
91104 struct buffer_page {
91105 struct list_head list; /* list of buffer pages */
91106 - local_t write; /* index for next write */
91107 + local_unchecked_t write; /* index for next write */
91108 unsigned read; /* index for next read */
91109 - local_t entries; /* entries on this page */
91110 + local_unchecked_t entries; /* entries on this page */
91111 unsigned long real_end; /* real end of data */
91112 struct buffer_data_page *page; /* Actual data page */
91113 };
91114 @@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
91115 unsigned long last_overrun;
91116 local_t entries_bytes;
91117 local_t entries;
91118 - local_t overrun;
91119 - local_t commit_overrun;
91120 + local_unchecked_t overrun;
91121 + local_unchecked_t commit_overrun;
91122 local_t dropped_events;
91123 local_t committing;
91124 local_t commits;
91125 @@ -992,8 +992,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
91126 *
91127 * We add a counter to the write field to denote this.
91128 */
91129 - old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
91130 - old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
91131 + old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
91132 + old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
91133
91134 /*
91135 * Just make sure we have seen our old_write and synchronize
91136 @@ -1021,8 +1021,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
91137 * cmpxchg to only update if an interrupt did not already
91138 * do it for us. If the cmpxchg fails, we don't care.
91139 */
91140 - (void)local_cmpxchg(&next_page->write, old_write, val);
91141 - (void)local_cmpxchg(&next_page->entries, old_entries, eval);
91142 + (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
91143 + (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
91144
91145 /*
91146 * No need to worry about races with clearing out the commit.
91147 @@ -1389,12 +1389,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
91148
91149 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
91150 {
91151 - return local_read(&bpage->entries) & RB_WRITE_MASK;
91152 + return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
91153 }
91154
91155 static inline unsigned long rb_page_write(struct buffer_page *bpage)
91156 {
91157 - return local_read(&bpage->write) & RB_WRITE_MASK;
91158 + return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
91159 }
91160
91161 static int
91162 @@ -1489,7 +1489,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
91163 * bytes consumed in ring buffer from here.
91164 * Increment overrun to account for the lost events.
91165 */
91166 - local_add(page_entries, &cpu_buffer->overrun);
91167 + local_add_unchecked(page_entries, &cpu_buffer->overrun);
91168 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
91169 }
91170
91171 @@ -2067,7 +2067,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
91172 * it is our responsibility to update
91173 * the counters.
91174 */
91175 - local_add(entries, &cpu_buffer->overrun);
91176 + local_add_unchecked(entries, &cpu_buffer->overrun);
91177 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
91178
91179 /*
91180 @@ -2217,7 +2217,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
91181 if (tail == BUF_PAGE_SIZE)
91182 tail_page->real_end = 0;
91183
91184 - local_sub(length, &tail_page->write);
91185 + local_sub_unchecked(length, &tail_page->write);
91186 return;
91187 }
91188
91189 @@ -2252,7 +2252,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
91190 rb_event_set_padding(event);
91191
91192 /* Set the write back to the previous setting */
91193 - local_sub(length, &tail_page->write);
91194 + local_sub_unchecked(length, &tail_page->write);
91195 return;
91196 }
91197
91198 @@ -2264,7 +2264,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
91199
91200 /* Set write to end of buffer */
91201 length = (tail + length) - BUF_PAGE_SIZE;
91202 - local_sub(length, &tail_page->write);
91203 + local_sub_unchecked(length, &tail_page->write);
91204 }
91205
91206 /*
91207 @@ -2290,7 +2290,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
91208 * about it.
91209 */
91210 if (unlikely(next_page == commit_page)) {
91211 - local_inc(&cpu_buffer->commit_overrun);
91212 + local_inc_unchecked(&cpu_buffer->commit_overrun);
91213 goto out_reset;
91214 }
91215
91216 @@ -2346,7 +2346,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
91217 cpu_buffer->tail_page) &&
91218 (cpu_buffer->commit_page ==
91219 cpu_buffer->reader_page))) {
91220 - local_inc(&cpu_buffer->commit_overrun);
91221 + local_inc_unchecked(&cpu_buffer->commit_overrun);
91222 goto out_reset;
91223 }
91224 }
91225 @@ -2394,7 +2394,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
91226 length += RB_LEN_TIME_EXTEND;
91227
91228 tail_page = cpu_buffer->tail_page;
91229 - write = local_add_return(length, &tail_page->write);
91230 + write = local_add_return_unchecked(length, &tail_page->write);
91231
91232 /* set write to only the index of the write */
91233 write &= RB_WRITE_MASK;
91234 @@ -2418,7 +2418,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
91235 kmemcheck_annotate_bitfield(event, bitfield);
91236 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
91237
91238 - local_inc(&tail_page->entries);
91239 + local_inc_unchecked(&tail_page->entries);
91240
91241 /*
91242 * If this is the first commit on the page, then update
91243 @@ -2451,7 +2451,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
91244
91245 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
91246 unsigned long write_mask =
91247 - local_read(&bpage->write) & ~RB_WRITE_MASK;
91248 + local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
91249 unsigned long event_length = rb_event_length(event);
91250 /*
91251 * This is on the tail page. It is possible that
91252 @@ -2461,7 +2461,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
91253 */
91254 old_index += write_mask;
91255 new_index += write_mask;
91256 - index = local_cmpxchg(&bpage->write, old_index, new_index);
91257 + index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
91258 if (index == old_index) {
91259 /* update counters */
91260 local_sub(event_length, &cpu_buffer->entries_bytes);
91261 @@ -2853,7 +2853,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
91262
91263 /* Do the likely case first */
91264 if (likely(bpage->page == (void *)addr)) {
91265 - local_dec(&bpage->entries);
91266 + local_dec_unchecked(&bpage->entries);
91267 return;
91268 }
91269
91270 @@ -2865,7 +2865,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
91271 start = bpage;
91272 do {
91273 if (bpage->page == (void *)addr) {
91274 - local_dec(&bpage->entries);
91275 + local_dec_unchecked(&bpage->entries);
91276 return;
91277 }
91278 rb_inc_page(cpu_buffer, &bpage);
91279 @@ -3149,7 +3149,7 @@ static inline unsigned long
91280 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
91281 {
91282 return local_read(&cpu_buffer->entries) -
91283 - (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
91284 + (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
91285 }
91286
91287 /**
91288 @@ -3238,7 +3238,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
91289 return 0;
91290
91291 cpu_buffer = buffer->buffers[cpu];
91292 - ret = local_read(&cpu_buffer->overrun);
91293 + ret = local_read_unchecked(&cpu_buffer->overrun);
91294
91295 return ret;
91296 }
91297 @@ -3261,7 +3261,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
91298 return 0;
91299
91300 cpu_buffer = buffer->buffers[cpu];
91301 - ret = local_read(&cpu_buffer->commit_overrun);
91302 + ret = local_read_unchecked(&cpu_buffer->commit_overrun);
91303
91304 return ret;
91305 }
91306 @@ -3346,7 +3346,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
91307 /* if you care about this being correct, lock the buffer */
91308 for_each_buffer_cpu(buffer, cpu) {
91309 cpu_buffer = buffer->buffers[cpu];
91310 - overruns += local_read(&cpu_buffer->overrun);
91311 + overruns += local_read_unchecked(&cpu_buffer->overrun);
91312 }
91313
91314 return overruns;
91315 @@ -3522,8 +3522,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
91316 /*
91317 * Reset the reader page to size zero.
91318 */
91319 - local_set(&cpu_buffer->reader_page->write, 0);
91320 - local_set(&cpu_buffer->reader_page->entries, 0);
91321 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
91322 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
91323 local_set(&cpu_buffer->reader_page->page->commit, 0);
91324 cpu_buffer->reader_page->real_end = 0;
91325
91326 @@ -3557,7 +3557,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
91327 * want to compare with the last_overrun.
91328 */
91329 smp_mb();
91330 - overwrite = local_read(&(cpu_buffer->overrun));
91331 + overwrite = local_read_unchecked(&(cpu_buffer->overrun));
91332
91333 /*
91334 * Here's the tricky part.
91335 @@ -4127,8 +4127,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
91336
91337 cpu_buffer->head_page
91338 = list_entry(cpu_buffer->pages, struct buffer_page, list);
91339 - local_set(&cpu_buffer->head_page->write, 0);
91340 - local_set(&cpu_buffer->head_page->entries, 0);
91341 + local_set_unchecked(&cpu_buffer->head_page->write, 0);
91342 + local_set_unchecked(&cpu_buffer->head_page->entries, 0);
91343 local_set(&cpu_buffer->head_page->page->commit, 0);
91344
91345 cpu_buffer->head_page->read = 0;
91346 @@ -4138,14 +4138,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
91347
91348 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
91349 INIT_LIST_HEAD(&cpu_buffer->new_pages);
91350 - local_set(&cpu_buffer->reader_page->write, 0);
91351 - local_set(&cpu_buffer->reader_page->entries, 0);
91352 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
91353 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
91354 local_set(&cpu_buffer->reader_page->page->commit, 0);
91355 cpu_buffer->reader_page->read = 0;
91356
91357 local_set(&cpu_buffer->entries_bytes, 0);
91358 - local_set(&cpu_buffer->overrun, 0);
91359 - local_set(&cpu_buffer->commit_overrun, 0);
91360 + local_set_unchecked(&cpu_buffer->overrun, 0);
91361 + local_set_unchecked(&cpu_buffer->commit_overrun, 0);
91362 local_set(&cpu_buffer->dropped_events, 0);
91363 local_set(&cpu_buffer->entries, 0);
91364 local_set(&cpu_buffer->committing, 0);
91365 @@ -4550,8 +4550,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
91366 rb_init_page(bpage);
91367 bpage = reader->page;
91368 reader->page = *data_page;
91369 - local_set(&reader->write, 0);
91370 - local_set(&reader->entries, 0);
91371 + local_set_unchecked(&reader->write, 0);
91372 + local_set_unchecked(&reader->entries, 0);
91373 reader->read = 0;
91374 *data_page = bpage;
91375
91376 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
91377 index 1848dc6..5fc244c 100644
91378 --- a/kernel/trace/trace.c
91379 +++ b/kernel/trace/trace.c
91380 @@ -3447,7 +3447,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
91381 return 0;
91382 }
91383
91384 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
91385 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
91386 {
91387 /* do nothing if flag is already set */
91388 if (!!(trace_flags & mask) == !!enabled)
91389 diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
91390 index 2e29d7b..61367d7 100644
91391 --- a/kernel/trace/trace.h
91392 +++ b/kernel/trace/trace.h
91393 @@ -1264,7 +1264,7 @@ extern const char *__stop___tracepoint_str[];
91394 void trace_printk_init_buffers(void);
91395 void trace_printk_start_comm(void);
91396 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
91397 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
91398 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
91399
91400 /*
91401 * Normal trace_printk() and friends allocates special buffers
91402 diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
91403 index 26dc348..8708ca7 100644
91404 --- a/kernel/trace/trace_clock.c
91405 +++ b/kernel/trace/trace_clock.c
91406 @@ -123,7 +123,7 @@ u64 notrace trace_clock_global(void)
91407 return now;
91408 }
91409
91410 -static atomic64_t trace_counter;
91411 +static atomic64_unchecked_t trace_counter;
91412
91413 /*
91414 * trace_clock_counter(): simply an atomic counter.
91415 @@ -132,5 +132,5 @@ static atomic64_t trace_counter;
91416 */
91417 u64 notrace trace_clock_counter(void)
91418 {
91419 - return atomic64_add_return(1, &trace_counter);
91420 + return atomic64_inc_return_unchecked(&trace_counter);
91421 }
91422 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
91423 index 3ddfd8f..41a10fe 100644
91424 --- a/kernel/trace/trace_events.c
91425 +++ b/kernel/trace/trace_events.c
91426 @@ -1718,7 +1718,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
91427 return 0;
91428 }
91429
91430 -struct ftrace_module_file_ops;
91431 static void __add_event_to_tracers(struct ftrace_event_call *call);
91432
91433 /* Add an additional event_call dynamically */
91434 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
91435 index 0abd9b8..6a663a2 100644
91436 --- a/kernel/trace/trace_mmiotrace.c
91437 +++ b/kernel/trace/trace_mmiotrace.c
91438 @@ -24,7 +24,7 @@ struct header_iter {
91439 static struct trace_array *mmio_trace_array;
91440 static bool overrun_detected;
91441 static unsigned long prev_overruns;
91442 -static atomic_t dropped_count;
91443 +static atomic_unchecked_t dropped_count;
91444
91445 static void mmio_reset_data(struct trace_array *tr)
91446 {
91447 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
91448
91449 static unsigned long count_overruns(struct trace_iterator *iter)
91450 {
91451 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
91452 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
91453 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
91454
91455 if (over > prev_overruns)
91456 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
91457 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
91458 sizeof(*entry), 0, pc);
91459 if (!event) {
91460 - atomic_inc(&dropped_count);
91461 + atomic_inc_unchecked(&dropped_count);
91462 return;
91463 }
91464 entry = ring_buffer_event_data(event);
91465 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
91466 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
91467 sizeof(*entry), 0, pc);
91468 if (!event) {
91469 - atomic_inc(&dropped_count);
91470 + atomic_inc_unchecked(&dropped_count);
91471 return;
91472 }
91473 entry = ring_buffer_event_data(event);
91474 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
91475 index a436de1..f64dde2 100644
91476 --- a/kernel/trace/trace_output.c
91477 +++ b/kernel/trace/trace_output.c
91478 @@ -294,7 +294,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
91479
91480 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
91481 if (!IS_ERR(p)) {
91482 - p = mangle_path(s->buffer + s->len, p, "\n");
91483 + p = mangle_path(s->buffer + s->len, p, "\n\\");
91484 if (p) {
91485 s->len = p - s->buffer;
91486 return 1;
91487 @@ -939,14 +939,16 @@ int register_ftrace_event(struct trace_event *event)
91488 goto out;
91489 }
91490
91491 + pax_open_kernel();
91492 if (event->funcs->trace == NULL)
91493 - event->funcs->trace = trace_nop_print;
91494 + *(void **)&event->funcs->trace = trace_nop_print;
91495 if (event->funcs->raw == NULL)
91496 - event->funcs->raw = trace_nop_print;
91497 + *(void **)&event->funcs->raw = trace_nop_print;
91498 if (event->funcs->hex == NULL)
91499 - event->funcs->hex = trace_nop_print;
91500 + *(void **)&event->funcs->hex = trace_nop_print;
91501 if (event->funcs->binary == NULL)
91502 - event->funcs->binary = trace_nop_print;
91503 + *(void **)&event->funcs->binary = trace_nop_print;
91504 + pax_close_kernel();
91505
91506 key = event->type & (EVENT_HASHSIZE - 1);
91507
91508 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
91509 index 21b320e..40607bc 100644
91510 --- a/kernel/trace/trace_stack.c
91511 +++ b/kernel/trace/trace_stack.c
91512 @@ -69,7 +69,7 @@ check_stack(unsigned long ip, unsigned long *stack)
91513 return;
91514
91515 /* we do not handle interrupt stacks yet */
91516 - if (!object_is_on_stack(stack))
91517 + if (!object_starts_on_stack(stack))
91518 return;
91519
91520 local_irq_save(flags);
91521 diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
91522 index bf71b4b..04dee68 100644
91523 --- a/kernel/user_namespace.c
91524 +++ b/kernel/user_namespace.c
91525 @@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
91526 !kgid_has_mapping(parent_ns, group))
91527 return -EPERM;
91528
91529 +#ifdef CONFIG_GRKERNSEC
91530 + /*
91531 + * This doesn't really inspire confidence:
91532 + * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
91533 + * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
91534 + * Increases kernel attack surface in areas developers
91535 + * previously cared little about ("low importance due
91536 + * to requiring "root" capability")
91537 + * To be removed when this code receives *proper* review
91538 + */
91539 + if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
91540 + !capable(CAP_SETGID))
91541 + return -EPERM;
91542 +#endif
91543 +
91544 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
91545 if (!ns)
91546 return -ENOMEM;
91547 @@ -865,7 +880,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
91548 if (atomic_read(&current->mm->mm_users) > 1)
91549 return -EINVAL;
91550
91551 - if (current->fs->users != 1)
91552 + if (atomic_read(&current->fs->users) != 1)
91553 return -EINVAL;
91554
91555 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
91556 diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
91557 index 4f69f9a..7c6f8f8 100644
91558 --- a/kernel/utsname_sysctl.c
91559 +++ b/kernel/utsname_sysctl.c
91560 @@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
91561 static int proc_do_uts_string(ctl_table *table, int write,
91562 void __user *buffer, size_t *lenp, loff_t *ppos)
91563 {
91564 - struct ctl_table uts_table;
91565 + ctl_table_no_const uts_table;
91566 int r;
91567 memcpy(&uts_table, table, sizeof(uts_table));
91568 uts_table.data = get_uts(table, write);
91569 diff --git a/kernel/watchdog.c b/kernel/watchdog.c
91570 index 30e4822..dd2b854 100644
91571 --- a/kernel/watchdog.c
91572 +++ b/kernel/watchdog.c
91573 @@ -479,7 +479,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
91574 static void watchdog_nmi_disable(unsigned int cpu) { return; }
91575 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
91576
91577 -static struct smp_hotplug_thread watchdog_threads = {
91578 +static struct smp_hotplug_thread watchdog_threads __read_only = {
91579 .store = &softlockup_watchdog,
91580 .thread_should_run = watchdog_should_run,
91581 .thread_fn = watchdog,
91582 diff --git a/kernel/workqueue.c b/kernel/workqueue.c
91583 index 8edc8718..b6a70b9 100644
91584 --- a/kernel/workqueue.c
91585 +++ b/kernel/workqueue.c
91586 @@ -4709,7 +4709,7 @@ static void rebind_workers(struct worker_pool *pool)
91587 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
91588 worker_flags |= WORKER_REBOUND;
91589 worker_flags &= ~WORKER_UNBOUND;
91590 - ACCESS_ONCE(worker->flags) = worker_flags;
91591 + ACCESS_ONCE_RW(worker->flags) = worker_flags;
91592 }
91593
91594 spin_unlock_irq(&pool->lock);
91595 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
91596 index 819ac51..1c8a65e 100644
91597 --- a/lib/Kconfig.debug
91598 +++ b/lib/Kconfig.debug
91599 @@ -853,7 +853,7 @@ config DEBUG_MUTEXES
91600
91601 config DEBUG_WW_MUTEX_SLOWPATH
91602 bool "Wait/wound mutex debugging: Slowpath testing"
91603 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91604 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91605 select DEBUG_LOCK_ALLOC
91606 select DEBUG_SPINLOCK
91607 select DEBUG_MUTEXES
91608 @@ -866,7 +866,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
91609
91610 config DEBUG_LOCK_ALLOC
91611 bool "Lock debugging: detect incorrect freeing of live locks"
91612 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91613 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91614 select DEBUG_SPINLOCK
91615 select DEBUG_MUTEXES
91616 select LOCKDEP
91617 @@ -880,7 +880,7 @@ config DEBUG_LOCK_ALLOC
91618
91619 config PROVE_LOCKING
91620 bool "Lock debugging: prove locking correctness"
91621 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91622 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91623 select LOCKDEP
91624 select DEBUG_SPINLOCK
91625 select DEBUG_MUTEXES
91626 @@ -931,7 +931,7 @@ config LOCKDEP
91627
91628 config LOCK_STAT
91629 bool "Lock usage statistics"
91630 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
91631 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
91632 select LOCKDEP
91633 select DEBUG_SPINLOCK
91634 select DEBUG_MUTEXES
91635 @@ -1403,6 +1403,7 @@ config LATENCYTOP
91636 depends on DEBUG_KERNEL
91637 depends on STACKTRACE_SUPPORT
91638 depends on PROC_FS
91639 + depends on !GRKERNSEC_HIDESYM
91640 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
91641 select KALLSYMS
91642 select KALLSYMS_ALL
91643 @@ -1419,7 +1420,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
91644 config DEBUG_STRICT_USER_COPY_CHECKS
91645 bool "Strict user copy size checks"
91646 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
91647 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
91648 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
91649 help
91650 Enabling this option turns a certain set of sanity checks for user
91651 copy operations into compile time failures.
91652 @@ -1538,7 +1539,7 @@ endmenu # runtime tests
91653
91654 config PROVIDE_OHCI1394_DMA_INIT
91655 bool "Remote debugging over FireWire early on boot"
91656 - depends on PCI && X86
91657 + depends on PCI && X86 && !GRKERNSEC
91658 help
91659 If you want to debug problems which hang or crash the kernel early
91660 on boot and the crashing machine has a FireWire port, you can use
91661 diff --git a/lib/Makefile b/lib/Makefile
91662 index 0cd7b68..e149e37 100644
91663 --- a/lib/Makefile
91664 +++ b/lib/Makefile
91665 @@ -52,7 +52,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
91666 obj-$(CONFIG_BTREE) += btree.o
91667 obj-$(CONFIG_ASSOCIATIVE_ARRAY) += assoc_array.o
91668 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
91669 -obj-$(CONFIG_DEBUG_LIST) += list_debug.o
91670 +obj-y += list_debug.o
91671 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
91672
91673 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
91674 diff --git a/lib/average.c b/lib/average.c
91675 index 114d1be..ab0350c 100644
91676 --- a/lib/average.c
91677 +++ b/lib/average.c
91678 @@ -55,7 +55,7 @@ struct ewma *ewma_add(struct ewma *avg, unsigned long val)
91679 {
91680 unsigned long internal = ACCESS_ONCE(avg->internal);
91681
91682 - ACCESS_ONCE(avg->internal) = internal ?
91683 + ACCESS_ONCE_RW(avg->internal) = internal ?
91684 (((internal << avg->weight) - internal) +
91685 (val << avg->factor)) >> avg->weight :
91686 (val << avg->factor);
91687 diff --git a/lib/bitmap.c b/lib/bitmap.c
91688 index 06f7e4f..f3cf2b0 100644
91689 --- a/lib/bitmap.c
91690 +++ b/lib/bitmap.c
91691 @@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
91692 {
91693 int c, old_c, totaldigits, ndigits, nchunks, nbits;
91694 u32 chunk;
91695 - const char __user __force *ubuf = (const char __user __force *)buf;
91696 + const char __user *ubuf = (const char __force_user *)buf;
91697
91698 bitmap_zero(maskp, nmaskbits);
91699
91700 @@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
91701 {
91702 if (!access_ok(VERIFY_READ, ubuf, ulen))
91703 return -EFAULT;
91704 - return __bitmap_parse((const char __force *)ubuf,
91705 + return __bitmap_parse((const char __force_kernel *)ubuf,
91706 ulen, 1, maskp, nmaskbits);
91707
91708 }
91709 @@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
91710 {
91711 unsigned a, b;
91712 int c, old_c, totaldigits;
91713 - const char __user __force *ubuf = (const char __user __force *)buf;
91714 + const char __user *ubuf = (const char __force_user *)buf;
91715 int exp_digit, in_range;
91716
91717 totaldigits = c = 0;
91718 @@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
91719 {
91720 if (!access_ok(VERIFY_READ, ubuf, ulen))
91721 return -EFAULT;
91722 - return __bitmap_parselist((const char __force *)ubuf,
91723 + return __bitmap_parselist((const char __force_kernel *)ubuf,
91724 ulen, 1, maskp, nmaskbits);
91725 }
91726 EXPORT_SYMBOL(bitmap_parselist_user);
91727 diff --git a/lib/bug.c b/lib/bug.c
91728 index 1686034..a9c00c8 100644
91729 --- a/lib/bug.c
91730 +++ b/lib/bug.c
91731 @@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
91732 return BUG_TRAP_TYPE_NONE;
91733
91734 bug = find_bug(bugaddr);
91735 + if (!bug)
91736 + return BUG_TRAP_TYPE_NONE;
91737
91738 file = NULL;
91739 line = 0;
91740 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
91741 index e0731c3..ad66444 100644
91742 --- a/lib/debugobjects.c
91743 +++ b/lib/debugobjects.c
91744 @@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
91745 if (limit > 4)
91746 return;
91747
91748 - is_on_stack = object_is_on_stack(addr);
91749 + is_on_stack = object_starts_on_stack(addr);
91750 if (is_on_stack == onstack)
91751 return;
91752
91753 diff --git a/lib/div64.c b/lib/div64.c
91754 index 4382ad7..08aa558 100644
91755 --- a/lib/div64.c
91756 +++ b/lib/div64.c
91757 @@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
91758 EXPORT_SYMBOL(__div64_32);
91759
91760 #ifndef div_s64_rem
91761 -s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
91762 +s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
91763 {
91764 u64 quotient;
91765
91766 @@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
91767 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
91768 */
91769 #ifndef div64_u64
91770 -u64 div64_u64(u64 dividend, u64 divisor)
91771 +u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
91772 {
91773 u32 high = divisor >> 32;
91774 u64 quot;
91775 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
91776 index 98f2d7e..899da5c 100644
91777 --- a/lib/dma-debug.c
91778 +++ b/lib/dma-debug.c
91779 @@ -971,7 +971,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
91780
91781 void dma_debug_add_bus(struct bus_type *bus)
91782 {
91783 - struct notifier_block *nb;
91784 + notifier_block_no_const *nb;
91785
91786 if (global_disable)
91787 return;
91788 @@ -1148,7 +1148,7 @@ static void check_unmap(struct dma_debug_entry *ref)
91789
91790 static void check_for_stack(struct device *dev, void *addr)
91791 {
91792 - if (object_is_on_stack(addr))
91793 + if (object_starts_on_stack(addr))
91794 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
91795 "stack [addr=%p]\n", addr);
91796 }
91797 diff --git a/lib/hash.c b/lib/hash.c
91798 index fea973f..386626f 100644
91799 --- a/lib/hash.c
91800 +++ b/lib/hash.c
91801 @@ -14,7 +14,7 @@
91802 #include <linux/hash.h>
91803 #include <linux/cache.h>
91804
91805 -static struct fast_hash_ops arch_hash_ops __read_mostly = {
91806 +static struct fast_hash_ops arch_hash_ops __read_only = {
91807 .hash = jhash,
91808 .hash2 = jhash2,
91809 };
91810 diff --git a/lib/inflate.c b/lib/inflate.c
91811 index 013a761..c28f3fc 100644
91812 --- a/lib/inflate.c
91813 +++ b/lib/inflate.c
91814 @@ -269,7 +269,7 @@ static void free(void *where)
91815 malloc_ptr = free_mem_ptr;
91816 }
91817 #else
91818 -#define malloc(a) kmalloc(a, GFP_KERNEL)
91819 +#define malloc(a) kmalloc((a), GFP_KERNEL)
91820 #define free(a) kfree(a)
91821 #endif
91822
91823 diff --git a/lib/ioremap.c b/lib/ioremap.c
91824 index 0c9216c..863bd89 100644
91825 --- a/lib/ioremap.c
91826 +++ b/lib/ioremap.c
91827 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
91828 unsigned long next;
91829
91830 phys_addr -= addr;
91831 - pmd = pmd_alloc(&init_mm, pud, addr);
91832 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
91833 if (!pmd)
91834 return -ENOMEM;
91835 do {
91836 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
91837 unsigned long next;
91838
91839 phys_addr -= addr;
91840 - pud = pud_alloc(&init_mm, pgd, addr);
91841 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
91842 if (!pud)
91843 return -ENOMEM;
91844 do {
91845 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
91846 index bd2bea9..6b3c95e 100644
91847 --- a/lib/is_single_threaded.c
91848 +++ b/lib/is_single_threaded.c
91849 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
91850 struct task_struct *p, *t;
91851 bool ret;
91852
91853 + if (!mm)
91854 + return true;
91855 +
91856 if (atomic_read(&task->signal->live) != 1)
91857 return false;
91858
91859 diff --git a/lib/kobject.c b/lib/kobject.c
91860 index 58751bb..93a1853 100644
91861 --- a/lib/kobject.c
91862 +++ b/lib/kobject.c
91863 @@ -931,9 +931,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
91864
91865
91866 static DEFINE_SPINLOCK(kobj_ns_type_lock);
91867 -static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
91868 +static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
91869
91870 -int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
91871 +int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
91872 {
91873 enum kobj_ns_type type = ops->type;
91874 int error;
91875 diff --git a/lib/list_debug.c b/lib/list_debug.c
91876 index c24c2f7..f0296f4 100644
91877 --- a/lib/list_debug.c
91878 +++ b/lib/list_debug.c
91879 @@ -11,7 +11,9 @@
91880 #include <linux/bug.h>
91881 #include <linux/kernel.h>
91882 #include <linux/rculist.h>
91883 +#include <linux/mm.h>
91884
91885 +#ifdef CONFIG_DEBUG_LIST
91886 /*
91887 * Insert a new entry between two known consecutive entries.
91888 *
91889 @@ -19,21 +21,40 @@
91890 * the prev/next entries already!
91891 */
91892
91893 +static bool __list_add_debug(struct list_head *new,
91894 + struct list_head *prev,
91895 + struct list_head *next)
91896 +{
91897 + if (unlikely(next->prev != prev)) {
91898 + printk(KERN_ERR "list_add corruption. next->prev should be "
91899 + "prev (%p), but was %p. (next=%p).\n",
91900 + prev, next->prev, next);
91901 + BUG();
91902 + return false;
91903 + }
91904 + if (unlikely(prev->next != next)) {
91905 + printk(KERN_ERR "list_add corruption. prev->next should be "
91906 + "next (%p), but was %p. (prev=%p).\n",
91907 + next, prev->next, prev);
91908 + BUG();
91909 + return false;
91910 + }
91911 + if (unlikely(new == prev || new == next)) {
91912 + printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
91913 + new, prev, next);
91914 + BUG();
91915 + return false;
91916 + }
91917 + return true;
91918 +}
91919 +
91920 void __list_add(struct list_head *new,
91921 - struct list_head *prev,
91922 - struct list_head *next)
91923 + struct list_head *prev,
91924 + struct list_head *next)
91925 {
91926 - WARN(next->prev != prev,
91927 - "list_add corruption. next->prev should be "
91928 - "prev (%p), but was %p. (next=%p).\n",
91929 - prev, next->prev, next);
91930 - WARN(prev->next != next,
91931 - "list_add corruption. prev->next should be "
91932 - "next (%p), but was %p. (prev=%p).\n",
91933 - next, prev->next, prev);
91934 - WARN(new == prev || new == next,
91935 - "list_add double add: new=%p, prev=%p, next=%p.\n",
91936 - new, prev, next);
91937 + if (!__list_add_debug(new, prev, next))
91938 + return;
91939 +
91940 next->prev = new;
91941 new->next = next;
91942 new->prev = prev;
91943 @@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
91944 }
91945 EXPORT_SYMBOL(__list_add);
91946
91947 -void __list_del_entry(struct list_head *entry)
91948 +static bool __list_del_entry_debug(struct list_head *entry)
91949 {
91950 struct list_head *prev, *next;
91951
91952 prev = entry->prev;
91953 next = entry->next;
91954
91955 - if (WARN(next == LIST_POISON1,
91956 - "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
91957 - entry, LIST_POISON1) ||
91958 - WARN(prev == LIST_POISON2,
91959 - "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
91960 - entry, LIST_POISON2) ||
91961 - WARN(prev->next != entry,
91962 - "list_del corruption. prev->next should be %p, "
91963 - "but was %p\n", entry, prev->next) ||
91964 - WARN(next->prev != entry,
91965 - "list_del corruption. next->prev should be %p, "
91966 - "but was %p\n", entry, next->prev))
91967 + if (unlikely(next == LIST_POISON1)) {
91968 + printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
91969 + entry, LIST_POISON1);
91970 + BUG();
91971 + return false;
91972 + }
91973 + if (unlikely(prev == LIST_POISON2)) {
91974 + printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
91975 + entry, LIST_POISON2);
91976 + BUG();
91977 + return false;
91978 + }
91979 + if (unlikely(entry->prev->next != entry)) {
91980 + printk(KERN_ERR "list_del corruption. prev->next should be %p, "
91981 + "but was %p\n", entry, prev->next);
91982 + BUG();
91983 + return false;
91984 + }
91985 + if (unlikely(entry->next->prev != entry)) {
91986 + printk(KERN_ERR "list_del corruption. next->prev should be %p, "
91987 + "but was %p\n", entry, next->prev);
91988 + BUG();
91989 + return false;
91990 + }
91991 + return true;
91992 +}
91993 +
91994 +void __list_del_entry(struct list_head *entry)
91995 +{
91996 + if (!__list_del_entry_debug(entry))
91997 return;
91998
91999 - __list_del(prev, next);
92000 + __list_del(entry->prev, entry->next);
92001 }
92002 EXPORT_SYMBOL(__list_del_entry);
92003
92004 @@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
92005 void __list_add_rcu(struct list_head *new,
92006 struct list_head *prev, struct list_head *next)
92007 {
92008 - WARN(next->prev != prev,
92009 - "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
92010 - prev, next->prev, next);
92011 - WARN(prev->next != next,
92012 - "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
92013 - next, prev->next, prev);
92014 + if (!__list_add_debug(new, prev, next))
92015 + return;
92016 +
92017 new->next = next;
92018 new->prev = prev;
92019 rcu_assign_pointer(list_next_rcu(prev), new);
92020 next->prev = new;
92021 }
92022 EXPORT_SYMBOL(__list_add_rcu);
92023 +#endif
92024 +
92025 +void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
92026 +{
92027 +#ifdef CONFIG_DEBUG_LIST
92028 + if (!__list_add_debug(new, prev, next))
92029 + return;
92030 +#endif
92031 +
92032 + pax_open_kernel();
92033 + next->prev = new;
92034 + new->next = next;
92035 + new->prev = prev;
92036 + prev->next = new;
92037 + pax_close_kernel();
92038 +}
92039 +EXPORT_SYMBOL(__pax_list_add);
92040 +
92041 +void pax_list_del(struct list_head *entry)
92042 +{
92043 +#ifdef CONFIG_DEBUG_LIST
92044 + if (!__list_del_entry_debug(entry))
92045 + return;
92046 +#endif
92047 +
92048 + pax_open_kernel();
92049 + __list_del(entry->prev, entry->next);
92050 + entry->next = LIST_POISON1;
92051 + entry->prev = LIST_POISON2;
92052 + pax_close_kernel();
92053 +}
92054 +EXPORT_SYMBOL(pax_list_del);
92055 +
92056 +void pax_list_del_init(struct list_head *entry)
92057 +{
92058 + pax_open_kernel();
92059 + __list_del(entry->prev, entry->next);
92060 + INIT_LIST_HEAD(entry);
92061 + pax_close_kernel();
92062 +}
92063 +EXPORT_SYMBOL(pax_list_del_init);
92064 +
92065 +void __pax_list_add_rcu(struct list_head *new,
92066 + struct list_head *prev, struct list_head *next)
92067 +{
92068 +#ifdef CONFIG_DEBUG_LIST
92069 + if (!__list_add_debug(new, prev, next))
92070 + return;
92071 +#endif
92072 +
92073 + pax_open_kernel();
92074 + new->next = next;
92075 + new->prev = prev;
92076 + rcu_assign_pointer(list_next_rcu(prev), new);
92077 + next->prev = new;
92078 + pax_close_kernel();
92079 +}
92080 +EXPORT_SYMBOL(__pax_list_add_rcu);
92081 +
92082 +void pax_list_del_rcu(struct list_head *entry)
92083 +{
92084 +#ifdef CONFIG_DEBUG_LIST
92085 + if (!__list_del_entry_debug(entry))
92086 + return;
92087 +#endif
92088 +
92089 + pax_open_kernel();
92090 + __list_del(entry->prev, entry->next);
92091 + entry->next = LIST_POISON1;
92092 + entry->prev = LIST_POISON2;
92093 + pax_close_kernel();
92094 +}
92095 +EXPORT_SYMBOL(pax_list_del_rcu);
92096 diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
92097 index 963b703..438bc51 100644
92098 --- a/lib/percpu-refcount.c
92099 +++ b/lib/percpu-refcount.c
92100 @@ -29,7 +29,7 @@
92101 * can't hit 0 before we've added up all the percpu refs.
92102 */
92103
92104 -#define PCPU_COUNT_BIAS (1U << 31)
92105 +#define PCPU_COUNT_BIAS (1U << 30)
92106
92107 /**
92108 * percpu_ref_init - initialize a percpu refcount
92109 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
92110 index 9599aa7..9cf6c72 100644
92111 --- a/lib/radix-tree.c
92112 +++ b/lib/radix-tree.c
92113 @@ -66,7 +66,7 @@ struct radix_tree_preload {
92114 int nr;
92115 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
92116 };
92117 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
92118 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
92119
92120 static inline void *ptr_to_indirect(void *ptr)
92121 {
92122 diff --git a/lib/random32.c b/lib/random32.c
92123 index fa5da61..35fe9af 100644
92124 --- a/lib/random32.c
92125 +++ b/lib/random32.c
92126 @@ -42,7 +42,7 @@
92127 static void __init prandom_state_selftest(void);
92128 #endif
92129
92130 -static DEFINE_PER_CPU(struct rnd_state, net_rand_state);
92131 +static DEFINE_PER_CPU(struct rnd_state, net_rand_state) __latent_entropy;
92132
92133 /**
92134 * prandom_u32_state - seeded pseudo-random number generator.
92135 diff --git a/lib/rbtree.c b/lib/rbtree.c
92136 index 65f4eff..2cfa167 100644
92137 --- a/lib/rbtree.c
92138 +++ b/lib/rbtree.c
92139 @@ -380,7 +380,9 @@ static inline void dummy_copy(struct rb_node *old, struct rb_node *new) {}
92140 static inline void dummy_rotate(struct rb_node *old, struct rb_node *new) {}
92141
92142 static const struct rb_augment_callbacks dummy_callbacks = {
92143 - dummy_propagate, dummy_copy, dummy_rotate
92144 + .propagate = dummy_propagate,
92145 + .copy = dummy_copy,
92146 + .rotate = dummy_rotate
92147 };
92148
92149 void rb_insert_color(struct rb_node *node, struct rb_root *root)
92150 diff --git a/lib/show_mem.c b/lib/show_mem.c
92151 index 0922579..9d7adb9 100644
92152 --- a/lib/show_mem.c
92153 +++ b/lib/show_mem.c
92154 @@ -44,6 +44,6 @@ void show_mem(unsigned int filter)
92155 quicklist_total_size());
92156 #endif
92157 #ifdef CONFIG_MEMORY_FAILURE
92158 - printk("%lu pages hwpoisoned\n", atomic_long_read(&num_poisoned_pages));
92159 + printk("%lu pages hwpoisoned\n", atomic_long_read_unchecked(&num_poisoned_pages));
92160 #endif
92161 }
92162 diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
92163 index bb2b201..46abaf9 100644
92164 --- a/lib/strncpy_from_user.c
92165 +++ b/lib/strncpy_from_user.c
92166 @@ -21,7 +21,7 @@
92167 */
92168 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
92169 {
92170 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
92171 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
92172 long res = 0;
92173
92174 /*
92175 diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
92176 index a28df52..3d55877 100644
92177 --- a/lib/strnlen_user.c
92178 +++ b/lib/strnlen_user.c
92179 @@ -26,7 +26,7 @@
92180 */
92181 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
92182 {
92183 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
92184 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
92185 long align, res = 0;
92186 unsigned long c;
92187
92188 diff --git a/lib/swiotlb.c b/lib/swiotlb.c
92189 index b604b83..c0547f6 100644
92190 --- a/lib/swiotlb.c
92191 +++ b/lib/swiotlb.c
92192 @@ -674,7 +674,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
92193
92194 void
92195 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
92196 - dma_addr_t dev_addr)
92197 + dma_addr_t dev_addr, struct dma_attrs *attrs)
92198 {
92199 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
92200
92201 diff --git a/lib/usercopy.c b/lib/usercopy.c
92202 index 4f5b1dd..7cab418 100644
92203 --- a/lib/usercopy.c
92204 +++ b/lib/usercopy.c
92205 @@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
92206 WARN(1, "Buffer overflow detected!\n");
92207 }
92208 EXPORT_SYMBOL(copy_from_user_overflow);
92209 +
92210 +void copy_to_user_overflow(void)
92211 +{
92212 + WARN(1, "Buffer overflow detected!\n");
92213 +}
92214 +EXPORT_SYMBOL(copy_to_user_overflow);
92215 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
92216 index 0648291..42bf42b 100644
92217 --- a/lib/vsprintf.c
92218 +++ b/lib/vsprintf.c
92219 @@ -16,6 +16,9 @@
92220 * - scnprintf and vscnprintf
92221 */
92222
92223 +#ifdef CONFIG_GRKERNSEC_HIDESYM
92224 +#define __INCLUDED_BY_HIDESYM 1
92225 +#endif
92226 #include <stdarg.h>
92227 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
92228 #include <linux/types.h>
92229 @@ -1183,7 +1186,11 @@ char *address_val(char *buf, char *end, const void *addr,
92230 return number(buf, end, num, spec);
92231 }
92232
92233 +#ifdef CONFIG_GRKERNSEC_HIDESYM
92234 +int kptr_restrict __read_mostly = 2;
92235 +#else
92236 int kptr_restrict __read_mostly;
92237 +#endif
92238
92239 /*
92240 * Show a '%p' thing. A kernel extension is that the '%p' is followed
92241 @@ -1196,6 +1203,7 @@ int kptr_restrict __read_mostly;
92242 * - 'f' For simple symbolic function names without offset
92243 * - 'S' For symbolic direct pointers with offset
92244 * - 's' For symbolic direct pointers without offset
92245 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
92246 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
92247 * - 'B' For backtraced symbolic direct pointers with offset
92248 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
92249 @@ -1263,12 +1271,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92250
92251 if (!ptr && *fmt != 'K') {
92252 /*
92253 - * Print (null) with the same width as a pointer so it makes
92254 + * Print (nil) with the same width as a pointer so it makes
92255 * tabular output look nice.
92256 */
92257 if (spec.field_width == -1)
92258 spec.field_width = default_width;
92259 - return string(buf, end, "(null)", spec);
92260 + return string(buf, end, "(nil)", spec);
92261 }
92262
92263 switch (*fmt) {
92264 @@ -1278,6 +1286,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92265 /* Fallthrough */
92266 case 'S':
92267 case 's':
92268 +#ifdef CONFIG_GRKERNSEC_HIDESYM
92269 + break;
92270 +#else
92271 + return symbol_string(buf, end, ptr, spec, fmt);
92272 +#endif
92273 + case 'A':
92274 case 'B':
92275 return symbol_string(buf, end, ptr, spec, fmt);
92276 case 'R':
92277 @@ -1333,6 +1347,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92278 va_end(va);
92279 return buf;
92280 }
92281 + case 'P':
92282 + break;
92283 case 'K':
92284 /*
92285 * %pK cannot be used in IRQ context because its test
92286 @@ -1390,6 +1406,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
92287 ((const struct file *)ptr)->f_path.dentry,
92288 spec, fmt);
92289 }
92290 +
92291 +#ifdef CONFIG_GRKERNSEC_HIDESYM
92292 + /* 'P' = approved pointers to copy to userland,
92293 + as in the /proc/kallsyms case, as we make it display nothing
92294 + for non-root users, and the real contents for root users
92295 + Also ignore 'K' pointers, since we force their NULLing for non-root users
92296 + above
92297 + */
92298 + if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
92299 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
92300 + dump_stack();
92301 + ptr = NULL;
92302 + }
92303 +#endif
92304 +
92305 spec.flags |= SMALL;
92306 if (spec.field_width == -1) {
92307 spec.field_width = default_width;
92308 @@ -2089,11 +2120,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
92309 typeof(type) value; \
92310 if (sizeof(type) == 8) { \
92311 args = PTR_ALIGN(args, sizeof(u32)); \
92312 - *(u32 *)&value = *(u32 *)args; \
92313 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
92314 + *(u32 *)&value = *(const u32 *)args; \
92315 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
92316 } else { \
92317 args = PTR_ALIGN(args, sizeof(type)); \
92318 - value = *(typeof(type) *)args; \
92319 + value = *(const typeof(type) *)args; \
92320 } \
92321 args += sizeof(type); \
92322 value; \
92323 @@ -2156,7 +2187,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
92324 case FORMAT_TYPE_STR: {
92325 const char *str_arg = args;
92326 args += strlen(str_arg) + 1;
92327 - str = string(str, end, (char *)str_arg, spec);
92328 + str = string(str, end, str_arg, spec);
92329 break;
92330 }
92331
92332 diff --git a/localversion-grsec b/localversion-grsec
92333 new file mode 100644
92334 index 0000000..7cd6065
92335 --- /dev/null
92336 +++ b/localversion-grsec
92337 @@ -0,0 +1 @@
92338 +-grsec
92339 diff --git a/mm/Kconfig b/mm/Kconfig
92340 index 2f42b9c..6095e14 100644
92341 --- a/mm/Kconfig
92342 +++ b/mm/Kconfig
92343 @@ -330,10 +330,11 @@ config KSM
92344 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
92345
92346 config DEFAULT_MMAP_MIN_ADDR
92347 - int "Low address space to protect from user allocation"
92348 + int "Low address space to protect from user allocation"
92349 depends on MMU
92350 - default 4096
92351 - help
92352 + default 32768 if ALPHA || ARM || PARISC || SPARC32
92353 + default 65536
92354 + help
92355 This is the portion of low virtual memory which should be protected
92356 from userspace allocation. Keeping a user from writing to low pages
92357 can help reduce the impact of kernel NULL pointer bugs.
92358 @@ -364,7 +365,7 @@ config MEMORY_FAILURE
92359
92360 config HWPOISON_INJECT
92361 tristate "HWPoison pages injector"
92362 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
92363 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
92364 select PROC_PAGE_MONITOR
92365
92366 config NOMMU_INITIAL_TRIM_EXCESS
92367 diff --git a/mm/backing-dev.c b/mm/backing-dev.c
92368 index 09d9591..165bb75 100644
92369 --- a/mm/backing-dev.c
92370 +++ b/mm/backing-dev.c
92371 @@ -12,7 +12,7 @@
92372 #include <linux/device.h>
92373 #include <trace/events/writeback.h>
92374
92375 -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
92376 +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
92377
92378 struct backing_dev_info default_backing_dev_info = {
92379 .name = "default",
92380 @@ -533,7 +533,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
92381 return err;
92382
92383 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
92384 - atomic_long_inc_return(&bdi_seq));
92385 + atomic_long_inc_return_unchecked(&bdi_seq));
92386 if (err) {
92387 bdi_destroy(bdi);
92388 return err;
92389 diff --git a/mm/filemap.c b/mm/filemap.c
92390 index 088358c..bb415bf 100644
92391 --- a/mm/filemap.c
92392 +++ b/mm/filemap.c
92393 @@ -2125,7 +2125,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
92394 struct address_space *mapping = file->f_mapping;
92395
92396 if (!mapping->a_ops->readpage)
92397 - return -ENOEXEC;
92398 + return -ENODEV;
92399 file_accessed(file);
92400 vma->vm_ops = &generic_file_vm_ops;
92401 return 0;
92402 @@ -2303,6 +2303,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
92403 *pos = i_size_read(inode);
92404
92405 if (limit != RLIM_INFINITY) {
92406 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
92407 if (*pos >= limit) {
92408 send_sig(SIGXFSZ, current, 0);
92409 return -EFBIG;
92410 diff --git a/mm/fremap.c b/mm/fremap.c
92411 index 34feba6..315fe78 100644
92412 --- a/mm/fremap.c
92413 +++ b/mm/fremap.c
92414 @@ -179,6 +179,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
92415 retry:
92416 vma = find_vma(mm, start);
92417
92418 +#ifdef CONFIG_PAX_SEGMEXEC
92419 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
92420 + goto out;
92421 +#endif
92422 +
92423 /*
92424 * Make sure the vma is shared, that it supports prefaulting,
92425 * and that the remapped range is valid and fully within
92426 diff --git a/mm/highmem.c b/mm/highmem.c
92427 index b32b70c..e512eb0 100644
92428 --- a/mm/highmem.c
92429 +++ b/mm/highmem.c
92430 @@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
92431 * So no dangers, even with speculative execution.
92432 */
92433 page = pte_page(pkmap_page_table[i]);
92434 + pax_open_kernel();
92435 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
92436 -
92437 + pax_close_kernel();
92438 set_page_address(page, NULL);
92439 need_flush = 1;
92440 }
92441 @@ -198,9 +199,11 @@ start:
92442 }
92443 }
92444 vaddr = PKMAP_ADDR(last_pkmap_nr);
92445 +
92446 + pax_open_kernel();
92447 set_pte_at(&init_mm, vaddr,
92448 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
92449 -
92450 + pax_close_kernel();
92451 pkmap_count[last_pkmap_nr] = 1;
92452 set_page_address(page, (void *)vaddr);
92453
92454 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
92455 index a646f15..f55da4c 100644
92456 --- a/mm/hugetlb.c
92457 +++ b/mm/hugetlb.c
92458 @@ -2107,6 +2107,7 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
92459 struct hstate *h = &default_hstate;
92460 unsigned long tmp;
92461 int ret;
92462 + ctl_table_no_const hugetlb_table;
92463
92464 if (!hugepages_supported())
92465 return -ENOTSUPP;
92466 @@ -2116,9 +2117,10 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
92467 if (write && h->order >= MAX_ORDER)
92468 return -EINVAL;
92469
92470 - table->data = &tmp;
92471 - table->maxlen = sizeof(unsigned long);
92472 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
92473 + hugetlb_table = *table;
92474 + hugetlb_table.data = &tmp;
92475 + hugetlb_table.maxlen = sizeof(unsigned long);
92476 + ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
92477 if (ret)
92478 goto out;
92479
92480 @@ -2163,6 +2165,7 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
92481 struct hstate *h = &default_hstate;
92482 unsigned long tmp;
92483 int ret;
92484 + ctl_table_no_const hugetlb_table;
92485
92486 if (!hugepages_supported())
92487 return -ENOTSUPP;
92488 @@ -2172,9 +2175,10 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
92489 if (write && h->order >= MAX_ORDER)
92490 return -EINVAL;
92491
92492 - table->data = &tmp;
92493 - table->maxlen = sizeof(unsigned long);
92494 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
92495 + hugetlb_table = *table;
92496 + hugetlb_table.data = &tmp;
92497 + hugetlb_table.maxlen = sizeof(unsigned long);
92498 + ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
92499 if (ret)
92500 goto out;
92501
92502 @@ -2654,6 +2658,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
92503 return 1;
92504 }
92505
92506 +#ifdef CONFIG_PAX_SEGMEXEC
92507 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
92508 +{
92509 + struct mm_struct *mm = vma->vm_mm;
92510 + struct vm_area_struct *vma_m;
92511 + unsigned long address_m;
92512 + pte_t *ptep_m;
92513 +
92514 + vma_m = pax_find_mirror_vma(vma);
92515 + if (!vma_m)
92516 + return;
92517 +
92518 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
92519 + address_m = address + SEGMEXEC_TASK_SIZE;
92520 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
92521 + get_page(page_m);
92522 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
92523 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
92524 +}
92525 +#endif
92526 +
92527 /*
92528 * Hugetlb_cow() should be called with page lock of the original hugepage held.
92529 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
92530 @@ -2771,6 +2796,11 @@ retry_avoidcopy:
92531 make_huge_pte(vma, new_page, 1));
92532 page_remove_rmap(old_page);
92533 hugepage_add_new_anon_rmap(new_page, vma, address);
92534 +
92535 +#ifdef CONFIG_PAX_SEGMEXEC
92536 + pax_mirror_huge_pte(vma, address, new_page);
92537 +#endif
92538 +
92539 /* Make the old page be freed below */
92540 new_page = old_page;
92541 }
92542 @@ -2930,6 +2960,10 @@ retry:
92543 && (vma->vm_flags & VM_SHARED)));
92544 set_huge_pte_at(mm, address, ptep, new_pte);
92545
92546 +#ifdef CONFIG_PAX_SEGMEXEC
92547 + pax_mirror_huge_pte(vma, address, page);
92548 +#endif
92549 +
92550 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
92551 /* Optimization, do the COW without a second fault */
92552 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page, ptl);
92553 @@ -2996,6 +3030,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92554 struct hstate *h = hstate_vma(vma);
92555 struct address_space *mapping;
92556
92557 +#ifdef CONFIG_PAX_SEGMEXEC
92558 + struct vm_area_struct *vma_m;
92559 +#endif
92560 +
92561 address &= huge_page_mask(h);
92562
92563 ptep = huge_pte_offset(mm, address);
92564 @@ -3009,6 +3047,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
92565 VM_FAULT_SET_HINDEX(hstate_index(h));
92566 }
92567
92568 +#ifdef CONFIG_PAX_SEGMEXEC
92569 + vma_m = pax_find_mirror_vma(vma);
92570 + if (vma_m) {
92571 + unsigned long address_m;
92572 +
92573 + if (vma->vm_start > vma_m->vm_start) {
92574 + address_m = address;
92575 + address -= SEGMEXEC_TASK_SIZE;
92576 + vma = vma_m;
92577 + h = hstate_vma(vma);
92578 + } else
92579 + address_m = address + SEGMEXEC_TASK_SIZE;
92580 +
92581 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
92582 + return VM_FAULT_OOM;
92583 + address_m &= HPAGE_MASK;
92584 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
92585 + }
92586 +#endif
92587 +
92588 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
92589 if (!ptep)
92590 return VM_FAULT_OOM;
92591 diff --git a/mm/internal.h b/mm/internal.h
92592 index 07b6736..ae8da20 100644
92593 --- a/mm/internal.h
92594 +++ b/mm/internal.h
92595 @@ -109,6 +109,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
92596 * in mm/page_alloc.c
92597 */
92598 extern void __free_pages_bootmem(struct page *page, unsigned int order);
92599 +extern void free_compound_page(struct page *page);
92600 extern void prep_compound_page(struct page *page, unsigned long order);
92601 #ifdef CONFIG_MEMORY_FAILURE
92602 extern bool is_free_buddy_page(struct page *page);
92603 @@ -367,7 +368,7 @@ extern u32 hwpoison_filter_enable;
92604
92605 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
92606 unsigned long, unsigned long,
92607 - unsigned long, unsigned long);
92608 + unsigned long, unsigned long) __intentional_overflow(-1);
92609
92610 extern void set_pageblock_order(void);
92611 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
92612 diff --git a/mm/iov_iter.c b/mm/iov_iter.c
92613 index 10e46cd..e3052f6 100644
92614 --- a/mm/iov_iter.c
92615 +++ b/mm/iov_iter.c
92616 @@ -87,7 +87,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
92617
92618 while (bytes) {
92619 char __user *buf = iov->iov_base + base;
92620 - int copy = min(bytes, iov->iov_len - base);
92621 + size_t copy = min(bytes, iov->iov_len - base);
92622
92623 base = 0;
92624 left = __copy_from_user_inatomic(vaddr, buf, copy);
92625 @@ -115,7 +115,7 @@ size_t iov_iter_copy_from_user_atomic(struct page *page,
92626
92627 kaddr = kmap_atomic(page);
92628 if (likely(i->nr_segs == 1)) {
92629 - int left;
92630 + size_t left;
92631 char __user *buf = i->iov->iov_base + i->iov_offset;
92632 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
92633 copied = bytes - left;
92634 @@ -143,7 +143,7 @@ size_t iov_iter_copy_from_user(struct page *page,
92635
92636 kaddr = kmap(page);
92637 if (likely(i->nr_segs == 1)) {
92638 - int left;
92639 + size_t left;
92640 char __user *buf = i->iov->iov_base + i->iov_offset;
92641 left = __copy_from_user(kaddr + offset, buf, bytes);
92642 copied = bytes - left;
92643 @@ -173,7 +173,7 @@ void iov_iter_advance(struct iov_iter *i, size_t bytes)
92644 * zero-length segments (without overruning the iovec).
92645 */
92646 while (bytes || unlikely(i->count && !iov->iov_len)) {
92647 - int copy;
92648 + size_t copy;
92649
92650 copy = min(bytes, iov->iov_len - base);
92651 BUG_ON(!i->count || i->count < copy);
92652 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
92653 index 8d2fcdf..6dd9f1a 100644
92654 --- a/mm/kmemleak.c
92655 +++ b/mm/kmemleak.c
92656 @@ -364,7 +364,7 @@ static void print_unreferenced(struct seq_file *seq,
92657
92658 for (i = 0; i < object->trace_len; i++) {
92659 void *ptr = (void *)object->trace[i];
92660 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
92661 + seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
92662 }
92663 }
92664
92665 @@ -1871,7 +1871,7 @@ static int __init kmemleak_late_init(void)
92666 return -ENOMEM;
92667 }
92668
92669 - dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
92670 + dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
92671 &kmemleak_fops);
92672 if (!dentry)
92673 pr_warning("Failed to create the debugfs kmemleak file\n");
92674 diff --git a/mm/maccess.c b/mm/maccess.c
92675 index d53adf9..03a24bf 100644
92676 --- a/mm/maccess.c
92677 +++ b/mm/maccess.c
92678 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
92679 set_fs(KERNEL_DS);
92680 pagefault_disable();
92681 ret = __copy_from_user_inatomic(dst,
92682 - (__force const void __user *)src, size);
92683 + (const void __force_user *)src, size);
92684 pagefault_enable();
92685 set_fs(old_fs);
92686
92687 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
92688
92689 set_fs(KERNEL_DS);
92690 pagefault_disable();
92691 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
92692 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
92693 pagefault_enable();
92694 set_fs(old_fs);
92695
92696 diff --git a/mm/madvise.c b/mm/madvise.c
92697 index a402f8f..f5e5daa 100644
92698 --- a/mm/madvise.c
92699 +++ b/mm/madvise.c
92700 @@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
92701 pgoff_t pgoff;
92702 unsigned long new_flags = vma->vm_flags;
92703
92704 +#ifdef CONFIG_PAX_SEGMEXEC
92705 + struct vm_area_struct *vma_m;
92706 +#endif
92707 +
92708 switch (behavior) {
92709 case MADV_NORMAL:
92710 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
92711 @@ -126,6 +130,13 @@ success:
92712 /*
92713 * vm_flags is protected by the mmap_sem held in write mode.
92714 */
92715 +
92716 +#ifdef CONFIG_PAX_SEGMEXEC
92717 + vma_m = pax_find_mirror_vma(vma);
92718 + if (vma_m)
92719 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
92720 +#endif
92721 +
92722 vma->vm_flags = new_flags;
92723
92724 out:
92725 @@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
92726 struct vm_area_struct **prev,
92727 unsigned long start, unsigned long end)
92728 {
92729 +
92730 +#ifdef CONFIG_PAX_SEGMEXEC
92731 + struct vm_area_struct *vma_m;
92732 +#endif
92733 +
92734 *prev = vma;
92735 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
92736 return -EINVAL;
92737 @@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
92738 zap_page_range(vma, start, end - start, &details);
92739 } else
92740 zap_page_range(vma, start, end - start, NULL);
92741 +
92742 +#ifdef CONFIG_PAX_SEGMEXEC
92743 + vma_m = pax_find_mirror_vma(vma);
92744 + if (vma_m) {
92745 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
92746 + struct zap_details details = {
92747 + .nonlinear_vma = vma_m,
92748 + .last_index = ULONG_MAX,
92749 + };
92750 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
92751 + } else
92752 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
92753 + }
92754 +#endif
92755 +
92756 return 0;
92757 }
92758
92759 @@ -491,6 +522,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
92760 if (end < start)
92761 return error;
92762
92763 +#ifdef CONFIG_PAX_SEGMEXEC
92764 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
92765 + if (end > SEGMEXEC_TASK_SIZE)
92766 + return error;
92767 + } else
92768 +#endif
92769 +
92770 + if (end > TASK_SIZE)
92771 + return error;
92772 +
92773 error = 0;
92774 if (end == start)
92775 return error;
92776 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
92777 index eb8fb72..ae36cf3 100644
92778 --- a/mm/memory-failure.c
92779 +++ b/mm/memory-failure.c
92780 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
92781
92782 int sysctl_memory_failure_recovery __read_mostly = 1;
92783
92784 -atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
92785 +atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
92786
92787 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
92788
92789 @@ -198,7 +198,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
92790 pfn, t->comm, t->pid);
92791 si.si_signo = SIGBUS;
92792 si.si_errno = 0;
92793 - si.si_addr = (void *)addr;
92794 + si.si_addr = (void __user *)addr;
92795 #ifdef __ARCH_SI_TRAPNO
92796 si.si_trapno = trapno;
92797 #endif
92798 @@ -791,7 +791,7 @@ static struct page_state {
92799 unsigned long res;
92800 char *msg;
92801 int (*action)(struct page *p, unsigned long pfn);
92802 -} error_states[] = {
92803 +} __do_const error_states[] = {
92804 { reserved, reserved, "reserved kernel", me_kernel },
92805 /*
92806 * free pages are specially detected outside this table:
92807 @@ -1091,7 +1091,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
92808 nr_pages = 1 << compound_order(hpage);
92809 else /* normal page or thp */
92810 nr_pages = 1;
92811 - atomic_long_add(nr_pages, &num_poisoned_pages);
92812 + atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
92813
92814 /*
92815 * We need/can do nothing about count=0 pages.
92816 @@ -1120,7 +1120,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
92817 if (PageHWPoison(hpage)) {
92818 if ((hwpoison_filter(p) && TestClearPageHWPoison(p))
92819 || (p != hpage && TestSetPageHWPoison(hpage))) {
92820 - atomic_long_sub(nr_pages, &num_poisoned_pages);
92821 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
92822 unlock_page(hpage);
92823 return 0;
92824 }
92825 @@ -1186,14 +1186,14 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
92826 */
92827 if (!PageHWPoison(p)) {
92828 printk(KERN_ERR "MCE %#lx: just unpoisoned\n", pfn);
92829 - atomic_long_sub(nr_pages, &num_poisoned_pages);
92830 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
92831 put_page(hpage);
92832 res = 0;
92833 goto out;
92834 }
92835 if (hwpoison_filter(p)) {
92836 if (TestClearPageHWPoison(p))
92837 - atomic_long_sub(nr_pages, &num_poisoned_pages);
92838 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
92839 unlock_page(hpage);
92840 put_page(hpage);
92841 return 0;
92842 @@ -1415,7 +1415,7 @@ int unpoison_memory(unsigned long pfn)
92843 return 0;
92844 }
92845 if (TestClearPageHWPoison(p))
92846 - atomic_long_dec(&num_poisoned_pages);
92847 + atomic_long_dec_unchecked(&num_poisoned_pages);
92848 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
92849 return 0;
92850 }
92851 @@ -1429,7 +1429,7 @@ int unpoison_memory(unsigned long pfn)
92852 */
92853 if (TestClearPageHWPoison(page)) {
92854 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
92855 - atomic_long_sub(nr_pages, &num_poisoned_pages);
92856 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
92857 freeit = 1;
92858 if (PageHuge(page))
92859 clear_page_hwpoison_huge_page(page);
92860 @@ -1554,11 +1554,11 @@ static int soft_offline_huge_page(struct page *page, int flags)
92861 if (PageHuge(page)) {
92862 set_page_hwpoison_huge_page(hpage);
92863 dequeue_hwpoisoned_huge_page(hpage);
92864 - atomic_long_add(1 << compound_order(hpage),
92865 + atomic_long_add_unchecked(1 << compound_order(hpage),
92866 &num_poisoned_pages);
92867 } else {
92868 SetPageHWPoison(page);
92869 - atomic_long_inc(&num_poisoned_pages);
92870 + atomic_long_inc_unchecked(&num_poisoned_pages);
92871 }
92872 }
92873 return ret;
92874 @@ -1597,7 +1597,7 @@ static int __soft_offline_page(struct page *page, int flags)
92875 put_page(page);
92876 pr_info("soft_offline: %#lx: invalidated\n", pfn);
92877 SetPageHWPoison(page);
92878 - atomic_long_inc(&num_poisoned_pages);
92879 + atomic_long_inc_unchecked(&num_poisoned_pages);
92880 return 0;
92881 }
92882
92883 @@ -1648,7 +1648,7 @@ static int __soft_offline_page(struct page *page, int flags)
92884 if (!is_free_buddy_page(page))
92885 pr_info("soft offline: %#lx: page leaked\n",
92886 pfn);
92887 - atomic_long_inc(&num_poisoned_pages);
92888 + atomic_long_inc_unchecked(&num_poisoned_pages);
92889 }
92890 } else {
92891 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
92892 @@ -1722,11 +1722,11 @@ int soft_offline_page(struct page *page, int flags)
92893 if (PageHuge(page)) {
92894 set_page_hwpoison_huge_page(hpage);
92895 dequeue_hwpoisoned_huge_page(hpage);
92896 - atomic_long_add(1 << compound_order(hpage),
92897 + atomic_long_add_unchecked(1 << compound_order(hpage),
92898 &num_poisoned_pages);
92899 } else {
92900 SetPageHWPoison(page);
92901 - atomic_long_inc(&num_poisoned_pages);
92902 + atomic_long_inc_unchecked(&num_poisoned_pages);
92903 }
92904 }
92905 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
92906 diff --git a/mm/memory.c b/mm/memory.c
92907 index e302ae1..c0ef712 100644
92908 --- a/mm/memory.c
92909 +++ b/mm/memory.c
92910 @@ -413,6 +413,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
92911 free_pte_range(tlb, pmd, addr);
92912 } while (pmd++, addr = next, addr != end);
92913
92914 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
92915 start &= PUD_MASK;
92916 if (start < floor)
92917 return;
92918 @@ -427,6 +428,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
92919 pmd = pmd_offset(pud, start);
92920 pud_clear(pud);
92921 pmd_free_tlb(tlb, pmd, start);
92922 +#endif
92923 +
92924 }
92925
92926 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
92927 @@ -446,6 +449,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
92928 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
92929 } while (pud++, addr = next, addr != end);
92930
92931 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
92932 start &= PGDIR_MASK;
92933 if (start < floor)
92934 return;
92935 @@ -460,6 +464,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
92936 pud = pud_offset(pgd, start);
92937 pgd_clear(pgd);
92938 pud_free_tlb(tlb, pud, start);
92939 +#endif
92940 +
92941 }
92942
92943 /*
92944 @@ -1652,12 +1658,6 @@ no_page_table:
92945 return page;
92946 }
92947
92948 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
92949 -{
92950 - return stack_guard_page_start(vma, addr) ||
92951 - stack_guard_page_end(vma, addr+PAGE_SIZE);
92952 -}
92953 -
92954 /**
92955 * __get_user_pages() - pin user pages in memory
92956 * @tsk: task_struct of target task
92957 @@ -1735,10 +1735,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
92958
92959 i = 0;
92960
92961 - do {
92962 + while (nr_pages) {
92963 struct vm_area_struct *vma;
92964
92965 - vma = find_extend_vma(mm, start);
92966 + vma = find_vma(mm, start);
92967 if (!vma && in_gate_area(mm, start)) {
92968 unsigned long pg = start & PAGE_MASK;
92969 pgd_t *pgd;
92970 @@ -1787,7 +1787,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
92971 goto next_page;
92972 }
92973
92974 - if (!vma)
92975 + if (!vma || start < vma->vm_start)
92976 goto efault;
92977 vm_flags = vma->vm_flags;
92978 if (vm_flags & (VM_IO | VM_PFNMAP))
92979 @@ -1848,11 +1848,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
92980 int ret;
92981 unsigned int fault_flags = 0;
92982
92983 - /* For mlock, just skip the stack guard page. */
92984 - if (foll_flags & FOLL_MLOCK) {
92985 - if (stack_guard_page(vma, start))
92986 - goto next_page;
92987 - }
92988 if (foll_flags & FOLL_WRITE)
92989 fault_flags |= FAULT_FLAG_WRITE;
92990 if (nonblocking)
92991 @@ -1932,7 +1927,7 @@ next_page:
92992 start += page_increm * PAGE_SIZE;
92993 nr_pages -= page_increm;
92994 } while (nr_pages && start < vma->vm_end);
92995 - } while (nr_pages);
92996 + }
92997 return i;
92998 efault:
92999 return i ? : -EFAULT;
93000 @@ -2145,6 +2140,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
93001 page_add_file_rmap(page);
93002 set_pte_at(mm, addr, pte, mk_pte(page, prot));
93003
93004 +#ifdef CONFIG_PAX_SEGMEXEC
93005 + pax_mirror_file_pte(vma, addr, page, ptl);
93006 +#endif
93007 +
93008 retval = 0;
93009 pte_unmap_unlock(pte, ptl);
93010 return retval;
93011 @@ -2189,9 +2188,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
93012 if (!page_count(page))
93013 return -EINVAL;
93014 if (!(vma->vm_flags & VM_MIXEDMAP)) {
93015 +
93016 +#ifdef CONFIG_PAX_SEGMEXEC
93017 + struct vm_area_struct *vma_m;
93018 +#endif
93019 +
93020 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
93021 BUG_ON(vma->vm_flags & VM_PFNMAP);
93022 vma->vm_flags |= VM_MIXEDMAP;
93023 +
93024 +#ifdef CONFIG_PAX_SEGMEXEC
93025 + vma_m = pax_find_mirror_vma(vma);
93026 + if (vma_m)
93027 + vma_m->vm_flags |= VM_MIXEDMAP;
93028 +#endif
93029 +
93030 }
93031 return insert_page(vma, addr, page, vma->vm_page_prot);
93032 }
93033 @@ -2274,6 +2285,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
93034 unsigned long pfn)
93035 {
93036 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
93037 + BUG_ON(vma->vm_mirror);
93038
93039 if (addr < vma->vm_start || addr >= vma->vm_end)
93040 return -EFAULT;
93041 @@ -2521,7 +2533,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
93042
93043 BUG_ON(pud_huge(*pud));
93044
93045 - pmd = pmd_alloc(mm, pud, addr);
93046 + pmd = (mm == &init_mm) ?
93047 + pmd_alloc_kernel(mm, pud, addr) :
93048 + pmd_alloc(mm, pud, addr);
93049 if (!pmd)
93050 return -ENOMEM;
93051 do {
93052 @@ -2541,7 +2555,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
93053 unsigned long next;
93054 int err;
93055
93056 - pud = pud_alloc(mm, pgd, addr);
93057 + pud = (mm == &init_mm) ?
93058 + pud_alloc_kernel(mm, pgd, addr) :
93059 + pud_alloc(mm, pgd, addr);
93060 if (!pud)
93061 return -ENOMEM;
93062 do {
93063 @@ -2663,6 +2679,186 @@ static int do_page_mkwrite(struct vm_area_struct *vma, struct page *page,
93064 return ret;
93065 }
93066
93067 +#ifdef CONFIG_PAX_SEGMEXEC
93068 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
93069 +{
93070 + struct mm_struct *mm = vma->vm_mm;
93071 + spinlock_t *ptl;
93072 + pte_t *pte, entry;
93073 +
93074 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
93075 + entry = *pte;
93076 + if (!pte_present(entry)) {
93077 + if (!pte_none(entry)) {
93078 + BUG_ON(pte_file(entry));
93079 + free_swap_and_cache(pte_to_swp_entry(entry));
93080 + pte_clear_not_present_full(mm, address, pte, 0);
93081 + }
93082 + } else {
93083 + struct page *page;
93084 +
93085 + flush_cache_page(vma, address, pte_pfn(entry));
93086 + entry = ptep_clear_flush(vma, address, pte);
93087 + BUG_ON(pte_dirty(entry));
93088 + page = vm_normal_page(vma, address, entry);
93089 + if (page) {
93090 + update_hiwater_rss(mm);
93091 + if (PageAnon(page))
93092 + dec_mm_counter_fast(mm, MM_ANONPAGES);
93093 + else
93094 + dec_mm_counter_fast(mm, MM_FILEPAGES);
93095 + page_remove_rmap(page);
93096 + page_cache_release(page);
93097 + }
93098 + }
93099 + pte_unmap_unlock(pte, ptl);
93100 +}
93101 +
93102 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
93103 + *
93104 + * the ptl of the lower mapped page is held on entry and is not released on exit
93105 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
93106 + */
93107 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
93108 +{
93109 + struct mm_struct *mm = vma->vm_mm;
93110 + unsigned long address_m;
93111 + spinlock_t *ptl_m;
93112 + struct vm_area_struct *vma_m;
93113 + pmd_t *pmd_m;
93114 + pte_t *pte_m, entry_m;
93115 +
93116 + BUG_ON(!page_m || !PageAnon(page_m));
93117 +
93118 + vma_m = pax_find_mirror_vma(vma);
93119 + if (!vma_m)
93120 + return;
93121 +
93122 + BUG_ON(!PageLocked(page_m));
93123 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
93124 + address_m = address + SEGMEXEC_TASK_SIZE;
93125 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
93126 + pte_m = pte_offset_map(pmd_m, address_m);
93127 + ptl_m = pte_lockptr(mm, pmd_m);
93128 + if (ptl != ptl_m) {
93129 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
93130 + if (!pte_none(*pte_m))
93131 + goto out;
93132 + }
93133 +
93134 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
93135 + page_cache_get(page_m);
93136 + page_add_anon_rmap(page_m, vma_m, address_m);
93137 + inc_mm_counter_fast(mm, MM_ANONPAGES);
93138 + set_pte_at(mm, address_m, pte_m, entry_m);
93139 + update_mmu_cache(vma_m, address_m, pte_m);
93140 +out:
93141 + if (ptl != ptl_m)
93142 + spin_unlock(ptl_m);
93143 + pte_unmap(pte_m);
93144 + unlock_page(page_m);
93145 +}
93146 +
93147 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
93148 +{
93149 + struct mm_struct *mm = vma->vm_mm;
93150 + unsigned long address_m;
93151 + spinlock_t *ptl_m;
93152 + struct vm_area_struct *vma_m;
93153 + pmd_t *pmd_m;
93154 + pte_t *pte_m, entry_m;
93155 +
93156 + BUG_ON(!page_m || PageAnon(page_m));
93157 +
93158 + vma_m = pax_find_mirror_vma(vma);
93159 + if (!vma_m)
93160 + return;
93161 +
93162 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
93163 + address_m = address + SEGMEXEC_TASK_SIZE;
93164 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
93165 + pte_m = pte_offset_map(pmd_m, address_m);
93166 + ptl_m = pte_lockptr(mm, pmd_m);
93167 + if (ptl != ptl_m) {
93168 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
93169 + if (!pte_none(*pte_m))
93170 + goto out;
93171 + }
93172 +
93173 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
93174 + page_cache_get(page_m);
93175 + page_add_file_rmap(page_m);
93176 + inc_mm_counter_fast(mm, MM_FILEPAGES);
93177 + set_pte_at(mm, address_m, pte_m, entry_m);
93178 + update_mmu_cache(vma_m, address_m, pte_m);
93179 +out:
93180 + if (ptl != ptl_m)
93181 + spin_unlock(ptl_m);
93182 + pte_unmap(pte_m);
93183 +}
93184 +
93185 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
93186 +{
93187 + struct mm_struct *mm = vma->vm_mm;
93188 + unsigned long address_m;
93189 + spinlock_t *ptl_m;
93190 + struct vm_area_struct *vma_m;
93191 + pmd_t *pmd_m;
93192 + pte_t *pte_m, entry_m;
93193 +
93194 + vma_m = pax_find_mirror_vma(vma);
93195 + if (!vma_m)
93196 + return;
93197 +
93198 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
93199 + address_m = address + SEGMEXEC_TASK_SIZE;
93200 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
93201 + pte_m = pte_offset_map(pmd_m, address_m);
93202 + ptl_m = pte_lockptr(mm, pmd_m);
93203 + if (ptl != ptl_m) {
93204 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
93205 + if (!pte_none(*pte_m))
93206 + goto out;
93207 + }
93208 +
93209 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
93210 + set_pte_at(mm, address_m, pte_m, entry_m);
93211 +out:
93212 + if (ptl != ptl_m)
93213 + spin_unlock(ptl_m);
93214 + pte_unmap(pte_m);
93215 +}
93216 +
93217 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
93218 +{
93219 + struct page *page_m;
93220 + pte_t entry;
93221 +
93222 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
93223 + goto out;
93224 +
93225 + entry = *pte;
93226 + page_m = vm_normal_page(vma, address, entry);
93227 + if (!page_m)
93228 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
93229 + else if (PageAnon(page_m)) {
93230 + if (pax_find_mirror_vma(vma)) {
93231 + pte_unmap_unlock(pte, ptl);
93232 + lock_page(page_m);
93233 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
93234 + if (pte_same(entry, *pte))
93235 + pax_mirror_anon_pte(vma, address, page_m, ptl);
93236 + else
93237 + unlock_page(page_m);
93238 + }
93239 + } else
93240 + pax_mirror_file_pte(vma, address, page_m, ptl);
93241 +
93242 +out:
93243 + pte_unmap_unlock(pte, ptl);
93244 +}
93245 +#endif
93246 +
93247 /*
93248 * This routine handles present pages, when users try to write
93249 * to a shared page. It is done by copying the page to a new address
93250 @@ -2860,6 +3056,12 @@ gotten:
93251 */
93252 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
93253 if (likely(pte_same(*page_table, orig_pte))) {
93254 +
93255 +#ifdef CONFIG_PAX_SEGMEXEC
93256 + if (pax_find_mirror_vma(vma))
93257 + BUG_ON(!trylock_page(new_page));
93258 +#endif
93259 +
93260 if (old_page) {
93261 if (!PageAnon(old_page)) {
93262 dec_mm_counter_fast(mm, MM_FILEPAGES);
93263 @@ -2911,6 +3113,10 @@ gotten:
93264 page_remove_rmap(old_page);
93265 }
93266
93267 +#ifdef CONFIG_PAX_SEGMEXEC
93268 + pax_mirror_anon_pte(vma, address, new_page, ptl);
93269 +#endif
93270 +
93271 /* Free the old page.. */
93272 new_page = old_page;
93273 ret |= VM_FAULT_WRITE;
93274 @@ -3184,6 +3390,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
93275 swap_free(entry);
93276 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
93277 try_to_free_swap(page);
93278 +
93279 +#ifdef CONFIG_PAX_SEGMEXEC
93280 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
93281 +#endif
93282 +
93283 unlock_page(page);
93284 if (page != swapcache) {
93285 /*
93286 @@ -3207,6 +3418,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
93287
93288 /* No need to invalidate - it was non-present before */
93289 update_mmu_cache(vma, address, page_table);
93290 +
93291 +#ifdef CONFIG_PAX_SEGMEXEC
93292 + pax_mirror_anon_pte(vma, address, page, ptl);
93293 +#endif
93294 +
93295 unlock:
93296 pte_unmap_unlock(page_table, ptl);
93297 out:
93298 @@ -3226,40 +3442,6 @@ out_release:
93299 }
93300
93301 /*
93302 - * This is like a special single-page "expand_{down|up}wards()",
93303 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
93304 - * doesn't hit another vma.
93305 - */
93306 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
93307 -{
93308 - address &= PAGE_MASK;
93309 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
93310 - struct vm_area_struct *prev = vma->vm_prev;
93311 -
93312 - /*
93313 - * Is there a mapping abutting this one below?
93314 - *
93315 - * That's only ok if it's the same stack mapping
93316 - * that has gotten split..
93317 - */
93318 - if (prev && prev->vm_end == address)
93319 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
93320 -
93321 - expand_downwards(vma, address - PAGE_SIZE);
93322 - }
93323 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
93324 - struct vm_area_struct *next = vma->vm_next;
93325 -
93326 - /* As VM_GROWSDOWN but s/below/above/ */
93327 - if (next && next->vm_start == address + PAGE_SIZE)
93328 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
93329 -
93330 - expand_upwards(vma, address + PAGE_SIZE);
93331 - }
93332 - return 0;
93333 -}
93334 -
93335 -/*
93336 * We enter with non-exclusive mmap_sem (to exclude vma changes,
93337 * but allow concurrent faults), and pte mapped but not yet locked.
93338 * We return with mmap_sem still held, but pte unmapped and unlocked.
93339 @@ -3268,27 +3450,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
93340 unsigned long address, pte_t *page_table, pmd_t *pmd,
93341 unsigned int flags)
93342 {
93343 - struct page *page;
93344 + struct page *page = NULL;
93345 spinlock_t *ptl;
93346 pte_t entry;
93347
93348 - pte_unmap(page_table);
93349 -
93350 - /* Check if we need to add a guard page to the stack */
93351 - if (check_stack_guard_page(vma, address) < 0)
93352 - return VM_FAULT_SIGBUS;
93353 -
93354 - /* Use the zero-page for reads */
93355 if (!(flags & FAULT_FLAG_WRITE)) {
93356 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
93357 vma->vm_page_prot));
93358 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
93359 + ptl = pte_lockptr(mm, pmd);
93360 + spin_lock(ptl);
93361 if (!pte_none(*page_table))
93362 goto unlock;
93363 goto setpte;
93364 }
93365
93366 /* Allocate our own private page. */
93367 + pte_unmap(page_table);
93368 +
93369 if (unlikely(anon_vma_prepare(vma)))
93370 goto oom;
93371 page = alloc_zeroed_user_highpage_movable(vma, address);
93372 @@ -3312,6 +3490,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
93373 if (!pte_none(*page_table))
93374 goto release;
93375
93376 +#ifdef CONFIG_PAX_SEGMEXEC
93377 + if (pax_find_mirror_vma(vma))
93378 + BUG_ON(!trylock_page(page));
93379 +#endif
93380 +
93381 inc_mm_counter_fast(mm, MM_ANONPAGES);
93382 page_add_new_anon_rmap(page, vma, address);
93383 setpte:
93384 @@ -3319,6 +3502,12 @@ setpte:
93385
93386 /* No need to invalidate - it was non-present before */
93387 update_mmu_cache(vma, address, page_table);
93388 +
93389 +#ifdef CONFIG_PAX_SEGMEXEC
93390 + if (page)
93391 + pax_mirror_anon_pte(vma, address, page, ptl);
93392 +#endif
93393 +
93394 unlock:
93395 pte_unmap_unlock(page_table, ptl);
93396 return 0;
93397 @@ -3535,6 +3724,11 @@ static int do_read_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93398 return ret;
93399 }
93400 do_set_pte(vma, address, fault_page, pte, false, false);
93401 +
93402 +#ifdef CONFIG_PAX_SEGMEXEC
93403 + pax_mirror_file_pte(vma, address, fault_page, ptl);
93404 +#endif
93405 +
93406 unlock_page(fault_page);
93407 unlock_out:
93408 pte_unmap_unlock(pte, ptl);
93409 @@ -3576,7 +3770,18 @@ static int do_cow_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93410 page_cache_release(fault_page);
93411 goto uncharge_out;
93412 }
93413 +
93414 +#ifdef CONFIG_PAX_SEGMEXEC
93415 + if (pax_find_mirror_vma(vma))
93416 + BUG_ON(!trylock_page(new_page));
93417 +#endif
93418 +
93419 do_set_pte(vma, address, new_page, pte, true, true);
93420 +
93421 +#ifdef CONFIG_PAX_SEGMEXEC
93422 + pax_mirror_anon_pte(vma, address, new_page, ptl);
93423 +#endif
93424 +
93425 pte_unmap_unlock(pte, ptl);
93426 unlock_page(fault_page);
93427 page_cache_release(fault_page);
93428 @@ -3624,6 +3829,11 @@ static int do_shared_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93429 return ret;
93430 }
93431 do_set_pte(vma, address, fault_page, pte, true, false);
93432 +
93433 +#ifdef CONFIG_PAX_SEGMEXEC
93434 + pax_mirror_file_pte(vma, address, fault_page, ptl);
93435 +#endif
93436 +
93437 pte_unmap_unlock(pte, ptl);
93438
93439 if (set_page_dirty(fault_page))
93440 @@ -3854,6 +4064,12 @@ static int handle_pte_fault(struct mm_struct *mm,
93441 if (flags & FAULT_FLAG_WRITE)
93442 flush_tlb_fix_spurious_fault(vma, address);
93443 }
93444 +
93445 +#ifdef CONFIG_PAX_SEGMEXEC
93446 + pax_mirror_pte(vma, address, pte, pmd, ptl);
93447 + return 0;
93448 +#endif
93449 +
93450 unlock:
93451 pte_unmap_unlock(pte, ptl);
93452 return 0;
93453 @@ -3870,9 +4086,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
93454 pmd_t *pmd;
93455 pte_t *pte;
93456
93457 +#ifdef CONFIG_PAX_SEGMEXEC
93458 + struct vm_area_struct *vma_m;
93459 +#endif
93460 +
93461 if (unlikely(is_vm_hugetlb_page(vma)))
93462 return hugetlb_fault(mm, vma, address, flags);
93463
93464 +#ifdef CONFIG_PAX_SEGMEXEC
93465 + vma_m = pax_find_mirror_vma(vma);
93466 + if (vma_m) {
93467 + unsigned long address_m;
93468 + pgd_t *pgd_m;
93469 + pud_t *pud_m;
93470 + pmd_t *pmd_m;
93471 +
93472 + if (vma->vm_start > vma_m->vm_start) {
93473 + address_m = address;
93474 + address -= SEGMEXEC_TASK_SIZE;
93475 + vma = vma_m;
93476 + } else
93477 + address_m = address + SEGMEXEC_TASK_SIZE;
93478 +
93479 + pgd_m = pgd_offset(mm, address_m);
93480 + pud_m = pud_alloc(mm, pgd_m, address_m);
93481 + if (!pud_m)
93482 + return VM_FAULT_OOM;
93483 + pmd_m = pmd_alloc(mm, pud_m, address_m);
93484 + if (!pmd_m)
93485 + return VM_FAULT_OOM;
93486 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
93487 + return VM_FAULT_OOM;
93488 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
93489 + }
93490 +#endif
93491 +
93492 pgd = pgd_offset(mm, address);
93493 pud = pud_alloc(mm, pgd, address);
93494 if (!pud)
93495 @@ -4000,6 +4248,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
93496 spin_unlock(&mm->page_table_lock);
93497 return 0;
93498 }
93499 +
93500 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
93501 +{
93502 + pud_t *new = pud_alloc_one(mm, address);
93503 + if (!new)
93504 + return -ENOMEM;
93505 +
93506 + smp_wmb(); /* See comment in __pte_alloc */
93507 +
93508 + spin_lock(&mm->page_table_lock);
93509 + if (pgd_present(*pgd)) /* Another has populated it */
93510 + pud_free(mm, new);
93511 + else
93512 + pgd_populate_kernel(mm, pgd, new);
93513 + spin_unlock(&mm->page_table_lock);
93514 + return 0;
93515 +}
93516 #endif /* __PAGETABLE_PUD_FOLDED */
93517
93518 #ifndef __PAGETABLE_PMD_FOLDED
93519 @@ -4030,6 +4295,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
93520 spin_unlock(&mm->page_table_lock);
93521 return 0;
93522 }
93523 +
93524 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
93525 +{
93526 + pmd_t *new = pmd_alloc_one(mm, address);
93527 + if (!new)
93528 + return -ENOMEM;
93529 +
93530 + smp_wmb(); /* See comment in __pte_alloc */
93531 +
93532 + spin_lock(&mm->page_table_lock);
93533 +#ifndef __ARCH_HAS_4LEVEL_HACK
93534 + if (pud_present(*pud)) /* Another has populated it */
93535 + pmd_free(mm, new);
93536 + else
93537 + pud_populate_kernel(mm, pud, new);
93538 +#else
93539 + if (pgd_present(*pud)) /* Another has populated it */
93540 + pmd_free(mm, new);
93541 + else
93542 + pgd_populate_kernel(mm, pud, new);
93543 +#endif /* __ARCH_HAS_4LEVEL_HACK */
93544 + spin_unlock(&mm->page_table_lock);
93545 + return 0;
93546 +}
93547 #endif /* __PAGETABLE_PMD_FOLDED */
93548
93549 #if !defined(__HAVE_ARCH_GATE_AREA)
93550 @@ -4043,7 +4332,7 @@ static int __init gate_vma_init(void)
93551 gate_vma.vm_start = FIXADDR_USER_START;
93552 gate_vma.vm_end = FIXADDR_USER_END;
93553 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
93554 - gate_vma.vm_page_prot = __P101;
93555 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
93556
93557 return 0;
93558 }
93559 @@ -4177,8 +4466,8 @@ out:
93560 return ret;
93561 }
93562
93563 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
93564 - void *buf, int len, int write)
93565 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
93566 + void *buf, size_t len, int write)
93567 {
93568 resource_size_t phys_addr;
93569 unsigned long prot = 0;
93570 @@ -4204,8 +4493,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
93571 * Access another process' address space as given in mm. If non-NULL, use the
93572 * given task for page fault accounting.
93573 */
93574 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93575 - unsigned long addr, void *buf, int len, int write)
93576 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93577 + unsigned long addr, void *buf, size_t len, int write)
93578 {
93579 struct vm_area_struct *vma;
93580 void *old_buf = buf;
93581 @@ -4213,7 +4502,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93582 down_read(&mm->mmap_sem);
93583 /* ignore errors, just check how much was successfully transferred */
93584 while (len) {
93585 - int bytes, ret, offset;
93586 + ssize_t bytes, ret, offset;
93587 void *maddr;
93588 struct page *page = NULL;
93589
93590 @@ -4272,8 +4561,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93591 *
93592 * The caller must hold a reference on @mm.
93593 */
93594 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
93595 - void *buf, int len, int write)
93596 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
93597 + void *buf, size_t len, int write)
93598 {
93599 return __access_remote_vm(NULL, mm, addr, buf, len, write);
93600 }
93601 @@ -4283,11 +4572,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
93602 * Source/target buffer must be kernel space,
93603 * Do not walk the page table directly, use get_user_pages
93604 */
93605 -int access_process_vm(struct task_struct *tsk, unsigned long addr,
93606 - void *buf, int len, int write)
93607 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
93608 + void *buf, size_t len, int write)
93609 {
93610 struct mm_struct *mm;
93611 - int ret;
93612 + ssize_t ret;
93613
93614 mm = get_task_mm(tsk);
93615 if (!mm)
93616 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
93617 index 35f9f91..bed4575 100644
93618 --- a/mm/mempolicy.c
93619 +++ b/mm/mempolicy.c
93620 @@ -747,6 +747,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
93621 unsigned long vmstart;
93622 unsigned long vmend;
93623
93624 +#ifdef CONFIG_PAX_SEGMEXEC
93625 + struct vm_area_struct *vma_m;
93626 +#endif
93627 +
93628 vma = find_vma(mm, start);
93629 if (!vma || vma->vm_start > start)
93630 return -EFAULT;
93631 @@ -790,6 +794,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
93632 err = vma_replace_policy(vma, new_pol);
93633 if (err)
93634 goto out;
93635 +
93636 +#ifdef CONFIG_PAX_SEGMEXEC
93637 + vma_m = pax_find_mirror_vma(vma);
93638 + if (vma_m) {
93639 + err = vma_replace_policy(vma_m, new_pol);
93640 + if (err)
93641 + goto out;
93642 + }
93643 +#endif
93644 +
93645 }
93646
93647 out:
93648 @@ -1222,6 +1236,17 @@ static long do_mbind(unsigned long start, unsigned long len,
93649
93650 if (end < start)
93651 return -EINVAL;
93652 +
93653 +#ifdef CONFIG_PAX_SEGMEXEC
93654 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
93655 + if (end > SEGMEXEC_TASK_SIZE)
93656 + return -EINVAL;
93657 + } else
93658 +#endif
93659 +
93660 + if (end > TASK_SIZE)
93661 + return -EINVAL;
93662 +
93663 if (end == start)
93664 return 0;
93665
93666 @@ -1447,8 +1472,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
93667 */
93668 tcred = __task_cred(task);
93669 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
93670 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
93671 - !capable(CAP_SYS_NICE)) {
93672 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
93673 rcu_read_unlock();
93674 err = -EPERM;
93675 goto out_put;
93676 @@ -1479,6 +1503,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
93677 goto out;
93678 }
93679
93680 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
93681 + if (mm != current->mm &&
93682 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
93683 + mmput(mm);
93684 + err = -EPERM;
93685 + goto out;
93686 + }
93687 +#endif
93688 +
93689 err = do_migrate_pages(mm, old, new,
93690 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
93691
93692 diff --git a/mm/migrate.c b/mm/migrate.c
93693 index bed4880..a493f67 100644
93694 --- a/mm/migrate.c
93695 +++ b/mm/migrate.c
93696 @@ -1485,8 +1485,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
93697 */
93698 tcred = __task_cred(task);
93699 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
93700 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
93701 - !capable(CAP_SYS_NICE)) {
93702 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
93703 rcu_read_unlock();
93704 err = -EPERM;
93705 goto out;
93706 diff --git a/mm/mlock.c b/mm/mlock.c
93707 index b1eb536..091d154 100644
93708 --- a/mm/mlock.c
93709 +++ b/mm/mlock.c
93710 @@ -14,6 +14,7 @@
93711 #include <linux/pagevec.h>
93712 #include <linux/mempolicy.h>
93713 #include <linux/syscalls.h>
93714 +#include <linux/security.h>
93715 #include <linux/sched.h>
93716 #include <linux/export.h>
93717 #include <linux/rmap.h>
93718 @@ -606,7 +607,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
93719 {
93720 unsigned long nstart, end, tmp;
93721 struct vm_area_struct * vma, * prev;
93722 - int error;
93723 + int error = 0;
93724
93725 VM_BUG_ON(start & ~PAGE_MASK);
93726 VM_BUG_ON(len != PAGE_ALIGN(len));
93727 @@ -615,6 +616,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
93728 return -EINVAL;
93729 if (end == start)
93730 return 0;
93731 + if (end > TASK_SIZE)
93732 + return -EINVAL;
93733 +
93734 vma = find_vma(current->mm, start);
93735 if (!vma || vma->vm_start > start)
93736 return -ENOMEM;
93737 @@ -626,6 +630,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
93738 for (nstart = start ; ; ) {
93739 vm_flags_t newflags;
93740
93741 +#ifdef CONFIG_PAX_SEGMEXEC
93742 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
93743 + break;
93744 +#endif
93745 +
93746 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
93747
93748 newflags = vma->vm_flags & ~VM_LOCKED;
93749 @@ -739,6 +748,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
93750 locked += current->mm->locked_vm;
93751
93752 /* check against resource limits */
93753 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
93754 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
93755 error = do_mlock(start, len, 1);
93756
93757 @@ -776,6 +786,11 @@ static int do_mlockall(int flags)
93758 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
93759 vm_flags_t newflags;
93760
93761 +#ifdef CONFIG_PAX_SEGMEXEC
93762 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
93763 + break;
93764 +#endif
93765 +
93766 newflags = vma->vm_flags & ~VM_LOCKED;
93767 if (flags & MCL_CURRENT)
93768 newflags |= VM_LOCKED;
93769 @@ -807,8 +822,10 @@ SYSCALL_DEFINE1(mlockall, int, flags)
93770 lock_limit >>= PAGE_SHIFT;
93771
93772 ret = -ENOMEM;
93773 +
93774 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
93775 +
93776 down_write(&current->mm->mmap_sem);
93777 -
93778 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
93779 capable(CAP_IPC_LOCK))
93780 ret = do_mlockall(flags);
93781 diff --git a/mm/mmap.c b/mm/mmap.c
93782 index b1202cf..ee487f8 100644
93783 --- a/mm/mmap.c
93784 +++ b/mm/mmap.c
93785 @@ -37,6 +37,7 @@
93786 #include <linux/sched/sysctl.h>
93787 #include <linux/notifier.h>
93788 #include <linux/memory.h>
93789 +#include <linux/random.h>
93790
93791 #include <asm/uaccess.h>
93792 #include <asm/cacheflush.h>
93793 @@ -53,6 +54,16 @@
93794 #define arch_rebalance_pgtables(addr, len) (addr)
93795 #endif
93796
93797 +static inline void verify_mm_writelocked(struct mm_struct *mm)
93798 +{
93799 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
93800 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
93801 + up_read(&mm->mmap_sem);
93802 + BUG();
93803 + }
93804 +#endif
93805 +}
93806 +
93807 static void unmap_region(struct mm_struct *mm,
93808 struct vm_area_struct *vma, struct vm_area_struct *prev,
93809 unsigned long start, unsigned long end);
93810 @@ -72,16 +83,25 @@ static void unmap_region(struct mm_struct *mm,
93811 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
93812 *
93813 */
93814 -pgprot_t protection_map[16] = {
93815 +pgprot_t protection_map[16] __read_only = {
93816 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
93817 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
93818 };
93819
93820 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
93821 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
93822 {
93823 - return __pgprot(pgprot_val(protection_map[vm_flags &
93824 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
93825 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
93826 pgprot_val(arch_vm_get_page_prot(vm_flags)));
93827 +
93828 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
93829 + if (!(__supported_pte_mask & _PAGE_NX) &&
93830 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
93831 + (vm_flags & (VM_READ | VM_WRITE)))
93832 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
93833 +#endif
93834 +
93835 + return prot;
93836 }
93837 EXPORT_SYMBOL(vm_get_page_prot);
93838
93839 @@ -91,6 +111,7 @@ unsigned long sysctl_overcommit_kbytes __read_mostly;
93840 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
93841 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
93842 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
93843 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
93844 /*
93845 * Make sure vm_committed_as in one cacheline and not cacheline shared with
93846 * other variables. It can be updated by several CPUs frequently.
93847 @@ -247,6 +268,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
93848 struct vm_area_struct *next = vma->vm_next;
93849
93850 might_sleep();
93851 + BUG_ON(vma->vm_mirror);
93852 if (vma->vm_ops && vma->vm_ops->close)
93853 vma->vm_ops->close(vma);
93854 if (vma->vm_file)
93855 @@ -291,6 +313,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
93856 * not page aligned -Ram Gupta
93857 */
93858 rlim = rlimit(RLIMIT_DATA);
93859 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
93860 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
93861 (mm->end_data - mm->start_data) > rlim)
93862 goto out;
93863 @@ -942,6 +965,12 @@ static int
93864 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
93865 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
93866 {
93867 +
93868 +#ifdef CONFIG_PAX_SEGMEXEC
93869 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
93870 + return 0;
93871 +#endif
93872 +
93873 if (is_mergeable_vma(vma, file, vm_flags) &&
93874 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
93875 if (vma->vm_pgoff == vm_pgoff)
93876 @@ -961,6 +990,12 @@ static int
93877 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
93878 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
93879 {
93880 +
93881 +#ifdef CONFIG_PAX_SEGMEXEC
93882 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
93883 + return 0;
93884 +#endif
93885 +
93886 if (is_mergeable_vma(vma, file, vm_flags) &&
93887 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
93888 pgoff_t vm_pglen;
93889 @@ -1003,13 +1038,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
93890 struct vm_area_struct *vma_merge(struct mm_struct *mm,
93891 struct vm_area_struct *prev, unsigned long addr,
93892 unsigned long end, unsigned long vm_flags,
93893 - struct anon_vma *anon_vma, struct file *file,
93894 + struct anon_vma *anon_vma, struct file *file,
93895 pgoff_t pgoff, struct mempolicy *policy)
93896 {
93897 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
93898 struct vm_area_struct *area, *next;
93899 int err;
93900
93901 +#ifdef CONFIG_PAX_SEGMEXEC
93902 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
93903 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
93904 +
93905 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
93906 +#endif
93907 +
93908 /*
93909 * We later require that vma->vm_flags == vm_flags,
93910 * so this tests vma->vm_flags & VM_SPECIAL, too.
93911 @@ -1025,6 +1067,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
93912 if (next && next->vm_end == end) /* cases 6, 7, 8 */
93913 next = next->vm_next;
93914
93915 +#ifdef CONFIG_PAX_SEGMEXEC
93916 + if (prev)
93917 + prev_m = pax_find_mirror_vma(prev);
93918 + if (area)
93919 + area_m = pax_find_mirror_vma(area);
93920 + if (next)
93921 + next_m = pax_find_mirror_vma(next);
93922 +#endif
93923 +
93924 /*
93925 * Can it merge with the predecessor?
93926 */
93927 @@ -1044,9 +1095,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
93928 /* cases 1, 6 */
93929 err = vma_adjust(prev, prev->vm_start,
93930 next->vm_end, prev->vm_pgoff, NULL);
93931 - } else /* cases 2, 5, 7 */
93932 +
93933 +#ifdef CONFIG_PAX_SEGMEXEC
93934 + if (!err && prev_m)
93935 + err = vma_adjust(prev_m, prev_m->vm_start,
93936 + next_m->vm_end, prev_m->vm_pgoff, NULL);
93937 +#endif
93938 +
93939 + } else { /* cases 2, 5, 7 */
93940 err = vma_adjust(prev, prev->vm_start,
93941 end, prev->vm_pgoff, NULL);
93942 +
93943 +#ifdef CONFIG_PAX_SEGMEXEC
93944 + if (!err && prev_m)
93945 + err = vma_adjust(prev_m, prev_m->vm_start,
93946 + end_m, prev_m->vm_pgoff, NULL);
93947 +#endif
93948 +
93949 + }
93950 if (err)
93951 return NULL;
93952 khugepaged_enter_vma_merge(prev);
93953 @@ -1060,12 +1126,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
93954 mpol_equal(policy, vma_policy(next)) &&
93955 can_vma_merge_before(next, vm_flags,
93956 anon_vma, file, pgoff+pglen)) {
93957 - if (prev && addr < prev->vm_end) /* case 4 */
93958 + if (prev && addr < prev->vm_end) { /* case 4 */
93959 err = vma_adjust(prev, prev->vm_start,
93960 addr, prev->vm_pgoff, NULL);
93961 - else /* cases 3, 8 */
93962 +
93963 +#ifdef CONFIG_PAX_SEGMEXEC
93964 + if (!err && prev_m)
93965 + err = vma_adjust(prev_m, prev_m->vm_start,
93966 + addr_m, prev_m->vm_pgoff, NULL);
93967 +#endif
93968 +
93969 + } else { /* cases 3, 8 */
93970 err = vma_adjust(area, addr, next->vm_end,
93971 next->vm_pgoff - pglen, NULL);
93972 +
93973 +#ifdef CONFIG_PAX_SEGMEXEC
93974 + if (!err && area_m)
93975 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
93976 + next_m->vm_pgoff - pglen, NULL);
93977 +#endif
93978 +
93979 + }
93980 if (err)
93981 return NULL;
93982 khugepaged_enter_vma_merge(area);
93983 @@ -1174,8 +1255,10 @@ none:
93984 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
93985 struct file *file, long pages)
93986 {
93987 - const unsigned long stack_flags
93988 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
93989 +
93990 +#ifdef CONFIG_PAX_RANDMMAP
93991 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
93992 +#endif
93993
93994 mm->total_vm += pages;
93995
93996 @@ -1183,7 +1266,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
93997 mm->shared_vm += pages;
93998 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
93999 mm->exec_vm += pages;
94000 - } else if (flags & stack_flags)
94001 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
94002 mm->stack_vm += pages;
94003 }
94004 #endif /* CONFIG_PROC_FS */
94005 @@ -1213,6 +1296,7 @@ static inline int mlock_future_check(struct mm_struct *mm,
94006 locked += mm->locked_vm;
94007 lock_limit = rlimit(RLIMIT_MEMLOCK);
94008 lock_limit >>= PAGE_SHIFT;
94009 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
94010 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
94011 return -EAGAIN;
94012 }
94013 @@ -1239,7 +1323,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
94014 * (the exception is when the underlying filesystem is noexec
94015 * mounted, in which case we dont add PROT_EXEC.)
94016 */
94017 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
94018 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
94019 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
94020 prot |= PROT_EXEC;
94021
94022 @@ -1265,7 +1349,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
94023 /* Obtain the address to map to. we verify (or select) it and ensure
94024 * that it represents a valid section of the address space.
94025 */
94026 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
94027 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
94028 if (addr & ~PAGE_MASK)
94029 return addr;
94030
94031 @@ -1276,6 +1360,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
94032 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
94033 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
94034
94035 +#ifdef CONFIG_PAX_MPROTECT
94036 + if (mm->pax_flags & MF_PAX_MPROTECT) {
94037 +
94038 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
94039 + if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
94040 + mm->binfmt->handle_mmap)
94041 + mm->binfmt->handle_mmap(file);
94042 +#endif
94043 +
94044 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
94045 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
94046 + gr_log_rwxmmap(file);
94047 +
94048 +#ifdef CONFIG_PAX_EMUPLT
94049 + vm_flags &= ~VM_EXEC;
94050 +#else
94051 + return -EPERM;
94052 +#endif
94053 +
94054 + }
94055 +
94056 + if (!(vm_flags & VM_EXEC))
94057 + vm_flags &= ~VM_MAYEXEC;
94058 +#else
94059 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
94060 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
94061 +#endif
94062 + else
94063 + vm_flags &= ~VM_MAYWRITE;
94064 + }
94065 +#endif
94066 +
94067 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
94068 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
94069 + vm_flags &= ~VM_PAGEEXEC;
94070 +#endif
94071 +
94072 if (flags & MAP_LOCKED)
94073 if (!can_do_mlock())
94074 return -EPERM;
94075 @@ -1363,6 +1484,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
94076 vm_flags |= VM_NORESERVE;
94077 }
94078
94079 + if (!gr_acl_handle_mmap(file, prot))
94080 + return -EACCES;
94081 +
94082 addr = mmap_region(file, addr, len, vm_flags, pgoff);
94083 if (!IS_ERR_VALUE(addr) &&
94084 ((vm_flags & VM_LOCKED) ||
94085 @@ -1456,7 +1580,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
94086 vm_flags_t vm_flags = vma->vm_flags;
94087
94088 /* If it was private or non-writable, the write bit is already clear */
94089 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
94090 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
94091 return 0;
94092
94093 /* The backer wishes to know when pages are first written to? */
94094 @@ -1502,7 +1626,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
94095 struct rb_node **rb_link, *rb_parent;
94096 unsigned long charged = 0;
94097
94098 +#ifdef CONFIG_PAX_SEGMEXEC
94099 + struct vm_area_struct *vma_m = NULL;
94100 +#endif
94101 +
94102 + /*
94103 + * mm->mmap_sem is required to protect against another thread
94104 + * changing the mappings in case we sleep.
94105 + */
94106 + verify_mm_writelocked(mm);
94107 +
94108 /* Check against address space limit. */
94109 +
94110 +#ifdef CONFIG_PAX_RANDMMAP
94111 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
94112 +#endif
94113 +
94114 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
94115 unsigned long nr_pages;
94116
94117 @@ -1521,11 +1660,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
94118
94119 /* Clear old maps */
94120 error = -ENOMEM;
94121 -munmap_back:
94122 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
94123 if (do_munmap(mm, addr, len))
94124 return -ENOMEM;
94125 - goto munmap_back;
94126 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
94127 }
94128
94129 /*
94130 @@ -1556,6 +1694,16 @@ munmap_back:
94131 goto unacct_error;
94132 }
94133
94134 +#ifdef CONFIG_PAX_SEGMEXEC
94135 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
94136 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
94137 + if (!vma_m) {
94138 + error = -ENOMEM;
94139 + goto free_vma;
94140 + }
94141 + }
94142 +#endif
94143 +
94144 vma->vm_mm = mm;
94145 vma->vm_start = addr;
94146 vma->vm_end = addr + len;
94147 @@ -1575,6 +1723,13 @@ munmap_back:
94148 if (error)
94149 goto unmap_and_free_vma;
94150
94151 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
94152 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
94153 + vma->vm_flags |= VM_PAGEEXEC;
94154 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
94155 + }
94156 +#endif
94157 +
94158 /* Can addr have changed??
94159 *
94160 * Answer: Yes, several device drivers can do it in their
94161 @@ -1608,6 +1763,12 @@ munmap_back:
94162 }
94163
94164 vma_link(mm, vma, prev, rb_link, rb_parent);
94165 +
94166 +#ifdef CONFIG_PAX_SEGMEXEC
94167 + if (vma_m)
94168 + BUG_ON(pax_mirror_vma(vma_m, vma));
94169 +#endif
94170 +
94171 /* Once vma denies write, undo our temporary denial count */
94172 if (vm_flags & VM_DENYWRITE)
94173 allow_write_access(file);
94174 @@ -1616,6 +1777,7 @@ out:
94175 perf_event_mmap(vma);
94176
94177 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
94178 + track_exec_limit(mm, addr, addr + len, vm_flags);
94179 if (vm_flags & VM_LOCKED) {
94180 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
94181 vma == get_gate_vma(current->mm)))
94182 @@ -1648,6 +1810,12 @@ unmap_and_free_vma:
94183 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
94184 charged = 0;
94185 free_vma:
94186 +
94187 +#ifdef CONFIG_PAX_SEGMEXEC
94188 + if (vma_m)
94189 + kmem_cache_free(vm_area_cachep, vma_m);
94190 +#endif
94191 +
94192 kmem_cache_free(vm_area_cachep, vma);
94193 unacct_error:
94194 if (charged)
94195 @@ -1655,7 +1823,63 @@ unacct_error:
94196 return error;
94197 }
94198
94199 -unsigned long unmapped_area(struct vm_unmapped_area_info *info)
94200 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
94201 +unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
94202 +{
94203 + if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
94204 + return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
94205 +
94206 + return 0;
94207 +}
94208 +#endif
94209 +
94210 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
94211 +{
94212 + if (!vma) {
94213 +#ifdef CONFIG_STACK_GROWSUP
94214 + if (addr > sysctl_heap_stack_gap)
94215 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
94216 + else
94217 + vma = find_vma(current->mm, 0);
94218 + if (vma && (vma->vm_flags & VM_GROWSUP))
94219 + return false;
94220 +#endif
94221 + return true;
94222 + }
94223 +
94224 + if (addr + len > vma->vm_start)
94225 + return false;
94226 +
94227 + if (vma->vm_flags & VM_GROWSDOWN)
94228 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
94229 +#ifdef CONFIG_STACK_GROWSUP
94230 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
94231 + return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
94232 +#endif
94233 + else if (offset)
94234 + return offset <= vma->vm_start - addr - len;
94235 +
94236 + return true;
94237 +}
94238 +
94239 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
94240 +{
94241 + if (vma->vm_start < len)
94242 + return -ENOMEM;
94243 +
94244 + if (!(vma->vm_flags & VM_GROWSDOWN)) {
94245 + if (offset <= vma->vm_start - len)
94246 + return vma->vm_start - len - offset;
94247 + else
94248 + return -ENOMEM;
94249 + }
94250 +
94251 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
94252 + return vma->vm_start - len - sysctl_heap_stack_gap;
94253 + return -ENOMEM;
94254 +}
94255 +
94256 +unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
94257 {
94258 /*
94259 * We implement the search by looking for an rbtree node that
94260 @@ -1703,11 +1927,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
94261 }
94262 }
94263
94264 - gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
94265 + gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
94266 check_current:
94267 /* Check if current node has a suitable gap */
94268 if (gap_start > high_limit)
94269 return -ENOMEM;
94270 +
94271 + if (gap_end - gap_start > info->threadstack_offset)
94272 + gap_start += info->threadstack_offset;
94273 + else
94274 + gap_start = gap_end;
94275 +
94276 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
94277 + if (gap_end - gap_start > sysctl_heap_stack_gap)
94278 + gap_start += sysctl_heap_stack_gap;
94279 + else
94280 + gap_start = gap_end;
94281 + }
94282 + if (vma->vm_flags & VM_GROWSDOWN) {
94283 + if (gap_end - gap_start > sysctl_heap_stack_gap)
94284 + gap_end -= sysctl_heap_stack_gap;
94285 + else
94286 + gap_end = gap_start;
94287 + }
94288 if (gap_end >= low_limit && gap_end - gap_start >= length)
94289 goto found;
94290
94291 @@ -1757,7 +1999,7 @@ found:
94292 return gap_start;
94293 }
94294
94295 -unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
94296 +unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
94297 {
94298 struct mm_struct *mm = current->mm;
94299 struct vm_area_struct *vma;
94300 @@ -1811,6 +2053,24 @@ check_current:
94301 gap_end = vma->vm_start;
94302 if (gap_end < low_limit)
94303 return -ENOMEM;
94304 +
94305 + if (gap_end - gap_start > info->threadstack_offset)
94306 + gap_end -= info->threadstack_offset;
94307 + else
94308 + gap_end = gap_start;
94309 +
94310 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
94311 + if (gap_end - gap_start > sysctl_heap_stack_gap)
94312 + gap_start += sysctl_heap_stack_gap;
94313 + else
94314 + gap_start = gap_end;
94315 + }
94316 + if (vma->vm_flags & VM_GROWSDOWN) {
94317 + if (gap_end - gap_start > sysctl_heap_stack_gap)
94318 + gap_end -= sysctl_heap_stack_gap;
94319 + else
94320 + gap_end = gap_start;
94321 + }
94322 if (gap_start <= high_limit && gap_end - gap_start >= length)
94323 goto found;
94324
94325 @@ -1874,6 +2134,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
94326 struct mm_struct *mm = current->mm;
94327 struct vm_area_struct *vma;
94328 struct vm_unmapped_area_info info;
94329 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
94330
94331 if (len > TASK_SIZE - mmap_min_addr)
94332 return -ENOMEM;
94333 @@ -1881,11 +2142,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
94334 if (flags & MAP_FIXED)
94335 return addr;
94336
94337 +#ifdef CONFIG_PAX_RANDMMAP
94338 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
94339 +#endif
94340 +
94341 if (addr) {
94342 addr = PAGE_ALIGN(addr);
94343 vma = find_vma(mm, addr);
94344 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
94345 - (!vma || addr + len <= vma->vm_start))
94346 + check_heap_stack_gap(vma, addr, len, offset))
94347 return addr;
94348 }
94349
94350 @@ -1894,6 +2159,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
94351 info.low_limit = mm->mmap_base;
94352 info.high_limit = TASK_SIZE;
94353 info.align_mask = 0;
94354 + info.threadstack_offset = offset;
94355 return vm_unmapped_area(&info);
94356 }
94357 #endif
94358 @@ -1912,6 +2178,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94359 struct mm_struct *mm = current->mm;
94360 unsigned long addr = addr0;
94361 struct vm_unmapped_area_info info;
94362 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
94363
94364 /* requested length too big for entire address space */
94365 if (len > TASK_SIZE - mmap_min_addr)
94366 @@ -1920,12 +2187,16 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94367 if (flags & MAP_FIXED)
94368 return addr;
94369
94370 +#ifdef CONFIG_PAX_RANDMMAP
94371 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
94372 +#endif
94373 +
94374 /* requesting a specific address */
94375 if (addr) {
94376 addr = PAGE_ALIGN(addr);
94377 vma = find_vma(mm, addr);
94378 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
94379 - (!vma || addr + len <= vma->vm_start))
94380 + check_heap_stack_gap(vma, addr, len, offset))
94381 return addr;
94382 }
94383
94384 @@ -1934,6 +2205,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94385 info.low_limit = max(PAGE_SIZE, mmap_min_addr);
94386 info.high_limit = mm->mmap_base;
94387 info.align_mask = 0;
94388 + info.threadstack_offset = offset;
94389 addr = vm_unmapped_area(&info);
94390
94391 /*
94392 @@ -1946,6 +2218,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
94393 VM_BUG_ON(addr != -ENOMEM);
94394 info.flags = 0;
94395 info.low_limit = TASK_UNMAPPED_BASE;
94396 +
94397 +#ifdef CONFIG_PAX_RANDMMAP
94398 + if (mm->pax_flags & MF_PAX_RANDMMAP)
94399 + info.low_limit += mm->delta_mmap;
94400 +#endif
94401 +
94402 info.high_limit = TASK_SIZE;
94403 addr = vm_unmapped_area(&info);
94404 }
94405 @@ -2046,6 +2324,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
94406 return vma;
94407 }
94408
94409 +#ifdef CONFIG_PAX_SEGMEXEC
94410 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
94411 +{
94412 + struct vm_area_struct *vma_m;
94413 +
94414 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
94415 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
94416 + BUG_ON(vma->vm_mirror);
94417 + return NULL;
94418 + }
94419 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
94420 + vma_m = vma->vm_mirror;
94421 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
94422 + BUG_ON(vma->vm_file != vma_m->vm_file);
94423 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
94424 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
94425 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
94426 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
94427 + return vma_m;
94428 +}
94429 +#endif
94430 +
94431 /*
94432 * Verify that the stack growth is acceptable and
94433 * update accounting. This is shared with both the
94434 @@ -2062,6 +2362,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
94435 return -ENOMEM;
94436
94437 /* Stack limit test */
94438 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
94439 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
94440 return -ENOMEM;
94441
94442 @@ -2072,6 +2373,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
94443 locked = mm->locked_vm + grow;
94444 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
94445 limit >>= PAGE_SHIFT;
94446 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
94447 if (locked > limit && !capable(CAP_IPC_LOCK))
94448 return -ENOMEM;
94449 }
94450 @@ -2101,37 +2403,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
94451 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
94452 * vma is the last one with address > vma->vm_end. Have to extend vma.
94453 */
94454 +#ifndef CONFIG_IA64
94455 +static
94456 +#endif
94457 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
94458 {
94459 int error;
94460 + bool locknext;
94461
94462 if (!(vma->vm_flags & VM_GROWSUP))
94463 return -EFAULT;
94464
94465 + /* Also guard against wrapping around to address 0. */
94466 + if (address < PAGE_ALIGN(address+1))
94467 + address = PAGE_ALIGN(address+1);
94468 + else
94469 + return -ENOMEM;
94470 +
94471 /*
94472 * We must make sure the anon_vma is allocated
94473 * so that the anon_vma locking is not a noop.
94474 */
94475 if (unlikely(anon_vma_prepare(vma)))
94476 return -ENOMEM;
94477 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
94478 + if (locknext && anon_vma_prepare(vma->vm_next))
94479 + return -ENOMEM;
94480 vma_lock_anon_vma(vma);
94481 + if (locknext)
94482 + vma_lock_anon_vma(vma->vm_next);
94483
94484 /*
94485 * vma->vm_start/vm_end cannot change under us because the caller
94486 * is required to hold the mmap_sem in read mode. We need the
94487 - * anon_vma lock to serialize against concurrent expand_stacks.
94488 - * Also guard against wrapping around to address 0.
94489 + * anon_vma locks to serialize against concurrent expand_stacks
94490 + * and expand_upwards.
94491 */
94492 - if (address < PAGE_ALIGN(address+4))
94493 - address = PAGE_ALIGN(address+4);
94494 - else {
94495 - vma_unlock_anon_vma(vma);
94496 - return -ENOMEM;
94497 - }
94498 error = 0;
94499
94500 /* Somebody else might have raced and expanded it already */
94501 - if (address > vma->vm_end) {
94502 + 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)
94503 + error = -ENOMEM;
94504 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
94505 unsigned long size, grow;
94506
94507 size = address - vma->vm_start;
94508 @@ -2166,6 +2479,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
94509 }
94510 }
94511 }
94512 + if (locknext)
94513 + vma_unlock_anon_vma(vma->vm_next);
94514 vma_unlock_anon_vma(vma);
94515 khugepaged_enter_vma_merge(vma);
94516 validate_mm(vma->vm_mm);
94517 @@ -2180,6 +2495,8 @@ int expand_downwards(struct vm_area_struct *vma,
94518 unsigned long address)
94519 {
94520 int error;
94521 + bool lockprev = false;
94522 + struct vm_area_struct *prev;
94523
94524 /*
94525 * We must make sure the anon_vma is allocated
94526 @@ -2193,6 +2510,15 @@ int expand_downwards(struct vm_area_struct *vma,
94527 if (error)
94528 return error;
94529
94530 + prev = vma->vm_prev;
94531 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
94532 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
94533 +#endif
94534 + if (lockprev && anon_vma_prepare(prev))
94535 + return -ENOMEM;
94536 + if (lockprev)
94537 + vma_lock_anon_vma(prev);
94538 +
94539 vma_lock_anon_vma(vma);
94540
94541 /*
94542 @@ -2202,9 +2528,17 @@ int expand_downwards(struct vm_area_struct *vma,
94543 */
94544
94545 /* Somebody else might have raced and expanded it already */
94546 - if (address < vma->vm_start) {
94547 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
94548 + error = -ENOMEM;
94549 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
94550 unsigned long size, grow;
94551
94552 +#ifdef CONFIG_PAX_SEGMEXEC
94553 + struct vm_area_struct *vma_m;
94554 +
94555 + vma_m = pax_find_mirror_vma(vma);
94556 +#endif
94557 +
94558 size = vma->vm_end - address;
94559 grow = (vma->vm_start - address) >> PAGE_SHIFT;
94560
94561 @@ -2229,13 +2563,27 @@ int expand_downwards(struct vm_area_struct *vma,
94562 vma->vm_pgoff -= grow;
94563 anon_vma_interval_tree_post_update_vma(vma);
94564 vma_gap_update(vma);
94565 +
94566 +#ifdef CONFIG_PAX_SEGMEXEC
94567 + if (vma_m) {
94568 + anon_vma_interval_tree_pre_update_vma(vma_m);
94569 + vma_m->vm_start -= grow << PAGE_SHIFT;
94570 + vma_m->vm_pgoff -= grow;
94571 + anon_vma_interval_tree_post_update_vma(vma_m);
94572 + vma_gap_update(vma_m);
94573 + }
94574 +#endif
94575 +
94576 spin_unlock(&vma->vm_mm->page_table_lock);
94577
94578 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
94579 perf_event_mmap(vma);
94580 }
94581 }
94582 }
94583 vma_unlock_anon_vma(vma);
94584 + if (lockprev)
94585 + vma_unlock_anon_vma(prev);
94586 khugepaged_enter_vma_merge(vma);
94587 validate_mm(vma->vm_mm);
94588 return error;
94589 @@ -2333,6 +2681,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
94590 do {
94591 long nrpages = vma_pages(vma);
94592
94593 +#ifdef CONFIG_PAX_SEGMEXEC
94594 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
94595 + vma = remove_vma(vma);
94596 + continue;
94597 + }
94598 +#endif
94599 +
94600 if (vma->vm_flags & VM_ACCOUNT)
94601 nr_accounted += nrpages;
94602 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
94603 @@ -2377,6 +2732,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
94604 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
94605 vma->vm_prev = NULL;
94606 do {
94607 +
94608 +#ifdef CONFIG_PAX_SEGMEXEC
94609 + if (vma->vm_mirror) {
94610 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
94611 + vma->vm_mirror->vm_mirror = NULL;
94612 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
94613 + vma->vm_mirror = NULL;
94614 + }
94615 +#endif
94616 +
94617 vma_rb_erase(vma, &mm->mm_rb);
94618 mm->map_count--;
94619 tail_vma = vma;
94620 @@ -2404,14 +2769,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94621 struct vm_area_struct *new;
94622 int err = -ENOMEM;
94623
94624 +#ifdef CONFIG_PAX_SEGMEXEC
94625 + struct vm_area_struct *vma_m, *new_m = NULL;
94626 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
94627 +#endif
94628 +
94629 if (is_vm_hugetlb_page(vma) && (addr &
94630 ~(huge_page_mask(hstate_vma(vma)))))
94631 return -EINVAL;
94632
94633 +#ifdef CONFIG_PAX_SEGMEXEC
94634 + vma_m = pax_find_mirror_vma(vma);
94635 +#endif
94636 +
94637 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
94638 if (!new)
94639 goto out_err;
94640
94641 +#ifdef CONFIG_PAX_SEGMEXEC
94642 + if (vma_m) {
94643 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
94644 + if (!new_m) {
94645 + kmem_cache_free(vm_area_cachep, new);
94646 + goto out_err;
94647 + }
94648 + }
94649 +#endif
94650 +
94651 /* most fields are the same, copy all, and then fixup */
94652 *new = *vma;
94653
94654 @@ -2424,6 +2808,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94655 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
94656 }
94657
94658 +#ifdef CONFIG_PAX_SEGMEXEC
94659 + if (vma_m) {
94660 + *new_m = *vma_m;
94661 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
94662 + new_m->vm_mirror = new;
94663 + new->vm_mirror = new_m;
94664 +
94665 + if (new_below)
94666 + new_m->vm_end = addr_m;
94667 + else {
94668 + new_m->vm_start = addr_m;
94669 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
94670 + }
94671 + }
94672 +#endif
94673 +
94674 err = vma_dup_policy(vma, new);
94675 if (err)
94676 goto out_free_vma;
94677 @@ -2443,6 +2843,38 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94678 else
94679 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
94680
94681 +#ifdef CONFIG_PAX_SEGMEXEC
94682 + if (!err && vma_m) {
94683 + struct mempolicy *pol = vma_policy(new);
94684 +
94685 + if (anon_vma_clone(new_m, vma_m))
94686 + goto out_free_mpol;
94687 +
94688 + mpol_get(pol);
94689 + set_vma_policy(new_m, pol);
94690 +
94691 + if (new_m->vm_file)
94692 + get_file(new_m->vm_file);
94693 +
94694 + if (new_m->vm_ops && new_m->vm_ops->open)
94695 + new_m->vm_ops->open(new_m);
94696 +
94697 + if (new_below)
94698 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
94699 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
94700 + else
94701 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
94702 +
94703 + if (err) {
94704 + if (new_m->vm_ops && new_m->vm_ops->close)
94705 + new_m->vm_ops->close(new_m);
94706 + if (new_m->vm_file)
94707 + fput(new_m->vm_file);
94708 + mpol_put(pol);
94709 + }
94710 + }
94711 +#endif
94712 +
94713 /* Success. */
94714 if (!err)
94715 return 0;
94716 @@ -2452,10 +2884,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94717 new->vm_ops->close(new);
94718 if (new->vm_file)
94719 fput(new->vm_file);
94720 - unlink_anon_vmas(new);
94721 out_free_mpol:
94722 mpol_put(vma_policy(new));
94723 out_free_vma:
94724 +
94725 +#ifdef CONFIG_PAX_SEGMEXEC
94726 + if (new_m) {
94727 + unlink_anon_vmas(new_m);
94728 + kmem_cache_free(vm_area_cachep, new_m);
94729 + }
94730 +#endif
94731 +
94732 + unlink_anon_vmas(new);
94733 kmem_cache_free(vm_area_cachep, new);
94734 out_err:
94735 return err;
94736 @@ -2468,6 +2908,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
94737 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
94738 unsigned long addr, int new_below)
94739 {
94740 +
94741 +#ifdef CONFIG_PAX_SEGMEXEC
94742 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
94743 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
94744 + if (mm->map_count >= sysctl_max_map_count-1)
94745 + return -ENOMEM;
94746 + } else
94747 +#endif
94748 +
94749 if (mm->map_count >= sysctl_max_map_count)
94750 return -ENOMEM;
94751
94752 @@ -2479,11 +2928,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
94753 * work. This now handles partial unmappings.
94754 * Jeremy Fitzhardinge <jeremy@goop.org>
94755 */
94756 +#ifdef CONFIG_PAX_SEGMEXEC
94757 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94758 {
94759 + int ret = __do_munmap(mm, start, len);
94760 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
94761 + return ret;
94762 +
94763 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
94764 +}
94765 +
94766 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94767 +#else
94768 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94769 +#endif
94770 +{
94771 unsigned long end;
94772 struct vm_area_struct *vma, *prev, *last;
94773
94774 + /*
94775 + * mm->mmap_sem is required to protect against another thread
94776 + * changing the mappings in case we sleep.
94777 + */
94778 + verify_mm_writelocked(mm);
94779 +
94780 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
94781 return -EINVAL;
94782
94783 @@ -2558,6 +3026,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
94784 /* Fix up all other VM information */
94785 remove_vma_list(mm, vma);
94786
94787 + track_exec_limit(mm, start, end, 0UL);
94788 +
94789 return 0;
94790 }
94791
94792 @@ -2566,6 +3036,13 @@ int vm_munmap(unsigned long start, size_t len)
94793 int ret;
94794 struct mm_struct *mm = current->mm;
94795
94796 +
94797 +#ifdef CONFIG_PAX_SEGMEXEC
94798 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
94799 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
94800 + return -EINVAL;
94801 +#endif
94802 +
94803 down_write(&mm->mmap_sem);
94804 ret = do_munmap(mm, start, len);
94805 up_write(&mm->mmap_sem);
94806 @@ -2579,16 +3056,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
94807 return vm_munmap(addr, len);
94808 }
94809
94810 -static inline void verify_mm_writelocked(struct mm_struct *mm)
94811 -{
94812 -#ifdef CONFIG_DEBUG_VM
94813 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
94814 - WARN_ON(1);
94815 - up_read(&mm->mmap_sem);
94816 - }
94817 -#endif
94818 -}
94819 -
94820 /*
94821 * this is really a simplified "do_mmap". it only handles
94822 * anonymous maps. eventually we may be able to do some
94823 @@ -2602,6 +3069,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94824 struct rb_node ** rb_link, * rb_parent;
94825 pgoff_t pgoff = addr >> PAGE_SHIFT;
94826 int error;
94827 + unsigned long charged;
94828
94829 len = PAGE_ALIGN(len);
94830 if (!len)
94831 @@ -2609,10 +3077,24 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94832
94833 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
94834
94835 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
94836 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
94837 + flags &= ~VM_EXEC;
94838 +
94839 +#ifdef CONFIG_PAX_MPROTECT
94840 + if (mm->pax_flags & MF_PAX_MPROTECT)
94841 + flags &= ~VM_MAYEXEC;
94842 +#endif
94843 +
94844 + }
94845 +#endif
94846 +
94847 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
94848 if (error & ~PAGE_MASK)
94849 return error;
94850
94851 + charged = len >> PAGE_SHIFT;
94852 +
94853 error = mlock_future_check(mm, mm->def_flags, len);
94854 if (error)
94855 return error;
94856 @@ -2626,21 +3108,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94857 /*
94858 * Clear old maps. this also does some error checking for us
94859 */
94860 - munmap_back:
94861 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
94862 if (do_munmap(mm, addr, len))
94863 return -ENOMEM;
94864 - goto munmap_back;
94865 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
94866 }
94867
94868 /* Check against address space limits *after* clearing old maps... */
94869 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
94870 + if (!may_expand_vm(mm, charged))
94871 return -ENOMEM;
94872
94873 if (mm->map_count > sysctl_max_map_count)
94874 return -ENOMEM;
94875
94876 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
94877 + if (security_vm_enough_memory_mm(mm, charged))
94878 return -ENOMEM;
94879
94880 /* Can we just expand an old private anonymous mapping? */
94881 @@ -2654,7 +3135,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94882 */
94883 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
94884 if (!vma) {
94885 - vm_unacct_memory(len >> PAGE_SHIFT);
94886 + vm_unacct_memory(charged);
94887 return -ENOMEM;
94888 }
94889
94890 @@ -2668,10 +3149,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
94891 vma_link(mm, vma, prev, rb_link, rb_parent);
94892 out:
94893 perf_event_mmap(vma);
94894 - mm->total_vm += len >> PAGE_SHIFT;
94895 + mm->total_vm += charged;
94896 if (flags & VM_LOCKED)
94897 - mm->locked_vm += (len >> PAGE_SHIFT);
94898 + mm->locked_vm += charged;
94899 vma->vm_flags |= VM_SOFTDIRTY;
94900 + track_exec_limit(mm, addr, addr + len, flags);
94901 return addr;
94902 }
94903
94904 @@ -2733,6 +3215,7 @@ void exit_mmap(struct mm_struct *mm)
94905 while (vma) {
94906 if (vma->vm_flags & VM_ACCOUNT)
94907 nr_accounted += vma_pages(vma);
94908 + vma->vm_mirror = NULL;
94909 vma = remove_vma(vma);
94910 }
94911 vm_unacct_memory(nr_accounted);
94912 @@ -2750,6 +3233,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
94913 struct vm_area_struct *prev;
94914 struct rb_node **rb_link, *rb_parent;
94915
94916 +#ifdef CONFIG_PAX_SEGMEXEC
94917 + struct vm_area_struct *vma_m = NULL;
94918 +#endif
94919 +
94920 + if (security_mmap_addr(vma->vm_start))
94921 + return -EPERM;
94922 +
94923 /*
94924 * The vm_pgoff of a purely anonymous vma should be irrelevant
94925 * until its first write fault, when page's anon_vma and index
94926 @@ -2773,7 +3263,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
94927 security_vm_enough_memory_mm(mm, vma_pages(vma)))
94928 return -ENOMEM;
94929
94930 +#ifdef CONFIG_PAX_SEGMEXEC
94931 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
94932 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
94933 + if (!vma_m)
94934 + return -ENOMEM;
94935 + }
94936 +#endif
94937 +
94938 vma_link(mm, vma, prev, rb_link, rb_parent);
94939 +
94940 +#ifdef CONFIG_PAX_SEGMEXEC
94941 + if (vma_m)
94942 + BUG_ON(pax_mirror_vma(vma_m, vma));
94943 +#endif
94944 +
94945 return 0;
94946 }
94947
94948 @@ -2792,6 +3296,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
94949 struct rb_node **rb_link, *rb_parent;
94950 bool faulted_in_anon_vma = true;
94951
94952 + BUG_ON(vma->vm_mirror);
94953 +
94954 /*
94955 * If anonymous vma has not yet been faulted, update new pgoff
94956 * to match new location, to increase its chance of merging.
94957 @@ -2856,6 +3362,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
94958 return NULL;
94959 }
94960
94961 +#ifdef CONFIG_PAX_SEGMEXEC
94962 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
94963 +{
94964 + struct vm_area_struct *prev_m;
94965 + struct rb_node **rb_link_m, *rb_parent_m;
94966 + struct mempolicy *pol_m;
94967 +
94968 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
94969 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
94970 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
94971 + *vma_m = *vma;
94972 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
94973 + if (anon_vma_clone(vma_m, vma))
94974 + return -ENOMEM;
94975 + pol_m = vma_policy(vma_m);
94976 + mpol_get(pol_m);
94977 + set_vma_policy(vma_m, pol_m);
94978 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
94979 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
94980 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
94981 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
94982 + if (vma_m->vm_file)
94983 + get_file(vma_m->vm_file);
94984 + if (vma_m->vm_ops && vma_m->vm_ops->open)
94985 + vma_m->vm_ops->open(vma_m);
94986 + BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
94987 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
94988 + vma_m->vm_mirror = vma;
94989 + vma->vm_mirror = vma_m;
94990 + return 0;
94991 +}
94992 +#endif
94993 +
94994 /*
94995 * Return true if the calling process may expand its vm space by the passed
94996 * number of pages
94997 @@ -2867,6 +3406,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
94998
94999 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
95000
95001 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
95002 if (cur + npages > lim)
95003 return 0;
95004 return 1;
95005 @@ -2937,6 +3477,22 @@ struct vm_area_struct *_install_special_mapping(struct mm_struct *mm,
95006 vma->vm_start = addr;
95007 vma->vm_end = addr + len;
95008
95009 +#ifdef CONFIG_PAX_MPROTECT
95010 + if (mm->pax_flags & MF_PAX_MPROTECT) {
95011 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
95012 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
95013 + return ERR_PTR(-EPERM);
95014 + if (!(vm_flags & VM_EXEC))
95015 + vm_flags &= ~VM_MAYEXEC;
95016 +#else
95017 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
95018 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
95019 +#endif
95020 + else
95021 + vm_flags &= ~VM_MAYWRITE;
95022 + }
95023 +#endif
95024 +
95025 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
95026 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
95027
95028 diff --git a/mm/mprotect.c b/mm/mprotect.c
95029 index c43d557..0b7ccd2 100644
95030 --- a/mm/mprotect.c
95031 +++ b/mm/mprotect.c
95032 @@ -24,10 +24,18 @@
95033 #include <linux/migrate.h>
95034 #include <linux/perf_event.h>
95035 #include <linux/ksm.h>
95036 +#include <linux/sched/sysctl.h>
95037 +
95038 +#ifdef CONFIG_PAX_MPROTECT
95039 +#include <linux/elf.h>
95040 +#include <linux/binfmts.h>
95041 +#endif
95042 +
95043 #include <asm/uaccess.h>
95044 #include <asm/pgtable.h>
95045 #include <asm/cacheflush.h>
95046 #include <asm/tlbflush.h>
95047 +#include <asm/mmu_context.h>
95048
95049 #ifndef pgprot_modify
95050 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
95051 @@ -256,6 +264,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
95052 return pages;
95053 }
95054
95055 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
95056 +/* called while holding the mmap semaphor for writing except stack expansion */
95057 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
95058 +{
95059 + unsigned long oldlimit, newlimit = 0UL;
95060 +
95061 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
95062 + return;
95063 +
95064 + spin_lock(&mm->page_table_lock);
95065 + oldlimit = mm->context.user_cs_limit;
95066 + if ((prot & VM_EXEC) && oldlimit < end)
95067 + /* USER_CS limit moved up */
95068 + newlimit = end;
95069 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
95070 + /* USER_CS limit moved down */
95071 + newlimit = start;
95072 +
95073 + if (newlimit) {
95074 + mm->context.user_cs_limit = newlimit;
95075 +
95076 +#ifdef CONFIG_SMP
95077 + wmb();
95078 + cpus_clear(mm->context.cpu_user_cs_mask);
95079 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
95080 +#endif
95081 +
95082 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
95083 + }
95084 + spin_unlock(&mm->page_table_lock);
95085 + if (newlimit == end) {
95086 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
95087 +
95088 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
95089 + if (is_vm_hugetlb_page(vma))
95090 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
95091 + else
95092 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
95093 + }
95094 +}
95095 +#endif
95096 +
95097 int
95098 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
95099 unsigned long start, unsigned long end, unsigned long newflags)
95100 @@ -268,11 +318,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
95101 int error;
95102 int dirty_accountable = 0;
95103
95104 +#ifdef CONFIG_PAX_SEGMEXEC
95105 + struct vm_area_struct *vma_m = NULL;
95106 + unsigned long start_m, end_m;
95107 +
95108 + start_m = start + SEGMEXEC_TASK_SIZE;
95109 + end_m = end + SEGMEXEC_TASK_SIZE;
95110 +#endif
95111 +
95112 if (newflags == oldflags) {
95113 *pprev = vma;
95114 return 0;
95115 }
95116
95117 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
95118 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
95119 +
95120 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
95121 + return -ENOMEM;
95122 +
95123 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
95124 + return -ENOMEM;
95125 + }
95126 +
95127 /*
95128 * If we make a private mapping writable we increase our commit;
95129 * but (without finer accounting) cannot reduce our commit if we
95130 @@ -289,6 +357,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
95131 }
95132 }
95133
95134 +#ifdef CONFIG_PAX_SEGMEXEC
95135 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
95136 + if (start != vma->vm_start) {
95137 + error = split_vma(mm, vma, start, 1);
95138 + if (error)
95139 + goto fail;
95140 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
95141 + *pprev = (*pprev)->vm_next;
95142 + }
95143 +
95144 + if (end != vma->vm_end) {
95145 + error = split_vma(mm, vma, end, 0);
95146 + if (error)
95147 + goto fail;
95148 + }
95149 +
95150 + if (pax_find_mirror_vma(vma)) {
95151 + error = __do_munmap(mm, start_m, end_m - start_m);
95152 + if (error)
95153 + goto fail;
95154 + } else {
95155 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
95156 + if (!vma_m) {
95157 + error = -ENOMEM;
95158 + goto fail;
95159 + }
95160 + vma->vm_flags = newflags;
95161 + error = pax_mirror_vma(vma_m, vma);
95162 + if (error) {
95163 + vma->vm_flags = oldflags;
95164 + goto fail;
95165 + }
95166 + }
95167 + }
95168 +#endif
95169 +
95170 /*
95171 * First try to merge with previous and/or next vma.
95172 */
95173 @@ -319,9 +423,21 @@ success:
95174 * vm_flags and vm_page_prot are protected by the mmap_sem
95175 * held in write mode.
95176 */
95177 +
95178 +#ifdef CONFIG_PAX_SEGMEXEC
95179 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
95180 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
95181 +#endif
95182 +
95183 vma->vm_flags = newflags;
95184 +
95185 +#ifdef CONFIG_PAX_MPROTECT
95186 + if (mm->binfmt && mm->binfmt->handle_mprotect)
95187 + mm->binfmt->handle_mprotect(vma, newflags);
95188 +#endif
95189 +
95190 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
95191 - vm_get_page_prot(newflags));
95192 + vm_get_page_prot(vma->vm_flags));
95193
95194 if (vma_wants_writenotify(vma)) {
95195 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
95196 @@ -360,6 +476,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95197 end = start + len;
95198 if (end <= start)
95199 return -ENOMEM;
95200 +
95201 +#ifdef CONFIG_PAX_SEGMEXEC
95202 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
95203 + if (end > SEGMEXEC_TASK_SIZE)
95204 + return -EINVAL;
95205 + } else
95206 +#endif
95207 +
95208 + if (end > TASK_SIZE)
95209 + return -EINVAL;
95210 +
95211 if (!arch_validate_prot(prot))
95212 return -EINVAL;
95213
95214 @@ -367,7 +494,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95215 /*
95216 * Does the application expect PROT_READ to imply PROT_EXEC:
95217 */
95218 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
95219 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
95220 prot |= PROT_EXEC;
95221
95222 vm_flags = calc_vm_prot_bits(prot);
95223 @@ -399,6 +526,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95224 if (start > vma->vm_start)
95225 prev = vma;
95226
95227 +#ifdef CONFIG_PAX_MPROTECT
95228 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
95229 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
95230 +#endif
95231 +
95232 for (nstart = start ; ; ) {
95233 unsigned long newflags;
95234
95235 @@ -409,6 +541,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95236
95237 /* newflags >> 4 shift VM_MAY% in place of VM_% */
95238 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
95239 + if (prot & (PROT_WRITE | PROT_EXEC))
95240 + gr_log_rwxmprotect(vma);
95241 +
95242 + error = -EACCES;
95243 + goto out;
95244 + }
95245 +
95246 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
95247 error = -EACCES;
95248 goto out;
95249 }
95250 @@ -423,6 +563,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
95251 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
95252 if (error)
95253 goto out;
95254 +
95255 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
95256 +
95257 nstart = tmp;
95258
95259 if (nstart < prev->vm_end)
95260 diff --git a/mm/mremap.c b/mm/mremap.c
95261 index 05f1180..c3cde48 100644
95262 --- a/mm/mremap.c
95263 +++ b/mm/mremap.c
95264 @@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
95265 continue;
95266 pte = ptep_get_and_clear(mm, old_addr, old_pte);
95267 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
95268 +
95269 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
95270 + if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
95271 + pte = pte_exprotect(pte);
95272 +#endif
95273 +
95274 pte = move_soft_dirty_pte(pte);
95275 set_pte_at(mm, new_addr, new_pte, pte);
95276 }
95277 @@ -344,6 +350,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
95278 if (is_vm_hugetlb_page(vma))
95279 goto Einval;
95280
95281 +#ifdef CONFIG_PAX_SEGMEXEC
95282 + if (pax_find_mirror_vma(vma))
95283 + goto Einval;
95284 +#endif
95285 +
95286 /* We can't remap across vm area boundaries */
95287 if (old_len > vma->vm_end - addr)
95288 goto Efault;
95289 @@ -399,20 +410,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
95290 unsigned long ret = -EINVAL;
95291 unsigned long charged = 0;
95292 unsigned long map_flags;
95293 + unsigned long pax_task_size = TASK_SIZE;
95294
95295 if (new_addr & ~PAGE_MASK)
95296 goto out;
95297
95298 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
95299 +#ifdef CONFIG_PAX_SEGMEXEC
95300 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
95301 + pax_task_size = SEGMEXEC_TASK_SIZE;
95302 +#endif
95303 +
95304 + pax_task_size -= PAGE_SIZE;
95305 +
95306 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
95307 goto out;
95308
95309 /* Check if the location we're moving into overlaps the
95310 * old location at all, and fail if it does.
95311 */
95312 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
95313 - goto out;
95314 -
95315 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
95316 + if (addr + old_len > new_addr && new_addr + new_len > addr)
95317 goto out;
95318
95319 ret = do_munmap(mm, new_addr, new_len);
95320 @@ -481,6 +497,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95321 unsigned long ret = -EINVAL;
95322 unsigned long charged = 0;
95323 bool locked = false;
95324 + unsigned long pax_task_size = TASK_SIZE;
95325
95326 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
95327 return ret;
95328 @@ -502,6 +519,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95329 if (!new_len)
95330 return ret;
95331
95332 +#ifdef CONFIG_PAX_SEGMEXEC
95333 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
95334 + pax_task_size = SEGMEXEC_TASK_SIZE;
95335 +#endif
95336 +
95337 + pax_task_size -= PAGE_SIZE;
95338 +
95339 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
95340 + old_len > pax_task_size || addr > pax_task_size-old_len)
95341 + return ret;
95342 +
95343 down_write(&current->mm->mmap_sem);
95344
95345 if (flags & MREMAP_FIXED) {
95346 @@ -552,6 +580,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95347 new_addr = addr;
95348 }
95349 ret = addr;
95350 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
95351 goto out;
95352 }
95353 }
95354 @@ -575,7 +604,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
95355 goto out;
95356 }
95357
95358 + map_flags = vma->vm_flags;
95359 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
95360 + if (!(ret & ~PAGE_MASK)) {
95361 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
95362 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
95363 + }
95364 }
95365 out:
95366 if (ret & ~PAGE_MASK)
95367 diff --git a/mm/nommu.c b/mm/nommu.c
95368 index 431fd7c..8674512 100644
95369 --- a/mm/nommu.c
95370 +++ b/mm/nommu.c
95371 @@ -67,7 +67,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
95372 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
95373 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
95374 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
95375 -int heap_stack_gap = 0;
95376
95377 atomic_long_t mmap_pages_allocated;
95378
95379 @@ -854,15 +853,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
95380 EXPORT_SYMBOL(find_vma);
95381
95382 /*
95383 - * find a VMA
95384 - * - we don't extend stack VMAs under NOMMU conditions
95385 - */
95386 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
95387 -{
95388 - return find_vma(mm, addr);
95389 -}
95390 -
95391 -/*
95392 * expand a stack to a given address
95393 * - not supported under NOMMU conditions
95394 */
95395 @@ -1569,6 +1559,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
95396
95397 /* most fields are the same, copy all, and then fixup */
95398 *new = *vma;
95399 + INIT_LIST_HEAD(&new->anon_vma_chain);
95400 *region = *vma->vm_region;
95401 new->vm_region = region;
95402
95403 @@ -2004,8 +1995,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
95404 }
95405 EXPORT_SYMBOL(generic_file_remap_pages);
95406
95407 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
95408 - unsigned long addr, void *buf, int len, int write)
95409 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
95410 + unsigned long addr, void *buf, size_t len, int write)
95411 {
95412 struct vm_area_struct *vma;
95413
95414 @@ -2046,8 +2037,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
95415 *
95416 * The caller must hold a reference on @mm.
95417 */
95418 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
95419 - void *buf, int len, int write)
95420 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
95421 + void *buf, size_t len, int write)
95422 {
95423 return __access_remote_vm(NULL, mm, addr, buf, len, write);
95424 }
95425 @@ -2056,7 +2047,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
95426 * Access another process' address space.
95427 * - source/target buffer must be kernel space
95428 */
95429 -int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
95430 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
95431 {
95432 struct mm_struct *mm;
95433
95434 diff --git a/mm/page-writeback.c b/mm/page-writeback.c
95435 index 154af21..86e447f 100644
95436 --- a/mm/page-writeback.c
95437 +++ b/mm/page-writeback.c
95438 @@ -685,7 +685,7 @@ static long long pos_ratio_polynom(unsigned long setpoint,
95439 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
95440 * - the bdi dirty thresh drops quickly due to change of JBOD workload
95441 */
95442 -static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
95443 +static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
95444 unsigned long thresh,
95445 unsigned long bg_thresh,
95446 unsigned long dirty,
95447 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
95448 index d64f5f9..9005ab5 100644
95449 --- a/mm/page_alloc.c
95450 +++ b/mm/page_alloc.c
95451 @@ -61,6 +61,7 @@
95452 #include <linux/page-debug-flags.h>
95453 #include <linux/hugetlb.h>
95454 #include <linux/sched/rt.h>
95455 +#include <linux/random.h>
95456
95457 #include <asm/sections.h>
95458 #include <asm/tlbflush.h>
95459 @@ -356,7 +357,7 @@ out:
95460 * This usage means that zero-order pages may not be compound.
95461 */
95462
95463 -static void free_compound_page(struct page *page)
95464 +void free_compound_page(struct page *page)
95465 {
95466 __free_pages_ok(page, compound_order(page));
95467 }
95468 @@ -730,6 +731,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
95469 int i;
95470 int bad = 0;
95471
95472 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
95473 + unsigned long index = 1UL << order;
95474 +#endif
95475 +
95476 trace_mm_page_free(page, order);
95477 kmemcheck_free_shadow(page, order);
95478
95479 @@ -746,6 +751,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
95480 debug_check_no_obj_freed(page_address(page),
95481 PAGE_SIZE << order);
95482 }
95483 +
95484 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
95485 + for (; index; --index)
95486 + sanitize_highpage(page + index - 1);
95487 +#endif
95488 +
95489 arch_free_page(page, order);
95490 kernel_map_pages(page, 1 << order, 0);
95491
95492 @@ -768,6 +779,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
95493 local_irq_restore(flags);
95494 }
95495
95496 +#ifdef CONFIG_PAX_LATENT_ENTROPY
95497 +bool __meminitdata extra_latent_entropy;
95498 +
95499 +static int __init setup_pax_extra_latent_entropy(char *str)
95500 +{
95501 + extra_latent_entropy = true;
95502 + return 0;
95503 +}
95504 +early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
95505 +
95506 +volatile u64 latent_entropy __latent_entropy;
95507 +EXPORT_SYMBOL(latent_entropy);
95508 +#endif
95509 +
95510 void __init __free_pages_bootmem(struct page *page, unsigned int order)
95511 {
95512 unsigned int nr_pages = 1 << order;
95513 @@ -783,6 +808,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
95514 __ClearPageReserved(p);
95515 set_page_count(p, 0);
95516
95517 +#ifdef CONFIG_PAX_LATENT_ENTROPY
95518 + if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
95519 + u64 hash = 0;
95520 + size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
95521 + const u64 *data = lowmem_page_address(page);
95522 +
95523 + for (index = 0; index < end; index++)
95524 + hash ^= hash + data[index];
95525 + latent_entropy ^= hash;
95526 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
95527 + }
95528 +#endif
95529 +
95530 page_zone(page)->managed_pages += nr_pages;
95531 set_page_refcounted(page);
95532 __free_pages(page, order);
95533 @@ -911,8 +949,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
95534 arch_alloc_page(page, order);
95535 kernel_map_pages(page, 1 << order, 1);
95536
95537 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
95538 if (gfp_flags & __GFP_ZERO)
95539 prep_zero_page(page, order, gfp_flags);
95540 +#endif
95541
95542 if (order && (gfp_flags & __GFP_COMP))
95543 prep_compound_page(page, order);
95544 @@ -2415,7 +2455,7 @@ static void reset_alloc_batches(struct zonelist *zonelist,
95545 continue;
95546 mod_zone_page_state(zone, NR_ALLOC_BATCH,
95547 high_wmark_pages(zone) - low_wmark_pages(zone) -
95548 - atomic_long_read(&zone->vm_stat[NR_ALLOC_BATCH]));
95549 + atomic_long_read_unchecked(&zone->vm_stat[NR_ALLOC_BATCH]));
95550 }
95551 }
95552
95553 diff --git a/mm/page_io.c b/mm/page_io.c
95554 index 7c59ef6..1358905 100644
95555 --- a/mm/page_io.c
95556 +++ b/mm/page_io.c
95557 @@ -260,7 +260,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
95558 struct file *swap_file = sis->swap_file;
95559 struct address_space *mapping = swap_file->f_mapping;
95560 struct iovec iov = {
95561 - .iov_base = kmap(page),
95562 + .iov_base = (void __force_user *)kmap(page),
95563 .iov_len = PAGE_SIZE,
95564 };
95565
95566 diff --git a/mm/percpu.c b/mm/percpu.c
95567 index 2ddf9a9..f8fc075 100644
95568 --- a/mm/percpu.c
95569 +++ b/mm/percpu.c
95570 @@ -123,7 +123,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
95571 static unsigned int pcpu_high_unit_cpu __read_mostly;
95572
95573 /* the address of the first chunk which starts with the kernel static area */
95574 -void *pcpu_base_addr __read_mostly;
95575 +void *pcpu_base_addr __read_only;
95576 EXPORT_SYMBOL_GPL(pcpu_base_addr);
95577
95578 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
95579 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
95580 index 8505c92..946bfc9 100644
95581 --- a/mm/process_vm_access.c
95582 +++ b/mm/process_vm_access.c
95583 @@ -13,6 +13,7 @@
95584 #include <linux/uio.h>
95585 #include <linux/sched.h>
95586 #include <linux/highmem.h>
95587 +#include <linux/security.h>
95588 #include <linux/ptrace.h>
95589 #include <linux/slab.h>
95590 #include <linux/syscalls.h>
95591 @@ -161,19 +162,19 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
95592 ssize_t iov_len;
95593 size_t total_len = iov_iter_count(iter);
95594
95595 + return -ENOSYS; // PaX: until properly audited
95596 +
95597 /*
95598 * Work out how many pages of struct pages we're going to need
95599 * when eventually calling get_user_pages
95600 */
95601 for (i = 0; i < riovcnt; i++) {
95602 iov_len = rvec[i].iov_len;
95603 - if (iov_len > 0) {
95604 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
95605 - + iov_len)
95606 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
95607 - / PAGE_SIZE + 1;
95608 - nr_pages = max(nr_pages, nr_pages_iov);
95609 - }
95610 + if (iov_len <= 0)
95611 + continue;
95612 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
95613 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
95614 + nr_pages = max(nr_pages, nr_pages_iov);
95615 }
95616
95617 if (nr_pages == 0)
95618 @@ -201,6 +202,11 @@ static ssize_t process_vm_rw_core(pid_t pid, struct iov_iter *iter,
95619 goto free_proc_pages;
95620 }
95621
95622 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
95623 + rc = -EPERM;
95624 + goto put_task_struct;
95625 + }
95626 +
95627 mm = mm_access(task, PTRACE_MODE_ATTACH);
95628 if (!mm || IS_ERR(mm)) {
95629 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
95630 diff --git a/mm/rmap.c b/mm/rmap.c
95631 index 14d1e28..3777962 100644
95632 --- a/mm/rmap.c
95633 +++ b/mm/rmap.c
95634 @@ -164,6 +164,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95635 struct anon_vma *anon_vma = vma->anon_vma;
95636 struct anon_vma_chain *avc;
95637
95638 +#ifdef CONFIG_PAX_SEGMEXEC
95639 + struct anon_vma_chain *avc_m = NULL;
95640 +#endif
95641 +
95642 might_sleep();
95643 if (unlikely(!anon_vma)) {
95644 struct mm_struct *mm = vma->vm_mm;
95645 @@ -173,6 +177,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95646 if (!avc)
95647 goto out_enomem;
95648
95649 +#ifdef CONFIG_PAX_SEGMEXEC
95650 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
95651 + if (!avc_m)
95652 + goto out_enomem_free_avc;
95653 +#endif
95654 +
95655 anon_vma = find_mergeable_anon_vma(vma);
95656 allocated = NULL;
95657 if (!anon_vma) {
95658 @@ -186,6 +196,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95659 /* page_table_lock to protect against threads */
95660 spin_lock(&mm->page_table_lock);
95661 if (likely(!vma->anon_vma)) {
95662 +
95663 +#ifdef CONFIG_PAX_SEGMEXEC
95664 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
95665 +
95666 + if (vma_m) {
95667 + BUG_ON(vma_m->anon_vma);
95668 + vma_m->anon_vma = anon_vma;
95669 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
95670 + avc_m = NULL;
95671 + }
95672 +#endif
95673 +
95674 vma->anon_vma = anon_vma;
95675 anon_vma_chain_link(vma, avc, anon_vma);
95676 allocated = NULL;
95677 @@ -196,12 +218,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
95678
95679 if (unlikely(allocated))
95680 put_anon_vma(allocated);
95681 +
95682 +#ifdef CONFIG_PAX_SEGMEXEC
95683 + if (unlikely(avc_m))
95684 + anon_vma_chain_free(avc_m);
95685 +#endif
95686 +
95687 if (unlikely(avc))
95688 anon_vma_chain_free(avc);
95689 }
95690 return 0;
95691
95692 out_enomem_free_avc:
95693 +
95694 +#ifdef CONFIG_PAX_SEGMEXEC
95695 + if (avc_m)
95696 + anon_vma_chain_free(avc_m);
95697 +#endif
95698 +
95699 anon_vma_chain_free(avc);
95700 out_enomem:
95701 return -ENOMEM;
95702 @@ -237,7 +271,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
95703 * Attach the anon_vmas from src to dst.
95704 * Returns 0 on success, -ENOMEM on failure.
95705 */
95706 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
95707 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
95708 {
95709 struct anon_vma_chain *avc, *pavc;
95710 struct anon_vma *root = NULL;
95711 @@ -270,7 +304,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
95712 * the corresponding VMA in the parent process is attached to.
95713 * Returns 0 on success, non-zero on failure.
95714 */
95715 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
95716 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
95717 {
95718 struct anon_vma_chain *avc;
95719 struct anon_vma *anon_vma;
95720 @@ -374,8 +408,10 @@ static void anon_vma_ctor(void *data)
95721 void __init anon_vma_init(void)
95722 {
95723 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
95724 - 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
95725 - anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
95726 + 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
95727 + anon_vma_ctor);
95728 + anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
95729 + SLAB_PANIC|SLAB_NO_SANITIZE);
95730 }
95731
95732 /*
95733 diff --git a/mm/shmem.c b/mm/shmem.c
95734 index a2801ba..b8651e6 100644
95735 --- a/mm/shmem.c
95736 +++ b/mm/shmem.c
95737 @@ -33,7 +33,7 @@
95738 #include <linux/swap.h>
95739 #include <linux/aio.h>
95740
95741 -static struct vfsmount *shm_mnt;
95742 +struct vfsmount *shm_mnt;
95743
95744 #ifdef CONFIG_SHMEM
95745 /*
95746 @@ -77,14 +77,15 @@ static struct vfsmount *shm_mnt;
95747 #define BOGO_DIRENT_SIZE 20
95748
95749 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
95750 -#define SHORT_SYMLINK_LEN 128
95751 +#define SHORT_SYMLINK_LEN 64
95752
95753 /*
95754 - * shmem_fallocate and shmem_writepage communicate via inode->i_private
95755 - * (with i_mutex making sure that it has only one user at a time):
95756 - * we would prefer not to enlarge the shmem inode just for that.
95757 + * shmem_fallocate communicates with shmem_fault or shmem_writepage via
95758 + * inode->i_private (with i_mutex making sure that it has only one user at
95759 + * a time): we would prefer not to enlarge the shmem inode just for that.
95760 */
95761 struct shmem_falloc {
95762 + int mode; /* FALLOC_FL mode currently operating */
95763 pgoff_t start; /* start of range currently being fallocated */
95764 pgoff_t next; /* the next page offset to be fallocated */
95765 pgoff_t nr_falloced; /* how many new pages have been fallocated */
95766 @@ -759,6 +760,7 @@ static int shmem_writepage(struct page *page, struct writeback_control *wbc)
95767 spin_lock(&inode->i_lock);
95768 shmem_falloc = inode->i_private;
95769 if (shmem_falloc &&
95770 + !shmem_falloc->mode &&
95771 index >= shmem_falloc->start &&
95772 index < shmem_falloc->next)
95773 shmem_falloc->nr_unswapped++;
95774 @@ -1233,6 +1235,43 @@ static int shmem_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
95775 int error;
95776 int ret = VM_FAULT_LOCKED;
95777
95778 + /*
95779 + * Trinity finds that probing a hole which tmpfs is punching can
95780 + * prevent the hole-punch from ever completing: which in turn
95781 + * locks writers out with its hold on i_mutex. So refrain from
95782 + * faulting pages into the hole while it's being punched, and
95783 + * wait on i_mutex to be released if vmf->flags permits,
95784 + */
95785 + if (unlikely(inode->i_private)) {
95786 + struct shmem_falloc *shmem_falloc;
95787 + spin_lock(&inode->i_lock);
95788 + shmem_falloc = inode->i_private;
95789 + if (!shmem_falloc ||
95790 + shmem_falloc->mode != FALLOC_FL_PUNCH_HOLE ||
95791 + vmf->pgoff < shmem_falloc->start ||
95792 + vmf->pgoff >= shmem_falloc->next)
95793 + shmem_falloc = NULL;
95794 + spin_unlock(&inode->i_lock);
95795 + /*
95796 + * i_lock has protected us from taking shmem_falloc seriously
95797 + * once return from shmem_fallocate() went back up that stack.
95798 + * i_lock does not serialize with i_mutex at all, but it does
95799 + * not matter if sometimes we wait unnecessarily, or sometimes
95800 + * miss out on waiting: we just need to make those cases rare.
95801 + */
95802 + if (shmem_falloc) {
95803 + if ((vmf->flags & FAULT_FLAG_ALLOW_RETRY) &&
95804 + !(vmf->flags & FAULT_FLAG_RETRY_NOWAIT)) {
95805 + up_read(&vma->vm_mm->mmap_sem);
95806 + mutex_lock(&inode->i_mutex);
95807 + mutex_unlock(&inode->i_mutex);
95808 + return VM_FAULT_RETRY;
95809 + }
95810 + /* cond_resched? Leave that to GUP or return to user */
95811 + return VM_FAULT_NOPAGE;
95812 + }
95813 + }
95814 +
95815 error = shmem_getpage(inode, vmf->pgoff, &vmf->page, SGP_CACHE, &ret);
95816 if (error)
95817 return ((error == -ENOMEM) ? VM_FAULT_OOM : VM_FAULT_SIGBUS);
95818 @@ -1733,18 +1772,26 @@ static long shmem_fallocate(struct file *file, int mode, loff_t offset,
95819
95820 mutex_lock(&inode->i_mutex);
95821
95822 + shmem_falloc.mode = mode & ~FALLOC_FL_KEEP_SIZE;
95823 +
95824 if (mode & FALLOC_FL_PUNCH_HOLE) {
95825 struct address_space *mapping = file->f_mapping;
95826 loff_t unmap_start = round_up(offset, PAGE_SIZE);
95827 loff_t unmap_end = round_down(offset + len, PAGE_SIZE) - 1;
95828
95829 + shmem_falloc.start = unmap_start >> PAGE_SHIFT;
95830 + shmem_falloc.next = (unmap_end + 1) >> PAGE_SHIFT;
95831 + spin_lock(&inode->i_lock);
95832 + inode->i_private = &shmem_falloc;
95833 + spin_unlock(&inode->i_lock);
95834 +
95835 if ((u64)unmap_end > (u64)unmap_start)
95836 unmap_mapping_range(mapping, unmap_start,
95837 1 + unmap_end - unmap_start, 0);
95838 shmem_truncate_range(inode, offset, offset + len - 1);
95839 /* No need to unmap again: hole-punching leaves COWed pages */
95840 error = 0;
95841 - goto out;
95842 + goto undone;
95843 }
95844
95845 /* We need to check rlimit even when FALLOC_FL_KEEP_SIZE */
95846 @@ -2138,6 +2185,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
95847 static int shmem_xattr_validate(const char *name)
95848 {
95849 struct { const char *prefix; size_t len; } arr[] = {
95850 +
95851 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
95852 + { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
95853 +#endif
95854 +
95855 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
95856 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
95857 };
95858 @@ -2193,6 +2245,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
95859 if (err)
95860 return err;
95861
95862 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
95863 + if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
95864 + if (strcmp(name, XATTR_NAME_PAX_FLAGS))
95865 + return -EOPNOTSUPP;
95866 + if (size > 8)
95867 + return -EINVAL;
95868 + }
95869 +#endif
95870 +
95871 return simple_xattr_set(&info->xattrs, name, value, size, flags);
95872 }
95873
95874 @@ -2505,8 +2566,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
95875 int err = -ENOMEM;
95876
95877 /* Round up to L1_CACHE_BYTES to resist false sharing */
95878 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
95879 - L1_CACHE_BYTES), GFP_KERNEL);
95880 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
95881 if (!sbinfo)
95882 return -ENOMEM;
95883
95884 diff --git a/mm/slab.c b/mm/slab.c
95885 index 9432556..e0dc685 100644
95886 --- a/mm/slab.c
95887 +++ b/mm/slab.c
95888 @@ -311,10 +311,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
95889 if ((x)->max_freeable < i) \
95890 (x)->max_freeable = i; \
95891 } while (0)
95892 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
95893 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
95894 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
95895 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
95896 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
95897 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
95898 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
95899 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
95900 +#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
95901 +#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
95902 #else
95903 #define STATS_INC_ACTIVE(x) do { } while (0)
95904 #define STATS_DEC_ACTIVE(x) do { } while (0)
95905 @@ -331,6 +333,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
95906 #define STATS_INC_ALLOCMISS(x) do { } while (0)
95907 #define STATS_INC_FREEHIT(x) do { } while (0)
95908 #define STATS_INC_FREEMISS(x) do { } while (0)
95909 +#define STATS_INC_SANITIZED(x) do { } while (0)
95910 +#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
95911 #endif
95912
95913 #if DEBUG
95914 @@ -447,7 +451,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct page *page,
95915 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
95916 */
95917 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
95918 - const struct page *page, void *obj)
95919 + const struct page *page, const void *obj)
95920 {
95921 u32 offset = (obj - page->s_mem);
95922 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
95923 @@ -1558,12 +1562,12 @@ void __init kmem_cache_init(void)
95924 */
95925
95926 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
95927 - kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
95928 + kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
95929
95930 if (INDEX_AC != INDEX_NODE)
95931 kmalloc_caches[INDEX_NODE] =
95932 create_kmalloc_cache("kmalloc-node",
95933 - kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
95934 + kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
95935
95936 slab_early_init = 0;
95937
95938 @@ -3525,6 +3529,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
95939 struct array_cache *ac = cpu_cache_get(cachep);
95940
95941 check_irq_off();
95942 +
95943 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
95944 + if (pax_sanitize_slab) {
95945 + if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
95946 + memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
95947 +
95948 + if (cachep->ctor)
95949 + cachep->ctor(objp);
95950 +
95951 + STATS_INC_SANITIZED(cachep);
95952 + } else
95953 + STATS_INC_NOT_SANITIZED(cachep);
95954 + }
95955 +#endif
95956 +
95957 kmemleak_free_recursive(objp, cachep->flags);
95958 objp = cache_free_debugcheck(cachep, objp, caller);
95959
95960 @@ -3748,6 +3767,7 @@ void kfree(const void *objp)
95961
95962 if (unlikely(ZERO_OR_NULL_PTR(objp)))
95963 return;
95964 + VM_BUG_ON(!virt_addr_valid(objp));
95965 local_irq_save(flags);
95966 kfree_debugcheck(objp);
95967 c = virt_to_cache(objp);
95968 @@ -4189,14 +4209,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
95969 }
95970 /* cpu stats */
95971 {
95972 - unsigned long allochit = atomic_read(&cachep->allochit);
95973 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
95974 - unsigned long freehit = atomic_read(&cachep->freehit);
95975 - unsigned long freemiss = atomic_read(&cachep->freemiss);
95976 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
95977 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
95978 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
95979 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
95980
95981 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
95982 allochit, allocmiss, freehit, freemiss);
95983 }
95984 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
95985 + {
95986 + unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
95987 + unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
95988 +
95989 + seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
95990 + }
95991 +#endif
95992 #endif
95993 }
95994
95995 @@ -4417,13 +4445,69 @@ static const struct file_operations proc_slabstats_operations = {
95996 static int __init slab_proc_init(void)
95997 {
95998 #ifdef CONFIG_DEBUG_SLAB_LEAK
95999 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
96000 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
96001 #endif
96002 return 0;
96003 }
96004 module_init(slab_proc_init);
96005 #endif
96006
96007 +bool is_usercopy_object(const void *ptr)
96008 +{
96009 + struct page *page;
96010 + struct kmem_cache *cachep;
96011 +
96012 + if (ZERO_OR_NULL_PTR(ptr))
96013 + return false;
96014 +
96015 + if (!slab_is_available())
96016 + return false;
96017 +
96018 + if (!virt_addr_valid(ptr))
96019 + return false;
96020 +
96021 + page = virt_to_head_page(ptr);
96022 +
96023 + if (!PageSlab(page))
96024 + return false;
96025 +
96026 + cachep = page->slab_cache;
96027 + return cachep->flags & SLAB_USERCOPY;
96028 +}
96029 +
96030 +#ifdef CONFIG_PAX_USERCOPY
96031 +const char *check_heap_object(const void *ptr, unsigned long n)
96032 +{
96033 + struct page *page;
96034 + struct kmem_cache *cachep;
96035 + unsigned int objnr;
96036 + unsigned long offset;
96037 +
96038 + if (ZERO_OR_NULL_PTR(ptr))
96039 + return "<null>";
96040 +
96041 + if (!virt_addr_valid(ptr))
96042 + return NULL;
96043 +
96044 + page = virt_to_head_page(ptr);
96045 +
96046 + if (!PageSlab(page))
96047 + return NULL;
96048 +
96049 + cachep = page->slab_cache;
96050 + if (!(cachep->flags & SLAB_USERCOPY))
96051 + return cachep->name;
96052 +
96053 + objnr = obj_to_index(cachep, page, ptr);
96054 + BUG_ON(objnr >= cachep->num);
96055 + offset = ptr - index_to_obj(cachep, page, objnr) - obj_offset(cachep);
96056 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
96057 + return NULL;
96058 +
96059 + return cachep->name;
96060 +}
96061 +#endif
96062 +
96063 /**
96064 * ksize - get the actual amount of memory allocated for a given object
96065 * @objp: Pointer to the object
96066 diff --git a/mm/slab.h b/mm/slab.h
96067 index 6bd4c35..97565a1 100644
96068 --- a/mm/slab.h
96069 +++ b/mm/slab.h
96070 @@ -32,6 +32,15 @@ extern struct list_head slab_caches;
96071 /* The slab cache that manages slab cache information */
96072 extern struct kmem_cache *kmem_cache;
96073
96074 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
96075 +#ifdef CONFIG_X86_64
96076 +#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
96077 +#else
96078 +#define PAX_MEMORY_SANITIZE_VALUE '\xff'
96079 +#endif
96080 +extern bool pax_sanitize_slab;
96081 +#endif
96082 +
96083 unsigned long calculate_alignment(unsigned long flags,
96084 unsigned long align, unsigned long size);
96085
96086 @@ -67,7 +76,8 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
96087
96088 /* Legal flag mask for kmem_cache_create(), for various configurations */
96089 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
96090 - SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
96091 + SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
96092 + SLAB_USERCOPY | SLAB_NO_SANITIZE)
96093
96094 #if defined(CONFIG_DEBUG_SLAB)
96095 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
96096 @@ -245,6 +255,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
96097 return s;
96098
96099 page = virt_to_head_page(x);
96100 +
96101 + BUG_ON(!PageSlab(page));
96102 +
96103 cachep = page->slab_cache;
96104 if (slab_equal_or_root(cachep, s))
96105 return cachep;
96106 diff --git a/mm/slab_common.c b/mm/slab_common.c
96107 index 102cc6f..c7aab3d 100644
96108 --- a/mm/slab_common.c
96109 +++ b/mm/slab_common.c
96110 @@ -23,11 +23,22 @@
96111
96112 #include "slab.h"
96113
96114 -enum slab_state slab_state;
96115 +enum slab_state slab_state __read_only;
96116 LIST_HEAD(slab_caches);
96117 DEFINE_MUTEX(slab_mutex);
96118 struct kmem_cache *kmem_cache;
96119
96120 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
96121 +bool pax_sanitize_slab __read_only = true;
96122 +static int __init pax_sanitize_slab_setup(char *str)
96123 +{
96124 + pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
96125 + printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
96126 + return 1;
96127 +}
96128 +__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
96129 +#endif
96130 +
96131 #ifdef CONFIG_DEBUG_VM
96132 static int kmem_cache_sanity_check(const char *name, size_t size)
96133 {
96134 @@ -158,7 +169,7 @@ do_kmem_cache_create(char *name, size_t object_size, size_t size, size_t align,
96135 if (err)
96136 goto out_free_cache;
96137
96138 - s->refcount = 1;
96139 + atomic_set(&s->refcount, 1);
96140 list_add(&s->list, &slab_caches);
96141 memcg_register_cache(s);
96142 out:
96143 @@ -334,8 +345,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
96144 get_online_cpus();
96145 mutex_lock(&slab_mutex);
96146
96147 - s->refcount--;
96148 - if (s->refcount)
96149 + if (!atomic_dec_and_test(&s->refcount))
96150 goto out_unlock;
96151
96152 if (kmem_cache_destroy_memcg_children(s) != 0)
96153 @@ -358,7 +368,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
96154 rcu_barrier();
96155
96156 memcg_free_cache_params(s);
96157 -#ifdef SLAB_SUPPORTS_SYSFS
96158 +#if defined(SLAB_SUPPORTS_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96159 sysfs_slab_remove(s);
96160 #else
96161 slab_kmem_cache_release(s);
96162 @@ -393,7 +403,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
96163 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
96164 name, size, err);
96165
96166 - s->refcount = -1; /* Exempt from merging for now */
96167 + atomic_set(&s->refcount, -1); /* Exempt from merging for now */
96168 }
96169
96170 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
96171 @@ -406,7 +416,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
96172
96173 create_boot_cache(s, name, size, flags);
96174 list_add(&s->list, &slab_caches);
96175 - s->refcount = 1;
96176 + atomic_set(&s->refcount, 1);
96177 return s;
96178 }
96179
96180 @@ -418,6 +428,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
96181 EXPORT_SYMBOL(kmalloc_dma_caches);
96182 #endif
96183
96184 +#ifdef CONFIG_PAX_USERCOPY_SLABS
96185 +struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
96186 +EXPORT_SYMBOL(kmalloc_usercopy_caches);
96187 +#endif
96188 +
96189 /*
96190 * Conversion table for small slabs sizes / 8 to the index in the
96191 * kmalloc array. This is necessary for slabs < 192 since we have non power
96192 @@ -482,6 +497,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
96193 return kmalloc_dma_caches[index];
96194
96195 #endif
96196 +
96197 +#ifdef CONFIG_PAX_USERCOPY_SLABS
96198 + if (unlikely((flags & GFP_USERCOPY)))
96199 + return kmalloc_usercopy_caches[index];
96200 +
96201 +#endif
96202 +
96203 return kmalloc_caches[index];
96204 }
96205
96206 @@ -538,7 +560,7 @@ void __init create_kmalloc_caches(unsigned long flags)
96207 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
96208 if (!kmalloc_caches[i]) {
96209 kmalloc_caches[i] = create_kmalloc_cache(NULL,
96210 - 1 << i, flags);
96211 + 1 << i, SLAB_USERCOPY | flags);
96212 }
96213
96214 /*
96215 @@ -547,10 +569,10 @@ void __init create_kmalloc_caches(unsigned long flags)
96216 * earlier power of two caches
96217 */
96218 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
96219 - kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
96220 + kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
96221
96222 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
96223 - kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
96224 + kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
96225 }
96226
96227 /* Kmalloc array is now usable */
96228 @@ -583,6 +605,23 @@ void __init create_kmalloc_caches(unsigned long flags)
96229 }
96230 }
96231 #endif
96232 +
96233 +#ifdef CONFIG_PAX_USERCOPY_SLABS
96234 + for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
96235 + struct kmem_cache *s = kmalloc_caches[i];
96236 +
96237 + if (s) {
96238 + int size = kmalloc_size(i);
96239 + char *n = kasprintf(GFP_NOWAIT,
96240 + "usercopy-kmalloc-%d", size);
96241 +
96242 + BUG_ON(!n);
96243 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
96244 + size, SLAB_USERCOPY | flags);
96245 + }
96246 + }
96247 +#endif
96248 +
96249 }
96250 #endif /* !CONFIG_SLOB */
96251
96252 @@ -623,6 +662,9 @@ void print_slabinfo_header(struct seq_file *m)
96253 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
96254 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
96255 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
96256 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
96257 + seq_puts(m, " : pax <sanitized> <not_sanitized>");
96258 +#endif
96259 #endif
96260 seq_putc(m, '\n');
96261 }
96262 diff --git a/mm/slob.c b/mm/slob.c
96263 index 730cad4..8cfd442 100644
96264 --- a/mm/slob.c
96265 +++ b/mm/slob.c
96266 @@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
96267 /*
96268 * Return the size of a slob block.
96269 */
96270 -static slobidx_t slob_units(slob_t *s)
96271 +static slobidx_t slob_units(const slob_t *s)
96272 {
96273 if (s->units > 0)
96274 return s->units;
96275 @@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
96276 /*
96277 * Return the next free slob block pointer after this one.
96278 */
96279 -static slob_t *slob_next(slob_t *s)
96280 +static slob_t *slob_next(const slob_t *s)
96281 {
96282 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
96283 slobidx_t next;
96284 @@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
96285 /*
96286 * Returns true if s is the last free block in its page.
96287 */
96288 -static int slob_last(slob_t *s)
96289 +static int slob_last(const slob_t *s)
96290 {
96291 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
96292 }
96293
96294 -static void *slob_new_pages(gfp_t gfp, int order, int node)
96295 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
96296 {
96297 - void *page;
96298 + struct page *page;
96299
96300 #ifdef CONFIG_NUMA
96301 if (node != NUMA_NO_NODE)
96302 @@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
96303 if (!page)
96304 return NULL;
96305
96306 - return page_address(page);
96307 + __SetPageSlab(page);
96308 + return page;
96309 }
96310
96311 -static void slob_free_pages(void *b, int order)
96312 +static void slob_free_pages(struct page *sp, int order)
96313 {
96314 if (current->reclaim_state)
96315 current->reclaim_state->reclaimed_slab += 1 << order;
96316 - free_pages((unsigned long)b, order);
96317 + __ClearPageSlab(sp);
96318 + page_mapcount_reset(sp);
96319 + sp->private = 0;
96320 + __free_pages(sp, order);
96321 }
96322
96323 /*
96324 @@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
96325
96326 /* Not enough space: must allocate a new page */
96327 if (!b) {
96328 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
96329 - if (!b)
96330 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
96331 + if (!sp)
96332 return NULL;
96333 - sp = virt_to_page(b);
96334 - __SetPageSlab(sp);
96335 + b = page_address(sp);
96336
96337 spin_lock_irqsave(&slob_lock, flags);
96338 sp->units = SLOB_UNITS(PAGE_SIZE);
96339 sp->freelist = b;
96340 + sp->private = 0;
96341 INIT_LIST_HEAD(&sp->lru);
96342 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
96343 set_slob_page_free(sp, slob_list);
96344 @@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
96345 if (slob_page_free(sp))
96346 clear_slob_page_free(sp);
96347 spin_unlock_irqrestore(&slob_lock, flags);
96348 - __ClearPageSlab(sp);
96349 - page_mapcount_reset(sp);
96350 - slob_free_pages(b, 0);
96351 + slob_free_pages(sp, 0);
96352 return;
96353 }
96354
96355 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
96356 + if (pax_sanitize_slab)
96357 + memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
96358 +#endif
96359 +
96360 if (!slob_page_free(sp)) {
96361 /* This slob page is about to become partially free. Easy! */
96362 sp->units = units;
96363 @@ -424,11 +431,10 @@ out:
96364 */
96365
96366 static __always_inline void *
96367 -__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
96368 +__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
96369 {
96370 - unsigned int *m;
96371 - int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96372 - void *ret;
96373 + slob_t *m;
96374 + void *ret = NULL;
96375
96376 gfp &= gfp_allowed_mask;
96377
96378 @@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
96379
96380 if (!m)
96381 return NULL;
96382 - *m = size;
96383 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
96384 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
96385 + m[0].units = size;
96386 + m[1].units = align;
96387 ret = (void *)m + align;
96388
96389 trace_kmalloc_node(caller, ret,
96390 size, size + align, gfp, node);
96391 } else {
96392 unsigned int order = get_order(size);
96393 + struct page *page;
96394
96395 if (likely(order))
96396 gfp |= __GFP_COMP;
96397 - ret = slob_new_pages(gfp, order, node);
96398 + page = slob_new_pages(gfp, order, node);
96399 + if (page) {
96400 + ret = page_address(page);
96401 + page->private = size;
96402 + }
96403
96404 trace_kmalloc_node(caller, ret,
96405 size, PAGE_SIZE << order, gfp, node);
96406 }
96407
96408 - kmemleak_alloc(ret, size, 1, gfp);
96409 + return ret;
96410 +}
96411 +
96412 +static __always_inline void *
96413 +__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
96414 +{
96415 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96416 + void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
96417 +
96418 + if (!ZERO_OR_NULL_PTR(ret))
96419 + kmemleak_alloc(ret, size, 1, gfp);
96420 return ret;
96421 }
96422
96423 @@ -493,34 +517,112 @@ void kfree(const void *block)
96424 return;
96425 kmemleak_free(block);
96426
96427 + VM_BUG_ON(!virt_addr_valid(block));
96428 sp = virt_to_page(block);
96429 - if (PageSlab(sp)) {
96430 + VM_BUG_ON(!PageSlab(sp));
96431 + if (!sp->private) {
96432 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96433 - unsigned int *m = (unsigned int *)(block - align);
96434 - slob_free(m, *m + align);
96435 - } else
96436 + slob_t *m = (slob_t *)(block - align);
96437 + slob_free(m, m[0].units + align);
96438 + } else {
96439 + __ClearPageSlab(sp);
96440 + page_mapcount_reset(sp);
96441 + sp->private = 0;
96442 __free_pages(sp, compound_order(sp));
96443 + }
96444 }
96445 EXPORT_SYMBOL(kfree);
96446
96447 +bool is_usercopy_object(const void *ptr)
96448 +{
96449 + if (!slab_is_available())
96450 + return false;
96451 +
96452 + // PAX: TODO
96453 +
96454 + return false;
96455 +}
96456 +
96457 +#ifdef CONFIG_PAX_USERCOPY
96458 +const char *check_heap_object(const void *ptr, unsigned long n)
96459 +{
96460 + struct page *page;
96461 + const slob_t *free;
96462 + const void *base;
96463 + unsigned long flags;
96464 +
96465 + if (ZERO_OR_NULL_PTR(ptr))
96466 + return "<null>";
96467 +
96468 + if (!virt_addr_valid(ptr))
96469 + return NULL;
96470 +
96471 + page = virt_to_head_page(ptr);
96472 + if (!PageSlab(page))
96473 + return NULL;
96474 +
96475 + if (page->private) {
96476 + base = page;
96477 + if (base <= ptr && n <= page->private - (ptr - base))
96478 + return NULL;
96479 + return "<slob>";
96480 + }
96481 +
96482 + /* some tricky double walking to find the chunk */
96483 + spin_lock_irqsave(&slob_lock, flags);
96484 + base = (void *)((unsigned long)ptr & PAGE_MASK);
96485 + free = page->freelist;
96486 +
96487 + while (!slob_last(free) && (void *)free <= ptr) {
96488 + base = free + slob_units(free);
96489 + free = slob_next(free);
96490 + }
96491 +
96492 + while (base < (void *)free) {
96493 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
96494 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
96495 + int offset;
96496 +
96497 + if (ptr < base + align)
96498 + break;
96499 +
96500 + offset = ptr - base - align;
96501 + if (offset >= m) {
96502 + base += size;
96503 + continue;
96504 + }
96505 +
96506 + if (n > m - offset)
96507 + break;
96508 +
96509 + spin_unlock_irqrestore(&slob_lock, flags);
96510 + return NULL;
96511 + }
96512 +
96513 + spin_unlock_irqrestore(&slob_lock, flags);
96514 + return "<slob>";
96515 +}
96516 +#endif
96517 +
96518 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
96519 size_t ksize(const void *block)
96520 {
96521 struct page *sp;
96522 int align;
96523 - unsigned int *m;
96524 + slob_t *m;
96525
96526 BUG_ON(!block);
96527 if (unlikely(block == ZERO_SIZE_PTR))
96528 return 0;
96529
96530 sp = virt_to_page(block);
96531 - if (unlikely(!PageSlab(sp)))
96532 - return PAGE_SIZE << compound_order(sp);
96533 + VM_BUG_ON(!PageSlab(sp));
96534 + if (sp->private)
96535 + return sp->private;
96536
96537 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
96538 - m = (unsigned int *)(block - align);
96539 - return SLOB_UNITS(*m) * SLOB_UNIT;
96540 + m = (slob_t *)(block - align);
96541 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
96542 }
96543 EXPORT_SYMBOL(ksize);
96544
96545 @@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
96546
96547 void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
96548 {
96549 - void *b;
96550 + void *b = NULL;
96551
96552 flags &= gfp_allowed_mask;
96553
96554 lockdep_trace_alloc(flags);
96555
96556 +#ifdef CONFIG_PAX_USERCOPY_SLABS
96557 + b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
96558 +#else
96559 if (c->size < PAGE_SIZE) {
96560 b = slob_alloc(c->size, flags, c->align, node);
96561 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
96562 SLOB_UNITS(c->size) * SLOB_UNIT,
96563 flags, node);
96564 } else {
96565 - b = slob_new_pages(flags, get_order(c->size), node);
96566 + struct page *sp;
96567 +
96568 + sp = slob_new_pages(flags, get_order(c->size), node);
96569 + if (sp) {
96570 + b = page_address(sp);
96571 + sp->private = c->size;
96572 + }
96573 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
96574 PAGE_SIZE << get_order(c->size),
96575 flags, node);
96576 }
96577 +#endif
96578
96579 if (b && c->ctor)
96580 c->ctor(b);
96581 @@ -584,10 +696,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
96582
96583 static void __kmem_cache_free(void *b, int size)
96584 {
96585 - if (size < PAGE_SIZE)
96586 + struct page *sp;
96587 +
96588 + sp = virt_to_page(b);
96589 + BUG_ON(!PageSlab(sp));
96590 + if (!sp->private)
96591 slob_free(b, size);
96592 else
96593 - slob_free_pages(b, get_order(size));
96594 + slob_free_pages(sp, get_order(size));
96595 }
96596
96597 static void kmem_rcu_free(struct rcu_head *head)
96598 @@ -600,17 +716,31 @@ static void kmem_rcu_free(struct rcu_head *head)
96599
96600 void kmem_cache_free(struct kmem_cache *c, void *b)
96601 {
96602 + int size = c->size;
96603 +
96604 +#ifdef CONFIG_PAX_USERCOPY_SLABS
96605 + if (size + c->align < PAGE_SIZE) {
96606 + size += c->align;
96607 + b -= c->align;
96608 + }
96609 +#endif
96610 +
96611 kmemleak_free_recursive(b, c->flags);
96612 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
96613 struct slob_rcu *slob_rcu;
96614 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
96615 - slob_rcu->size = c->size;
96616 + slob_rcu = b + (size - sizeof(struct slob_rcu));
96617 + slob_rcu->size = size;
96618 call_rcu(&slob_rcu->head, kmem_rcu_free);
96619 } else {
96620 - __kmem_cache_free(b, c->size);
96621 + __kmem_cache_free(b, size);
96622 }
96623
96624 +#ifdef CONFIG_PAX_USERCOPY_SLABS
96625 + trace_kfree(_RET_IP_, b);
96626 +#else
96627 trace_kmem_cache_free(_RET_IP_, b);
96628 +#endif
96629 +
96630 }
96631 EXPORT_SYMBOL(kmem_cache_free);
96632
96633 diff --git a/mm/slub.c b/mm/slub.c
96634 index 2b1ce69..4a2193f 100644
96635 --- a/mm/slub.c
96636 +++ b/mm/slub.c
96637 @@ -207,7 +207,7 @@ struct track {
96638
96639 enum track_item { TRACK_ALLOC, TRACK_FREE };
96640
96641 -#ifdef CONFIG_SYSFS
96642 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96643 static int sysfs_slab_add(struct kmem_cache *);
96644 static int sysfs_slab_alias(struct kmem_cache *, const char *);
96645 static void memcg_propagate_slab_attrs(struct kmem_cache *s);
96646 @@ -546,7 +546,7 @@ static void print_track(const char *s, struct track *t)
96647 if (!t->addr)
96648 return;
96649
96650 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
96651 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
96652 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
96653 #ifdef CONFIG_STACKTRACE
96654 {
96655 @@ -2666,6 +2666,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
96656
96657 slab_free_hook(s, x);
96658
96659 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
96660 + if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
96661 + memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
96662 + if (s->ctor)
96663 + s->ctor(x);
96664 + }
96665 +#endif
96666 +
96667 redo:
96668 /*
96669 * Determine the currently cpus per cpu slab.
96670 @@ -2733,7 +2741,7 @@ static int slub_min_objects;
96671 * Merge control. If this is set then no merging of slab caches will occur.
96672 * (Could be removed. This was introduced to pacify the merge skeptics.)
96673 */
96674 -static int slub_nomerge;
96675 +static int slub_nomerge = 1;
96676
96677 /*
96678 * Calculate the order of allocation given an slab object size.
96679 @@ -3014,6 +3022,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
96680 s->inuse = size;
96681
96682 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
96683 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
96684 + (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
96685 +#endif
96686 s->ctor)) {
96687 /*
96688 * Relocate free pointer after the object if it is not
96689 @@ -3343,6 +3354,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
96690 EXPORT_SYMBOL(__kmalloc_node);
96691 #endif
96692
96693 +bool is_usercopy_object(const void *ptr)
96694 +{
96695 + struct page *page;
96696 + struct kmem_cache *s;
96697 +
96698 + if (ZERO_OR_NULL_PTR(ptr))
96699 + return false;
96700 +
96701 + if (!slab_is_available())
96702 + return false;
96703 +
96704 + if (!virt_addr_valid(ptr))
96705 + return false;
96706 +
96707 + page = virt_to_head_page(ptr);
96708 +
96709 + if (!PageSlab(page))
96710 + return false;
96711 +
96712 + s = page->slab_cache;
96713 + return s->flags & SLAB_USERCOPY;
96714 +}
96715 +
96716 +#ifdef CONFIG_PAX_USERCOPY
96717 +const char *check_heap_object(const void *ptr, unsigned long n)
96718 +{
96719 + struct page *page;
96720 + struct kmem_cache *s;
96721 + unsigned long offset;
96722 +
96723 + if (ZERO_OR_NULL_PTR(ptr))
96724 + return "<null>";
96725 +
96726 + if (!virt_addr_valid(ptr))
96727 + return NULL;
96728 +
96729 + page = virt_to_head_page(ptr);
96730 +
96731 + if (!PageSlab(page))
96732 + return NULL;
96733 +
96734 + s = page->slab_cache;
96735 + if (!(s->flags & SLAB_USERCOPY))
96736 + return s->name;
96737 +
96738 + offset = (ptr - page_address(page)) % s->size;
96739 + if (offset <= s->object_size && n <= s->object_size - offset)
96740 + return NULL;
96741 +
96742 + return s->name;
96743 +}
96744 +#endif
96745 +
96746 size_t ksize(const void *object)
96747 {
96748 struct page *page;
96749 @@ -3371,6 +3435,7 @@ void kfree(const void *x)
96750 if (unlikely(ZERO_OR_NULL_PTR(x)))
96751 return;
96752
96753 + VM_BUG_ON(!virt_addr_valid(x));
96754 page = virt_to_head_page(x);
96755 if (unlikely(!PageSlab(page))) {
96756 BUG_ON(!PageCompound(page));
96757 @@ -3679,7 +3744,7 @@ static int slab_unmergeable(struct kmem_cache *s)
96758 /*
96759 * We may have set a slab to be unmergeable during bootstrap.
96760 */
96761 - if (s->refcount < 0)
96762 + if (atomic_read(&s->refcount) < 0)
96763 return 1;
96764
96765 return 0;
96766 @@ -3736,7 +3801,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
96767 int i;
96768 struct kmem_cache *c;
96769
96770 - s->refcount++;
96771 + atomic_inc(&s->refcount);
96772
96773 /*
96774 * Adjust the object sizes so that we clear
96775 @@ -3755,7 +3820,7 @@ __kmem_cache_alias(const char *name, size_t size, size_t align,
96776 }
96777
96778 if (sysfs_slab_alias(s, name)) {
96779 - s->refcount--;
96780 + atomic_dec(&s->refcount);
96781 s = NULL;
96782 }
96783 }
96784 @@ -3872,7 +3937,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
96785 }
96786 #endif
96787
96788 -#ifdef CONFIG_SYSFS
96789 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96790 static int count_inuse(struct page *page)
96791 {
96792 return page->inuse;
96793 @@ -4156,7 +4221,11 @@ static int list_locations(struct kmem_cache *s, char *buf,
96794 len += sprintf(buf + len, "%7ld ", l->count);
96795
96796 if (l->addr)
96797 +#ifdef CONFIG_GRKERNSEC_HIDESYM
96798 + len += sprintf(buf + len, "%pS", NULL);
96799 +#else
96800 len += sprintf(buf + len, "%pS", (void *)l->addr);
96801 +#endif
96802 else
96803 len += sprintf(buf + len, "<not-available>");
96804
96805 @@ -4261,12 +4330,12 @@ static void resiliency_test(void)
96806 validate_slab_cache(kmalloc_caches[9]);
96807 }
96808 #else
96809 -#ifdef CONFIG_SYSFS
96810 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96811 static void resiliency_test(void) {};
96812 #endif
96813 #endif
96814
96815 -#ifdef CONFIG_SYSFS
96816 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96817 enum slab_stat_type {
96818 SL_ALL, /* All slabs */
96819 SL_PARTIAL, /* Only partially allocated slabs */
96820 @@ -4506,13 +4575,17 @@ static ssize_t ctor_show(struct kmem_cache *s, char *buf)
96821 {
96822 if (!s->ctor)
96823 return 0;
96824 +#ifdef CONFIG_GRKERNSEC_HIDESYM
96825 + return sprintf(buf, "%pS\n", NULL);
96826 +#else
96827 return sprintf(buf, "%pS\n", s->ctor);
96828 +#endif
96829 }
96830 SLAB_ATTR_RO(ctor);
96831
96832 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
96833 {
96834 - return sprintf(buf, "%d\n", s->refcount - 1);
96835 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
96836 }
96837 SLAB_ATTR_RO(aliases);
96838
96839 @@ -4600,6 +4673,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
96840 SLAB_ATTR_RO(cache_dma);
96841 #endif
96842
96843 +#ifdef CONFIG_PAX_USERCOPY_SLABS
96844 +static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
96845 +{
96846 + return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
96847 +}
96848 +SLAB_ATTR_RO(usercopy);
96849 +#endif
96850 +
96851 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
96852 {
96853 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
96854 @@ -4934,6 +5015,9 @@ static struct attribute *slab_attrs[] = {
96855 #ifdef CONFIG_ZONE_DMA
96856 &cache_dma_attr.attr,
96857 #endif
96858 +#ifdef CONFIG_PAX_USERCOPY_SLABS
96859 + &usercopy_attr.attr,
96860 +#endif
96861 #ifdef CONFIG_NUMA
96862 &remote_node_defrag_ratio_attr.attr,
96863 #endif
96864 @@ -5184,6 +5268,7 @@ static char *create_unique_id(struct kmem_cache *s)
96865 return name;
96866 }
96867
96868 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96869 static int sysfs_slab_add(struct kmem_cache *s)
96870 {
96871 int err;
96872 @@ -5257,6 +5342,7 @@ void sysfs_slab_remove(struct kmem_cache *s)
96873 kobject_del(&s->kobj);
96874 kobject_put(&s->kobj);
96875 }
96876 +#endif
96877
96878 /*
96879 * Need to buffer aliases during bootup until sysfs becomes
96880 @@ -5270,6 +5356,7 @@ struct saved_alias {
96881
96882 static struct saved_alias *alias_list;
96883
96884 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
96885 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
96886 {
96887 struct saved_alias *al;
96888 @@ -5292,6 +5379,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
96889 alias_list = al;
96890 return 0;
96891 }
96892 +#endif
96893
96894 static int __init slab_sysfs_init(void)
96895 {
96896 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
96897 index 4cba9c2..b4f9fcc 100644
96898 --- a/mm/sparse-vmemmap.c
96899 +++ b/mm/sparse-vmemmap.c
96900 @@ -131,7 +131,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
96901 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
96902 if (!p)
96903 return NULL;
96904 - pud_populate(&init_mm, pud, p);
96905 + pud_populate_kernel(&init_mm, pud, p);
96906 }
96907 return pud;
96908 }
96909 @@ -143,7 +143,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
96910 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
96911 if (!p)
96912 return NULL;
96913 - pgd_populate(&init_mm, pgd, p);
96914 + pgd_populate_kernel(&init_mm, pgd, p);
96915 }
96916 return pgd;
96917 }
96918 diff --git a/mm/sparse.c b/mm/sparse.c
96919 index d1b48b6..6e8590e 100644
96920 --- a/mm/sparse.c
96921 +++ b/mm/sparse.c
96922 @@ -750,7 +750,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
96923
96924 for (i = 0; i < PAGES_PER_SECTION; i++) {
96925 if (PageHWPoison(&memmap[i])) {
96926 - atomic_long_sub(1, &num_poisoned_pages);
96927 + atomic_long_sub_unchecked(1, &num_poisoned_pages);
96928 ClearPageHWPoison(&memmap[i]);
96929 }
96930 }
96931 diff --git a/mm/swap.c b/mm/swap.c
96932 index 9ce43ba..43bdc4c 100644
96933 --- a/mm/swap.c
96934 +++ b/mm/swap.c
96935 @@ -31,6 +31,7 @@
96936 #include <linux/memcontrol.h>
96937 #include <linux/gfp.h>
96938 #include <linux/uio.h>
96939 +#include <linux/hugetlb.h>
96940
96941 #include "internal.h"
96942
96943 @@ -76,6 +77,8 @@ static void __put_compound_page(struct page *page)
96944
96945 __page_cache_release(page);
96946 dtor = get_compound_page_dtor(page);
96947 + if (!PageHuge(page))
96948 + BUG_ON(dtor != free_compound_page);
96949 (*dtor)(page);
96950 }
96951
96952 diff --git a/mm/swapfile.c b/mm/swapfile.c
96953 index 4a7f7e6..22cddf5 100644
96954 --- a/mm/swapfile.c
96955 +++ b/mm/swapfile.c
96956 @@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
96957
96958 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
96959 /* Activity counter to indicate that a swapon or swapoff has occurred */
96960 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
96961 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
96962
96963 static inline unsigned char swap_count(unsigned char ent)
96964 {
96965 @@ -1959,7 +1959,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
96966 spin_unlock(&swap_lock);
96967
96968 err = 0;
96969 - atomic_inc(&proc_poll_event);
96970 + atomic_inc_unchecked(&proc_poll_event);
96971 wake_up_interruptible(&proc_poll_wait);
96972
96973 out_dput:
96974 @@ -1976,8 +1976,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
96975
96976 poll_wait(file, &proc_poll_wait, wait);
96977
96978 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
96979 - seq->poll_event = atomic_read(&proc_poll_event);
96980 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
96981 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
96982 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
96983 }
96984
96985 @@ -2075,7 +2075,7 @@ static int swaps_open(struct inode *inode, struct file *file)
96986 return ret;
96987
96988 seq = file->private_data;
96989 - seq->poll_event = atomic_read(&proc_poll_event);
96990 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
96991 return 0;
96992 }
96993
96994 @@ -2534,7 +2534,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
96995 (frontswap_map) ? "FS" : "");
96996
96997 mutex_unlock(&swapon_mutex);
96998 - atomic_inc(&proc_poll_event);
96999 + atomic_inc_unchecked(&proc_poll_event);
97000 wake_up_interruptible(&proc_poll_wait);
97001
97002 if (S_ISREG(inode->i_mode))
97003 diff --git a/mm/util.c b/mm/util.c
97004 index d5ea733..e8953f9 100644
97005 --- a/mm/util.c
97006 +++ b/mm/util.c
97007 @@ -299,6 +299,12 @@ done:
97008 void arch_pick_mmap_layout(struct mm_struct *mm)
97009 {
97010 mm->mmap_base = TASK_UNMAPPED_BASE;
97011 +
97012 +#ifdef CONFIG_PAX_RANDMMAP
97013 + if (mm->pax_flags & MF_PAX_RANDMMAP)
97014 + mm->mmap_base += mm->delta_mmap;
97015 +#endif
97016 +
97017 mm->get_unmapped_area = arch_get_unmapped_area;
97018 }
97019 #endif
97020 @@ -475,6 +481,9 @@ int get_cmdline(struct task_struct *task, char *buffer, int buflen)
97021 if (!mm->arg_end)
97022 goto out_mm; /* Shh! No looking before we're done */
97023
97024 + if (gr_acl_handle_procpidmem(task))
97025 + goto out_mm;
97026 +
97027 len = mm->arg_end - mm->arg_start;
97028
97029 if (len > buflen)
97030 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
97031 index bf233b2..1dfa1bc 100644
97032 --- a/mm/vmalloc.c
97033 +++ b/mm/vmalloc.c
97034 @@ -40,6 +40,21 @@ struct vfree_deferred {
97035 };
97036 static DEFINE_PER_CPU(struct vfree_deferred, vfree_deferred);
97037
97038 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
97039 +struct stack_deferred_llist {
97040 + struct llist_head list;
97041 + void *stack;
97042 + void *lowmem_stack;
97043 +};
97044 +
97045 +struct stack_deferred {
97046 + struct stack_deferred_llist list;
97047 + struct work_struct wq;
97048 +};
97049 +
97050 +static DEFINE_PER_CPU(struct stack_deferred, stack_deferred);
97051 +#endif
97052 +
97053 static void __vunmap(const void *, int);
97054
97055 static void free_work(struct work_struct *w)
97056 @@ -47,12 +62,30 @@ static void free_work(struct work_struct *w)
97057 struct vfree_deferred *p = container_of(w, struct vfree_deferred, wq);
97058 struct llist_node *llnode = llist_del_all(&p->list);
97059 while (llnode) {
97060 - void *p = llnode;
97061 + void *x = llnode;
97062 llnode = llist_next(llnode);
97063 - __vunmap(p, 1);
97064 + __vunmap(x, 1);
97065 }
97066 }
97067
97068 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
97069 +static void unmap_work(struct work_struct *w)
97070 +{
97071 + struct stack_deferred *p = container_of(w, struct stack_deferred, wq);
97072 + struct llist_node *llnode = llist_del_all(&p->list.list);
97073 + while (llnode) {
97074 + struct stack_deferred_llist *x =
97075 + llist_entry((struct llist_head *)llnode,
97076 + struct stack_deferred_llist, list);
97077 + void *stack = ACCESS_ONCE(x->stack);
97078 + void *lowmem_stack = ACCESS_ONCE(x->lowmem_stack);
97079 + llnode = llist_next(llnode);
97080 + __vunmap(stack, 0);
97081 + free_memcg_kmem_pages((unsigned long)lowmem_stack, THREAD_SIZE_ORDER);
97082 + }
97083 +}
97084 +#endif
97085 +
97086 /*** Page table manipulation functions ***/
97087
97088 static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
97089 @@ -61,8 +94,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
97090
97091 pte = pte_offset_kernel(pmd, addr);
97092 do {
97093 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
97094 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
97095 +
97096 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
97097 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
97098 + BUG_ON(!pte_exec(*pte));
97099 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
97100 + continue;
97101 + }
97102 +#endif
97103 +
97104 + {
97105 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
97106 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
97107 + }
97108 } while (pte++, addr += PAGE_SIZE, addr != end);
97109 }
97110
97111 @@ -122,16 +166,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
97112 pte = pte_alloc_kernel(pmd, addr);
97113 if (!pte)
97114 return -ENOMEM;
97115 +
97116 + pax_open_kernel();
97117 do {
97118 struct page *page = pages[*nr];
97119
97120 - if (WARN_ON(!pte_none(*pte)))
97121 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
97122 + if (pgprot_val(prot) & _PAGE_NX)
97123 +#endif
97124 +
97125 + if (!pte_none(*pte)) {
97126 + pax_close_kernel();
97127 + WARN_ON(1);
97128 return -EBUSY;
97129 - if (WARN_ON(!page))
97130 + }
97131 + if (!page) {
97132 + pax_close_kernel();
97133 + WARN_ON(1);
97134 return -ENOMEM;
97135 + }
97136 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
97137 (*nr)++;
97138 } while (pte++, addr += PAGE_SIZE, addr != end);
97139 + pax_close_kernel();
97140 return 0;
97141 }
97142
97143 @@ -141,7 +198,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
97144 pmd_t *pmd;
97145 unsigned long next;
97146
97147 - pmd = pmd_alloc(&init_mm, pud, addr);
97148 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
97149 if (!pmd)
97150 return -ENOMEM;
97151 do {
97152 @@ -158,7 +215,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
97153 pud_t *pud;
97154 unsigned long next;
97155
97156 - pud = pud_alloc(&init_mm, pgd, addr);
97157 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
97158 if (!pud)
97159 return -ENOMEM;
97160 do {
97161 @@ -218,6 +275,12 @@ int is_vmalloc_or_module_addr(const void *x)
97162 if (addr >= MODULES_VADDR && addr < MODULES_END)
97163 return 1;
97164 #endif
97165 +
97166 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
97167 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
97168 + return 1;
97169 +#endif
97170 +
97171 return is_vmalloc_addr(x);
97172 }
97173
97174 @@ -238,8 +301,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
97175
97176 if (!pgd_none(*pgd)) {
97177 pud_t *pud = pud_offset(pgd, addr);
97178 +#ifdef CONFIG_X86
97179 + if (!pud_large(*pud))
97180 +#endif
97181 if (!pud_none(*pud)) {
97182 pmd_t *pmd = pmd_offset(pud, addr);
97183 +#ifdef CONFIG_X86
97184 + if (!pmd_large(*pmd))
97185 +#endif
97186 if (!pmd_none(*pmd)) {
97187 pte_t *ptep, pte;
97188
97189 @@ -1183,13 +1252,23 @@ void __init vmalloc_init(void)
97190 for_each_possible_cpu(i) {
97191 struct vmap_block_queue *vbq;
97192 struct vfree_deferred *p;
97193 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
97194 + struct stack_deferred *p2;
97195 +#endif
97196
97197 vbq = &per_cpu(vmap_block_queue, i);
97198 spin_lock_init(&vbq->lock);
97199 INIT_LIST_HEAD(&vbq->free);
97200 +
97201 p = &per_cpu(vfree_deferred, i);
97202 init_llist_head(&p->list);
97203 INIT_WORK(&p->wq, free_work);
97204 +
97205 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
97206 + p2 = &per_cpu(stack_deferred, i);
97207 + init_llist_head(&p2->list.list);
97208 + INIT_WORK(&p2->wq, unmap_work);
97209 +#endif
97210 }
97211
97212 /* Import existing vmlist entries. */
97213 @@ -1317,6 +1396,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
97214 struct vm_struct *area;
97215
97216 BUG_ON(in_interrupt());
97217 +
97218 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
97219 + if (flags & VM_KERNEXEC) {
97220 + if (start != VMALLOC_START || end != VMALLOC_END)
97221 + return NULL;
97222 + start = (unsigned long)MODULES_EXEC_VADDR;
97223 + end = (unsigned long)MODULES_EXEC_END;
97224 + }
97225 +#endif
97226 +
97227 if (flags & VM_IOREMAP)
97228 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
97229
97230 @@ -1522,6 +1611,23 @@ void vunmap(const void *addr)
97231 }
97232 EXPORT_SYMBOL(vunmap);
97233
97234 +#ifdef CONFIG_GRKERNSEC_KSTACKOVERFLOW
97235 +void unmap_process_stacks(struct task_struct *task)
97236 +{
97237 + if (unlikely(in_interrupt())) {
97238 + struct stack_deferred *p = &__get_cpu_var(stack_deferred);
97239 + struct stack_deferred_llist *list = task->stack;
97240 + list->stack = task->stack;
97241 + list->lowmem_stack = task->lowmem_stack;
97242 + if (llist_add((struct llist_node *)&list->list, &p->list.list))
97243 + schedule_work(&p->wq);
97244 + } else {
97245 + __vunmap(task->stack, 0);
97246 + free_memcg_kmem_pages((unsigned long)task->lowmem_stack, THREAD_SIZE_ORDER);
97247 + }
97248 +}
97249 +#endif
97250 +
97251 /**
97252 * vmap - map an array of pages into virtually contiguous space
97253 * @pages: array of page pointers
97254 @@ -1542,6 +1648,11 @@ void *vmap(struct page **pages, unsigned int count,
97255 if (count > totalram_pages)
97256 return NULL;
97257
97258 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
97259 + if (!(pgprot_val(prot) & _PAGE_NX))
97260 + flags |= VM_KERNEXEC;
97261 +#endif
97262 +
97263 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
97264 __builtin_return_address(0));
97265 if (!area)
97266 @@ -1642,6 +1753,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
97267 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
97268 goto fail;
97269
97270 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
97271 + if (!(pgprot_val(prot) & _PAGE_NX))
97272 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
97273 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
97274 + else
97275 +#endif
97276 +
97277 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
97278 start, end, node, gfp_mask, caller);
97279 if (!area)
97280 @@ -1818,10 +1936,9 @@ EXPORT_SYMBOL(vzalloc_node);
97281 * For tight control over page level allocator and protection flags
97282 * use __vmalloc() instead.
97283 */
97284 -
97285 void *vmalloc_exec(unsigned long size)
97286 {
97287 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
97288 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
97289 NUMA_NO_NODE, __builtin_return_address(0));
97290 }
97291
97292 @@ -2128,6 +2245,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
97293 {
97294 struct vm_struct *area;
97295
97296 + BUG_ON(vma->vm_mirror);
97297 +
97298 size = PAGE_ALIGN(size);
97299
97300 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
97301 @@ -2610,7 +2729,11 @@ static int s_show(struct seq_file *m, void *p)
97302 v->addr, v->addr + v->size, v->size);
97303
97304 if (v->caller)
97305 +#ifdef CONFIG_GRKERNSEC_HIDESYM
97306 + seq_printf(m, " %pK", v->caller);
97307 +#else
97308 seq_printf(m, " %pS", v->caller);
97309 +#endif
97310
97311 if (v->nr_pages)
97312 seq_printf(m, " pages=%d", v->nr_pages);
97313 diff --git a/mm/vmstat.c b/mm/vmstat.c
97314 index 302dd07..3841f1c 100644
97315 --- a/mm/vmstat.c
97316 +++ b/mm/vmstat.c
97317 @@ -20,6 +20,7 @@
97318 #include <linux/writeback.h>
97319 #include <linux/compaction.h>
97320 #include <linux/mm_inline.h>
97321 +#include <linux/grsecurity.h>
97322
97323 #include "internal.h"
97324
97325 @@ -79,7 +80,7 @@ void vm_events_fold_cpu(int cpu)
97326 *
97327 * vm_stat contains the global counters
97328 */
97329 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
97330 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
97331 EXPORT_SYMBOL(vm_stat);
97332
97333 #ifdef CONFIG_SMP
97334 @@ -423,7 +424,7 @@ static inline void fold_diff(int *diff)
97335
97336 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
97337 if (diff[i])
97338 - atomic_long_add(diff[i], &vm_stat[i]);
97339 + atomic_long_add_unchecked(diff[i], &vm_stat[i]);
97340 }
97341
97342 /*
97343 @@ -455,7 +456,7 @@ static void refresh_cpu_vm_stats(void)
97344 v = this_cpu_xchg(p->vm_stat_diff[i], 0);
97345 if (v) {
97346
97347 - atomic_long_add(v, &zone->vm_stat[i]);
97348 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
97349 global_diff[i] += v;
97350 #ifdef CONFIG_NUMA
97351 /* 3 seconds idle till flush */
97352 @@ -517,7 +518,7 @@ void cpu_vm_stats_fold(int cpu)
97353
97354 v = p->vm_stat_diff[i];
97355 p->vm_stat_diff[i] = 0;
97356 - atomic_long_add(v, &zone->vm_stat[i]);
97357 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
97358 global_diff[i] += v;
97359 }
97360 }
97361 @@ -537,8 +538,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
97362 if (pset->vm_stat_diff[i]) {
97363 int v = pset->vm_stat_diff[i];
97364 pset->vm_stat_diff[i] = 0;
97365 - atomic_long_add(v, &zone->vm_stat[i]);
97366 - atomic_long_add(v, &vm_stat[i]);
97367 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
97368 + atomic_long_add_unchecked(v, &vm_stat[i]);
97369 }
97370 }
97371 #endif
97372 @@ -1156,10 +1157,22 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos)
97373 stat_items_size += sizeof(struct vm_event_state);
97374 #endif
97375
97376 - v = kmalloc(stat_items_size, GFP_KERNEL);
97377 + v = kzalloc(stat_items_size, GFP_KERNEL);
97378 m->private = v;
97379 if (!v)
97380 return ERR_PTR(-ENOMEM);
97381 +
97382 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
97383 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
97384 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
97385 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
97386 + && !in_group_p(grsec_proc_gid)
97387 +#endif
97388 + )
97389 + return (unsigned long *)m->private + *pos;
97390 +#endif
97391 +#endif
97392 +
97393 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
97394 v[i] = global_page_state(i);
97395 v += NR_VM_ZONE_STAT_ITEMS;
97396 @@ -1308,10 +1321,16 @@ static int __init setup_vmstat(void)
97397 cpu_notifier_register_done();
97398 #endif
97399 #ifdef CONFIG_PROC_FS
97400 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
97401 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
97402 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
97403 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
97404 + {
97405 + mode_t gr_mode = S_IRUGO;
97406 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
97407 + gr_mode = S_IRUSR;
97408 +#endif
97409 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
97410 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
97411 + proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
97412 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
97413 + }
97414 #endif
97415 return 0;
97416 }
97417 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
97418 index 44ebd5c..1f732bae 100644
97419 --- a/net/8021q/vlan.c
97420 +++ b/net/8021q/vlan.c
97421 @@ -475,7 +475,7 @@ out:
97422 return NOTIFY_DONE;
97423 }
97424
97425 -static struct notifier_block vlan_notifier_block __read_mostly = {
97426 +static struct notifier_block vlan_notifier_block = {
97427 .notifier_call = vlan_device_event,
97428 };
97429
97430 @@ -550,8 +550,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
97431 err = -EPERM;
97432 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
97433 break;
97434 - if ((args.u.name_type >= 0) &&
97435 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
97436 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
97437 struct vlan_net *vn;
97438
97439 vn = net_generic(net, vlan_net_id);
97440 diff --git a/net/9p/client.c b/net/9p/client.c
97441 index 0004cba..feba240 100644
97442 --- a/net/9p/client.c
97443 +++ b/net/9p/client.c
97444 @@ -596,7 +596,7 @@ static int p9_check_zc_errors(struct p9_client *c, struct p9_req_t *req,
97445 len - inline_len);
97446 } else {
97447 err = copy_from_user(ename + inline_len,
97448 - uidata, len - inline_len);
97449 + (char __force_user *)uidata, len - inline_len);
97450 if (err) {
97451 err = -EFAULT;
97452 goto out_err;
97453 @@ -1571,7 +1571,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
97454 kernel_buf = 1;
97455 indata = data;
97456 } else
97457 - indata = (__force char *)udata;
97458 + indata = (__force_kernel char *)udata;
97459 /*
97460 * response header len is 11
97461 * PDU Header(7) + IO Size (4)
97462 @@ -1646,7 +1646,7 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
97463 kernel_buf = 1;
97464 odata = data;
97465 } else
97466 - odata = (char *)udata;
97467 + odata = (char __force_kernel *)udata;
97468 req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, odata, 0, rsize,
97469 P9_ZC_HDR_SZ, kernel_buf, "dqd",
97470 fid->fid, offset, rsize);
97471 diff --git a/net/9p/mod.c b/net/9p/mod.c
97472 index 6ab36ae..6f1841b 100644
97473 --- a/net/9p/mod.c
97474 +++ b/net/9p/mod.c
97475 @@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
97476 void v9fs_register_trans(struct p9_trans_module *m)
97477 {
97478 spin_lock(&v9fs_trans_lock);
97479 - list_add_tail(&m->list, &v9fs_trans_list);
97480 + pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
97481 spin_unlock(&v9fs_trans_lock);
97482 }
97483 EXPORT_SYMBOL(v9fs_register_trans);
97484 @@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
97485 void v9fs_unregister_trans(struct p9_trans_module *m)
97486 {
97487 spin_lock(&v9fs_trans_lock);
97488 - list_del_init(&m->list);
97489 + pax_list_del_init((struct list_head *)&m->list);
97490 spin_unlock(&v9fs_trans_lock);
97491 }
97492 EXPORT_SYMBOL(v9fs_unregister_trans);
97493 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
97494 index 80d08f6..de63fd1 100644
97495 --- a/net/9p/trans_fd.c
97496 +++ b/net/9p/trans_fd.c
97497 @@ -428,7 +428,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
97498 oldfs = get_fs();
97499 set_fs(get_ds());
97500 /* The cast to a user pointer is valid due to the set_fs() */
97501 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
97502 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
97503 set_fs(oldfs);
97504
97505 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
97506 diff --git a/net/appletalk/atalk_proc.c b/net/appletalk/atalk_proc.c
97507 index af46bc4..f9adfcd 100644
97508 --- a/net/appletalk/atalk_proc.c
97509 +++ b/net/appletalk/atalk_proc.c
97510 @@ -256,7 +256,7 @@ int __init atalk_proc_init(void)
97511 struct proc_dir_entry *p;
97512 int rc = -ENOMEM;
97513
97514 - atalk_proc_dir = proc_mkdir("atalk", init_net.proc_net);
97515 + atalk_proc_dir = proc_mkdir_restrict("atalk", init_net.proc_net);
97516 if (!atalk_proc_dir)
97517 goto out;
97518
97519 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
97520 index 876fbe8..8bbea9f 100644
97521 --- a/net/atm/atm_misc.c
97522 +++ b/net/atm/atm_misc.c
97523 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
97524 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
97525 return 1;
97526 atm_return(vcc, truesize);
97527 - atomic_inc(&vcc->stats->rx_drop);
97528 + atomic_inc_unchecked(&vcc->stats->rx_drop);
97529 return 0;
97530 }
97531 EXPORT_SYMBOL(atm_charge);
97532 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
97533 }
97534 }
97535 atm_return(vcc, guess);
97536 - atomic_inc(&vcc->stats->rx_drop);
97537 + atomic_inc_unchecked(&vcc->stats->rx_drop);
97538 return NULL;
97539 }
97540 EXPORT_SYMBOL(atm_alloc_charge);
97541 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
97542
97543 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
97544 {
97545 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
97546 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
97547 __SONET_ITEMS
97548 #undef __HANDLE_ITEM
97549 }
97550 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
97551
97552 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
97553 {
97554 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
97555 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
97556 __SONET_ITEMS
97557 #undef __HANDLE_ITEM
97558 }
97559 diff --git a/net/atm/lec.c b/net/atm/lec.c
97560 index 4c5b8ba..95f7005 100644
97561 --- a/net/atm/lec.c
97562 +++ b/net/atm/lec.c
97563 @@ -111,9 +111,9 @@ static inline void lec_arp_put(struct lec_arp_table *entry)
97564 }
97565
97566 static struct lane2_ops lane2_ops = {
97567 - lane2_resolve, /* resolve, spec 3.1.3 */
97568 - lane2_associate_req, /* associate_req, spec 3.1.4 */
97569 - NULL /* associate indicator, spec 3.1.5 */
97570 + .resolve = lane2_resolve,
97571 + .associate_req = lane2_associate_req,
97572 + .associate_indicator = NULL
97573 };
97574
97575 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
97576 diff --git a/net/atm/lec.h b/net/atm/lec.h
97577 index 4149db1..f2ab682 100644
97578 --- a/net/atm/lec.h
97579 +++ b/net/atm/lec.h
97580 @@ -48,7 +48,7 @@ struct lane2_ops {
97581 const u8 *tlvs, u32 sizeoftlvs);
97582 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
97583 const u8 *tlvs, u32 sizeoftlvs);
97584 -};
97585 +} __no_const;
97586
97587 /*
97588 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
97589 diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
97590 index d1b2d9a..d549f7f 100644
97591 --- a/net/atm/mpoa_caches.c
97592 +++ b/net/atm/mpoa_caches.c
97593 @@ -535,30 +535,30 @@ static void eg_destroy_cache(struct mpoa_client *mpc)
97594
97595
97596 static struct in_cache_ops ingress_ops = {
97597 - in_cache_add_entry, /* add_entry */
97598 - in_cache_get, /* get */
97599 - in_cache_get_with_mask, /* get_with_mask */
97600 - in_cache_get_by_vcc, /* get_by_vcc */
97601 - in_cache_put, /* put */
97602 - in_cache_remove_entry, /* remove_entry */
97603 - cache_hit, /* cache_hit */
97604 - clear_count_and_expired, /* clear_count */
97605 - check_resolving_entries, /* check_resolving */
97606 - refresh_entries, /* refresh */
97607 - in_destroy_cache /* destroy_cache */
97608 + .add_entry = in_cache_add_entry,
97609 + .get = in_cache_get,
97610 + .get_with_mask = in_cache_get_with_mask,
97611 + .get_by_vcc = in_cache_get_by_vcc,
97612 + .put = in_cache_put,
97613 + .remove_entry = in_cache_remove_entry,
97614 + .cache_hit = cache_hit,
97615 + .clear_count = clear_count_and_expired,
97616 + .check_resolving = check_resolving_entries,
97617 + .refresh = refresh_entries,
97618 + .destroy_cache = in_destroy_cache
97619 };
97620
97621 static struct eg_cache_ops egress_ops = {
97622 - eg_cache_add_entry, /* add_entry */
97623 - eg_cache_get_by_cache_id, /* get_by_cache_id */
97624 - eg_cache_get_by_tag, /* get_by_tag */
97625 - eg_cache_get_by_vcc, /* get_by_vcc */
97626 - eg_cache_get_by_src_ip, /* get_by_src_ip */
97627 - eg_cache_put, /* put */
97628 - eg_cache_remove_entry, /* remove_entry */
97629 - update_eg_cache_entry, /* update */
97630 - clear_expired, /* clear_expired */
97631 - eg_destroy_cache /* destroy_cache */
97632 + .add_entry = eg_cache_add_entry,
97633 + .get_by_cache_id = eg_cache_get_by_cache_id,
97634 + .get_by_tag = eg_cache_get_by_tag,
97635 + .get_by_vcc = eg_cache_get_by_vcc,
97636 + .get_by_src_ip = eg_cache_get_by_src_ip,
97637 + .put = eg_cache_put,
97638 + .remove_entry = eg_cache_remove_entry,
97639 + .update = update_eg_cache_entry,
97640 + .clear_expired = clear_expired,
97641 + .destroy_cache = eg_destroy_cache
97642 };
97643
97644
97645 diff --git a/net/atm/proc.c b/net/atm/proc.c
97646 index bbb6461..cf04016 100644
97647 --- a/net/atm/proc.c
97648 +++ b/net/atm/proc.c
97649 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
97650 const struct k_atm_aal_stats *stats)
97651 {
97652 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
97653 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
97654 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
97655 - atomic_read(&stats->rx_drop));
97656 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
97657 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
97658 + atomic_read_unchecked(&stats->rx_drop));
97659 }
97660
97661 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
97662 diff --git a/net/atm/resources.c b/net/atm/resources.c
97663 index 0447d5d..3cf4728 100644
97664 --- a/net/atm/resources.c
97665 +++ b/net/atm/resources.c
97666 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
97667 static void copy_aal_stats(struct k_atm_aal_stats *from,
97668 struct atm_aal_stats *to)
97669 {
97670 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
97671 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
97672 __AAL_STAT_ITEMS
97673 #undef __HANDLE_ITEM
97674 }
97675 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
97676 static void subtract_aal_stats(struct k_atm_aal_stats *from,
97677 struct atm_aal_stats *to)
97678 {
97679 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
97680 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
97681 __AAL_STAT_ITEMS
97682 #undef __HANDLE_ITEM
97683 }
97684 diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
97685 index 919a5ce..cc6b444 100644
97686 --- a/net/ax25/sysctl_net_ax25.c
97687 +++ b/net/ax25/sysctl_net_ax25.c
97688 @@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
97689 {
97690 char path[sizeof("net/ax25/") + IFNAMSIZ];
97691 int k;
97692 - struct ctl_table *table;
97693 + ctl_table_no_const *table;
97694
97695 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
97696 if (!table)
97697 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
97698 index f04224c..f326579 100644
97699 --- a/net/batman-adv/bat_iv_ogm.c
97700 +++ b/net/batman-adv/bat_iv_ogm.c
97701 @@ -312,7 +312,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
97702
97703 /* randomize initial seqno to avoid collision */
97704 get_random_bytes(&random_seqno, sizeof(random_seqno));
97705 - atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
97706 + atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
97707
97708 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
97709 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
97710 @@ -917,9 +917,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
97711 batadv_ogm_packet->tvlv_len = htons(tvlv_len);
97712
97713 /* change sequence number to network order */
97714 - seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
97715 + seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
97716 batadv_ogm_packet->seqno = htonl(seqno);
97717 - atomic_inc(&hard_iface->bat_iv.ogm_seqno);
97718 + atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
97719
97720 batadv_iv_ogm_slide_own_bcast_window(hard_iface);
97721
97722 @@ -1596,7 +1596,7 @@ static void batadv_iv_ogm_process(const struct sk_buff *skb, int ogm_offset,
97723 return;
97724
97725 /* could be changed by schedule_own_packet() */
97726 - if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
97727 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
97728
97729 if (ogm_packet->flags & BATADV_DIRECTLINK)
97730 has_directlink_flag = true;
97731 diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
97732 index f14e54a..66f3e2e 100644
97733 --- a/net/batman-adv/fragmentation.c
97734 +++ b/net/batman-adv/fragmentation.c
97735 @@ -446,7 +446,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
97736 frag_header.packet_type = BATADV_UNICAST_FRAG;
97737 frag_header.version = BATADV_COMPAT_VERSION;
97738 frag_header.ttl = BATADV_TTL;
97739 - frag_header.seqno = htons(atomic_inc_return(&bat_priv->frag_seqno));
97740 + frag_header.seqno = htons(atomic_inc_return_unchecked(&bat_priv->frag_seqno));
97741 frag_header.reserved = 0;
97742 frag_header.no = 0;
97743 frag_header.total_size = htons(skb->len);
97744 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
97745 index 744a59b..8fd037c 100644
97746 --- a/net/batman-adv/soft-interface.c
97747 +++ b/net/batman-adv/soft-interface.c
97748 @@ -296,7 +296,7 @@ send:
97749 primary_if->net_dev->dev_addr);
97750
97751 /* set broadcast sequence number */
97752 - seqno = atomic_inc_return(&bat_priv->bcast_seqno);
97753 + seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
97754 bcast_packet->seqno = htonl(seqno);
97755
97756 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
97757 @@ -729,7 +729,7 @@ static int batadv_softif_init_late(struct net_device *dev)
97758 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
97759
97760 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
97761 - atomic_set(&bat_priv->bcast_seqno, 1);
97762 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
97763 atomic_set(&bat_priv->tt.vn, 0);
97764 atomic_set(&bat_priv->tt.local_changes, 0);
97765 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
97766 @@ -743,7 +743,7 @@ static int batadv_softif_init_late(struct net_device *dev)
97767
97768 /* randomize initial seqno to avoid collision */
97769 get_random_bytes(&random_seqno, sizeof(random_seqno));
97770 - atomic_set(&bat_priv->frag_seqno, random_seqno);
97771 + atomic_set_unchecked(&bat_priv->frag_seqno, random_seqno);
97772
97773 bat_priv->primary_if = NULL;
97774 bat_priv->num_ifaces = 0;
97775 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
97776 index 34891a5..3cfece0 100644
97777 --- a/net/batman-adv/types.h
97778 +++ b/net/batman-adv/types.h
97779 @@ -67,7 +67,7 @@ enum batadv_dhcp_recipient {
97780 struct batadv_hard_iface_bat_iv {
97781 unsigned char *ogm_buff;
97782 int ogm_buff_len;
97783 - atomic_t ogm_seqno;
97784 + atomic_unchecked_t ogm_seqno;
97785 };
97786
97787 /**
97788 @@ -766,7 +766,7 @@ struct batadv_priv {
97789 atomic_t bonding;
97790 atomic_t fragmentation;
97791 atomic_t packet_size_max;
97792 - atomic_t frag_seqno;
97793 + atomic_unchecked_t frag_seqno;
97794 #ifdef CONFIG_BATMAN_ADV_BLA
97795 atomic_t bridge_loop_avoidance;
97796 #endif
97797 @@ -785,7 +785,7 @@ struct batadv_priv {
97798 #endif
97799 uint32_t isolation_mark;
97800 uint32_t isolation_mark_mask;
97801 - atomic_t bcast_seqno;
97802 + atomic_unchecked_t bcast_seqno;
97803 atomic_t bcast_queue_left;
97804 atomic_t batman_queue_left;
97805 char num_ifaces;
97806 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
97807 index b9a418e..2af862a 100644
97808 --- a/net/bluetooth/hci_sock.c
97809 +++ b/net/bluetooth/hci_sock.c
97810 @@ -1053,7 +1053,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
97811 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
97812 }
97813
97814 - len = min_t(unsigned int, len, sizeof(uf));
97815 + len = min((size_t)len, sizeof(uf));
97816 if (copy_from_user(&uf, optval, len)) {
97817 err = -EFAULT;
97818 break;
97819 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
97820 index 1c97b7a..9171d69 100644
97821 --- a/net/bluetooth/l2cap_core.c
97822 +++ b/net/bluetooth/l2cap_core.c
97823 @@ -3542,8 +3542,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
97824 break;
97825
97826 case L2CAP_CONF_RFC:
97827 - if (olen == sizeof(rfc))
97828 - memcpy(&rfc, (void *)val, olen);
97829 + if (olen != sizeof(rfc))
97830 + break;
97831 +
97832 + memcpy(&rfc, (void *)val, olen);
97833
97834 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
97835 rfc.mode != chan->mode)
97836 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
97837 index e137869..33f3ebd 100644
97838 --- a/net/bluetooth/l2cap_sock.c
97839 +++ b/net/bluetooth/l2cap_sock.c
97840 @@ -628,7 +628,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
97841 struct sock *sk = sock->sk;
97842 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
97843 struct l2cap_options opts;
97844 - int len, err = 0;
97845 + int err = 0;
97846 + size_t len = optlen;
97847 u32 opt;
97848
97849 BT_DBG("sk %p", sk);
97850 @@ -655,7 +656,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
97851 opts.max_tx = chan->max_tx;
97852 opts.txwin_size = chan->tx_win;
97853
97854 - len = min_t(unsigned int, sizeof(opts), optlen);
97855 + len = min(sizeof(opts), len);
97856 if (copy_from_user((char *) &opts, optval, len)) {
97857 err = -EFAULT;
97858 break;
97859 @@ -742,7 +743,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
97860 struct bt_security sec;
97861 struct bt_power pwr;
97862 struct l2cap_conn *conn;
97863 - int len, err = 0;
97864 + int err = 0;
97865 + size_t len = optlen;
97866 u32 opt;
97867
97868 BT_DBG("sk %p", sk);
97869 @@ -766,7 +768,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
97870
97871 sec.level = BT_SECURITY_LOW;
97872
97873 - len = min_t(unsigned int, sizeof(sec), optlen);
97874 + len = min(sizeof(sec), len);
97875 if (copy_from_user((char *) &sec, optval, len)) {
97876 err = -EFAULT;
97877 break;
97878 @@ -861,7 +863,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
97879
97880 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
97881
97882 - len = min_t(unsigned int, sizeof(pwr), optlen);
97883 + len = min(sizeof(pwr), len);
97884 if (copy_from_user((char *) &pwr, optval, len)) {
97885 err = -EFAULT;
97886 break;
97887 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
97888 index c603a5e..7f08991 100644
97889 --- a/net/bluetooth/rfcomm/sock.c
97890 +++ b/net/bluetooth/rfcomm/sock.c
97891 @@ -687,7 +687,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
97892 struct sock *sk = sock->sk;
97893 struct bt_security sec;
97894 int err = 0;
97895 - size_t len;
97896 + size_t len = optlen;
97897 u32 opt;
97898
97899 BT_DBG("sk %p", sk);
97900 @@ -709,7 +709,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
97901
97902 sec.level = BT_SECURITY_LOW;
97903
97904 - len = min_t(unsigned int, sizeof(sec), optlen);
97905 + len = min(sizeof(sec), len);
97906 if (copy_from_user((char *) &sec, optval, len)) {
97907 err = -EFAULT;
97908 break;
97909 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
97910 index 403ec09..a21a003 100644
97911 --- a/net/bluetooth/rfcomm/tty.c
97912 +++ b/net/bluetooth/rfcomm/tty.c
97913 @@ -752,7 +752,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
97914 BT_DBG("tty %p id %d", tty, tty->index);
97915
97916 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
97917 - dev->channel, dev->port.count);
97918 + dev->channel, atomic_read(&dev->port.count));
97919
97920 err = tty_port_open(&dev->port, tty, filp);
97921 if (err)
97922 @@ -775,7 +775,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
97923 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
97924
97925 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
97926 - dev->port.count);
97927 + atomic_read(&dev->port.count));
97928
97929 tty_port_close(&dev->port, tty, filp);
97930 }
97931 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
97932 index 1059ed3..d70846a 100644
97933 --- a/net/bridge/netfilter/ebtables.c
97934 +++ b/net/bridge/netfilter/ebtables.c
97935 @@ -1524,7 +1524,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
97936 tmp.valid_hooks = t->table->valid_hooks;
97937 }
97938 mutex_unlock(&ebt_mutex);
97939 - if (copy_to_user(user, &tmp, *len) != 0) {
97940 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
97941 BUGPRINT("c2u Didn't work\n");
97942 ret = -EFAULT;
97943 break;
97944 @@ -2330,7 +2330,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
97945 goto out;
97946 tmp.valid_hooks = t->valid_hooks;
97947
97948 - if (copy_to_user(user, &tmp, *len) != 0) {
97949 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
97950 ret = -EFAULT;
97951 break;
97952 }
97953 @@ -2341,7 +2341,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
97954 tmp.entries_size = t->table->entries_size;
97955 tmp.valid_hooks = t->table->valid_hooks;
97956
97957 - if (copy_to_user(user, &tmp, *len) != 0) {
97958 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
97959 ret = -EFAULT;
97960 break;
97961 }
97962 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
97963 index 0f45522..dab651f 100644
97964 --- a/net/caif/cfctrl.c
97965 +++ b/net/caif/cfctrl.c
97966 @@ -10,6 +10,7 @@
97967 #include <linux/spinlock.h>
97968 #include <linux/slab.h>
97969 #include <linux/pkt_sched.h>
97970 +#include <linux/sched.h>
97971 #include <net/caif/caif_layer.h>
97972 #include <net/caif/cfpkt.h>
97973 #include <net/caif/cfctrl.h>
97974 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
97975 memset(&dev_info, 0, sizeof(dev_info));
97976 dev_info.id = 0xff;
97977 cfsrvl_init(&this->serv, 0, &dev_info, false);
97978 - atomic_set(&this->req_seq_no, 1);
97979 - atomic_set(&this->rsp_seq_no, 1);
97980 + atomic_set_unchecked(&this->req_seq_no, 1);
97981 + atomic_set_unchecked(&this->rsp_seq_no, 1);
97982 this->serv.layer.receive = cfctrl_recv;
97983 sprintf(this->serv.layer.name, "ctrl");
97984 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
97985 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
97986 struct cfctrl_request_info *req)
97987 {
97988 spin_lock_bh(&ctrl->info_list_lock);
97989 - atomic_inc(&ctrl->req_seq_no);
97990 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
97991 + atomic_inc_unchecked(&ctrl->req_seq_no);
97992 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
97993 list_add_tail(&req->list, &ctrl->list);
97994 spin_unlock_bh(&ctrl->info_list_lock);
97995 }
97996 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
97997 if (p != first)
97998 pr_warn("Requests are not received in order\n");
97999
98000 - atomic_set(&ctrl->rsp_seq_no,
98001 + atomic_set_unchecked(&ctrl->rsp_seq_no,
98002 p->sequence_no);
98003 list_del(&p->list);
98004 goto out;
98005 diff --git a/net/can/af_can.c b/net/can/af_can.c
98006 index a27f8aa..67174a3 100644
98007 --- a/net/can/af_can.c
98008 +++ b/net/can/af_can.c
98009 @@ -863,7 +863,7 @@ static const struct net_proto_family can_family_ops = {
98010 };
98011
98012 /* notifier block for netdevice event */
98013 -static struct notifier_block can_netdev_notifier __read_mostly = {
98014 +static struct notifier_block can_netdev_notifier = {
98015 .notifier_call = can_notifier,
98016 };
98017
98018 diff --git a/net/can/bcm.c b/net/can/bcm.c
98019 index dcb75c0..24b1b43 100644
98020 --- a/net/can/bcm.c
98021 +++ b/net/can/bcm.c
98022 @@ -1624,7 +1624,7 @@ static int __init bcm_module_init(void)
98023 }
98024
98025 /* create /proc/net/can-bcm directory */
98026 - proc_dir = proc_mkdir("can-bcm", init_net.proc_net);
98027 + proc_dir = proc_mkdir_restrict("can-bcm", init_net.proc_net);
98028 return 0;
98029 }
98030
98031 diff --git a/net/can/gw.c b/net/can/gw.c
98032 index 050a211..bb9fe33 100644
98033 --- a/net/can/gw.c
98034 +++ b/net/can/gw.c
98035 @@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
98036 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
98037
98038 static HLIST_HEAD(cgw_list);
98039 -static struct notifier_block notifier;
98040
98041 static struct kmem_cache *cgw_cache __read_mostly;
98042
98043 @@ -947,6 +946,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
98044 return err;
98045 }
98046
98047 +static struct notifier_block notifier = {
98048 + .notifier_call = cgw_notifier
98049 +};
98050 +
98051 static __init int cgw_module_init(void)
98052 {
98053 /* sanitize given module parameter */
98054 @@ -962,7 +965,6 @@ static __init int cgw_module_init(void)
98055 return -ENOMEM;
98056
98057 /* set notifier */
98058 - notifier.notifier_call = cgw_notifier;
98059 register_netdevice_notifier(&notifier);
98060
98061 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
98062 diff --git a/net/can/proc.c b/net/can/proc.c
98063 index b543470..d2ddae2 100644
98064 --- a/net/can/proc.c
98065 +++ b/net/can/proc.c
98066 @@ -468,7 +468,7 @@ static void can_remove_proc_readentry(const char *name)
98067 void can_init_proc(void)
98068 {
98069 /* create /proc/net/can directory */
98070 - can_dir = proc_mkdir("can", init_net.proc_net);
98071 + can_dir = proc_mkdir_restrict("can", init_net.proc_net);
98072
98073 if (!can_dir) {
98074 printk(KERN_INFO "can: failed to create /proc/net/can . "
98075 diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
98076 index 1948d59..9e854d5 100644
98077 --- a/net/ceph/messenger.c
98078 +++ b/net/ceph/messenger.c
98079 @@ -187,7 +187,7 @@ static void con_fault(struct ceph_connection *con);
98080 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
98081
98082 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
98083 -static atomic_t addr_str_seq = ATOMIC_INIT(0);
98084 +static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
98085
98086 static struct page *zero_page; /* used in certain error cases */
98087
98088 @@ -198,7 +198,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
98089 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
98090 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
98091
98092 - i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
98093 + i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
98094 s = addr_str[i];
98095
98096 switch (ss->ss_family) {
98097 diff --git a/net/compat.c b/net/compat.c
98098 index 9a76eaf..5b8ccfd 100644
98099 --- a/net/compat.c
98100 +++ b/net/compat.c
98101 @@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
98102 return -EFAULT;
98103 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
98104 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
98105 - kmsg->msg_name = compat_ptr(tmp1);
98106 - kmsg->msg_iov = compat_ptr(tmp2);
98107 - kmsg->msg_control = compat_ptr(tmp3);
98108 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
98109 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
98110 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
98111 return 0;
98112 }
98113
98114 @@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
98115
98116 if (kern_msg->msg_namelen) {
98117 if (mode == VERIFY_READ) {
98118 - int err = move_addr_to_kernel(kern_msg->msg_name,
98119 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
98120 kern_msg->msg_namelen,
98121 kern_address);
98122 if (err < 0)
98123 @@ -99,7 +99,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
98124 kern_msg->msg_name = NULL;
98125
98126 tot_len = iov_from_user_compat_to_kern(kern_iov,
98127 - (struct compat_iovec __user *)kern_msg->msg_iov,
98128 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
98129 kern_msg->msg_iovlen);
98130 if (tot_len >= 0)
98131 kern_msg->msg_iov = kern_iov;
98132 @@ -119,20 +119,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
98133
98134 #define CMSG_COMPAT_FIRSTHDR(msg) \
98135 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
98136 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
98137 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
98138 (struct compat_cmsghdr __user *)NULL)
98139
98140 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
98141 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
98142 (ucmlen) <= (unsigned long) \
98143 ((mhdr)->msg_controllen - \
98144 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
98145 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
98146
98147 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
98148 struct compat_cmsghdr __user *cmsg, int cmsg_len)
98149 {
98150 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
98151 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
98152 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
98153 msg->msg_controllen)
98154 return NULL;
98155 return (struct compat_cmsghdr __user *)ptr;
98156 @@ -222,7 +222,7 @@ Efault:
98157
98158 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
98159 {
98160 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
98161 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
98162 struct compat_cmsghdr cmhdr;
98163 struct compat_timeval ctv;
98164 struct compat_timespec cts[3];
98165 @@ -278,7 +278,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
98166
98167 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
98168 {
98169 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
98170 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
98171 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
98172 int fdnum = scm->fp->count;
98173 struct file **fp = scm->fp->fp;
98174 @@ -366,7 +366,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
98175 return -EFAULT;
98176 old_fs = get_fs();
98177 set_fs(KERNEL_DS);
98178 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
98179 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
98180 set_fs(old_fs);
98181
98182 return err;
98183 @@ -427,7 +427,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
98184 len = sizeof(ktime);
98185 old_fs = get_fs();
98186 set_fs(KERNEL_DS);
98187 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
98188 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
98189 set_fs(old_fs);
98190
98191 if (!err) {
98192 @@ -570,7 +570,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
98193 case MCAST_JOIN_GROUP:
98194 case MCAST_LEAVE_GROUP:
98195 {
98196 - struct compat_group_req __user *gr32 = (void *)optval;
98197 + struct compat_group_req __user *gr32 = (void __user *)optval;
98198 struct group_req __user *kgr =
98199 compat_alloc_user_space(sizeof(struct group_req));
98200 u32 interface;
98201 @@ -591,7 +591,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
98202 case MCAST_BLOCK_SOURCE:
98203 case MCAST_UNBLOCK_SOURCE:
98204 {
98205 - struct compat_group_source_req __user *gsr32 = (void *)optval;
98206 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
98207 struct group_source_req __user *kgsr = compat_alloc_user_space(
98208 sizeof(struct group_source_req));
98209 u32 interface;
98210 @@ -612,7 +612,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
98211 }
98212 case MCAST_MSFILTER:
98213 {
98214 - struct compat_group_filter __user *gf32 = (void *)optval;
98215 + struct compat_group_filter __user *gf32 = (void __user *)optval;
98216 struct group_filter __user *kgf;
98217 u32 interface, fmode, numsrc;
98218
98219 @@ -650,7 +650,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
98220 char __user *optval, int __user *optlen,
98221 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
98222 {
98223 - struct compat_group_filter __user *gf32 = (void *)optval;
98224 + struct compat_group_filter __user *gf32 = (void __user *)optval;
98225 struct group_filter __user *kgf;
98226 int __user *koptlen;
98227 u32 interface, fmode, numsrc;
98228 @@ -803,7 +803,7 @@ COMPAT_SYSCALL_DEFINE2(socketcall, int, call, u32 __user *, args)
98229
98230 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
98231 return -EINVAL;
98232 - if (copy_from_user(a, args, nas[call]))
98233 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
98234 return -EFAULT;
98235 a0 = a[0];
98236 a1 = a[1];
98237 diff --git a/net/core/datagram.c b/net/core/datagram.c
98238 index a16ed7b..eb44d17 100644
98239 --- a/net/core/datagram.c
98240 +++ b/net/core/datagram.c
98241 @@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
98242 }
98243
98244 kfree_skb(skb);
98245 - atomic_inc(&sk->sk_drops);
98246 + atomic_inc_unchecked(&sk->sk_drops);
98247 sk_mem_reclaim_partial(sk);
98248
98249 return err;
98250 diff --git a/net/core/dev.c b/net/core/dev.c
98251 index a30bef1..51d3e33 100644
98252 --- a/net/core/dev.c
98253 +++ b/net/core/dev.c
98254 @@ -1683,14 +1683,14 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
98255 {
98256 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
98257 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
98258 - atomic_long_inc(&dev->rx_dropped);
98259 + atomic_long_inc_unchecked(&dev->rx_dropped);
98260 kfree_skb(skb);
98261 return NET_RX_DROP;
98262 }
98263 }
98264
98265 if (unlikely(!is_skb_forwardable(dev, skb))) {
98266 - atomic_long_inc(&dev->rx_dropped);
98267 + atomic_long_inc_unchecked(&dev->rx_dropped);
98268 kfree_skb(skb);
98269 return NET_RX_DROP;
98270 }
98271 @@ -2463,7 +2463,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
98272
98273 struct dev_gso_cb {
98274 void (*destructor)(struct sk_buff *skb);
98275 -};
98276 +} __no_const;
98277
98278 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
98279
98280 @@ -2893,7 +2893,7 @@ recursion_alert:
98281 rc = -ENETDOWN;
98282 rcu_read_unlock_bh();
98283
98284 - atomic_long_inc(&dev->tx_dropped);
98285 + atomic_long_inc_unchecked(&dev->tx_dropped);
98286 kfree_skb(skb);
98287 return rc;
98288 out:
98289 @@ -3237,7 +3237,7 @@ enqueue:
98290
98291 local_irq_restore(flags);
98292
98293 - atomic_long_inc(&skb->dev->rx_dropped);
98294 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
98295 kfree_skb(skb);
98296 return NET_RX_DROP;
98297 }
98298 @@ -3314,7 +3314,7 @@ int netif_rx_ni(struct sk_buff *skb)
98299 }
98300 EXPORT_SYMBOL(netif_rx_ni);
98301
98302 -static void net_tx_action(struct softirq_action *h)
98303 +static __latent_entropy void net_tx_action(void)
98304 {
98305 struct softnet_data *sd = &__get_cpu_var(softnet_data);
98306
98307 @@ -3647,7 +3647,7 @@ ncls:
98308 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
98309 } else {
98310 drop:
98311 - atomic_long_inc(&skb->dev->rx_dropped);
98312 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
98313 kfree_skb(skb);
98314 /* Jamal, now you will not able to escape explaining
98315 * me how you were going to use this. :-)
98316 @@ -4366,7 +4366,7 @@ void netif_napi_del(struct napi_struct *napi)
98317 }
98318 EXPORT_SYMBOL(netif_napi_del);
98319
98320 -static void net_rx_action(struct softirq_action *h)
98321 +static __latent_entropy void net_rx_action(void)
98322 {
98323 struct softnet_data *sd = &__get_cpu_var(softnet_data);
98324 unsigned long time_limit = jiffies + 2;
98325 @@ -6366,8 +6366,8 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
98326 } else {
98327 netdev_stats_to_stats64(storage, &dev->stats);
98328 }
98329 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
98330 - storage->tx_dropped += atomic_long_read(&dev->tx_dropped);
98331 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
98332 + storage->tx_dropped += atomic_long_read_unchecked(&dev->tx_dropped);
98333 return storage;
98334 }
98335 EXPORT_SYMBOL(dev_get_stats);
98336 diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
98337 index cf999e0..c59a975 100644
98338 --- a/net/core/dev_ioctl.c
98339 +++ b/net/core/dev_ioctl.c
98340 @@ -366,9 +366,13 @@ void dev_load(struct net *net, const char *name)
98341 if (no_module && capable(CAP_NET_ADMIN))
98342 no_module = request_module("netdev-%s", name);
98343 if (no_module && capable(CAP_SYS_MODULE)) {
98344 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
98345 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
98346 +#else
98347 if (!request_module("%s", name))
98348 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
98349 name);
98350 +#endif
98351 }
98352 }
98353 EXPORT_SYMBOL(dev_load);
98354 diff --git a/net/core/dst.c b/net/core/dst.c
98355 index 80d6286..a028409 100644
98356 --- a/net/core/dst.c
98357 +++ b/net/core/dst.c
98358 @@ -269,6 +269,15 @@ again:
98359 }
98360 EXPORT_SYMBOL(dst_destroy);
98361
98362 +static void dst_destroy_rcu(struct rcu_head *head)
98363 +{
98364 + struct dst_entry *dst = container_of(head, struct dst_entry, rcu_head);
98365 +
98366 + dst = dst_destroy(dst);
98367 + if (dst)
98368 + __dst_free(dst);
98369 +}
98370 +
98371 void dst_release(struct dst_entry *dst)
98372 {
98373 if (dst) {
98374 @@ -276,11 +285,8 @@ void dst_release(struct dst_entry *dst)
98375
98376 newrefcnt = atomic_dec_return(&dst->__refcnt);
98377 WARN_ON(newrefcnt < 0);
98378 - if (unlikely(dst->flags & DST_NOCACHE) && !newrefcnt) {
98379 - dst = dst_destroy(dst);
98380 - if (dst)
98381 - __dst_free(dst);
98382 - }
98383 + if (unlikely(dst->flags & DST_NOCACHE) && !newrefcnt)
98384 + call_rcu(&dst->rcu_head, dst_destroy_rcu);
98385 }
98386 }
98387 EXPORT_SYMBOL(dst_release);
98388 diff --git a/net/core/filter.c b/net/core/filter.c
98389 index 4aec7b9..5cf605c 100644
98390 --- a/net/core/filter.c
98391 +++ b/net/core/filter.c
98392 @@ -1121,7 +1121,11 @@ do_pass:
98393 break;
98394
98395 default:
98396 - goto err;
98397 + WARN(1, KERN_ALERT "Unknown sock filter code:%u jt:%u tf:%u k:%u\n",
98398 + fp->code, fp->jt, fp->jf, fp->k);
98399 + kfree(addrs);
98400 + BUG();
98401 + return -EINVAL;
98402 }
98403
98404 insn++;
98405 @@ -1170,7 +1174,7 @@ static int check_load_and_stores(struct sock_filter *filter, int flen)
98406 u16 *masks, memvalid = 0; /* one bit per cell, 16 cells */
98407 int pc, ret = 0;
98408
98409 - BUILD_BUG_ON(BPF_MEMWORDS > 16);
98410 + BUILD_BUG_ON(BPF_MEMWORDS != 16);
98411 masks = kmalloc(flen * sizeof(*masks), GFP_KERNEL);
98412 if (!masks)
98413 return -ENOMEM;
98414 @@ -1605,7 +1609,7 @@ int sk_unattached_filter_create(struct sk_filter **pfp,
98415 if (!fp)
98416 return -ENOMEM;
98417
98418 - memcpy(fp->insns, fprog->filter, fsize);
98419 + memcpy(fp->insns, (void __force_kernel *)fprog->filter, fsize);
98420
98421 atomic_set(&fp->refcnt, 1);
98422 fp->len = fprog->len;
98423 diff --git a/net/core/flow.c b/net/core/flow.c
98424 index a0348fd..6951c76 100644
98425 --- a/net/core/flow.c
98426 +++ b/net/core/flow.c
98427 @@ -65,7 +65,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
98428 static int flow_entry_valid(struct flow_cache_entry *fle,
98429 struct netns_xfrm *xfrm)
98430 {
98431 - if (atomic_read(&xfrm->flow_cache_genid) != fle->genid)
98432 + if (atomic_read_unchecked(&xfrm->flow_cache_genid) != fle->genid)
98433 return 0;
98434 if (fle->object && !fle->object->ops->check(fle->object))
98435 return 0;
98436 @@ -242,7 +242,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
98437 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
98438 fcp->hash_count++;
98439 }
98440 - } else if (likely(fle->genid == atomic_read(&net->xfrm.flow_cache_genid))) {
98441 + } else if (likely(fle->genid == atomic_read_unchecked(&net->xfrm.flow_cache_genid))) {
98442 flo = fle->object;
98443 if (!flo)
98444 goto ret_object;
98445 @@ -263,7 +263,7 @@ nocache:
98446 }
98447 flo = resolver(net, key, family, dir, flo, ctx);
98448 if (fle) {
98449 - fle->genid = atomic_read(&net->xfrm.flow_cache_genid);
98450 + fle->genid = atomic_read_unchecked(&net->xfrm.flow_cache_genid);
98451 if (!IS_ERR(flo))
98452 fle->object = flo;
98453 else
98454 diff --git a/net/core/iovec.c b/net/core/iovec.c
98455 index b618694..192bbba 100644
98456 --- a/net/core/iovec.c
98457 +++ b/net/core/iovec.c
98458 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
98459 if (m->msg_namelen) {
98460 if (mode == VERIFY_READ) {
98461 void __user *namep;
98462 - namep = (void __user __force *) m->msg_name;
98463 + namep = (void __force_user *) m->msg_name;
98464 err = move_addr_to_kernel(namep, m->msg_namelen,
98465 address);
98466 if (err < 0)
98467 @@ -55,7 +55,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
98468 }
98469
98470 size = m->msg_iovlen * sizeof(struct iovec);
98471 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
98472 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
98473 return -EFAULT;
98474
98475 m->msg_iov = iov;
98476 diff --git a/net/core/neighbour.c b/net/core/neighbour.c
98477 index 32d872e..487e769 100644
98478 --- a/net/core/neighbour.c
98479 +++ b/net/core/neighbour.c
98480 @@ -2825,7 +2825,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
98481 void __user *buffer, size_t *lenp, loff_t *ppos)
98482 {
98483 int size, ret;
98484 - struct ctl_table tmp = *ctl;
98485 + ctl_table_no_const tmp = *ctl;
98486
98487 tmp.extra1 = &zero;
98488 tmp.extra2 = &unres_qlen_max;
98489 @@ -2887,7 +2887,7 @@ static int neigh_proc_dointvec_zero_intmax(struct ctl_table *ctl, int write,
98490 void __user *buffer,
98491 size_t *lenp, loff_t *ppos)
98492 {
98493 - struct ctl_table tmp = *ctl;
98494 + ctl_table_no_const tmp = *ctl;
98495 int ret;
98496
98497 tmp.extra1 = &zero;
98498 @@ -3059,11 +3059,12 @@ int neigh_sysctl_register(struct net_device *dev, struct neigh_parms *p,
98499 memset(&t->neigh_vars[NEIGH_VAR_GC_INTERVAL], 0,
98500 sizeof(t->neigh_vars[NEIGH_VAR_GC_INTERVAL]));
98501 } else {
98502 + struct neigh_table *ntable = container_of(p, struct neigh_table, parms);
98503 dev_name_source = "default";
98504 - t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = (int *)(p + 1);
98505 - t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = (int *)(p + 1) + 1;
98506 - t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = (int *)(p + 1) + 2;
98507 - t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = (int *)(p + 1) + 3;
98508 + t->neigh_vars[NEIGH_VAR_GC_INTERVAL].data = &ntable->gc_interval;
98509 + t->neigh_vars[NEIGH_VAR_GC_THRESH1].data = &ntable->gc_thresh1;
98510 + t->neigh_vars[NEIGH_VAR_GC_THRESH2].data = &ntable->gc_thresh2;
98511 + t->neigh_vars[NEIGH_VAR_GC_THRESH3].data = &ntable->gc_thresh3;
98512 }
98513
98514 if (handler) {
98515 diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
98516 index 2bf8329..2eb1423 100644
98517 --- a/net/core/net-procfs.c
98518 +++ b/net/core/net-procfs.c
98519 @@ -79,7 +79,13 @@ static void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev)
98520 struct rtnl_link_stats64 temp;
98521 const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp);
98522
98523 - seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
98524 + if (gr_proc_is_restricted())
98525 + seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
98526 + "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
98527 + dev->name, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL,
98528 + 0ULL, 0ULL, 0ULL, 0ULL, 0ULL, 0ULL);
98529 + else
98530 + seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu "
98531 "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n",
98532 dev->name, stats->rx_bytes, stats->rx_packets,
98533 stats->rx_errors,
98534 @@ -166,7 +172,7 @@ static int softnet_seq_show(struct seq_file *seq, void *v)
98535 return 0;
98536 }
98537
98538 -static const struct seq_operations dev_seq_ops = {
98539 +const struct seq_operations dev_seq_ops = {
98540 .start = dev_seq_start,
98541 .next = dev_seq_next,
98542 .stop = dev_seq_stop,
98543 @@ -196,7 +202,7 @@ static const struct seq_operations softnet_seq_ops = {
98544
98545 static int softnet_seq_open(struct inode *inode, struct file *file)
98546 {
98547 - return seq_open(file, &softnet_seq_ops);
98548 + return seq_open_restrict(file, &softnet_seq_ops);
98549 }
98550
98551 static const struct file_operations softnet_seq_fops = {
98552 @@ -283,8 +289,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
98553 else
98554 seq_printf(seq, "%04x", ntohs(pt->type));
98555
98556 +#ifdef CONFIG_GRKERNSEC_HIDESYM
98557 + seq_printf(seq, " %-8s %pf\n",
98558 + pt->dev ? pt->dev->name : "", NULL);
98559 +#else
98560 seq_printf(seq, " %-8s %pf\n",
98561 pt->dev ? pt->dev->name : "", pt->func);
98562 +#endif
98563 }
98564
98565 return 0;
98566 diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
98567 index 1cac29e..fb482f3 100644
98568 --- a/net/core/net-sysfs.c
98569 +++ b/net/core/net-sysfs.c
98570 @@ -259,7 +259,7 @@ static ssize_t carrier_changes_show(struct device *dev,
98571 {
98572 struct net_device *netdev = to_net_dev(dev);
98573 return sprintf(buf, fmt_dec,
98574 - atomic_read(&netdev->carrier_changes));
98575 + atomic_read_unchecked(&netdev->carrier_changes));
98576 }
98577 static DEVICE_ATTR_RO(carrier_changes);
98578
98579 diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
98580 index 7c8ffd9..0cb3687 100644
98581 --- a/net/core/net_namespace.c
98582 +++ b/net/core/net_namespace.c
98583 @@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
98584 int error;
98585 LIST_HEAD(net_exit_list);
98586
98587 - list_add_tail(&ops->list, list);
98588 + pax_list_add_tail((struct list_head *)&ops->list, list);
98589 if (ops->init || (ops->id && ops->size)) {
98590 for_each_net(net) {
98591 error = ops_init(ops, net);
98592 @@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
98593
98594 out_undo:
98595 /* If I have an error cleanup all namespaces I initialized */
98596 - list_del(&ops->list);
98597 + pax_list_del((struct list_head *)&ops->list);
98598 ops_exit_list(ops, &net_exit_list);
98599 ops_free_list(ops, &net_exit_list);
98600 return error;
98601 @@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
98602 struct net *net;
98603 LIST_HEAD(net_exit_list);
98604
98605 - list_del(&ops->list);
98606 + pax_list_del((struct list_head *)&ops->list);
98607 for_each_net(net)
98608 list_add_tail(&net->exit_list, &net_exit_list);
98609 ops_exit_list(ops, &net_exit_list);
98610 @@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
98611 mutex_lock(&net_mutex);
98612 error = register_pernet_operations(&pernet_list, ops);
98613 if (!error && (first_device == &pernet_list))
98614 - first_device = &ops->list;
98615 + first_device = (struct list_head *)&ops->list;
98616 mutex_unlock(&net_mutex);
98617 return error;
98618 }
98619 diff --git a/net/core/netpoll.c b/net/core/netpoll.c
98620 index e33937f..b2b4981 100644
98621 --- a/net/core/netpoll.c
98622 +++ b/net/core/netpoll.c
98623 @@ -382,7 +382,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
98624 struct udphdr *udph;
98625 struct iphdr *iph;
98626 struct ethhdr *eth;
98627 - static atomic_t ip_ident;
98628 + static atomic_unchecked_t ip_ident;
98629 struct ipv6hdr *ip6h;
98630
98631 udp_len = len + sizeof(*udph);
98632 @@ -453,7 +453,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
98633 put_unaligned(0x45, (unsigned char *)iph);
98634 iph->tos = 0;
98635 put_unaligned(htons(ip_len), &(iph->tot_len));
98636 - iph->id = htons(atomic_inc_return(&ip_ident));
98637 + iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
98638 iph->frag_off = 0;
98639 iph->ttl = 64;
98640 iph->protocol = IPPROTO_UDP;
98641 diff --git a/net/core/pktgen.c b/net/core/pktgen.c
98642 index 0304f98..ddfead6 100644
98643 --- a/net/core/pktgen.c
98644 +++ b/net/core/pktgen.c
98645 @@ -3725,7 +3725,7 @@ static int __net_init pg_net_init(struct net *net)
98646 pn->net = net;
98647 INIT_LIST_HEAD(&pn->pktgen_threads);
98648 pn->pktgen_exiting = false;
98649 - pn->proc_dir = proc_mkdir(PG_PROC_DIR, pn->net->proc_net);
98650 + pn->proc_dir = proc_mkdir_restrict(PG_PROC_DIR, pn->net->proc_net);
98651 if (!pn->proc_dir) {
98652 pr_warn("cannot create /proc/net/%s\n", PG_PROC_DIR);
98653 return -ENODEV;
98654 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
98655 index 1999ed8..1e6e58a 100644
98656 --- a/net/core/rtnetlink.c
98657 +++ b/net/core/rtnetlink.c
98658 @@ -58,7 +58,7 @@ struct rtnl_link {
98659 rtnl_doit_func doit;
98660 rtnl_dumpit_func dumpit;
98661 rtnl_calcit_func calcit;
98662 -};
98663 +} __no_const;
98664
98665 static DEFINE_MUTEX(rtnl_mutex);
98666
98667 @@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
98668 if (rtnl_link_ops_get(ops->kind))
98669 return -EEXIST;
98670
98671 - if (!ops->dellink)
98672 - ops->dellink = unregister_netdevice_queue;
98673 + if (!ops->dellink) {
98674 + pax_open_kernel();
98675 + *(void **)&ops->dellink = unregister_netdevice_queue;
98676 + pax_close_kernel();
98677 + }
98678
98679 - list_add_tail(&ops->list, &link_ops);
98680 + pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
98681 return 0;
98682 }
98683 EXPORT_SYMBOL_GPL(__rtnl_link_register);
98684 @@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
98685 for_each_net(net) {
98686 __rtnl_kill_links(net, ops);
98687 }
98688 - list_del(&ops->list);
98689 + pax_list_del((struct list_head *)&ops->list);
98690 }
98691 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
98692
98693 @@ -1008,7 +1011,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
98694 (dev->ifalias &&
98695 nla_put_string(skb, IFLA_IFALIAS, dev->ifalias)) ||
98696 nla_put_u32(skb, IFLA_CARRIER_CHANGES,
98697 - atomic_read(&dev->carrier_changes)))
98698 + atomic_read_unchecked(&dev->carrier_changes)))
98699 goto nla_put_failure;
98700
98701 if (1) {
98702 diff --git a/net/core/scm.c b/net/core/scm.c
98703 index b442e7e..6f5b5a2 100644
98704 --- a/net/core/scm.c
98705 +++ b/net/core/scm.c
98706 @@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
98707 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
98708 {
98709 struct cmsghdr __user *cm
98710 - = (__force struct cmsghdr __user *)msg->msg_control;
98711 + = (struct cmsghdr __force_user *)msg->msg_control;
98712 struct cmsghdr cmhdr;
98713 int cmlen = CMSG_LEN(len);
98714 int err;
98715 @@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
98716 err = -EFAULT;
98717 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
98718 goto out;
98719 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
98720 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
98721 goto out;
98722 cmlen = CMSG_SPACE(len);
98723 if (msg->msg_controllen < cmlen)
98724 @@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
98725 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
98726 {
98727 struct cmsghdr __user *cm
98728 - = (__force struct cmsghdr __user*)msg->msg_control;
98729 + = (struct cmsghdr __force_user *)msg->msg_control;
98730
98731 int fdmax = 0;
98732 int fdnum = scm->fp->count;
98733 @@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
98734 if (fdnum < fdmax)
98735 fdmax = fdnum;
98736
98737 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
98738 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
98739 i++, cmfptr++)
98740 {
98741 struct socket *sock;
98742 diff --git a/net/core/skbuff.c b/net/core/skbuff.c
98743 index 8383b2b..6397efb 100644
98744 --- a/net/core/skbuff.c
98745 +++ b/net/core/skbuff.c
98746 @@ -2003,7 +2003,7 @@ EXPORT_SYMBOL(__skb_checksum);
98747 __wsum skb_checksum(const struct sk_buff *skb, int offset,
98748 int len, __wsum csum)
98749 {
98750 - const struct skb_checksum_ops ops = {
98751 + static const struct skb_checksum_ops ops = {
98752 .update = csum_partial_ext,
98753 .combine = csum_block_add_ext,
98754 };
98755 @@ -3220,13 +3220,15 @@ void __init skb_init(void)
98756 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
98757 sizeof(struct sk_buff),
98758 0,
98759 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
98760 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
98761 + SLAB_NO_SANITIZE,
98762 NULL);
98763 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
98764 (2*sizeof(struct sk_buff)) +
98765 sizeof(atomic_t),
98766 0,
98767 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
98768 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
98769 + SLAB_NO_SANITIZE,
98770 NULL);
98771 }
98772
98773 diff --git a/net/core/sock.c b/net/core/sock.c
98774 index 664ee42..aaf9e6e 100644
98775 --- a/net/core/sock.c
98776 +++ b/net/core/sock.c
98777 @@ -442,7 +442,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
98778 struct sk_buff_head *list = &sk->sk_receive_queue;
98779
98780 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
98781 - atomic_inc(&sk->sk_drops);
98782 + atomic_inc_unchecked(&sk->sk_drops);
98783 trace_sock_rcvqueue_full(sk, skb);
98784 return -ENOMEM;
98785 }
98786 @@ -452,7 +452,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
98787 return err;
98788
98789 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
98790 - atomic_inc(&sk->sk_drops);
98791 + atomic_inc_unchecked(&sk->sk_drops);
98792 return -ENOBUFS;
98793 }
98794
98795 @@ -472,7 +472,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
98796 skb_dst_force(skb);
98797
98798 spin_lock_irqsave(&list->lock, flags);
98799 - skb->dropcount = atomic_read(&sk->sk_drops);
98800 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
98801 __skb_queue_tail(list, skb);
98802 spin_unlock_irqrestore(&list->lock, flags);
98803
98804 @@ -492,7 +492,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
98805 skb->dev = NULL;
98806
98807 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
98808 - atomic_inc(&sk->sk_drops);
98809 + atomic_inc_unchecked(&sk->sk_drops);
98810 goto discard_and_relse;
98811 }
98812 if (nested)
98813 @@ -510,7 +510,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
98814 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
98815 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
98816 bh_unlock_sock(sk);
98817 - atomic_inc(&sk->sk_drops);
98818 + atomic_inc_unchecked(&sk->sk_drops);
98819 goto discard_and_relse;
98820 }
98821
98822 @@ -998,12 +998,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
98823 struct timeval tm;
98824 } v;
98825
98826 - int lv = sizeof(int);
98827 - int len;
98828 + unsigned int lv = sizeof(int);
98829 + unsigned int len;
98830
98831 if (get_user(len, optlen))
98832 return -EFAULT;
98833 - if (len < 0)
98834 + if (len > INT_MAX)
98835 return -EINVAL;
98836
98837 memset(&v, 0, sizeof(v));
98838 @@ -1155,11 +1155,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
98839
98840 case SO_PEERNAME:
98841 {
98842 - char address[128];
98843 + char address[_K_SS_MAXSIZE];
98844
98845 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
98846 return -ENOTCONN;
98847 - if (lv < len)
98848 + if (lv < len || sizeof address < len)
98849 return -EINVAL;
98850 if (copy_to_user(optval, address, len))
98851 return -EFAULT;
98852 @@ -1240,7 +1240,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
98853
98854 if (len > lv)
98855 len = lv;
98856 - if (copy_to_user(optval, &v, len))
98857 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
98858 return -EFAULT;
98859 lenout:
98860 if (put_user(len, optlen))
98861 @@ -2375,7 +2375,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
98862 */
98863 smp_wmb();
98864 atomic_set(&sk->sk_refcnt, 1);
98865 - atomic_set(&sk->sk_drops, 0);
98866 + atomic_set_unchecked(&sk->sk_drops, 0);
98867 }
98868 EXPORT_SYMBOL(sock_init_data);
98869
98870 @@ -2503,6 +2503,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
98871 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
98872 int level, int type)
98873 {
98874 + struct sock_extended_err ee;
98875 struct sock_exterr_skb *serr;
98876 struct sk_buff *skb, *skb2;
98877 int copied, err;
98878 @@ -2524,7 +2525,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
98879 sock_recv_timestamp(msg, sk, skb);
98880
98881 serr = SKB_EXT_ERR(skb);
98882 - put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
98883 + ee = serr->ee;
98884 + put_cmsg(msg, level, type, sizeof ee, &ee);
98885
98886 msg->msg_flags |= MSG_ERRQUEUE;
98887 err = copied;
98888 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
98889 index a4216a4..1c07687 100644
98890 --- a/net/core/sock_diag.c
98891 +++ b/net/core/sock_diag.c
98892 @@ -9,26 +9,33 @@
98893 #include <linux/inet_diag.h>
98894 #include <linux/sock_diag.h>
98895
98896 -static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
98897 +static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
98898 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
98899 static DEFINE_MUTEX(sock_diag_table_mutex);
98900
98901 int sock_diag_check_cookie(void *sk, __u32 *cookie)
98902 {
98903 +#ifndef CONFIG_GRKERNSEC_HIDESYM
98904 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
98905 cookie[1] != INET_DIAG_NOCOOKIE) &&
98906 ((u32)(unsigned long)sk != cookie[0] ||
98907 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
98908 return -ESTALE;
98909 else
98910 +#endif
98911 return 0;
98912 }
98913 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
98914
98915 void sock_diag_save_cookie(void *sk, __u32 *cookie)
98916 {
98917 +#ifdef CONFIG_GRKERNSEC_HIDESYM
98918 + cookie[0] = 0;
98919 + cookie[1] = 0;
98920 +#else
98921 cookie[0] = (u32)(unsigned long)sk;
98922 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
98923 +#endif
98924 }
98925 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
98926
98927 @@ -110,8 +117,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
98928 mutex_lock(&sock_diag_table_mutex);
98929 if (sock_diag_handlers[hndl->family])
98930 err = -EBUSY;
98931 - else
98932 + else {
98933 + pax_open_kernel();
98934 sock_diag_handlers[hndl->family] = hndl;
98935 + pax_close_kernel();
98936 + }
98937 mutex_unlock(&sock_diag_table_mutex);
98938
98939 return err;
98940 @@ -127,7 +137,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
98941
98942 mutex_lock(&sock_diag_table_mutex);
98943 BUG_ON(sock_diag_handlers[family] != hnld);
98944 + pax_open_kernel();
98945 sock_diag_handlers[family] = NULL;
98946 + pax_close_kernel();
98947 mutex_unlock(&sock_diag_table_mutex);
98948 }
98949 EXPORT_SYMBOL_GPL(sock_diag_unregister);
98950 diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
98951 index cf9cd13..8b56af3 100644
98952 --- a/net/core/sysctl_net_core.c
98953 +++ b/net/core/sysctl_net_core.c
98954 @@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
98955 {
98956 unsigned int orig_size, size;
98957 int ret, i;
98958 - struct ctl_table tmp = {
98959 + ctl_table_no_const tmp = {
98960 .data = &size,
98961 .maxlen = sizeof(size),
98962 .mode = table->mode
98963 @@ -200,7 +200,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
98964 void __user *buffer, size_t *lenp, loff_t *ppos)
98965 {
98966 char id[IFNAMSIZ];
98967 - struct ctl_table tbl = {
98968 + ctl_table_no_const tbl = {
98969 .data = id,
98970 .maxlen = IFNAMSIZ,
98971 };
98972 @@ -379,13 +379,12 @@ static struct ctl_table netns_core_table[] = {
98973
98974 static __net_init int sysctl_core_net_init(struct net *net)
98975 {
98976 - struct ctl_table *tbl;
98977 + ctl_table_no_const *tbl = NULL;
98978
98979 net->core.sysctl_somaxconn = SOMAXCONN;
98980
98981 - tbl = netns_core_table;
98982 if (!net_eq(net, &init_net)) {
98983 - tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
98984 + tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
98985 if (tbl == NULL)
98986 goto err_dup;
98987
98988 @@ -395,17 +394,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
98989 if (net->user_ns != &init_user_ns) {
98990 tbl[0].procname = NULL;
98991 }
98992 - }
98993 -
98994 - net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
98995 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
98996 + } else
98997 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
98998 if (net->core.sysctl_hdr == NULL)
98999 goto err_reg;
99000
99001 return 0;
99002
99003 err_reg:
99004 - if (tbl != netns_core_table)
99005 - kfree(tbl);
99006 + kfree(tbl);
99007 err_dup:
99008 return -ENOMEM;
99009 }
99010 @@ -420,7 +418,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
99011 kfree(tbl);
99012 }
99013
99014 -static __net_initdata struct pernet_operations sysctl_core_ops = {
99015 +static __net_initconst struct pernet_operations sysctl_core_ops = {
99016 .init = sysctl_core_net_init,
99017 .exit = sysctl_core_net_exit,
99018 };
99019 diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
99020 index 4c04848..f575934 100644
99021 --- a/net/decnet/af_decnet.c
99022 +++ b/net/decnet/af_decnet.c
99023 @@ -465,6 +465,7 @@ static struct proto dn_proto = {
99024 .sysctl_rmem = sysctl_decnet_rmem,
99025 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
99026 .obj_size = sizeof(struct dn_sock),
99027 + .slab_flags = SLAB_USERCOPY,
99028 };
99029
99030 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
99031 diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
99032 index 3b726f3..1af6368 100644
99033 --- a/net/decnet/dn_dev.c
99034 +++ b/net/decnet/dn_dev.c
99035 @@ -200,7 +200,7 @@ static struct dn_dev_sysctl_table {
99036 .extra1 = &min_t3,
99037 .extra2 = &max_t3
99038 },
99039 - {0}
99040 + { }
99041 },
99042 };
99043
99044 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
99045 index 5325b54..a0d4d69 100644
99046 --- a/net/decnet/sysctl_net_decnet.c
99047 +++ b/net/decnet/sysctl_net_decnet.c
99048 @@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
99049
99050 if (len > *lenp) len = *lenp;
99051
99052 - if (copy_to_user(buffer, addr, len))
99053 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
99054 return -EFAULT;
99055
99056 *lenp = len;
99057 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
99058
99059 if (len > *lenp) len = *lenp;
99060
99061 - if (copy_to_user(buffer, devname, len))
99062 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
99063 return -EFAULT;
99064
99065 *lenp = len;
99066 diff --git a/net/ieee802154/reassembly.c b/net/ieee802154/reassembly.c
99067 index ef2d543..5b9b73f 100644
99068 --- a/net/ieee802154/reassembly.c
99069 +++ b/net/ieee802154/reassembly.c
99070 @@ -434,12 +434,11 @@ static struct ctl_table lowpan_frags_ctl_table[] = {
99071
99072 static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
99073 {
99074 - struct ctl_table *table;
99075 + ctl_table_no_const *table = NULL;
99076 struct ctl_table_header *hdr;
99077
99078 - table = lowpan_frags_ns_ctl_table;
99079 if (!net_eq(net, &init_net)) {
99080 - table = kmemdup(table, sizeof(lowpan_frags_ns_ctl_table),
99081 + table = kmemdup(lowpan_frags_ns_ctl_table, sizeof(lowpan_frags_ns_ctl_table),
99082 GFP_KERNEL);
99083 if (table == NULL)
99084 goto err_alloc;
99085 @@ -452,9 +451,9 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
99086 /* Don't export sysctls to unprivileged users */
99087 if (net->user_ns != &init_user_ns)
99088 table[0].procname = NULL;
99089 - }
99090 -
99091 - hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
99092 + hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", table);
99093 + } else
99094 + hdr = register_net_sysctl(net, "net/ieee802154/6lowpan", lowpan_frags_ns_ctl_table);
99095 if (hdr == NULL)
99096 goto err_reg;
99097
99098 @@ -462,8 +461,7 @@ static int __net_init lowpan_frags_ns_sysctl_register(struct net *net)
99099 return 0;
99100
99101 err_reg:
99102 - if (!net_eq(net, &init_net))
99103 - kfree(table);
99104 + kfree(table);
99105 err_alloc:
99106 return -ENOMEM;
99107 }
99108 diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
99109 index 6d6dd34..e5c9bec 100644
99110 --- a/net/ipv4/af_inet.c
99111 +++ b/net/ipv4/af_inet.c
99112 @@ -1736,13 +1736,9 @@ static int __init inet_init(void)
99113
99114 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
99115
99116 - sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
99117 - if (!sysctl_local_reserved_ports)
99118 - goto out;
99119 -
99120 rc = proto_register(&tcp_prot, 1);
99121 if (rc)
99122 - goto out_free_reserved_ports;
99123 + goto out;
99124
99125 rc = proto_register(&udp_prot, 1);
99126 if (rc)
99127 @@ -1852,8 +1848,6 @@ out_unregister_udp_proto:
99128 proto_unregister(&udp_prot);
99129 out_unregister_tcp_proto:
99130 proto_unregister(&tcp_prot);
99131 -out_free_reserved_ports:
99132 - kfree(sysctl_local_reserved_ports);
99133 goto out;
99134 }
99135
99136 diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
99137 index bdbf68b..deb4759 100644
99138 --- a/net/ipv4/devinet.c
99139 +++ b/net/ipv4/devinet.c
99140 @@ -1543,7 +1543,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
99141 idx = 0;
99142 head = &net->dev_index_head[h];
99143 rcu_read_lock();
99144 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
99145 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
99146 net->dev_base_seq;
99147 hlist_for_each_entry_rcu(dev, head, index_hlist) {
99148 if (idx < s_idx)
99149 @@ -1861,7 +1861,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
99150 idx = 0;
99151 head = &net->dev_index_head[h];
99152 rcu_read_lock();
99153 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
99154 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
99155 net->dev_base_seq;
99156 hlist_for_each_entry_rcu(dev, head, index_hlist) {
99157 if (idx < s_idx)
99158 @@ -2096,7 +2096,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
99159 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
99160 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
99161
99162 -static struct devinet_sysctl_table {
99163 +static const struct devinet_sysctl_table {
99164 struct ctl_table_header *sysctl_header;
99165 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
99166 } devinet_sysctl = {
99167 @@ -2218,7 +2218,7 @@ static __net_init int devinet_init_net(struct net *net)
99168 int err;
99169 struct ipv4_devconf *all, *dflt;
99170 #ifdef CONFIG_SYSCTL
99171 - struct ctl_table *tbl = ctl_forward_entry;
99172 + ctl_table_no_const *tbl = NULL;
99173 struct ctl_table_header *forw_hdr;
99174 #endif
99175
99176 @@ -2236,7 +2236,7 @@ static __net_init int devinet_init_net(struct net *net)
99177 goto err_alloc_dflt;
99178
99179 #ifdef CONFIG_SYSCTL
99180 - tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
99181 + tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
99182 if (tbl == NULL)
99183 goto err_alloc_ctl;
99184
99185 @@ -2256,7 +2256,10 @@ static __net_init int devinet_init_net(struct net *net)
99186 goto err_reg_dflt;
99187
99188 err = -ENOMEM;
99189 - forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
99190 + if (!net_eq(net, &init_net))
99191 + forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
99192 + else
99193 + forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
99194 if (forw_hdr == NULL)
99195 goto err_reg_ctl;
99196 net->ipv4.forw_hdr = forw_hdr;
99197 @@ -2272,8 +2275,7 @@ err_reg_ctl:
99198 err_reg_dflt:
99199 __devinet_sysctl_unregister(all);
99200 err_reg_all:
99201 - if (tbl != ctl_forward_entry)
99202 - kfree(tbl);
99203 + kfree(tbl);
99204 err_alloc_ctl:
99205 #endif
99206 if (dflt != &ipv4_devconf_dflt)
99207 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
99208 index 255aa99..45c78f8 100644
99209 --- a/net/ipv4/fib_frontend.c
99210 +++ b/net/ipv4/fib_frontend.c
99211 @@ -1015,12 +1015,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
99212 #ifdef CONFIG_IP_ROUTE_MULTIPATH
99213 fib_sync_up(dev);
99214 #endif
99215 - atomic_inc(&net->ipv4.dev_addr_genid);
99216 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
99217 rt_cache_flush(dev_net(dev));
99218 break;
99219 case NETDEV_DOWN:
99220 fib_del_ifaddr(ifa, NULL);
99221 - atomic_inc(&net->ipv4.dev_addr_genid);
99222 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
99223 if (ifa->ifa_dev->ifa_list == NULL) {
99224 /* Last address was deleted from this interface.
99225 * Disable IP.
99226 @@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
99227 #ifdef CONFIG_IP_ROUTE_MULTIPATH
99228 fib_sync_up(dev);
99229 #endif
99230 - atomic_inc(&net->ipv4.dev_addr_genid);
99231 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
99232 rt_cache_flush(net);
99233 break;
99234 case NETDEV_DOWN:
99235 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
99236 index b10cd43a..22327f9 100644
99237 --- a/net/ipv4/fib_semantics.c
99238 +++ b/net/ipv4/fib_semantics.c
99239 @@ -768,7 +768,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
99240 nh->nh_saddr = inet_select_addr(nh->nh_dev,
99241 nh->nh_gw,
99242 nh->nh_parent->fib_scope);
99243 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
99244 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
99245
99246 return nh->nh_saddr;
99247 }
99248 diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
99249 index a56b8e6..5be2a30 100644
99250 --- a/net/ipv4/inet_connection_sock.c
99251 +++ b/net/ipv4/inet_connection_sock.c
99252 @@ -29,7 +29,7 @@ const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n";
99253 EXPORT_SYMBOL(inet_csk_timer_bug_msg);
99254 #endif
99255
99256 -unsigned long *sysctl_local_reserved_ports;
99257 +unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
99258 EXPORT_SYMBOL(sysctl_local_reserved_ports);
99259
99260 void inet_get_local_port_range(struct net *net, int *low, int *high)
99261 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
99262 index 8b9cf27..0d8d592 100644
99263 --- a/net/ipv4/inet_hashtables.c
99264 +++ b/net/ipv4/inet_hashtables.c
99265 @@ -18,6 +18,7 @@
99266 #include <linux/sched.h>
99267 #include <linux/slab.h>
99268 #include <linux/wait.h>
99269 +#include <linux/security.h>
99270
99271 #include <net/inet_connection_sock.h>
99272 #include <net/inet_hashtables.h>
99273 @@ -49,6 +50,8 @@ static unsigned int inet_sk_ehashfn(const struct sock *sk)
99274 return inet_ehashfn(net, laddr, lport, faddr, fport);
99275 }
99276
99277 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
99278 +
99279 /*
99280 * Allocate and initialize a new local port bind bucket.
99281 * The bindhash mutex for snum's hash chain must be held here.
99282 @@ -554,6 +557,8 @@ ok:
99283 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
99284 spin_unlock(&head->lock);
99285
99286 + gr_update_task_in_ip_table(current, inet_sk(sk));
99287 +
99288 if (tw) {
99289 inet_twsk_deschedule(tw, death_row);
99290 while (twrefcnt) {
99291 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
99292 index 48f4244..f56d83a 100644
99293 --- a/net/ipv4/inetpeer.c
99294 +++ b/net/ipv4/inetpeer.c
99295 @@ -496,8 +496,8 @@ relookup:
99296 if (p) {
99297 p->daddr = *daddr;
99298 atomic_set(&p->refcnt, 1);
99299 - atomic_set(&p->rid, 0);
99300 - atomic_set(&p->ip_id_count,
99301 + atomic_set_unchecked(&p->rid, 0);
99302 + atomic_set_unchecked(&p->ip_id_count,
99303 (daddr->family == AF_INET) ?
99304 secure_ip_id(daddr->addr.a4) :
99305 secure_ipv6_id(daddr->addr.a6));
99306 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
99307 index ed32313..3762abe 100644
99308 --- a/net/ipv4/ip_fragment.c
99309 +++ b/net/ipv4/ip_fragment.c
99310 @@ -284,7 +284,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
99311 return 0;
99312
99313 start = qp->rid;
99314 - end = atomic_inc_return(&peer->rid);
99315 + end = atomic_inc_return_unchecked(&peer->rid);
99316 qp->rid = end;
99317
99318 rc = qp->q.fragments && (end - start) > max;
99319 @@ -761,12 +761,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
99320
99321 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
99322 {
99323 - struct ctl_table *table;
99324 + ctl_table_no_const *table = NULL;
99325 struct ctl_table_header *hdr;
99326
99327 - table = ip4_frags_ns_ctl_table;
99328 if (!net_eq(net, &init_net)) {
99329 - table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
99330 + table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
99331 if (table == NULL)
99332 goto err_alloc;
99333
99334 @@ -777,9 +776,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
99335 /* Don't export sysctls to unprivileged users */
99336 if (net->user_ns != &init_user_ns)
99337 table[0].procname = NULL;
99338 - }
99339 + hdr = register_net_sysctl(net, "net/ipv4", table);
99340 + } else
99341 + hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
99342
99343 - hdr = register_net_sysctl(net, "net/ipv4", table);
99344 if (hdr == NULL)
99345 goto err_reg;
99346
99347 @@ -787,8 +787,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
99348 return 0;
99349
99350 err_reg:
99351 - if (!net_eq(net, &init_net))
99352 - kfree(table);
99353 + kfree(table);
99354 err_alloc:
99355 return -ENOMEM;
99356 }
99357 diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
99358 index 94213c8..8bdb342 100644
99359 --- a/net/ipv4/ip_gre.c
99360 +++ b/net/ipv4/ip_gre.c
99361 @@ -115,7 +115,7 @@ static bool log_ecn_error = true;
99362 module_param(log_ecn_error, bool, 0644);
99363 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
99364
99365 -static struct rtnl_link_ops ipgre_link_ops __read_mostly;
99366 +static struct rtnl_link_ops ipgre_link_ops;
99367 static int ipgre_tunnel_init(struct net_device *dev);
99368
99369 static int ipgre_net_id __read_mostly;
99370 @@ -732,7 +732,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
99371 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
99372 };
99373
99374 -static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
99375 +static struct rtnl_link_ops ipgre_link_ops = {
99376 .kind = "gre",
99377 .maxtype = IFLA_GRE_MAX,
99378 .policy = ipgre_policy,
99379 @@ -746,7 +746,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
99380 .fill_info = ipgre_fill_info,
99381 };
99382
99383 -static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
99384 +static struct rtnl_link_ops ipgre_tap_ops = {
99385 .kind = "gretap",
99386 .maxtype = IFLA_GRE_MAX,
99387 .policy = ipgre_policy,
99388 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
99389 index 64741b9..6f334a2 100644
99390 --- a/net/ipv4/ip_sockglue.c
99391 +++ b/net/ipv4/ip_sockglue.c
99392 @@ -1188,7 +1188,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
99393 len = min_t(unsigned int, len, opt->optlen);
99394 if (put_user(len, optlen))
99395 return -EFAULT;
99396 - if (copy_to_user(optval, opt->__data, len))
99397 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
99398 + copy_to_user(optval, opt->__data, len))
99399 return -EFAULT;
99400 return 0;
99401 }
99402 @@ -1319,7 +1320,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
99403 if (sk->sk_type != SOCK_STREAM)
99404 return -ENOPROTOOPT;
99405
99406 - msg.msg_control = optval;
99407 + msg.msg_control = (void __force_kernel *)optval;
99408 msg.msg_controllen = len;
99409 msg.msg_flags = flags;
99410
99411 diff --git a/net/ipv4/ip_tunnel.c b/net/ipv4/ip_tunnel.c
99412 index 2acc233..b93143f 100644
99413 --- a/net/ipv4/ip_tunnel.c
99414 +++ b/net/ipv4/ip_tunnel.c
99415 @@ -73,12 +73,7 @@ static void __tunnel_dst_set(struct ip_tunnel_dst *idst,
99416 {
99417 struct dst_entry *old_dst;
99418
99419 - if (dst) {
99420 - if (dst->flags & DST_NOCACHE)
99421 - dst = NULL;
99422 - else
99423 - dst_clone(dst);
99424 - }
99425 + dst_clone(dst);
99426 old_dst = xchg((__force struct dst_entry **)&idst->dst, dst);
99427 dst_release(old_dst);
99428 }
99429 @@ -108,13 +103,14 @@ static struct rtable *tunnel_rtable_get(struct ip_tunnel *t, u32 cookie)
99430
99431 rcu_read_lock();
99432 dst = rcu_dereference(this_cpu_ptr(t->dst_cache)->dst);
99433 + if (dst && !atomic_inc_not_zero(&dst->__refcnt))
99434 + dst = NULL;
99435 if (dst) {
99436 if (dst->obsolete && dst->ops->check(dst, cookie) == NULL) {
99437 - rcu_read_unlock();
99438 tunnel_dst_reset(t);
99439 - return NULL;
99440 + dst_release(dst);
99441 + dst = NULL;
99442 }
99443 - dst_hold(dst);
99444 }
99445 rcu_read_unlock();
99446 return (struct rtable *)dst;
99447 diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
99448 index 13ef00f..8ffca25 100644
99449 --- a/net/ipv4/ip_vti.c
99450 +++ b/net/ipv4/ip_vti.c
99451 @@ -45,7 +45,7 @@
99452 #include <net/net_namespace.h>
99453 #include <net/netns/generic.h>
99454
99455 -static struct rtnl_link_ops vti_link_ops __read_mostly;
99456 +static struct rtnl_link_ops vti_link_ops;
99457
99458 static int vti_net_id __read_mostly;
99459 static int vti_tunnel_init(struct net_device *dev);
99460 @@ -513,7 +513,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
99461 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
99462 };
99463
99464 -static struct rtnl_link_ops vti_link_ops __read_mostly = {
99465 +static struct rtnl_link_ops vti_link_ops = {
99466 .kind = "vti",
99467 .maxtype = IFLA_VTI_MAX,
99468 .policy = vti_policy,
99469 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
99470 index b3e86ea..18ce98c 100644
99471 --- a/net/ipv4/ipconfig.c
99472 +++ b/net/ipv4/ipconfig.c
99473 @@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
99474
99475 mm_segment_t oldfs = get_fs();
99476 set_fs(get_ds());
99477 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
99478 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
99479 set_fs(oldfs);
99480 return res;
99481 }
99482 @@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
99483
99484 mm_segment_t oldfs = get_fs();
99485 set_fs(get_ds());
99486 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
99487 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
99488 set_fs(oldfs);
99489 return res;
99490 }
99491 @@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
99492
99493 mm_segment_t oldfs = get_fs();
99494 set_fs(get_ds());
99495 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
99496 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
99497 set_fs(oldfs);
99498 return res;
99499 }
99500 diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
99501 index 62eaa00..29b2dc2 100644
99502 --- a/net/ipv4/ipip.c
99503 +++ b/net/ipv4/ipip.c
99504 @@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
99505 static int ipip_net_id __read_mostly;
99506
99507 static int ipip_tunnel_init(struct net_device *dev);
99508 -static struct rtnl_link_ops ipip_link_ops __read_mostly;
99509 +static struct rtnl_link_ops ipip_link_ops;
99510
99511 static int ipip_err(struct sk_buff *skb, u32 info)
99512 {
99513 @@ -409,7 +409,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
99514 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
99515 };
99516
99517 -static struct rtnl_link_ops ipip_link_ops __read_mostly = {
99518 +static struct rtnl_link_ops ipip_link_ops = {
99519 .kind = "ipip",
99520 .maxtype = IFLA_IPTUN_MAX,
99521 .policy = ipip_policy,
99522 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
99523 index f95b6f9..2ee2097 100644
99524 --- a/net/ipv4/netfilter/arp_tables.c
99525 +++ b/net/ipv4/netfilter/arp_tables.c
99526 @@ -885,14 +885,14 @@ static int compat_table_info(const struct xt_table_info *info,
99527 #endif
99528
99529 static int get_info(struct net *net, void __user *user,
99530 - const int *len, int compat)
99531 + int len, int compat)
99532 {
99533 char name[XT_TABLE_MAXNAMELEN];
99534 struct xt_table *t;
99535 int ret;
99536
99537 - if (*len != sizeof(struct arpt_getinfo)) {
99538 - duprintf("length %u != %Zu\n", *len,
99539 + if (len != sizeof(struct arpt_getinfo)) {
99540 + duprintf("length %u != %Zu\n", len,
99541 sizeof(struct arpt_getinfo));
99542 return -EINVAL;
99543 }
99544 @@ -929,7 +929,7 @@ static int get_info(struct net *net, void __user *user,
99545 info.size = private->size;
99546 strcpy(info.name, name);
99547
99548 - if (copy_to_user(user, &info, *len) != 0)
99549 + if (copy_to_user(user, &info, len) != 0)
99550 ret = -EFAULT;
99551 else
99552 ret = 0;
99553 @@ -1690,7 +1690,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
99554
99555 switch (cmd) {
99556 case ARPT_SO_GET_INFO:
99557 - ret = get_info(sock_net(sk), user, len, 1);
99558 + ret = get_info(sock_net(sk), user, *len, 1);
99559 break;
99560 case ARPT_SO_GET_ENTRIES:
99561 ret = compat_get_entries(sock_net(sk), user, len);
99562 @@ -1735,7 +1735,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
99563
99564 switch (cmd) {
99565 case ARPT_SO_GET_INFO:
99566 - ret = get_info(sock_net(sk), user, len, 0);
99567 + ret = get_info(sock_net(sk), user, *len, 0);
99568 break;
99569
99570 case ARPT_SO_GET_ENTRIES:
99571 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
99572 index 99e810f..3711b81 100644
99573 --- a/net/ipv4/netfilter/ip_tables.c
99574 +++ b/net/ipv4/netfilter/ip_tables.c
99575 @@ -1073,14 +1073,14 @@ static int compat_table_info(const struct xt_table_info *info,
99576 #endif
99577
99578 static int get_info(struct net *net, void __user *user,
99579 - const int *len, int compat)
99580 + int len, int compat)
99581 {
99582 char name[XT_TABLE_MAXNAMELEN];
99583 struct xt_table *t;
99584 int ret;
99585
99586 - if (*len != sizeof(struct ipt_getinfo)) {
99587 - duprintf("length %u != %zu\n", *len,
99588 + if (len != sizeof(struct ipt_getinfo)) {
99589 + duprintf("length %u != %zu\n", len,
99590 sizeof(struct ipt_getinfo));
99591 return -EINVAL;
99592 }
99593 @@ -1117,7 +1117,7 @@ static int get_info(struct net *net, void __user *user,
99594 info.size = private->size;
99595 strcpy(info.name, name);
99596
99597 - if (copy_to_user(user, &info, *len) != 0)
99598 + if (copy_to_user(user, &info, len) != 0)
99599 ret = -EFAULT;
99600 else
99601 ret = 0;
99602 @@ -1973,7 +1973,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
99603
99604 switch (cmd) {
99605 case IPT_SO_GET_INFO:
99606 - ret = get_info(sock_net(sk), user, len, 1);
99607 + ret = get_info(sock_net(sk), user, *len, 1);
99608 break;
99609 case IPT_SO_GET_ENTRIES:
99610 ret = compat_get_entries(sock_net(sk), user, len);
99611 @@ -2020,7 +2020,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
99612
99613 switch (cmd) {
99614 case IPT_SO_GET_INFO:
99615 - ret = get_info(sock_net(sk), user, len, 0);
99616 + ret = get_info(sock_net(sk), user, *len, 0);
99617 break;
99618
99619 case IPT_SO_GET_ENTRIES:
99620 diff --git a/net/ipv4/netfilter/ipt_CLUSTERIP.c b/net/ipv4/netfilter/ipt_CLUSTERIP.c
99621 index 2510c02..cfb34fa 100644
99622 --- a/net/ipv4/netfilter/ipt_CLUSTERIP.c
99623 +++ b/net/ipv4/netfilter/ipt_CLUSTERIP.c
99624 @@ -720,7 +720,7 @@ static int clusterip_net_init(struct net *net)
99625 spin_lock_init(&cn->lock);
99626
99627 #ifdef CONFIG_PROC_FS
99628 - cn->procdir = proc_mkdir("ipt_CLUSTERIP", net->proc_net);
99629 + cn->procdir = proc_mkdir_restrict("ipt_CLUSTERIP", net->proc_net);
99630 if (!cn->procdir) {
99631 pr_err("Unable to proc dir entry\n");
99632 return -ENOMEM;
99633 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
99634 index 044a0dd..e0c1971 100644
99635 --- a/net/ipv4/ping.c
99636 +++ b/net/ipv4/ping.c
99637 @@ -59,7 +59,7 @@ struct ping_table {
99638 };
99639
99640 static struct ping_table ping_table;
99641 -struct pingv6_ops pingv6_ops;
99642 +struct pingv6_ops *pingv6_ops;
99643 EXPORT_SYMBOL_GPL(pingv6_ops);
99644
99645 static u16 ping_port_rover;
99646 @@ -348,7 +348,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
99647 return -ENODEV;
99648 }
99649 }
99650 - has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
99651 + has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
99652 scoped);
99653 rcu_read_unlock();
99654
99655 @@ -556,7 +556,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
99656 }
99657 #if IS_ENABLED(CONFIG_IPV6)
99658 } else if (skb->protocol == htons(ETH_P_IPV6)) {
99659 - harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
99660 + harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
99661 #endif
99662 }
99663
99664 @@ -574,7 +574,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
99665 info, (u8 *)icmph);
99666 #if IS_ENABLED(CONFIG_IPV6)
99667 } else if (family == AF_INET6) {
99668 - pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
99669 + pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
99670 info, (u8 *)icmph);
99671 #endif
99672 }
99673 @@ -844,6 +844,8 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99674 {
99675 struct inet_sock *isk = inet_sk(sk);
99676 int family = sk->sk_family;
99677 + struct sockaddr_in *sin;
99678 + struct sockaddr_in6 *sin6;
99679 struct sk_buff *skb;
99680 int copied, err;
99681
99682 @@ -853,12 +855,19 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99683 if (flags & MSG_OOB)
99684 goto out;
99685
99686 + if (addr_len) {
99687 + if (family == AF_INET)
99688 + *addr_len = sizeof(*sin);
99689 + else if (family == AF_INET6 && addr_len)
99690 + *addr_len = sizeof(*sin6);
99691 + }
99692 +
99693 if (flags & MSG_ERRQUEUE) {
99694 if (family == AF_INET) {
99695 return ip_recv_error(sk, msg, len, addr_len);
99696 #if IS_ENABLED(CONFIG_IPV6)
99697 } else if (family == AF_INET6) {
99698 - return pingv6_ops.ipv6_recv_error(sk, msg, len,
99699 + return pingv6_ops->ipv6_recv_error(sk, msg, len,
99700 addr_len);
99701 #endif
99702 }
99703 @@ -890,7 +899,6 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99704 sin->sin_port = 0 /* skb->h.uh->source */;
99705 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
99706 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
99707 - *addr_len = sizeof(*sin);
99708 }
99709
99710 if (isk->cmsg_flags)
99711 @@ -912,14 +920,13 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99712 sin6->sin6_scope_id =
99713 ipv6_iface_scope_id(&sin6->sin6_addr,
99714 IP6CB(skb)->iif);
99715 - *addr_len = sizeof(*sin6);
99716 }
99717
99718 if (inet6_sk(sk)->rxopt.all)
99719 - pingv6_ops.ip6_datagram_recv_common_ctl(sk, msg, skb);
99720 + pingv6_ops->ip6_datagram_recv_common_ctl(sk, msg, skb);
99721 if (skb->protocol == htons(ETH_P_IPV6) &&
99722 inet6_sk(sk)->rxopt.all)
99723 - pingv6_ops.ip6_datagram_recv_specific_ctl(sk, msg, skb);
99724 + pingv6_ops->ip6_datagram_recv_specific_ctl(sk, msg, skb);
99725 else if (skb->protocol == htons(ETH_P_IP) && isk->cmsg_flags)
99726 ip_cmsg_recv(msg, skb);
99727 #endif
99728 @@ -1111,7 +1118,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
99729 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
99730 0, sock_i_ino(sp),
99731 atomic_read(&sp->sk_refcnt), sp,
99732 - atomic_read(&sp->sk_drops));
99733 + atomic_read_unchecked(&sp->sk_drops));
99734 }
99735
99736 static int ping_v4_seq_show(struct seq_file *seq, void *v)
99737 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
99738 index a9dbe58..46f577f 100644
99739 --- a/net/ipv4/raw.c
99740 +++ b/net/ipv4/raw.c
99741 @@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
99742 int raw_rcv(struct sock *sk, struct sk_buff *skb)
99743 {
99744 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
99745 - atomic_inc(&sk->sk_drops);
99746 + atomic_inc_unchecked(&sk->sk_drops);
99747 kfree_skb(skb);
99748 return NET_RX_DROP;
99749 }
99750 @@ -696,6 +696,9 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99751 if (flags & MSG_OOB)
99752 goto out;
99753
99754 + if (addr_len)
99755 + *addr_len = sizeof(*sin);
99756 +
99757 if (flags & MSG_ERRQUEUE) {
99758 err = ip_recv_error(sk, msg, len, addr_len);
99759 goto out;
99760 @@ -723,7 +726,6 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
99761 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
99762 sin->sin_port = 0;
99763 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
99764 - *addr_len = sizeof(*sin);
99765 }
99766 if (inet->cmsg_flags)
99767 ip_cmsg_recv(msg, skb);
99768 @@ -748,16 +750,20 @@ static int raw_init(struct sock *sk)
99769
99770 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
99771 {
99772 + struct icmp_filter filter;
99773 +
99774 if (optlen > sizeof(struct icmp_filter))
99775 optlen = sizeof(struct icmp_filter);
99776 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
99777 + if (copy_from_user(&filter, optval, optlen))
99778 return -EFAULT;
99779 + raw_sk(sk)->filter = filter;
99780 return 0;
99781 }
99782
99783 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
99784 {
99785 int len, ret = -EFAULT;
99786 + struct icmp_filter filter;
99787
99788 if (get_user(len, optlen))
99789 goto out;
99790 @@ -767,8 +773,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
99791 if (len > sizeof(struct icmp_filter))
99792 len = sizeof(struct icmp_filter);
99793 ret = -EFAULT;
99794 - if (put_user(len, optlen) ||
99795 - copy_to_user(optval, &raw_sk(sk)->filter, len))
99796 + filter = raw_sk(sk)->filter;
99797 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
99798 goto out;
99799 ret = 0;
99800 out: return ret;
99801 @@ -997,7 +1003,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
99802 0, 0L, 0,
99803 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
99804 0, sock_i_ino(sp),
99805 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
99806 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
99807 }
99808
99809 static int raw_seq_show(struct seq_file *seq, void *v)
99810 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
99811 index 5e676be..f6c62f1 100644
99812 --- a/net/ipv4/route.c
99813 +++ b/net/ipv4/route.c
99814 @@ -227,7 +227,7 @@ static const struct seq_operations rt_cache_seq_ops = {
99815
99816 static int rt_cache_seq_open(struct inode *inode, struct file *file)
99817 {
99818 - return seq_open(file, &rt_cache_seq_ops);
99819 + return seq_open_restrict(file, &rt_cache_seq_ops);
99820 }
99821
99822 static const struct file_operations rt_cache_seq_fops = {
99823 @@ -318,7 +318,7 @@ static const struct seq_operations rt_cpu_seq_ops = {
99824
99825 static int rt_cpu_seq_open(struct inode *inode, struct file *file)
99826 {
99827 - return seq_open(file, &rt_cpu_seq_ops);
99828 + return seq_open_restrict(file, &rt_cpu_seq_ops);
99829 }
99830
99831 static const struct file_operations rt_cpu_seq_fops = {
99832 @@ -356,7 +356,7 @@ static int rt_acct_proc_show(struct seq_file *m, void *v)
99833
99834 static int rt_acct_proc_open(struct inode *inode, struct file *file)
99835 {
99836 - return single_open(file, rt_acct_proc_show, NULL);
99837 + return single_open_restrict(file, rt_acct_proc_show, NULL);
99838 }
99839
99840 static const struct file_operations rt_acct_proc_fops = {
99841 @@ -2610,34 +2610,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
99842 .maxlen = sizeof(int),
99843 .mode = 0200,
99844 .proc_handler = ipv4_sysctl_rtcache_flush,
99845 + .extra1 = &init_net,
99846 },
99847 { },
99848 };
99849
99850 static __net_init int sysctl_route_net_init(struct net *net)
99851 {
99852 - struct ctl_table *tbl;
99853 + ctl_table_no_const *tbl = NULL;
99854
99855 - tbl = ipv4_route_flush_table;
99856 if (!net_eq(net, &init_net)) {
99857 - tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
99858 + tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
99859 if (tbl == NULL)
99860 goto err_dup;
99861
99862 /* Don't export sysctls to unprivileged users */
99863 if (net->user_ns != &init_user_ns)
99864 tbl[0].procname = NULL;
99865 - }
99866 - tbl[0].extra1 = net;
99867 + tbl[0].extra1 = net;
99868 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
99869 + } else
99870 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
99871
99872 - net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
99873 if (net->ipv4.route_hdr == NULL)
99874 goto err_reg;
99875 return 0;
99876
99877 err_reg:
99878 - if (tbl != ipv4_route_flush_table)
99879 - kfree(tbl);
99880 + kfree(tbl);
99881 err_dup:
99882 return -ENOMEM;
99883 }
99884 @@ -2660,8 +2660,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
99885
99886 static __net_init int rt_genid_init(struct net *net)
99887 {
99888 - atomic_set(&net->ipv4.rt_genid, 0);
99889 - atomic_set(&net->fnhe_genid, 0);
99890 + atomic_set_unchecked(&net->ipv4.rt_genid, 0);
99891 + atomic_set_unchecked(&net->fnhe_genid, 0);
99892 get_random_bytes(&net->ipv4.dev_addr_genid,
99893 sizeof(net->ipv4.dev_addr_genid));
99894 return 0;
99895 diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
99896 index 5cde8f2..5f5684e 100644
99897 --- a/net/ipv4/sysctl_net_ipv4.c
99898 +++ b/net/ipv4/sysctl_net_ipv4.c
99899 @@ -60,7 +60,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
99900 container_of(table->data, struct net, ipv4.ip_local_ports.range);
99901 int ret;
99902 int range[2];
99903 - struct ctl_table tmp = {
99904 + ctl_table_no_const tmp = {
99905 .data = &range,
99906 .maxlen = sizeof(range),
99907 .mode = table->mode,
99908 @@ -118,7 +118,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
99909 int ret;
99910 gid_t urange[2];
99911 kgid_t low, high;
99912 - struct ctl_table tmp = {
99913 + ctl_table_no_const tmp = {
99914 .data = &urange,
99915 .maxlen = sizeof(urange),
99916 .mode = table->mode,
99917 @@ -149,7 +149,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
99918 void __user *buffer, size_t *lenp, loff_t *ppos)
99919 {
99920 char val[TCP_CA_NAME_MAX];
99921 - struct ctl_table tbl = {
99922 + ctl_table_no_const tbl = {
99923 .data = val,
99924 .maxlen = TCP_CA_NAME_MAX,
99925 };
99926 @@ -168,7 +168,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
99927 void __user *buffer, size_t *lenp,
99928 loff_t *ppos)
99929 {
99930 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
99931 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
99932 int ret;
99933
99934 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
99935 @@ -185,7 +185,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
99936 void __user *buffer, size_t *lenp,
99937 loff_t *ppos)
99938 {
99939 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
99940 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
99941 int ret;
99942
99943 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
99944 @@ -204,7 +204,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
99945 void __user *buffer, size_t *lenp,
99946 loff_t *ppos)
99947 {
99948 - struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
99949 + ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
99950 struct tcp_fastopen_context *ctxt;
99951 int ret;
99952 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
99953 @@ -438,7 +438,7 @@ static struct ctl_table ipv4_table[] = {
99954 },
99955 {
99956 .procname = "ip_local_reserved_ports",
99957 - .data = NULL, /* initialized in sysctl_ipv4_init */
99958 + .data = sysctl_local_reserved_ports,
99959 .maxlen = 65536,
99960 .mode = 0644,
99961 .proc_handler = proc_do_large_bitmap,
99962 @@ -843,13 +843,12 @@ static struct ctl_table ipv4_net_table[] = {
99963
99964 static __net_init int ipv4_sysctl_init_net(struct net *net)
99965 {
99966 - struct ctl_table *table;
99967 + ctl_table_no_const *table = NULL;
99968
99969 - table = ipv4_net_table;
99970 if (!net_eq(net, &init_net)) {
99971 int i;
99972
99973 - table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
99974 + table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
99975 if (table == NULL)
99976 goto err_alloc;
99977
99978 @@ -858,15 +857,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
99979 table[i].data += (void *)net - (void *)&init_net;
99980 }
99981
99982 - net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
99983 + if (!net_eq(net, &init_net))
99984 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
99985 + else
99986 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
99987 if (net->ipv4.ipv4_hdr == NULL)
99988 goto err_reg;
99989
99990 return 0;
99991
99992 err_reg:
99993 - if (!net_eq(net, &init_net))
99994 - kfree(table);
99995 + kfree(table);
99996 err_alloc:
99997 return -ENOMEM;
99998 }
99999 @@ -888,16 +889,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
100000 static __init int sysctl_ipv4_init(void)
100001 {
100002 struct ctl_table_header *hdr;
100003 - struct ctl_table *i;
100004 -
100005 - for (i = ipv4_table; i->procname; i++) {
100006 - if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
100007 - i->data = sysctl_local_reserved_ports;
100008 - break;
100009 - }
100010 - }
100011 - if (!i->procname)
100012 - return -EINVAL;
100013
100014 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
100015 if (hdr == NULL)
100016 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
100017 index 3a26b3b..8bbe4ae 100644
100018 --- a/net/ipv4/tcp_input.c
100019 +++ b/net/ipv4/tcp_input.c
100020 @@ -754,7 +754,7 @@ static void tcp_update_pacing_rate(struct sock *sk)
100021 * without any lock. We want to make sure compiler wont store
100022 * intermediate values in this location.
100023 */
100024 - ACCESS_ONCE(sk->sk_pacing_rate) = min_t(u64, rate,
100025 + ACCESS_ONCE_RW(sk->sk_pacing_rate) = min_t(u64, rate,
100026 sk->sk_max_pacing_rate);
100027 }
100028
100029 @@ -4478,7 +4478,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
100030 * simplifies code)
100031 */
100032 static void
100033 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
100034 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
100035 struct sk_buff *head, struct sk_buff *tail,
100036 u32 start, u32 end)
100037 {
100038 @@ -5558,6 +5558,7 @@ discard:
100039 tcp_paws_reject(&tp->rx_opt, 0))
100040 goto discard_and_undo;
100041
100042 +#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
100043 if (th->syn) {
100044 /* We see SYN without ACK. It is attempt of
100045 * simultaneous connect with crossed SYNs.
100046 @@ -5608,6 +5609,7 @@ discard:
100047 goto discard;
100048 #endif
100049 }
100050 +#endif
100051 /* "fifth, if neither of the SYN or RST bits is set then
100052 * drop the segment and return."
100053 */
100054 @@ -5654,7 +5656,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
100055 goto discard;
100056
100057 if (th->syn) {
100058 - if (th->fin)
100059 + if (th->fin || th->urg || th->psh)
100060 goto discard;
100061 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
100062 return 1;
100063 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
100064 index 438f3b9..bc9e1ad 100644
100065 --- a/net/ipv4/tcp_ipv4.c
100066 +++ b/net/ipv4/tcp_ipv4.c
100067 @@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
100068 EXPORT_SYMBOL(sysctl_tcp_low_latency);
100069
100070
100071 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100072 +extern int grsec_enable_blackhole;
100073 +#endif
100074 +
100075 #ifdef CONFIG_TCP_MD5SIG
100076 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
100077 __be32 daddr, __be32 saddr, const struct tcphdr *th);
100078 @@ -1829,6 +1833,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
100079 return 0;
100080
100081 reset:
100082 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100083 + if (!grsec_enable_blackhole)
100084 +#endif
100085 tcp_v4_send_reset(rsk, skb);
100086 discard:
100087 kfree_skb(skb);
100088 @@ -1974,12 +1981,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
100089 TCP_SKB_CB(skb)->sacked = 0;
100090
100091 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
100092 - if (!sk)
100093 + if (!sk) {
100094 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100095 + ret = 1;
100096 +#endif
100097 goto no_tcp_socket;
100098 -
100099 + }
100100 process:
100101 - if (sk->sk_state == TCP_TIME_WAIT)
100102 + if (sk->sk_state == TCP_TIME_WAIT) {
100103 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100104 + ret = 2;
100105 +#endif
100106 goto do_time_wait;
100107 + }
100108
100109 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
100110 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
100111 @@ -2033,6 +2047,10 @@ csum_error:
100112 bad_packet:
100113 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
100114 } else {
100115 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100116 + if (!grsec_enable_blackhole || (ret == 1 &&
100117 + (skb->dev->flags & IFF_LOOPBACK)))
100118 +#endif
100119 tcp_v4_send_reset(NULL, skb);
100120 }
100121
100122 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
100123 index 05c1b15..3e9344b 100644
100124 --- a/net/ipv4/tcp_minisocks.c
100125 +++ b/net/ipv4/tcp_minisocks.c
100126 @@ -27,6 +27,10 @@
100127 #include <net/inet_common.h>
100128 #include <net/xfrm.h>
100129
100130 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100131 +extern int grsec_enable_blackhole;
100132 +#endif
100133 +
100134 int sysctl_tcp_syncookies __read_mostly = 1;
100135 EXPORT_SYMBOL(sysctl_tcp_syncookies);
100136
100137 @@ -709,7 +713,10 @@ embryonic_reset:
100138 * avoid becoming vulnerable to outside attack aiming at
100139 * resetting legit local connections.
100140 */
100141 - req->rsk_ops->send_reset(sk, skb);
100142 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100143 + if (!grsec_enable_blackhole)
100144 +#endif
100145 + req->rsk_ops->send_reset(sk, skb);
100146 } else if (fastopen) { /* received a valid RST pkt */
100147 reqsk_fastopen_remove(sk, req, true);
100148 tcp_reset(sk);
100149 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
100150 index 3b66610..bfbe23a 100644
100151 --- a/net/ipv4/tcp_probe.c
100152 +++ b/net/ipv4/tcp_probe.c
100153 @@ -238,7 +238,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
100154 if (cnt + width >= len)
100155 break;
100156
100157 - if (copy_to_user(buf + cnt, tbuf, width))
100158 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
100159 return -EFAULT;
100160 cnt += width;
100161 }
100162 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
100163 index 286227a..c495a76 100644
100164 --- a/net/ipv4/tcp_timer.c
100165 +++ b/net/ipv4/tcp_timer.c
100166 @@ -22,6 +22,10 @@
100167 #include <linux/gfp.h>
100168 #include <net/tcp.h>
100169
100170 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100171 +extern int grsec_lastack_retries;
100172 +#endif
100173 +
100174 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
100175 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
100176 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
100177 @@ -192,6 +196,13 @@ static int tcp_write_timeout(struct sock *sk)
100178 }
100179 }
100180
100181 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100182 + if ((sk->sk_state == TCP_LAST_ACK) &&
100183 + (grsec_lastack_retries > 0) &&
100184 + (grsec_lastack_retries < retry_until))
100185 + retry_until = grsec_lastack_retries;
100186 +#endif
100187 +
100188 if (retransmits_timed_out(sk, retry_until,
100189 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
100190 /* Has it gone just too far? */
100191 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
100192 index 54a5fe9..78fea00 100644
100193 --- a/net/ipv4/udp.c
100194 +++ b/net/ipv4/udp.c
100195 @@ -87,6 +87,7 @@
100196 #include <linux/types.h>
100197 #include <linux/fcntl.h>
100198 #include <linux/module.h>
100199 +#include <linux/security.h>
100200 #include <linux/socket.h>
100201 #include <linux/sockios.h>
100202 #include <linux/igmp.h>
100203 @@ -113,6 +114,10 @@
100204 #include <net/busy_poll.h>
100205 #include "udp_impl.h"
100206
100207 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100208 +extern int grsec_enable_blackhole;
100209 +#endif
100210 +
100211 struct udp_table udp_table __read_mostly;
100212 EXPORT_SYMBOL(udp_table);
100213
100214 @@ -615,6 +620,9 @@ found:
100215 return s;
100216 }
100217
100218 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
100219 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
100220 +
100221 /*
100222 * This routine is called by the ICMP module when it gets some
100223 * sort of error condition. If err < 0 then the socket should
100224 @@ -914,9 +922,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
100225 dport = usin->sin_port;
100226 if (dport == 0)
100227 return -EINVAL;
100228 +
100229 + err = gr_search_udp_sendmsg(sk, usin);
100230 + if (err)
100231 + return err;
100232 } else {
100233 if (sk->sk_state != TCP_ESTABLISHED)
100234 return -EDESTADDRREQ;
100235 +
100236 + err = gr_search_udp_sendmsg(sk, NULL);
100237 + if (err)
100238 + return err;
100239 +
100240 daddr = inet->inet_daddr;
100241 dport = inet->inet_dport;
100242 /* Open fast path for connected socket.
100243 @@ -1164,7 +1181,7 @@ static unsigned int first_packet_length(struct sock *sk)
100244 IS_UDPLITE(sk));
100245 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
100246 IS_UDPLITE(sk));
100247 - atomic_inc(&sk->sk_drops);
100248 + atomic_inc_unchecked(&sk->sk_drops);
100249 __skb_unlink(skb, rcvq);
100250 __skb_queue_tail(&list_kill, skb);
100251 }
100252 @@ -1235,6 +1252,12 @@ int udp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
100253 int is_udplite = IS_UDPLITE(sk);
100254 bool slow;
100255
100256 + /*
100257 + * Check any passed addresses
100258 + */
100259 + if (addr_len)
100260 + *addr_len = sizeof(*sin);
100261 +
100262 if (flags & MSG_ERRQUEUE)
100263 return ip_recv_error(sk, msg, len, addr_len);
100264
100265 @@ -1244,6 +1267,10 @@ try_again:
100266 if (!skb)
100267 goto out;
100268
100269 + err = gr_search_udp_recvmsg(sk, skb);
100270 + if (err)
100271 + goto out_free;
100272 +
100273 ulen = skb->len - sizeof(struct udphdr);
100274 copied = len;
100275 if (copied > ulen)
100276 @@ -1277,7 +1304,7 @@ try_again:
100277 if (unlikely(err)) {
100278 trace_kfree_skb(skb, udp_recvmsg);
100279 if (!peeked) {
100280 - atomic_inc(&sk->sk_drops);
100281 + atomic_inc_unchecked(&sk->sk_drops);
100282 UDP_INC_STATS_USER(sock_net(sk),
100283 UDP_MIB_INERRORS, is_udplite);
100284 }
100285 @@ -1296,7 +1323,6 @@ try_again:
100286 sin->sin_port = udp_hdr(skb)->source;
100287 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
100288 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
100289 - *addr_len = sizeof(*sin);
100290 }
100291 if (inet->cmsg_flags)
100292 ip_cmsg_recv(msg, skb);
100293 @@ -1567,7 +1593,7 @@ csum_error:
100294 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
100295 drop:
100296 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
100297 - atomic_inc(&sk->sk_drops);
100298 + atomic_inc_unchecked(&sk->sk_drops);
100299 kfree_skb(skb);
100300 return -1;
100301 }
100302 @@ -1586,7 +1612,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
100303 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
100304
100305 if (!skb1) {
100306 - atomic_inc(&sk->sk_drops);
100307 + atomic_inc_unchecked(&sk->sk_drops);
100308 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
100309 IS_UDPLITE(sk));
100310 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
100311 @@ -1787,6 +1813,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
100312 goto csum_error;
100313
100314 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
100315 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100316 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
100317 +#endif
100318 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
100319
100320 /*
100321 @@ -2355,7 +2384,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
100322 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
100323 0, sock_i_ino(sp),
100324 atomic_read(&sp->sk_refcnt), sp,
100325 - atomic_read(&sp->sk_drops));
100326 + atomic_read_unchecked(&sp->sk_drops));
100327 }
100328
100329 int udp4_seq_show(struct seq_file *seq, void *v)
100330 diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
100331 index 6156f68..d6ab46d 100644
100332 --- a/net/ipv4/xfrm4_policy.c
100333 +++ b/net/ipv4/xfrm4_policy.c
100334 @@ -186,11 +186,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
100335 fl4->flowi4_tos = iph->tos;
100336 }
100337
100338 -static inline int xfrm4_garbage_collect(struct dst_ops *ops)
100339 +static int xfrm4_garbage_collect(struct dst_ops *ops)
100340 {
100341 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
100342
100343 - xfrm4_policy_afinfo.garbage_collect(net);
100344 + xfrm_garbage_collect_deferred(net);
100345 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
100346 }
100347
100348 @@ -269,19 +269,18 @@ static struct ctl_table xfrm4_policy_table[] = {
100349
100350 static int __net_init xfrm4_net_init(struct net *net)
100351 {
100352 - struct ctl_table *table;
100353 + ctl_table_no_const *table = NULL;
100354 struct ctl_table_header *hdr;
100355
100356 - table = xfrm4_policy_table;
100357 if (!net_eq(net, &init_net)) {
100358 - table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
100359 + table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
100360 if (!table)
100361 goto err_alloc;
100362
100363 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
100364 - }
100365 -
100366 - hdr = register_net_sysctl(net, "net/ipv4", table);
100367 + hdr = register_net_sysctl(net, "net/ipv4", table);
100368 + } else
100369 + hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
100370 if (!hdr)
100371 goto err_reg;
100372
100373 @@ -289,8 +288,7 @@ static int __net_init xfrm4_net_init(struct net *net)
100374 return 0;
100375
100376 err_reg:
100377 - if (!net_eq(net, &init_net))
100378 - kfree(table);
100379 + kfree(table);
100380 err_alloc:
100381 return -ENOMEM;
100382 }
100383 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
100384 index 6c7fa08..8a31430 100644
100385 --- a/net/ipv6/addrconf.c
100386 +++ b/net/ipv6/addrconf.c
100387 @@ -598,7 +598,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
100388 idx = 0;
100389 head = &net->dev_index_head[h];
100390 rcu_read_lock();
100391 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
100392 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
100393 net->dev_base_seq;
100394 hlist_for_each_entry_rcu(dev, head, index_hlist) {
100395 if (idx < s_idx)
100396 @@ -2395,7 +2395,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
100397 p.iph.ihl = 5;
100398 p.iph.protocol = IPPROTO_IPV6;
100399 p.iph.ttl = 64;
100400 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
100401 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
100402
100403 if (ops->ndo_do_ioctl) {
100404 mm_segment_t oldfs = get_fs();
100405 @@ -3528,16 +3528,23 @@ static const struct file_operations if6_fops = {
100406 .release = seq_release_net,
100407 };
100408
100409 +extern void register_ipv6_seq_ops_addr(struct seq_operations *addr);
100410 +extern void unregister_ipv6_seq_ops_addr(void);
100411 +
100412 static int __net_init if6_proc_net_init(struct net *net)
100413 {
100414 - if (!proc_create("if_inet6", S_IRUGO, net->proc_net, &if6_fops))
100415 + register_ipv6_seq_ops_addr(&if6_seq_ops);
100416 + if (!proc_create("if_inet6", S_IRUGO, net->proc_net, &if6_fops)) {
100417 + unregister_ipv6_seq_ops_addr();
100418 return -ENOMEM;
100419 + }
100420 return 0;
100421 }
100422
100423 static void __net_exit if6_proc_net_exit(struct net *net)
100424 {
100425 remove_proc_entry("if_inet6", net->proc_net);
100426 + unregister_ipv6_seq_ops_addr();
100427 }
100428
100429 static struct pernet_operations if6_proc_net_ops = {
100430 @@ -4146,7 +4153,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
100431 s_ip_idx = ip_idx = cb->args[2];
100432
100433 rcu_read_lock();
100434 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
100435 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
100436 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
100437 idx = 0;
100438 head = &net->dev_index_head[h];
100439 @@ -4758,7 +4765,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
100440 dst_free(&ifp->rt->dst);
100441 break;
100442 }
100443 - atomic_inc(&net->ipv6.dev_addr_genid);
100444 + atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
100445 rt_genid_bump_ipv6(net);
100446 }
100447
100448 @@ -4779,7 +4786,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
100449 int *valp = ctl->data;
100450 int val = *valp;
100451 loff_t pos = *ppos;
100452 - struct ctl_table lctl;
100453 + ctl_table_no_const lctl;
100454 int ret;
100455
100456 /*
100457 @@ -4864,7 +4871,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
100458 int *valp = ctl->data;
100459 int val = *valp;
100460 loff_t pos = *ppos;
100461 - struct ctl_table lctl;
100462 + ctl_table_no_const lctl;
100463 int ret;
100464
100465 /*
100466 diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
100467 index d935889..2f64330 100644
100468 --- a/net/ipv6/af_inet6.c
100469 +++ b/net/ipv6/af_inet6.c
100470 @@ -776,7 +776,7 @@ static int __net_init inet6_net_init(struct net *net)
100471 net->ipv6.sysctl.bindv6only = 0;
100472 net->ipv6.sysctl.icmpv6_time = 1*HZ;
100473 net->ipv6.sysctl.flowlabel_consistency = 1;
100474 - atomic_set(&net->ipv6.rt_genid, 0);
100475 + atomic_set_unchecked(&net->ipv6.rt_genid, 0);
100476
100477 err = ipv6_init_mibs(net);
100478 if (err)
100479 diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
100480 index c3bf2d2..1f00573 100644
100481 --- a/net/ipv6/datagram.c
100482 +++ b/net/ipv6/datagram.c
100483 @@ -938,5 +938,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
100484 0,
100485 sock_i_ino(sp),
100486 atomic_read(&sp->sk_refcnt), sp,
100487 - atomic_read(&sp->sk_drops));
100488 + atomic_read_unchecked(&sp->sk_drops));
100489 }
100490 diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
100491 index 7b32652..0bc348b 100644
100492 --- a/net/ipv6/icmp.c
100493 +++ b/net/ipv6/icmp.c
100494 @@ -1005,7 +1005,7 @@ static struct ctl_table ipv6_icmp_table_template[] = {
100495
100496 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
100497 {
100498 - struct ctl_table *table;
100499 + ctl_table_no_const *table;
100500
100501 table = kmemdup(ipv6_icmp_table_template,
100502 sizeof(ipv6_icmp_table_template),
100503 diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
100504 index 9d92146..d986c6a 100644
100505 --- a/net/ipv6/ip6_gre.c
100506 +++ b/net/ipv6/ip6_gre.c
100507 @@ -71,7 +71,7 @@ struct ip6gre_net {
100508 struct net_device *fb_tunnel_dev;
100509 };
100510
100511 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
100512 +static struct rtnl_link_ops ip6gre_link_ops;
100513 static int ip6gre_tunnel_init(struct net_device *dev);
100514 static void ip6gre_tunnel_setup(struct net_device *dev);
100515 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
100516 @@ -1291,7 +1291,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
100517 }
100518
100519
100520 -static struct inet6_protocol ip6gre_protocol __read_mostly = {
100521 +static struct inet6_protocol ip6gre_protocol = {
100522 .handler = ip6gre_rcv,
100523 .err_handler = ip6gre_err,
100524 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
100525 @@ -1636,7 +1636,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
100526 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
100527 };
100528
100529 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
100530 +static struct rtnl_link_ops ip6gre_link_ops = {
100531 .kind = "ip6gre",
100532 .maxtype = IFLA_GRE_MAX,
100533 .policy = ip6gre_policy,
100534 @@ -1650,7 +1650,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
100535 .fill_info = ip6gre_fill_info,
100536 };
100537
100538 -static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
100539 +static struct rtnl_link_ops ip6gre_tap_ops = {
100540 .kind = "ip6gretap",
100541 .maxtype = IFLA_GRE_MAX,
100542 .policy = ip6gre_policy,
100543 diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
100544 index afa0824..04ba530 100644
100545 --- a/net/ipv6/ip6_tunnel.c
100546 +++ b/net/ipv6/ip6_tunnel.c
100547 @@ -86,7 +86,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
100548
100549 static int ip6_tnl_dev_init(struct net_device *dev);
100550 static void ip6_tnl_dev_setup(struct net_device *dev);
100551 -static struct rtnl_link_ops ip6_link_ops __read_mostly;
100552 +static struct rtnl_link_ops ip6_link_ops;
100553
100554 static int ip6_tnl_net_id __read_mostly;
100555 struct ip6_tnl_net {
100556 @@ -1708,7 +1708,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
100557 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
100558 };
100559
100560 -static struct rtnl_link_ops ip6_link_ops __read_mostly = {
100561 +static struct rtnl_link_ops ip6_link_ops = {
100562 .kind = "ip6tnl",
100563 .maxtype = IFLA_IPTUN_MAX,
100564 .policy = ip6_tnl_policy,
100565 diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
100566 index 6cc9f93..6e5bb7c 100644
100567 --- a/net/ipv6/ip6_vti.c
100568 +++ b/net/ipv6/ip6_vti.c
100569 @@ -62,7 +62,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
100570
100571 static int vti6_dev_init(struct net_device *dev);
100572 static void vti6_dev_setup(struct net_device *dev);
100573 -static struct rtnl_link_ops vti6_link_ops __read_mostly;
100574 +static struct rtnl_link_ops vti6_link_ops;
100575
100576 static int vti6_net_id __read_mostly;
100577 struct vti6_net {
100578 @@ -980,7 +980,7 @@ static const struct nla_policy vti6_policy[IFLA_VTI_MAX + 1] = {
100579 [IFLA_VTI_OKEY] = { .type = NLA_U32 },
100580 };
100581
100582 -static struct rtnl_link_ops vti6_link_ops __read_mostly = {
100583 +static struct rtnl_link_ops vti6_link_ops = {
100584 .kind = "vti6",
100585 .maxtype = IFLA_VTI_MAX,
100586 .policy = vti6_policy,
100587 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
100588 index edb58af..78de133 100644
100589 --- a/net/ipv6/ipv6_sockglue.c
100590 +++ b/net/ipv6/ipv6_sockglue.c
100591 @@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
100592 if (sk->sk_type != SOCK_STREAM)
100593 return -ENOPROTOOPT;
100594
100595 - msg.msg_control = optval;
100596 + msg.msg_control = (void __force_kernel *)optval;
100597 msg.msg_controllen = len;
100598 msg.msg_flags = flags;
100599
100600 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
100601 index e080fbb..412b3cf 100644
100602 --- a/net/ipv6/netfilter/ip6_tables.c
100603 +++ b/net/ipv6/netfilter/ip6_tables.c
100604 @@ -1083,14 +1083,14 @@ static int compat_table_info(const struct xt_table_info *info,
100605 #endif
100606
100607 static int get_info(struct net *net, void __user *user,
100608 - const int *len, int compat)
100609 + int len, int compat)
100610 {
100611 char name[XT_TABLE_MAXNAMELEN];
100612 struct xt_table *t;
100613 int ret;
100614
100615 - if (*len != sizeof(struct ip6t_getinfo)) {
100616 - duprintf("length %u != %zu\n", *len,
100617 + if (len != sizeof(struct ip6t_getinfo)) {
100618 + duprintf("length %u != %zu\n", len,
100619 sizeof(struct ip6t_getinfo));
100620 return -EINVAL;
100621 }
100622 @@ -1127,7 +1127,7 @@ static int get_info(struct net *net, void __user *user,
100623 info.size = private->size;
100624 strcpy(info.name, name);
100625
100626 - if (copy_to_user(user, &info, *len) != 0)
100627 + if (copy_to_user(user, &info, len) != 0)
100628 ret = -EFAULT;
100629 else
100630 ret = 0;
100631 @@ -1983,7 +1983,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
100632
100633 switch (cmd) {
100634 case IP6T_SO_GET_INFO:
100635 - ret = get_info(sock_net(sk), user, len, 1);
100636 + ret = get_info(sock_net(sk), user, *len, 1);
100637 break;
100638 case IP6T_SO_GET_ENTRIES:
100639 ret = compat_get_entries(sock_net(sk), user, len);
100640 @@ -2030,7 +2030,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
100641
100642 switch (cmd) {
100643 case IP6T_SO_GET_INFO:
100644 - ret = get_info(sock_net(sk), user, len, 0);
100645 + ret = get_info(sock_net(sk), user, *len, 0);
100646 break;
100647
100648 case IP6T_SO_GET_ENTRIES:
100649 diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
100650 index 767ab8d..c5ec70a 100644
100651 --- a/net/ipv6/netfilter/nf_conntrack_reasm.c
100652 +++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
100653 @@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
100654
100655 static int nf_ct_frag6_sysctl_register(struct net *net)
100656 {
100657 - struct ctl_table *table;
100658 + ctl_table_no_const *table = NULL;
100659 struct ctl_table_header *hdr;
100660
100661 - table = nf_ct_frag6_sysctl_table;
100662 if (!net_eq(net, &init_net)) {
100663 - table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
100664 + table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
100665 GFP_KERNEL);
100666 if (table == NULL)
100667 goto err_alloc;
100668 @@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
100669 table[0].data = &net->nf_frag.frags.timeout;
100670 table[1].data = &net->nf_frag.frags.low_thresh;
100671 table[2].data = &net->nf_frag.frags.high_thresh;
100672 - }
100673 -
100674 - hdr = register_net_sysctl(net, "net/netfilter", table);
100675 + hdr = register_net_sysctl(net, "net/netfilter", table);
100676 + } else
100677 + hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
100678 if (hdr == NULL)
100679 goto err_reg;
100680
100681 @@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
100682 return 0;
100683
100684 err_reg:
100685 - if (!net_eq(net, &init_net))
100686 - kfree(table);
100687 + kfree(table);
100688 err_alloc:
100689 return -ENOMEM;
100690 }
100691 diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c
100692 index 56596ce..c734618 100644
100693 --- a/net/ipv6/output_core.c
100694 +++ b/net/ipv6/output_core.c
100695 @@ -10,7 +10,7 @@
100696
100697 void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
100698 {
100699 - static atomic_t ipv6_fragmentation_id;
100700 + static atomic_unchecked_t ipv6_fragmentation_id;
100701 struct in6_addr addr;
100702 int ident;
100703
100704 @@ -26,7 +26,7 @@ void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
100705 return;
100706 }
100707 #endif
100708 - ident = atomic_inc_return(&ipv6_fragmentation_id);
100709 + ident = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
100710
100711 addr = rt->rt6i_dst.addr;
100712 addr.s6_addr32[0] ^= (__force __be32)ident;
100713 diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
100714 index bda7429..469b26b 100644
100715 --- a/net/ipv6/ping.c
100716 +++ b/net/ipv6/ping.c
100717 @@ -246,6 +246,24 @@ static struct pernet_operations ping_v6_net_ops = {
100718 };
100719 #endif
100720
100721 +static struct pingv6_ops real_pingv6_ops = {
100722 + .ipv6_recv_error = ipv6_recv_error,
100723 + .ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl,
100724 + .ip6_datagram_recv_specific_ctl = ip6_datagram_recv_specific_ctl,
100725 + .icmpv6_err_convert = icmpv6_err_convert,
100726 + .ipv6_icmp_error = ipv6_icmp_error,
100727 + .ipv6_chk_addr = ipv6_chk_addr,
100728 +};
100729 +
100730 +static struct pingv6_ops dummy_pingv6_ops = {
100731 + .ipv6_recv_error = dummy_ipv6_recv_error,
100732 + .ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl,
100733 + .ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl,
100734 + .icmpv6_err_convert = dummy_icmpv6_err_convert,
100735 + .ipv6_icmp_error = dummy_ipv6_icmp_error,
100736 + .ipv6_chk_addr = dummy_ipv6_chk_addr,
100737 +};
100738 +
100739 int __init pingv6_init(void)
100740 {
100741 #ifdef CONFIG_PROC_FS
100742 @@ -253,13 +271,7 @@ int __init pingv6_init(void)
100743 if (ret)
100744 return ret;
100745 #endif
100746 - pingv6_ops.ipv6_recv_error = ipv6_recv_error;
100747 - pingv6_ops.ip6_datagram_recv_common_ctl = ip6_datagram_recv_common_ctl;
100748 - pingv6_ops.ip6_datagram_recv_specific_ctl =
100749 - ip6_datagram_recv_specific_ctl;
100750 - pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
100751 - pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
100752 - pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
100753 + pingv6_ops = &real_pingv6_ops;
100754 return inet6_register_protosw(&pingv6_protosw);
100755 }
100756
100757 @@ -268,14 +280,9 @@ int __init pingv6_init(void)
100758 */
100759 void pingv6_exit(void)
100760 {
100761 - pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
100762 - pingv6_ops.ip6_datagram_recv_common_ctl = dummy_ip6_datagram_recv_ctl;
100763 - pingv6_ops.ip6_datagram_recv_specific_ctl = dummy_ip6_datagram_recv_ctl;
100764 - pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
100765 - pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
100766 - pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
100767 #ifdef CONFIG_PROC_FS
100768 unregister_pernet_subsys(&ping_v6_net_ops);
100769 #endif
100770 + pingv6_ops = &dummy_pingv6_ops;
100771 inet6_unregister_protosw(&pingv6_protosw);
100772 }
100773 diff --git a/net/ipv6/proc.c b/net/ipv6/proc.c
100774 index 091d066..139d410 100644
100775 --- a/net/ipv6/proc.c
100776 +++ b/net/ipv6/proc.c
100777 @@ -309,7 +309,7 @@ static int __net_init ipv6_proc_init_net(struct net *net)
100778 if (!proc_create("snmp6", S_IRUGO, net->proc_net, &snmp6_seq_fops))
100779 goto proc_snmp6_fail;
100780
100781 - net->mib.proc_net_devsnmp6 = proc_mkdir("dev_snmp6", net->proc_net);
100782 + net->mib.proc_net_devsnmp6 = proc_mkdir_restrict("dev_snmp6", net->proc_net);
100783 if (!net->mib.proc_net_devsnmp6)
100784 goto proc_dev_snmp6_fail;
100785 return 0;
100786 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
100787 index 1f29996..46fe0c7 100644
100788 --- a/net/ipv6/raw.c
100789 +++ b/net/ipv6/raw.c
100790 @@ -388,7 +388,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
100791 {
100792 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
100793 skb_checksum_complete(skb)) {
100794 - atomic_inc(&sk->sk_drops);
100795 + atomic_inc_unchecked(&sk->sk_drops);
100796 kfree_skb(skb);
100797 return NET_RX_DROP;
100798 }
100799 @@ -416,7 +416,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
100800 struct raw6_sock *rp = raw6_sk(sk);
100801
100802 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
100803 - atomic_inc(&sk->sk_drops);
100804 + atomic_inc_unchecked(&sk->sk_drops);
100805 kfree_skb(skb);
100806 return NET_RX_DROP;
100807 }
100808 @@ -440,7 +440,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
100809
100810 if (inet->hdrincl) {
100811 if (skb_checksum_complete(skb)) {
100812 - atomic_inc(&sk->sk_drops);
100813 + atomic_inc_unchecked(&sk->sk_drops);
100814 kfree_skb(skb);
100815 return NET_RX_DROP;
100816 }
100817 @@ -469,6 +469,9 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
100818 if (flags & MSG_OOB)
100819 return -EOPNOTSUPP;
100820
100821 + if (addr_len)
100822 + *addr_len=sizeof(*sin6);
100823 +
100824 if (flags & MSG_ERRQUEUE)
100825 return ipv6_recv_error(sk, msg, len, addr_len);
100826
100827 @@ -507,7 +510,6 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
100828 sin6->sin6_flowinfo = 0;
100829 sin6->sin6_scope_id = ipv6_iface_scope_id(&sin6->sin6_addr,
100830 IP6CB(skb)->iif);
100831 - *addr_len = sizeof(*sin6);
100832 }
100833
100834 sock_recv_ts_and_drops(msg, sk, skb);
100835 @@ -610,7 +612,7 @@ out:
100836 return err;
100837 }
100838
100839 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
100840 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
100841 struct flowi6 *fl6, struct dst_entry **dstp,
100842 unsigned int flags)
100843 {
100844 @@ -922,12 +924,15 @@ do_confirm:
100845 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
100846 char __user *optval, int optlen)
100847 {
100848 + struct icmp6_filter filter;
100849 +
100850 switch (optname) {
100851 case ICMPV6_FILTER:
100852 if (optlen > sizeof(struct icmp6_filter))
100853 optlen = sizeof(struct icmp6_filter);
100854 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
100855 + if (copy_from_user(&filter, optval, optlen))
100856 return -EFAULT;
100857 + raw6_sk(sk)->filter = filter;
100858 return 0;
100859 default:
100860 return -ENOPROTOOPT;
100861 @@ -940,6 +945,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
100862 char __user *optval, int __user *optlen)
100863 {
100864 int len;
100865 + struct icmp6_filter filter;
100866
100867 switch (optname) {
100868 case ICMPV6_FILTER:
100869 @@ -951,7 +957,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
100870 len = sizeof(struct icmp6_filter);
100871 if (put_user(len, optlen))
100872 return -EFAULT;
100873 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
100874 + filter = raw6_sk(sk)->filter;
100875 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
100876 return -EFAULT;
100877 return 0;
100878 default:
100879 diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
100880 index cc85a9b..526a133 100644
100881 --- a/net/ipv6/reassembly.c
100882 +++ b/net/ipv6/reassembly.c
100883 @@ -626,12 +626,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
100884
100885 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
100886 {
100887 - struct ctl_table *table;
100888 + ctl_table_no_const *table = NULL;
100889 struct ctl_table_header *hdr;
100890
100891 - table = ip6_frags_ns_ctl_table;
100892 if (!net_eq(net, &init_net)) {
100893 - table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
100894 + table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
100895 if (table == NULL)
100896 goto err_alloc;
100897
100898 @@ -642,9 +641,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
100899 /* Don't export sysctls to unprivileged users */
100900 if (net->user_ns != &init_user_ns)
100901 table[0].procname = NULL;
100902 - }
100903 + hdr = register_net_sysctl(net, "net/ipv6", table);
100904 + } else
100905 + hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
100906
100907 - hdr = register_net_sysctl(net, "net/ipv6", table);
100908 if (hdr == NULL)
100909 goto err_reg;
100910
100911 @@ -652,8 +652,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
100912 return 0;
100913
100914 err_reg:
100915 - if (!net_eq(net, &init_net))
100916 - kfree(table);
100917 + kfree(table);
100918 err_alloc:
100919 return -ENOMEM;
100920 }
100921 diff --git a/net/ipv6/route.c b/net/ipv6/route.c
100922 index 6ebdb7b6..f225ab1 100644
100923 --- a/net/ipv6/route.c
100924 +++ b/net/ipv6/route.c
100925 @@ -2971,7 +2971,7 @@ struct ctl_table ipv6_route_table_template[] = {
100926
100927 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
100928 {
100929 - struct ctl_table *table;
100930 + ctl_table_no_const *table;
100931
100932 table = kmemdup(ipv6_route_table_template,
100933 sizeof(ipv6_route_table_template),
100934 diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
100935 index 4f40817..54dcbef 100644
100936 --- a/net/ipv6/sit.c
100937 +++ b/net/ipv6/sit.c
100938 @@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
100939 static void ipip6_dev_free(struct net_device *dev);
100940 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
100941 __be32 *v4dst);
100942 -static struct rtnl_link_ops sit_link_ops __read_mostly;
100943 +static struct rtnl_link_ops sit_link_ops;
100944
100945 static int sit_net_id __read_mostly;
100946 struct sit_net {
100947 @@ -1661,7 +1661,7 @@ static void ipip6_dellink(struct net_device *dev, struct list_head *head)
100948 unregister_netdevice_queue(dev, head);
100949 }
100950
100951 -static struct rtnl_link_ops sit_link_ops __read_mostly = {
100952 +static struct rtnl_link_ops sit_link_ops = {
100953 .kind = "sit",
100954 .maxtype = IFLA_IPTUN_MAX,
100955 .policy = ipip6_policy,
100956 diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
100957 index 7f405a1..eabef92 100644
100958 --- a/net/ipv6/sysctl_net_ipv6.c
100959 +++ b/net/ipv6/sysctl_net_ipv6.c
100960 @@ -54,7 +54,7 @@ static struct ctl_table ipv6_rotable[] = {
100961
100962 static int __net_init ipv6_sysctl_net_init(struct net *net)
100963 {
100964 - struct ctl_table *ipv6_table;
100965 + ctl_table_no_const *ipv6_table;
100966 struct ctl_table *ipv6_route_table;
100967 struct ctl_table *ipv6_icmp_table;
100968 int err;
100969 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
100970 index e289830..79a5718 100644
100971 --- a/net/ipv6/tcp_ipv6.c
100972 +++ b/net/ipv6/tcp_ipv6.c
100973 @@ -102,6 +102,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
100974 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
100975 }
100976
100977 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100978 +extern int grsec_enable_blackhole;
100979 +#endif
100980 +
100981 static void tcp_v6_hash(struct sock *sk)
100982 {
100983 if (sk->sk_state != TCP_CLOSE) {
100984 @@ -1416,6 +1420,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
100985 return 0;
100986
100987 reset:
100988 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
100989 + if (!grsec_enable_blackhole)
100990 +#endif
100991 tcp_v6_send_reset(sk, skb);
100992 discard:
100993 if (opt_skb)
100994 @@ -1500,12 +1507,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
100995 TCP_SKB_CB(skb)->sacked = 0;
100996
100997 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
100998 - if (!sk)
100999 + if (!sk) {
101000 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
101001 + ret = 1;
101002 +#endif
101003 goto no_tcp_socket;
101004 + }
101005
101006 process:
101007 - if (sk->sk_state == TCP_TIME_WAIT)
101008 + if (sk->sk_state == TCP_TIME_WAIT) {
101009 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
101010 + ret = 2;
101011 +#endif
101012 goto do_time_wait;
101013 + }
101014
101015 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
101016 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
101017 @@ -1557,6 +1572,10 @@ csum_error:
101018 bad_packet:
101019 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
101020 } else {
101021 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
101022 + if (!grsec_enable_blackhole || (ret == 1 &&
101023 + (skb->dev->flags & IFF_LOOPBACK)))
101024 +#endif
101025 tcp_v6_send_reset(NULL, skb);
101026 }
101027
101028 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
101029 index 20b63d2..13be908 100644
101030 --- a/net/ipv6/udp.c
101031 +++ b/net/ipv6/udp.c
101032 @@ -76,6 +76,10 @@ static unsigned int udp6_ehashfn(struct net *net,
101033 udp_ipv6_hash_secret + net_hash_mix(net));
101034 }
101035
101036 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
101037 +extern int grsec_enable_blackhole;
101038 +#endif
101039 +
101040 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
101041 {
101042 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
101043 @@ -392,6 +396,9 @@ int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk,
101044 int is_udp4;
101045 bool slow;
101046
101047 + if (addr_len)
101048 + *addr_len = sizeof(struct sockaddr_in6);
101049 +
101050 if (flags & MSG_ERRQUEUE)
101051 return ipv6_recv_error(sk, msg, len, addr_len);
101052
101053 @@ -435,7 +442,7 @@ try_again:
101054 if (unlikely(err)) {
101055 trace_kfree_skb(skb, udpv6_recvmsg);
101056 if (!peeked) {
101057 - atomic_inc(&sk->sk_drops);
101058 + atomic_inc_unchecked(&sk->sk_drops);
101059 if (is_udp4)
101060 UDP_INC_STATS_USER(sock_net(sk),
101061 UDP_MIB_INERRORS,
101062 @@ -475,7 +482,7 @@ try_again:
101063 ipv6_iface_scope_id(&sin6->sin6_addr,
101064 IP6CB(skb)->iif);
101065 }
101066 - *addr_len = sizeof(*sin6);
101067 +
101068 }
101069
101070 if (np->rxopt.all)
101071 @@ -690,7 +697,7 @@ csum_error:
101072 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
101073 drop:
101074 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
101075 - atomic_inc(&sk->sk_drops);
101076 + atomic_inc_unchecked(&sk->sk_drops);
101077 kfree_skb(skb);
101078 return -1;
101079 }
101080 @@ -747,7 +754,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
101081 if (likely(skb1 == NULL))
101082 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
101083 if (!skb1) {
101084 - atomic_inc(&sk->sk_drops);
101085 + atomic_inc_unchecked(&sk->sk_drops);
101086 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
101087 IS_UDPLITE(sk));
101088 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
101089 @@ -886,6 +893,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
101090 goto csum_error;
101091
101092 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
101093 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
101094 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
101095 +#endif
101096 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
101097
101098 kfree_skb(skb);
101099 diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
101100 index 2a0bbda..d75ca57 100644
101101 --- a/net/ipv6/xfrm6_policy.c
101102 +++ b/net/ipv6/xfrm6_policy.c
101103 @@ -212,11 +212,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
101104 }
101105 }
101106
101107 -static inline int xfrm6_garbage_collect(struct dst_ops *ops)
101108 +static int xfrm6_garbage_collect(struct dst_ops *ops)
101109 {
101110 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
101111
101112 - xfrm6_policy_afinfo.garbage_collect(net);
101113 + xfrm_garbage_collect_deferred(net);
101114 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
101115 }
101116
101117 @@ -329,19 +329,19 @@ static struct ctl_table xfrm6_policy_table[] = {
101118
101119 static int __net_init xfrm6_net_init(struct net *net)
101120 {
101121 - struct ctl_table *table;
101122 + ctl_table_no_const *table = NULL;
101123 struct ctl_table_header *hdr;
101124
101125 - table = xfrm6_policy_table;
101126 if (!net_eq(net, &init_net)) {
101127 - table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
101128 + table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
101129 if (!table)
101130 goto err_alloc;
101131
101132 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
101133 - }
101134 + hdr = register_net_sysctl(net, "net/ipv6", table);
101135 + } else
101136 + hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
101137
101138 - hdr = register_net_sysctl(net, "net/ipv6", table);
101139 if (!hdr)
101140 goto err_reg;
101141
101142 @@ -349,8 +349,7 @@ static int __net_init xfrm6_net_init(struct net *net)
101143 return 0;
101144
101145 err_reg:
101146 - if (!net_eq(net, &init_net))
101147 - kfree(table);
101148 + kfree(table);
101149 err_alloc:
101150 return -ENOMEM;
101151 }
101152 diff --git a/net/ipx/ipx_proc.c b/net/ipx/ipx_proc.c
101153 index e15c16a..7cf07aa 100644
101154 --- a/net/ipx/ipx_proc.c
101155 +++ b/net/ipx/ipx_proc.c
101156 @@ -289,7 +289,7 @@ int __init ipx_proc_init(void)
101157 struct proc_dir_entry *p;
101158 int rc = -ENOMEM;
101159
101160 - ipx_proc_dir = proc_mkdir("ipx", init_net.proc_net);
101161 + ipx_proc_dir = proc_mkdir_restrict("ipx", init_net.proc_net);
101162
101163 if (!ipx_proc_dir)
101164 goto out;
101165 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
101166 index 2ba8b97..6d33010 100644
101167 --- a/net/irda/ircomm/ircomm_tty.c
101168 +++ b/net/irda/ircomm/ircomm_tty.c
101169 @@ -317,11 +317,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
101170 add_wait_queue(&port->open_wait, &wait);
101171
101172 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
101173 - __FILE__, __LINE__, tty->driver->name, port->count);
101174 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
101175
101176 spin_lock_irqsave(&port->lock, flags);
101177 if (!tty_hung_up_p(filp))
101178 - port->count--;
101179 + atomic_dec(&port->count);
101180 port->blocked_open++;
101181 spin_unlock_irqrestore(&port->lock, flags);
101182
101183 @@ -356,7 +356,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
101184 }
101185
101186 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
101187 - __FILE__, __LINE__, tty->driver->name, port->count);
101188 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
101189
101190 schedule();
101191 }
101192 @@ -366,12 +366,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
101193
101194 spin_lock_irqsave(&port->lock, flags);
101195 if (!tty_hung_up_p(filp))
101196 - port->count++;
101197 + atomic_inc(&port->count);
101198 port->blocked_open--;
101199 spin_unlock_irqrestore(&port->lock, flags);
101200
101201 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
101202 - __FILE__, __LINE__, tty->driver->name, port->count);
101203 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
101204
101205 if (!retval)
101206 port->flags |= ASYNC_NORMAL_ACTIVE;
101207 @@ -445,12 +445,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
101208
101209 /* ++ is not atomic, so this should be protected - Jean II */
101210 spin_lock_irqsave(&self->port.lock, flags);
101211 - self->port.count++;
101212 + atomic_inc(&self->port.count);
101213 spin_unlock_irqrestore(&self->port.lock, flags);
101214 tty_port_tty_set(&self->port, tty);
101215
101216 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
101217 - self->line, self->port.count);
101218 + self->line, atomic_read(&self->port.count));
101219
101220 /* Not really used by us, but lets do it anyway */
101221 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
101222 @@ -987,7 +987,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
101223 tty_kref_put(port->tty);
101224 }
101225 port->tty = NULL;
101226 - port->count = 0;
101227 + atomic_set(&port->count, 0);
101228 spin_unlock_irqrestore(&port->lock, flags);
101229
101230 wake_up_interruptible(&port->open_wait);
101231 @@ -1344,7 +1344,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
101232 seq_putc(m, '\n');
101233
101234 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
101235 - seq_printf(m, "Open count: %d\n", self->port.count);
101236 + seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
101237 seq_printf(m, "Max data size: %d\n", self->max_data_size);
101238 seq_printf(m, "Max header size: %d\n", self->max_header_size);
101239
101240 diff --git a/net/irda/irproc.c b/net/irda/irproc.c
101241 index b9ac598..f88cc56 100644
101242 --- a/net/irda/irproc.c
101243 +++ b/net/irda/irproc.c
101244 @@ -66,7 +66,7 @@ void __init irda_proc_register(void)
101245 {
101246 int i;
101247
101248 - proc_irda = proc_mkdir("irda", init_net.proc_net);
101249 + proc_irda = proc_mkdir_restrict("irda", init_net.proc_net);
101250 if (proc_irda == NULL)
101251 return;
101252
101253 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
101254 index 8c9d730..66c6305 100644
101255 --- a/net/iucv/af_iucv.c
101256 +++ b/net/iucv/af_iucv.c
101257 @@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
101258
101259 write_lock_bh(&iucv_sk_list.lock);
101260
101261 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
101262 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
101263 while (__iucv_get_sock_by_name(name)) {
101264 sprintf(name, "%08x",
101265 - atomic_inc_return(&iucv_sk_list.autobind_name));
101266 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
101267 }
101268
101269 write_unlock_bh(&iucv_sk_list.lock);
101270 diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
101271 index da78793..bdd78cf 100644
101272 --- a/net/iucv/iucv.c
101273 +++ b/net/iucv/iucv.c
101274 @@ -702,7 +702,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
101275 return NOTIFY_OK;
101276 }
101277
101278 -static struct notifier_block __refdata iucv_cpu_notifier = {
101279 +static struct notifier_block iucv_cpu_notifier = {
101280 .notifier_call = iucv_cpu_notify,
101281 };
101282
101283 diff --git a/net/key/af_key.c b/net/key/af_key.c
101284 index f3c8307..7127791 100644
101285 --- a/net/key/af_key.c
101286 +++ b/net/key/af_key.c
101287 @@ -3070,10 +3070,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
101288 static u32 get_acqseq(void)
101289 {
101290 u32 res;
101291 - static atomic_t acqseq;
101292 + static atomic_unchecked_t acqseq;
101293
101294 do {
101295 - res = atomic_inc_return(&acqseq);
101296 + res = atomic_inc_return_unchecked(&acqseq);
101297 } while (!res);
101298 return res;
101299 }
101300 diff --git a/net/l2tp/l2tp_eth.c b/net/l2tp/l2tp_eth.c
101301 index 76125c5..e474828 100644
101302 --- a/net/l2tp/l2tp_eth.c
101303 +++ b/net/l2tp/l2tp_eth.c
101304 @@ -42,12 +42,12 @@ struct l2tp_eth {
101305 struct sock *tunnel_sock;
101306 struct l2tp_session *session;
101307 struct list_head list;
101308 - atomic_long_t tx_bytes;
101309 - atomic_long_t tx_packets;
101310 - atomic_long_t tx_dropped;
101311 - atomic_long_t rx_bytes;
101312 - atomic_long_t rx_packets;
101313 - atomic_long_t rx_errors;
101314 + atomic_long_unchecked_t tx_bytes;
101315 + atomic_long_unchecked_t tx_packets;
101316 + atomic_long_unchecked_t tx_dropped;
101317 + atomic_long_unchecked_t rx_bytes;
101318 + atomic_long_unchecked_t rx_packets;
101319 + atomic_long_unchecked_t rx_errors;
101320 };
101321
101322 /* via l2tp_session_priv() */
101323 @@ -98,10 +98,10 @@ static int l2tp_eth_dev_xmit(struct sk_buff *skb, struct net_device *dev)
101324 int ret = l2tp_xmit_skb(session, skb, session->hdr_len);
101325
101326 if (likely(ret == NET_XMIT_SUCCESS)) {
101327 - atomic_long_add(len, &priv->tx_bytes);
101328 - atomic_long_inc(&priv->tx_packets);
101329 + atomic_long_add_unchecked(len, &priv->tx_bytes);
101330 + atomic_long_inc_unchecked(&priv->tx_packets);
101331 } else {
101332 - atomic_long_inc(&priv->tx_dropped);
101333 + atomic_long_inc_unchecked(&priv->tx_dropped);
101334 }
101335 return NETDEV_TX_OK;
101336 }
101337 @@ -111,12 +111,12 @@ static struct rtnl_link_stats64 *l2tp_eth_get_stats64(struct net_device *dev,
101338 {
101339 struct l2tp_eth *priv = netdev_priv(dev);
101340
101341 - stats->tx_bytes = atomic_long_read(&priv->tx_bytes);
101342 - stats->tx_packets = atomic_long_read(&priv->tx_packets);
101343 - stats->tx_dropped = atomic_long_read(&priv->tx_dropped);
101344 - stats->rx_bytes = atomic_long_read(&priv->rx_bytes);
101345 - stats->rx_packets = atomic_long_read(&priv->rx_packets);
101346 - stats->rx_errors = atomic_long_read(&priv->rx_errors);
101347 + stats->tx_bytes = atomic_long_read_unchecked(&priv->tx_bytes);
101348 + stats->tx_packets = atomic_long_read_unchecked(&priv->tx_packets);
101349 + stats->tx_dropped = atomic_long_read_unchecked(&priv->tx_dropped);
101350 + stats->rx_bytes = atomic_long_read_unchecked(&priv->rx_bytes);
101351 + stats->rx_packets = atomic_long_read_unchecked(&priv->rx_packets);
101352 + stats->rx_errors = atomic_long_read_unchecked(&priv->rx_errors);
101353 return stats;
101354 }
101355
101356 @@ -166,15 +166,15 @@ static void l2tp_eth_dev_recv(struct l2tp_session *session, struct sk_buff *skb,
101357 nf_reset(skb);
101358
101359 if (dev_forward_skb(dev, skb) == NET_RX_SUCCESS) {
101360 - atomic_long_inc(&priv->rx_packets);
101361 - atomic_long_add(data_len, &priv->rx_bytes);
101362 + atomic_long_inc_unchecked(&priv->rx_packets);
101363 + atomic_long_add_unchecked(data_len, &priv->rx_bytes);
101364 } else {
101365 - atomic_long_inc(&priv->rx_errors);
101366 + atomic_long_inc_unchecked(&priv->rx_errors);
101367 }
101368 return;
101369
101370 error:
101371 - atomic_long_inc(&priv->rx_errors);
101372 + atomic_long_inc_unchecked(&priv->rx_errors);
101373 kfree_skb(skb);
101374 }
101375
101376 diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c
101377 index 3397fe6..861fd1a 100644
101378 --- a/net/l2tp/l2tp_ip.c
101379 +++ b/net/l2tp/l2tp_ip.c
101380 @@ -518,6 +518,9 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
101381 if (flags & MSG_OOB)
101382 goto out;
101383
101384 + if (addr_len)
101385 + *addr_len = sizeof(*sin);
101386 +
101387 skb = skb_recv_datagram(sk, flags, noblock, &err);
101388 if (!skb)
101389 goto out;
101390 @@ -540,7 +543,6 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
101391 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
101392 sin->sin_port = 0;
101393 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
101394 - *addr_len = sizeof(*sin);
101395 }
101396 if (inet->cmsg_flags)
101397 ip_cmsg_recv(msg, skb);
101398 diff --git a/net/llc/llc_proc.c b/net/llc/llc_proc.c
101399 index 1a3c7e0..80f8b0c 100644
101400 --- a/net/llc/llc_proc.c
101401 +++ b/net/llc/llc_proc.c
101402 @@ -247,7 +247,7 @@ int __init llc_proc_init(void)
101403 int rc = -ENOMEM;
101404 struct proc_dir_entry *p;
101405
101406 - llc_proc_dir = proc_mkdir("llc", init_net.proc_net);
101407 + llc_proc_dir = proc_mkdir_restrict("llc", init_net.proc_net);
101408 if (!llc_proc_dir)
101409 goto out;
101410
101411 diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
101412 index aaa59d7..21a2c4a 100644
101413 --- a/net/mac80211/cfg.c
101414 +++ b/net/mac80211/cfg.c
101415 @@ -839,7 +839,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
101416 ret = ieee80211_vif_use_channel(sdata, chandef,
101417 IEEE80211_CHANCTX_EXCLUSIVE);
101418 }
101419 - } else if (local->open_count == local->monitors) {
101420 + } else if (local_read(&local->open_count) == local->monitors) {
101421 local->_oper_chandef = *chandef;
101422 ieee80211_hw_config(local, 0);
101423 }
101424 @@ -3440,7 +3440,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
101425 else
101426 local->probe_req_reg--;
101427
101428 - if (!local->open_count)
101429 + if (!local_read(&local->open_count))
101430 break;
101431
101432 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
101433 @@ -3903,8 +3903,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
101434 if (chanctx_conf) {
101435 *chandef = chanctx_conf->def;
101436 ret = 0;
101437 - } else if (local->open_count > 0 &&
101438 - local->open_count == local->monitors &&
101439 + } else if (local_read(&local->open_count) > 0 &&
101440 + local_read(&local->open_count) == local->monitors &&
101441 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
101442 if (local->use_chanctx)
101443 *chandef = local->monitor_chandef;
101444 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
101445 index f169b6e..a5dc4eb 100644
101446 --- a/net/mac80211/ieee80211_i.h
101447 +++ b/net/mac80211/ieee80211_i.h
101448 @@ -28,6 +28,7 @@
101449 #include <net/ieee80211_radiotap.h>
101450 #include <net/cfg80211.h>
101451 #include <net/mac80211.h>
101452 +#include <asm/local.h>
101453 #include "key.h"
101454 #include "sta_info.h"
101455 #include "debug.h"
101456 @@ -999,7 +1000,7 @@ struct ieee80211_local {
101457 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
101458 spinlock_t queue_stop_reason_lock;
101459
101460 - int open_count;
101461 + local_t open_count;
101462 int monitors, cooked_mntrs;
101463 /* number of interfaces with corresponding FIF_ flags */
101464 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
101465 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
101466 index 34799e0..b411290 100644
101467 --- a/net/mac80211/iface.c
101468 +++ b/net/mac80211/iface.c
101469 @@ -524,7 +524,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
101470 break;
101471 }
101472
101473 - if (local->open_count == 0) {
101474 + if (local_read(&local->open_count) == 0) {
101475 res = drv_start(local);
101476 if (res)
101477 goto err_del_bss;
101478 @@ -571,7 +571,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
101479 res = drv_add_interface(local, sdata);
101480 if (res)
101481 goto err_stop;
101482 - } else if (local->monitors == 0 && local->open_count == 0) {
101483 + } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
101484 res = ieee80211_add_virtual_monitor(local);
101485 if (res)
101486 goto err_stop;
101487 @@ -680,7 +680,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
101488 atomic_inc(&local->iff_promiscs);
101489
101490 if (coming_up)
101491 - local->open_count++;
101492 + local_inc(&local->open_count);
101493
101494 if (hw_reconf_flags)
101495 ieee80211_hw_config(local, hw_reconf_flags);
101496 @@ -718,7 +718,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
101497 err_del_interface:
101498 drv_remove_interface(local, sdata);
101499 err_stop:
101500 - if (!local->open_count)
101501 + if (!local_read(&local->open_count))
101502 drv_stop(local);
101503 err_del_bss:
101504 sdata->bss = NULL;
101505 @@ -871,7 +871,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
101506 }
101507
101508 if (going_down)
101509 - local->open_count--;
101510 + local_dec(&local->open_count);
101511
101512 switch (sdata->vif.type) {
101513 case NL80211_IFTYPE_AP_VLAN:
101514 @@ -930,7 +930,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
101515 }
101516 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
101517
101518 - if (local->open_count == 0)
101519 + if (local_read(&local->open_count) == 0)
101520 ieee80211_clear_tx_pending(local);
101521
101522 /*
101523 @@ -970,7 +970,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
101524
101525 ieee80211_recalc_ps(local, -1);
101526
101527 - if (local->open_count == 0) {
101528 + if (local_read(&local->open_count) == 0) {
101529 ieee80211_stop_device(local);
101530
101531 /* no reconfiguring after stop! */
101532 @@ -981,7 +981,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
101533 ieee80211_configure_filter(local);
101534 ieee80211_hw_config(local, hw_reconf_flags);
101535
101536 - if (local->monitors == local->open_count)
101537 + if (local->monitors == local_read(&local->open_count))
101538 ieee80211_add_virtual_monitor(local);
101539 }
101540
101541 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
101542 index 4c1bf61..00b449b 100644
101543 --- a/net/mac80211/main.c
101544 +++ b/net/mac80211/main.c
101545 @@ -174,7 +174,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
101546 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
101547 IEEE80211_CONF_CHANGE_POWER);
101548
101549 - if (changed && local->open_count) {
101550 + if (changed && local_read(&local->open_count)) {
101551 ret = drv_config(local, changed);
101552 /*
101553 * Goal:
101554 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
101555 index d478b88..8c8d157 100644
101556 --- a/net/mac80211/pm.c
101557 +++ b/net/mac80211/pm.c
101558 @@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
101559 struct ieee80211_sub_if_data *sdata;
101560 struct sta_info *sta;
101561
101562 - if (!local->open_count)
101563 + if (!local_read(&local->open_count))
101564 goto suspend;
101565
101566 ieee80211_scan_cancel(local);
101567 @@ -58,7 +58,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
101568 cancel_work_sync(&local->dynamic_ps_enable_work);
101569 del_timer_sync(&local->dynamic_ps_timer);
101570
101571 - local->wowlan = wowlan && local->open_count;
101572 + local->wowlan = wowlan && local_read(&local->open_count);
101573 if (local->wowlan) {
101574 int err = drv_suspend(local, wowlan);
101575 if (err < 0) {
101576 @@ -123,7 +123,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
101577 WARN_ON(!list_empty(&local->chanctx_list));
101578
101579 /* stop hardware - this must stop RX */
101580 - if (local->open_count)
101581 + if (local_read(&local->open_count))
101582 ieee80211_stop_device(local);
101583
101584 suspend:
101585 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
101586 index 8fdadfd..a4f72b8 100644
101587 --- a/net/mac80211/rate.c
101588 +++ b/net/mac80211/rate.c
101589 @@ -720,7 +720,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
101590
101591 ASSERT_RTNL();
101592
101593 - if (local->open_count)
101594 + if (local_read(&local->open_count))
101595 return -EBUSY;
101596
101597 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
101598 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
101599 index 6ff1346..936ca9a 100644
101600 --- a/net/mac80211/rc80211_pid_debugfs.c
101601 +++ b/net/mac80211/rc80211_pid_debugfs.c
101602 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
101603
101604 spin_unlock_irqrestore(&events->lock, status);
101605
101606 - if (copy_to_user(buf, pb, p))
101607 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
101608 return -EFAULT;
101609
101610 return p;
101611 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
101612 index 3c36583..12887fe 100644
101613 --- a/net/mac80211/util.c
101614 +++ b/net/mac80211/util.c
101615 @@ -1509,7 +1509,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
101616 }
101617 #endif
101618 /* everything else happens only if HW was up & running */
101619 - if (!local->open_count)
101620 + if (!local_read(&local->open_count))
101621 goto wake_up;
101622
101623 /*
101624 @@ -1734,7 +1734,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
101625 local->in_reconfig = false;
101626 barrier();
101627
101628 - if (local->monitors == local->open_count && local->monitors > 0)
101629 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
101630 ieee80211_add_virtual_monitor(local);
101631
101632 /*
101633 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
101634 index e9410d1..77b6378 100644
101635 --- a/net/netfilter/Kconfig
101636 +++ b/net/netfilter/Kconfig
101637 @@ -1081,6 +1081,16 @@ config NETFILTER_XT_MATCH_ESP
101638
101639 To compile it as a module, choose M here. If unsure, say N.
101640
101641 +config NETFILTER_XT_MATCH_GRADM
101642 + tristate '"gradm" match support'
101643 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
101644 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
101645 + ---help---
101646 + The gradm match allows to match on grsecurity RBAC being enabled.
101647 + It is useful when iptables rules are applied early on bootup to
101648 + prevent connections to the machine (except from a trusted host)
101649 + while the RBAC system is disabled.
101650 +
101651 config NETFILTER_XT_MATCH_HASHLIMIT
101652 tristate '"hashlimit" match support'
101653 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
101654 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
101655 index bffdad7..f9317d1 100644
101656 --- a/net/netfilter/Makefile
101657 +++ b/net/netfilter/Makefile
101658 @@ -133,6 +133,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
101659 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
101660 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
101661 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
101662 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
101663 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
101664 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
101665 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
101666 diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
101667 index 1172083..986f1c1 100644
101668 --- a/net/netfilter/ipset/ip_set_core.c
101669 +++ b/net/netfilter/ipset/ip_set_core.c
101670 @@ -1924,7 +1924,7 @@ done:
101671 return ret;
101672 }
101673
101674 -static struct nf_sockopt_ops so_set __read_mostly = {
101675 +static struct nf_sockopt_ops so_set = {
101676 .pf = PF_INET,
101677 .get_optmin = SO_IP_SET,
101678 .get_optmax = SO_IP_SET + 1,
101679 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
101680 index a8eb0a8..86f2de4 100644
101681 --- a/net/netfilter/ipvs/ip_vs_conn.c
101682 +++ b/net/netfilter/ipvs/ip_vs_conn.c
101683 @@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
101684 /* Increase the refcnt counter of the dest */
101685 ip_vs_dest_hold(dest);
101686
101687 - conn_flags = atomic_read(&dest->conn_flags);
101688 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
101689 if (cp->protocol != IPPROTO_UDP)
101690 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
101691 flags = cp->flags;
101692 @@ -900,7 +900,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
101693
101694 cp->control = NULL;
101695 atomic_set(&cp->n_control, 0);
101696 - atomic_set(&cp->in_pkts, 0);
101697 + atomic_set_unchecked(&cp->in_pkts, 0);
101698
101699 cp->packet_xmit = NULL;
101700 cp->app = NULL;
101701 @@ -1188,7 +1188,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
101702
101703 /* Don't drop the entry if its number of incoming packets is not
101704 located in [0, 8] */
101705 - i = atomic_read(&cp->in_pkts);
101706 + i = atomic_read_unchecked(&cp->in_pkts);
101707 if (i > 8 || i < 0) return 0;
101708
101709 if (!todrop_rate[i]) return 0;
101710 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
101711 index 3d2d2c8..c87e4d3 100644
101712 --- a/net/netfilter/ipvs/ip_vs_core.c
101713 +++ b/net/netfilter/ipvs/ip_vs_core.c
101714 @@ -567,7 +567,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
101715 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
101716 /* do not touch skb anymore */
101717
101718 - atomic_inc(&cp->in_pkts);
101719 + atomic_inc_unchecked(&cp->in_pkts);
101720 ip_vs_conn_put(cp);
101721 return ret;
101722 }
101723 @@ -1711,7 +1711,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
101724 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
101725 pkts = sysctl_sync_threshold(ipvs);
101726 else
101727 - pkts = atomic_add_return(1, &cp->in_pkts);
101728 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
101729
101730 if (ipvs->sync_state & IP_VS_STATE_MASTER)
101731 ip_vs_sync_conn(net, cp, pkts);
101732 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
101733 index c42e83d..a6a3f8b 100644
101734 --- a/net/netfilter/ipvs/ip_vs_ctl.c
101735 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
101736 @@ -794,7 +794,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
101737 */
101738 ip_vs_rs_hash(ipvs, dest);
101739 }
101740 - atomic_set(&dest->conn_flags, conn_flags);
101741 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
101742
101743 /* bind the service */
101744 old_svc = rcu_dereference_protected(dest->svc, 1);
101745 @@ -1654,7 +1654,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
101746 * align with netns init in ip_vs_control_net_init()
101747 */
101748
101749 -static struct ctl_table vs_vars[] = {
101750 +static ctl_table_no_const vs_vars[] __read_only = {
101751 {
101752 .procname = "amemthresh",
101753 .maxlen = sizeof(int),
101754 @@ -2075,7 +2075,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
101755 " %-7s %-6d %-10d %-10d\n",
101756 &dest->addr.in6,
101757 ntohs(dest->port),
101758 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
101759 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
101760 atomic_read(&dest->weight),
101761 atomic_read(&dest->activeconns),
101762 atomic_read(&dest->inactconns));
101763 @@ -2086,7 +2086,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
101764 "%-7s %-6d %-10d %-10d\n",
101765 ntohl(dest->addr.ip),
101766 ntohs(dest->port),
101767 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
101768 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
101769 atomic_read(&dest->weight),
101770 atomic_read(&dest->activeconns),
101771 atomic_read(&dest->inactconns));
101772 @@ -2564,7 +2564,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
101773
101774 entry.addr = dest->addr.ip;
101775 entry.port = dest->port;
101776 - entry.conn_flags = atomic_read(&dest->conn_flags);
101777 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
101778 entry.weight = atomic_read(&dest->weight);
101779 entry.u_threshold = dest->u_threshold;
101780 entry.l_threshold = dest->l_threshold;
101781 @@ -3107,7 +3107,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
101782 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
101783 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
101784 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
101785 - (atomic_read(&dest->conn_flags) &
101786 + (atomic_read_unchecked(&dest->conn_flags) &
101787 IP_VS_CONN_F_FWD_MASK)) ||
101788 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
101789 atomic_read(&dest->weight)) ||
101790 @@ -3697,7 +3697,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
101791 {
101792 int idx;
101793 struct netns_ipvs *ipvs = net_ipvs(net);
101794 - struct ctl_table *tbl;
101795 + ctl_table_no_const *tbl;
101796
101797 atomic_set(&ipvs->dropentry, 0);
101798 spin_lock_init(&ipvs->dropentry_lock);
101799 diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
101800 index 547ff33..c8c8117 100644
101801 --- a/net/netfilter/ipvs/ip_vs_lblc.c
101802 +++ b/net/netfilter/ipvs/ip_vs_lblc.c
101803 @@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
101804 * IPVS LBLC sysctl table
101805 */
101806 #ifdef CONFIG_SYSCTL
101807 -static struct ctl_table vs_vars_table[] = {
101808 +static ctl_table_no_const vs_vars_table[] __read_only = {
101809 {
101810 .procname = "lblc_expiration",
101811 .data = NULL,
101812 diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
101813 index 3f21a2f..a112e85 100644
101814 --- a/net/netfilter/ipvs/ip_vs_lblcr.c
101815 +++ b/net/netfilter/ipvs/ip_vs_lblcr.c
101816 @@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
101817 * IPVS LBLCR sysctl table
101818 */
101819
101820 -static struct ctl_table vs_vars_table[] = {
101821 +static ctl_table_no_const vs_vars_table[] __read_only = {
101822 {
101823 .procname = "lblcr_expiration",
101824 .data = NULL,
101825 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
101826 index db80126..ef7110e 100644
101827 --- a/net/netfilter/ipvs/ip_vs_sync.c
101828 +++ b/net/netfilter/ipvs/ip_vs_sync.c
101829 @@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
101830 cp = cp->control;
101831 if (cp) {
101832 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
101833 - pkts = atomic_add_return(1, &cp->in_pkts);
101834 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
101835 else
101836 pkts = sysctl_sync_threshold(ipvs);
101837 ip_vs_sync_conn(net, cp->control, pkts);
101838 @@ -771,7 +771,7 @@ control:
101839 if (!cp)
101840 return;
101841 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
101842 - pkts = atomic_add_return(1, &cp->in_pkts);
101843 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
101844 else
101845 pkts = sysctl_sync_threshold(ipvs);
101846 goto sloop;
101847 @@ -895,7 +895,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
101848
101849 if (opt)
101850 memcpy(&cp->in_seq, opt, sizeof(*opt));
101851 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
101852 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
101853 cp->state = state;
101854 cp->old_state = cp->state;
101855 /*
101856 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
101857 index c47444e..b0961c6 100644
101858 --- a/net/netfilter/ipvs/ip_vs_xmit.c
101859 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
101860 @@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
101861 else
101862 rc = NF_ACCEPT;
101863 /* do not touch skb anymore */
101864 - atomic_inc(&cp->in_pkts);
101865 + atomic_inc_unchecked(&cp->in_pkts);
101866 goto out;
101867 }
101868
101869 @@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
101870 else
101871 rc = NF_ACCEPT;
101872 /* do not touch skb anymore */
101873 - atomic_inc(&cp->in_pkts);
101874 + atomic_inc_unchecked(&cp->in_pkts);
101875 goto out;
101876 }
101877
101878 diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
101879 index a4b5e2a..13b1de3 100644
101880 --- a/net/netfilter/nf_conntrack_acct.c
101881 +++ b/net/netfilter/nf_conntrack_acct.c
101882 @@ -62,7 +62,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
101883 #ifdef CONFIG_SYSCTL
101884 static int nf_conntrack_acct_init_sysctl(struct net *net)
101885 {
101886 - struct ctl_table *table;
101887 + ctl_table_no_const *table;
101888
101889 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
101890 GFP_KERNEL);
101891 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
101892 index 75421f2..0e69621 100644
101893 --- a/net/netfilter/nf_conntrack_core.c
101894 +++ b/net/netfilter/nf_conntrack_core.c
101895 @@ -1789,6 +1789,10 @@ void nf_conntrack_init_end(void)
101896 #define DYING_NULLS_VAL ((1<<30)+1)
101897 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
101898
101899 +#ifdef CONFIG_GRKERNSEC_HIDESYM
101900 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
101901 +#endif
101902 +
101903 int nf_conntrack_init_net(struct net *net)
101904 {
101905 int ret = -ENOMEM;
101906 @@ -1814,7 +1818,11 @@ int nf_conntrack_init_net(struct net *net)
101907 if (!net->ct.stat)
101908 goto err_pcpu_lists;
101909
101910 +#ifdef CONFIG_GRKERNSEC_HIDESYM
101911 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08x", atomic_inc_return_unchecked(&conntrack_cache_id));
101912 +#else
101913 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
101914 +#endif
101915 if (!net->ct.slabname)
101916 goto err_slabname;
101917
101918 diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
101919 index 1df1761..ce8b88a 100644
101920 --- a/net/netfilter/nf_conntrack_ecache.c
101921 +++ b/net/netfilter/nf_conntrack_ecache.c
101922 @@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
101923 #ifdef CONFIG_SYSCTL
101924 static int nf_conntrack_event_init_sysctl(struct net *net)
101925 {
101926 - struct ctl_table *table;
101927 + ctl_table_no_const *table;
101928
101929 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
101930 GFP_KERNEL);
101931 diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
101932 index 5b3eae7..dd4b8fe 100644
101933 --- a/net/netfilter/nf_conntrack_helper.c
101934 +++ b/net/netfilter/nf_conntrack_helper.c
101935 @@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
101936
101937 static int nf_conntrack_helper_init_sysctl(struct net *net)
101938 {
101939 - struct ctl_table *table;
101940 + ctl_table_no_const *table;
101941
101942 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
101943 GFP_KERNEL);
101944 diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
101945 index b65d586..beec902 100644
101946 --- a/net/netfilter/nf_conntrack_proto.c
101947 +++ b/net/netfilter/nf_conntrack_proto.c
101948 @@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
101949
101950 static void
101951 nf_ct_unregister_sysctl(struct ctl_table_header **header,
101952 - struct ctl_table **table,
101953 + ctl_table_no_const **table,
101954 unsigned int users)
101955 {
101956 if (users > 0)
101957 diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
101958 index f641751..d3c5b51 100644
101959 --- a/net/netfilter/nf_conntrack_standalone.c
101960 +++ b/net/netfilter/nf_conntrack_standalone.c
101961 @@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
101962
101963 static int nf_conntrack_standalone_init_sysctl(struct net *net)
101964 {
101965 - struct ctl_table *table;
101966 + ctl_table_no_const *table;
101967
101968 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
101969 GFP_KERNEL);
101970 diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
101971 index 7a394df..bd91a8a 100644
101972 --- a/net/netfilter/nf_conntrack_timestamp.c
101973 +++ b/net/netfilter/nf_conntrack_timestamp.c
101974 @@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
101975 #ifdef CONFIG_SYSCTL
101976 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
101977 {
101978 - struct ctl_table *table;
101979 + ctl_table_no_const *table;
101980
101981 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
101982 GFP_KERNEL);
101983 diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
101984 index 85296d4..8becdec 100644
101985 --- a/net/netfilter/nf_log.c
101986 +++ b/net/netfilter/nf_log.c
101987 @@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
101988
101989 #ifdef CONFIG_SYSCTL
101990 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
101991 -static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
101992 +static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
101993
101994 static int nf_log_proc_dostring(struct ctl_table *table, int write,
101995 void __user *buffer, size_t *lenp, loff_t *ppos)
101996 @@ -274,14 +274,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
101997 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
101998 mutex_unlock(&nf_log_mutex);
101999 } else {
102000 + ctl_table_no_const nf_log_table = *table;
102001 +
102002 mutex_lock(&nf_log_mutex);
102003 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
102004 lockdep_is_held(&nf_log_mutex));
102005 if (!logger)
102006 - table->data = "NONE";
102007 + nf_log_table.data = "NONE";
102008 else
102009 - table->data = logger->name;
102010 - r = proc_dostring(table, write, buffer, lenp, ppos);
102011 + nf_log_table.data = logger->name;
102012 + r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
102013 mutex_unlock(&nf_log_mutex);
102014 }
102015
102016 diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
102017 index f042ae5..30ea486 100644
102018 --- a/net/netfilter/nf_sockopt.c
102019 +++ b/net/netfilter/nf_sockopt.c
102020 @@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
102021 }
102022 }
102023
102024 - list_add(&reg->list, &nf_sockopts);
102025 + pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
102026 out:
102027 mutex_unlock(&nf_sockopt_mutex);
102028 return ret;
102029 @@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
102030 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
102031 {
102032 mutex_lock(&nf_sockopt_mutex);
102033 - list_del(&reg->list);
102034 + pax_list_del((struct list_head *)&reg->list);
102035 mutex_unlock(&nf_sockopt_mutex);
102036 }
102037 EXPORT_SYMBOL(nf_unregister_sockopt);
102038 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
102039 index d292c8d..9f1e166 100644
102040 --- a/net/netfilter/nfnetlink_log.c
102041 +++ b/net/netfilter/nfnetlink_log.c
102042 @@ -79,7 +79,7 @@ static int nfnl_log_net_id __read_mostly;
102043 struct nfnl_log_net {
102044 spinlock_t instances_lock;
102045 struct hlist_head instance_table[INSTANCE_BUCKETS];
102046 - atomic_t global_seq;
102047 + atomic_unchecked_t global_seq;
102048 };
102049
102050 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
102051 @@ -561,7 +561,7 @@ __build_packet_message(struct nfnl_log_net *log,
102052 /* global sequence number */
102053 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
102054 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
102055 - htonl(atomic_inc_return(&log->global_seq))))
102056 + htonl(atomic_inc_return_unchecked(&log->global_seq))))
102057 goto nla_put_failure;
102058
102059 if (data_len) {
102060 diff --git a/net/netfilter/nft_compat.c b/net/netfilter/nft_compat.c
102061 index 8a779be..1551d4c 100644
102062 --- a/net/netfilter/nft_compat.c
102063 +++ b/net/netfilter/nft_compat.c
102064 @@ -216,7 +216,7 @@ target_dump_info(struct sk_buff *skb, const struct xt_target *t, const void *in)
102065 /* We want to reuse existing compat_to_user */
102066 old_fs = get_fs();
102067 set_fs(KERNEL_DS);
102068 - t->compat_to_user(out, in);
102069 + t->compat_to_user((void __force_user *)out, in);
102070 set_fs(old_fs);
102071 ret = nla_put(skb, NFTA_TARGET_INFO, XT_ALIGN(t->targetsize), out);
102072 kfree(out);
102073 @@ -403,7 +403,7 @@ match_dump_info(struct sk_buff *skb, const struct xt_match *m, const void *in)
102074 /* We want to reuse existing compat_to_user */
102075 old_fs = get_fs();
102076 set_fs(KERNEL_DS);
102077 - m->compat_to_user(out, in);
102078 + m->compat_to_user((void __force_user *)out, in);
102079 set_fs(old_fs);
102080 ret = nla_put(skb, NFTA_MATCH_INFO, XT_ALIGN(m->matchsize), out);
102081 kfree(out);
102082 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
102083 new file mode 100644
102084 index 0000000..c566332
102085 --- /dev/null
102086 +++ b/net/netfilter/xt_gradm.c
102087 @@ -0,0 +1,51 @@
102088 +/*
102089 + * gradm match for netfilter
102090 + * Copyright © Zbigniew Krzystolik, 2010
102091 + *
102092 + * This program is free software; you can redistribute it and/or modify
102093 + * it under the terms of the GNU General Public License; either version
102094 + * 2 or 3 as published by the Free Software Foundation.
102095 + */
102096 +#include <linux/module.h>
102097 +#include <linux/moduleparam.h>
102098 +#include <linux/skbuff.h>
102099 +#include <linux/netfilter/x_tables.h>
102100 +#include <linux/grsecurity.h>
102101 +#include <linux/netfilter/xt_gradm.h>
102102 +
102103 +static bool
102104 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
102105 +{
102106 + const struct xt_gradm_mtinfo *info = par->matchinfo;
102107 + bool retval = false;
102108 + if (gr_acl_is_enabled())
102109 + retval = true;
102110 + return retval ^ info->invflags;
102111 +}
102112 +
102113 +static struct xt_match gradm_mt_reg __read_mostly = {
102114 + .name = "gradm",
102115 + .revision = 0,
102116 + .family = NFPROTO_UNSPEC,
102117 + .match = gradm_mt,
102118 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
102119 + .me = THIS_MODULE,
102120 +};
102121 +
102122 +static int __init gradm_mt_init(void)
102123 +{
102124 + return xt_register_match(&gradm_mt_reg);
102125 +}
102126 +
102127 +static void __exit gradm_mt_exit(void)
102128 +{
102129 + xt_unregister_match(&gradm_mt_reg);
102130 +}
102131 +
102132 +module_init(gradm_mt_init);
102133 +module_exit(gradm_mt_exit);
102134 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
102135 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
102136 +MODULE_LICENSE("GPL");
102137 +MODULE_ALIAS("ipt_gradm");
102138 +MODULE_ALIAS("ip6t_gradm");
102139 diff --git a/net/netfilter/xt_hashlimit.c b/net/netfilter/xt_hashlimit.c
102140 index a3910fc..2d2ba14 100644
102141 --- a/net/netfilter/xt_hashlimit.c
102142 +++ b/net/netfilter/xt_hashlimit.c
102143 @@ -870,11 +870,11 @@ static int __net_init hashlimit_proc_net_init(struct net *net)
102144 {
102145 struct hashlimit_net *hashlimit_net = hashlimit_pernet(net);
102146
102147 - hashlimit_net->ipt_hashlimit = proc_mkdir("ipt_hashlimit", net->proc_net);
102148 + hashlimit_net->ipt_hashlimit = proc_mkdir_restrict("ipt_hashlimit", net->proc_net);
102149 if (!hashlimit_net->ipt_hashlimit)
102150 return -ENOMEM;
102151 #if IS_ENABLED(CONFIG_IP6_NF_IPTABLES)
102152 - hashlimit_net->ip6t_hashlimit = proc_mkdir("ip6t_hashlimit", net->proc_net);
102153 + hashlimit_net->ip6t_hashlimit = proc_mkdir_restrict("ip6t_hashlimit", net->proc_net);
102154 if (!hashlimit_net->ip6t_hashlimit) {
102155 remove_proc_entry("ipt_hashlimit", net->proc_net);
102156 return -ENOMEM;
102157 diff --git a/net/netfilter/xt_recent.c b/net/netfilter/xt_recent.c
102158 index 1e657cf..1eb1c34 100644
102159 --- a/net/netfilter/xt_recent.c
102160 +++ b/net/netfilter/xt_recent.c
102161 @@ -618,7 +618,7 @@ static int __net_init recent_proc_net_init(struct net *net)
102162 {
102163 struct recent_net *recent_net = recent_pernet(net);
102164
102165 - recent_net->xt_recent = proc_mkdir("xt_recent", net->proc_net);
102166 + recent_net->xt_recent = proc_mkdir_restrict("xt_recent", net->proc_net);
102167 if (!recent_net->xt_recent)
102168 return -ENOMEM;
102169 return 0;
102170 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
102171 index 11de55e..f25e448 100644
102172 --- a/net/netfilter/xt_statistic.c
102173 +++ b/net/netfilter/xt_statistic.c
102174 @@ -19,7 +19,7 @@
102175 #include <linux/module.h>
102176
102177 struct xt_statistic_priv {
102178 - atomic_t count;
102179 + atomic_unchecked_t count;
102180 } ____cacheline_aligned_in_smp;
102181
102182 MODULE_LICENSE("GPL");
102183 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
102184 break;
102185 case XT_STATISTIC_MODE_NTH:
102186 do {
102187 - oval = atomic_read(&info->master->count);
102188 + oval = atomic_read_unchecked(&info->master->count);
102189 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
102190 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
102191 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
102192 if (nval == 0)
102193 ret = !ret;
102194 break;
102195 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
102196 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
102197 if (info->master == NULL)
102198 return -ENOMEM;
102199 - atomic_set(&info->master->count, info->u.nth.count);
102200 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
102201
102202 return 0;
102203 }
102204 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
102205 index f22757a..daf62a2 100644
102206 --- a/net/netlink/af_netlink.c
102207 +++ b/net/netlink/af_netlink.c
102208 @@ -257,7 +257,7 @@ static void netlink_overrun(struct sock *sk)
102209 sk->sk_error_report(sk);
102210 }
102211 }
102212 - atomic_inc(&sk->sk_drops);
102213 + atomic_inc_unchecked(&sk->sk_drops);
102214 }
102215
102216 static void netlink_rcv_wake(struct sock *sk)
102217 @@ -3028,7 +3028,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
102218 sk_wmem_alloc_get(s),
102219 nlk->cb_running,
102220 atomic_read(&s->sk_refcnt),
102221 - atomic_read(&s->sk_drops),
102222 + atomic_read_unchecked(&s->sk_drops),
102223 sock_i_ino(s)
102224 );
102225
102226 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
102227 index ede50d1..d2468e6 100644
102228 --- a/net/netrom/af_netrom.c
102229 +++ b/net/netrom/af_netrom.c
102230 @@ -850,7 +850,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
102231 *uaddr_len = sizeof(struct full_sockaddr_ax25);
102232 } else {
102233 sax->fsa_ax25.sax25_family = AF_NETROM;
102234 - sax->fsa_ax25.sax25_ndigis = 0;
102235 sax->fsa_ax25.sax25_call = nr->source_addr;
102236 *uaddr_len = sizeof(struct sockaddr_ax25);
102237 }
102238 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
102239 index b85c67c..27c3368 100644
102240 --- a/net/packet/af_packet.c
102241 +++ b/net/packet/af_packet.c
102242 @@ -275,7 +275,7 @@ static int packet_direct_xmit(struct sk_buff *skb)
102243
102244 return ret;
102245 drop:
102246 - atomic_long_inc(&dev->tx_dropped);
102247 + atomic_long_inc_unchecked(&dev->tx_dropped);
102248 kfree_skb(skb);
102249 return NET_XMIT_DROP;
102250 }
102251 @@ -1845,7 +1845,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
102252
102253 spin_lock(&sk->sk_receive_queue.lock);
102254 po->stats.stats1.tp_packets++;
102255 - skb->dropcount = atomic_read(&sk->sk_drops);
102256 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
102257 __skb_queue_tail(&sk->sk_receive_queue, skb);
102258 spin_unlock(&sk->sk_receive_queue.lock);
102259 sk->sk_data_ready(sk);
102260 @@ -1854,7 +1854,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
102261 drop_n_acct:
102262 spin_lock(&sk->sk_receive_queue.lock);
102263 po->stats.stats1.tp_drops++;
102264 - atomic_inc(&sk->sk_drops);
102265 + atomic_inc_unchecked(&sk->sk_drops);
102266 spin_unlock(&sk->sk_receive_queue.lock);
102267
102268 drop_n_restore:
102269 @@ -3459,7 +3459,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
102270 case PACKET_HDRLEN:
102271 if (len > sizeof(int))
102272 len = sizeof(int);
102273 - if (copy_from_user(&val, optval, len))
102274 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
102275 return -EFAULT;
102276 switch (val) {
102277 case TPACKET_V1:
102278 @@ -3505,7 +3505,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
102279 len = lv;
102280 if (put_user(len, optlen))
102281 return -EFAULT;
102282 - if (copy_to_user(optval, data, len))
102283 + if (len > sizeof(st) || copy_to_user(optval, data, len))
102284 return -EFAULT;
102285 return 0;
102286 }
102287 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
102288 index 70a547e..23477fe 100644
102289 --- a/net/phonet/pep.c
102290 +++ b/net/phonet/pep.c
102291 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
102292
102293 case PNS_PEP_CTRL_REQ:
102294 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
102295 - atomic_inc(&sk->sk_drops);
102296 + atomic_inc_unchecked(&sk->sk_drops);
102297 break;
102298 }
102299 __skb_pull(skb, 4);
102300 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
102301 }
102302
102303 if (pn->rx_credits == 0) {
102304 - atomic_inc(&sk->sk_drops);
102305 + atomic_inc_unchecked(&sk->sk_drops);
102306 err = -ENOBUFS;
102307 break;
102308 }
102309 @@ -579,7 +579,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
102310 }
102311
102312 if (pn->rx_credits == 0) {
102313 - atomic_inc(&sk->sk_drops);
102314 + atomic_inc_unchecked(&sk->sk_drops);
102315 err = NET_RX_DROP;
102316 break;
102317 }
102318 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
102319 index 008214a..bb68240 100644
102320 --- a/net/phonet/socket.c
102321 +++ b/net/phonet/socket.c
102322 @@ -611,7 +611,7 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
102323 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk)),
102324 sock_i_ino(sk),
102325 atomic_read(&sk->sk_refcnt), sk,
102326 - atomic_read(&sk->sk_drops));
102327 + atomic_read_unchecked(&sk->sk_drops));
102328 }
102329 seq_pad(seq, '\n');
102330 return 0;
102331 diff --git a/net/phonet/sysctl.c b/net/phonet/sysctl.c
102332 index c02a8c4..3c5b600 100644
102333 --- a/net/phonet/sysctl.c
102334 +++ b/net/phonet/sysctl.c
102335 @@ -67,7 +67,7 @@ static int proc_local_port_range(struct ctl_table *table, int write,
102336 {
102337 int ret;
102338 int range[2] = {local_port_range[0], local_port_range[1]};
102339 - struct ctl_table tmp = {
102340 + ctl_table_no_const tmp = {
102341 .data = &range,
102342 .maxlen = sizeof(range),
102343 .mode = table->mode,
102344 diff --git a/net/rds/cong.c b/net/rds/cong.c
102345 index e5b65ac..f3b6fb7 100644
102346 --- a/net/rds/cong.c
102347 +++ b/net/rds/cong.c
102348 @@ -78,7 +78,7 @@
102349 * finds that the saved generation number is smaller than the global generation
102350 * number, it wakes up the process.
102351 */
102352 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
102353 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
102354
102355 /*
102356 * Congestion monitoring
102357 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
102358 rdsdebug("waking map %p for %pI4\n",
102359 map, &map->m_addr);
102360 rds_stats_inc(s_cong_update_received);
102361 - atomic_inc(&rds_cong_generation);
102362 + atomic_inc_unchecked(&rds_cong_generation);
102363 if (waitqueue_active(&map->m_waitq))
102364 wake_up(&map->m_waitq);
102365 if (waitqueue_active(&rds_poll_waitq))
102366 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
102367
102368 int rds_cong_updated_since(unsigned long *recent)
102369 {
102370 - unsigned long gen = atomic_read(&rds_cong_generation);
102371 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
102372
102373 if (likely(*recent == gen))
102374 return 0;
102375 diff --git a/net/rds/ib.h b/net/rds/ib.h
102376 index 7280ab8..e04f4ea 100644
102377 --- a/net/rds/ib.h
102378 +++ b/net/rds/ib.h
102379 @@ -128,7 +128,7 @@ struct rds_ib_connection {
102380 /* sending acks */
102381 unsigned long i_ack_flags;
102382 #ifdef KERNEL_HAS_ATOMIC64
102383 - atomic64_t i_ack_next; /* next ACK to send */
102384 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
102385 #else
102386 spinlock_t i_ack_lock; /* protect i_ack_next */
102387 u64 i_ack_next; /* next ACK to send */
102388 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
102389 index 31b74f5..dc1fbfa 100644
102390 --- a/net/rds/ib_cm.c
102391 +++ b/net/rds/ib_cm.c
102392 @@ -717,7 +717,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
102393 /* Clear the ACK state */
102394 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
102395 #ifdef KERNEL_HAS_ATOMIC64
102396 - atomic64_set(&ic->i_ack_next, 0);
102397 + atomic64_set_unchecked(&ic->i_ack_next, 0);
102398 #else
102399 ic->i_ack_next = 0;
102400 #endif
102401 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
102402 index b7ebe23..b6352f6 100644
102403 --- a/net/rds/ib_recv.c
102404 +++ b/net/rds/ib_recv.c
102405 @@ -596,7 +596,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
102406 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
102407 int ack_required)
102408 {
102409 - atomic64_set(&ic->i_ack_next, seq);
102410 + atomic64_set_unchecked(&ic->i_ack_next, seq);
102411 if (ack_required) {
102412 smp_mb__before_clear_bit();
102413 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
102414 @@ -608,7 +608,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
102415 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
102416 smp_mb__after_clear_bit();
102417
102418 - return atomic64_read(&ic->i_ack_next);
102419 + return atomic64_read_unchecked(&ic->i_ack_next);
102420 }
102421 #endif
102422
102423 diff --git a/net/rds/iw.h b/net/rds/iw.h
102424 index 04ce3b1..48119a6 100644
102425 --- a/net/rds/iw.h
102426 +++ b/net/rds/iw.h
102427 @@ -134,7 +134,7 @@ struct rds_iw_connection {
102428 /* sending acks */
102429 unsigned long i_ack_flags;
102430 #ifdef KERNEL_HAS_ATOMIC64
102431 - atomic64_t i_ack_next; /* next ACK to send */
102432 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
102433 #else
102434 spinlock_t i_ack_lock; /* protect i_ack_next */
102435 u64 i_ack_next; /* next ACK to send */
102436 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
102437 index a91e1db..cf3053f 100644
102438 --- a/net/rds/iw_cm.c
102439 +++ b/net/rds/iw_cm.c
102440 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
102441 /* Clear the ACK state */
102442 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
102443 #ifdef KERNEL_HAS_ATOMIC64
102444 - atomic64_set(&ic->i_ack_next, 0);
102445 + atomic64_set_unchecked(&ic->i_ack_next, 0);
102446 #else
102447 ic->i_ack_next = 0;
102448 #endif
102449 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
102450 index 4503335..db566b4 100644
102451 --- a/net/rds/iw_recv.c
102452 +++ b/net/rds/iw_recv.c
102453 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
102454 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
102455 int ack_required)
102456 {
102457 - atomic64_set(&ic->i_ack_next, seq);
102458 + atomic64_set_unchecked(&ic->i_ack_next, seq);
102459 if (ack_required) {
102460 smp_mb__before_clear_bit();
102461 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
102462 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
102463 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
102464 smp_mb__after_clear_bit();
102465
102466 - return atomic64_read(&ic->i_ack_next);
102467 + return atomic64_read_unchecked(&ic->i_ack_next);
102468 }
102469 #endif
102470
102471 diff --git a/net/rds/rds.h b/net/rds/rds.h
102472 index 48f8ffc..0ef3eec 100644
102473 --- a/net/rds/rds.h
102474 +++ b/net/rds/rds.h
102475 @@ -449,7 +449,7 @@ struct rds_transport {
102476 void (*sync_mr)(void *trans_private, int direction);
102477 void (*free_mr)(void *trans_private, int invalidate);
102478 void (*flush_mrs)(void);
102479 -};
102480 +} __do_const;
102481
102482 struct rds_sock {
102483 struct sock rs_sk;
102484 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
102485 index edac9ef..16bcb98 100644
102486 --- a/net/rds/tcp.c
102487 +++ b/net/rds/tcp.c
102488 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
102489 int val = 1;
102490
102491 set_fs(KERNEL_DS);
102492 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
102493 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
102494 sizeof(val));
102495 set_fs(oldfs);
102496 }
102497 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
102498 index 81cf5a4..b5826ff 100644
102499 --- a/net/rds/tcp_send.c
102500 +++ b/net/rds/tcp_send.c
102501 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
102502
102503 oldfs = get_fs();
102504 set_fs(KERNEL_DS);
102505 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
102506 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
102507 sizeof(val));
102508 set_fs(oldfs);
102509 }
102510 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
102511 index 7b16704..9628ec6 100644
102512 --- a/net/rxrpc/af_rxrpc.c
102513 +++ b/net/rxrpc/af_rxrpc.c
102514 @@ -40,7 +40,7 @@ static const struct proto_ops rxrpc_rpc_ops;
102515 __be32 rxrpc_epoch;
102516
102517 /* current debugging ID */
102518 -atomic_t rxrpc_debug_id;
102519 +atomic_unchecked_t rxrpc_debug_id;
102520
102521 /* count of skbs currently in use */
102522 atomic_t rxrpc_n_skbs;
102523 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
102524 index c6be17a..2a6200a 100644
102525 --- a/net/rxrpc/ar-ack.c
102526 +++ b/net/rxrpc/ar-ack.c
102527 @@ -223,7 +223,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
102528
102529 _enter("{%d,%d,%d,%d},",
102530 call->acks_hard, call->acks_unacked,
102531 - atomic_read(&call->sequence),
102532 + atomic_read_unchecked(&call->sequence),
102533 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
102534
102535 stop = 0;
102536 @@ -247,7 +247,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
102537
102538 /* each Tx packet has a new serial number */
102539 sp->hdr.serial =
102540 - htonl(atomic_inc_return(&call->conn->serial));
102541 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
102542
102543 hdr = (struct rxrpc_header *) txb->head;
102544 hdr->serial = sp->hdr.serial;
102545 @@ -451,7 +451,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
102546 */
102547 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
102548 {
102549 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
102550 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
102551 }
102552
102553 /*
102554 @@ -677,7 +677,7 @@ process_further:
102555
102556 latest = ntohl(sp->hdr.serial);
102557 hard = ntohl(ack.firstPacket);
102558 - tx = atomic_read(&call->sequence);
102559 + tx = atomic_read_unchecked(&call->sequence);
102560
102561 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
102562 latest,
102563 @@ -1209,7 +1209,7 @@ void rxrpc_process_call(struct work_struct *work)
102564 goto maybe_reschedule;
102565
102566 send_ACK_with_skew:
102567 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
102568 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
102569 ntohl(ack.serial));
102570 send_ACK:
102571 mtu = call->conn->trans->peer->if_mtu;
102572 @@ -1221,7 +1221,7 @@ send_ACK:
102573 ackinfo.rxMTU = htonl(rxrpc_rx_mtu);
102574 ackinfo.jumbo_max = htonl(rxrpc_rx_jumbo_max);
102575
102576 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
102577 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
102578 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
102579 ntohl(hdr.serial),
102580 ntohs(ack.maxSkew),
102581 @@ -1239,7 +1239,7 @@ send_ACK:
102582 send_message:
102583 _debug("send message");
102584
102585 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
102586 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
102587 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
102588 send_message_2:
102589
102590 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
102591 index a9e05db..194e793 100644
102592 --- a/net/rxrpc/ar-call.c
102593 +++ b/net/rxrpc/ar-call.c
102594 @@ -232,7 +232,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
102595 spin_lock_init(&call->lock);
102596 rwlock_init(&call->state_lock);
102597 atomic_set(&call->usage, 1);
102598 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
102599 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
102600 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
102601
102602 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
102603 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
102604 index 6631f4f..bfdf056 100644
102605 --- a/net/rxrpc/ar-connection.c
102606 +++ b/net/rxrpc/ar-connection.c
102607 @@ -210,7 +210,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
102608 rwlock_init(&conn->lock);
102609 spin_lock_init(&conn->state_lock);
102610 atomic_set(&conn->usage, 1);
102611 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
102612 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
102613 conn->avail_calls = RXRPC_MAXCALLS;
102614 conn->size_align = 4;
102615 conn->header_size = sizeof(struct rxrpc_header);
102616 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
102617 index e7ed43a..6afa140 100644
102618 --- a/net/rxrpc/ar-connevent.c
102619 +++ b/net/rxrpc/ar-connevent.c
102620 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
102621
102622 len = iov[0].iov_len + iov[1].iov_len;
102623
102624 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
102625 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
102626 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
102627
102628 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
102629 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
102630 index 63b21e5..330232e 100644
102631 --- a/net/rxrpc/ar-input.c
102632 +++ b/net/rxrpc/ar-input.c
102633 @@ -338,9 +338,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
102634 /* track the latest serial number on this connection for ACK packet
102635 * information */
102636 serial = ntohl(sp->hdr.serial);
102637 - hi_serial = atomic_read(&call->conn->hi_serial);
102638 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
102639 while (serial > hi_serial)
102640 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
102641 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
102642 serial);
102643
102644 /* request ACK generation for any ACK or DATA packet that requests
102645 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
102646 index ba9fd36..9bbfe01 100644
102647 --- a/net/rxrpc/ar-internal.h
102648 +++ b/net/rxrpc/ar-internal.h
102649 @@ -272,8 +272,8 @@ struct rxrpc_connection {
102650 int error; /* error code for local abort */
102651 int debug_id; /* debug ID for printks */
102652 unsigned int call_counter; /* call ID counter */
102653 - atomic_t serial; /* packet serial number counter */
102654 - atomic_t hi_serial; /* highest serial number received */
102655 + atomic_unchecked_t serial; /* packet serial number counter */
102656 + atomic_unchecked_t hi_serial; /* highest serial number received */
102657 u8 avail_calls; /* number of calls available */
102658 u8 size_align; /* data size alignment (for security) */
102659 u8 header_size; /* rxrpc + security header size */
102660 @@ -346,7 +346,7 @@ struct rxrpc_call {
102661 spinlock_t lock;
102662 rwlock_t state_lock; /* lock for state transition */
102663 atomic_t usage;
102664 - atomic_t sequence; /* Tx data packet sequence counter */
102665 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
102666 u32 abort_code; /* local/remote abort code */
102667 enum { /* current state of call */
102668 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
102669 @@ -431,7 +431,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
102670 */
102671 extern atomic_t rxrpc_n_skbs;
102672 extern __be32 rxrpc_epoch;
102673 -extern atomic_t rxrpc_debug_id;
102674 +extern atomic_unchecked_t rxrpc_debug_id;
102675 extern struct workqueue_struct *rxrpc_workqueue;
102676
102677 /*
102678 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
102679 index 87f7135..74d3703 100644
102680 --- a/net/rxrpc/ar-local.c
102681 +++ b/net/rxrpc/ar-local.c
102682 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
102683 spin_lock_init(&local->lock);
102684 rwlock_init(&local->services_lock);
102685 atomic_set(&local->usage, 1);
102686 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
102687 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
102688 memcpy(&local->srx, srx, sizeof(*srx));
102689 }
102690
102691 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
102692 index 0b4b9a7..966ffbb 100644
102693 --- a/net/rxrpc/ar-output.c
102694 +++ b/net/rxrpc/ar-output.c
102695 @@ -682,14 +682,14 @@ static int rxrpc_send_data(struct kiocb *iocb,
102696 memset(skb_put(skb, pad), 0, pad);
102697 }
102698
102699 - seq = atomic_inc_return(&call->sequence);
102700 + seq = atomic_inc_return_unchecked(&call->sequence);
102701
102702 sp->hdr.epoch = conn->epoch;
102703 sp->hdr.cid = call->cid;
102704 sp->hdr.callNumber = call->call_id;
102705 sp->hdr.seq = htonl(seq);
102706 sp->hdr.serial =
102707 - htonl(atomic_inc_return(&conn->serial));
102708 + htonl(atomic_inc_return_unchecked(&conn->serial));
102709 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
102710 sp->hdr.userStatus = 0;
102711 sp->hdr.securityIndex = conn->security_ix;
102712 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
102713 index bebaa43..2644591 100644
102714 --- a/net/rxrpc/ar-peer.c
102715 +++ b/net/rxrpc/ar-peer.c
102716 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
102717 INIT_LIST_HEAD(&peer->error_targets);
102718 spin_lock_init(&peer->lock);
102719 atomic_set(&peer->usage, 1);
102720 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
102721 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
102722 memcpy(&peer->srx, srx, sizeof(*srx));
102723
102724 rxrpc_assess_MTU_size(peer);
102725 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
102726 index 38047f7..9f48511 100644
102727 --- a/net/rxrpc/ar-proc.c
102728 +++ b/net/rxrpc/ar-proc.c
102729 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
102730 atomic_read(&conn->usage),
102731 rxrpc_conn_states[conn->state],
102732 key_serial(conn->key),
102733 - atomic_read(&conn->serial),
102734 - atomic_read(&conn->hi_serial));
102735 + atomic_read_unchecked(&conn->serial),
102736 + atomic_read_unchecked(&conn->hi_serial));
102737
102738 return 0;
102739 }
102740 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
102741 index 1976dec..aa70be5 100644
102742 --- a/net/rxrpc/ar-transport.c
102743 +++ b/net/rxrpc/ar-transport.c
102744 @@ -51,7 +51,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
102745 spin_lock_init(&trans->client_lock);
102746 rwlock_init(&trans->conn_lock);
102747 atomic_set(&trans->usage, 1);
102748 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
102749 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
102750
102751 if (peer->srx.transport.family == AF_INET) {
102752 switch (peer->srx.transport_type) {
102753 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
102754 index f226709..0e735a8 100644
102755 --- a/net/rxrpc/rxkad.c
102756 +++ b/net/rxrpc/rxkad.c
102757 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
102758
102759 len = iov[0].iov_len + iov[1].iov_len;
102760
102761 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
102762 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
102763 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
102764
102765 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
102766 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
102767
102768 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
102769
102770 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
102771 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
102772 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
102773
102774 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
102775 diff --git a/net/sched/sch_generic.c b/net/sched/sch_generic.c
102776 index e1543b0..7ce8bd0 100644
102777 --- a/net/sched/sch_generic.c
102778 +++ b/net/sched/sch_generic.c
102779 @@ -310,7 +310,7 @@ void netif_carrier_on(struct net_device *dev)
102780 if (test_and_clear_bit(__LINK_STATE_NOCARRIER, &dev->state)) {
102781 if (dev->reg_state == NETREG_UNINITIALIZED)
102782 return;
102783 - atomic_inc(&dev->carrier_changes);
102784 + atomic_inc_unchecked(&dev->carrier_changes);
102785 linkwatch_fire_event(dev);
102786 if (netif_running(dev))
102787 __netdev_watchdog_up(dev);
102788 @@ -329,7 +329,7 @@ void netif_carrier_off(struct net_device *dev)
102789 if (!test_and_set_bit(__LINK_STATE_NOCARRIER, &dev->state)) {
102790 if (dev->reg_state == NETREG_UNINITIALIZED)
102791 return;
102792 - atomic_inc(&dev->carrier_changes);
102793 + atomic_inc_unchecked(&dev->carrier_changes);
102794 linkwatch_fire_event(dev);
102795 }
102796 }
102797 diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
102798 index 2b1738e..a9d0fc9 100644
102799 --- a/net/sctp/ipv6.c
102800 +++ b/net/sctp/ipv6.c
102801 @@ -966,7 +966,7 @@ static const struct inet6_protocol sctpv6_protocol = {
102802 .flags = INET6_PROTO_NOPOLICY | INET6_PROTO_FINAL,
102803 };
102804
102805 -static struct sctp_af sctp_af_inet6 = {
102806 +static struct sctp_af sctp_af_inet6 __read_only = {
102807 .sa_family = AF_INET6,
102808 .sctp_xmit = sctp_v6_xmit,
102809 .setsockopt = ipv6_setsockopt,
102810 @@ -998,7 +998,7 @@ static struct sctp_af sctp_af_inet6 = {
102811 #endif
102812 };
102813
102814 -static struct sctp_pf sctp_pf_inet6 = {
102815 +static struct sctp_pf sctp_pf_inet6 __read_only = {
102816 .event_msgname = sctp_inet6_event_msgname,
102817 .skb_msgname = sctp_inet6_skb_msgname,
102818 .af_supported = sctp_inet6_af_supported,
102819 @@ -1023,7 +1023,7 @@ void sctp_v6_pf_init(void)
102820
102821 void sctp_v6_pf_exit(void)
102822 {
102823 - list_del(&sctp_af_inet6.list);
102824 + pax_list_del(&sctp_af_inet6.list);
102825 }
102826
102827 /* Initialize IPv6 support and register with socket layer. */
102828 diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
102829 index 44cbb54..4c5dce6 100644
102830 --- a/net/sctp/protocol.c
102831 +++ b/net/sctp/protocol.c
102832 @@ -836,8 +836,10 @@ int sctp_register_af(struct sctp_af *af)
102833 return 0;
102834 }
102835
102836 + pax_open_kernel();
102837 INIT_LIST_HEAD(&af->list);
102838 - list_add_tail(&af->list, &sctp_address_families);
102839 + pax_close_kernel();
102840 + pax_list_add_tail(&af->list, &sctp_address_families);
102841 return 1;
102842 }
102843
102844 @@ -967,7 +969,7 @@ static inline int sctp_v4_xmit(struct sk_buff *skb,
102845
102846 static struct sctp_af sctp_af_inet;
102847
102848 -static struct sctp_pf sctp_pf_inet = {
102849 +static struct sctp_pf sctp_pf_inet __read_only = {
102850 .event_msgname = sctp_inet_event_msgname,
102851 .skb_msgname = sctp_inet_skb_msgname,
102852 .af_supported = sctp_inet_af_supported,
102853 @@ -1039,7 +1041,7 @@ static const struct net_protocol sctp_protocol = {
102854 };
102855
102856 /* IPv4 address related functions. */
102857 -static struct sctp_af sctp_af_inet = {
102858 +static struct sctp_af sctp_af_inet __read_only = {
102859 .sa_family = AF_INET,
102860 .sctp_xmit = sctp_v4_xmit,
102861 .setsockopt = ip_setsockopt,
102862 @@ -1124,7 +1126,7 @@ static void sctp_v4_pf_init(void)
102863
102864 static void sctp_v4_pf_exit(void)
102865 {
102866 - list_del(&sctp_af_inet.list);
102867 + pax_list_del(&sctp_af_inet.list);
102868 }
102869
102870 static int sctp_v4_protosw_init(void)
102871 diff --git a/net/sctp/sm_sideeffect.c b/net/sctp/sm_sideeffect.c
102872 index fef2acd..c705c4f 100644
102873 --- a/net/sctp/sm_sideeffect.c
102874 +++ b/net/sctp/sm_sideeffect.c
102875 @@ -439,7 +439,7 @@ static void sctp_generate_sack_event(unsigned long data)
102876 sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_SACK);
102877 }
102878
102879 -sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
102880 +sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
102881 NULL,
102882 sctp_generate_t1_cookie_event,
102883 sctp_generate_t1_init_event,
102884 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
102885 index fee06b9..eabc613 100644
102886 --- a/net/sctp/socket.c
102887 +++ b/net/sctp/socket.c
102888 @@ -2175,11 +2175,13 @@ static int sctp_setsockopt_events(struct sock *sk, char __user *optval,
102889 {
102890 struct sctp_association *asoc;
102891 struct sctp_ulpevent *event;
102892 + struct sctp_event_subscribe subscribe;
102893
102894 if (optlen > sizeof(struct sctp_event_subscribe))
102895 return -EINVAL;
102896 - if (copy_from_user(&sctp_sk(sk)->subscribe, optval, optlen))
102897 + if (copy_from_user(&subscribe, optval, optlen))
102898 return -EFAULT;
102899 + sctp_sk(sk)->subscribe = subscribe;
102900
102901 /*
102902 * At the time when a user app subscribes to SCTP_SENDER_DRY_EVENT,
102903 @@ -4259,13 +4261,16 @@ static int sctp_getsockopt_disable_fragments(struct sock *sk, int len,
102904 static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
102905 int __user *optlen)
102906 {
102907 + struct sctp_event_subscribe subscribe;
102908 +
102909 if (len <= 0)
102910 return -EINVAL;
102911 if (len > sizeof(struct sctp_event_subscribe))
102912 len = sizeof(struct sctp_event_subscribe);
102913 if (put_user(len, optlen))
102914 return -EFAULT;
102915 - if (copy_to_user(optval, &sctp_sk(sk)->subscribe, len))
102916 + subscribe = sctp_sk(sk)->subscribe;
102917 + if (copy_to_user(optval, &subscribe, len))
102918 return -EFAULT;
102919 return 0;
102920 }
102921 @@ -4283,6 +4288,8 @@ static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
102922 */
102923 static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optval, int __user *optlen)
102924 {
102925 + __u32 autoclose;
102926 +
102927 /* Applicable to UDP-style socket only */
102928 if (sctp_style(sk, TCP))
102929 return -EOPNOTSUPP;
102930 @@ -4291,7 +4298,8 @@ static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optv
102931 len = sizeof(int);
102932 if (put_user(len, optlen))
102933 return -EFAULT;
102934 - if (copy_to_user(optval, &sctp_sk(sk)->autoclose, sizeof(int)))
102935 + autoclose = sctp_sk(sk)->autoclose;
102936 + if (copy_to_user(optval, &autoclose, sizeof(int)))
102937 return -EFAULT;
102938 return 0;
102939 }
102940 @@ -4666,12 +4674,15 @@ static int sctp_getsockopt_delayed_ack(struct sock *sk, int len,
102941 */
102942 static int sctp_getsockopt_initmsg(struct sock *sk, int len, char __user *optval, int __user *optlen)
102943 {
102944 + struct sctp_initmsg initmsg;
102945 +
102946 if (len < sizeof(struct sctp_initmsg))
102947 return -EINVAL;
102948 len = sizeof(struct sctp_initmsg);
102949 if (put_user(len, optlen))
102950 return -EFAULT;
102951 - if (copy_to_user(optval, &sctp_sk(sk)->initmsg, len))
102952 + initmsg = sctp_sk(sk)->initmsg;
102953 + if (copy_to_user(optval, &initmsg, len))
102954 return -EFAULT;
102955 return 0;
102956 }
102957 @@ -4712,6 +4723,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
102958 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
102959 if (space_left < addrlen)
102960 return -ENOMEM;
102961 + if (addrlen > sizeof(temp) || addrlen < 0)
102962 + return -EFAULT;
102963 if (copy_to_user(to, &temp, addrlen))
102964 return -EFAULT;
102965 to += addrlen;
102966 diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c
102967 index c82fdc1..4ca1f95 100644
102968 --- a/net/sctp/sysctl.c
102969 +++ b/net/sctp/sysctl.c
102970 @@ -308,7 +308,7 @@ static int proc_sctp_do_hmac_alg(struct ctl_table *ctl, int write,
102971 {
102972 struct net *net = current->nsproxy->net_ns;
102973 char tmp[8];
102974 - struct ctl_table tbl;
102975 + ctl_table_no_const tbl;
102976 int ret;
102977 int changed = 0;
102978 char *none = "none";
102979 @@ -355,7 +355,7 @@ static int proc_sctp_do_rto_min(struct ctl_table *ctl, int write,
102980 {
102981 struct net *net = current->nsproxy->net_ns;
102982 int new_value;
102983 - struct ctl_table tbl;
102984 + ctl_table_no_const tbl;
102985 unsigned int min = *(unsigned int *) ctl->extra1;
102986 unsigned int max = *(unsigned int *) ctl->extra2;
102987 int ret;
102988 @@ -382,7 +382,7 @@ static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write,
102989 {
102990 struct net *net = current->nsproxy->net_ns;
102991 int new_value;
102992 - struct ctl_table tbl;
102993 + ctl_table_no_const tbl;
102994 unsigned int min = *(unsigned int *) ctl->extra1;
102995 unsigned int max = *(unsigned int *) ctl->extra2;
102996 int ret;
102997 @@ -408,7 +408,7 @@ static int proc_sctp_do_auth(struct ctl_table *ctl, int write,
102998 loff_t *ppos)
102999 {
103000 struct net *net = current->nsproxy->net_ns;
103001 - struct ctl_table tbl;
103002 + ctl_table_no_const tbl;
103003 int new_value, ret;
103004
103005 memset(&tbl, 0, sizeof(struct ctl_table));
103006 @@ -436,7 +436,7 @@ static int proc_sctp_do_auth(struct ctl_table *ctl, int write,
103007
103008 int sctp_sysctl_net_register(struct net *net)
103009 {
103010 - struct ctl_table *table = sctp_net_table;
103011 + ctl_table_no_const *table = NULL;
103012
103013 if (!net_eq(net, &init_net)) {
103014 int i;
103015 @@ -449,7 +449,10 @@ int sctp_sysctl_net_register(struct net *net)
103016 table[i].data += (char *)(&net->sctp) - (char *)&init_net.sctp;
103017 }
103018
103019 - net->sctp.sysctl_header = register_net_sysctl(net, "net/sctp", table);
103020 + if (!net_eq(net, &init_net))
103021 + net->sctp.sysctl_header = register_net_sysctl(net, "net/sctp", table);
103022 + else
103023 + net->sctp.sysctl_header = register_net_sysctl(net, "net/sctp", sctp_net_table);
103024 return 0;
103025 }
103026
103027 diff --git a/net/socket.c b/net/socket.c
103028 index abf56b2..b8998bc 100644
103029 --- a/net/socket.c
103030 +++ b/net/socket.c
103031 @@ -89,6 +89,7 @@
103032 #include <linux/magic.h>
103033 #include <linux/slab.h>
103034 #include <linux/xattr.h>
103035 +#include <linux/in.h>
103036
103037 #include <asm/uaccess.h>
103038 #include <asm/unistd.h>
103039 @@ -112,6 +113,8 @@ unsigned int sysctl_net_busy_read __read_mostly;
103040 unsigned int sysctl_net_busy_poll __read_mostly;
103041 #endif
103042
103043 +#include <linux/grsock.h>
103044 +
103045 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
103046 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
103047 unsigned long nr_segs, loff_t pos);
103048 @@ -163,7 +166,7 @@ static const struct file_operations socket_file_ops = {
103049 */
103050
103051 static DEFINE_SPINLOCK(net_family_lock);
103052 -static const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
103053 +const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
103054
103055 /*
103056 * Statistics counters of the socket lists
103057 @@ -329,7 +332,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
103058 &sockfs_dentry_operations, SOCKFS_MAGIC);
103059 }
103060
103061 -static struct vfsmount *sock_mnt __read_mostly;
103062 +struct vfsmount *sock_mnt __read_mostly;
103063
103064 static struct file_system_type sock_fs_type = {
103065 .name = "sockfs",
103066 @@ -1257,6 +1260,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
103067 return -EAFNOSUPPORT;
103068 if (type < 0 || type >= SOCK_MAX)
103069 return -EINVAL;
103070 + if (protocol < 0)
103071 + return -EINVAL;
103072
103073 /* Compatibility.
103074
103075 @@ -1277,6 +1282,20 @@ int __sock_create(struct net *net, int family, int type, int protocol,
103076 if (err)
103077 return err;
103078
103079 + if(!kern && !gr_search_socket(family, type, protocol)) {
103080 + if (rcu_access_pointer(net_families[family]) == NULL)
103081 + return -EAFNOSUPPORT;
103082 + else
103083 + return -EACCES;
103084 + }
103085 +
103086 + if (!kern && gr_handle_sock_all(family, type, protocol)) {
103087 + if (rcu_access_pointer(net_families[family]) == NULL)
103088 + return -EAFNOSUPPORT;
103089 + else
103090 + return -EACCES;
103091 + }
103092 +
103093 /*
103094 * Allocate the socket and allow the family to set things up. if
103095 * the protocol is 0, the family is instructed to select an appropriate
103096 @@ -1528,6 +1547,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
103097 if (sock) {
103098 err = move_addr_to_kernel(umyaddr, addrlen, &address);
103099 if (err >= 0) {
103100 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
103101 + err = -EACCES;
103102 + goto error;
103103 + }
103104 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
103105 + if (err)
103106 + goto error;
103107 +
103108 err = security_socket_bind(sock,
103109 (struct sockaddr *)&address,
103110 addrlen);
103111 @@ -1536,6 +1563,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
103112 (struct sockaddr *)
103113 &address, addrlen);
103114 }
103115 +error:
103116 fput_light(sock->file, fput_needed);
103117 }
103118 return err;
103119 @@ -1559,10 +1587,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
103120 if ((unsigned int)backlog > somaxconn)
103121 backlog = somaxconn;
103122
103123 + if (gr_handle_sock_server_other(sock->sk)) {
103124 + err = -EPERM;
103125 + goto error;
103126 + }
103127 +
103128 + err = gr_search_listen(sock);
103129 + if (err)
103130 + goto error;
103131 +
103132 err = security_socket_listen(sock, backlog);
103133 if (!err)
103134 err = sock->ops->listen(sock, backlog);
103135
103136 +error:
103137 fput_light(sock->file, fput_needed);
103138 }
103139 return err;
103140 @@ -1606,6 +1644,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
103141 newsock->type = sock->type;
103142 newsock->ops = sock->ops;
103143
103144 + if (gr_handle_sock_server_other(sock->sk)) {
103145 + err = -EPERM;
103146 + sock_release(newsock);
103147 + goto out_put;
103148 + }
103149 +
103150 + err = gr_search_accept(sock);
103151 + if (err) {
103152 + sock_release(newsock);
103153 + goto out_put;
103154 + }
103155 +
103156 /*
103157 * We don't need try_module_get here, as the listening socket (sock)
103158 * has the protocol module (sock->ops->owner) held.
103159 @@ -1651,6 +1701,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
103160 fd_install(newfd, newfile);
103161 err = newfd;
103162
103163 + gr_attach_curr_ip(newsock->sk);
103164 +
103165 out_put:
103166 fput_light(sock->file, fput_needed);
103167 out:
103168 @@ -1683,6 +1735,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
103169 int, addrlen)
103170 {
103171 struct socket *sock;
103172 + struct sockaddr *sck;
103173 struct sockaddr_storage address;
103174 int err, fput_needed;
103175
103176 @@ -1693,6 +1746,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
103177 if (err < 0)
103178 goto out_put;
103179
103180 + sck = (struct sockaddr *)&address;
103181 +
103182 + if (gr_handle_sock_client(sck)) {
103183 + err = -EACCES;
103184 + goto out_put;
103185 + }
103186 +
103187 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
103188 + if (err)
103189 + goto out_put;
103190 +
103191 err =
103192 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
103193 if (err)
103194 @@ -1774,6 +1838,8 @@ SYSCALL_DEFINE3(getpeername, int, fd, struct sockaddr __user *, usockaddr,
103195 * the protocol.
103196 */
103197
103198 +asmlinkage long sys_sendto(int, void __user *, size_t, unsigned, struct sockaddr __user *, int);
103199 +
103200 SYSCALL_DEFINE6(sendto, int, fd, void __user *, buff, size_t, len,
103201 unsigned int, flags, struct sockaddr __user *, addr,
103202 int, addr_len)
103203 @@ -1840,7 +1906,7 @@ SYSCALL_DEFINE6(recvfrom, int, fd, void __user *, ubuf, size_t, size,
103204 struct socket *sock;
103205 struct iovec iov;
103206 struct msghdr msg;
103207 - struct sockaddr_storage address;
103208 + struct sockaddr_storage address = { };
103209 int err, err2;
103210 int fput_needed;
103211
103212 @@ -2066,7 +2132,7 @@ static int ___sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
103213 * checking falls down on this.
103214 */
103215 if (copy_from_user(ctl_buf,
103216 - (void __user __force *)msg_sys->msg_control,
103217 + (void __force_user *)msg_sys->msg_control,
103218 ctl_len))
103219 goto out_freectl;
103220 msg_sys->msg_control = ctl_buf;
103221 @@ -2217,7 +2283,7 @@ static int ___sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
103222 int err, total_len, len;
103223
103224 /* kernel mode address */
103225 - struct sockaddr_storage addr;
103226 + struct sockaddr_storage addr = { };
103227
103228 /* user mode address pointers */
103229 struct sockaddr __user *uaddr;
103230 @@ -2246,7 +2312,7 @@ static int ___sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
103231 /* Save the user-mode address (verify_iovec will change the
103232 * kernel msghdr to use the kernel address space)
103233 */
103234 - uaddr = (__force void __user *)msg_sys->msg_name;
103235 + uaddr = (void __force_user *)msg_sys->msg_name;
103236 uaddr_len = COMPAT_NAMELEN(msg);
103237 if (MSG_CMSG_COMPAT & flags)
103238 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
103239 @@ -2887,7 +2953,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
103240 ifr = compat_alloc_user_space(buf_size);
103241 rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
103242
103243 - if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
103244 + if (copy_in_user(ifr->ifr_name, ifr32->ifr_name, IFNAMSIZ))
103245 return -EFAULT;
103246
103247 if (put_user(convert_in ? rxnfc : compat_ptr(data),
103248 @@ -2998,7 +3064,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
103249 old_fs = get_fs();
103250 set_fs(KERNEL_DS);
103251 err = dev_ioctl(net, cmd,
103252 - (struct ifreq __user __force *) &kifr);
103253 + (struct ifreq __force_user *) &kifr);
103254 set_fs(old_fs);
103255
103256 return err;
103257 @@ -3091,7 +3157,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
103258
103259 old_fs = get_fs();
103260 set_fs(KERNEL_DS);
103261 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
103262 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
103263 set_fs(old_fs);
103264
103265 if (cmd == SIOCGIFMAP && !err) {
103266 @@ -3175,7 +3241,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
103267 ret |= get_user(rtdev, &(ur4->rt_dev));
103268 if (rtdev) {
103269 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
103270 - r4.rt_dev = (char __user __force *)devname;
103271 + r4.rt_dev = (char __force_user *)devname;
103272 devname[15] = 0;
103273 } else
103274 r4.rt_dev = NULL;
103275 @@ -3402,8 +3468,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
103276 int __user *uoptlen;
103277 int err;
103278
103279 - uoptval = (char __user __force *) optval;
103280 - uoptlen = (int __user __force *) optlen;
103281 + uoptval = (char __force_user *) optval;
103282 + uoptlen = (int __force_user *) optlen;
103283
103284 set_fs(KERNEL_DS);
103285 if (level == SOL_SOCKET)
103286 @@ -3423,7 +3489,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
103287 char __user *uoptval;
103288 int err;
103289
103290 - uoptval = (char __user __force *) optval;
103291 + uoptval = (char __force_user *) optval;
103292
103293 set_fs(KERNEL_DS);
103294 if (level == SOL_SOCKET)
103295 diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c
103296 index 0f73f45..a96aa52 100644
103297 --- a/net/sunrpc/auth_gss/svcauth_gss.c
103298 +++ b/net/sunrpc/auth_gss/svcauth_gss.c
103299 @@ -1140,7 +1140,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
103300 uint64_t *handle)
103301 {
103302 struct rsc rsci, *rscp = NULL;
103303 - static atomic64_t ctxhctr;
103304 + static atomic64_unchecked_t ctxhctr = ATOMIC64_INIT(0);
103305 long long ctxh;
103306 struct gss_api_mech *gm = NULL;
103307 time_t expiry;
103308 @@ -1151,7 +1151,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
103309 status = -ENOMEM;
103310 /* the handle needs to be just a unique id,
103311 * use a static counter */
103312 - ctxh = atomic64_inc_return(&ctxhctr);
103313 + ctxh = atomic64_inc_return_unchecked(&ctxhctr);
103314
103315 /* make a copy for the caller */
103316 *handle = ctxh;
103317 diff --git a/net/sunrpc/cache.c b/net/sunrpc/cache.c
103318 index ae333c1..18521f0 100644
103319 --- a/net/sunrpc/cache.c
103320 +++ b/net/sunrpc/cache.c
103321 @@ -1609,7 +1609,7 @@ static int create_cache_proc_entries(struct cache_detail *cd, struct net *net)
103322 struct sunrpc_net *sn;
103323
103324 sn = net_generic(net, sunrpc_net_id);
103325 - cd->u.procfs.proc_ent = proc_mkdir(cd->name, sn->proc_net_rpc);
103326 + cd->u.procfs.proc_ent = proc_mkdir_restrict(cd->name, sn->proc_net_rpc);
103327 if (cd->u.procfs.proc_ent == NULL)
103328 goto out_nomem;
103329 cd->u.procfs.channel_ent = NULL;
103330 diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
103331 index 2e6ab10..3170800 100644
103332 --- a/net/sunrpc/clnt.c
103333 +++ b/net/sunrpc/clnt.c
103334 @@ -1425,7 +1425,9 @@ call_start(struct rpc_task *task)
103335 (RPC_IS_ASYNC(task) ? "async" : "sync"));
103336
103337 /* Increment call count */
103338 - task->tk_msg.rpc_proc->p_count++;
103339 + pax_open_kernel();
103340 + (*(unsigned int *)&task->tk_msg.rpc_proc->p_count)++;
103341 + pax_close_kernel();
103342 clnt->cl_stats->rpccnt++;
103343 task->tk_action = call_reserve;
103344 }
103345 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
103346 index 25578af..a29298d 100644
103347 --- a/net/sunrpc/sched.c
103348 +++ b/net/sunrpc/sched.c
103349 @@ -261,9 +261,9 @@ static int rpc_wait_bit_killable(void *word)
103350 #if defined(RPC_DEBUG) || defined(RPC_TRACEPOINTS)
103351 static void rpc_task_set_debuginfo(struct rpc_task *task)
103352 {
103353 - static atomic_t rpc_pid;
103354 + static atomic_unchecked_t rpc_pid;
103355
103356 - task->tk_pid = atomic_inc_return(&rpc_pid);
103357 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
103358 }
103359 #else
103360 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
103361 diff --git a/net/sunrpc/stats.c b/net/sunrpc/stats.c
103362 index 5453049..465669a 100644
103363 --- a/net/sunrpc/stats.c
103364 +++ b/net/sunrpc/stats.c
103365 @@ -267,7 +267,7 @@ int rpc_proc_init(struct net *net)
103366
103367 dprintk("RPC: registering /proc/net/rpc\n");
103368 sn = net_generic(net, sunrpc_net_id);
103369 - sn->proc_net_rpc = proc_mkdir("rpc", net->proc_net);
103370 + sn->proc_net_rpc = proc_mkdir_restrict("rpc", net->proc_net);
103371 if (sn->proc_net_rpc == NULL)
103372 return -ENOMEM;
103373
103374 diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c
103375 index 5de6801..b4e330d 100644
103376 --- a/net/sunrpc/svc.c
103377 +++ b/net/sunrpc/svc.c
103378 @@ -1167,7 +1167,9 @@ svc_process_common(struct svc_rqst *rqstp, struct kvec *argv, struct kvec *resv)
103379 svc_putnl(resv, RPC_SUCCESS);
103380
103381 /* Bump per-procedure stats counter */
103382 - procp->pc_count++;
103383 + pax_open_kernel();
103384 + (*(unsigned int *)&procp->pc_count)++;
103385 + pax_close_kernel();
103386
103387 /* Initialize storage for argp and resp */
103388 memset(rqstp->rq_argp, 0, procp->pc_argsize);
103389 diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c
103390 index 621ca7b..59421dd 100644
103391 --- a/net/sunrpc/svcauth_unix.c
103392 +++ b/net/sunrpc/svcauth_unix.c
103393 @@ -414,7 +414,7 @@ struct unix_gid {
103394 struct group_info *gi;
103395 };
103396
103397 -static int unix_gid_hash(kuid_t uid)
103398 +static int __intentional_overflow(-1) unix_gid_hash(kuid_t uid)
103399 {
103400 return hash_long(from_kuid(&init_user_ns, uid), GID_HASHBITS);
103401 }
103402 @@ -470,7 +470,7 @@ static void unix_gid_request(struct cache_detail *cd,
103403 (*bpp)[-1] = '\n';
103404 }
103405
103406 -static struct unix_gid *unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
103407 +static struct unix_gid * __intentional_overflow(-1) unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
103408
103409 static int unix_gid_parse(struct cache_detail *cd,
103410 char *mesg, int mlen)
103411 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
103412 index c1b6270..05089c1 100644
103413 --- a/net/sunrpc/xprtrdma/svc_rdma.c
103414 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
103415 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
103416 static unsigned int min_max_inline = 4096;
103417 static unsigned int max_max_inline = 65536;
103418
103419 -atomic_t rdma_stat_recv;
103420 -atomic_t rdma_stat_read;
103421 -atomic_t rdma_stat_write;
103422 -atomic_t rdma_stat_sq_starve;
103423 -atomic_t rdma_stat_rq_starve;
103424 -atomic_t rdma_stat_rq_poll;
103425 -atomic_t rdma_stat_rq_prod;
103426 -atomic_t rdma_stat_sq_poll;
103427 -atomic_t rdma_stat_sq_prod;
103428 +atomic_unchecked_t rdma_stat_recv;
103429 +atomic_unchecked_t rdma_stat_read;
103430 +atomic_unchecked_t rdma_stat_write;
103431 +atomic_unchecked_t rdma_stat_sq_starve;
103432 +atomic_unchecked_t rdma_stat_rq_starve;
103433 +atomic_unchecked_t rdma_stat_rq_poll;
103434 +atomic_unchecked_t rdma_stat_rq_prod;
103435 +atomic_unchecked_t rdma_stat_sq_poll;
103436 +atomic_unchecked_t rdma_stat_sq_prod;
103437
103438 /* Temporary NFS request map and context caches */
103439 struct kmem_cache *svc_rdma_map_cachep;
103440 @@ -110,7 +110,7 @@ static int read_reset_stat(struct ctl_table *table, int write,
103441 len -= *ppos;
103442 if (len > *lenp)
103443 len = *lenp;
103444 - if (len && copy_to_user(buffer, str_buf, len))
103445 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
103446 return -EFAULT;
103447 *lenp = len;
103448 *ppos += len;
103449 @@ -151,63 +151,63 @@ static struct ctl_table svcrdma_parm_table[] = {
103450 {
103451 .procname = "rdma_stat_read",
103452 .data = &rdma_stat_read,
103453 - .maxlen = sizeof(atomic_t),
103454 + .maxlen = sizeof(atomic_unchecked_t),
103455 .mode = 0644,
103456 .proc_handler = read_reset_stat,
103457 },
103458 {
103459 .procname = "rdma_stat_recv",
103460 .data = &rdma_stat_recv,
103461 - .maxlen = sizeof(atomic_t),
103462 + .maxlen = sizeof(atomic_unchecked_t),
103463 .mode = 0644,
103464 .proc_handler = read_reset_stat,
103465 },
103466 {
103467 .procname = "rdma_stat_write",
103468 .data = &rdma_stat_write,
103469 - .maxlen = sizeof(atomic_t),
103470 + .maxlen = sizeof(atomic_unchecked_t),
103471 .mode = 0644,
103472 .proc_handler = read_reset_stat,
103473 },
103474 {
103475 .procname = "rdma_stat_sq_starve",
103476 .data = &rdma_stat_sq_starve,
103477 - .maxlen = sizeof(atomic_t),
103478 + .maxlen = sizeof(atomic_unchecked_t),
103479 .mode = 0644,
103480 .proc_handler = read_reset_stat,
103481 },
103482 {
103483 .procname = "rdma_stat_rq_starve",
103484 .data = &rdma_stat_rq_starve,
103485 - .maxlen = sizeof(atomic_t),
103486 + .maxlen = sizeof(atomic_unchecked_t),
103487 .mode = 0644,
103488 .proc_handler = read_reset_stat,
103489 },
103490 {
103491 .procname = "rdma_stat_rq_poll",
103492 .data = &rdma_stat_rq_poll,
103493 - .maxlen = sizeof(atomic_t),
103494 + .maxlen = sizeof(atomic_unchecked_t),
103495 .mode = 0644,
103496 .proc_handler = read_reset_stat,
103497 },
103498 {
103499 .procname = "rdma_stat_rq_prod",
103500 .data = &rdma_stat_rq_prod,
103501 - .maxlen = sizeof(atomic_t),
103502 + .maxlen = sizeof(atomic_unchecked_t),
103503 .mode = 0644,
103504 .proc_handler = read_reset_stat,
103505 },
103506 {
103507 .procname = "rdma_stat_sq_poll",
103508 .data = &rdma_stat_sq_poll,
103509 - .maxlen = sizeof(atomic_t),
103510 + .maxlen = sizeof(atomic_unchecked_t),
103511 .mode = 0644,
103512 .proc_handler = read_reset_stat,
103513 },
103514 {
103515 .procname = "rdma_stat_sq_prod",
103516 .data = &rdma_stat_sq_prod,
103517 - .maxlen = sizeof(atomic_t),
103518 + .maxlen = sizeof(atomic_unchecked_t),
103519 .mode = 0644,
103520 .proc_handler = read_reset_stat,
103521 },
103522 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
103523 index 8d904e4..b2fc727 100644
103524 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
103525 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
103526 @@ -504,7 +504,7 @@ next_sge:
103527 svc_rdma_put_context(ctxt, 0);
103528 goto out;
103529 }
103530 - atomic_inc(&rdma_stat_read);
103531 + atomic_inc_unchecked(&rdma_stat_read);
103532
103533 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
103534 chl_map->ch[ch_no].count -= read_wr.num_sge;
103535 @@ -607,7 +607,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
103536 dto_q);
103537 list_del_init(&ctxt->dto_q);
103538 } else {
103539 - atomic_inc(&rdma_stat_rq_starve);
103540 + atomic_inc_unchecked(&rdma_stat_rq_starve);
103541 clear_bit(XPT_DATA, &xprt->xpt_flags);
103542 ctxt = NULL;
103543 }
103544 @@ -627,7 +627,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
103545 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
103546 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
103547 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
103548 - atomic_inc(&rdma_stat_recv);
103549 + atomic_inc_unchecked(&rdma_stat_recv);
103550
103551 /* Build up the XDR from the receive buffers. */
103552 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
103553 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
103554 index 7e024a5..17f13d3 100644
103555 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
103556 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
103557 @@ -363,7 +363,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
103558 write_wr.wr.rdma.remote_addr = to;
103559
103560 /* Post It */
103561 - atomic_inc(&rdma_stat_write);
103562 + atomic_inc_unchecked(&rdma_stat_write);
103563 if (svc_rdma_send(xprt, &write_wr))
103564 goto err;
103565 return 0;
103566 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
103567 index 25688fa..dc72003 100644
103568 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
103569 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
103570 @@ -292,7 +292,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
103571 return;
103572
103573 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
103574 - atomic_inc(&rdma_stat_rq_poll);
103575 + atomic_inc_unchecked(&rdma_stat_rq_poll);
103576
103577 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
103578 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
103579 @@ -314,7 +314,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
103580 }
103581
103582 if (ctxt)
103583 - atomic_inc(&rdma_stat_rq_prod);
103584 + atomic_inc_unchecked(&rdma_stat_rq_prod);
103585
103586 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
103587 /*
103588 @@ -386,7 +386,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
103589 return;
103590
103591 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
103592 - atomic_inc(&rdma_stat_sq_poll);
103593 + atomic_inc_unchecked(&rdma_stat_sq_poll);
103594 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
103595 if (wc.status != IB_WC_SUCCESS)
103596 /* Close the transport */
103597 @@ -404,7 +404,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
103598 }
103599
103600 if (ctxt)
103601 - atomic_inc(&rdma_stat_sq_prod);
103602 + atomic_inc_unchecked(&rdma_stat_sq_prod);
103603 }
103604
103605 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
103606 @@ -1261,7 +1261,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
103607 spin_lock_bh(&xprt->sc_lock);
103608 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
103609 spin_unlock_bh(&xprt->sc_lock);
103610 - atomic_inc(&rdma_stat_sq_starve);
103611 + atomic_inc_unchecked(&rdma_stat_sq_starve);
103612
103613 /* See if we can opportunistically reap SQ WR to make room */
103614 sq_cq_reap(xprt);
103615 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
103616 index e7000be..e3b0ba7 100644
103617 --- a/net/sysctl_net.c
103618 +++ b/net/sysctl_net.c
103619 @@ -46,7 +46,7 @@ static int net_ctl_permissions(struct ctl_table_header *head,
103620 kgid_t root_gid = make_kgid(net->user_ns, 0);
103621
103622 /* Allow network administrator to have same access as root. */
103623 - if (ns_capable(net->user_ns, CAP_NET_ADMIN) ||
103624 + if (ns_capable_nolog(net->user_ns, CAP_NET_ADMIN) ||
103625 uid_eq(root_uid, current_euid())) {
103626 int mode = (table->mode >> 6) & 7;
103627 return (mode << 6) | (mode << 3) | mode;
103628 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
103629 index 6424372..afd36e9 100644
103630 --- a/net/tipc/subscr.c
103631 +++ b/net/tipc/subscr.c
103632 @@ -97,7 +97,7 @@ static void subscr_send_event(struct tipc_subscription *sub, u32 found_lower,
103633 struct tipc_subscriber *subscriber = sub->subscriber;
103634 struct kvec msg_sect;
103635
103636 - msg_sect.iov_base = (void *)&sub->evt;
103637 + msg_sect.iov_base = &sub->evt;
103638 msg_sect.iov_len = sizeof(struct tipc_event);
103639 sub->evt.event = htohl(event, sub->swap);
103640 sub->evt.found_lower = htohl(found_lower, sub->swap);
103641 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
103642 index bb7e8ba..9f444c6 100644
103643 --- a/net/unix/af_unix.c
103644 +++ b/net/unix/af_unix.c
103645 @@ -791,6 +791,12 @@ static struct sock *unix_find_other(struct net *net,
103646 err = -ECONNREFUSED;
103647 if (!S_ISSOCK(inode->i_mode))
103648 goto put_fail;
103649 +
103650 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
103651 + err = -EACCES;
103652 + goto put_fail;
103653 + }
103654 +
103655 u = unix_find_socket_byinode(inode);
103656 if (!u)
103657 goto put_fail;
103658 @@ -811,6 +817,13 @@ static struct sock *unix_find_other(struct net *net,
103659 if (u) {
103660 struct dentry *dentry;
103661 dentry = unix_sk(u)->path.dentry;
103662 +
103663 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
103664 + err = -EPERM;
103665 + sock_put(u);
103666 + goto fail;
103667 + }
103668 +
103669 if (dentry)
103670 touch_atime(&unix_sk(u)->path);
103671 } else
103672 @@ -844,12 +857,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
103673 */
103674 err = security_path_mknod(&path, dentry, mode, 0);
103675 if (!err) {
103676 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
103677 + err = -EACCES;
103678 + goto out;
103679 + }
103680 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
103681 if (!err) {
103682 res->mnt = mntget(path.mnt);
103683 res->dentry = dget(dentry);
103684 + gr_handle_create(dentry, path.mnt);
103685 }
103686 }
103687 +out:
103688 done_path_create(&path, dentry);
103689 return err;
103690 }
103691 @@ -2344,9 +2363,13 @@ static int unix_seq_show(struct seq_file *seq, void *v)
103692 seq_puts(seq, "Num RefCount Protocol Flags Type St "
103693 "Inode Path\n");
103694 else {
103695 - struct sock *s = v;
103696 + struct sock *s = v, *peer;
103697 struct unix_sock *u = unix_sk(s);
103698 unix_state_lock(s);
103699 + peer = unix_peer(s);
103700 + unix_state_unlock(s);
103701 +
103702 + unix_state_double_lock(s, peer);
103703
103704 seq_printf(seq, "%pK: %08X %08X %08X %04X %02X %5lu",
103705 s,
103706 @@ -2373,8 +2396,10 @@ static int unix_seq_show(struct seq_file *seq, void *v)
103707 }
103708 for ( ; i < len; i++)
103709 seq_putc(seq, u->addr->name->sun_path[i]);
103710 - }
103711 - unix_state_unlock(s);
103712 + } else if (peer)
103713 + seq_printf(seq, " P%lu", sock_i_ino(peer));
103714 +
103715 + unix_state_double_unlock(s, peer);
103716 seq_putc(seq, '\n');
103717 }
103718
103719 diff --git a/net/unix/sysctl_net_unix.c b/net/unix/sysctl_net_unix.c
103720 index b3d5150..ff3a837 100644
103721 --- a/net/unix/sysctl_net_unix.c
103722 +++ b/net/unix/sysctl_net_unix.c
103723 @@ -28,7 +28,7 @@ static struct ctl_table unix_table[] = {
103724
103725 int __net_init unix_sysctl_register(struct net *net)
103726 {
103727 - struct ctl_table *table;
103728 + ctl_table_no_const *table;
103729
103730 table = kmemdup(unix_table, sizeof(unix_table), GFP_KERNEL);
103731 if (table == NULL)
103732 diff --git a/net/vmw_vsock/vmci_transport_notify.c b/net/vmw_vsock/vmci_transport_notify.c
103733 index 9b7f207..2596621 100644
103734 --- a/net/vmw_vsock/vmci_transport_notify.c
103735 +++ b/net/vmw_vsock/vmci_transport_notify.c
103736 @@ -662,19 +662,19 @@ static void vmci_transport_notify_pkt_process_negotiate(struct sock *sk)
103737
103738 /* Socket control packet based operations. */
103739 struct vmci_transport_notify_ops vmci_transport_notify_pkt_ops = {
103740 - vmci_transport_notify_pkt_socket_init,
103741 - vmci_transport_notify_pkt_socket_destruct,
103742 - vmci_transport_notify_pkt_poll_in,
103743 - vmci_transport_notify_pkt_poll_out,
103744 - vmci_transport_notify_pkt_handle_pkt,
103745 - vmci_transport_notify_pkt_recv_init,
103746 - vmci_transport_notify_pkt_recv_pre_block,
103747 - vmci_transport_notify_pkt_recv_pre_dequeue,
103748 - vmci_transport_notify_pkt_recv_post_dequeue,
103749 - vmci_transport_notify_pkt_send_init,
103750 - vmci_transport_notify_pkt_send_pre_block,
103751 - vmci_transport_notify_pkt_send_pre_enqueue,
103752 - vmci_transport_notify_pkt_send_post_enqueue,
103753 - vmci_transport_notify_pkt_process_request,
103754 - vmci_transport_notify_pkt_process_negotiate,
103755 + .socket_init = vmci_transport_notify_pkt_socket_init,
103756 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
103757 + .poll_in = vmci_transport_notify_pkt_poll_in,
103758 + .poll_out = vmci_transport_notify_pkt_poll_out,
103759 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
103760 + .recv_init = vmci_transport_notify_pkt_recv_init,
103761 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
103762 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
103763 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
103764 + .send_init = vmci_transport_notify_pkt_send_init,
103765 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
103766 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
103767 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
103768 + .process_request = vmci_transport_notify_pkt_process_request,
103769 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
103770 };
103771 diff --git a/net/vmw_vsock/vmci_transport_notify_qstate.c b/net/vmw_vsock/vmci_transport_notify_qstate.c
103772 index dc9c792..3089de0 100644
103773 --- a/net/vmw_vsock/vmci_transport_notify_qstate.c
103774 +++ b/net/vmw_vsock/vmci_transport_notify_qstate.c
103775 @@ -420,19 +420,19 @@ vmci_transport_notify_pkt_send_pre_enqueue(
103776
103777 /* Socket always on control packet based operations. */
103778 struct vmci_transport_notify_ops vmci_transport_notify_pkt_q_state_ops = {
103779 - vmci_transport_notify_pkt_socket_init,
103780 - vmci_transport_notify_pkt_socket_destruct,
103781 - vmci_transport_notify_pkt_poll_in,
103782 - vmci_transport_notify_pkt_poll_out,
103783 - vmci_transport_notify_pkt_handle_pkt,
103784 - vmci_transport_notify_pkt_recv_init,
103785 - vmci_transport_notify_pkt_recv_pre_block,
103786 - vmci_transport_notify_pkt_recv_pre_dequeue,
103787 - vmci_transport_notify_pkt_recv_post_dequeue,
103788 - vmci_transport_notify_pkt_send_init,
103789 - vmci_transport_notify_pkt_send_pre_block,
103790 - vmci_transport_notify_pkt_send_pre_enqueue,
103791 - vmci_transport_notify_pkt_send_post_enqueue,
103792 - vmci_transport_notify_pkt_process_request,
103793 - vmci_transport_notify_pkt_process_negotiate,
103794 + .socket_init = vmci_transport_notify_pkt_socket_init,
103795 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
103796 + .poll_in = vmci_transport_notify_pkt_poll_in,
103797 + .poll_out = vmci_transport_notify_pkt_poll_out,
103798 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
103799 + .recv_init = vmci_transport_notify_pkt_recv_init,
103800 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
103801 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
103802 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
103803 + .send_init = vmci_transport_notify_pkt_send_init,
103804 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
103805 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
103806 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
103807 + .process_request = vmci_transport_notify_pkt_process_request,
103808 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
103809 };
103810 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
103811 index c8717c1..08539f5 100644
103812 --- a/net/wireless/wext-core.c
103813 +++ b/net/wireless/wext-core.c
103814 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
103815 */
103816
103817 /* Support for very large requests */
103818 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
103819 - (user_length > descr->max_tokens)) {
103820 + if (user_length > descr->max_tokens) {
103821 /* Allow userspace to GET more than max so
103822 * we can support any size GET requests.
103823 * There is still a limit : -ENOMEM.
103824 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
103825 }
103826 }
103827
103828 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
103829 - /*
103830 - * If this is a GET, but not NOMAX, it means that the extra
103831 - * data is not bounded by userspace, but by max_tokens. Thus
103832 - * set the length to max_tokens. This matches the extra data
103833 - * allocation.
103834 - * The driver should fill it with the number of tokens it
103835 - * provided, and it may check iwp->length rather than having
103836 - * knowledge of max_tokens. If the driver doesn't change the
103837 - * iwp->length, this ioctl just copies back max_token tokens
103838 - * filled with zeroes. Hopefully the driver isn't claiming
103839 - * them to be valid data.
103840 - */
103841 - iwp->length = descr->max_tokens;
103842 - }
103843 -
103844 err = handler(dev, info, (union iwreq_data *) iwp, extra);
103845
103846 iwp->length += essid_compat;
103847 diff --git a/net/x25/sysctl_net_x25.c b/net/x25/sysctl_net_x25.c
103848 index 4323952..a06dfe1 100644
103849 --- a/net/x25/sysctl_net_x25.c
103850 +++ b/net/x25/sysctl_net_x25.c
103851 @@ -70,7 +70,7 @@ static struct ctl_table x25_table[] = {
103852 .mode = 0644,
103853 .proc_handler = proc_dointvec,
103854 },
103855 - { 0, },
103856 + { },
103857 };
103858
103859 void __init x25_register_sysctl(void)
103860 diff --git a/net/x25/x25_proc.c b/net/x25/x25_proc.c
103861 index 0917f04..f4e3d8c 100644
103862 --- a/net/x25/x25_proc.c
103863 +++ b/net/x25/x25_proc.c
103864 @@ -209,7 +209,7 @@ static const struct file_operations x25_seq_forward_fops = {
103865
103866 int __init x25_proc_init(void)
103867 {
103868 - if (!proc_mkdir("x25", init_net.proc_net))
103869 + if (!proc_mkdir_restrict("x25", init_net.proc_net))
103870 return -ENOMEM;
103871
103872 if (!proc_create("x25/route", S_IRUGO, init_net.proc_net,
103873 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
103874 index c08fbd1..3d99e85 100644
103875 --- a/net/xfrm/xfrm_policy.c
103876 +++ b/net/xfrm/xfrm_policy.c
103877 @@ -325,7 +325,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
103878 {
103879 policy->walk.dead = 1;
103880
103881 - atomic_inc(&policy->genid);
103882 + atomic_inc_unchecked(&policy->genid);
103883
103884 if (del_timer(&policy->polq.hold_timer))
103885 xfrm_pol_put(policy);
103886 @@ -659,7 +659,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
103887 hlist_add_head(&policy->bydst, chain);
103888 xfrm_pol_hold(policy);
103889 net->xfrm.policy_count[dir]++;
103890 - atomic_inc(&net->xfrm.flow_cache_genid);
103891 + atomic_inc_unchecked(&net->xfrm.flow_cache_genid);
103892
103893 /* After previous checking, family can either be AF_INET or AF_INET6 */
103894 if (policy->family == AF_INET)
103895 @@ -1759,7 +1759,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
103896
103897 xdst->num_pols = num_pols;
103898 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy *) * num_pols);
103899 - xdst->policy_genid = atomic_read(&pols[0]->genid);
103900 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
103901
103902 return xdst;
103903 }
103904 @@ -2546,10 +2546,11 @@ void xfrm_garbage_collect(struct net *net)
103905 }
103906 EXPORT_SYMBOL(xfrm_garbage_collect);
103907
103908 -static void xfrm_garbage_collect_deferred(struct net *net)
103909 +void xfrm_garbage_collect_deferred(struct net *net)
103910 {
103911 flow_cache_flush_deferred(net);
103912 }
103913 +EXPORT_SYMBOL(xfrm_garbage_collect_deferred);
103914
103915 static void xfrm_init_pmtu(struct dst_entry *dst)
103916 {
103917 @@ -2599,7 +2600,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
103918 if (xdst->xfrm_genid != dst->xfrm->genid)
103919 return 0;
103920 if (xdst->num_pols > 0 &&
103921 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
103922 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
103923 return 0;
103924
103925 mtu = dst_mtu(dst->child);
103926 @@ -2687,8 +2688,6 @@ int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo)
103927 dst_ops->link_failure = xfrm_link_failure;
103928 if (likely(dst_ops->neigh_lookup == NULL))
103929 dst_ops->neigh_lookup = xfrm_neigh_lookup;
103930 - if (likely(afinfo->garbage_collect == NULL))
103931 - afinfo->garbage_collect = xfrm_garbage_collect_deferred;
103932 rcu_assign_pointer(xfrm_policy_afinfo[afinfo->family], afinfo);
103933 }
103934 spin_unlock(&xfrm_policy_afinfo_lock);
103935 @@ -2742,7 +2741,6 @@ int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo)
103936 dst_ops->check = NULL;
103937 dst_ops->negative_advice = NULL;
103938 dst_ops->link_failure = NULL;
103939 - afinfo->garbage_collect = NULL;
103940 }
103941 return err;
103942 }
103943 @@ -3137,7 +3135,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
103944 sizeof(pol->xfrm_vec[i].saddr));
103945 pol->xfrm_vec[i].encap_family = mp->new_family;
103946 /* flush bundles */
103947 - atomic_inc(&pol->genid);
103948 + atomic_inc_unchecked(&pol->genid);
103949 }
103950 }
103951
103952 diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
103953 index 8e9c781..3972135 100644
103954 --- a/net/xfrm/xfrm_state.c
103955 +++ b/net/xfrm/xfrm_state.c
103956 @@ -173,12 +173,14 @@ int xfrm_register_type(const struct xfrm_type *type, unsigned short family)
103957
103958 if (unlikely(afinfo == NULL))
103959 return -EAFNOSUPPORT;
103960 - typemap = afinfo->type_map;
103961 + typemap = (const struct xfrm_type **)afinfo->type_map;
103962 spin_lock_bh(&xfrm_type_lock);
103963
103964 - if (likely(typemap[type->proto] == NULL))
103965 + if (likely(typemap[type->proto] == NULL)) {
103966 + pax_open_kernel();
103967 typemap[type->proto] = type;
103968 - else
103969 + pax_close_kernel();
103970 + } else
103971 err = -EEXIST;
103972 spin_unlock_bh(&xfrm_type_lock);
103973 xfrm_state_put_afinfo(afinfo);
103974 @@ -194,13 +196,16 @@ int xfrm_unregister_type(const struct xfrm_type *type, unsigned short family)
103975
103976 if (unlikely(afinfo == NULL))
103977 return -EAFNOSUPPORT;
103978 - typemap = afinfo->type_map;
103979 + typemap = (const struct xfrm_type **)afinfo->type_map;
103980 spin_lock_bh(&xfrm_type_lock);
103981
103982 if (unlikely(typemap[type->proto] != type))
103983 err = -ENOENT;
103984 - else
103985 + else {
103986 + pax_open_kernel();
103987 typemap[type->proto] = NULL;
103988 + pax_close_kernel();
103989 + }
103990 spin_unlock_bh(&xfrm_type_lock);
103991 xfrm_state_put_afinfo(afinfo);
103992 return err;
103993 @@ -210,7 +215,6 @@ EXPORT_SYMBOL(xfrm_unregister_type);
103994 static const struct xfrm_type *xfrm_get_type(u8 proto, unsigned short family)
103995 {
103996 struct xfrm_state_afinfo *afinfo;
103997 - const struct xfrm_type **typemap;
103998 const struct xfrm_type *type;
103999 int modload_attempted = 0;
104000
104001 @@ -218,9 +222,8 @@ retry:
104002 afinfo = xfrm_state_get_afinfo(family);
104003 if (unlikely(afinfo == NULL))
104004 return NULL;
104005 - typemap = afinfo->type_map;
104006
104007 - type = typemap[proto];
104008 + type = afinfo->type_map[proto];
104009 if (unlikely(type && !try_module_get(type->owner)))
104010 type = NULL;
104011 if (!type && !modload_attempted) {
104012 @@ -254,7 +257,7 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
104013 return -EAFNOSUPPORT;
104014
104015 err = -EEXIST;
104016 - modemap = afinfo->mode_map;
104017 + modemap = (struct xfrm_mode **)afinfo->mode_map;
104018 spin_lock_bh(&xfrm_mode_lock);
104019 if (modemap[mode->encap])
104020 goto out;
104021 @@ -263,8 +266,10 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
104022 if (!try_module_get(afinfo->owner))
104023 goto out;
104024
104025 - mode->afinfo = afinfo;
104026 + pax_open_kernel();
104027 + *(const void **)&mode->afinfo = afinfo;
104028 modemap[mode->encap] = mode;
104029 + pax_close_kernel();
104030 err = 0;
104031
104032 out:
104033 @@ -288,10 +293,12 @@ int xfrm_unregister_mode(struct xfrm_mode *mode, int family)
104034 return -EAFNOSUPPORT;
104035
104036 err = -ENOENT;
104037 - modemap = afinfo->mode_map;
104038 + modemap = (struct xfrm_mode **)afinfo->mode_map;
104039 spin_lock_bh(&xfrm_mode_lock);
104040 if (likely(modemap[mode->encap] == mode)) {
104041 + pax_open_kernel();
104042 modemap[mode->encap] = NULL;
104043 + pax_close_kernel();
104044 module_put(mode->afinfo->owner);
104045 err = 0;
104046 }
104047 @@ -1519,10 +1526,10 @@ EXPORT_SYMBOL(xfrm_find_acq_byseq);
104048 u32 xfrm_get_acqseq(void)
104049 {
104050 u32 res;
104051 - static atomic_t acqseq;
104052 + static atomic_unchecked_t acqseq;
104053
104054 do {
104055 - res = atomic_inc_return(&acqseq);
104056 + res = atomic_inc_return_unchecked(&acqseq);
104057 } while (!res);
104058
104059 return res;
104060 diff --git a/net/xfrm/xfrm_sysctl.c b/net/xfrm/xfrm_sysctl.c
104061 index 05a6e3d..6716ec9 100644
104062 --- a/net/xfrm/xfrm_sysctl.c
104063 +++ b/net/xfrm/xfrm_sysctl.c
104064 @@ -42,7 +42,7 @@ static struct ctl_table xfrm_table[] = {
104065
104066 int __net_init xfrm_sysctl_init(struct net *net)
104067 {
104068 - struct ctl_table *table;
104069 + ctl_table_no_const *table;
104070
104071 __xfrm_sysctl_init(net);
104072
104073 diff --git a/scripts/Makefile b/scripts/Makefile
104074 index 1d07860..f16fc22 100644
104075 --- a/scripts/Makefile
104076 +++ b/scripts/Makefile
104077 @@ -40,3 +40,5 @@ subdir-$(CONFIG_DTC) += dtc
104078
104079 # Let clean descend into subdirs
104080 subdir- += basic kconfig package selinux
104081 +
104082 +clean-files := randstruct.seed
104083 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
104084 index 003bc26..d5f02b0 100644
104085 --- a/scripts/Makefile.build
104086 +++ b/scripts/Makefile.build
104087 @@ -121,7 +121,7 @@ endif
104088 endif
104089
104090 # Do not include host rules unless needed
104091 -ifneq ($(hostprogs-y)$(hostprogs-m),)
104092 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
104093 include scripts/Makefile.host
104094 endif
104095
104096 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
104097 index 686cb0d..9d653bf 100644
104098 --- a/scripts/Makefile.clean
104099 +++ b/scripts/Makefile.clean
104100 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
104101 __clean-files := $(extra-y) $(always) \
104102 $(targets) $(clean-files) \
104103 $(host-progs) \
104104 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
104105 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
104106 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
104107
104108 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
104109
104110 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
104111 index 1ac414f..38575f7 100644
104112 --- a/scripts/Makefile.host
104113 +++ b/scripts/Makefile.host
104114 @@ -31,6 +31,8 @@
104115 # Note: Shared libraries consisting of C++ files are not supported
104116
104117 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
104118 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
104119 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
104120
104121 # C code
104122 # Executables compiled from a single .c file
104123 @@ -54,11 +56,15 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
104124 # Shared libaries (only .c supported)
104125 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
104126 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
104127 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
104128 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
104129 # Remove .so files from "xxx-objs"
104130 host-cobjs := $(filter-out %.so,$(host-cobjs))
104131 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
104132
104133 -#Object (.o) files used by the shared libaries
104134 +# Object (.o) files used by the shared libaries
104135 host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
104136 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
104137
104138 # output directory for programs/.o files
104139 # hostprogs-y := tools/build may have been specified. Retrieve directory
104140 @@ -82,7 +88,9 @@ host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
104141 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
104142 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
104143 host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
104144 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
104145 host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
104146 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
104147 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
104148
104149 obj-dirs += $(host-objdirs)
104150 @@ -156,6 +164,13 @@ quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
104151 $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
104152 $(call if_changed_dep,host-cshobjs)
104153
104154 +# Compile .c file, create position independent .o file
104155 +# host-cxxshobjs -> .o
104156 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
104157 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
104158 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
104159 + $(call if_changed_dep,host-cxxshobjs)
104160 +
104161 # Link a shared library, based on position independent .o files
104162 # *.o -> .so shared library (host-cshlib)
104163 quiet_cmd_host-cshlib = HOSTLLD -shared $@
104164 @@ -165,6 +180,15 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
104165 $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
104166 $(call if_changed,host-cshlib)
104167
104168 +# Link a shared library, based on position independent .o files
104169 +# *.o -> .so shared library (host-cxxshlib)
104170 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
104171 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
104172 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
104173 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
104174 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
104175 + $(call if_changed,host-cxxshlib)
104176 +
104177 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
104178 - $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
104179 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
104180
104181 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
104182 index 078fe1d..fbdb363 100644
104183 --- a/scripts/basic/fixdep.c
104184 +++ b/scripts/basic/fixdep.c
104185 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
104186 /*
104187 * Lookup a value in the configuration string.
104188 */
104189 -static int is_defined_config(const char *name, int len, unsigned int hash)
104190 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
104191 {
104192 struct item *aux;
104193
104194 @@ -211,10 +211,10 @@ static void clear_config(void)
104195 /*
104196 * Record the use of a CONFIG_* word.
104197 */
104198 -static void use_config(const char *m, int slen)
104199 +static void use_config(const char *m, unsigned int slen)
104200 {
104201 unsigned int hash = strhash(m, slen);
104202 - int c, i;
104203 + unsigned int c, i;
104204
104205 if (is_defined_config(m, slen, hash))
104206 return;
104207 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
104208
104209 static void parse_config_file(const char *map, size_t len)
104210 {
104211 - const int *end = (const int *) (map + len);
104212 + const unsigned int *end = (const unsigned int *) (map + len);
104213 /* start at +1, so that p can never be < map */
104214 - const int *m = (const int *) map + 1;
104215 + const unsigned int *m = (const unsigned int *) map + 1;
104216 const char *p, *q;
104217
104218 for (; m < end; m++) {
104219 @@ -435,7 +435,7 @@ static void print_deps(void)
104220 static void traps(void)
104221 {
104222 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
104223 - int *p = (int *)test;
104224 + unsigned int *p = (unsigned int *)test;
104225
104226 if (*p != INT_CONF) {
104227 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianness? %#x\n",
104228 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
104229 new file mode 100644
104230 index 0000000..3fd3699
104231 --- /dev/null
104232 +++ b/scripts/gcc-plugin.sh
104233 @@ -0,0 +1,43 @@
104234 +#!/bin/bash
104235 +srctree=$(dirname "$0")
104236 +gccplugins_dir=$($3 -print-file-name=plugin)
104237 +plugincc=$($1 -E - -o /dev/null -I${srctree}/../tools/gcc -I${gccplugins_dir}/include 2>&1 <<EOF
104238 +#include "gcc-common.h"
104239 +#if BUILDING_GCC_VERSION >= 4008 || defined(ENABLE_BUILD_WITH_CXX)
104240 +#warning $2 CXX
104241 +#else
104242 +#warning $1 CC
104243 +#endif
104244 +EOF
104245 +)
104246 +
104247 +if [ $? -ne 0 ]
104248 +then
104249 + exit 1
104250 +fi
104251 +
104252 +if [[ "$plugincc" =~ "$1 CC" ]]
104253 +then
104254 + echo "$1"
104255 + exit 0
104256 +fi
104257 +
104258 +if [[ "$plugincc" =~ "$2 CXX" ]]
104259 +then
104260 +plugincc=$($1 -c -x c++ -std=gnu++98 - -o /dev/null -I${srctree}/../tools/gcc -I${gccplugins_dir}/include 2>&1 <<EOF
104261 +#include "gcc-common.h"
104262 +class test {
104263 +public:
104264 + int test;
104265 +} test = {
104266 + .test = 1
104267 +};
104268 +EOF
104269 +)
104270 +if [ $? -eq 0 ]
104271 +then
104272 + echo "$2"
104273 + exit 0
104274 +fi
104275 +fi
104276 +exit 1
104277 diff --git a/scripts/headers_install.sh b/scripts/headers_install.sh
104278 index 5de5660..d3deb89 100644
104279 --- a/scripts/headers_install.sh
104280 +++ b/scripts/headers_install.sh
104281 @@ -32,6 +32,7 @@ do
104282 FILE="$(basename "$i")"
104283 sed -r \
104284 -e 's/([ \t(])(__user|__force|__iomem)[ \t]/\1/g' \
104285 + -e 's/__intentional_overflow\([- \t,0-9]*\)//g' \
104286 -e 's/__attribute_const__([ \t]|$)/\1/g' \
104287 -e 's@^#include <linux/compiler.h>@@' \
104288 -e 's/(^|[^a-zA-Z0-9])__packed([^a-zA-Z0-9_]|$)/\1__attribute__((packed))\2/g' \
104289 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
104290 index 86a4fe7..99e91f9 100644
104291 --- a/scripts/link-vmlinux.sh
104292 +++ b/scripts/link-vmlinux.sh
104293 @@ -166,7 +166,7 @@ else
104294 fi;
104295
104296 # final build of init/
104297 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
104298 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
104299
104300 kallsymso=""
104301 kallsyms_vmlinux=""
104302 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
104303 index 1924990..3de7363 100644
104304 --- a/scripts/mod/file2alias.c
104305 +++ b/scripts/mod/file2alias.c
104306 @@ -142,7 +142,7 @@ static void device_id_check(const char *modname, const char *device_id,
104307 unsigned long size, unsigned long id_size,
104308 void *symval)
104309 {
104310 - int i;
104311 + unsigned int i;
104312
104313 if (size % id_size || size < id_size) {
104314 fatal("%s: sizeof(struct %s_device_id)=%lu is not a modulo "
104315 @@ -171,7 +171,7 @@ static void device_id_check(const char *modname, const char *device_id,
104316 /* USB is special because the bcdDevice can be matched against a numeric range */
104317 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
104318 static void do_usb_entry(void *symval,
104319 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
104320 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
104321 unsigned char range_lo, unsigned char range_hi,
104322 unsigned char max, struct module *mod)
104323 {
104324 @@ -281,7 +281,7 @@ static void do_usb_entry_multi(void *symval, struct module *mod)
104325 {
104326 unsigned int devlo, devhi;
104327 unsigned char chi, clo, max;
104328 - int ndigits;
104329 + unsigned int ndigits;
104330
104331 DEF_FIELD(symval, usb_device_id, match_flags);
104332 DEF_FIELD(symval, usb_device_id, idVendor);
104333 @@ -534,7 +534,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
104334 for (i = 0; i < count; i++) {
104335 DEF_FIELD_ADDR(symval + i*id_size, pnp_device_id, id);
104336 char acpi_id[sizeof(*id)];
104337 - int j;
104338 + unsigned int j;
104339
104340 buf_printf(&mod->dev_table_buf,
104341 "MODULE_ALIAS(\"pnp:d%s*\");\n", *id);
104342 @@ -563,7 +563,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
104343
104344 for (j = 0; j < PNP_MAX_DEVICES; j++) {
104345 const char *id = (char *)(*devs)[j].id;
104346 - int i2, j2;
104347 + unsigned int i2, j2;
104348 int dup = 0;
104349
104350 if (!id[0])
104351 @@ -589,7 +589,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
104352 /* add an individual alias for every device entry */
104353 if (!dup) {
104354 char acpi_id[PNP_ID_LEN];
104355 - int k;
104356 + unsigned int k;
104357
104358 buf_printf(&mod->dev_table_buf,
104359 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
104360 @@ -941,7 +941,7 @@ static void dmi_ascii_filter(char *d, const char *s)
104361 static int do_dmi_entry(const char *filename, void *symval,
104362 char *alias)
104363 {
104364 - int i, j;
104365 + unsigned int i, j;
104366 DEF_FIELD_ADDR(symval, dmi_system_id, matches);
104367 sprintf(alias, "dmi*");
104368
104369 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
104370 index 0663556..d9494f0 100644
104371 --- a/scripts/mod/modpost.c
104372 +++ b/scripts/mod/modpost.c
104373 @@ -949,6 +949,7 @@ enum mismatch {
104374 ANY_INIT_TO_ANY_EXIT,
104375 ANY_EXIT_TO_ANY_INIT,
104376 EXPORT_TO_INIT_EXIT,
104377 + DATA_TO_TEXT
104378 };
104379
104380 struct sectioncheck {
104381 @@ -1035,6 +1036,12 @@ const struct sectioncheck sectioncheck[] = {
104382 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
104383 .mismatch = EXPORT_TO_INIT_EXIT,
104384 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
104385 +},
104386 +/* Do not reference code from writable data */
104387 +{
104388 + .fromsec = { DATA_SECTIONS, NULL },
104389 + .tosec = { TEXT_SECTIONS, NULL },
104390 + .mismatch = DATA_TO_TEXT
104391 }
104392 };
104393
104394 @@ -1155,10 +1162,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
104395 continue;
104396 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
104397 continue;
104398 - if (sym->st_value == addr)
104399 - return sym;
104400 /* Find a symbol nearby - addr are maybe negative */
104401 d = sym->st_value - addr;
104402 + if (d == 0)
104403 + return sym;
104404 if (d < 0)
104405 d = addr - sym->st_value;
104406 if (d < distance) {
104407 @@ -1436,6 +1443,14 @@ static void report_sec_mismatch(const char *modname,
104408 tosym, prl_to, prl_to, tosym);
104409 free(prl_to);
104410 break;
104411 + case DATA_TO_TEXT:
104412 +#if 0
104413 + fprintf(stderr,
104414 + "The %s %s:%s references\n"
104415 + "the %s %s:%s%s\n",
104416 + from, fromsec, fromsym, to, tosec, tosym, to_p);
104417 +#endif
104418 + break;
104419 }
104420 fprintf(stderr, "\n");
104421 }
104422 @@ -1687,7 +1702,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
104423 static void check_sec_ref(struct module *mod, const char *modname,
104424 struct elf_info *elf)
104425 {
104426 - int i;
104427 + unsigned int i;
104428 Elf_Shdr *sechdrs = elf->sechdrs;
104429
104430 /* Walk through all sections */
104431 @@ -1819,7 +1834,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
104432 va_end(ap);
104433 }
104434
104435 -void buf_write(struct buffer *buf, const char *s, int len)
104436 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
104437 {
104438 if (buf->size - buf->pos < len) {
104439 buf->size += len + SZ;
104440 @@ -2038,7 +2053,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
104441 if (fstat(fileno(file), &st) < 0)
104442 goto close_write;
104443
104444 - if (st.st_size != b->pos)
104445 + if (st.st_size != (off_t)b->pos)
104446 goto close_write;
104447
104448 tmp = NOFAIL(malloc(b->pos));
104449 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
104450 index 168b43d..77914bf 100644
104451 --- a/scripts/mod/modpost.h
104452 +++ b/scripts/mod/modpost.h
104453 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
104454
104455 struct buffer {
104456 char *p;
104457 - int pos;
104458 - int size;
104459 + unsigned int pos;
104460 + unsigned int size;
104461 };
104462
104463 void __attribute__((format(printf, 2, 3)))
104464 buf_printf(struct buffer *buf, const char *fmt, ...);
104465
104466 void
104467 -buf_write(struct buffer *buf, const char *s, int len);
104468 +buf_write(struct buffer *buf, const char *s, unsigned int len);
104469
104470 struct module {
104471 struct module *next;
104472 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
104473 index deb2994..af4f63e 100644
104474 --- a/scripts/mod/sumversion.c
104475 +++ b/scripts/mod/sumversion.c
104476 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
104477 goto out;
104478 }
104479
104480 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
104481 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
104482 warn("writing sum in %s failed: %s\n",
104483 filename, strerror(errno));
104484 goto out;
104485 diff --git a/scripts/module-common.lds b/scripts/module-common.lds
104486 index 0865b3e..7235dd4 100644
104487 --- a/scripts/module-common.lds
104488 +++ b/scripts/module-common.lds
104489 @@ -6,6 +6,10 @@
104490 SECTIONS {
104491 /DISCARD/ : { *(.discard) }
104492
104493 + .rodata : {
104494 + *(.rodata) *(.rodata.*)
104495 + *(.data..read_only)
104496 + }
104497 __ksymtab : { *(SORT(___ksymtab+*)) }
104498 __ksymtab_gpl : { *(SORT(___ksymtab_gpl+*)) }
104499 __ksymtab_unused : { *(SORT(___ksymtab_unused+*)) }
104500 diff --git a/scripts/package/builddeb b/scripts/package/builddeb
104501 index 152d4d2..791684c 100644
104502 --- a/scripts/package/builddeb
104503 +++ b/scripts/package/builddeb
104504 @@ -291,6 +291,7 @@ fi
104505 (cd $srctree; find . -name Makefile\* -o -name Kconfig\* -o -name \*.pl > "$objtree/debian/hdrsrcfiles")
104506 (cd $srctree; find arch/$SRCARCH/include include scripts -type f >> "$objtree/debian/hdrsrcfiles")
104507 (cd $objtree; find arch/$SRCARCH/include Module.symvers include scripts -type f >> "$objtree/debian/hdrobjfiles")
104508 +(cd $objtree; find tools/gcc -name \*.so >> "$objtree/debian/hdrobjfiles")
104509 destdir=$kernel_headers_dir/usr/src/linux-headers-$version
104510 mkdir -p "$destdir"
104511 (cd $srctree; tar -c -f - -T "$objtree/debian/hdrsrcfiles") | (cd $destdir; tar -xf -)
104512 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
104513 index 68bb4ef..2f419e1 100644
104514 --- a/scripts/pnmtologo.c
104515 +++ b/scripts/pnmtologo.c
104516 @@ -244,14 +244,14 @@ static void write_header(void)
104517 fprintf(out, " * Linux logo %s\n", logoname);
104518 fputs(" */\n\n", out);
104519 fputs("#include <linux/linux_logo.h>\n\n", out);
104520 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
104521 + fprintf(out, "static unsigned char %s_data[] = {\n",
104522 logoname);
104523 }
104524
104525 static void write_footer(void)
104526 {
104527 fputs("\n};\n\n", out);
104528 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
104529 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
104530 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
104531 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
104532 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
104533 @@ -381,7 +381,7 @@ static void write_logo_clut224(void)
104534 fputs("\n};\n\n", out);
104535
104536 /* write logo clut */
104537 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
104538 + fprintf(out, "static unsigned char %s_clut[] = {\n",
104539 logoname);
104540 write_hex_cnt = 0;
104541 for (i = 0; i < logo_clutsize; i++) {
104542 diff --git a/scripts/sortextable.h b/scripts/sortextable.h
104543 index 8fac3fd..32ff38d 100644
104544 --- a/scripts/sortextable.h
104545 +++ b/scripts/sortextable.h
104546 @@ -108,9 +108,9 @@ do_func(Elf_Ehdr *ehdr, char const *const fname, table_sort_t custom_sort)
104547 const char *secstrtab;
104548 const char *strtab;
104549 char *extab_image;
104550 - int extab_index = 0;
104551 - int i;
104552 - int idx;
104553 + unsigned int extab_index = 0;
104554 + unsigned int i;
104555 + unsigned int idx;
104556 unsigned int num_sections;
104557 unsigned int secindex_strings;
104558
104559 diff --git a/security/Kconfig b/security/Kconfig
104560 index beb86b5..40b1edb 100644
104561 --- a/security/Kconfig
104562 +++ b/security/Kconfig
104563 @@ -4,6 +4,957 @@
104564
104565 menu "Security options"
104566
104567 +menu "Grsecurity"
104568 +
104569 + config ARCH_TRACK_EXEC_LIMIT
104570 + bool
104571 +
104572 + config PAX_KERNEXEC_PLUGIN
104573 + bool
104574 +
104575 + config PAX_PER_CPU_PGD
104576 + bool
104577 +
104578 + config TASK_SIZE_MAX_SHIFT
104579 + int
104580 + depends on X86_64
104581 + default 47 if !PAX_PER_CPU_PGD
104582 + default 42 if PAX_PER_CPU_PGD
104583 +
104584 + config PAX_ENABLE_PAE
104585 + bool
104586 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
104587 +
104588 + config PAX_USERCOPY_SLABS
104589 + bool
104590 +
104591 +config GRKERNSEC
104592 + bool "Grsecurity"
104593 + select CRYPTO
104594 + select CRYPTO_SHA256
104595 + select PROC_FS
104596 + select STOP_MACHINE
104597 + select TTY
104598 + select DEBUG_KERNEL
104599 + select DEBUG_LIST
104600 + help
104601 + If you say Y here, you will be able to configure many features
104602 + that will enhance the security of your system. It is highly
104603 + recommended that you say Y here and read through the help
104604 + for each option so that you fully understand the features and
104605 + can evaluate their usefulness for your machine.
104606 +
104607 +choice
104608 + prompt "Configuration Method"
104609 + depends on GRKERNSEC
104610 + default GRKERNSEC_CONFIG_CUSTOM
104611 + help
104612 +
104613 +config GRKERNSEC_CONFIG_AUTO
104614 + bool "Automatic"
104615 + help
104616 + If you choose this configuration method, you'll be able to answer a small
104617 + number of simple questions about how you plan to use this kernel.
104618 + The settings of grsecurity and PaX will be automatically configured for
104619 + the highest commonly-used settings within the provided constraints.
104620 +
104621 + If you require additional configuration, custom changes can still be made
104622 + from the "custom configuration" menu.
104623 +
104624 +config GRKERNSEC_CONFIG_CUSTOM
104625 + bool "Custom"
104626 + help
104627 + If you choose this configuration method, you'll be able to configure all
104628 + grsecurity and PaX settings manually. Via this method, no options are
104629 + automatically enabled.
104630 +
104631 +endchoice
104632 +
104633 +choice
104634 + prompt "Usage Type"
104635 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
104636 + default GRKERNSEC_CONFIG_SERVER
104637 + help
104638 +
104639 +config GRKERNSEC_CONFIG_SERVER
104640 + bool "Server"
104641 + help
104642 + Choose this option if you plan to use this kernel on a server.
104643 +
104644 +config GRKERNSEC_CONFIG_DESKTOP
104645 + bool "Desktop"
104646 + help
104647 + Choose this option if you plan to use this kernel on a desktop.
104648 +
104649 +endchoice
104650 +
104651 +choice
104652 + prompt "Virtualization Type"
104653 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
104654 + default GRKERNSEC_CONFIG_VIRT_NONE
104655 + help
104656 +
104657 +config GRKERNSEC_CONFIG_VIRT_NONE
104658 + bool "None"
104659 + help
104660 + Choose this option if this kernel will be run on bare metal.
104661 +
104662 +config GRKERNSEC_CONFIG_VIRT_GUEST
104663 + bool "Guest"
104664 + help
104665 + Choose this option if this kernel will be run as a VM guest.
104666 +
104667 +config GRKERNSEC_CONFIG_VIRT_HOST
104668 + bool "Host"
104669 + help
104670 + Choose this option if this kernel will be run as a VM host.
104671 +
104672 +endchoice
104673 +
104674 +choice
104675 + prompt "Virtualization Hardware"
104676 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
104677 + help
104678 +
104679 +config GRKERNSEC_CONFIG_VIRT_EPT
104680 + bool "EPT/RVI Processor Support"
104681 + depends on X86
104682 + help
104683 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
104684 + hardware virtualization. This allows for additional kernel hardening protections
104685 + to operate without additional performance impact.
104686 +
104687 + To see if your Intel processor supports EPT, see:
104688 + http://ark.intel.com/Products/VirtualizationTechnology
104689 + (Most Core i3/5/7 support EPT)
104690 +
104691 + To see if your AMD processor supports RVI, see:
104692 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
104693 +
104694 +config GRKERNSEC_CONFIG_VIRT_SOFT
104695 + bool "First-gen/No Hardware Virtualization"
104696 + help
104697 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
104698 + support hardware virtualization or doesn't support the EPT/RVI extensions.
104699 +
104700 +endchoice
104701 +
104702 +choice
104703 + prompt "Virtualization Software"
104704 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
104705 + help
104706 +
104707 +config GRKERNSEC_CONFIG_VIRT_XEN
104708 + bool "Xen"
104709 + help
104710 + Choose this option if this kernel is running as a Xen guest or host.
104711 +
104712 +config GRKERNSEC_CONFIG_VIRT_VMWARE
104713 + bool "VMWare"
104714 + help
104715 + Choose this option if this kernel is running as a VMWare guest or host.
104716 +
104717 +config GRKERNSEC_CONFIG_VIRT_KVM
104718 + bool "KVM"
104719 + help
104720 + Choose this option if this kernel is running as a KVM guest or host.
104721 +
104722 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
104723 + bool "VirtualBox"
104724 + help
104725 + Choose this option if this kernel is running as a VirtualBox guest or host.
104726 +
104727 +endchoice
104728 +
104729 +choice
104730 + prompt "Required Priorities"
104731 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
104732 + default GRKERNSEC_CONFIG_PRIORITY_PERF
104733 + help
104734 +
104735 +config GRKERNSEC_CONFIG_PRIORITY_PERF
104736 + bool "Performance"
104737 + help
104738 + Choose this option if performance is of highest priority for this deployment
104739 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
104740 + clearing of structures intended for userland, and freed memory sanitizing will
104741 + be disabled.
104742 +
104743 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
104744 + bool "Security"
104745 + help
104746 + Choose this option if security is of highest priority for this deployment of
104747 + grsecurity. UDEREF, kernel stack clearing, clearing of structures intended
104748 + for userland, and freed memory sanitizing will be enabled for this kernel.
104749 + In a worst-case scenario, these features can introduce a 20% performance hit
104750 + (UDEREF on x64 contributing half of this hit).
104751 +
104752 +endchoice
104753 +
104754 +menu "Default Special Groups"
104755 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
104756 +
104757 +config GRKERNSEC_PROC_GID
104758 + int "GID exempted from /proc restrictions"
104759 + default 1001
104760 + help
104761 + Setting this GID determines which group will be exempted from
104762 + grsecurity's /proc restrictions, allowing users of the specified
104763 + group to view network statistics and the existence of other users'
104764 + processes on the system. This GID may also be chosen at boot time
104765 + via "grsec_proc_gid=" on the kernel commandline.
104766 +
104767 +config GRKERNSEC_TPE_UNTRUSTED_GID
104768 + int "GID for TPE-untrusted users"
104769 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
104770 + default 1005
104771 + help
104772 + Setting this GID determines which group untrusted users should
104773 + be added to. These users will be placed under grsecurity's Trusted Path
104774 + Execution mechanism, preventing them from executing their own binaries.
104775 + The users will only be able to execute binaries in directories owned and
104776 + writable only by the root user. If the sysctl option is enabled, a sysctl
104777 + option with name "tpe_gid" is created.
104778 +
104779 +config GRKERNSEC_TPE_TRUSTED_GID
104780 + int "GID for TPE-trusted users"
104781 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
104782 + default 1005
104783 + help
104784 + Setting this GID determines what group TPE restrictions will be
104785 + *disabled* for. If the sysctl option is enabled, a sysctl option
104786 + with name "tpe_gid" is created.
104787 +
104788 +config GRKERNSEC_SYMLINKOWN_GID
104789 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
104790 + depends on GRKERNSEC_CONFIG_SERVER
104791 + default 1006
104792 + help
104793 + Setting this GID determines what group kernel-enforced
104794 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
104795 + is enabled, a sysctl option with name "symlinkown_gid" is created.
104796 +
104797 +
104798 +endmenu
104799 +
104800 +menu "Customize Configuration"
104801 +depends on GRKERNSEC
104802 +
104803 +menu "PaX"
104804 +
104805 +config PAX
104806 + bool "Enable various PaX features"
104807 + default y if GRKERNSEC_CONFIG_AUTO
104808 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
104809 + help
104810 + This allows you to enable various PaX features. PaX adds
104811 + intrusion prevention mechanisms to the kernel that reduce
104812 + the risks posed by exploitable memory corruption bugs.
104813 +
104814 +menu "PaX Control"
104815 + depends on PAX
104816 +
104817 +config PAX_SOFTMODE
104818 + bool 'Support soft mode'
104819 + help
104820 + Enabling this option will allow you to run PaX in soft mode, that
104821 + is, PaX features will not be enforced by default, only on executables
104822 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
104823 + support as they are the only way to mark executables for soft mode use.
104824 +
104825 + Soft mode can be activated by using the "pax_softmode=1" kernel command
104826 + line option on boot. Furthermore you can control various PaX features
104827 + at runtime via the entries in /proc/sys/kernel/pax.
104828 +
104829 +config PAX_EI_PAX
104830 + bool 'Use legacy ELF header marking'
104831 + default y if GRKERNSEC_CONFIG_AUTO
104832 + help
104833 + Enabling this option will allow you to control PaX features on
104834 + a per executable basis via the 'chpax' utility available at
104835 + http://pax.grsecurity.net/. The control flags will be read from
104836 + an otherwise reserved part of the ELF header. This marking has
104837 + numerous drawbacks (no support for soft-mode, toolchain does not
104838 + know about the non-standard use of the ELF header) therefore it
104839 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
104840 + support.
104841 +
104842 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
104843 + support as well, they will override the legacy EI_PAX marks.
104844 +
104845 + If you enable none of the marking options then all applications
104846 + will run with PaX enabled on them by default.
104847 +
104848 +config PAX_PT_PAX_FLAGS
104849 + bool 'Use ELF program header marking'
104850 + default y if GRKERNSEC_CONFIG_AUTO
104851 + help
104852 + Enabling this option will allow you to control PaX features on
104853 + a per executable basis via the 'paxctl' utility available at
104854 + http://pax.grsecurity.net/. The control flags will be read from
104855 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
104856 + has the benefits of supporting both soft mode and being fully
104857 + integrated into the toolchain (the binutils patch is available
104858 + from http://pax.grsecurity.net).
104859 +
104860 + Note that if you enable the legacy EI_PAX marking support as well,
104861 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
104862 +
104863 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
104864 + must make sure that the marks are the same if a binary has both marks.
104865 +
104866 + If you enable none of the marking options then all applications
104867 + will run with PaX enabled on them by default.
104868 +
104869 +config PAX_XATTR_PAX_FLAGS
104870 + bool 'Use filesystem extended attributes marking'
104871 + default y if GRKERNSEC_CONFIG_AUTO
104872 + select CIFS_XATTR if CIFS
104873 + select F2FS_FS_XATTR if F2FS_FS
104874 + select EXT2_FS_XATTR if EXT2_FS
104875 + select EXT3_FS_XATTR if EXT3_FS
104876 + select JFFS2_FS_XATTR if JFFS2_FS
104877 + select REISERFS_FS_XATTR if REISERFS_FS
104878 + select SQUASHFS_XATTR if SQUASHFS
104879 + select TMPFS_XATTR if TMPFS
104880 + help
104881 + Enabling this option will allow you to control PaX features on
104882 + a per executable basis via the 'setfattr' utility. The control
104883 + flags will be read from the user.pax.flags extended attribute of
104884 + the file. This marking has the benefit of supporting binary-only
104885 + applications that self-check themselves (e.g., skype) and would
104886 + not tolerate chpax/paxctl changes. The main drawback is that
104887 + extended attributes are not supported by some filesystems (e.g.,
104888 + isofs, udf, vfat) so copying files through such filesystems will
104889 + lose the extended attributes and these PaX markings.
104890 +
104891 + Note that if you enable the legacy EI_PAX marking support as well,
104892 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
104893 +
104894 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
104895 + must make sure that the marks are the same if a binary has both marks.
104896 +
104897 + If you enable none of the marking options then all applications
104898 + will run with PaX enabled on them by default.
104899 +
104900 +choice
104901 + prompt 'MAC system integration'
104902 + default PAX_HAVE_ACL_FLAGS
104903 + help
104904 + Mandatory Access Control systems have the option of controlling
104905 + PaX flags on a per executable basis, choose the method supported
104906 + by your particular system.
104907 +
104908 + - "none": if your MAC system does not interact with PaX,
104909 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
104910 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
104911 +
104912 + NOTE: this option is for developers/integrators only.
104913 +
104914 + config PAX_NO_ACL_FLAGS
104915 + bool 'none'
104916 +
104917 + config PAX_HAVE_ACL_FLAGS
104918 + bool 'direct'
104919 +
104920 + config PAX_HOOK_ACL_FLAGS
104921 + bool 'hook'
104922 +endchoice
104923 +
104924 +endmenu
104925 +
104926 +menu "Non-executable pages"
104927 + depends on PAX
104928 +
104929 +config PAX_NOEXEC
104930 + bool "Enforce non-executable pages"
104931 + default y if GRKERNSEC_CONFIG_AUTO
104932 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
104933 + help
104934 + By design some architectures do not allow for protecting memory
104935 + pages against execution or even if they do, Linux does not make
104936 + use of this feature. In practice this means that if a page is
104937 + readable (such as the stack or heap) it is also executable.
104938 +
104939 + There is a well known exploit technique that makes use of this
104940 + fact and a common programming mistake where an attacker can
104941 + introduce code of his choice somewhere in the attacked program's
104942 + memory (typically the stack or the heap) and then execute it.
104943 +
104944 + If the attacked program was running with different (typically
104945 + higher) privileges than that of the attacker, then he can elevate
104946 + his own privilege level (e.g. get a root shell, write to files for
104947 + which he does not have write access to, etc).
104948 +
104949 + Enabling this option will let you choose from various features
104950 + that prevent the injection and execution of 'foreign' code in
104951 + a program.
104952 +
104953 + This will also break programs that rely on the old behaviour and
104954 + expect that dynamically allocated memory via the malloc() family
104955 + of functions is executable (which it is not). Notable examples
104956 + are the XFree86 4.x server, the java runtime and wine.
104957 +
104958 +config PAX_PAGEEXEC
104959 + bool "Paging based non-executable pages"
104960 + default y if GRKERNSEC_CONFIG_AUTO
104961 + 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)
104962 + select ARCH_TRACK_EXEC_LIMIT if X86_32
104963 + help
104964 + This implementation is based on the paging feature of the CPU.
104965 + On i386 without hardware non-executable bit support there is a
104966 + variable but usually low performance impact, however on Intel's
104967 + P4 core based CPUs it is very high so you should not enable this
104968 + for kernels meant to be used on such CPUs.
104969 +
104970 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
104971 + with hardware non-executable bit support there is no performance
104972 + impact, on ppc the impact is negligible.
104973 +
104974 + Note that several architectures require various emulations due to
104975 + badly designed userland ABIs, this will cause a performance impact
104976 + but will disappear as soon as userland is fixed. For example, ppc
104977 + userland MUST have been built with secure-plt by a recent toolchain.
104978 +
104979 +config PAX_SEGMEXEC
104980 + bool "Segmentation based non-executable pages"
104981 + default y if GRKERNSEC_CONFIG_AUTO
104982 + depends on PAX_NOEXEC && X86_32
104983 + help
104984 + This implementation is based on the segmentation feature of the
104985 + CPU and has a very small performance impact, however applications
104986 + will be limited to a 1.5 GB address space instead of the normal
104987 + 3 GB.
104988 +
104989 +config PAX_EMUTRAMP
104990 + bool "Emulate trampolines"
104991 + default y if PARISC || GRKERNSEC_CONFIG_AUTO
104992 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
104993 + help
104994 + There are some programs and libraries that for one reason or
104995 + another attempt to execute special small code snippets from
104996 + non-executable memory pages. Most notable examples are the
104997 + signal handler return code generated by the kernel itself and
104998 + the GCC trampolines.
104999 +
105000 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
105001 + such programs will no longer work under your kernel.
105002 +
105003 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
105004 + utilities to enable trampoline emulation for the affected programs
105005 + yet still have the protection provided by the non-executable pages.
105006 +
105007 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
105008 + your system will not even boot.
105009 +
105010 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
105011 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
105012 + for the affected files.
105013 +
105014 + NOTE: enabling this feature *may* open up a loophole in the
105015 + protection provided by non-executable pages that an attacker
105016 + could abuse. Therefore the best solution is to not have any
105017 + files on your system that would require this option. This can
105018 + be achieved by not using libc5 (which relies on the kernel
105019 + signal handler return code) and not using or rewriting programs
105020 + that make use of the nested function implementation of GCC.
105021 + Skilled users can just fix GCC itself so that it implements
105022 + nested function calls in a way that does not interfere with PaX.
105023 +
105024 +config PAX_EMUSIGRT
105025 + bool "Automatically emulate sigreturn trampolines"
105026 + depends on PAX_EMUTRAMP && PARISC
105027 + default y
105028 + help
105029 + Enabling this option will have the kernel automatically detect
105030 + and emulate signal return trampolines executing on the stack
105031 + that would otherwise lead to task termination.
105032 +
105033 + This solution is intended as a temporary one for users with
105034 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
105035 + Modula-3 runtime, etc) or executables linked to such, basically
105036 + everything that does not specify its own SA_RESTORER function in
105037 + normal executable memory like glibc 2.1+ does.
105038 +
105039 + On parisc you MUST enable this option, otherwise your system will
105040 + not even boot.
105041 +
105042 + NOTE: this feature cannot be disabled on a per executable basis
105043 + and since it *does* open up a loophole in the protection provided
105044 + by non-executable pages, the best solution is to not have any
105045 + files on your system that would require this option.
105046 +
105047 +config PAX_MPROTECT
105048 + bool "Restrict mprotect()"
105049 + default y if GRKERNSEC_CONFIG_AUTO
105050 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
105051 + help
105052 + Enabling this option will prevent programs from
105053 + - changing the executable status of memory pages that were
105054 + not originally created as executable,
105055 + - making read-only executable pages writable again,
105056 + - creating executable pages from anonymous memory,
105057 + - making read-only-after-relocations (RELRO) data pages writable again.
105058 +
105059 + You should say Y here to complete the protection provided by
105060 + the enforcement of non-executable pages.
105061 +
105062 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
105063 + this feature on a per file basis.
105064 +
105065 +config PAX_MPROTECT_COMPAT
105066 + bool "Use legacy/compat protection demoting (read help)"
105067 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
105068 + depends on PAX_MPROTECT
105069 + help
105070 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
105071 + by sending the proper error code to the application. For some broken
105072 + userland, this can cause problems with Python or other applications. The
105073 + current implementation however allows for applications like clamav to
105074 + detect if JIT compilation/execution is allowed and to fall back gracefully
105075 + to an interpreter-based mode if it does not. While we encourage everyone
105076 + to use the current implementation as-is and push upstream to fix broken
105077 + userland (note that the RWX logging option can assist with this), in some
105078 + environments this may not be possible. Having to disable MPROTECT
105079 + completely on certain binaries reduces the security benefit of PaX,
105080 + so this option is provided for those environments to revert to the old
105081 + behavior.
105082 +
105083 +config PAX_ELFRELOCS
105084 + bool "Allow ELF text relocations (read help)"
105085 + depends on PAX_MPROTECT
105086 + default n
105087 + help
105088 + Non-executable pages and mprotect() restrictions are effective
105089 + in preventing the introduction of new executable code into an
105090 + attacked task's address space. There remain only two venues
105091 + for this kind of attack: if the attacker can execute already
105092 + existing code in the attacked task then he can either have it
105093 + create and mmap() a file containing his code or have it mmap()
105094 + an already existing ELF library that does not have position
105095 + independent code in it and use mprotect() on it to make it
105096 + writable and copy his code there. While protecting against
105097 + the former approach is beyond PaX, the latter can be prevented
105098 + by having only PIC ELF libraries on one's system (which do not
105099 + need to relocate their code). If you are sure this is your case,
105100 + as is the case with all modern Linux distributions, then leave
105101 + this option disabled. You should say 'n' here.
105102 +
105103 +config PAX_ETEXECRELOCS
105104 + bool "Allow ELF ET_EXEC text relocations"
105105 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
105106 + select PAX_ELFRELOCS
105107 + default y
105108 + help
105109 + On some architectures there are incorrectly created applications
105110 + that require text relocations and would not work without enabling
105111 + this option. If you are an alpha, ia64 or parisc user, you should
105112 + enable this option and disable it once you have made sure that
105113 + none of your applications need it.
105114 +
105115 +config PAX_EMUPLT
105116 + bool "Automatically emulate ELF PLT"
105117 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
105118 + default y
105119 + help
105120 + Enabling this option will have the kernel automatically detect
105121 + and emulate the Procedure Linkage Table entries in ELF files.
105122 + On some architectures such entries are in writable memory, and
105123 + become non-executable leading to task termination. Therefore
105124 + it is mandatory that you enable this option on alpha, parisc,
105125 + sparc and sparc64, otherwise your system would not even boot.
105126 +
105127 + NOTE: this feature *does* open up a loophole in the protection
105128 + provided by the non-executable pages, therefore the proper
105129 + solution is to modify the toolchain to produce a PLT that does
105130 + not need to be writable.
105131 +
105132 +config PAX_DLRESOLVE
105133 + bool 'Emulate old glibc resolver stub'
105134 + depends on PAX_EMUPLT && SPARC
105135 + default n
105136 + help
105137 + This option is needed if userland has an old glibc (before 2.4)
105138 + that puts a 'save' instruction into the runtime generated resolver
105139 + stub that needs special emulation.
105140 +
105141 +config PAX_KERNEXEC
105142 + bool "Enforce non-executable kernel pages"
105143 + 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))
105144 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !(ARM_LPAE && MODULES))) && !XEN
105145 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
105146 + select PAX_KERNEXEC_PLUGIN if X86_64
105147 + help
105148 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
105149 + that is, enabling this option will make it harder to inject
105150 + and execute 'foreign' code in kernel memory itself.
105151 +
105152 +choice
105153 + prompt "Return Address Instrumentation Method"
105154 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
105155 + depends on PAX_KERNEXEC_PLUGIN
105156 + help
105157 + Select the method used to instrument function pointer dereferences.
105158 + Note that binary modules cannot be instrumented by this approach.
105159 +
105160 + Note that the implementation requires a gcc with plugin support,
105161 + i.e., gcc 4.5 or newer. You may need to install the supporting
105162 + headers explicitly in addition to the normal gcc package.
105163 +
105164 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
105165 + bool "bts"
105166 + help
105167 + This method is compatible with binary only modules but has
105168 + a higher runtime overhead.
105169 +
105170 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
105171 + bool "or"
105172 + depends on !PARAVIRT
105173 + help
105174 + This method is incompatible with binary only modules but has
105175 + a lower runtime overhead.
105176 +endchoice
105177 +
105178 +config PAX_KERNEXEC_PLUGIN_METHOD
105179 + string
105180 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
105181 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
105182 + default ""
105183 +
105184 +config PAX_KERNEXEC_MODULE_TEXT
105185 + int "Minimum amount of memory reserved for module code"
105186 + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
105187 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
105188 + depends on PAX_KERNEXEC && X86_32
105189 + help
105190 + Due to implementation details the kernel must reserve a fixed
105191 + amount of memory for runtime allocated code (such as modules)
105192 + at compile time that cannot be changed at runtime. Here you
105193 + can specify the minimum amount in MB that will be reserved.
105194 + Due to the same implementation details this size will always
105195 + be rounded up to the next 2/4 MB boundary (depends on PAE) so
105196 + the actually available memory for runtime allocated code will
105197 + usually be more than this minimum.
105198 +
105199 + The default 4 MB should be enough for most users but if you have
105200 + an excessive number of modules (e.g., most distribution configs
105201 + compile many drivers as modules) or use huge modules such as
105202 + nvidia's kernel driver, you will need to adjust this amount.
105203 + A good rule of thumb is to look at your currently loaded kernel
105204 + modules and add up their sizes.
105205 +
105206 +endmenu
105207 +
105208 +menu "Address Space Layout Randomization"
105209 + depends on PAX
105210 +
105211 +config PAX_ASLR
105212 + bool "Address Space Layout Randomization"
105213 + default y if GRKERNSEC_CONFIG_AUTO
105214 + help
105215 + Many if not most exploit techniques rely on the knowledge of
105216 + certain addresses in the attacked program. The following options
105217 + will allow the kernel to apply a certain amount of randomization
105218 + to specific parts of the program thereby forcing an attacker to
105219 + guess them in most cases. Any failed guess will most likely crash
105220 + the attacked program which allows the kernel to detect such attempts
105221 + and react on them. PaX itself provides no reaction mechanisms,
105222 + instead it is strongly encouraged that you make use of grsecurity's
105223 + (http://www.grsecurity.net/) built-in crash detection features or
105224 + develop one yourself.
105225 +
105226 + By saying Y here you can choose to randomize the following areas:
105227 + - top of the task's kernel stack
105228 + - top of the task's userland stack
105229 + - base address for mmap() requests that do not specify one
105230 + (this includes all libraries)
105231 + - base address of the main executable
105232 +
105233 + It is strongly recommended to say Y here as address space layout
105234 + randomization has negligible impact on performance yet it provides
105235 + a very effective protection.
105236 +
105237 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
105238 + this feature on a per file basis.
105239 +
105240 +config PAX_RANDKSTACK
105241 + bool "Randomize kernel stack base"
105242 + default y if GRKERNSEC_CONFIG_AUTO && !(GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_VIRTUALBOX)
105243 + depends on X86_TSC && X86
105244 + help
105245 + By saying Y here the kernel will randomize every task's kernel
105246 + stack on every system call. This will not only force an attacker
105247 + to guess it but also prevent him from making use of possible
105248 + leaked information about it.
105249 +
105250 + Since the kernel stack is a rather scarce resource, randomization
105251 + may cause unexpected stack overflows, therefore you should very
105252 + carefully test your system. Note that once enabled in the kernel
105253 + configuration, this feature cannot be disabled on a per file basis.
105254 +
105255 +config PAX_RANDUSTACK
105256 + bool
105257 +
105258 +config PAX_RANDMMAP
105259 + bool "Randomize user stack and mmap() bases"
105260 + default y if GRKERNSEC_CONFIG_AUTO
105261 + depends on PAX_ASLR
105262 + select PAX_RANDUSTACK
105263 + help
105264 + By saying Y here the kernel will randomize every task's userland
105265 + stack and use a randomized base address for mmap() requests that
105266 + do not specify one themselves.
105267 +
105268 + The stack randomization is done in two steps where the second
105269 + one may apply a big amount of shift to the top of the stack and
105270 + cause problems for programs that want to use lots of memory (more
105271 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
105272 +
105273 + As a result of mmap randomization all dynamically loaded libraries
105274 + will appear at random addresses and therefore be harder to exploit
105275 + by a technique where an attacker attempts to execute library code
105276 + for his purposes (e.g. spawn a shell from an exploited program that
105277 + is running at an elevated privilege level).
105278 +
105279 + Furthermore, if a program is relinked as a dynamic ELF file, its
105280 + base address will be randomized as well, completing the full
105281 + randomization of the address space layout. Attacking such programs
105282 + becomes a guess game. You can find an example of doing this at
105283 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
105284 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
105285 +
105286 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
105287 + feature on a per file basis.
105288 +
105289 +endmenu
105290 +
105291 +menu "Miscellaneous hardening features"
105292 +
105293 +config PAX_MEMORY_SANITIZE
105294 + bool "Sanitize all freed memory"
105295 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
105296 + help
105297 + By saying Y here the kernel will erase memory pages and slab objects
105298 + as soon as they are freed. This in turn reduces the lifetime of data
105299 + stored in them, making it less likely that sensitive information such
105300 + as passwords, cryptographic secrets, etc stay in memory for too long.
105301 +
105302 + This is especially useful for programs whose runtime is short, long
105303 + lived processes and the kernel itself benefit from this as long as
105304 + they ensure timely freeing of memory that may hold sensitive
105305 + information.
105306 +
105307 + A nice side effect of the sanitization of slab objects is the
105308 + reduction of possible info leaks caused by padding bytes within the
105309 + leaky structures. Use-after-free bugs for structures containing
105310 + pointers can also be detected as dereferencing the sanitized pointer
105311 + will generate an access violation.
105312 +
105313 + The tradeoff is performance impact, on a single CPU system kernel
105314 + compilation sees a 3% slowdown, other systems and workloads may vary
105315 + and you are advised to test this feature on your expected workload
105316 + before deploying it.
105317 +
105318 + To reduce the performance penalty by sanitizing pages only, albeit
105319 + limiting the effectiveness of this feature at the same time, slab
105320 + sanitization can be disabled with the kernel commandline parameter
105321 + "pax_sanitize_slab=0".
105322 +
105323 + Note that this feature does not protect data stored in live pages,
105324 + e.g., process memory swapped to disk may stay there for a long time.
105325 +
105326 +config PAX_MEMORY_STACKLEAK
105327 + bool "Sanitize kernel stack"
105328 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
105329 + depends on X86
105330 + help
105331 + By saying Y here the kernel will erase the kernel stack before it
105332 + returns from a system call. This in turn reduces the information
105333 + that a kernel stack leak bug can reveal.
105334 +
105335 + Note that such a bug can still leak information that was put on
105336 + the stack by the current system call (the one eventually triggering
105337 + the bug) but traces of earlier system calls on the kernel stack
105338 + cannot leak anymore.
105339 +
105340 + The tradeoff is performance impact: on a single CPU system kernel
105341 + compilation sees a 1% slowdown, other systems and workloads may vary
105342 + and you are advised to test this feature on your expected workload
105343 + before deploying it.
105344 +
105345 + Note that the full feature requires a gcc with plugin support,
105346 + i.e., gcc 4.5 or newer. You may need to install the supporting
105347 + headers explicitly in addition to the normal gcc package. Using
105348 + older gcc versions means that functions with large enough stack
105349 + frames may leave uninitialized memory behind that may be exposed
105350 + to a later syscall leaking the stack.
105351 +
105352 +config PAX_MEMORY_STRUCTLEAK
105353 + bool "Forcibly initialize local variables copied to userland"
105354 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
105355 + help
105356 + By saying Y here the kernel will zero initialize some local
105357 + variables that are going to be copied to userland. This in
105358 + turn prevents unintended information leakage from the kernel
105359 + stack should later code forget to explicitly set all parts of
105360 + the copied variable.
105361 +
105362 + The tradeoff is less performance impact than PAX_MEMORY_STACKLEAK
105363 + at a much smaller coverage.
105364 +
105365 + Note that the implementation requires a gcc with plugin support,
105366 + i.e., gcc 4.5 or newer. You may need to install the supporting
105367 + headers explicitly in addition to the normal gcc package.
105368 +
105369 +config PAX_MEMORY_UDEREF
105370 + bool "Prevent invalid userland pointer dereference"
105371 + default y if GRKERNSEC_CONFIG_AUTO && !(X86_64 && GRKERNSEC_CONFIG_PRIORITY_PERF) && (!X86 || GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
105372 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !ARM_LPAE)) && !UML_X86 && !XEN
105373 + select PAX_PER_CPU_PGD if X86_64
105374 + help
105375 + By saying Y here the kernel will be prevented from dereferencing
105376 + userland pointers in contexts where the kernel expects only kernel
105377 + pointers. This is both a useful runtime debugging feature and a
105378 + security measure that prevents exploiting a class of kernel bugs.
105379 +
105380 + The tradeoff is that some virtualization solutions may experience
105381 + a huge slowdown and therefore you should not enable this feature
105382 + for kernels meant to run in such environments. Whether a given VM
105383 + solution is affected or not is best determined by simply trying it
105384 + out, the performance impact will be obvious right on boot as this
105385 + mechanism engages from very early on. A good rule of thumb is that
105386 + VMs running on CPUs without hardware virtualization support (i.e.,
105387 + the majority of IA-32 CPUs) will likely experience the slowdown.
105388 +
105389 + On X86_64 the kernel will make use of PCID support when available
105390 + (Intel's Westmere, Sandy Bridge, etc) for better security (default)
105391 + or performance impact. Pass pax_weakuderef on the kernel command
105392 + line to choose the latter.
105393 +
105394 +config PAX_REFCOUNT
105395 + bool "Prevent various kernel object reference counter overflows"
105396 + default y if GRKERNSEC_CONFIG_AUTO
105397 + depends on GRKERNSEC && ((ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || MIPS || SPARC64 || X86)
105398 + help
105399 + By saying Y here the kernel will detect and prevent overflowing
105400 + various (but not all) kinds of object reference counters. Such
105401 + overflows can normally occur due to bugs only and are often, if
105402 + not always, exploitable.
105403 +
105404 + The tradeoff is that data structures protected by an overflowed
105405 + refcount will never be freed and therefore will leak memory. Note
105406 + that this leak also happens even without this protection but in
105407 + that case the overflow can eventually trigger the freeing of the
105408 + data structure while it is still being used elsewhere, resulting
105409 + in the exploitable situation that this feature prevents.
105410 +
105411 + Since this has a negligible performance impact, you should enable
105412 + this feature.
105413 +
105414 +config PAX_CONSTIFY_PLUGIN
105415 + bool "Automatically constify eligible structures"
105416 + default y
105417 + depends on !UML && PAX_KERNEXEC
105418 + help
105419 + By saying Y here the compiler will automatically constify a class
105420 + of types that contain only function pointers. This reduces the
105421 + kernel's attack surface and also produces a better memory layout.
105422 +
105423 + Note that the implementation requires a gcc with plugin support,
105424 + i.e., gcc 4.5 or newer. You may need to install the supporting
105425 + headers explicitly in addition to the normal gcc package.
105426 +
105427 + Note that if some code really has to modify constified variables
105428 + then the source code will have to be patched to allow it. Examples
105429 + can be found in PaX itself (the no_const attribute) and for some
105430 + out-of-tree modules at http://www.grsecurity.net/~paxguy1/ .
105431 +
105432 +config PAX_USERCOPY
105433 + bool "Harden heap object copies between kernel and userland"
105434 + default y if GRKERNSEC_CONFIG_AUTO
105435 + depends on ARM || IA64 || PPC || SPARC || X86
105436 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
105437 + select PAX_USERCOPY_SLABS
105438 + help
105439 + By saying Y here the kernel will enforce the size of heap objects
105440 + when they are copied in either direction between the kernel and
105441 + userland, even if only a part of the heap object is copied.
105442 +
105443 + Specifically, this checking prevents information leaking from the
105444 + kernel heap during kernel to userland copies (if the kernel heap
105445 + object is otherwise fully initialized) and prevents kernel heap
105446 + overflows during userland to kernel copies.
105447 +
105448 + Note that the current implementation provides the strictest bounds
105449 + checks for the SLUB allocator.
105450 +
105451 + Enabling this option also enables per-slab cache protection against
105452 + data in a given cache being copied into/out of via userland
105453 + accessors. Though the whitelist of regions will be reduced over
105454 + time, it notably protects important data structures like task structs.
105455 +
105456 + If frame pointers are enabled on x86, this option will also restrict
105457 + copies into and out of the kernel stack to local variables within a
105458 + single frame.
105459 +
105460 + Since this has a negligible performance impact, you should enable
105461 + this feature.
105462 +
105463 +config PAX_USERCOPY_DEBUG
105464 + bool
105465 + depends on X86 && PAX_USERCOPY
105466 + default n
105467 +
105468 +config PAX_SIZE_OVERFLOW
105469 + bool "Prevent various integer overflows in function size parameters"
105470 + default y if GRKERNSEC_CONFIG_AUTO
105471 + depends on X86
105472 + help
105473 + By saying Y here the kernel recomputes expressions of function
105474 + arguments marked by a size_overflow attribute with double integer
105475 + precision (DImode/TImode for 32/64 bit integer types).
105476 +
105477 + The recomputed argument is checked against TYPE_MAX and an event
105478 + is logged on overflow and the triggering process is killed.
105479 +
105480 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
105481 +
105482 + Note that the implementation requires a gcc with plugin support,
105483 + i.e., gcc 4.5 or newer. You may need to install the supporting
105484 + headers explicitly in addition to the normal gcc package.
105485 +
105486 +config PAX_LATENT_ENTROPY
105487 + bool "Generate some entropy during boot and runtime"
105488 + default y if GRKERNSEC_CONFIG_AUTO
105489 + help
105490 + By saying Y here the kernel will instrument some kernel code to
105491 + extract some entropy from both original and artificially created
105492 + program state. This will help especially embedded systems where
105493 + there is little 'natural' source of entropy normally. The cost
105494 + is some slowdown of the boot process and fork and irq processing.
105495 +
105496 + When pax_extra_latent_entropy is passed on the kernel command line,
105497 + entropy will be extracted from up to the first 4GB of RAM while the
105498 + runtime memory allocator is being initialized. This costs even more
105499 + slowdown of the boot process.
105500 +
105501 + Note that the implementation requires a gcc with plugin support,
105502 + i.e., gcc 4.5 or newer. You may need to install the supporting
105503 + headers explicitly in addition to the normal gcc package.
105504 +
105505 + Note that entropy extracted this way is not cryptographically
105506 + secure!
105507 +
105508 +endmenu
105509 +
105510 +endmenu
105511 +
105512 +source grsecurity/Kconfig
105513 +
105514 +endmenu
105515 +
105516 +endmenu
105517 +
105518 source security/keys/Kconfig
105519
105520 config SECURITY_DMESG_RESTRICT
105521 @@ -103,7 +1054,7 @@ config INTEL_TXT
105522 config LSM_MMAP_MIN_ADDR
105523 int "Low address space for LSM to protect from user allocation"
105524 depends on SECURITY && SECURITY_SELINUX
105525 - default 32768 if ARM || (ARM64 && COMPAT)
105526 + default 32768 if ALPHA || ARM || (ARM64 && COMPAT) || PARISC || SPARC32
105527 default 65536
105528 help
105529 This is the portion of low virtual memory which should be protected
105530 diff --git a/security/apparmor/file.c b/security/apparmor/file.c
105531 index fdaa50c..2761dcb 100644
105532 --- a/security/apparmor/file.c
105533 +++ b/security/apparmor/file.c
105534 @@ -348,8 +348,8 @@ static inline bool xindex_is_subset(u32 link, u32 target)
105535 int aa_path_link(struct aa_profile *profile, struct dentry *old_dentry,
105536 struct path *new_dir, struct dentry *new_dentry)
105537 {
105538 - struct path link = { new_dir->mnt, new_dentry };
105539 - struct path target = { new_dir->mnt, old_dentry };
105540 + struct path link = { .mnt = new_dir->mnt, .dentry = new_dentry };
105541 + struct path target = { .mnt = new_dir->mnt, .dentry = old_dentry };
105542 struct path_cond cond = {
105543 old_dentry->d_inode->i_uid,
105544 old_dentry->d_inode->i_mode
105545 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
105546 index 9981000..eb21356 100644
105547 --- a/security/apparmor/lsm.c
105548 +++ b/security/apparmor/lsm.c
105549 @@ -186,7 +186,7 @@ static int common_perm_dir_dentry(int op, struct path *dir,
105550 struct dentry *dentry, u32 mask,
105551 struct path_cond *cond)
105552 {
105553 - struct path path = { dir->mnt, dentry };
105554 + struct path path = { .mnt = dir->mnt, .dentry = dentry };
105555
105556 return common_perm(op, &path, mask, cond);
105557 }
105558 @@ -203,7 +203,7 @@ static int common_perm_dir_dentry(int op, struct path *dir,
105559 static int common_perm_mnt_dentry(int op, struct vfsmount *mnt,
105560 struct dentry *dentry, u32 mask)
105561 {
105562 - struct path path = { mnt, dentry };
105563 + struct path path = { .mnt = mnt, .dentry = dentry };
105564 struct path_cond cond = { dentry->d_inode->i_uid,
105565 dentry->d_inode->i_mode
105566 };
105567 @@ -325,8 +325,8 @@ static int apparmor_path_rename(struct path *old_dir, struct dentry *old_dentry,
105568
105569 profile = aa_current_profile();
105570 if (!unconfined(profile)) {
105571 - struct path old_path = { old_dir->mnt, old_dentry };
105572 - struct path new_path = { new_dir->mnt, new_dentry };
105573 + struct path old_path = { .mnt = old_dir->mnt, .dentry = old_dentry };
105574 + struct path new_path = { .mnt = new_dir->mnt, .dentry = new_dentry };
105575 struct path_cond cond = { old_dentry->d_inode->i_uid,
105576 old_dentry->d_inode->i_mode
105577 };
105578 @@ -615,7 +615,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
105579 return error;
105580 }
105581
105582 -static struct security_operations apparmor_ops = {
105583 +static struct security_operations apparmor_ops __read_only = {
105584 .name = "apparmor",
105585
105586 .ptrace_access_check = apparmor_ptrace_access_check,
105587 diff --git a/security/commoncap.c b/security/commoncap.c
105588 index b9d613e..f68305c 100644
105589 --- a/security/commoncap.c
105590 +++ b/security/commoncap.c
105591 @@ -424,6 +424,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
105592 return 0;
105593 }
105594
105595 +/* returns:
105596 + 1 for suid privilege
105597 + 2 for sgid privilege
105598 + 3 for fscap privilege
105599 +*/
105600 +int is_privileged_binary(const struct dentry *dentry)
105601 +{
105602 + struct cpu_vfs_cap_data capdata;
105603 + struct inode *inode = dentry->d_inode;
105604 +
105605 + if (!inode || S_ISDIR(inode->i_mode))
105606 + return 0;
105607 +
105608 + if (inode->i_mode & S_ISUID)
105609 + return 1;
105610 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
105611 + return 2;
105612 +
105613 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
105614 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
105615 + return 3;
105616 + }
105617 +
105618 + return 0;
105619 +}
105620 +
105621 /*
105622 * Attempt to get the on-exec apply capability sets for an executable file from
105623 * its xattrs and, if present, apply them to the proposed credentials being
105624 @@ -592,6 +618,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
105625 const struct cred *cred = current_cred();
105626 kuid_t root_uid = make_kuid(cred->user_ns, 0);
105627
105628 + if (gr_acl_enable_at_secure())
105629 + return 1;
105630 +
105631 if (!uid_eq(cred->uid, root_uid)) {
105632 if (bprm->cap_effective)
105633 return 1;
105634 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
105635 index f79fa8b..6161868 100644
105636 --- a/security/integrity/ima/ima.h
105637 +++ b/security/integrity/ima/ima.h
105638 @@ -118,8 +118,8 @@ int ima_init_template(void);
105639 extern spinlock_t ima_queue_lock;
105640
105641 struct ima_h_table {
105642 - atomic_long_t len; /* number of stored measurements in the list */
105643 - atomic_long_t violations;
105644 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
105645 + atomic_long_unchecked_t violations;
105646 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
105647 };
105648 extern struct ima_h_table ima_htable;
105649 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
105650 index d9cd5ce..c5c29ac 100644
105651 --- a/security/integrity/ima/ima_api.c
105652 +++ b/security/integrity/ima/ima_api.c
105653 @@ -137,7 +137,7 @@ void ima_add_violation(struct file *file, const unsigned char *filename,
105654 int result;
105655
105656 /* can overflow, only indicator */
105657 - atomic_long_inc(&ima_htable.violations);
105658 + atomic_long_inc_unchecked(&ima_htable.violations);
105659
105660 result = ima_alloc_init_template(NULL, file, filename,
105661 NULL, 0, &entry);
105662 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
105663 index da92fcc..8a5d390 100644
105664 --- a/security/integrity/ima/ima_fs.c
105665 +++ b/security/integrity/ima/ima_fs.c
105666 @@ -28,12 +28,12 @@
105667 static int valid_policy = 1;
105668 #define TMPBUFLEN 12
105669 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
105670 - loff_t *ppos, atomic_long_t *val)
105671 + loff_t *ppos, atomic_long_unchecked_t *val)
105672 {
105673 char tmpbuf[TMPBUFLEN];
105674 ssize_t len;
105675
105676 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
105677 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
105678 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
105679 }
105680
105681 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
105682 index 552705d..9920f4fb 100644
105683 --- a/security/integrity/ima/ima_queue.c
105684 +++ b/security/integrity/ima/ima_queue.c
105685 @@ -83,7 +83,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
105686 INIT_LIST_HEAD(&qe->later);
105687 list_add_tail_rcu(&qe->later, &ima_measurements);
105688
105689 - atomic_long_inc(&ima_htable.len);
105690 + atomic_long_inc_unchecked(&ima_htable.len);
105691 key = ima_hash_key(entry->digest);
105692 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
105693 return 0;
105694 diff --git a/security/keys/compat.c b/security/keys/compat.c
105695 index 3478965..ec7bb9e 100644
105696 --- a/security/keys/compat.c
105697 +++ b/security/keys/compat.c
105698 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
105699 if (ret == 0)
105700 goto no_payload_free;
105701
105702 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
105703 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
105704 err:
105705 if (iov != iovstack)
105706 kfree(iov);
105707 diff --git a/security/keys/internal.h b/security/keys/internal.h
105708 index 80b2aac..bb7ee65 100644
105709 --- a/security/keys/internal.h
105710 +++ b/security/keys/internal.h
105711 @@ -253,7 +253,7 @@ extern long keyctl_instantiate_key_iov(key_serial_t,
105712 extern long keyctl_invalidate_key(key_serial_t);
105713
105714 extern long keyctl_instantiate_key_common(key_serial_t,
105715 - const struct iovec *,
105716 + const struct iovec __user *,
105717 unsigned, size_t, key_serial_t);
105718 #ifdef CONFIG_PERSISTENT_KEYRINGS
105719 extern long keyctl_get_persistent(uid_t, key_serial_t);
105720 diff --git a/security/keys/key.c b/security/keys/key.c
105721 index 6e21c11..9ed67ca 100644
105722 --- a/security/keys/key.c
105723 +++ b/security/keys/key.c
105724 @@ -285,7 +285,7 @@ struct key *key_alloc(struct key_type *type, const char *desc,
105725
105726 atomic_set(&key->usage, 1);
105727 init_rwsem(&key->sem);
105728 - lockdep_set_class(&key->sem, &type->lock_class);
105729 + lockdep_set_class(&key->sem, (struct lock_class_key *)&type->lock_class);
105730 key->index_key.type = type;
105731 key->user = user;
105732 key->quotalen = quotalen;
105733 @@ -1036,7 +1036,9 @@ int register_key_type(struct key_type *ktype)
105734 struct key_type *p;
105735 int ret;
105736
105737 - memset(&ktype->lock_class, 0, sizeof(ktype->lock_class));
105738 + pax_open_kernel();
105739 + memset((void *)&ktype->lock_class, 0, sizeof(ktype->lock_class));
105740 + pax_close_kernel();
105741
105742 ret = -EEXIST;
105743 down_write(&key_types_sem);
105744 @@ -1048,7 +1050,7 @@ int register_key_type(struct key_type *ktype)
105745 }
105746
105747 /* store the type */
105748 - list_add(&ktype->link, &key_types_list);
105749 + pax_list_add((struct list_head *)&ktype->link, &key_types_list);
105750
105751 pr_notice("Key type %s registered\n", ktype->name);
105752 ret = 0;
105753 @@ -1070,7 +1072,7 @@ EXPORT_SYMBOL(register_key_type);
105754 void unregister_key_type(struct key_type *ktype)
105755 {
105756 down_write(&key_types_sem);
105757 - list_del_init(&ktype->link);
105758 + pax_list_del_init((struct list_head *)&ktype->link);
105759 downgrade_write(&key_types_sem);
105760 key_gc_keytype(ktype);
105761 pr_notice("Key type %s unregistered\n", ktype->name);
105762 @@ -1088,10 +1090,10 @@ void __init key_init(void)
105763 0, SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
105764
105765 /* add the special key types */
105766 - list_add_tail(&key_type_keyring.link, &key_types_list);
105767 - list_add_tail(&key_type_dead.link, &key_types_list);
105768 - list_add_tail(&key_type_user.link, &key_types_list);
105769 - list_add_tail(&key_type_logon.link, &key_types_list);
105770 + pax_list_add_tail((struct list_head *)&key_type_keyring.link, &key_types_list);
105771 + pax_list_add_tail((struct list_head *)&key_type_dead.link, &key_types_list);
105772 + pax_list_add_tail((struct list_head *)&key_type_user.link, &key_types_list);
105773 + pax_list_add_tail((struct list_head *)&key_type_logon.link, &key_types_list);
105774
105775 /* record the root user tracking */
105776 rb_link_node(&root_key_user.node,
105777 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
105778 index cee72ce..e46074a 100644
105779 --- a/security/keys/keyctl.c
105780 +++ b/security/keys/keyctl.c
105781 @@ -987,7 +987,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
105782 /*
105783 * Copy the iovec data from userspace
105784 */
105785 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
105786 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
105787 unsigned ioc)
105788 {
105789 for (; ioc > 0; ioc--) {
105790 @@ -1009,7 +1009,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
105791 * If successful, 0 will be returned.
105792 */
105793 long keyctl_instantiate_key_common(key_serial_t id,
105794 - const struct iovec *payload_iov,
105795 + const struct iovec __user *payload_iov,
105796 unsigned ioc,
105797 size_t plen,
105798 key_serial_t ringid)
105799 @@ -1104,7 +1104,7 @@ long keyctl_instantiate_key(key_serial_t id,
105800 [0].iov_len = plen
105801 };
105802
105803 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
105804 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
105805 }
105806
105807 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
105808 @@ -1137,7 +1137,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
105809 if (ret == 0)
105810 goto no_payload_free;
105811
105812 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
105813 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
105814 err:
105815 if (iov != iovstack)
105816 kfree(iov);
105817 diff --git a/security/min_addr.c b/security/min_addr.c
105818 index f728728..6457a0c 100644
105819 --- a/security/min_addr.c
105820 +++ b/security/min_addr.c
105821 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
105822 */
105823 static void update_mmap_min_addr(void)
105824 {
105825 +#ifndef SPARC
105826 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
105827 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
105828 mmap_min_addr = dac_mmap_min_addr;
105829 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
105830 #else
105831 mmap_min_addr = dac_mmap_min_addr;
105832 #endif
105833 +#endif
105834 }
105835
105836 /*
105837 diff --git a/security/security.c b/security/security.c
105838 index 8b774f3..a396233 100644
105839 --- a/security/security.c
105840 +++ b/security/security.c
105841 @@ -33,8 +33,8 @@
105842 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
105843 CONFIG_DEFAULT_SECURITY;
105844
105845 -static struct security_operations *security_ops;
105846 -static struct security_operations default_security_ops = {
105847 +struct security_operations *security_ops __read_only;
105848 +struct security_operations default_security_ops __read_only = {
105849 .name = "default",
105850 };
105851
105852 @@ -73,11 +73,6 @@ int __init security_init(void)
105853 return 0;
105854 }
105855
105856 -void reset_security_ops(void)
105857 -{
105858 - security_ops = &default_security_ops;
105859 -}
105860 -
105861 /* Save user chosen LSM */
105862 static int __init choose_lsm(char *str)
105863 {
105864 diff --git a/security/selinux/avc.c b/security/selinux/avc.c
105865 index fc3e662..7844c60 100644
105866 --- a/security/selinux/avc.c
105867 +++ b/security/selinux/avc.c
105868 @@ -59,7 +59,7 @@ struct avc_node {
105869 struct avc_cache {
105870 struct hlist_head slots[AVC_CACHE_SLOTS]; /* head for avc_node->list */
105871 spinlock_t slots_lock[AVC_CACHE_SLOTS]; /* lock for writes */
105872 - atomic_t lru_hint; /* LRU hint for reclaim scan */
105873 + atomic_unchecked_t lru_hint; /* LRU hint for reclaim scan */
105874 atomic_t active_nodes;
105875 u32 latest_notif; /* latest revocation notification */
105876 };
105877 @@ -167,7 +167,7 @@ void __init avc_init(void)
105878 spin_lock_init(&avc_cache.slots_lock[i]);
105879 }
105880 atomic_set(&avc_cache.active_nodes, 0);
105881 - atomic_set(&avc_cache.lru_hint, 0);
105882 + atomic_set_unchecked(&avc_cache.lru_hint, 0);
105883
105884 avc_node_cachep = kmem_cache_create("avc_node", sizeof(struct avc_node),
105885 0, SLAB_PANIC, NULL);
105886 @@ -242,7 +242,7 @@ static inline int avc_reclaim_node(void)
105887 spinlock_t *lock;
105888
105889 for (try = 0, ecx = 0; try < AVC_CACHE_SLOTS; try++) {
105890 - hvalue = atomic_inc_return(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
105891 + hvalue = atomic_inc_return_unchecked(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
105892 head = &avc_cache.slots[hvalue];
105893 lock = &avc_cache.slots_lock[hvalue];
105894
105895 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
105896 index 2c7341d..1da068e 100644
105897 --- a/security/selinux/hooks.c
105898 +++ b/security/selinux/hooks.c
105899 @@ -95,8 +95,6 @@
105900 #include "audit.h"
105901 #include "avc_ss.h"
105902
105903 -extern struct security_operations *security_ops;
105904 -
105905 /* SECMARK reference count */
105906 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
105907
105908 @@ -5758,7 +5756,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
105909
105910 #endif
105911
105912 -static struct security_operations selinux_ops = {
105913 +static struct security_operations selinux_ops __read_only = {
105914 .name = "selinux",
105915
105916 .ptrace_access_check = selinux_ptrace_access_check,
105917 @@ -6111,6 +6109,9 @@ static void selinux_nf_ip_exit(void)
105918 #ifdef CONFIG_SECURITY_SELINUX_DISABLE
105919 static int selinux_disabled;
105920
105921 +extern struct security_operations *security_ops;
105922 +extern struct security_operations default_security_ops;
105923 +
105924 int selinux_disable(void)
105925 {
105926 if (ss_initialized) {
105927 @@ -6128,7 +6129,9 @@ int selinux_disable(void)
105928 selinux_disabled = 1;
105929 selinux_enabled = 0;
105930
105931 - reset_security_ops();
105932 + pax_open_kernel();
105933 + security_ops = &default_security_ops;
105934 + pax_close_kernel();
105935
105936 /* Try to destroy the avc node cache */
105937 avc_disable();
105938 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
105939 index 1450f85..a91e0bc 100644
105940 --- a/security/selinux/include/xfrm.h
105941 +++ b/security/selinux/include/xfrm.h
105942 @@ -48,7 +48,7 @@ static inline void selinux_xfrm_notify_policyload(void)
105943
105944 rtnl_lock();
105945 for_each_net(net) {
105946 - atomic_inc(&net->xfrm.flow_cache_genid);
105947 + atomic_inc_unchecked(&net->xfrm.flow_cache_genid);
105948 rt_genid_bump_all(net);
105949 }
105950 rtnl_unlock();
105951 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
105952 index 14f52be..7352368 100644
105953 --- a/security/smack/smack_lsm.c
105954 +++ b/security/smack/smack_lsm.c
105955 @@ -3726,7 +3726,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
105956 return 0;
105957 }
105958
105959 -struct security_operations smack_ops = {
105960 +struct security_operations smack_ops __read_only = {
105961 .name = "smack",
105962
105963 .ptrace_access_check = smack_ptrace_access_check,
105964 diff --git a/security/tomoyo/file.c b/security/tomoyo/file.c
105965 index 4003907..13a2b55 100644
105966 --- a/security/tomoyo/file.c
105967 +++ b/security/tomoyo/file.c
105968 @@ -692,7 +692,7 @@ int tomoyo_path_number_perm(const u8 type, struct path *path,
105969 {
105970 struct tomoyo_request_info r;
105971 struct tomoyo_obj_info obj = {
105972 - .path1 = *path,
105973 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
105974 };
105975 int error = -ENOMEM;
105976 struct tomoyo_path_info buf;
105977 @@ -740,7 +740,7 @@ int tomoyo_check_open_permission(struct tomoyo_domain_info *domain,
105978 struct tomoyo_path_info buf;
105979 struct tomoyo_request_info r;
105980 struct tomoyo_obj_info obj = {
105981 - .path1 = *path,
105982 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
105983 };
105984 int idx;
105985
105986 @@ -786,7 +786,7 @@ int tomoyo_path_perm(const u8 operation, struct path *path, const char *target)
105987 {
105988 struct tomoyo_request_info r;
105989 struct tomoyo_obj_info obj = {
105990 - .path1 = *path,
105991 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
105992 };
105993 int error;
105994 struct tomoyo_path_info buf;
105995 @@ -843,7 +843,7 @@ int tomoyo_mkdev_perm(const u8 operation, struct path *path,
105996 {
105997 struct tomoyo_request_info r;
105998 struct tomoyo_obj_info obj = {
105999 - .path1 = *path,
106000 + .path1 = { .mnt = path->mnt, .dentry = path->dentry },
106001 };
106002 int error = -ENOMEM;
106003 struct tomoyo_path_info buf;
106004 @@ -890,8 +890,8 @@ int tomoyo_path2_perm(const u8 operation, struct path *path1,
106005 struct tomoyo_path_info buf2;
106006 struct tomoyo_request_info r;
106007 struct tomoyo_obj_info obj = {
106008 - .path1 = *path1,
106009 - .path2 = *path2,
106010 + .path1 = { .mnt = path1->mnt, .dentry = path1->dentry },
106011 + .path2 = { .mnt = path2->mnt, .dentry = path2->dentry }
106012 };
106013 int idx;
106014
106015 diff --git a/security/tomoyo/mount.c b/security/tomoyo/mount.c
106016 index 390c646..f2f8db3 100644
106017 --- a/security/tomoyo/mount.c
106018 +++ b/security/tomoyo/mount.c
106019 @@ -118,6 +118,10 @@ static int tomoyo_mount_acl(struct tomoyo_request_info *r,
106020 type == tomoyo_mounts[TOMOYO_MOUNT_MOVE]) {
106021 need_dev = -1; /* dev_name is a directory */
106022 } else {
106023 + if (!capable(CAP_SYS_ADMIN)) {
106024 + error = -EPERM;
106025 + goto out;
106026 + }
106027 fstype = get_fs_type(type);
106028 if (!fstype) {
106029 error = -ENODEV;
106030 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
106031 index f0b756e..8aa497b 100644
106032 --- a/security/tomoyo/tomoyo.c
106033 +++ b/security/tomoyo/tomoyo.c
106034 @@ -146,7 +146,7 @@ static int tomoyo_bprm_check_security(struct linux_binprm *bprm)
106035 */
106036 static int tomoyo_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
106037 {
106038 - struct path path = { mnt, dentry };
106039 + struct path path = { .mnt = mnt, .dentry = dentry };
106040 return tomoyo_path_perm(TOMOYO_TYPE_GETATTR, &path, NULL);
106041 }
106042
106043 @@ -172,7 +172,7 @@ static int tomoyo_path_truncate(struct path *path)
106044 */
106045 static int tomoyo_path_unlink(struct path *parent, struct dentry *dentry)
106046 {
106047 - struct path path = { parent->mnt, dentry };
106048 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
106049 return tomoyo_path_perm(TOMOYO_TYPE_UNLINK, &path, NULL);
106050 }
106051
106052 @@ -188,7 +188,7 @@ static int tomoyo_path_unlink(struct path *parent, struct dentry *dentry)
106053 static int tomoyo_path_mkdir(struct path *parent, struct dentry *dentry,
106054 umode_t mode)
106055 {
106056 - struct path path = { parent->mnt, dentry };
106057 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
106058 return tomoyo_path_number_perm(TOMOYO_TYPE_MKDIR, &path,
106059 mode & S_IALLUGO);
106060 }
106061 @@ -203,7 +203,7 @@ static int tomoyo_path_mkdir(struct path *parent, struct dentry *dentry,
106062 */
106063 static int tomoyo_path_rmdir(struct path *parent, struct dentry *dentry)
106064 {
106065 - struct path path = { parent->mnt, dentry };
106066 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
106067 return tomoyo_path_perm(TOMOYO_TYPE_RMDIR, &path, NULL);
106068 }
106069
106070 @@ -219,7 +219,7 @@ static int tomoyo_path_rmdir(struct path *parent, struct dentry *dentry)
106071 static int tomoyo_path_symlink(struct path *parent, struct dentry *dentry,
106072 const char *old_name)
106073 {
106074 - struct path path = { parent->mnt, dentry };
106075 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
106076 return tomoyo_path_perm(TOMOYO_TYPE_SYMLINK, &path, old_name);
106077 }
106078
106079 @@ -236,7 +236,7 @@ static int tomoyo_path_symlink(struct path *parent, struct dentry *dentry,
106080 static int tomoyo_path_mknod(struct path *parent, struct dentry *dentry,
106081 umode_t mode, unsigned int dev)
106082 {
106083 - struct path path = { parent->mnt, dentry };
106084 + struct path path = { .mnt = parent->mnt, .dentry = dentry };
106085 int type = TOMOYO_TYPE_CREATE;
106086 const unsigned int perm = mode & S_IALLUGO;
106087
106088 @@ -275,8 +275,8 @@ static int tomoyo_path_mknod(struct path *parent, struct dentry *dentry,
106089 static int tomoyo_path_link(struct dentry *old_dentry, struct path *new_dir,
106090 struct dentry *new_dentry)
106091 {
106092 - struct path path1 = { new_dir->mnt, old_dentry };
106093 - struct path path2 = { new_dir->mnt, new_dentry };
106094 + struct path path1 = { .mnt = new_dir->mnt, .dentry = old_dentry };
106095 + struct path path2 = { .mnt = new_dir->mnt, .dentry = new_dentry };
106096 return tomoyo_path2_perm(TOMOYO_TYPE_LINK, &path1, &path2);
106097 }
106098
106099 @@ -295,8 +295,8 @@ static int tomoyo_path_rename(struct path *old_parent,
106100 struct path *new_parent,
106101 struct dentry *new_dentry)
106102 {
106103 - struct path path1 = { old_parent->mnt, old_dentry };
106104 - struct path path2 = { new_parent->mnt, new_dentry };
106105 + struct path path1 = { .mnt = old_parent->mnt, .dentry = old_dentry };
106106 + struct path path2 = { .mnt = new_parent->mnt, .dentry = new_dentry };
106107 return tomoyo_path2_perm(TOMOYO_TYPE_RENAME, &path1, &path2);
106108 }
106109
106110 @@ -424,7 +424,7 @@ static int tomoyo_sb_mount(const char *dev_name, struct path *path,
106111 */
106112 static int tomoyo_sb_umount(struct vfsmount *mnt, int flags)
106113 {
106114 - struct path path = { mnt, mnt->mnt_root };
106115 + struct path path = { .mnt = mnt, .dentry = mnt->mnt_root };
106116 return tomoyo_path_perm(TOMOYO_TYPE_UMOUNT, &path, NULL);
106117 }
106118
106119 @@ -503,7 +503,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
106120 * tomoyo_security_ops is a "struct security_operations" which is used for
106121 * registering TOMOYO.
106122 */
106123 -static struct security_operations tomoyo_security_ops = {
106124 +static struct security_operations tomoyo_security_ops __read_only = {
106125 .name = "tomoyo",
106126 .cred_alloc_blank = tomoyo_cred_alloc_blank,
106127 .cred_prepare = tomoyo_cred_prepare,
106128 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
106129 index 20ef514..4182bed 100644
106130 --- a/security/yama/Kconfig
106131 +++ b/security/yama/Kconfig
106132 @@ -1,6 +1,6 @@
106133 config SECURITY_YAMA
106134 bool "Yama support"
106135 - depends on SECURITY
106136 + depends on SECURITY && !GRKERNSEC
106137 select SECURITYFS
106138 select SECURITY_PATH
106139 default n
106140 diff --git a/security/yama/yama_lsm.c b/security/yama/yama_lsm.c
106141 index 13c88fbc..f8c115e 100644
106142 --- a/security/yama/yama_lsm.c
106143 +++ b/security/yama/yama_lsm.c
106144 @@ -365,7 +365,7 @@ int yama_ptrace_traceme(struct task_struct *parent)
106145 }
106146
106147 #ifndef CONFIG_SECURITY_YAMA_STACKED
106148 -static struct security_operations yama_ops = {
106149 +static struct security_operations yama_ops __read_only = {
106150 .name = "yama",
106151
106152 .ptrace_access_check = yama_ptrace_access_check,
106153 @@ -376,28 +376,24 @@ static struct security_operations yama_ops = {
106154 #endif
106155
106156 #ifdef CONFIG_SYSCTL
106157 +static int zero __read_only;
106158 +static int max_scope __read_only = YAMA_SCOPE_NO_ATTACH;
106159 +
106160 static int yama_dointvec_minmax(struct ctl_table *table, int write,
106161 void __user *buffer, size_t *lenp, loff_t *ppos)
106162 {
106163 - int rc;
106164 + ctl_table_no_const yama_table;
106165
106166 if (write && !capable(CAP_SYS_PTRACE))
106167 return -EPERM;
106168
106169 - rc = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
106170 - if (rc)
106171 - return rc;
106172 -
106173 + yama_table = *table;
106174 /* Lock the max value if it ever gets set. */
106175 - if (write && *(int *)table->data == *(int *)table->extra2)
106176 - table->extra1 = table->extra2;
106177 -
106178 - return rc;
106179 + if (ptrace_scope == max_scope)
106180 + yama_table.extra1 = &max_scope;
106181 + return proc_dointvec_minmax(&yama_table, write, buffer, lenp, ppos);
106182 }
106183
106184 -static int zero;
106185 -static int max_scope = YAMA_SCOPE_NO_ATTACH;
106186 -
106187 struct ctl_path yama_sysctl_path[] = {
106188 { .procname = "kernel", },
106189 { .procname = "yama", },
106190 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
106191 index f01bffb..bdda392 100644
106192 --- a/sound/aoa/codecs/onyx.c
106193 +++ b/sound/aoa/codecs/onyx.c
106194 @@ -54,7 +54,7 @@ struct onyx {
106195 spdif_locked:1,
106196 analog_locked:1,
106197 original_mute:2;
106198 - int open_count;
106199 + local_t open_count;
106200 struct codec_info *codec_info;
106201
106202 /* mutex serializes concurrent access to the device
106203 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
106204 struct onyx *onyx = cii->codec_data;
106205
106206 mutex_lock(&onyx->mutex);
106207 - onyx->open_count++;
106208 + local_inc(&onyx->open_count);
106209 mutex_unlock(&onyx->mutex);
106210
106211 return 0;
106212 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
106213 struct onyx *onyx = cii->codec_data;
106214
106215 mutex_lock(&onyx->mutex);
106216 - onyx->open_count--;
106217 - if (!onyx->open_count)
106218 + if (local_dec_and_test(&onyx->open_count))
106219 onyx->spdif_locked = onyx->analog_locked = 0;
106220 mutex_unlock(&onyx->mutex);
106221
106222 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
106223 index ffd2025..df062c9 100644
106224 --- a/sound/aoa/codecs/onyx.h
106225 +++ b/sound/aoa/codecs/onyx.h
106226 @@ -11,6 +11,7 @@
106227 #include <linux/i2c.h>
106228 #include <asm/pmac_low_i2c.h>
106229 #include <asm/prom.h>
106230 +#include <asm/local.h>
106231
106232 /* PCM3052 register definitions */
106233
106234 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
106235 index ada69d7..5f65386 100644
106236 --- a/sound/core/oss/pcm_oss.c
106237 +++ b/sound/core/oss/pcm_oss.c
106238 @@ -1190,10 +1190,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
106239 if (in_kernel) {
106240 mm_segment_t fs;
106241 fs = snd_enter_user();
106242 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
106243 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
106244 snd_leave_user(fs);
106245 } else {
106246 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
106247 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
106248 }
106249 if (ret != -EPIPE && ret != -ESTRPIPE)
106250 break;
106251 @@ -1233,10 +1233,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
106252 if (in_kernel) {
106253 mm_segment_t fs;
106254 fs = snd_enter_user();
106255 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
106256 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
106257 snd_leave_user(fs);
106258 } else {
106259 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
106260 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
106261 }
106262 if (ret == -EPIPE) {
106263 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
106264 @@ -1332,7 +1332,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
106265 struct snd_pcm_plugin_channel *channels;
106266 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
106267 if (!in_kernel) {
106268 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
106269 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
106270 return -EFAULT;
106271 buf = runtime->oss.buffer;
106272 }
106273 @@ -1402,7 +1402,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
106274 }
106275 } else {
106276 tmp = snd_pcm_oss_write2(substream,
106277 - (const char __force *)buf,
106278 + (const char __force_kernel *)buf,
106279 runtime->oss.period_bytes, 0);
106280 if (tmp <= 0)
106281 goto err;
106282 @@ -1428,7 +1428,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
106283 struct snd_pcm_runtime *runtime = substream->runtime;
106284 snd_pcm_sframes_t frames, frames1;
106285 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
106286 - char __user *final_dst = (char __force __user *)buf;
106287 + char __user *final_dst = (char __force_user *)buf;
106288 if (runtime->oss.plugin_first) {
106289 struct snd_pcm_plugin_channel *channels;
106290 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
106291 @@ -1490,7 +1490,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
106292 xfer += tmp;
106293 runtime->oss.buffer_used -= tmp;
106294 } else {
106295 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
106296 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
106297 runtime->oss.period_bytes, 0);
106298 if (tmp <= 0)
106299 goto err;
106300 @@ -1659,7 +1659,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
106301 size1);
106302 size1 /= runtime->channels; /* frames */
106303 fs = snd_enter_user();
106304 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
106305 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
106306 snd_leave_user(fs);
106307 }
106308 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
106309 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
106310 index af49721..e85058e 100644
106311 --- a/sound/core/pcm_compat.c
106312 +++ b/sound/core/pcm_compat.c
106313 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
106314 int err;
106315
106316 fs = snd_enter_user();
106317 - err = snd_pcm_delay(substream, &delay);
106318 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
106319 snd_leave_user(fs);
106320 if (err < 0)
106321 return err;
106322 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
106323 index b653ab0..a4738e3 100644
106324 --- a/sound/core/pcm_native.c
106325 +++ b/sound/core/pcm_native.c
106326 @@ -2812,11 +2812,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
106327 switch (substream->stream) {
106328 case SNDRV_PCM_STREAM_PLAYBACK:
106329 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
106330 - (void __user *)arg);
106331 + (void __force_user *)arg);
106332 break;
106333 case SNDRV_PCM_STREAM_CAPTURE:
106334 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
106335 - (void __user *)arg);
106336 + (void __force_user *)arg);
106337 break;
106338 default:
106339 result = -EINVAL;
106340 diff --git a/sound/core/seq/oss/seq_oss.c b/sound/core/seq/oss/seq_oss.c
106341 index 16d4267..fe8b49b 100644
106342 --- a/sound/core/seq/oss/seq_oss.c
106343 +++ b/sound/core/seq/oss/seq_oss.c
106344 @@ -69,8 +69,8 @@ static int __init alsa_seq_oss_init(void)
106345 {
106346 int rc;
106347 static struct snd_seq_dev_ops ops = {
106348 - snd_seq_oss_synth_register,
106349 - snd_seq_oss_synth_unregister,
106350 + .init_device = snd_seq_oss_synth_register,
106351 + .free_device = snd_seq_oss_synth_unregister,
106352 };
106353
106354 snd_seq_autoload_lock();
106355 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
106356 index 91a786a..4c07ed4 100644
106357 --- a/sound/core/seq/seq_device.c
106358 +++ b/sound/core/seq/seq_device.c
106359 @@ -64,7 +64,7 @@ struct ops_list {
106360 int argsize; /* argument size */
106361
106362 /* operators */
106363 - struct snd_seq_dev_ops ops;
106364 + struct snd_seq_dev_ops *ops;
106365
106366 /* registered devices */
106367 struct list_head dev_list; /* list of devices */
106368 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
106369
106370 mutex_lock(&ops->reg_mutex);
106371 /* copy driver operators */
106372 - ops->ops = *entry;
106373 + ops->ops = entry;
106374 ops->driver |= DRIVER_LOADED;
106375 ops->argsize = argsize;
106376
106377 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
106378 dev->name, ops->id, ops->argsize, dev->argsize);
106379 return -EINVAL;
106380 }
106381 - if (ops->ops.init_device(dev) >= 0) {
106382 + if (ops->ops->init_device(dev) >= 0) {
106383 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
106384 ops->num_init_devices++;
106385 } else {
106386 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
106387 dev->name, ops->id, ops->argsize, dev->argsize);
106388 return -EINVAL;
106389 }
106390 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
106391 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
106392 dev->status = SNDRV_SEQ_DEVICE_FREE;
106393 dev->driver_data = NULL;
106394 ops->num_init_devices--;
106395 diff --git a/sound/core/seq/seq_midi.c b/sound/core/seq/seq_midi.c
106396 index 3e05c55..0f02efc 100644
106397 --- a/sound/core/seq/seq_midi.c
106398 +++ b/sound/core/seq/seq_midi.c
106399 @@ -462,8 +462,8 @@ snd_seq_midisynth_unregister_port(struct snd_seq_device *dev)
106400 static int __init alsa_seq_midi_init(void)
106401 {
106402 static struct snd_seq_dev_ops ops = {
106403 - snd_seq_midisynth_register_port,
106404 - snd_seq_midisynth_unregister_port,
106405 + .init_device = snd_seq_midisynth_register_port,
106406 + .free_device = snd_seq_midisynth_unregister_port,
106407 };
106408 memset(&synths, 0, sizeof(synths));
106409 snd_seq_autoload_lock();
106410 diff --git a/sound/core/sound.c b/sound/core/sound.c
106411 index 38ad1a0..5010a40 100644
106412 --- a/sound/core/sound.c
106413 +++ b/sound/core/sound.c
106414 @@ -86,7 +86,7 @@ static void snd_request_other(int minor)
106415 case SNDRV_MINOR_TIMER: str = "snd-timer"; break;
106416 default: return;
106417 }
106418 - request_module(str);
106419 + request_module("%s", str);
106420 }
106421
106422 #endif /* modular kernel */
106423 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
106424 index f5fd448..6ae276da 100644
106425 --- a/sound/drivers/mts64.c
106426 +++ b/sound/drivers/mts64.c
106427 @@ -29,6 +29,7 @@
106428 #include <sound/initval.h>
106429 #include <sound/rawmidi.h>
106430 #include <sound/control.h>
106431 +#include <asm/local.h>
106432
106433 #define CARD_NAME "Miditerminal 4140"
106434 #define DRIVER_NAME "MTS64"
106435 @@ -67,7 +68,7 @@ struct mts64 {
106436 struct pardevice *pardev;
106437 int pardev_claimed;
106438
106439 - int open_count;
106440 + local_t open_count;
106441 int current_midi_output_port;
106442 int current_midi_input_port;
106443 u8 mode[MTS64_NUM_INPUT_PORTS];
106444 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
106445 {
106446 struct mts64 *mts = substream->rmidi->private_data;
106447
106448 - if (mts->open_count == 0) {
106449 + if (local_read(&mts->open_count) == 0) {
106450 /* We don't need a spinlock here, because this is just called
106451 if the device has not been opened before.
106452 So there aren't any IRQs from the device */
106453 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
106454
106455 msleep(50);
106456 }
106457 - ++(mts->open_count);
106458 + local_inc(&mts->open_count);
106459
106460 return 0;
106461 }
106462 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
106463 struct mts64 *mts = substream->rmidi->private_data;
106464 unsigned long flags;
106465
106466 - --(mts->open_count);
106467 - if (mts->open_count == 0) {
106468 + if (local_dec_return(&mts->open_count) == 0) {
106469 /* We need the spinlock_irqsave here because we can still
106470 have IRQs at this point */
106471 spin_lock_irqsave(&mts->lock, flags);
106472 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
106473
106474 msleep(500);
106475
106476 - } else if (mts->open_count < 0)
106477 - mts->open_count = 0;
106478 + } else if (local_read(&mts->open_count) < 0)
106479 + local_set(&mts->open_count, 0);
106480
106481 return 0;
106482 }
106483 diff --git a/sound/drivers/opl3/opl3_seq.c b/sound/drivers/opl3/opl3_seq.c
106484 index 6839953..7a0f4b9 100644
106485 --- a/sound/drivers/opl3/opl3_seq.c
106486 +++ b/sound/drivers/opl3/opl3_seq.c
106487 @@ -281,8 +281,8 @@ static int __init alsa_opl3_seq_init(void)
106488 {
106489 static struct snd_seq_dev_ops ops =
106490 {
106491 - snd_opl3_seq_new_device,
106492 - snd_opl3_seq_delete_device
106493 + .init_device = snd_opl3_seq_new_device,
106494 + .free_device = snd_opl3_seq_delete_device
106495 };
106496
106497 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL3, &ops,
106498 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
106499 index b953fb4..1999c01 100644
106500 --- a/sound/drivers/opl4/opl4_lib.c
106501 +++ b/sound/drivers/opl4/opl4_lib.c
106502 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
106503 MODULE_DESCRIPTION("OPL4 driver");
106504 MODULE_LICENSE("GPL");
106505
106506 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
106507 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
106508 {
106509 int timeout = 10;
106510 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
106511 diff --git a/sound/drivers/opl4/opl4_seq.c b/sound/drivers/opl4/opl4_seq.c
106512 index 9919769..d7de36c 100644
106513 --- a/sound/drivers/opl4/opl4_seq.c
106514 +++ b/sound/drivers/opl4/opl4_seq.c
106515 @@ -198,8 +198,8 @@ static int snd_opl4_seq_delete_device(struct snd_seq_device *dev)
106516 static int __init alsa_opl4_synth_init(void)
106517 {
106518 static struct snd_seq_dev_ops ops = {
106519 - snd_opl4_seq_new_device,
106520 - snd_opl4_seq_delete_device
106521 + .init_device = snd_opl4_seq_new_device,
106522 + .free_device = snd_opl4_seq_delete_device
106523 };
106524
106525 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL4, &ops,
106526 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
106527 index 78ccfa4..7a0857b 100644
106528 --- a/sound/drivers/portman2x4.c
106529 +++ b/sound/drivers/portman2x4.c
106530 @@ -48,6 +48,7 @@
106531 #include <sound/initval.h>
106532 #include <sound/rawmidi.h>
106533 #include <sound/control.h>
106534 +#include <asm/local.h>
106535
106536 #define CARD_NAME "Portman 2x4"
106537 #define DRIVER_NAME "portman"
106538 @@ -85,7 +86,7 @@ struct portman {
106539 struct pardevice *pardev;
106540 int pardev_claimed;
106541
106542 - int open_count;
106543 + local_t open_count;
106544 int mode[PORTMAN_NUM_INPUT_PORTS];
106545 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
106546 };
106547 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
106548 index 9048777..2d8b1fc 100644
106549 --- a/sound/firewire/amdtp.c
106550 +++ b/sound/firewire/amdtp.c
106551 @@ -488,7 +488,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
106552 ptr = s->pcm_buffer_pointer + data_blocks;
106553 if (ptr >= pcm->runtime->buffer_size)
106554 ptr -= pcm->runtime->buffer_size;
106555 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
106556 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
106557
106558 s->pcm_period_pointer += data_blocks;
106559 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
106560 @@ -655,7 +655,7 @@ EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer);
106561 */
106562 void amdtp_out_stream_update(struct amdtp_out_stream *s)
106563 {
106564 - ACCESS_ONCE(s->source_node_id_field) =
106565 + ACCESS_ONCE_RW(s->source_node_id_field) =
106566 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
106567 }
106568 EXPORT_SYMBOL(amdtp_out_stream_update);
106569 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
106570 index 2746ecd..c35dedd 100644
106571 --- a/sound/firewire/amdtp.h
106572 +++ b/sound/firewire/amdtp.h
106573 @@ -135,7 +135,7 @@ static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
106574 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
106575 struct snd_pcm_substream *pcm)
106576 {
106577 - ACCESS_ONCE(s->pcm) = pcm;
106578 + ACCESS_ONCE_RW(s->pcm) = pcm;
106579 }
106580
106581 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
106582 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
106583 index 7ac9443..0ec6274 100644
106584 --- a/sound/firewire/isight.c
106585 +++ b/sound/firewire/isight.c
106586 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
106587 ptr += count;
106588 if (ptr >= runtime->buffer_size)
106589 ptr -= runtime->buffer_size;
106590 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
106591 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
106592
106593 isight->period_counter += count;
106594 if (isight->period_counter >= runtime->period_size) {
106595 @@ -299,7 +299,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
106596 if (err < 0)
106597 return err;
106598
106599 - ACCESS_ONCE(isight->pcm_active) = true;
106600 + ACCESS_ONCE_RW(isight->pcm_active) = true;
106601
106602 return 0;
106603 }
106604 @@ -337,7 +337,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
106605 {
106606 struct isight *isight = substream->private_data;
106607
106608 - ACCESS_ONCE(isight->pcm_active) = false;
106609 + ACCESS_ONCE_RW(isight->pcm_active) = false;
106610
106611 mutex_lock(&isight->mutex);
106612 isight_stop_streaming(isight);
106613 @@ -430,10 +430,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
106614
106615 switch (cmd) {
106616 case SNDRV_PCM_TRIGGER_START:
106617 - ACCESS_ONCE(isight->pcm_running) = true;
106618 + ACCESS_ONCE_RW(isight->pcm_running) = true;
106619 break;
106620 case SNDRV_PCM_TRIGGER_STOP:
106621 - ACCESS_ONCE(isight->pcm_running) = false;
106622 + ACCESS_ONCE_RW(isight->pcm_running) = false;
106623 break;
106624 default:
106625 return -EINVAL;
106626 diff --git a/sound/firewire/scs1x.c b/sound/firewire/scs1x.c
106627 index 2dba848..c682aef 100644
106628 --- a/sound/firewire/scs1x.c
106629 +++ b/sound/firewire/scs1x.c
106630 @@ -74,7 +74,7 @@ static void scs_output_trigger(struct snd_rawmidi_substream *stream, int up)
106631 {
106632 struct scs *scs = stream->rmidi->private_data;
106633
106634 - ACCESS_ONCE(scs->output) = up ? stream : NULL;
106635 + ACCESS_ONCE_RW(scs->output) = up ? stream : NULL;
106636 if (up) {
106637 scs->output_idle = false;
106638 tasklet_schedule(&scs->tasklet);
106639 @@ -257,7 +257,7 @@ static void scs_input_trigger(struct snd_rawmidi_substream *stream, int up)
106640 {
106641 struct scs *scs = stream->rmidi->private_data;
106642
106643 - ACCESS_ONCE(scs->input) = up ? stream : NULL;
106644 + ACCESS_ONCE_RW(scs->input) = up ? stream : NULL;
106645 }
106646
106647 static void scs_input_escaped_byte(struct snd_rawmidi_substream *stream,
106648 @@ -473,8 +473,8 @@ static void scs_remove(struct fw_unit *unit)
106649
106650 snd_card_disconnect(scs->card);
106651
106652 - ACCESS_ONCE(scs->output) = NULL;
106653 - ACCESS_ONCE(scs->input) = NULL;
106654 + ACCESS_ONCE_RW(scs->output) = NULL;
106655 + ACCESS_ONCE_RW(scs->input) = NULL;
106656
106657 wait_event(scs->idle_wait, scs->output_idle);
106658
106659 diff --git a/sound/isa/sb/emu8000_synth.c b/sound/isa/sb/emu8000_synth.c
106660 index 4e3fcfb..ab45a9d 100644
106661 --- a/sound/isa/sb/emu8000_synth.c
106662 +++ b/sound/isa/sb/emu8000_synth.c
106663 @@ -120,8 +120,8 @@ static int __init alsa_emu8000_init(void)
106664 {
106665
106666 static struct snd_seq_dev_ops ops = {
106667 - snd_emu8000_new_device,
106668 - snd_emu8000_delete_device,
106669 + .init_device = snd_emu8000_new_device,
106670 + .free_device = snd_emu8000_delete_device,
106671 };
106672 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU8000, &ops,
106673 sizeof(struct snd_emu8000*));
106674 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
106675 index 048439a..3be9f6f 100644
106676 --- a/sound/oss/sb_audio.c
106677 +++ b/sound/oss/sb_audio.c
106678 @@ -904,7 +904,7 @@ sb16_copy_from_user(int dev,
106679 buf16 = (signed short *)(localbuf + localoffs);
106680 while (c)
106681 {
106682 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
106683 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
106684 if (copy_from_user(lbuf8,
106685 userbuf+useroffs + p,
106686 locallen))
106687 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
106688 index f851fd0..92576fb 100644
106689 --- a/sound/oss/swarm_cs4297a.c
106690 +++ b/sound/oss/swarm_cs4297a.c
106691 @@ -2623,7 +2623,6 @@ static int __init cs4297a_init(void)
106692 {
106693 struct cs4297a_state *s;
106694 u32 pwr, id;
106695 - mm_segment_t fs;
106696 int rval;
106697 #ifndef CONFIG_BCM_CS4297A_CSWARM
106698 u64 cfg;
106699 @@ -2713,22 +2712,23 @@ static int __init cs4297a_init(void)
106700 if (!rval) {
106701 char *sb1250_duart_present;
106702
106703 +#if 0
106704 + mm_segment_t fs;
106705 fs = get_fs();
106706 set_fs(KERNEL_DS);
106707 -#if 0
106708 val = SOUND_MASK_LINE;
106709 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
106710 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
106711 val = initvol[i].vol;
106712 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
106713 }
106714 + set_fs(fs);
106715 // cs4297a_write_ac97(s, 0x18, 0x0808);
106716 #else
106717 // cs4297a_write_ac97(s, 0x5e, 0x180);
106718 cs4297a_write_ac97(s, 0x02, 0x0808);
106719 cs4297a_write_ac97(s, 0x18, 0x0808);
106720 #endif
106721 - set_fs(fs);
106722
106723 list_add(&s->list, &cs4297a_devs);
106724
106725 diff --git a/sound/pci/emu10k1/emu10k1_synth.c b/sound/pci/emu10k1/emu10k1_synth.c
106726 index 4c41c90..37f3631 100644
106727 --- a/sound/pci/emu10k1/emu10k1_synth.c
106728 +++ b/sound/pci/emu10k1/emu10k1_synth.c
106729 @@ -108,8 +108,8 @@ static int __init alsa_emu10k1_synth_init(void)
106730 {
106731
106732 static struct snd_seq_dev_ops ops = {
106733 - snd_emu10k1_synth_new_device,
106734 - snd_emu10k1_synth_delete_device,
106735 + .init_device = snd_emu10k1_synth_new_device,
106736 + .free_device = snd_emu10k1_synth_delete_device,
106737 };
106738 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH, &ops,
106739 sizeof(struct snd_emu10k1_synth_arg));
106740 diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
106741 index 4c20277..91abdce 100644
106742 --- a/sound/pci/hda/hda_codec.c
106743 +++ b/sound/pci/hda/hda_codec.c
106744 @@ -966,14 +966,10 @@ find_codec_preset(struct hda_codec *codec)
106745 mutex_unlock(&preset_mutex);
106746
106747 if (mod_requested < HDA_MODREQ_MAX_COUNT) {
106748 - char name[32];
106749 if (!mod_requested)
106750 - snprintf(name, sizeof(name), "snd-hda-codec-id:%08x",
106751 - codec->vendor_id);
106752 + request_module("snd-hda-codec-id:%08x", codec->vendor_id);
106753 else
106754 - snprintf(name, sizeof(name), "snd-hda-codec-id:%04x*",
106755 - (codec->vendor_id >> 16) & 0xffff);
106756 - request_module(name);
106757 + request_module("snd-hda-codec-id:%04x*", (codec->vendor_id >> 16) & 0xffff);
106758 mod_requested++;
106759 goto again;
106760 }
106761 @@ -2777,7 +2773,7 @@ static int get_kctl_0dB_offset(struct snd_kcontrol *kctl, int *step_to_check)
106762 /* FIXME: set_fs() hack for obtaining user-space TLV data */
106763 mm_segment_t fs = get_fs();
106764 set_fs(get_ds());
106765 - if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), _tlv))
106766 + if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), (unsigned int __force_user *)_tlv))
106767 tlv = _tlv;
106768 set_fs(fs);
106769 } else if (kctl->vd[0].access & SNDRV_CTL_ELEM_ACCESS_TLV_READ)
106770 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
106771 index 4631a23..001ae57 100644
106772 --- a/sound/pci/ymfpci/ymfpci.h
106773 +++ b/sound/pci/ymfpci/ymfpci.h
106774 @@ -358,7 +358,7 @@ struct snd_ymfpci {
106775 spinlock_t reg_lock;
106776 spinlock_t voice_lock;
106777 wait_queue_head_t interrupt_sleep;
106778 - atomic_t interrupt_sleep_count;
106779 + atomic_unchecked_t interrupt_sleep_count;
106780 struct snd_info_entry *proc_entry;
106781 const struct firmware *dsp_microcode;
106782 const struct firmware *controller_microcode;
106783 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
106784 index 81c916a..516f0bf 100644
106785 --- a/sound/pci/ymfpci/ymfpci_main.c
106786 +++ b/sound/pci/ymfpci/ymfpci_main.c
106787 @@ -204,8 +204,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
106788 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
106789 break;
106790 }
106791 - if (atomic_read(&chip->interrupt_sleep_count)) {
106792 - atomic_set(&chip->interrupt_sleep_count, 0);
106793 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
106794 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
106795 wake_up(&chip->interrupt_sleep);
106796 }
106797 __end:
106798 @@ -789,7 +789,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
106799 continue;
106800 init_waitqueue_entry(&wait, current);
106801 add_wait_queue(&chip->interrupt_sleep, &wait);
106802 - atomic_inc(&chip->interrupt_sleep_count);
106803 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
106804 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
106805 remove_wait_queue(&chip->interrupt_sleep, &wait);
106806 }
106807 @@ -827,8 +827,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
106808 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
106809 spin_unlock(&chip->reg_lock);
106810
106811 - if (atomic_read(&chip->interrupt_sleep_count)) {
106812 - atomic_set(&chip->interrupt_sleep_count, 0);
106813 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
106814 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
106815 wake_up(&chip->interrupt_sleep);
106816 }
106817 }
106818 @@ -2423,7 +2423,7 @@ int snd_ymfpci_create(struct snd_card *card,
106819 spin_lock_init(&chip->reg_lock);
106820 spin_lock_init(&chip->voice_lock);
106821 init_waitqueue_head(&chip->interrupt_sleep);
106822 - atomic_set(&chip->interrupt_sleep_count, 0);
106823 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
106824 chip->card = card;
106825 chip->pci = pci;
106826 chip->irq = -1;
106827 diff --git a/sound/soc/fsl/fsl_ssi.c b/sound/soc/fsl/fsl_ssi.c
106828 index 5428a1f..474f651 100644
106829 --- a/sound/soc/fsl/fsl_ssi.c
106830 +++ b/sound/soc/fsl/fsl_ssi.c
106831 @@ -1255,7 +1255,6 @@ static int fsl_ssi_probe(struct platform_device *pdev)
106832 {
106833 struct fsl_ssi_private *ssi_private;
106834 int ret = 0;
106835 - struct device_attribute *dev_attr = NULL;
106836 struct device_node *np = pdev->dev.of_node;
106837 const struct of_device_id *of_id;
106838 enum fsl_ssi_type hw_type;
106839 @@ -1481,7 +1480,7 @@ static int fsl_ssi_probe(struct platform_device *pdev)
106840 &ssi_private->cpu_dai_drv, 1);
106841 if (ret) {
106842 dev_err(&pdev->dev, "failed to register DAI: %d\n", ret);
106843 - goto error_dev;
106844 + goto error_clk;
106845 }
106846
106847 ret = fsl_ssi_debugfs_create(ssi_private, &pdev->dev);
106848 @@ -1562,9 +1561,6 @@ error_pcm:
106849 error_dbgfs:
106850 snd_soc_unregister_component(&pdev->dev);
106851
106852 -error_dev:
106853 - device_remove_file(&pdev->dev, dev_attr);
106854 -
106855 error_clk:
106856 if (ssi_private->ssi_on_imx) {
106857 if (!IS_ERR(ssi_private->baudclk))
106858 diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
106859 index 051c006..70598e8 100644
106860 --- a/sound/soc/soc-core.c
106861 +++ b/sound/soc/soc-core.c
106862 @@ -2255,8 +2255,10 @@ int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
106863 if (ret)
106864 return ret;
106865
106866 - ops->warm_reset = snd_soc_ac97_warm_reset;
106867 - ops->reset = snd_soc_ac97_reset;
106868 + pax_open_kernel();
106869 + *(void **)&ops->warm_reset = snd_soc_ac97_warm_reset;
106870 + *(void **)&ops->reset = snd_soc_ac97_reset;
106871 + pax_close_kernel();
106872
106873 snd_ac97_rst_cfg = cfg;
106874 return 0;
106875 diff --git a/sound/synth/emux/emux_seq.c b/sound/synth/emux/emux_seq.c
106876 index 7778b8e..3d619fc 100644
106877 --- a/sound/synth/emux/emux_seq.c
106878 +++ b/sound/synth/emux/emux_seq.c
106879 @@ -33,13 +33,13 @@ static int snd_emux_unuse(void *private_data, struct snd_seq_port_subscribe *inf
106880 * MIDI emulation operators
106881 */
106882 static struct snd_midi_op emux_ops = {
106883 - snd_emux_note_on,
106884 - snd_emux_note_off,
106885 - snd_emux_key_press,
106886 - snd_emux_terminate_note,
106887 - snd_emux_control,
106888 - snd_emux_nrpn,
106889 - snd_emux_sysex,
106890 + .note_on = snd_emux_note_on,
106891 + .note_off = snd_emux_note_off,
106892 + .key_press = snd_emux_key_press,
106893 + .note_terminate = snd_emux_terminate_note,
106894 + .control = snd_emux_control,
106895 + .nrpn = snd_emux_nrpn,
106896 + .sysex = snd_emux_sysex,
106897 };
106898
106899
106900 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
106901 new file mode 100644
106902 index 0000000..7b8921f
106903 --- /dev/null
106904 +++ b/tools/gcc/Makefile
106905 @@ -0,0 +1,52 @@
106906 +#CC := gcc
106907 +#PLUGIN_SOURCE_FILES := pax_plugin.c
106908 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
106909 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
106910 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
106911 +
106912 +ifeq ($(PLUGINCC),$(HOSTCC))
106913 +HOSTLIBS := hostlibs
106914 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(src) -std=gnu99 -ggdb
106915 +export HOST_EXTRACFLAGS
106916 +else
106917 +HOSTLIBS := hostcxxlibs
106918 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(src) -std=gnu++98 -fno-rtti -ggdb -Wno-unused-parameter -Wno-narrowing -Wno-unused-variable
106919 +export HOST_EXTRACXXFLAGS
106920 +endif
106921 +
106922 +export GCCPLUGINS_DIR HOSTLIBS
106923 +
106924 +$(HOSTLIBS)-$(CONFIG_PAX_CONSTIFY_PLUGIN) := constify_plugin.so
106925 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
106926 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
106927 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
106928 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
106929 +$(HOSTLIBS)-y += colorize_plugin.so
106930 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
106931 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STRUCTLEAK) += structleak_plugin.so
106932 +$(HOSTLIBS)-$(CONFIG_GRKERNSEC_RANDSTRUCT) += randomize_layout_plugin.so
106933 +
106934 +subdir-$(CONFIG_PAX_SIZE_OVERFLOW) := size_overflow_plugin
106935 +subdir- += size_overflow_plugin
106936 +
106937 +always := $($(HOSTLIBS)-y)
106938 +
106939 +constify_plugin-objs := constify_plugin.o
106940 +stackleak_plugin-objs := stackleak_plugin.o
106941 +kallocstat_plugin-objs := kallocstat_plugin.o
106942 +kernexec_plugin-objs := kernexec_plugin.o
106943 +checker_plugin-objs := checker_plugin.o
106944 +colorize_plugin-objs := colorize_plugin.o
106945 +latent_entropy_plugin-objs := latent_entropy_plugin.o
106946 +structleak_plugin-objs := structleak_plugin.o
106947 +randomize_layout_plugin-objs := randomize_layout_plugin.o
106948 +
106949 +$(obj)/randomize_layout_plugin.o: $(objtree)/$(obj)/randomize_layout_seed.h
106950 +
106951 +quiet_cmd_create_randomize_layout_seed = GENSEED $@
106952 + cmd_create_randomize_layout_seed = \
106953 + $(CONFIG_SHELL) $(srctree)/$(src)/gen-random-seed.sh $@ $(objtree)/include/generated/randomize_layout_hash.h
106954 +$(objtree)/$(obj)/randomize_layout_seed.h: FORCE
106955 + $(call if_changed,create_randomize_layout_seed)
106956 +
106957 +targets += randomize_layout_seed.h randomize_layout_hash.h
106958 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
106959 new file mode 100644
106960 index 0000000..5452feea
106961 --- /dev/null
106962 +++ b/tools/gcc/checker_plugin.c
106963 @@ -0,0 +1,150 @@
106964 +/*
106965 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
106966 + * Licensed under the GPL v2
106967 + *
106968 + * Note: the choice of the license means that the compilation process is
106969 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
106970 + * but for the kernel it doesn't matter since it doesn't link against
106971 + * any of the gcc libraries
106972 + *
106973 + * gcc plugin to implement various sparse (source code checker) features
106974 + *
106975 + * TODO:
106976 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
106977 + *
106978 + * BUGS:
106979 + * - none known
106980 + */
106981 +
106982 +#include "gcc-common.h"
106983 +
106984 +extern void c_register_addr_space (const char *str, addr_space_t as);
106985 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
106986 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
106987 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
106988 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
106989 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
106990 +
106991 +int plugin_is_GPL_compatible;
106992 +
106993 +static struct plugin_info checker_plugin_info = {
106994 + .version = "201304082245",
106995 + .help = NULL,
106996 +};
106997 +
106998 +#define ADDR_SPACE_KERNEL 0
106999 +#define ADDR_SPACE_FORCE_KERNEL 1
107000 +#define ADDR_SPACE_USER 2
107001 +#define ADDR_SPACE_FORCE_USER 3
107002 +#define ADDR_SPACE_IOMEM 0
107003 +#define ADDR_SPACE_FORCE_IOMEM 0
107004 +#define ADDR_SPACE_PERCPU 0
107005 +#define ADDR_SPACE_FORCE_PERCPU 0
107006 +#define ADDR_SPACE_RCU 0
107007 +#define ADDR_SPACE_FORCE_RCU 0
107008 +
107009 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
107010 +{
107011 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
107012 +}
107013 +
107014 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
107015 +{
107016 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
107017 +}
107018 +
107019 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
107020 +{
107021 + return default_addr_space_valid_pointer_mode(mode, as);
107022 +}
107023 +
107024 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
107025 +{
107026 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
107027 +}
107028 +
107029 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
107030 +{
107031 + return default_addr_space_legitimize_address(x, oldx, mode, as);
107032 +}
107033 +
107034 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
107035 +{
107036 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
107037 + return true;
107038 +
107039 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
107040 + return true;
107041 +
107042 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
107043 + return true;
107044 +
107045 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
107046 + return true;
107047 +
107048 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
107049 + return true;
107050 +
107051 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
107052 + return true;
107053 +
107054 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
107055 + return true;
107056 +
107057 + return subset == superset;
107058 +}
107059 +
107060 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
107061 +{
107062 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
107063 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
107064 +
107065 + return op;
107066 +}
107067 +
107068 +static void register_checker_address_spaces(void *event_data, void *data)
107069 +{
107070 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
107071 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
107072 + c_register_addr_space("__user", ADDR_SPACE_USER);
107073 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
107074 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
107075 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
107076 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
107077 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
107078 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
107079 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
107080 +
107081 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
107082 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
107083 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
107084 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
107085 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
107086 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
107087 + targetm.addr_space.convert = checker_addr_space_convert;
107088 +}
107089 +
107090 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
107091 +{
107092 + const char * const plugin_name = plugin_info->base_name;
107093 + const int argc = plugin_info->argc;
107094 + const struct plugin_argument * const argv = plugin_info->argv;
107095 + int i;
107096 +
107097 + if (!plugin_default_version_check(version, &gcc_version)) {
107098 + error(G_("incompatible gcc/plugin versions"));
107099 + return 1;
107100 + }
107101 +
107102 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
107103 +
107104 + for (i = 0; i < argc; ++i)
107105 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
107106 +
107107 + if (TARGET_64BIT == 0)
107108 + return 0;
107109 +
107110 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
107111 +
107112 + return 0;
107113 +}
107114 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
107115 new file mode 100644
107116 index 0000000..54461af
107117 --- /dev/null
107118 +++ b/tools/gcc/colorize_plugin.c
107119 @@ -0,0 +1,210 @@
107120 +/*
107121 + * Copyright 2012-2014 by PaX Team <pageexec@freemail.hu>
107122 + * Licensed under the GPL v2
107123 + *
107124 + * Note: the choice of the license means that the compilation process is
107125 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
107126 + * but for the kernel it doesn't matter since it doesn't link against
107127 + * any of the gcc libraries
107128 + *
107129 + * gcc plugin to colorize diagnostic output
107130 + *
107131 + */
107132 +
107133 +#include "gcc-common.h"
107134 +
107135 +int plugin_is_GPL_compatible;
107136 +
107137 +static struct plugin_info colorize_plugin_info = {
107138 + .version = "201404202350",
107139 + .help = "color=[never|always|auto]\tdetermine when to colorize\n",
107140 +};
107141 +
107142 +#define GREEN "\033[32m\033[K"
107143 +#define LIGHTGREEN "\033[1;32m\033[K"
107144 +#define YELLOW "\033[33m\033[K"
107145 +#define LIGHTYELLOW "\033[1;33m\033[K"
107146 +#define RED "\033[31m\033[K"
107147 +#define LIGHTRED "\033[1;31m\033[K"
107148 +#define BLUE "\033[34m\033[K"
107149 +#define LIGHTBLUE "\033[1;34m\033[K"
107150 +#define BRIGHT "\033[1;m\033[K"
107151 +#define NORMAL "\033[m\033[K"
107152 +
107153 +static diagnostic_starter_fn old_starter;
107154 +static diagnostic_finalizer_fn old_finalizer;
107155 +
107156 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
107157 +{
107158 + const char *color;
107159 + char *newprefix;
107160 +
107161 + switch (diagnostic->kind) {
107162 + case DK_NOTE:
107163 + color = LIGHTBLUE;
107164 + break;
107165 +
107166 + case DK_PEDWARN:
107167 + case DK_WARNING:
107168 + color = LIGHTYELLOW;
107169 + break;
107170 +
107171 + case DK_ERROR:
107172 + case DK_FATAL:
107173 + case DK_ICE:
107174 + case DK_PERMERROR:
107175 + case DK_SORRY:
107176 + color = LIGHTRED;
107177 + break;
107178 +
107179 + default:
107180 + color = NORMAL;
107181 + }
107182 +
107183 + old_starter(context, diagnostic);
107184 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
107185 + return;
107186 + pp_destroy_prefix(context->printer);
107187 + pp_set_prefix(context->printer, newprefix);
107188 +}
107189 +
107190 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
107191 +{
107192 + old_finalizer(context, diagnostic);
107193 +}
107194 +
107195 +static void colorize_arm(void)
107196 +{
107197 + old_starter = diagnostic_starter(global_dc);
107198 + old_finalizer = diagnostic_finalizer(global_dc);
107199 +
107200 + diagnostic_starter(global_dc) = start_colorize;
107201 + diagnostic_finalizer(global_dc) = finalize_colorize;
107202 +}
107203 +
107204 +static unsigned int execute_colorize_rearm(void)
107205 +{
107206 + if (diagnostic_starter(global_dc) == start_colorize)
107207 + return 0;
107208 +
107209 + colorize_arm();
107210 + return 0;
107211 +}
107212 +
107213 +#if BUILDING_GCC_VERSION >= 4009
107214 +static const struct pass_data colorize_rearm_pass_data = {
107215 +#else
107216 +struct simple_ipa_opt_pass colorize_rearm_pass = {
107217 + .pass = {
107218 +#endif
107219 + .type = SIMPLE_IPA_PASS,
107220 + .name = "colorize_rearm",
107221 +#if BUILDING_GCC_VERSION >= 4008
107222 + .optinfo_flags = OPTGROUP_NONE,
107223 +#endif
107224 +#if BUILDING_GCC_VERSION >= 4009
107225 + .has_gate = false,
107226 + .has_execute = true,
107227 +#else
107228 + .gate = NULL,
107229 + .execute = execute_colorize_rearm,
107230 + .sub = NULL,
107231 + .next = NULL,
107232 + .static_pass_number = 0,
107233 +#endif
107234 + .tv_id = TV_NONE,
107235 + .properties_required = 0,
107236 + .properties_provided = 0,
107237 + .properties_destroyed = 0,
107238 + .todo_flags_start = 0,
107239 + .todo_flags_finish = 0
107240 +#if BUILDING_GCC_VERSION < 4009
107241 + }
107242 +#endif
107243 +};
107244 +
107245 +#if BUILDING_GCC_VERSION >= 4009
107246 +namespace {
107247 +class colorize_rearm_pass : public simple_ipa_opt_pass {
107248 +public:
107249 + colorize_rearm_pass() : simple_ipa_opt_pass(colorize_rearm_pass_data, g) {}
107250 + unsigned int execute() { return execute_colorize_rearm(); }
107251 +};
107252 +}
107253 +
107254 +static opt_pass *make_colorize_rearm_pass(void)
107255 +{
107256 + return new colorize_rearm_pass();
107257 +}
107258 +#else
107259 +static struct opt_pass *make_colorize_rearm_pass(void)
107260 +{
107261 + return &colorize_rearm_pass.pass;
107262 +}
107263 +#endif
107264 +
107265 +static void colorize_start_unit(void *gcc_data, void *user_data)
107266 +{
107267 + colorize_arm();
107268 +}
107269 +
107270 +static bool should_colorize(void)
107271 +{
107272 +#if BUILDING_GCC_VERSION >= 4009
107273 + return false;
107274 +#else
107275 + char const *t = getenv("TERM");
107276 +
107277 + return t && strcmp(t, "dumb") && isatty(STDERR_FILENO);
107278 +#endif
107279 +}
107280 +
107281 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
107282 +{
107283 + const char * const plugin_name = plugin_info->base_name;
107284 + const int argc = plugin_info->argc;
107285 + const struct plugin_argument * const argv = plugin_info->argv;
107286 + int i;
107287 + struct register_pass_info colorize_rearm_pass_info;
107288 + bool colorize;
107289 +
107290 + colorize_rearm_pass_info.pass = make_colorize_rearm_pass();
107291 + colorize_rearm_pass_info.reference_pass_name = "*free_lang_data";
107292 + colorize_rearm_pass_info.ref_pass_instance_number = 1;
107293 + colorize_rearm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
107294 +
107295 + if (!plugin_default_version_check(version, &gcc_version)) {
107296 + error(G_("incompatible gcc/plugin versions"));
107297 + return 1;
107298 + }
107299 +
107300 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
107301 +
107302 + colorize = getenv("GCC_COLORS") ? should_colorize() : false;
107303 +
107304 + for (i = 0; i < argc; ++i) {
107305 + if (!strcmp(argv[i].key, "color")) {
107306 + if (!argv[i].value) {
107307 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
107308 + continue;
107309 + }
107310 + if (!strcmp(argv[i].value, "always"))
107311 + colorize = true;
107312 + else if (!strcmp(argv[i].value, "never"))
107313 + colorize = false;
107314 + else if (!strcmp(argv[i].value, "auto"))
107315 + colorize = should_colorize();
107316 + else
107317 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
107318 + continue;
107319 + }
107320 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
107321 + }
107322 +
107323 + if (colorize) {
107324 + // TODO: parse GCC_COLORS as used by gcc 4.9+
107325 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
107326 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
107327 + }
107328 + return 0;
107329 +}
107330 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
107331 new file mode 100644
107332 index 0000000..82bc5a8
107333 --- /dev/null
107334 +++ b/tools/gcc/constify_plugin.c
107335 @@ -0,0 +1,557 @@
107336 +/*
107337 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
107338 + * Copyright 2011-2014 by PaX Team <pageexec@freemail.hu>
107339 + * Licensed under the GPL v2, or (at your option) v3
107340 + *
107341 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
107342 + *
107343 + * Homepage:
107344 + * http://www.grsecurity.net/~ephox/const_plugin/
107345 + *
107346 + * Usage:
107347 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
107348 + * $ gcc -fplugin=constify_plugin.so test.c -O2
107349 + */
107350 +
107351 +#include "gcc-common.h"
107352 +
107353 +// unused C type flag in all versions 4.5-4.9
107354 +#define TYPE_CONSTIFY_VISITED(TYPE) TYPE_LANG_FLAG_4(TYPE)
107355 +
107356 +int plugin_is_GPL_compatible;
107357 +
107358 +static struct plugin_info const_plugin_info = {
107359 + .version = "201401270210",
107360 + .help = "no-constify\tturn off constification\n",
107361 +};
107362 +
107363 +typedef struct {
107364 + bool has_fptr_field;
107365 + bool has_writable_field;
107366 + bool has_do_const_field;
107367 + bool has_no_const_field;
107368 +} constify_info;
107369 +
107370 +static const_tree get_field_type(const_tree field)
107371 +{
107372 + return strip_array_types(TREE_TYPE(field));
107373 +}
107374 +
107375 +static bool is_fptr(const_tree field)
107376 +{
107377 + const_tree ptr = get_field_type(field);
107378 +
107379 + if (TREE_CODE(ptr) != POINTER_TYPE)
107380 + return false;
107381 +
107382 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
107383 +}
107384 +
107385 +/*
107386 + * determine whether the given structure type meets the requirements for automatic constification,
107387 + * including the constification attributes on nested structure types
107388 + */
107389 +static void constifiable(const_tree node, constify_info *cinfo)
107390 +{
107391 + const_tree field;
107392 +
107393 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
107394 +
107395 + // e.g., pointer to structure fields while still constructing the structure type
107396 + if (TYPE_FIELDS(node) == NULL_TREE)
107397 + return;
107398 +
107399 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
107400 + const_tree type = get_field_type(field);
107401 + enum tree_code code = TREE_CODE(type);
107402 +
107403 + if (node == type)
107404 + continue;
107405 +
107406 + if (is_fptr(field))
107407 + cinfo->has_fptr_field = true;
107408 + else if (!TREE_READONLY(field))
107409 + cinfo->has_writable_field = true;
107410 +
107411 + if (code == RECORD_TYPE || code == UNION_TYPE) {
107412 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
107413 + cinfo->has_do_const_field = true;
107414 + else if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
107415 + cinfo->has_no_const_field = true;
107416 + else
107417 + constifiable(type, cinfo);
107418 + }
107419 + }
107420 +}
107421 +
107422 +static bool constified(const_tree node)
107423 +{
107424 + constify_info cinfo = {
107425 + .has_fptr_field = false,
107426 + .has_writable_field = false,
107427 + .has_do_const_field = false,
107428 + .has_no_const_field = false
107429 + };
107430 +
107431 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
107432 +
107433 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
107434 +// gcc_assert(!TYPE_READONLY(node));
107435 + return false;
107436 + }
107437 +
107438 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(node))) {
107439 + gcc_assert(TYPE_READONLY(node));
107440 + return true;
107441 + }
107442 +
107443 + constifiable(node, &cinfo);
107444 + if ((!cinfo.has_fptr_field || cinfo.has_writable_field) && !cinfo.has_do_const_field)
107445 + return false;
107446 +
107447 + return TYPE_READONLY(node);
107448 +}
107449 +
107450 +static void deconstify_tree(tree node);
107451 +
107452 +static void deconstify_type(tree type)
107453 +{
107454 + tree field;
107455 +
107456 + gcc_assert(TREE_CODE(type) == RECORD_TYPE || TREE_CODE(type) == UNION_TYPE);
107457 +
107458 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
107459 + const_tree fieldtype = get_field_type(field);
107460 +
107461 + // special case handling of simple ptr-to-same-array-type members
107462 + if (TREE_CODE(TREE_TYPE(field)) == POINTER_TYPE) {
107463 + tree ptrtype = TREE_TYPE(TREE_TYPE(field));
107464 +
107465 + if (TREE_TYPE(TREE_TYPE(field)) == type)
107466 + continue;
107467 + if (TREE_CODE(ptrtype) != RECORD_TYPE && TREE_CODE(ptrtype) != UNION_TYPE)
107468 + continue;
107469 + if (!constified(ptrtype))
107470 + continue;
107471 + if (TYPE_MAIN_VARIANT(ptrtype) == TYPE_MAIN_VARIANT(type)) {
107472 + TREE_TYPE(field) = copy_node(TREE_TYPE(field));
107473 + TREE_TYPE(TREE_TYPE(field)) = build_qualified_type(type, TYPE_QUALS(ptrtype) & ~TYPE_QUAL_CONST);
107474 + }
107475 + continue;
107476 + }
107477 + if (TREE_CODE(fieldtype) != RECORD_TYPE && TREE_CODE(fieldtype) != UNION_TYPE)
107478 + continue;
107479 + if (!constified(fieldtype))
107480 + continue;
107481 +
107482 + deconstify_tree(field);
107483 + TREE_READONLY(field) = 0;
107484 + }
107485 + TYPE_READONLY(type) = 0;
107486 + C_TYPE_FIELDS_READONLY(type) = 0;
107487 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
107488 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
107489 + TYPE_ATTRIBUTES(type) = remove_attribute("do_const", TYPE_ATTRIBUTES(type));
107490 + }
107491 +}
107492 +
107493 +static void deconstify_tree(tree node)
107494 +{
107495 + tree old_type, new_type, field;
107496 +
107497 + old_type = TREE_TYPE(node);
107498 + while (TREE_CODE(old_type) == ARRAY_TYPE && TREE_CODE(TREE_TYPE(old_type)) != ARRAY_TYPE) {
107499 + node = TREE_TYPE(node) = copy_node(old_type);
107500 + old_type = TREE_TYPE(old_type);
107501 + }
107502 +
107503 + gcc_assert(TREE_CODE(old_type) == RECORD_TYPE || TREE_CODE(old_type) == UNION_TYPE);
107504 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
107505 +
107506 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
107507 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
107508 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
107509 + DECL_FIELD_CONTEXT(field) = new_type;
107510 +
107511 + deconstify_type(new_type);
107512 +
107513 + TREE_TYPE(node) = new_type;
107514 +}
107515 +
107516 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
107517 +{
107518 + tree type;
107519 + constify_info cinfo = {
107520 + .has_fptr_field = false,
107521 + .has_writable_field = false,
107522 + .has_do_const_field = false,
107523 + .has_no_const_field = false
107524 + };
107525 +
107526 + *no_add_attrs = true;
107527 + if (TREE_CODE(*node) == FUNCTION_DECL) {
107528 + error("%qE attribute does not apply to functions (%qF)", name, *node);
107529 + return NULL_TREE;
107530 + }
107531 +
107532 + if (TREE_CODE(*node) == PARM_DECL) {
107533 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
107534 + return NULL_TREE;
107535 + }
107536 +
107537 + if (TREE_CODE(*node) == VAR_DECL) {
107538 + error("%qE attribute does not apply to variables (%qD)", name, *node);
107539 + return NULL_TREE;
107540 + }
107541 +
107542 + if (TYPE_P(*node)) {
107543 + type = *node;
107544 + } else {
107545 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
107546 + type = TREE_TYPE(*node);
107547 + }
107548 +
107549 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
107550 + error("%qE attribute used on %qT applies to struct and union types only", name, type);
107551 + return NULL_TREE;
107552 + }
107553 +
107554 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
107555 + error("%qE attribute is already applied to the type %qT", name, type);
107556 + return NULL_TREE;
107557 + }
107558 +
107559 + if (TYPE_P(*node)) {
107560 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
107561 + error("%qE attribute used on type %qT is incompatible with 'do_const'", name, type);
107562 + else
107563 + *no_add_attrs = false;
107564 + return NULL_TREE;
107565 + }
107566 +
107567 + constifiable(type, &cinfo);
107568 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
107569 + deconstify_tree(*node);
107570 + TYPE_CONSTIFY_VISITED(TREE_TYPE(*node)) = 1;
107571 + return NULL_TREE;
107572 + }
107573 +
107574 + error("%qE attribute used on type %qT that is not constified", name, type);
107575 + return NULL_TREE;
107576 +}
107577 +
107578 +static void constify_type(tree type)
107579 +{
107580 + TYPE_READONLY(type) = 1;
107581 + C_TYPE_FIELDS_READONLY(type) = 1;
107582 + TYPE_CONSTIFY_VISITED(type) = 1;
107583 +// TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
107584 +// TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("do_const"), NULL_TREE, TYPE_ATTRIBUTES(type));
107585 +}
107586 +
107587 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
107588 +{
107589 + *no_add_attrs = true;
107590 + if (!TYPE_P(*node)) {
107591 + error("%qE attribute applies to types only (%qD)", name, *node);
107592 + return NULL_TREE;
107593 + }
107594 +
107595 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
107596 + error("%qE attribute used on %qT applies to struct and union types only", name, *node);
107597 + return NULL_TREE;
107598 + }
107599 +
107600 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(*node))) {
107601 + error("%qE attribute used on %qT is already applied to the type", name, *node);
107602 + return NULL_TREE;
107603 + }
107604 +
107605 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(*node))) {
107606 + error("%qE attribute used on %qT is incompatible with 'no_const'", name, *node);
107607 + return NULL_TREE;
107608 + }
107609 +
107610 + *no_add_attrs = false;
107611 + return NULL_TREE;
107612 +}
107613 +
107614 +static struct attribute_spec no_const_attr = {
107615 + .name = "no_const",
107616 + .min_length = 0,
107617 + .max_length = 0,
107618 + .decl_required = false,
107619 + .type_required = false,
107620 + .function_type_required = false,
107621 + .handler = handle_no_const_attribute,
107622 +#if BUILDING_GCC_VERSION >= 4007
107623 + .affects_type_identity = true
107624 +#endif
107625 +};
107626 +
107627 +static struct attribute_spec do_const_attr = {
107628 + .name = "do_const",
107629 + .min_length = 0,
107630 + .max_length = 0,
107631 + .decl_required = false,
107632 + .type_required = false,
107633 + .function_type_required = false,
107634 + .handler = handle_do_const_attribute,
107635 +#if BUILDING_GCC_VERSION >= 4007
107636 + .affects_type_identity = true
107637 +#endif
107638 +};
107639 +
107640 +static void register_attributes(void *event_data, void *data)
107641 +{
107642 + register_attribute(&no_const_attr);
107643 + register_attribute(&do_const_attr);
107644 +}
107645 +
107646 +static void finish_type(void *event_data, void *data)
107647 +{
107648 + tree type = (tree)event_data;
107649 + constify_info cinfo = {
107650 + .has_fptr_field = false,
107651 + .has_writable_field = false,
107652 + .has_do_const_field = false,
107653 + .has_no_const_field = false
107654 + };
107655 +
107656 + if (type == NULL_TREE || type == error_mark_node)
107657 + return;
107658 +
107659 + if (TYPE_FIELDS(type) == NULL_TREE || TYPE_CONSTIFY_VISITED(type))
107660 + return;
107661 +
107662 + constifiable(type, &cinfo);
107663 +
107664 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type))) {
107665 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || cinfo.has_do_const_field) {
107666 + deconstify_type(type);
107667 + TYPE_CONSTIFY_VISITED(type) = 1;
107668 + } else
107669 + error("'no_const' attribute used on type %qT that is not constified", type);
107670 + return;
107671 + }
107672 +
107673 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
107674 + if (!cinfo.has_writable_field) {
107675 + error("'do_const' attribute used on type %qT that is%sconstified", type, cinfo.has_fptr_field ? " " : " not ");
107676 + return;
107677 + }
107678 + constify_type(type);
107679 + return;
107680 + }
107681 +
107682 + if (cinfo.has_fptr_field && !cinfo.has_writable_field) {
107683 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
107684 + error("'do_const' attribute used on type %qT that is constified", type);
107685 + return;
107686 + }
107687 + constify_type(type);
107688 + return;
107689 + }
107690 +
107691 + deconstify_type(type);
107692 + TYPE_CONSTIFY_VISITED(type) = 1;
107693 +}
107694 +
107695 +static void check_global_variables(void *event_data, void *data)
107696 +{
107697 +#if BUILDING_GCC_VERSION >= 4009
107698 + varpool_node *node;
107699 +#else
107700 + struct varpool_node *node;
107701 +#endif
107702 +
107703 + FOR_EACH_VARIABLE(node) {
107704 + tree var = NODE_DECL(node);
107705 + tree type = TREE_TYPE(var);
107706 +
107707 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
107708 + continue;
107709 +
107710 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
107711 + continue;
107712 +
107713 + if (!TYPE_CONSTIFY_VISITED(type))
107714 + continue;
107715 +
107716 + if (DECL_EXTERNAL(var))
107717 + continue;
107718 +
107719 + if (DECL_INITIAL(var))
107720 + continue;
107721 +
107722 + // this works around a gcc bug/feature where uninitialized globals
107723 + // are moved into the .bss section regardless of any constification
107724 + DECL_INITIAL(var) = build_constructor(type, NULL);
107725 +// inform(DECL_SOURCE_LOCATION(var), "constified variable %qE moved into .rodata", var);
107726 + }
107727 +}
107728 +
107729 +static unsigned int check_local_variables(void)
107730 +{
107731 + unsigned int ret = 0;
107732 + tree var;
107733 +
107734 + unsigned int i;
107735 +
107736 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
107737 + tree type = TREE_TYPE(var);
107738 +
107739 + gcc_assert(DECL_P(var));
107740 + if (is_global_var(var))
107741 + continue;
107742 +
107743 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
107744 + continue;
107745 +
107746 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
107747 + continue;
107748 +
107749 + if (!TYPE_CONSTIFY_VISITED(type))
107750 + continue;
107751 +
107752 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
107753 + ret = 1;
107754 + }
107755 + return ret;
107756 +}
107757 +
107758 +#if BUILDING_GCC_VERSION >= 4009
107759 +static const struct pass_data check_local_variables_pass_data = {
107760 +#else
107761 +static struct gimple_opt_pass check_local_variables_pass = {
107762 + .pass = {
107763 +#endif
107764 + .type = GIMPLE_PASS,
107765 + .name = "check_local_variables",
107766 +#if BUILDING_GCC_VERSION >= 4008
107767 + .optinfo_flags = OPTGROUP_NONE,
107768 +#endif
107769 +#if BUILDING_GCC_VERSION >= 4009
107770 + .has_gate = false,
107771 + .has_execute = true,
107772 +#else
107773 + .gate = NULL,
107774 + .execute = check_local_variables,
107775 + .sub = NULL,
107776 + .next = NULL,
107777 + .static_pass_number = 0,
107778 +#endif
107779 + .tv_id = TV_NONE,
107780 + .properties_required = 0,
107781 + .properties_provided = 0,
107782 + .properties_destroyed = 0,
107783 + .todo_flags_start = 0,
107784 + .todo_flags_finish = 0
107785 +#if BUILDING_GCC_VERSION < 4009
107786 + }
107787 +#endif
107788 +};
107789 +
107790 +#if BUILDING_GCC_VERSION >= 4009
107791 +namespace {
107792 +class check_local_variables_pass : public gimple_opt_pass {
107793 +public:
107794 + check_local_variables_pass() : gimple_opt_pass(check_local_variables_pass_data, g) {}
107795 + unsigned int execute() { return check_local_variables(); }
107796 +};
107797 +}
107798 +
107799 +static opt_pass *make_check_local_variables_pass(void)
107800 +{
107801 + return new check_local_variables_pass();
107802 +}
107803 +#else
107804 +static struct opt_pass *make_check_local_variables_pass(void)
107805 +{
107806 + return &check_local_variables_pass.pass;
107807 +}
107808 +#endif
107809 +
107810 +static struct {
107811 + const char *name;
107812 + const char *asm_op;
107813 +} sections[] = {
107814 + {".init.rodata", "\t.section\t.init.rodata,\"a\""},
107815 + {".ref.rodata", "\t.section\t.ref.rodata,\"a\""},
107816 + {".devinit.rodata", "\t.section\t.devinit.rodata,\"a\""},
107817 + {".devexit.rodata", "\t.section\t.devexit.rodata,\"a\""},
107818 + {".cpuinit.rodata", "\t.section\t.cpuinit.rodata,\"a\""},
107819 + {".cpuexit.rodata", "\t.section\t.cpuexit.rodata,\"a\""},
107820 + {".meminit.rodata", "\t.section\t.meminit.rodata,\"a\""},
107821 + {".memexit.rodata", "\t.section\t.memexit.rodata,\"a\""},
107822 + {".data..read_only", "\t.section\t.data..read_only,\"a\""},
107823 +};
107824 +
107825 +static unsigned int (*old_section_type_flags)(tree decl, const char *name, int reloc);
107826 +
107827 +static unsigned int constify_section_type_flags(tree decl, const char *name, int reloc)
107828 +{
107829 + size_t i;
107830 +
107831 + for (i = 0; i < ARRAY_SIZE(sections); i++)
107832 + if (!strcmp(sections[i].name, name))
107833 + return 0;
107834 + return old_section_type_flags(decl, name, reloc);
107835 +}
107836 +
107837 +static void constify_start_unit(void *gcc_data, void *user_data)
107838 +{
107839 +// size_t i;
107840 +
107841 +// for (i = 0; i < ARRAY_SIZE(sections); i++)
107842 +// sections[i].section = get_unnamed_section(0, output_section_asm_op, sections[i].asm_op);
107843 +// sections[i].section = get_section(sections[i].name, 0, NULL);
107844 +
107845 + old_section_type_flags = targetm.section_type_flags;
107846 + targetm.section_type_flags = constify_section_type_flags;
107847 +}
107848 +
107849 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
107850 +{
107851 + const char * const plugin_name = plugin_info->base_name;
107852 + const int argc = plugin_info->argc;
107853 + const struct plugin_argument * const argv = plugin_info->argv;
107854 + int i;
107855 + bool constify = true;
107856 +
107857 + struct register_pass_info check_local_variables_pass_info;
107858 +
107859 + check_local_variables_pass_info.pass = make_check_local_variables_pass();
107860 + check_local_variables_pass_info.reference_pass_name = "ssa";
107861 + check_local_variables_pass_info.ref_pass_instance_number = 1;
107862 + check_local_variables_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
107863 +
107864 + if (!plugin_default_version_check(version, &gcc_version)) {
107865 + error(G_("incompatible gcc/plugin versions"));
107866 + return 1;
107867 + }
107868 +
107869 + for (i = 0; i < argc; ++i) {
107870 + if (!(strcmp(argv[i].key, "no-constify"))) {
107871 + constify = false;
107872 + continue;
107873 + }
107874 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
107875 + }
107876 +
107877 + if (strcmp(lang_hooks.name, "GNU C")) {
107878 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
107879 + constify = false;
107880 + }
107881 +
107882 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
107883 + if (constify) {
107884 + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
107885 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
107886 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &check_local_variables_pass_info);
107887 + register_callback(plugin_name, PLUGIN_START_UNIT, constify_start_unit, NULL);
107888 + }
107889 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
107890 +
107891 + return 0;
107892 +}
107893 diff --git a/tools/gcc/gcc-common.h b/tools/gcc/gcc-common.h
107894 new file mode 100644
107895 index 0000000..e90c205
107896 --- /dev/null
107897 +++ b/tools/gcc/gcc-common.h
107898 @@ -0,0 +1,295 @@
107899 +#ifndef GCC_COMMON_H_INCLUDED
107900 +#define GCC_COMMON_H_INCLUDED
107901 +
107902 +#include "plugin.h"
107903 +#include "bversion.h"
107904 +#include "plugin-version.h"
107905 +#include "config.h"
107906 +#include "system.h"
107907 +#include "coretypes.h"
107908 +#include "tm.h"
107909 +#include "line-map.h"
107910 +#include "input.h"
107911 +#include "tree.h"
107912 +
107913 +#include "tree-inline.h"
107914 +#include "version.h"
107915 +#include "rtl.h"
107916 +#include "tm_p.h"
107917 +#include "flags.h"
107918 +//#include "insn-attr.h"
107919 +//#include "insn-config.h"
107920 +//#include "insn-flags.h"
107921 +#include "hard-reg-set.h"
107922 +//#include "recog.h"
107923 +#include "output.h"
107924 +#include "except.h"
107925 +#include "function.h"
107926 +#include "toplev.h"
107927 +//#include "expr.h"
107928 +#include "basic-block.h"
107929 +#include "intl.h"
107930 +#include "ggc.h"
107931 +//#include "regs.h"
107932 +#include "timevar.h"
107933 +
107934 +#include "params.h"
107935 +#include "pointer-set.h"
107936 +#include "emit-rtl.h"
107937 +//#include "reload.h"
107938 +//#include "ira.h"
107939 +//#include "dwarf2asm.h"
107940 +#include "debug.h"
107941 +#include "target.h"
107942 +#include "langhooks.h"
107943 +#include "cfgloop.h"
107944 +//#include "hosthooks.h"
107945 +#include "cgraph.h"
107946 +#include "opts.h"
107947 +//#include "coverage.h"
107948 +//#include "value-prof.h"
107949 +
107950 +#if BUILDING_GCC_VERSION >= 4007
107951 +#include "tree-pretty-print.h"
107952 +#include "gimple-pretty-print.h"
107953 +#include "c-tree.h"
107954 +//#include "alloc-pool.h"
107955 +#endif
107956 +
107957 +#if BUILDING_GCC_VERSION <= 4008
107958 +#include "tree-flow.h"
107959 +#else
107960 +#include "tree-cfgcleanup.h"
107961 +#endif
107962 +
107963 +#include "diagnostic.h"
107964 +//#include "tree-diagnostic.h"
107965 +#include "tree-dump.h"
107966 +#include "tree-pass.h"
107967 +//#include "df.h"
107968 +#include "predict.h"
107969 +#include "ipa-utils.h"
107970 +
107971 +#if BUILDING_GCC_VERSION >= 4009
107972 +#include "varasm.h"
107973 +#include "stor-layout.h"
107974 +#include "internal-fn.h"
107975 +#include "gimple-expr.h"
107976 +//#include "diagnostic-color.h"
107977 +#include "context.h"
107978 +#include "tree-ssa-alias.h"
107979 +#include "stringpool.h"
107980 +#include "tree-ssanames.h"
107981 +#include "print-tree.h"
107982 +#include "tree-eh.h"
107983 +#include "stmt.h"
107984 +#endif
107985 +
107986 +#include "gimple.h"
107987 +
107988 +#if BUILDING_GCC_VERSION >= 4009
107989 +#include "tree-ssa-operands.h"
107990 +#include "tree-phinodes.h"
107991 +#include "tree-cfg.h"
107992 +#include "gimple-iterator.h"
107993 +#include "gimple-ssa.h"
107994 +#include "ssa-iterators.h"
107995 +#endif
107996 +
107997 +//#include "lto/lto.h"
107998 +//#include "data-streamer.h"
107999 +//#include "lto-compress.h"
108000 +
108001 +//#include "expr.h" where are you...
108002 +extern rtx emit_move_insn(rtx x, rtx y);
108003 +
108004 +// missing from basic_block.h...
108005 +extern void debug_dominance_info(enum cdi_direction dir);
108006 +extern void debug_dominance_tree(enum cdi_direction dir, basic_block root);
108007 +
108008 +#define __unused __attribute__((__unused__))
108009 +
108010 +#define DECL_NAME_POINTER(node) IDENTIFIER_POINTER(DECL_NAME(node))
108011 +#define DECL_NAME_LENGTH(node) IDENTIFIER_LENGTH(DECL_NAME(node))
108012 +#define TYPE_NAME_POINTER(node) IDENTIFIER_POINTER(TYPE_NAME(node))
108013 +#define TYPE_NAME_LENGTH(node) IDENTIFIER_LENGTH(TYPE_NAME(node))
108014 +
108015 +#if BUILDING_GCC_VERSION == 4005
108016 +#define FOR_EACH_LOCAL_DECL(FUN, I, D) for (tree vars = (FUN)->local_decls; vars && (D = TREE_VALUE(vars)); vars = TREE_CHAIN(vars), I)
108017 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
108018 +#define FOR_EACH_VEC_ELT(T, V, I, P) for (I = 0; VEC_iterate(T, (V), (I), (P)); ++(I))
108019 +#define TODO_rebuild_cgraph_edges 0
108020 +
108021 +static inline bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
108022 +{
108023 + tree fndecl;
108024 +
108025 + if (!is_gimple_call(stmt))
108026 + return false;
108027 + fndecl = gimple_call_fndecl(stmt);
108028 + if (!fndecl || DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
108029 + return false;
108030 +// print_node(stderr, "pax", fndecl, 4);
108031 + return DECL_FUNCTION_CODE(fndecl) == code;
108032 +}
108033 +
108034 +static inline bool is_simple_builtin(tree decl)
108035 +{
108036 + if (decl && DECL_BUILT_IN_CLASS(decl) != BUILT_IN_NORMAL)
108037 + return false;
108038 +
108039 + switch (DECL_FUNCTION_CODE(decl)) {
108040 + /* Builtins that expand to constants. */
108041 + case BUILT_IN_CONSTANT_P:
108042 + case BUILT_IN_EXPECT:
108043 + case BUILT_IN_OBJECT_SIZE:
108044 + case BUILT_IN_UNREACHABLE:
108045 + /* Simple register moves or loads from stack. */
108046 + case BUILT_IN_RETURN_ADDRESS:
108047 + case BUILT_IN_EXTRACT_RETURN_ADDR:
108048 + case BUILT_IN_FROB_RETURN_ADDR:
108049 + case BUILT_IN_RETURN:
108050 + case BUILT_IN_AGGREGATE_INCOMING_ADDRESS:
108051 + case BUILT_IN_FRAME_ADDRESS:
108052 + case BUILT_IN_VA_END:
108053 + case BUILT_IN_STACK_SAVE:
108054 + case BUILT_IN_STACK_RESTORE:
108055 + /* Exception state returns or moves registers around. */
108056 + case BUILT_IN_EH_FILTER:
108057 + case BUILT_IN_EH_POINTER:
108058 + case BUILT_IN_EH_COPY_VALUES:
108059 + return true;
108060 +
108061 + default:
108062 + return false;
108063 + }
108064 +}
108065 +#endif
108066 +
108067 +#if BUILDING_GCC_VERSION <= 4006
108068 +#define ANY_RETURN_P(rtx) (GET_CODE(rtx) == RETURN)
108069 +#define C_DECL_REGISTER(EXP) DECL_LANG_FLAG_4(EXP)
108070 +
108071 +// should come from c-tree.h if only it were installed for gcc 4.5...
108072 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
108073 +
108074 +#define get_random_seed(noinit) ({ \
108075 + unsigned HOST_WIDE_INT seed; \
108076 + sscanf(get_random_seed(noinit), "%" HOST_WIDE_INT_PRINT "x", &seed); \
108077 + seed * seed; })
108078 +
108079 +static inline bool gimple_clobber_p(gimple s)
108080 +{
108081 + return false;
108082 +}
108083 +
108084 +static inline tree builtin_decl_implicit(enum built_in_function fncode)
108085 +{
108086 + return implicit_built_in_decls[fncode];
108087 +}
108088 +
108089 +static inline struct cgraph_node *cgraph_get_create_node(tree decl)
108090 +{
108091 + struct cgraph_node *node = cgraph_get_node(decl);
108092 +
108093 + return node ? node : cgraph_node(decl);
108094 +}
108095 +
108096 +static inline bool cgraph_function_with_gimple_body_p(struct cgraph_node *node)
108097 +{
108098 + return node->analyzed && !node->thunk.thunk_p && !node->alias;
108099 +}
108100 +
108101 +static inline struct cgraph_node *cgraph_first_function_with_gimple_body(void)
108102 +{
108103 + struct cgraph_node *node;
108104 +
108105 + for (node = cgraph_nodes; node; node = node->next)
108106 + if (cgraph_function_with_gimple_body_p(node))
108107 + return node;
108108 + return NULL;
108109 +}
108110 +
108111 +static inline struct cgraph_node *cgraph_next_function_with_gimple_body(struct cgraph_node *node)
108112 +{
108113 + for (node = node->next; node; node = node->next)
108114 + if (cgraph_function_with_gimple_body_p(node))
108115 + return node;
108116 + return NULL;
108117 +}
108118 +
108119 +#define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
108120 + for ((node) = cgraph_first_function_with_gimple_body(); (node); \
108121 + (node) = cgraph_next_function_with_gimple_body(node))
108122 +#endif
108123 +
108124 +#if BUILDING_GCC_VERSION == 4006
108125 +extern void debug_gimple_stmt(gimple);
108126 +extern void debug_gimple_seq(gimple_seq);
108127 +extern void print_gimple_seq(FILE *, gimple_seq, int, int);
108128 +extern void print_gimple_stmt(FILE *, gimple, int, int);
108129 +extern void print_gimple_expr(FILE *, gimple, int, int);
108130 +extern void dump_gimple_stmt(pretty_printer *, gimple, int, int);
108131 +#endif
108132 +
108133 +#if BUILDING_GCC_VERSION <= 4007
108134 +#define FOR_EACH_VARIABLE(node) for (node = varpool_nodes; node; node = node->next)
108135 +#define PROP_loops 0
108136 +
108137 +static inline int bb_loop_depth(const_basic_block bb)
108138 +{
108139 + return bb->loop_father ? loop_depth(bb->loop_father) : 0;
108140 +}
108141 +
108142 +static inline bool gimple_store_p(gimple gs)
108143 +{
108144 + tree lhs = gimple_get_lhs(gs);
108145 + return lhs && !is_gimple_reg(lhs);
108146 +}
108147 +#endif
108148 +
108149 +#if BUILDING_GCC_VERSION >= 4007
108150 +#define cgraph_create_edge(caller, callee, call_stmt, count, freq, nest) \
108151 + cgraph_create_edge((caller), (callee), (call_stmt), (count), (freq))
108152 +#define cgraph_create_edge_including_clones(caller, callee, old_call_stmt, call_stmt, count, freq, nest, reason) \
108153 + cgraph_create_edge_including_clones((caller), (callee), (old_call_stmt), (call_stmt), (count), (freq), (reason))
108154 +#endif
108155 +
108156 +#if BUILDING_GCC_VERSION <= 4008
108157 +#define ENTRY_BLOCK_PTR_FOR_FN(FN) ENTRY_BLOCK_PTR_FOR_FUNCTION(FN)
108158 +#define EXIT_BLOCK_PTR_FOR_FN(FN) EXIT_BLOCK_PTR_FOR_FUNCTION(FN)
108159 +#define basic_block_info_for_fn(FN) ((FN)->cfg->x_basic_block_info)
108160 +#define n_basic_blocks_for_fn(FN) ((FN)->cfg->x_n_basic_blocks)
108161 +#define n_edges_for_fn(FN) ((FN)->cfg->x_n_edges)
108162 +#define last_basic_block_for_fn(FN) ((FN)->cfg->x_last_basic_block)
108163 +#define label_to_block_map_for_fn(FN) ((FN)->cfg->x_label_to_block_map)
108164 +#define profile_status_for_fn(FN) ((FN)->cfg->x_profile_status)
108165 +
108166 +static inline const char *get_tree_code_name(enum tree_code code)
108167 +{
108168 + gcc_assert(code < MAX_TREE_CODES);
108169 + return tree_code_name[code];
108170 +}
108171 +
108172 +#define ipa_remove_stmt_references(cnode, stmt)
108173 +#endif
108174 +
108175 +#if BUILDING_GCC_VERSION == 4008
108176 +#define NODE_DECL(node) node->symbol.decl
108177 +#else
108178 +#define NODE_DECL(node) node->decl
108179 +#endif
108180 +
108181 +#if BUILDING_GCC_VERSION >= 4008
108182 +#define add_referenced_var(var)
108183 +#define mark_sym_for_renaming(var)
108184 +#define varpool_mark_needed_node(node)
108185 +#define TODO_dump_func 0
108186 +#define TODO_dump_cgraph 0
108187 +#endif
108188 +
108189 +#if BUILDING_GCC_VERSION >= 4009
108190 +#define TODO_ggc_collect 0
108191 +#endif
108192 +
108193 +#endif
108194 diff --git a/tools/gcc/gen-random-seed.sh b/tools/gcc/gen-random-seed.sh
108195 new file mode 100644
108196 index 0000000..7514850
108197 --- /dev/null
108198 +++ b/tools/gcc/gen-random-seed.sh
108199 @@ -0,0 +1,8 @@
108200 +#!/bin/sh
108201 +
108202 +if [ ! -f "$1" ]; then
108203 + SEED=`od -A n -t x8 -N 32 /dev/urandom | tr -d ' \n'`
108204 + echo "const char *randstruct_seed = \"$SEED\";" > "$1"
108205 + HASH=`echo -n "$SEED" | sha256sum | cut -d" " -f1 | tr -d ' \n'`
108206 + echo "#define RANDSTRUCT_HASHED_SEED \"$HASH\"" > "$2"
108207 +fi
108208 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
108209 new file mode 100644
108210 index 0000000..d81c094
108211 --- /dev/null
108212 +++ b/tools/gcc/kallocstat_plugin.c
108213 @@ -0,0 +1,183 @@
108214 +/*
108215 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
108216 + * Licensed under the GPL v2
108217 + *
108218 + * Note: the choice of the license means that the compilation process is
108219 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
108220 + * but for the kernel it doesn't matter since it doesn't link against
108221 + * any of the gcc libraries
108222 + *
108223 + * gcc plugin to find the distribution of k*alloc sizes
108224 + *
108225 + * TODO:
108226 + *
108227 + * BUGS:
108228 + * - none known
108229 + */
108230 +
108231 +#include "gcc-common.h"
108232 +
108233 +int plugin_is_GPL_compatible;
108234 +
108235 +static struct plugin_info kallocstat_plugin_info = {
108236 + .version = "201401260140",
108237 + .help = NULL
108238 +};
108239 +
108240 +static const char * const kalloc_functions[] = {
108241 + "__kmalloc",
108242 + "kmalloc",
108243 + "kmalloc_large",
108244 + "kmalloc_node",
108245 + "kmalloc_order",
108246 + "kmalloc_order_trace",
108247 + "kmalloc_slab",
108248 + "kzalloc",
108249 + "kzalloc_node",
108250 +};
108251 +
108252 +static bool is_kalloc(const char *fnname)
108253 +{
108254 + size_t i;
108255 +
108256 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
108257 + if (!strcmp(fnname, kalloc_functions[i]))
108258 + return true;
108259 + return false;
108260 +}
108261 +
108262 +static unsigned int execute_kallocstat(void)
108263 +{
108264 + basic_block bb;
108265 +
108266 + // 1. loop through BBs and GIMPLE statements
108267 + FOR_EACH_BB_FN(bb, cfun) {
108268 + gimple_stmt_iterator gsi;
108269 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
108270 + // gimple match:
108271 + tree fndecl, size;
108272 + gimple stmt;
108273 + const char *fnname;
108274 +
108275 + // is it a call
108276 + stmt = gsi_stmt(gsi);
108277 + if (!is_gimple_call(stmt))
108278 + continue;
108279 + fndecl = gimple_call_fndecl(stmt);
108280 + if (fndecl == NULL_TREE)
108281 + continue;
108282 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
108283 + continue;
108284 +
108285 + // is it a call to k*alloc
108286 + fnname = DECL_NAME_POINTER(fndecl);
108287 + if (!is_kalloc(fnname))
108288 + continue;
108289 +
108290 + // is the size arg const or the result of a simple const assignment
108291 + size = gimple_call_arg(stmt, 0);
108292 + while (true) {
108293 + expanded_location xloc;
108294 + size_t size_val;
108295 +
108296 + if (TREE_CONSTANT(size)) {
108297 + xloc = expand_location(gimple_location(stmt));
108298 + if (!xloc.file)
108299 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
108300 + size_val = TREE_INT_CST_LOW(size);
108301 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
108302 + break;
108303 + }
108304 +
108305 + if (TREE_CODE(size) != SSA_NAME)
108306 + break;
108307 + stmt = SSA_NAME_DEF_STMT(size);
108308 +//debug_gimple_stmt(stmt);
108309 +//debug_tree(size);
108310 + if (!stmt || !is_gimple_assign(stmt))
108311 + break;
108312 + if (gimple_num_ops(stmt) != 2)
108313 + break;
108314 + size = gimple_assign_rhs1(stmt);
108315 + }
108316 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
108317 +//debug_tree(gimple_call_fn(call_stmt));
108318 +//print_node(stderr, "pax", fndecl, 4);
108319 + }
108320 + }
108321 +
108322 + return 0;
108323 +}
108324 +
108325 +#if BUILDING_GCC_VERSION >= 4009
108326 +static const struct pass_data kallocstat_pass_data = {
108327 +#else
108328 +static struct gimple_opt_pass kallocstat_pass = {
108329 + .pass = {
108330 +#endif
108331 + .type = GIMPLE_PASS,
108332 + .name = "kallocstat",
108333 +#if BUILDING_GCC_VERSION >= 4008
108334 + .optinfo_flags = OPTGROUP_NONE,
108335 +#endif
108336 +#if BUILDING_GCC_VERSION >= 4009
108337 + .has_gate = false,
108338 + .has_execute = true,
108339 +#else
108340 + .gate = NULL,
108341 + .execute = execute_kallocstat,
108342 + .sub = NULL,
108343 + .next = NULL,
108344 + .static_pass_number = 0,
108345 +#endif
108346 + .tv_id = TV_NONE,
108347 + .properties_required = 0,
108348 + .properties_provided = 0,
108349 + .properties_destroyed = 0,
108350 + .todo_flags_start = 0,
108351 + .todo_flags_finish = 0
108352 +#if BUILDING_GCC_VERSION < 4009
108353 + }
108354 +#endif
108355 +};
108356 +
108357 +#if BUILDING_GCC_VERSION >= 4009
108358 +namespace {
108359 +class kallocstat_pass : public gimple_opt_pass {
108360 +public:
108361 + kallocstat_pass() : gimple_opt_pass(kallocstat_pass_data, g) {}
108362 + unsigned int execute() { return execute_kallocstat(); }
108363 +};
108364 +}
108365 +
108366 +static opt_pass *make_kallocstat_pass(void)
108367 +{
108368 + return new kallocstat_pass();
108369 +}
108370 +#else
108371 +static struct opt_pass *make_kallocstat_pass(void)
108372 +{
108373 + return &kallocstat_pass.pass;
108374 +}
108375 +#endif
108376 +
108377 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
108378 +{
108379 + const char * const plugin_name = plugin_info->base_name;
108380 + struct register_pass_info kallocstat_pass_info;
108381 +
108382 + kallocstat_pass_info.pass = make_kallocstat_pass();
108383 + kallocstat_pass_info.reference_pass_name = "ssa";
108384 + kallocstat_pass_info.ref_pass_instance_number = 1;
108385 + kallocstat_pass_info.pos_op = PASS_POS_INSERT_AFTER;
108386 +
108387 + if (!plugin_default_version_check(version, &gcc_version)) {
108388 + error(G_("incompatible gcc/plugin versions"));
108389 + return 1;
108390 + }
108391 +
108392 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
108393 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
108394 +
108395 + return 0;
108396 +}
108397 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
108398 new file mode 100644
108399 index 0000000..89f256d
108400 --- /dev/null
108401 +++ b/tools/gcc/kernexec_plugin.c
108402 @@ -0,0 +1,522 @@
108403 +/*
108404 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
108405 + * Licensed under the GPL v2
108406 + *
108407 + * Note: the choice of the license means that the compilation process is
108408 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
108409 + * but for the kernel it doesn't matter since it doesn't link against
108410 + * any of the gcc libraries
108411 + *
108412 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
108413 + *
108414 + * TODO:
108415 + *
108416 + * BUGS:
108417 + * - none known
108418 + */
108419 +
108420 +#include "gcc-common.h"
108421 +
108422 +int plugin_is_GPL_compatible;
108423 +
108424 +static struct plugin_info kernexec_plugin_info = {
108425 + .version = "201401260140",
108426 + .help = "method=[bts|or]\tinstrumentation method\n"
108427 +};
108428 +
108429 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
108430 +static void (*kernexec_instrument_retaddr)(rtx);
108431 +
108432 +/*
108433 + * add special KERNEXEC instrumentation: reload %r12 after it has been clobbered
108434 + */
108435 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
108436 +{
108437 + gimple asm_movabs_stmt;
108438 +
108439 + // build asm volatile("movabs $0x8000000000000000, %%r12\n\t" : : : );
108440 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r12\n\t", NULL, NULL, NULL, NULL);
108441 + gimple_asm_set_volatile(asm_movabs_stmt, true);
108442 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
108443 + update_stmt(asm_movabs_stmt);
108444 +}
108445 +
108446 +/*
108447 + * find all asm() stmts that clobber r12 and add a reload of r12
108448 + */
108449 +static unsigned int execute_kernexec_reload(void)
108450 +{
108451 + basic_block bb;
108452 +
108453 + // 1. loop through BBs and GIMPLE statements
108454 + FOR_EACH_BB_FN(bb, cfun) {
108455 + gimple_stmt_iterator gsi;
108456 +
108457 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
108458 + // gimple match: __asm__ ("" : : : "r12");
108459 + gimple asm_stmt;
108460 + size_t nclobbers;
108461 +
108462 + // is it an asm ...
108463 + asm_stmt = gsi_stmt(gsi);
108464 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
108465 + continue;
108466 +
108467 + // ... clobbering r12
108468 + nclobbers = gimple_asm_nclobbers(asm_stmt);
108469 + while (nclobbers--) {
108470 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
108471 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r12"))
108472 + continue;
108473 + kernexec_reload_fptr_mask(&gsi);
108474 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
108475 + break;
108476 + }
108477 + }
108478 + }
108479 +
108480 + return 0;
108481 +}
108482 +
108483 +/*
108484 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
108485 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
108486 + */
108487 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
108488 +{
108489 + gimple assign_intptr, assign_new_fptr, call_stmt;
108490 + tree intptr, orptr, old_fptr, new_fptr, kernexec_mask;
108491 +
108492 + call_stmt = gsi_stmt(*gsi);
108493 + old_fptr = gimple_call_fn(call_stmt);
108494 +
108495 + // create temporary unsigned long variable used for bitops and cast fptr to it
108496 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
108497 + add_referenced_var(intptr);
108498 + intptr = make_ssa_name(intptr, NULL);
108499 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
108500 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
108501 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
108502 + update_stmt(assign_intptr);
108503 +
108504 + // apply logical or to temporary unsigned long and bitmask
108505 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
108506 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
108507 + orptr = fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask);
108508 + intptr = make_ssa_name(SSA_NAME_VAR(intptr), NULL);
108509 + assign_intptr = gimple_build_assign(intptr, orptr);
108510 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
108511 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
108512 + update_stmt(assign_intptr);
108513 +
108514 + // cast temporary unsigned long back to a temporary fptr variable
108515 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
108516 + add_referenced_var(new_fptr);
108517 + new_fptr = make_ssa_name(new_fptr, NULL);
108518 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
108519 + SSA_NAME_DEF_STMT(new_fptr) = assign_new_fptr;
108520 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
108521 + update_stmt(assign_new_fptr);
108522 +
108523 + // replace call stmt fn with the new fptr
108524 + gimple_call_set_fn(call_stmt, new_fptr);
108525 + update_stmt(call_stmt);
108526 +}
108527 +
108528 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
108529 +{
108530 + gimple asm_or_stmt, call_stmt;
108531 + tree old_fptr, new_fptr, input, output;
108532 +#if BUILDING_GCC_VERSION <= 4007
108533 + VEC(tree, gc) *inputs = NULL;
108534 + VEC(tree, gc) *outputs = NULL;
108535 +#else
108536 + vec<tree, va_gc> *inputs = NULL;
108537 + vec<tree, va_gc> *outputs = NULL;
108538 +#endif
108539 +
108540 + call_stmt = gsi_stmt(*gsi);
108541 + old_fptr = gimple_call_fn(call_stmt);
108542 +
108543 + // create temporary fptr variable
108544 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
108545 + add_referenced_var(new_fptr);
108546 + new_fptr = make_ssa_name(new_fptr, NULL);
108547 +
108548 + // build asm volatile("orq %%r12, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
108549 + input = build_tree_list(NULL_TREE, build_string(1, "0"));
108550 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
108551 + output = build_tree_list(NULL_TREE, build_string(2, "=r"));
108552 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
108553 +#if BUILDING_GCC_VERSION <= 4007
108554 + VEC_safe_push(tree, gc, inputs, input);
108555 + VEC_safe_push(tree, gc, outputs, output);
108556 +#else
108557 + vec_safe_push(inputs, input);
108558 + vec_safe_push(outputs, output);
108559 +#endif
108560 + asm_or_stmt = gimple_build_asm_vec("orq %%r12, %0\n\t", inputs, outputs, NULL, NULL);
108561 + SSA_NAME_DEF_STMT(new_fptr) = asm_or_stmt;
108562 + gimple_asm_set_volatile(asm_or_stmt, true);
108563 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
108564 + update_stmt(asm_or_stmt);
108565 +
108566 + // replace call stmt fn with the new fptr
108567 + gimple_call_set_fn(call_stmt, new_fptr);
108568 + update_stmt(call_stmt);
108569 +}
108570 +
108571 +/*
108572 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
108573 + */
108574 +static unsigned int execute_kernexec_fptr(void)
108575 +{
108576 + basic_block bb;
108577 +
108578 + // 1. loop through BBs and GIMPLE statements
108579 + FOR_EACH_BB_FN(bb, cfun) {
108580 + gimple_stmt_iterator gsi;
108581 +
108582 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
108583 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
108584 + tree fn;
108585 + gimple call_stmt;
108586 +
108587 + // is it a call ...
108588 + call_stmt = gsi_stmt(gsi);
108589 + if (!is_gimple_call(call_stmt))
108590 + continue;
108591 + fn = gimple_call_fn(call_stmt);
108592 + if (TREE_CODE(fn) == ADDR_EXPR)
108593 + continue;
108594 + if (TREE_CODE(fn) != SSA_NAME)
108595 + gcc_unreachable();
108596 +
108597 + // ... through a function pointer
108598 + if (SSA_NAME_VAR(fn) != NULL_TREE) {
108599 + fn = SSA_NAME_VAR(fn);
108600 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL) {
108601 + debug_tree(fn);
108602 + gcc_unreachable();
108603 + }
108604 + }
108605 + fn = TREE_TYPE(fn);
108606 + if (TREE_CODE(fn) != POINTER_TYPE)
108607 + continue;
108608 + fn = TREE_TYPE(fn);
108609 + if (TREE_CODE(fn) != FUNCTION_TYPE)
108610 + continue;
108611 +
108612 + kernexec_instrument_fptr(&gsi);
108613 +
108614 +//debug_tree(gimple_call_fn(call_stmt));
108615 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
108616 + }
108617 + }
108618 +
108619 + return 0;
108620 +}
108621 +
108622 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
108623 +static void kernexec_instrument_retaddr_bts(rtx insn)
108624 +{
108625 + rtx btsq;
108626 + rtvec argvec, constraintvec, labelvec;
108627 + int line;
108628 +
108629 + // create asm volatile("btsq $63,(%%rsp)":::)
108630 + argvec = rtvec_alloc(0);
108631 + constraintvec = rtvec_alloc(0);
108632 + labelvec = rtvec_alloc(0);
108633 + line = expand_location(RTL_LOCATION(insn)).line;
108634 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
108635 + MEM_VOLATILE_P(btsq) = 1;
108636 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
108637 + emit_insn_before(btsq, insn);
108638 +}
108639 +
108640 +// add special KERNEXEC instrumentation: orq %r12,(%rsp) just before retn
108641 +static void kernexec_instrument_retaddr_or(rtx insn)
108642 +{
108643 + rtx orq;
108644 + rtvec argvec, constraintvec, labelvec;
108645 + int line;
108646 +
108647 + // create asm volatile("orq %%r12,(%%rsp)":::)
108648 + argvec = rtvec_alloc(0);
108649 + constraintvec = rtvec_alloc(0);
108650 + labelvec = rtvec_alloc(0);
108651 + line = expand_location(RTL_LOCATION(insn)).line;
108652 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r12,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
108653 + MEM_VOLATILE_P(orq) = 1;
108654 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
108655 + emit_insn_before(orq, insn);
108656 +}
108657 +
108658 +/*
108659 + * find all asm level function returns and forcibly set the highest bit of the return address
108660 + */
108661 +static unsigned int execute_kernexec_retaddr(void)
108662 +{
108663 + rtx insn;
108664 +
108665 +// if (stack_realign_drap)
108666 +// inform(DECL_SOURCE_LOCATION(current_function_decl), "drap detected in %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
108667 +
108668 + // 1. find function returns
108669 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
108670 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
108671 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
108672 + // (jump_insn 97 96 98 6 (simple_return) fptr.c:50 -1 (nil) -> simple_return)
108673 + rtx body;
108674 +
108675 + // is it a retn
108676 + if (!JUMP_P(insn))
108677 + continue;
108678 + body = PATTERN(insn);
108679 + if (GET_CODE(body) == PARALLEL)
108680 + body = XVECEXP(body, 0, 0);
108681 + if (!ANY_RETURN_P(body))
108682 + continue;
108683 + kernexec_instrument_retaddr(insn);
108684 + }
108685 +
108686 +// print_simple_rtl(stderr, get_insns());
108687 +// print_rtl(stderr, get_insns());
108688 +
108689 + return 0;
108690 +}
108691 +
108692 +static bool kernexec_cmodel_check(void)
108693 +{
108694 + tree section;
108695 +
108696 + if (ix86_cmodel != CM_KERNEL)
108697 + return false;
108698 +
108699 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
108700 + if (!section || !TREE_VALUE(section))
108701 + return true;
108702 +
108703 + section = TREE_VALUE(TREE_VALUE(section));
108704 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
108705 + return true;
108706 +
108707 + return false;
108708 +}
108709 +
108710 +#if BUILDING_GCC_VERSION >= 4009
108711 +static const struct pass_data kernexec_reload_pass_data = {
108712 +#else
108713 +static struct gimple_opt_pass kernexec_reload_pass = {
108714 + .pass = {
108715 +#endif
108716 + .type = GIMPLE_PASS,
108717 + .name = "kernexec_reload",
108718 +#if BUILDING_GCC_VERSION >= 4008
108719 + .optinfo_flags = OPTGROUP_NONE,
108720 +#endif
108721 +#if BUILDING_GCC_VERSION >= 4009
108722 + .has_gate = true,
108723 + .has_execute = true,
108724 +#else
108725 + .gate = kernexec_cmodel_check,
108726 + .execute = execute_kernexec_reload,
108727 + .sub = NULL,
108728 + .next = NULL,
108729 + .static_pass_number = 0,
108730 +#endif
108731 + .tv_id = TV_NONE,
108732 + .properties_required = 0,
108733 + .properties_provided = 0,
108734 + .properties_destroyed = 0,
108735 + .todo_flags_start = 0,
108736 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
108737 +#if BUILDING_GCC_VERSION < 4009
108738 + }
108739 +#endif
108740 +};
108741 +
108742 +#if BUILDING_GCC_VERSION >= 4009
108743 +static const struct pass_data kernexec_fptr_pass_data = {
108744 +#else
108745 +static struct gimple_opt_pass kernexec_fptr_pass = {
108746 + .pass = {
108747 +#endif
108748 + .type = GIMPLE_PASS,
108749 + .name = "kernexec_fptr",
108750 +#if BUILDING_GCC_VERSION >= 4008
108751 + .optinfo_flags = OPTGROUP_NONE,
108752 +#endif
108753 +#if BUILDING_GCC_VERSION >= 4009
108754 + .has_gate = true,
108755 + .has_execute = true,
108756 +#else
108757 + .gate = kernexec_cmodel_check,
108758 + .execute = execute_kernexec_fptr,
108759 + .sub = NULL,
108760 + .next = NULL,
108761 + .static_pass_number = 0,
108762 +#endif
108763 + .tv_id = TV_NONE,
108764 + .properties_required = 0,
108765 + .properties_provided = 0,
108766 + .properties_destroyed = 0,
108767 + .todo_flags_start = 0,
108768 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
108769 +#if BUILDING_GCC_VERSION < 4009
108770 + }
108771 +#endif
108772 +};
108773 +
108774 +#if BUILDING_GCC_VERSION >= 4009
108775 +static const struct pass_data kernexec_retaddr_pass_data = {
108776 +#else
108777 +static struct rtl_opt_pass kernexec_retaddr_pass = {
108778 + .pass = {
108779 +#endif
108780 + .type = RTL_PASS,
108781 + .name = "kernexec_retaddr",
108782 +#if BUILDING_GCC_VERSION >= 4008
108783 + .optinfo_flags = OPTGROUP_NONE,
108784 +#endif
108785 +#if BUILDING_GCC_VERSION >= 4009
108786 + .has_gate = true,
108787 + .has_execute = true,
108788 +#else
108789 + .gate = kernexec_cmodel_check,
108790 + .execute = execute_kernexec_retaddr,
108791 + .sub = NULL,
108792 + .next = NULL,
108793 + .static_pass_number = 0,
108794 +#endif
108795 + .tv_id = TV_NONE,
108796 + .properties_required = 0,
108797 + .properties_provided = 0,
108798 + .properties_destroyed = 0,
108799 + .todo_flags_start = 0,
108800 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
108801 +#if BUILDING_GCC_VERSION < 4009
108802 + }
108803 +#endif
108804 +};
108805 +
108806 +#if BUILDING_GCC_VERSION >= 4009
108807 +namespace {
108808 +class kernexec_reload_pass : public gimple_opt_pass {
108809 +public:
108810 + kernexec_reload_pass() : gimple_opt_pass(kernexec_reload_pass_data, g) {}
108811 + bool gate() { return kernexec_cmodel_check(); }
108812 + unsigned int execute() { return execute_kernexec_reload(); }
108813 +};
108814 +
108815 +class kernexec_fptr_pass : public gimple_opt_pass {
108816 +public:
108817 + kernexec_fptr_pass() : gimple_opt_pass(kernexec_fptr_pass_data, g) {}
108818 + bool gate() { return kernexec_cmodel_check(); }
108819 + unsigned int execute() { return execute_kernexec_fptr(); }
108820 +};
108821 +
108822 +class kernexec_retaddr_pass : public rtl_opt_pass {
108823 +public:
108824 + kernexec_retaddr_pass() : rtl_opt_pass(kernexec_retaddr_pass_data, g) {}
108825 + bool gate() { return kernexec_cmodel_check(); }
108826 + unsigned int execute() { return execute_kernexec_retaddr(); }
108827 +};
108828 +}
108829 +
108830 +static opt_pass *make_kernexec_reload_pass(void)
108831 +{
108832 + return new kernexec_reload_pass();
108833 +}
108834 +
108835 +static opt_pass *make_kernexec_fptr_pass(void)
108836 +{
108837 + return new kernexec_fptr_pass();
108838 +}
108839 +
108840 +static opt_pass *make_kernexec_retaddr_pass(void)
108841 +{
108842 + return new kernexec_retaddr_pass();
108843 +}
108844 +#else
108845 +static struct opt_pass *make_kernexec_reload_pass(void)
108846 +{
108847 + return &kernexec_reload_pass.pass;
108848 +}
108849 +
108850 +static struct opt_pass *make_kernexec_fptr_pass(void)
108851 +{
108852 + return &kernexec_fptr_pass.pass;
108853 +}
108854 +
108855 +static struct opt_pass *make_kernexec_retaddr_pass(void)
108856 +{
108857 + return &kernexec_retaddr_pass.pass;
108858 +}
108859 +#endif
108860 +
108861 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
108862 +{
108863 + const char * const plugin_name = plugin_info->base_name;
108864 + const int argc = plugin_info->argc;
108865 + const struct plugin_argument * const argv = plugin_info->argv;
108866 + int i;
108867 + struct register_pass_info kernexec_reload_pass_info;
108868 + struct register_pass_info kernexec_fptr_pass_info;
108869 + struct register_pass_info kernexec_retaddr_pass_info;
108870 +
108871 + kernexec_reload_pass_info.pass = make_kernexec_reload_pass();
108872 + kernexec_reload_pass_info.reference_pass_name = "ssa";
108873 + kernexec_reload_pass_info.ref_pass_instance_number = 1;
108874 + kernexec_reload_pass_info.pos_op = PASS_POS_INSERT_AFTER;
108875 +
108876 + kernexec_fptr_pass_info.pass = make_kernexec_fptr_pass();
108877 + kernexec_fptr_pass_info.reference_pass_name = "ssa";
108878 + kernexec_fptr_pass_info.ref_pass_instance_number = 1;
108879 + kernexec_fptr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
108880 +
108881 + kernexec_retaddr_pass_info.pass = make_kernexec_retaddr_pass();
108882 + kernexec_retaddr_pass_info.reference_pass_name = "pro_and_epilogue";
108883 + kernexec_retaddr_pass_info.ref_pass_instance_number = 1;
108884 + kernexec_retaddr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
108885 +
108886 + if (!plugin_default_version_check(version, &gcc_version)) {
108887 + error(G_("incompatible gcc/plugin versions"));
108888 + return 1;
108889 + }
108890 +
108891 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
108892 +
108893 + if (TARGET_64BIT == 0)
108894 + return 0;
108895 +
108896 + for (i = 0; i < argc; ++i) {
108897 + if (!strcmp(argv[i].key, "method")) {
108898 + if (!argv[i].value) {
108899 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
108900 + continue;
108901 + }
108902 + if (!strcmp(argv[i].value, "bts")) {
108903 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
108904 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
108905 + } else if (!strcmp(argv[i].value, "or")) {
108906 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
108907 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
108908 + fix_register("r12", 1, 1);
108909 + } else
108910 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
108911 + continue;
108912 + }
108913 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
108914 + }
108915 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
108916 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
108917 +
108918 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
108919 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
108920 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
108921 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
108922 +
108923 + return 0;
108924 +}
108925 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
108926 new file mode 100644
108927 index 0000000..39d7cc7
108928 --- /dev/null
108929 +++ b/tools/gcc/latent_entropy_plugin.c
108930 @@ -0,0 +1,462 @@
108931 +/*
108932 + * Copyright 2012-2014 by the PaX Team <pageexec@freemail.hu>
108933 + * Licensed under the GPL v2
108934 + *
108935 + * Note: the choice of the license means that the compilation process is
108936 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
108937 + * but for the kernel it doesn't matter since it doesn't link against
108938 + * any of the gcc libraries
108939 + *
108940 + * gcc plugin to help generate a little bit of entropy from program state,
108941 + * used throughout the uptime of the kernel
108942 + *
108943 + * TODO:
108944 + * - add ipa pass to identify not explicitly marked candidate functions
108945 + * - mix in more program state (function arguments/return values, loop variables, etc)
108946 + * - more instrumentation control via attribute parameters
108947 + *
108948 + * BUGS:
108949 + * - LTO needs -flto-partition=none for now
108950 + */
108951 +
108952 +#include "gcc-common.h"
108953 +
108954 +int plugin_is_GPL_compatible;
108955 +
108956 +static tree latent_entropy_decl;
108957 +
108958 +static struct plugin_info latent_entropy_plugin_info = {
108959 + .version = "201403280150",
108960 + .help = NULL
108961 +};
108962 +
108963 +static unsigned HOST_WIDE_INT seed;
108964 +static unsigned HOST_WIDE_INT get_random_const(void)
108965 +{
108966 + unsigned int i;
108967 + unsigned HOST_WIDE_INT ret = 0;
108968 +
108969 + for (i = 0; i < 8 * sizeof ret; i++) {
108970 + ret = (ret << 1) | (seed & 1);
108971 + seed >>= 1;
108972 + if (ret & 1)
108973 + seed ^= 0xD800000000000000ULL;
108974 + }
108975 +
108976 + return ret;
108977 +}
108978 +
108979 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
108980 +{
108981 + tree type;
108982 + unsigned long long mask;
108983 +#if BUILDING_GCC_VERSION <= 4007
108984 + VEC(constructor_elt, gc) *vals;
108985 +#else
108986 + vec<constructor_elt, va_gc> *vals;
108987 +#endif
108988 +
108989 + switch (TREE_CODE(*node)) {
108990 + default:
108991 + *no_add_attrs = true;
108992 + error("%qE attribute only applies to functions and variables", name);
108993 + break;
108994 +
108995 + case VAR_DECL:
108996 + if (DECL_INITIAL(*node)) {
108997 + *no_add_attrs = true;
108998 + error("variable %qD with %qE attribute must not be initialized", *node, name);
108999 + break;
109000 + }
109001 +
109002 + if (!TREE_STATIC(*node)) {
109003 + *no_add_attrs = true;
109004 + error("variable %qD with %qE attribute must not be local", *node, name);
109005 + break;
109006 + }
109007 +
109008 + type = TREE_TYPE(*node);
109009 + switch (TREE_CODE(type)) {
109010 + default:
109011 + *no_add_attrs = true;
109012 + 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);
109013 + break;
109014 +
109015 + case RECORD_TYPE: {
109016 + tree field;
109017 + unsigned int nelt = 0;
109018 +
109019 + for (field = TYPE_FIELDS(type); field; nelt++, field = TREE_CHAIN(field)) {
109020 + tree fieldtype;
109021 +
109022 + fieldtype = TREE_TYPE(field);
109023 + if (TREE_CODE(fieldtype) != INTEGER_TYPE) {
109024 + *no_add_attrs = true;
109025 + error("structure variable %qD with %qE attribute has a non-integer field %qE", *node, name, field);
109026 + break;
109027 + }
109028 + }
109029 +
109030 + if (field)
109031 + break;
109032 +
109033 +#if BUILDING_GCC_VERSION <= 4007
109034 + vals = VEC_alloc(constructor_elt, gc, nelt);
109035 +#else
109036 + vec_alloc(vals, nelt);
109037 +#endif
109038 +
109039 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
109040 + tree fieldtype;
109041 +
109042 + fieldtype = TREE_TYPE(field);
109043 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(fieldtype)) - 1);
109044 + mask = 2 * (mask - 1) + 1;
109045 +
109046 + if (TYPE_UNSIGNED(fieldtype))
109047 + CONSTRUCTOR_APPEND_ELT(vals, field, build_int_cstu(fieldtype, mask & get_random_const()));
109048 + else
109049 + CONSTRUCTOR_APPEND_ELT(vals, field, build_int_cst(fieldtype, mask & get_random_const()));
109050 + }
109051 +
109052 + DECL_INITIAL(*node) = build_constructor(type, vals);
109053 +//debug_tree(DECL_INITIAL(*node));
109054 + break;
109055 + }
109056 +
109057 + case INTEGER_TYPE:
109058 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(type)) - 1);
109059 + mask = 2 * (mask - 1) + 1;
109060 +
109061 + if (TYPE_UNSIGNED(type))
109062 + DECL_INITIAL(*node) = build_int_cstu(type, mask & get_random_const());
109063 + else
109064 + DECL_INITIAL(*node) = build_int_cst(type, mask & get_random_const());
109065 + break;
109066 +
109067 + case ARRAY_TYPE: {
109068 + tree elt_type, array_size, elt_size;
109069 + unsigned int i, nelt;
109070 +
109071 + elt_type = TREE_TYPE(type);
109072 + elt_size = TYPE_SIZE_UNIT(TREE_TYPE(type));
109073 + array_size = TYPE_SIZE_UNIT(type);
109074 +
109075 + if (TREE_CODE(elt_type) != INTEGER_TYPE || !array_size || TREE_CODE(array_size) != INTEGER_CST) {
109076 + *no_add_attrs = true;
109077 + error("array variable %qD with %qE attribute must be a fixed length integer array type", *node, name);
109078 + break;
109079 + }
109080 +
109081 + nelt = TREE_INT_CST_LOW(array_size) / TREE_INT_CST_LOW(elt_size);
109082 +#if BUILDING_GCC_VERSION <= 4007
109083 + vals = VEC_alloc(constructor_elt, gc, nelt);
109084 +#else
109085 + vec_alloc(vals, nelt);
109086 +#endif
109087 +
109088 + mask = 1ULL << (TREE_INT_CST_LOW(TYPE_SIZE(elt_type)) - 1);
109089 + mask = 2 * (mask - 1) + 1;
109090 +
109091 + for (i = 0; i < nelt; i++)
109092 + if (TYPE_UNSIGNED(elt_type))
109093 + CONSTRUCTOR_APPEND_ELT(vals, size_int(i), build_int_cstu(elt_type, mask & get_random_const()));
109094 + else
109095 + CONSTRUCTOR_APPEND_ELT(vals, size_int(i), build_int_cst(elt_type, mask & get_random_const()));
109096 +
109097 + DECL_INITIAL(*node) = build_constructor(type, vals);
109098 +//debug_tree(DECL_INITIAL(*node));
109099 + break;
109100 + }
109101 + }
109102 + break;
109103 +
109104 + case FUNCTION_DECL:
109105 + break;
109106 + }
109107 +
109108 + return NULL_TREE;
109109 +}
109110 +
109111 +static struct attribute_spec latent_entropy_attr = {
109112 + .name = "latent_entropy",
109113 + .min_length = 0,
109114 + .max_length = 0,
109115 + .decl_required = true,
109116 + .type_required = false,
109117 + .function_type_required = false,
109118 + .handler = handle_latent_entropy_attribute,
109119 +#if BUILDING_GCC_VERSION >= 4007
109120 + .affects_type_identity = false
109121 +#endif
109122 +};
109123 +
109124 +static void register_attributes(void *event_data, void *data)
109125 +{
109126 + register_attribute(&latent_entropy_attr);
109127 +}
109128 +
109129 +static bool gate_latent_entropy(void)
109130 +{
109131 + // don't bother with noreturn functions for now
109132 + if (TREE_THIS_VOLATILE(current_function_decl))
109133 + return false;
109134 +
109135 + return lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl)) != NULL_TREE;
109136 +}
109137 +
109138 +static enum tree_code get_op(tree *rhs)
109139 +{
109140 + static enum tree_code op;
109141 + unsigned HOST_WIDE_INT random_const;
109142 +
109143 + random_const = get_random_const();
109144 +
109145 + switch (op) {
109146 + case BIT_XOR_EXPR:
109147 + op = PLUS_EXPR;
109148 + break;
109149 +
109150 + case PLUS_EXPR:
109151 + if (rhs) {
109152 + op = LROTATE_EXPR;
109153 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
109154 + break;
109155 + }
109156 +
109157 + case LROTATE_EXPR:
109158 + default:
109159 + op = BIT_XOR_EXPR;
109160 + break;
109161 + }
109162 + if (rhs)
109163 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
109164 + return op;
109165 +}
109166 +
109167 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
109168 +{
109169 + gimple_stmt_iterator gsi;
109170 + gimple assign;
109171 + tree addxorrol, rhs;
109172 + enum tree_code op;
109173 +
109174 + op = get_op(&rhs);
109175 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
109176 + assign = gimple_build_assign(local_entropy, addxorrol);
109177 + gsi = gsi_after_labels(bb);
109178 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
109179 + update_stmt(assign);
109180 +//debug_bb(bb);
109181 +}
109182 +
109183 +static void perturb_latent_entropy(basic_block bb, tree rhs)
109184 +{
109185 + gimple_stmt_iterator gsi;
109186 + gimple assign;
109187 + tree addxorrol, temp;
109188 +
109189 + // 1. create temporary copy of latent_entropy
109190 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
109191 + add_referenced_var(temp);
109192 +
109193 + // 2. read...
109194 + temp = make_ssa_name(temp, NULL);
109195 + assign = gimple_build_assign(temp, latent_entropy_decl);
109196 + SSA_NAME_DEF_STMT(temp) = assign;
109197 + add_referenced_var(latent_entropy_decl);
109198 + gsi = gsi_after_labels(bb);
109199 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
109200 + update_stmt(assign);
109201 +
109202 + // 3. ...modify...
109203 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
109204 + temp = make_ssa_name(SSA_NAME_VAR(temp), NULL);
109205 + assign = gimple_build_assign(temp, addxorrol);
109206 + SSA_NAME_DEF_STMT(temp) = assign;
109207 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
109208 + update_stmt(assign);
109209 +
109210 + // 4. ...write latent_entropy
109211 + assign = gimple_build_assign(latent_entropy_decl, temp);
109212 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
109213 + update_stmt(assign);
109214 +}
109215 +
109216 +static unsigned int execute_latent_entropy(void)
109217 +{
109218 + basic_block bb;
109219 + gimple assign;
109220 + gimple_stmt_iterator gsi;
109221 + tree local_entropy;
109222 +
109223 + if (!latent_entropy_decl) {
109224 +#if BUILDING_GCC_VERSION >= 4009
109225 + varpool_node *node;
109226 +#else
109227 + struct varpool_node *node;
109228 +#endif
109229 +
109230 + FOR_EACH_VARIABLE(node) {
109231 + tree var = NODE_DECL(node);
109232 +
109233 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
109234 + continue;
109235 + latent_entropy_decl = var;
109236 +// debug_tree(var);
109237 + break;
109238 + }
109239 + if (!latent_entropy_decl) {
109240 +// debug_tree(current_function_decl);
109241 + return 0;
109242 + }
109243 + }
109244 +
109245 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
109246 +
109247 + // 1. create local entropy variable
109248 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
109249 + add_referenced_var(local_entropy);
109250 + mark_sym_for_renaming(local_entropy);
109251 +
109252 + // 2. initialize local entropy variable
109253 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
109254 + if (dom_info_available_p(CDI_DOMINATORS))
109255 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
109256 + gsi = gsi_start_bb(bb);
109257 +
109258 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
109259 +// gimple_set_location(assign, loc);
109260 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
109261 + update_stmt(assign);
109262 +//debug_bb(bb);
109263 + gcc_assert(single_succ_p(bb));
109264 + bb = single_succ(bb);
109265 +
109266 + // 3. instrument each BB with an operation on the local entropy variable
109267 + while (bb != EXIT_BLOCK_PTR_FOR_FN(cfun)) {
109268 + perturb_local_entropy(bb, local_entropy);
109269 +//debug_bb(bb);
109270 + bb = bb->next_bb;
109271 + };
109272 +
109273 + // 4. mix local entropy into the global entropy variable
109274 + gcc_assert(single_pred_p(EXIT_BLOCK_PTR_FOR_FN(cfun)));
109275 + perturb_latent_entropy(single_pred(EXIT_BLOCK_PTR_FOR_FN(cfun)), local_entropy);
109276 +//debug_bb(single_pred(EXIT_BLOCK_PTR_FOR_FN(cfun)));
109277 + return 0;
109278 +}
109279 +
109280 +static void latent_entropy_start_unit(void *gcc_data, void *user_data)
109281 +{
109282 + tree latent_entropy_type;
109283 +
109284 + seed = get_random_seed(false);
109285 +
109286 + if (in_lto_p)
109287 + return;
109288 +
109289 + // extern volatile u64 latent_entropy
109290 + gcc_assert(TYPE_PRECISION(long_long_unsigned_type_node) == 64);
109291 + latent_entropy_type = build_qualified_type(long_long_unsigned_type_node, TYPE_QUALS(long_long_unsigned_type_node) | TYPE_QUAL_VOLATILE);
109292 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), latent_entropy_type);
109293 +
109294 + TREE_STATIC(latent_entropy_decl) = 1;
109295 + TREE_PUBLIC(latent_entropy_decl) = 1;
109296 + TREE_USED(latent_entropy_decl) = 1;
109297 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
109298 + DECL_EXTERNAL(latent_entropy_decl) = 1;
109299 + DECL_ARTIFICIAL(latent_entropy_decl) = 1;
109300 + lang_hooks.decls.pushdecl(latent_entropy_decl);
109301 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
109302 +// varpool_finalize_decl(latent_entropy_decl);
109303 +// varpool_mark_needed_node(latent_entropy_decl);
109304 +}
109305 +
109306 +#if BUILDING_GCC_VERSION >= 4009
109307 +static const struct pass_data latent_entropy_pass_data = {
109308 +#else
109309 +static struct gimple_opt_pass latent_entropy_pass = {
109310 + .pass = {
109311 +#endif
109312 + .type = GIMPLE_PASS,
109313 + .name = "latent_entropy",
109314 +#if BUILDING_GCC_VERSION >= 4008
109315 + .optinfo_flags = OPTGROUP_NONE,
109316 +#endif
109317 +#if BUILDING_GCC_VERSION >= 4009
109318 + .has_gate = true,
109319 + .has_execute = true,
109320 +#else
109321 + .gate = gate_latent_entropy,
109322 + .execute = execute_latent_entropy,
109323 + .sub = NULL,
109324 + .next = NULL,
109325 + .static_pass_number = 0,
109326 +#endif
109327 + .tv_id = TV_NONE,
109328 + .properties_required = PROP_gimple_leh | PROP_cfg,
109329 + .properties_provided = 0,
109330 + .properties_destroyed = 0,
109331 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
109332 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
109333 +#if BUILDING_GCC_VERSION < 4009
109334 + }
109335 +#endif
109336 +};
109337 +
109338 +#if BUILDING_GCC_VERSION >= 4009
109339 +namespace {
109340 +class latent_entropy_pass : public gimple_opt_pass {
109341 +public:
109342 + latent_entropy_pass() : gimple_opt_pass(latent_entropy_pass_data, g) {}
109343 + bool gate() { return gate_latent_entropy(); }
109344 + unsigned int execute() { return execute_latent_entropy(); }
109345 +};
109346 +}
109347 +
109348 +static opt_pass *make_latent_entropy_pass(void)
109349 +{
109350 + return new latent_entropy_pass();
109351 +}
109352 +#else
109353 +static struct opt_pass *make_latent_entropy_pass(void)
109354 +{
109355 + return &latent_entropy_pass.pass;
109356 +}
109357 +#endif
109358 +
109359 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
109360 +{
109361 + const char * const plugin_name = plugin_info->base_name;
109362 + struct register_pass_info latent_entropy_pass_info;
109363 +
109364 + latent_entropy_pass_info.pass = make_latent_entropy_pass();
109365 + latent_entropy_pass_info.reference_pass_name = "optimized";
109366 + latent_entropy_pass_info.ref_pass_instance_number = 1;
109367 + latent_entropy_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
109368 + static const struct ggc_root_tab gt_ggc_r_gt_latent_entropy[] = {
109369 + {
109370 + .base = &latent_entropy_decl,
109371 + .nelt = 1,
109372 + .stride = sizeof(latent_entropy_decl),
109373 + .cb = &gt_ggc_mx_tree_node,
109374 + .pchw = &gt_pch_nx_tree_node
109375 + },
109376 + LAST_GGC_ROOT_TAB
109377 + };
109378 +
109379 + if (!plugin_default_version_check(version, &gcc_version)) {
109380 + error(G_("incompatible gcc/plugin versions"));
109381 + return 1;
109382 + }
109383 +
109384 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
109385 + register_callback(plugin_name, PLUGIN_START_UNIT, &latent_entropy_start_unit, NULL);
109386 + if (!in_lto_p)
109387 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_latent_entropy);
109388 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
109389 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
109390 +
109391 + return 0;
109392 +}
109393 diff --git a/tools/gcc/randomize_layout_plugin.c b/tools/gcc/randomize_layout_plugin.c
109394 new file mode 100644
109395 index 0000000..8dafb22
109396 --- /dev/null
109397 +++ b/tools/gcc/randomize_layout_plugin.c
109398 @@ -0,0 +1,910 @@
109399 +/*
109400 + * Copyright 2014 by Open Source Security, Inc., Brad Spengler <spender@grsecurity.net>
109401 + * and PaX Team <pageexec@freemail.hu>
109402 + * Licensed under the GPL v2
109403 + *
109404 + * Usage:
109405 + * $ # for 4.5/4.6/C based 4.7
109406 + * $ 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
109407 + * $ # for C++ based 4.7/4.8+
109408 + * $ 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
109409 + * $ gcc -fplugin=./randomize_layout_plugin.so test.c -O2
109410 + */
109411 +
109412 +#include "gcc-common.h"
109413 +#include "randomize_layout_seed.h"
109414 +
109415 +#if BUILDING_GCC_MAJOR < 4 || BUILDING_GCC_MINOR < 6 || (BUILDING_GCC_MINOR == 6 && BUILDING_GCC_PATCHLEVEL < 4)
109416 +#error "The RANDSTRUCT plugin requires GCC 4.6.4 or newer."
109417 +#endif
109418 +
109419 +#define ORIG_TYPE_NAME(node) \
109420 + (TYPE_NAME(TYPE_MAIN_VARIANT(node)) != NULL_TREE ? ((const unsigned char *)IDENTIFIER_POINTER(TYPE_NAME(TYPE_MAIN_VARIANT(node)))) : (const unsigned char *)"anonymous")
109421 +
109422 +int plugin_is_GPL_compatible;
109423 +
109424 +static int performance_mode;
109425 +
109426 +static struct plugin_info randomize_layout_plugin_info = {
109427 + .version = "201402201816",
109428 + .help = "disable\t\t\tdo not activate plugin\n"
109429 + "performance-mode\tenable cacheline-aware layout randomization\n"
109430 +};
109431 +
109432 +/* from old Linux dcache.h */
109433 +static inline unsigned long
109434 +partial_name_hash(unsigned long c, unsigned long prevhash)
109435 +{
109436 + return (prevhash + (c << 4) + (c >> 4)) * 11;
109437 +}
109438 +static inline unsigned int
109439 +name_hash(const unsigned char *name)
109440 +{
109441 + unsigned long hash = 0;
109442 + unsigned int len = strlen((const char *)name);
109443 + while (len--)
109444 + hash = partial_name_hash(*name++, hash);
109445 + return (unsigned int)hash;
109446 +}
109447 +
109448 +static tree handle_randomize_layout_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
109449 +{
109450 + tree type;
109451 +
109452 + *no_add_attrs = true;
109453 + if (TREE_CODE(*node) == FUNCTION_DECL) {
109454 + error("%qE attribute does not apply to functions (%qF)", name, *node);
109455 + return NULL_TREE;
109456 + }
109457 +
109458 + if (TREE_CODE(*node) == PARM_DECL) {
109459 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
109460 + return NULL_TREE;
109461 + }
109462 +
109463 + if (TREE_CODE(*node) == VAR_DECL) {
109464 + error("%qE attribute does not apply to variables (%qD)", name, *node);
109465 + return NULL_TREE;
109466 + }
109467 +
109468 + if (TYPE_P(*node)) {
109469 + type = *node;
109470 + } else {
109471 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
109472 + type = TREE_TYPE(*node);
109473 + }
109474 +
109475 + if (TREE_CODE(type) != RECORD_TYPE) {
109476 + error("%qE attribute used on %qT applies to struct types only", name, type);
109477 + return NULL_TREE;
109478 + }
109479 +
109480 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
109481 + error("%qE attribute is already applied to the type %qT", name, type);
109482 + return NULL_TREE;
109483 + }
109484 +
109485 + *no_add_attrs = false;
109486 +
109487 + return NULL_TREE;
109488 +}
109489 +
109490 +/* set on complete types that we don't need to inspect further at all */
109491 +static tree handle_randomize_considered_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
109492 +{
109493 + *no_add_attrs = false;
109494 + return NULL_TREE;
109495 +}
109496 +
109497 +/*
109498 + * set on types that we've performed a shuffle on, to prevent re-shuffling
109499 + * this does not preclude us from inspecting its fields for potential shuffles
109500 + */
109501 +static tree handle_randomize_performed_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
109502 +{
109503 + *no_add_attrs = false;
109504 + return NULL_TREE;
109505 +}
109506 +
109507 +/*
109508 + * 64bit variant of Bob Jenkins' public domain PRNG
109509 + * 256 bits of internal state
109510 + */
109511 +
109512 +typedef unsigned long long u64;
109513 +
109514 +typedef struct ranctx { u64 a; u64 b; u64 c; u64 d; } ranctx;
109515 +
109516 +#define rot(x,k) (((x)<<(k))|((x)>>(64-(k))))
109517 +static u64 ranval(ranctx *x) {
109518 + u64 e = x->a - rot(x->b, 7);
109519 + x->a = x->b ^ rot(x->c, 13);
109520 + x->b = x->c + rot(x->d, 37);
109521 + x->c = x->d + e;
109522 + x->d = e + x->a;
109523 + return x->d;
109524 +}
109525 +
109526 +static void raninit(ranctx *x, u64 *seed) {
109527 + int i;
109528 +
109529 + x->a = seed[0];
109530 + x->b = seed[1];
109531 + x->c = seed[2];
109532 + x->d = seed[3];
109533 +
109534 + for (i=0; i < 30; ++i)
109535 + (void)ranval(x);
109536 +}
109537 +
109538 +static u64 shuffle_seed[4];
109539 +
109540 +struct partition_group {
109541 + tree tree_start;
109542 + unsigned long start;
109543 + unsigned long length;
109544 +};
109545 +
109546 +static void partition_struct(tree *fields, unsigned long length, struct partition_group *size_groups, unsigned long *num_groups)
109547 +{
109548 + unsigned long i;
109549 + unsigned long accum_size = 0;
109550 + unsigned long accum_length = 0;
109551 + unsigned long group_idx = 0;
109552 +
109553 + gcc_assert(length < INT_MAX);
109554 +
109555 + memset(size_groups, 0, sizeof(struct partition_group) * length);
109556 +
109557 + for (i = 0; i < length; i++) {
109558 + if (size_groups[group_idx].tree_start == NULL_TREE) {
109559 + size_groups[group_idx].tree_start = fields[i];
109560 + size_groups[group_idx].start = i;
109561 + accum_length = 0;
109562 + accum_size = 0;
109563 + }
109564 + accum_size += (unsigned long)int_size_in_bytes(TREE_TYPE(fields[i]));
109565 + accum_length++;
109566 + if (accum_size >= 64) {
109567 + size_groups[group_idx].length = accum_length;
109568 + accum_length = 0;
109569 + group_idx++;
109570 + }
109571 + }
109572 +
109573 + if (size_groups[group_idx].tree_start != NULL_TREE &&
109574 + !size_groups[group_idx].length) {
109575 + size_groups[group_idx].length = accum_length;
109576 + group_idx++;
109577 + }
109578 +
109579 + *num_groups = group_idx;
109580 +}
109581 +
109582 +static void performance_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
109583 +{
109584 + unsigned long i, x;
109585 + struct partition_group size_group[length];
109586 + unsigned long num_groups = 0;
109587 + unsigned long randnum;
109588 +
109589 + partition_struct(newtree, length, (struct partition_group *)&size_group, &num_groups);
109590 + for (i = num_groups - 1; i > 0; i--) {
109591 + struct partition_group tmp;
109592 + randnum = ranval(prng_state) % (i + 1);
109593 + tmp = size_group[i];
109594 + size_group[i] = size_group[randnum];
109595 + size_group[randnum] = tmp;
109596 + }
109597 +
109598 + for (x = 0; x < num_groups; x++) {
109599 + for (i = size_group[x].start + size_group[x].length - 1; i > size_group[x].start; i--) {
109600 + tree tmp;
109601 + if (DECL_BIT_FIELD_TYPE(newtree[i]))
109602 + continue;
109603 + randnum = ranval(prng_state) % (i + 1);
109604 + // we could handle this case differently if desired
109605 + if (DECL_BIT_FIELD_TYPE(newtree[randnum]))
109606 + continue;
109607 + tmp = newtree[i];
109608 + newtree[i] = newtree[randnum];
109609 + newtree[randnum] = tmp;
109610 + }
109611 + }
109612 +}
109613 +
109614 +static void full_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
109615 +{
109616 + unsigned long i, randnum;
109617 +
109618 + for (i = length - 1; i > 0; i--) {
109619 + tree tmp;
109620 + randnum = ranval(prng_state) % (i + 1);
109621 + tmp = newtree[i];
109622 + newtree[i] = newtree[randnum];
109623 + newtree[randnum] = tmp;
109624 + }
109625 +}
109626 +
109627 +/* modern in-place Fisher-Yates shuffle */
109628 +static void shuffle(const_tree type, tree *newtree, unsigned long length)
109629 +{
109630 + unsigned long i;
109631 + u64 seed[4];
109632 + ranctx prng_state;
109633 + const unsigned char *structname;
109634 +
109635 + if (length == 0)
109636 + return;
109637 +
109638 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
109639 +
109640 + structname = ORIG_TYPE_NAME(type);
109641 +
109642 +#ifdef __DEBUG_PLUGIN
109643 + fprintf(stderr, "Shuffling struct %s %p\n", (const char *)structname, type);
109644 +#ifdef __DEBUG_VERBOSE
109645 + debug_tree((tree)type);
109646 +#endif
109647 +#endif
109648 +
109649 + for (i = 0; i < 4; i++) {
109650 + seed[i] = shuffle_seed[i];
109651 + seed[i] ^= name_hash(structname);
109652 + }
109653 +
109654 + raninit(&prng_state, (u64 *)&seed);
109655 +
109656 + if (performance_mode)
109657 + performance_shuffle(newtree, length, &prng_state);
109658 + else
109659 + full_shuffle(newtree, length, &prng_state);
109660 +}
109661 +
109662 +static bool is_flexible_array(const_tree field)
109663 +{
109664 + const_tree fieldtype;
109665 + const_tree typesize;
109666 + const_tree elemtype;
109667 + const_tree elemsize;
109668 +
109669 + fieldtype = TREE_TYPE(field);
109670 + typesize = TYPE_SIZE(fieldtype);
109671 +
109672 + if (TREE_CODE(fieldtype) != ARRAY_TYPE)
109673 + return false;
109674 +
109675 + elemtype = TREE_TYPE(fieldtype);
109676 + elemsize = TYPE_SIZE(elemtype);
109677 +
109678 + /* size of type is represented in bits */
109679 +
109680 + if (typesize == NULL_TREE && TYPE_DOMAIN(fieldtype) != NULL_TREE &&
109681 + TYPE_MAX_VALUE(TYPE_DOMAIN(fieldtype)) == NULL_TREE)
109682 + return true;
109683 +
109684 + if (typesize != NULL_TREE &&
109685 + (TREE_CONSTANT(typesize) && (!TREE_INT_CST_LOW(typesize) ||
109686 + TREE_INT_CST_LOW(typesize) == TREE_INT_CST_LOW(elemsize))))
109687 + return true;
109688 +
109689 + return false;
109690 +}
109691 +
109692 +static int relayout_struct(tree type)
109693 +{
109694 + unsigned long num_fields = (unsigned long)list_length(TYPE_FIELDS(type));
109695 + unsigned long shuffle_length = num_fields;
109696 + tree field;
109697 + tree newtree[num_fields];
109698 + unsigned long i;
109699 + tree list;
109700 + tree variant;
109701 + expanded_location xloc;
109702 +
109703 + if (TYPE_FIELDS(type) == NULL_TREE)
109704 + return 0;
109705 +
109706 + if (num_fields < 2)
109707 + return 0;
109708 +
109709 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
109710 +
109711 + gcc_assert(num_fields < INT_MAX);
109712 +
109713 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)) ||
109714 + lookup_attribute("no_randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))))
109715 + return 0;
109716 +
109717 + /* throw out any structs in uapi */
109718 + xloc = expand_location(DECL_SOURCE_LOCATION(TYPE_FIELDS(type)));
109719 +
109720 + if (strstr(xloc.file, "/uapi/"))
109721 + error(G_("attempted to randomize userland API struct %s"), ORIG_TYPE_NAME(type));
109722 +
109723 + for (field = TYPE_FIELDS(type), i = 0; field; field = TREE_CHAIN(field), i++) {
109724 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
109725 + newtree[i] = field;
109726 + }
109727 +
109728 + /*
109729 + * enforce that we don't randomize the layout of the last
109730 + * element of a struct if it's a 0 or 1-length array
109731 + * or a proper flexible array
109732 + */
109733 + if (is_flexible_array(newtree[num_fields - 1]))
109734 + shuffle_length--;
109735 +
109736 + shuffle(type, (tree *)newtree, shuffle_length);
109737 +
109738 + /*
109739 + * set up a bogus anonymous struct field designed to error out on unnamed struct initializers
109740 + * as gcc provides no other way to detect such code
109741 + */
109742 + list = make_node(FIELD_DECL);
109743 + TREE_CHAIN(list) = newtree[0];
109744 + TREE_TYPE(list) = void_type_node;
109745 + DECL_SIZE(list) = bitsize_zero_node;
109746 + DECL_NONADDRESSABLE_P(list) = 1;
109747 + DECL_FIELD_BIT_OFFSET(list) = bitsize_zero_node;
109748 + DECL_SIZE_UNIT(list) = size_zero_node;
109749 + DECL_FIELD_OFFSET(list) = size_zero_node;
109750 + // to satisfy the constify plugin
109751 + TREE_READONLY(list) = 1;
109752 +
109753 + for (i = 0; i < num_fields - 1; i++)
109754 + TREE_CHAIN(newtree[i]) = newtree[i+1];
109755 + TREE_CHAIN(newtree[num_fields - 1]) = NULL_TREE;
109756 +
109757 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
109758 + TYPE_FIELDS(variant) = list;
109759 + TYPE_ATTRIBUTES(variant) = copy_list(TYPE_ATTRIBUTES(variant));
109760 + TYPE_ATTRIBUTES(variant) = tree_cons(get_identifier("randomize_performed"), NULL_TREE, TYPE_ATTRIBUTES(variant));
109761 + // force a re-layout
109762 + TYPE_SIZE(variant) = NULL_TREE;
109763 + layout_type(variant);
109764 + }
109765 +
109766 + return 1;
109767 +}
109768 +
109769 +/* from constify plugin */
109770 +static const_tree get_field_type(const_tree field)
109771 +{
109772 + return strip_array_types(TREE_TYPE(field));
109773 +}
109774 +
109775 +/* from constify plugin */
109776 +static bool is_fptr(const_tree fieldtype)
109777 +{
109778 + if (TREE_CODE(fieldtype) != POINTER_TYPE)
109779 + return false;
109780 +
109781 + return TREE_CODE(TREE_TYPE(fieldtype)) == FUNCTION_TYPE;
109782 +}
109783 +
109784 +/* derived from constify plugin */
109785 +static int is_pure_ops_struct(const_tree node)
109786 +{
109787 + const_tree field;
109788 +
109789 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
109790 +
109791 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
109792 + const_tree fieldtype = get_field_type(field);
109793 + enum tree_code code = TREE_CODE(fieldtype);
109794 +
109795 + if (node == fieldtype)
109796 + continue;
109797 +
109798 + if (!is_fptr(fieldtype))
109799 + return 0;
109800 +
109801 + if (code != RECORD_TYPE && code != UNION_TYPE)
109802 + continue;
109803 +
109804 + if (!is_pure_ops_struct(fieldtype))
109805 + return 0;
109806 + }
109807 +
109808 + return 1;
109809 +}
109810 +
109811 +static void randomize_type(tree type)
109812 +{
109813 + tree variant;
109814 +
109815 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
109816 +
109817 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
109818 + return;
109819 +
109820 + if (lookup_attribute("randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))) || is_pure_ops_struct(type))
109821 + relayout_struct(type);
109822 +
109823 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
109824 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
109825 + TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("randomize_considered"), NULL_TREE, TYPE_ATTRIBUTES(type));
109826 + }
109827 +#ifdef __DEBUG_PLUGIN
109828 + fprintf(stderr, "Marking randomize_considered on struct %s\n", ORIG_TYPE_NAME(type));
109829 +#ifdef __DEBUG_VERBOSE
109830 + debug_tree(type);
109831 +#endif
109832 +#endif
109833 +}
109834 +
109835 +static void randomize_layout_finish_decl(void *event_data, void *data)
109836 +{
109837 + tree decl = (tree)event_data;
109838 + tree type;
109839 +
109840 + if (decl == NULL_TREE || decl == error_mark_node)
109841 + return;
109842 +
109843 + type = TREE_TYPE(decl);
109844 +
109845 + if (TREE_CODE(decl) != VAR_DECL)
109846 + return;
109847 +
109848 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
109849 + return;
109850 +
109851 + if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)))
109852 + return;
109853 +
109854 + relayout_decl(decl);
109855 +}
109856 +
109857 +static void finish_type(void *event_data, void *data)
109858 +{
109859 + tree type = (tree)event_data;
109860 +
109861 + if (type == NULL_TREE || type == error_mark_node)
109862 + return;
109863 +
109864 + if (TREE_CODE(type) != RECORD_TYPE)
109865 + return;
109866 +
109867 + if (TYPE_FIELDS(type) == NULL_TREE)
109868 + return;
109869 +
109870 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
109871 + return;
109872 +
109873 +#ifdef __DEBUG_PLUGIN
109874 + fprintf(stderr, "Calling randomize_type on %s\n", ORIG_TYPE_NAME(type));
109875 +#endif
109876 +#ifdef __DEBUG_VERBOSE
109877 + debug_tree(type);
109878 +#endif
109879 + randomize_type(type);
109880 +
109881 + return;
109882 +}
109883 +
109884 +static struct attribute_spec randomize_layout_attr = {
109885 + .name = "randomize_layout",
109886 + // related to args
109887 + .min_length = 0,
109888 + .max_length = 0,
109889 + .decl_required = false,
109890 + // need type declaration
109891 + .type_required = true,
109892 + .function_type_required = false,
109893 + .handler = handle_randomize_layout_attr,
109894 +#if BUILDING_GCC_VERSION >= 4007
109895 + .affects_type_identity = true
109896 +#endif
109897 +};
109898 +
109899 +static struct attribute_spec no_randomize_layout_attr = {
109900 + .name = "no_randomize_layout",
109901 + // related to args
109902 + .min_length = 0,
109903 + .max_length = 0,
109904 + .decl_required = false,
109905 + // need type declaration
109906 + .type_required = true,
109907 + .function_type_required = false,
109908 + .handler = handle_randomize_layout_attr,
109909 +#if BUILDING_GCC_VERSION >= 4007
109910 + .affects_type_identity = true
109911 +#endif
109912 +};
109913 +
109914 +static struct attribute_spec randomize_considered_attr = {
109915 + .name = "randomize_considered",
109916 + // related to args
109917 + .min_length = 0,
109918 + .max_length = 0,
109919 + .decl_required = false,
109920 + // need type declaration
109921 + .type_required = true,
109922 + .function_type_required = false,
109923 + .handler = handle_randomize_considered_attr,
109924 +#if BUILDING_GCC_VERSION >= 4007
109925 + .affects_type_identity = false
109926 +#endif
109927 +};
109928 +
109929 +static struct attribute_spec randomize_performed_attr = {
109930 + .name = "randomize_performed",
109931 + // related to args
109932 + .min_length = 0,
109933 + .max_length = 0,
109934 + .decl_required = false,
109935 + // need type declaration
109936 + .type_required = true,
109937 + .function_type_required = false,
109938 + .handler = handle_randomize_performed_attr,
109939 +#if BUILDING_GCC_VERSION >= 4007
109940 + .affects_type_identity = false
109941 +#endif
109942 +};
109943 +
109944 +static void register_attributes(void *event_data, void *data)
109945 +{
109946 + register_attribute(&randomize_layout_attr);
109947 + register_attribute(&no_randomize_layout_attr);
109948 + register_attribute(&randomize_considered_attr);
109949 + register_attribute(&randomize_performed_attr);
109950 +}
109951 +
109952 +static void check_bad_casts_in_constructor(tree var, tree init)
109953 +{
109954 + unsigned HOST_WIDE_INT idx;
109955 + tree field, val;
109956 + tree field_type, val_type;
109957 +
109958 + FOR_EACH_CONSTRUCTOR_ELT(CONSTRUCTOR_ELTS(init), idx, field, val) {
109959 + if (TREE_CODE(val) == CONSTRUCTOR) {
109960 + check_bad_casts_in_constructor(var, val);
109961 + continue;
109962 + }
109963 +
109964 + /* pipacs' plugin creates franken-arrays that differ from those produced by
109965 + normal code which all have valid 'field' trees. work around this */
109966 + if (field == NULL_TREE)
109967 + continue;
109968 + field_type = TREE_TYPE(field);
109969 + val_type = TREE_TYPE(val);
109970 +
109971 + if (TREE_CODE(field_type) != POINTER_TYPE || TREE_CODE(val_type) != POINTER_TYPE)
109972 + continue;
109973 +
109974 + if (field_type == val_type)
109975 + continue;
109976 +
109977 + field_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(field_type))));
109978 + val_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(val_type))));
109979 +
109980 + if (field_type == void_type_node)
109981 + continue;
109982 + if (field_type == val_type)
109983 + continue;
109984 + if (TREE_CODE(val_type) != RECORD_TYPE)
109985 + continue;
109986 +
109987 + if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(val_type)))
109988 + continue;
109989 + inform(DECL_SOURCE_LOCATION(var), "found mismatched struct pointer types: %qT and %qT\n", TYPE_MAIN_VARIANT(field_type), TYPE_MAIN_VARIANT(val_type));
109990 + }
109991 +}
109992 +
109993 +/* derived from the constify plugin */
109994 +static void check_global_variables(void *event_data, void *data)
109995 +{
109996 + struct varpool_node *node;
109997 + tree init;
109998 +
109999 + FOR_EACH_VARIABLE(node) {
110000 + tree var = NODE_DECL(node);
110001 + init = DECL_INITIAL(var);
110002 + if (init == NULL_TREE)
110003 + continue;
110004 +
110005 + if (TREE_CODE(init) != CONSTRUCTOR)
110006 + continue;
110007 +
110008 + check_bad_casts_in_constructor(var, init);
110009 + }
110010 +}
110011 +
110012 +static bool dominated_by_is_err(const_tree rhs, basic_block bb)
110013 +{
110014 + basic_block dom;
110015 + gimple dom_stmt;
110016 + gimple call_stmt;
110017 + const_tree dom_lhs;
110018 + const_tree poss_is_err_cond;
110019 + const_tree poss_is_err_func;
110020 + const_tree is_err_arg;
110021 +
110022 + dom = get_immediate_dominator(CDI_DOMINATORS, bb);
110023 + if (!dom)
110024 + return false;
110025 +
110026 + dom_stmt = last_stmt(dom);
110027 + if (!dom_stmt)
110028 + return false;
110029 +
110030 + if (gimple_code(dom_stmt) != GIMPLE_COND)
110031 + return false;
110032 +
110033 + if (gimple_cond_code(dom_stmt) != NE_EXPR)
110034 + return false;
110035 +
110036 + if (!integer_zerop(gimple_cond_rhs(dom_stmt)))
110037 + return false;
110038 +
110039 + poss_is_err_cond = gimple_cond_lhs(dom_stmt);
110040 +
110041 + if (TREE_CODE(poss_is_err_cond) != SSA_NAME)
110042 + return false;
110043 +
110044 + call_stmt = SSA_NAME_DEF_STMT(poss_is_err_cond);
110045 +
110046 + if (gimple_code(call_stmt) != GIMPLE_CALL)
110047 + return false;
110048 +
110049 + dom_lhs = gimple_get_lhs(call_stmt);
110050 + poss_is_err_func = gimple_call_fndecl(call_stmt);
110051 + if (!poss_is_err_func)
110052 + return false;
110053 + if (dom_lhs != poss_is_err_cond)
110054 + return false;
110055 + if (strcmp(DECL_NAME_POINTER(poss_is_err_func), "IS_ERR"))
110056 + return false;
110057 +
110058 + is_err_arg = gimple_call_arg(call_stmt, 0);
110059 + if (!is_err_arg)
110060 + return false;
110061 +
110062 + if (is_err_arg != rhs)
110063 + return false;
110064 +
110065 + return true;
110066 +}
110067 +
110068 +static void handle_local_var_initializers(void)
110069 +{
110070 + tree var;
110071 + unsigned int i;
110072 +
110073 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
110074 + tree init = DECL_INITIAL(var);
110075 + if (!init)
110076 + continue;
110077 + if (TREE_CODE(init) != CONSTRUCTOR)
110078 + continue;
110079 + check_bad_casts_in_constructor(var, init);
110080 + }
110081 +}
110082 +
110083 +/*
110084 + * iterate over all statements to find "bad" casts:
110085 + * those where the address of the start of a structure is cast
110086 + * to a pointer of a structure of a different type, or a
110087 + * structure pointer type is cast to a different structure pointer type
110088 + */
110089 +static unsigned int find_bad_casts(void)
110090 +{
110091 + basic_block bb;
110092 +
110093 + handle_local_var_initializers();
110094 +
110095 + FOR_ALL_BB_FN(bb, cfun) {
110096 + gimple_stmt_iterator gsi;
110097 +
110098 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
110099 + gimple stmt;
110100 + const_tree lhs;
110101 + const_tree lhs_type;
110102 + const_tree rhs1;
110103 + const_tree rhs_type;
110104 + const_tree ptr_lhs_type;
110105 + const_tree ptr_rhs_type;
110106 + const_tree op0;
110107 + const_tree op0_type;
110108 + enum tree_code rhs_code;
110109 +
110110 + stmt = gsi_stmt(gsi);
110111 +
110112 +#ifdef __DEBUG_PLUGIN
110113 +#ifdef __DEBUG_VERBOSE
110114 + debug_gimple_stmt(stmt);
110115 + debug_tree(gimple_get_lhs(stmt));
110116 +#endif
110117 +#endif
110118 +
110119 + if (gimple_code(stmt) != GIMPLE_ASSIGN)
110120 + continue;
110121 +
110122 +#ifdef __DEBUG_PLUGIN
110123 +#ifdef __DEBUG_VERBOSE
110124 + debug_tree(gimple_assign_rhs1(stmt));
110125 +#endif
110126 +#endif
110127 +
110128 + rhs_code = gimple_assign_rhs_code(stmt);
110129 +
110130 + if (rhs_code != ADDR_EXPR && rhs_code != SSA_NAME)
110131 + continue;
110132 +
110133 + lhs = gimple_get_lhs(stmt);
110134 + lhs_type = TREE_TYPE(lhs);
110135 + rhs1 = gimple_assign_rhs1(stmt);
110136 + rhs_type = TREE_TYPE(rhs1);
110137 +
110138 + if (TREE_CODE(rhs_type) != POINTER_TYPE ||
110139 + TREE_CODE(lhs_type) != POINTER_TYPE)
110140 + continue;
110141 +
110142 + ptr_lhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(lhs_type))));
110143 + ptr_rhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(rhs_type))));
110144 +
110145 + if (ptr_rhs_type == void_type_node)
110146 + continue;
110147 +
110148 + if (ptr_lhs_type == void_type_node)
110149 + continue;
110150 +
110151 + if (dominated_by_is_err(rhs1, bb))
110152 + continue;
110153 +
110154 + if (TREE_CODE(ptr_rhs_type) != RECORD_TYPE) {
110155 +#ifndef __DEBUG_PLUGIN
110156 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_lhs_type)))
110157 +#endif
110158 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
110159 + continue;
110160 + }
110161 +
110162 + if (rhs_code == SSA_NAME && ptr_lhs_type == ptr_rhs_type)
110163 + continue;
110164 +
110165 + if (rhs_code == ADDR_EXPR) {
110166 + op0 = TREE_OPERAND(rhs1, 0);
110167 +
110168 + if (op0 == NULL_TREE)
110169 + continue;
110170 +
110171 + if (TREE_CODE(op0) != VAR_DECL)
110172 + continue;
110173 +
110174 + op0_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(op0))));
110175 + if (op0_type == ptr_lhs_type)
110176 + continue;
110177 +
110178 +#ifndef __DEBUG_PLUGIN
110179 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(op0_type)))
110180 +#endif
110181 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, op0_type);
110182 + } else {
110183 + const_tree ssa_name_var = SSA_NAME_VAR(rhs1);
110184 + /* skip bogus type casts introduced by container_of */
110185 + if (ssa_name_var != NULL_TREE && DECL_NAME(ssa_name_var) &&
110186 + !strcmp((const char *)DECL_NAME_POINTER(ssa_name_var), "__mptr"))
110187 + continue;
110188 +#ifndef __DEBUG_PLUGIN
110189 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_rhs_type)))
110190 +#endif
110191 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
110192 + }
110193 +
110194 + }
110195 + }
110196 + return 0;
110197 +}
110198 +
110199 +#if BUILDING_GCC_VERSION >= 4009
110200 +static const struct pass_data randomize_layout_bad_cast_data = {
110201 +#else
110202 +static struct gimple_opt_pass randomize_layout_bad_cast = {
110203 + .pass = {
110204 +#endif
110205 + .type = GIMPLE_PASS,
110206 + .name = "randomize_layout_bad_cast",
110207 +#if BUILDING_GCC_VERSION >= 4008
110208 + .optinfo_flags = OPTGROUP_NONE,
110209 +#endif
110210 +#if BUILDING_GCC_VERSION >= 4009
110211 + .has_gate = false,
110212 + .has_execute = true,
110213 +#else
110214 + .gate = NULL,
110215 + .execute = find_bad_casts,
110216 + .sub = NULL,
110217 + .next = NULL,
110218 + .static_pass_number = 0,
110219 +#endif
110220 + .tv_id = TV_NONE,
110221 + .properties_required = PROP_cfg,
110222 + .properties_provided = 0,
110223 + .properties_destroyed = 0,
110224 + .todo_flags_start = 0,
110225 + .todo_flags_finish = TODO_dump_func
110226 +#if BUILDING_GCC_VERSION < 4009
110227 + }
110228 +#endif
110229 +};
110230 +
110231 +#if BUILDING_GCC_VERSION >= 4009
110232 +namespace {
110233 +class randomize_layout_bad_cast : public gimple_opt_pass {
110234 +public:
110235 + randomize_layout_bad_cast() : gimple_opt_pass(randomize_layout_bad_cast_data, g) {}
110236 + unsigned int execute() { return find_bad_casts(); }
110237 +};
110238 +}
110239 +#endif
110240 +
110241 +static struct opt_pass *make_randomize_layout_bad_cast(void)
110242 +{
110243 +#if BUILDING_GCC_VERSION >= 4009
110244 + return new randomize_layout_bad_cast();
110245 +#else
110246 + return &randomize_layout_bad_cast.pass;
110247 +#endif
110248 +}
110249 +
110250 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
110251 +{
110252 + int i;
110253 + const char * const plugin_name = plugin_info->base_name;
110254 + const int argc = plugin_info->argc;
110255 + const struct plugin_argument * const argv = plugin_info->argv;
110256 + bool enable = true;
110257 + int obtained_seed = 0;
110258 + struct register_pass_info randomize_layout_bad_cast_info;
110259 +
110260 + randomize_layout_bad_cast_info.pass = make_randomize_layout_bad_cast();
110261 + randomize_layout_bad_cast_info.reference_pass_name = "ssa";
110262 + randomize_layout_bad_cast_info.ref_pass_instance_number = 1;
110263 + randomize_layout_bad_cast_info.pos_op = PASS_POS_INSERT_AFTER;
110264 +
110265 + if (!plugin_default_version_check(version, &gcc_version)) {
110266 + error(G_("incompatible gcc/plugin versions"));
110267 + return 1;
110268 + }
110269 +
110270 + if (strcmp(lang_hooks.name, "GNU C")) {
110271 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
110272 + enable = false;
110273 + }
110274 +
110275 + for (i = 0; i < argc; ++i) {
110276 + if (!strcmp(argv[i].key, "disable")) {
110277 + enable = false;
110278 + continue;
110279 + }
110280 + if (!strcmp(argv[i].key, "performance-mode")) {
110281 + performance_mode = 1;
110282 + continue;
110283 + }
110284 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
110285 + }
110286 +
110287 + if (strlen(randstruct_seed) != 64) {
110288 + error(G_("invalid seed value supplied for %s plugin"), plugin_name);
110289 + return 1;
110290 + }
110291 + obtained_seed = sscanf(randstruct_seed, "%016llx%016llx%016llx%016llx",
110292 + &shuffle_seed[0], &shuffle_seed[1], &shuffle_seed[2], &shuffle_seed[3]);
110293 + if (obtained_seed != 4) {
110294 + error(G_("Invalid seed supplied for %s plugin"), plugin_name);
110295 + return 1;
110296 + }
110297 +
110298 + register_callback(plugin_name, PLUGIN_INFO, NULL, &randomize_layout_plugin_info);
110299 + if (enable) {
110300 + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
110301 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &randomize_layout_bad_cast_info);
110302 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
110303 + register_callback(plugin_name, PLUGIN_FINISH_DECL, randomize_layout_finish_decl, NULL);
110304 + }
110305 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
110306 +
110307 + return 0;
110308 +}
110309 diff --git a/tools/gcc/size_overflow_plugin/.gitignore b/tools/gcc/size_overflow_plugin/.gitignore
110310 new file mode 100644
110311 index 0000000..1f0214f
110312 --- /dev/null
110313 +++ b/tools/gcc/size_overflow_plugin/.gitignore
110314 @@ -0,0 +1,3 @@
110315 +randomize_layout_seed.h
110316 +size_overflow_hash.h
110317 +size_overflow_hash_aux.h
110318 diff --git a/tools/gcc/size_overflow_plugin/Makefile b/tools/gcc/size_overflow_plugin/Makefile
110319 new file mode 100644
110320 index 0000000..1ae2ed5
110321 --- /dev/null
110322 +++ b/tools/gcc/size_overflow_plugin/Makefile
110323 @@ -0,0 +1,20 @@
110324 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
110325 +always := $($(HOSTLIBS)-y)
110326 +
110327 +size_overflow_plugin-objs := $(patsubst $(srctree)/$(src)/%.c,%.o,$(wildcard $(srctree)/$(src)/*.c))
110328 +
110329 +$(patsubst $(srctree)/$(src)/%.c,$(obj)/%.o,$(wildcard $(srctree)/$(src)/*.c)): $(objtree)/$(obj)/size_overflow_hash.h $(objtree)/$(obj)/size_overflow_hash_aux.h
110330 +
110331 +quiet_cmd_build_size_overflow_hash = GENHASH $@
110332 + cmd_build_size_overflow_hash = \
110333 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -s size_overflow_hash -d $< -o $@
110334 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
110335 + $(call if_changed,build_size_overflow_hash)
110336 +
110337 +quiet_cmd_build_size_overflow_hash_aux = GENHASH $@
110338 + cmd_build_size_overflow_hash_aux = \
110339 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -s size_overflow_hash_aux -d $< -o $@
110340 +$(objtree)/$(obj)/size_overflow_hash_aux.h: $(src)/size_overflow_hash_aux.data FORCE
110341 + $(call if_changed,build_size_overflow_hash_aux)
110342 +
110343 +targets += size_overflow_hash.h size_overflow_hash_aux.h
110344 diff --git a/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh b/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh
110345 new file mode 100644
110346 index 0000000..12b1e3b
110347 --- /dev/null
110348 +++ b/tools/gcc/size_overflow_plugin/generate_size_overflow_hash.sh
110349 @@ -0,0 +1,102 @@
110350 +#!/bin/bash
110351 +
110352 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
110353 +
110354 +header1="size_overflow_hash.h"
110355 +database="size_overflow_hash.data"
110356 +n=65536
110357 +hashtable_name="size_overflow_hash"
110358 +
110359 +usage() {
110360 +cat <<EOF
110361 +usage: $0 options
110362 +OPTIONS:
110363 + -h|--help help
110364 + -o header file
110365 + -d database file
110366 + -n hash array size
110367 + -s name of the hash table
110368 +EOF
110369 + return 0
110370 +}
110371 +
110372 +while true
110373 +do
110374 + case "$1" in
110375 + -h|--help) usage && exit 0;;
110376 + -n) n=$2; shift 2;;
110377 + -o) header1="$2"; shift 2;;
110378 + -d) database="$2"; shift 2;;
110379 + -s) hashtable_name="$2"; shift 2;;
110380 + --) shift 1; break ;;
110381 + *) break ;;
110382 + esac
110383 +done
110384 +
110385 +create_defines() {
110386 + for i in `seq 0 31`
110387 + do
110388 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
110389 + done
110390 + echo >> "$header1"
110391 +}
110392 +
110393 +create_structs() {
110394 + rm -f "$header1"
110395 +
110396 + create_defines
110397 +
110398 + cat "$database" | while read data
110399 + do
110400 + data_array=($data)
110401 + struct_hash_name="${data_array[0]}"
110402 + funcn="${data_array[1]}"
110403 + params="${data_array[2]}"
110404 + next="${data_array[4]}"
110405 +
110406 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
110407 +
110408 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
110409 + echo -en "\t.param\t= " >> "$header1"
110410 + line=
110411 + for param_num in ${params//-/ };
110412 + do
110413 + line="${line}PARAM"$param_num"|"
110414 + done
110415 +
110416 + echo -e "${line%?},\n};\n" >> "$header1"
110417 + done
110418 +}
110419 +
110420 +create_headers() {
110421 + echo "const struct size_overflow_hash * const $hashtable_name[$n] = {" >> "$header1"
110422 +}
110423 +
110424 +create_array_elements() {
110425 + index=0
110426 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
110427 + do
110428 + data_array=($data)
110429 + i="${data_array[3]}"
110430 + hash="${data_array[0]}"
110431 + while [[ $index -lt $i ]]
110432 + do
110433 + echo -e "\t["$index"]\t= NULL," >> "$header1"
110434 + index=$(($index + 1))
110435 + done
110436 + index=$(($index + 1))
110437 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
110438 + done
110439 + echo '};' >> $header1
110440 +}
110441 +
110442 +size_overflow_plugin_dir=`dirname $header1`
110443 +if [ "$size_overflow_plugin_dir" != '.' ]; then
110444 + mkdir -p "$size_overflow_plugin_dir" 2> /dev/null
110445 +fi
110446 +
110447 +create_structs
110448 +create_headers
110449 +create_array_elements
110450 +
110451 +exit 0
110452 diff --git a/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c b/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c
110453 new file mode 100644
110454 index 0000000..3e8148c
110455 --- /dev/null
110456 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_asm.c
110457 @@ -0,0 +1,790 @@
110458 +/*
110459 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
110460 + * Licensed under the GPL v2, or (at your option) v3
110461 + *
110462 + * Homepage:
110463 + * http://www.grsecurity.net/~ephox/overflow_plugin/
110464 + *
110465 + * Documentation:
110466 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
110467 + *
110468 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
110469 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
110470 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
110471 + *
110472 + * Usage:
110473 + * $ make
110474 + * $ make run
110475 + */
110476 +
110477 +#include "gcc-common.h"
110478 +#include "size_overflow.h"
110479 +
110480 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs);
110481 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs);
110482 +
110483 +// data for the size_overflow asm stmt
110484 +struct asm_data {
110485 + gimple def_stmt;
110486 + tree input;
110487 + tree output;
110488 +};
110489 +
110490 +#if BUILDING_GCC_VERSION <= 4007
110491 +static VEC(tree, gc) *create_asm_io_list(tree string, tree io)
110492 +#else
110493 +static vec<tree, va_gc> *create_asm_io_list(tree string, tree io)
110494 +#endif
110495 +{
110496 + tree list;
110497 +#if BUILDING_GCC_VERSION <= 4007
110498 + VEC(tree, gc) *vec_list = NULL;
110499 +#else
110500 + vec<tree, va_gc> *vec_list = NULL;
110501 +#endif
110502 +
110503 + list = build_tree_list(NULL_TREE, string);
110504 + list = chainon(NULL_TREE, build_tree_list(list, io));
110505 +#if BUILDING_GCC_VERSION <= 4007
110506 + VEC_safe_push(tree, gc, vec_list, list);
110507 +#else
110508 + vec_safe_push(vec_list, list);
110509 +#endif
110510 + return vec_list;
110511 +}
110512 +
110513 +static void create_asm_stmt(const char *str, tree str_input, tree str_output, struct asm_data *asm_data)
110514 +{
110515 + gimple asm_stmt;
110516 + gimple_stmt_iterator gsi;
110517 +#if BUILDING_GCC_VERSION <= 4007
110518 + VEC(tree, gc) *input, *output = NULL;
110519 +#else
110520 + vec<tree, va_gc> *input, *output = NULL;
110521 +#endif
110522 +
110523 + input = create_asm_io_list(str_input, asm_data->input);
110524 +
110525 + if (asm_data->output)
110526 + output = create_asm_io_list(str_output, asm_data->output);
110527 +
110528 + asm_stmt = gimple_build_asm_vec(str, input, output, NULL, NULL);
110529 + gsi = gsi_for_stmt(asm_data->def_stmt);
110530 + gsi_insert_after(&gsi, asm_stmt, GSI_NEW_STMT);
110531 +
110532 + if (asm_data->output)
110533 + SSA_NAME_DEF_STMT(asm_data->output) = asm_stmt;
110534 +}
110535 +
110536 +static void replace_call_lhs(const struct asm_data *asm_data)
110537 +{
110538 + gimple_set_lhs(asm_data->def_stmt, asm_data->input);
110539 + update_stmt(asm_data->def_stmt);
110540 + SSA_NAME_DEF_STMT(asm_data->input) = asm_data->def_stmt;
110541 +}
110542 +
110543 +static enum mark search_intentional_phi(struct pointer_set_t *visited, const_tree result)
110544 +{
110545 + enum mark cur_fndecl_attr;
110546 + gimple phi = get_def_stmt(result);
110547 + unsigned int i, n = gimple_phi_num_args(phi);
110548 +
110549 + pointer_set_insert(visited, phi);
110550 + for (i = 0; i < n; i++) {
110551 + tree arg = gimple_phi_arg_def(phi, i);
110552 +
110553 + cur_fndecl_attr = search_intentional(visited, arg);
110554 + if (cur_fndecl_attr != MARK_NO)
110555 + return cur_fndecl_attr;
110556 + }
110557 + return MARK_NO;
110558 +}
110559 +
110560 +static enum mark search_intentional_binary(struct pointer_set_t *visited, const_tree lhs)
110561 +{
110562 + enum mark cur_fndecl_attr;
110563 + const_tree rhs1, rhs2;
110564 + gimple def_stmt = get_def_stmt(lhs);
110565 +
110566 + rhs1 = gimple_assign_rhs1(def_stmt);
110567 + rhs2 = gimple_assign_rhs2(def_stmt);
110568 +
110569 + cur_fndecl_attr = search_intentional(visited, rhs1);
110570 + if (cur_fndecl_attr != MARK_NO)
110571 + return cur_fndecl_attr;
110572 + return search_intentional(visited, rhs2);
110573 +}
110574 +
110575 +// Look up the intentional_overflow attribute on the caller and the callee functions.
110576 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs)
110577 +{
110578 + const_gimple def_stmt;
110579 +
110580 + if (TREE_CODE(lhs) != SSA_NAME)
110581 + return get_intentional_attr_type(lhs);
110582 +
110583 + def_stmt = get_def_stmt(lhs);
110584 + if (!def_stmt)
110585 + return MARK_NO;
110586 +
110587 + if (pointer_set_contains(visited, def_stmt))
110588 + return MARK_NO;
110589 +
110590 + switch (gimple_code(def_stmt)) {
110591 + case GIMPLE_NOP:
110592 + return search_intentional(visited, SSA_NAME_VAR(lhs));
110593 + case GIMPLE_ASM:
110594 + if (is_size_overflow_intentional_asm_turn_off(def_stmt))
110595 + return MARK_TURN_OFF;
110596 + return MARK_NO;
110597 + case GIMPLE_CALL:
110598 + return MARK_NO;
110599 + case GIMPLE_PHI:
110600 + return search_intentional_phi(visited, lhs);
110601 + case GIMPLE_ASSIGN:
110602 + switch (gimple_num_ops(def_stmt)) {
110603 + case 2:
110604 + return search_intentional(visited, gimple_assign_rhs1(def_stmt));
110605 + case 3:
110606 + return search_intentional_binary(visited, lhs);
110607 + }
110608 + case GIMPLE_RETURN:
110609 + return MARK_NO;
110610 + default:
110611 + debug_gimple_stmt((gimple)def_stmt);
110612 + error("%s: unknown gimple code", __func__);
110613 + gcc_unreachable();
110614 + }
110615 +}
110616 +
110617 +// Check the intentional_overflow attribute and create the asm comment string for the size_overflow asm stmt.
110618 +static enum mark check_intentional_attribute_gimple(const_tree arg, const_gimple stmt, unsigned int argnum)
110619 +{
110620 + const_tree fndecl;
110621 + struct pointer_set_t *visited;
110622 + enum mark cur_fndecl_attr, decl_attr = MARK_NO;
110623 +
110624 + fndecl = get_interesting_orig_fndecl(stmt, argnum);
110625 + if (is_end_intentional_intentional_attr(fndecl, argnum))
110626 + decl_attr = MARK_NOT_INTENTIONAL;
110627 + else if (is_yes_intentional_attr(fndecl, argnum))
110628 + decl_attr = MARK_YES;
110629 + else if (is_turn_off_intentional_attr(fndecl) || is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
110630 + return MARK_TURN_OFF;
110631 + }
110632 +
110633 + visited = pointer_set_create();
110634 + cur_fndecl_attr = search_intentional(visited, arg);
110635 + pointer_set_destroy(visited);
110636 +
110637 + switch (cur_fndecl_attr) {
110638 + case MARK_NO:
110639 + case MARK_TURN_OFF:
110640 + return cur_fndecl_attr;
110641 + default:
110642 + print_missing_intentional(decl_attr, cur_fndecl_attr, fndecl, argnum);
110643 + return MARK_YES;
110644 + }
110645 +}
110646 +
110647 +static void check_missing_size_overflow_attribute(tree var)
110648 +{
110649 + tree orig_fndecl;
110650 + unsigned int num;
110651 +
110652 + if (is_a_return_check(var))
110653 + orig_fndecl = DECL_ORIGIN(var);
110654 + else
110655 + orig_fndecl = DECL_ORIGIN(current_function_decl);
110656 +
110657 + num = get_function_num(var, orig_fndecl);
110658 + if (num == CANNOT_FIND_ARG)
110659 + return;
110660 +
110661 + is_missing_function(orig_fndecl, num);
110662 +}
110663 +
110664 +static void search_size_overflow_attribute_phi(struct pointer_set_t *visited, const_tree result)
110665 +{
110666 + gimple phi = get_def_stmt(result);
110667 + unsigned int i, n = gimple_phi_num_args(phi);
110668 +
110669 + pointer_set_insert(visited, phi);
110670 + for (i = 0; i < n; i++) {
110671 + tree arg = gimple_phi_arg_def(phi, i);
110672 +
110673 + search_size_overflow_attribute(visited, arg);
110674 + }
110675 +}
110676 +
110677 +static void search_size_overflow_attribute_binary(struct pointer_set_t *visited, const_tree lhs)
110678 +{
110679 + const_gimple def_stmt = get_def_stmt(lhs);
110680 + tree rhs1, rhs2;
110681 +
110682 + rhs1 = gimple_assign_rhs1(def_stmt);
110683 + rhs2 = gimple_assign_rhs2(def_stmt);
110684 +
110685 + search_size_overflow_attribute(visited, rhs1);
110686 + search_size_overflow_attribute(visited, rhs2);
110687 +}
110688 +
110689 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs)
110690 +{
110691 + const_gimple def_stmt;
110692 +
110693 + if (TREE_CODE(lhs) == PARM_DECL) {
110694 + check_missing_size_overflow_attribute(lhs);
110695 + return;
110696 + }
110697 +
110698 + def_stmt = get_def_stmt(lhs);
110699 + if (!def_stmt)
110700 + return;
110701 +
110702 + if (pointer_set_insert(visited, def_stmt))
110703 + return;
110704 +
110705 + switch (gimple_code(def_stmt)) {
110706 + case GIMPLE_NOP:
110707 + return search_size_overflow_attribute(visited, SSA_NAME_VAR(lhs));
110708 + case GIMPLE_ASM:
110709 + return;
110710 + case GIMPLE_CALL: {
110711 + tree fndecl = gimple_call_fndecl(def_stmt);
110712 +
110713 + if (fndecl == NULL_TREE)
110714 + return;
110715 + check_missing_size_overflow_attribute(fndecl);
110716 + return;
110717 + }
110718 + case GIMPLE_PHI:
110719 + return search_size_overflow_attribute_phi(visited, lhs);
110720 + case GIMPLE_ASSIGN:
110721 + switch (gimple_num_ops(def_stmt)) {
110722 + case 2:
110723 + return search_size_overflow_attribute(visited, gimple_assign_rhs1(def_stmt));
110724 + case 3:
110725 + return search_size_overflow_attribute_binary(visited, lhs);
110726 + }
110727 + default:
110728 + debug_gimple_stmt((gimple)def_stmt);
110729 + error("%s: unknown gimple code", __func__);
110730 + gcc_unreachable();
110731 + }
110732 +}
110733 +
110734 +// Search missing entries in the hash table (invoked from the gimple pass)
110735 +static void search_missing_size_overflow_attribute_gimple(const_gimple stmt, unsigned int num)
110736 +{
110737 + tree fndecl = NULL_TREE;
110738 + tree lhs;
110739 + struct pointer_set_t *visited;
110740 +
110741 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl)))
110742 + return;
110743 +
110744 + if (num == 0) {
110745 + gcc_assert(gimple_code(stmt) == GIMPLE_RETURN);
110746 + lhs = gimple_return_retval(stmt);
110747 + } else {
110748 + gcc_assert(is_gimple_call(stmt));
110749 + lhs = gimple_call_arg(stmt, num - 1);
110750 + fndecl = gimple_call_fndecl(stmt);
110751 + }
110752 +
110753 + if (fndecl != NULL_TREE && is_turn_off_intentional_attr(DECL_ORIGIN(fndecl)))
110754 + return;
110755 +
110756 + visited = pointer_set_create();
110757 + search_size_overflow_attribute(visited, lhs);
110758 + pointer_set_destroy(visited);
110759 +}
110760 +
110761 +static void create_output_from_phi(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
110762 +{
110763 + gimple_stmt_iterator gsi;
110764 + gimple assign;
110765 +
110766 + assign = gimple_build_assign(asm_data->input, asm_data->output);
110767 + gsi = gsi_for_stmt(stmt);
110768 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
110769 + asm_data->def_stmt = assign;
110770 +
110771 + asm_data->output = create_new_var(TREE_TYPE(asm_data->output));
110772 + asm_data->output = make_ssa_name(asm_data->output, stmt);
110773 + if (gimple_code(stmt) == GIMPLE_RETURN)
110774 + gimple_return_set_retval(stmt, asm_data->output);
110775 + else
110776 + gimple_call_set_arg(stmt, argnum - 1, asm_data->output);
110777 + update_stmt(stmt);
110778 +}
110779 +
110780 +static char *create_asm_comment(unsigned int argnum, const_gimple stmt , const char *mark_str)
110781 +{
110782 + const char *fn_name;
110783 + char *asm_comment;
110784 + unsigned int len;
110785 +
110786 + if (argnum == 0)
110787 + fn_name = DECL_NAME_POINTER(current_function_decl);
110788 + else
110789 + fn_name = DECL_NAME_POINTER(gimple_call_fndecl(stmt));
110790 +
110791 + len = asprintf(&asm_comment, "%s %s %u", mark_str, fn_name, argnum);
110792 + gcc_assert(len > 0);
110793 +
110794 + return asm_comment;
110795 +}
110796 +
110797 +static const char *convert_mark_to_str(enum mark mark)
110798 +{
110799 + switch (mark) {
110800 + case MARK_NO:
110801 + return OK_ASM_STR;
110802 + case MARK_YES:
110803 + case MARK_NOT_INTENTIONAL:
110804 + return YES_ASM_STR;
110805 + case MARK_TURN_OFF:
110806 + return TURN_OFF_ASM_STR;
110807 + }
110808 +
110809 + gcc_unreachable();
110810 +}
110811 +
110812 +/* Create the input of the size_overflow asm stmt.
110813 + * When the arg of the callee function is a parm_decl it creates this kind of size_overflow asm stmt:
110814 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
110815 + * The input field in asm_data will be empty if there is no need for further size_overflow asm stmt insertion.
110816 + * otherwise create the input (for a phi stmt the output too) of the asm stmt.
110817 + */
110818 +static void create_asm_input(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
110819 +{
110820 + if (!asm_data->def_stmt) {
110821 + asm_data->input = NULL_TREE;
110822 + return;
110823 + }
110824 +
110825 + asm_data->input = create_new_var(TREE_TYPE(asm_data->output));
110826 + asm_data->input = make_ssa_name(asm_data->input, asm_data->def_stmt);
110827 +
110828 + switch (gimple_code(asm_data->def_stmt)) {
110829 + case GIMPLE_ASSIGN:
110830 + case GIMPLE_CALL:
110831 + replace_call_lhs(asm_data);
110832 + break;
110833 + case GIMPLE_PHI:
110834 + create_output_from_phi(stmt, argnum, asm_data);
110835 + break;
110836 + case GIMPLE_NOP: {
110837 + enum mark mark;
110838 + const char *mark_str;
110839 + char *asm_comment;
110840 +
110841 + mark = check_intentional_attribute_gimple(asm_data->output, stmt, argnum);
110842 +
110843 + asm_data->input = asm_data->output;
110844 + asm_data->output = NULL;
110845 + asm_data->def_stmt = stmt;
110846 +
110847 + mark_str = convert_mark_to_str(mark);
110848 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
110849 +
110850 + create_asm_stmt(asm_comment, build_string(3, "rm"), NULL, asm_data);
110851 + free(asm_comment);
110852 + asm_data->input = NULL_TREE;
110853 + break;
110854 + }
110855 + case GIMPLE_ASM:
110856 + if (is_size_overflow_asm(asm_data->def_stmt)) {
110857 + asm_data->input = NULL_TREE;
110858 + break;
110859 + }
110860 + default:
110861 + debug_gimple_stmt(asm_data->def_stmt);
110862 + gcc_unreachable();
110863 + }
110864 +}
110865 +
110866 +/* This is the gimple part of searching for a missing size_overflow attribute. If the intentional_overflow attribute type
110867 + * is of the right kind create the appropriate size_overflow asm stmts:
110868 + * __asm__("# size_overflow" : =rm" D.3344_8 : "0" cicus.4_16);
110869 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
110870 + */
110871 +static void create_size_overflow_asm(gimple stmt, tree output_node, unsigned int argnum)
110872 +{
110873 + struct asm_data asm_data;
110874 + const char *mark_str;
110875 + char *asm_comment;
110876 + enum mark mark;
110877 +
110878 + if (is_gimple_constant(output_node))
110879 + return;
110880 +
110881 + asm_data.output = output_node;
110882 + mark = check_intentional_attribute_gimple(asm_data.output, stmt, argnum);
110883 + if (mark != MARK_TURN_OFF)
110884 + search_missing_size_overflow_attribute_gimple(stmt, argnum);
110885 +
110886 + asm_data.def_stmt = get_def_stmt(asm_data.output);
110887 + if (is_size_overflow_intentional_asm_turn_off(asm_data.def_stmt))
110888 + return;
110889 +
110890 + create_asm_input(stmt, argnum, &asm_data);
110891 + if (asm_data.input == NULL_TREE)
110892 + return;
110893 +
110894 + mark_str = convert_mark_to_str(mark);
110895 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
110896 + create_asm_stmt(asm_comment, build_string(2, "0"), build_string(4, "=rm"), &asm_data);
110897 + free(asm_comment);
110898 +}
110899 +
110900 +// Insert an asm stmt with "MARK_TURN_OFF", "MARK_YES" or "MARK_NOT_INTENTIONAL".
110901 +static bool create_mark_asm(gimple stmt, enum mark mark)
110902 +{
110903 + struct asm_data asm_data;
110904 + const char *asm_str;
110905 +
110906 + switch (mark) {
110907 + case MARK_TURN_OFF:
110908 + asm_str = TURN_OFF_ASM_STR;
110909 + break;
110910 + case MARK_NOT_INTENTIONAL:
110911 + case MARK_YES:
110912 + asm_str = YES_ASM_STR;
110913 + break;
110914 + default:
110915 + gcc_unreachable();
110916 + }
110917 +
110918 + asm_data.def_stmt = stmt;
110919 + asm_data.output = gimple_call_lhs(stmt);
110920 +
110921 + if (asm_data.output == NULL_TREE) {
110922 + asm_data.input = gimple_call_arg(stmt, 0);
110923 + if (is_gimple_constant(asm_data.input))
110924 + return false;
110925 + asm_data.output = NULL;
110926 + create_asm_stmt(asm_str, build_string(3, "rm"), NULL, &asm_data);
110927 + return true;
110928 + }
110929 +
110930 + create_asm_input(stmt, 0, &asm_data);
110931 + gcc_assert(asm_data.input != NULL_TREE);
110932 +
110933 + create_asm_stmt(asm_str, build_string(2, "0"), build_string(4, "=rm"), &asm_data);
110934 + return true;
110935 +}
110936 +
110937 +static bool is_from_cast(const_tree node)
110938 +{
110939 + gimple def_stmt = get_def_stmt(node);
110940 +
110941 + if (!def_stmt)
110942 + return false;
110943 +
110944 + if (gimple_assign_cast_p(def_stmt))
110945 + return true;
110946 +
110947 + return false;
110948 +}
110949 +
110950 +// Skip duplication when there is a minus expr and the type of rhs1 or rhs2 is a pointer_type.
110951 +static bool skip_ptr_minus(gimple stmt)
110952 +{
110953 + const_tree rhs1, rhs2, ptr1_rhs, ptr2_rhs;
110954 +
110955 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
110956 + return false;
110957 +
110958 + rhs1 = gimple_assign_rhs1(stmt);
110959 + if (!is_from_cast(rhs1))
110960 + return false;
110961 +
110962 + rhs2 = gimple_assign_rhs2(stmt);
110963 + if (!is_from_cast(rhs2))
110964 + return false;
110965 +
110966 + ptr1_rhs = gimple_assign_rhs1(get_def_stmt(rhs1));
110967 + ptr2_rhs = gimple_assign_rhs1(get_def_stmt(rhs2));
110968 +
110969 + if (TREE_CODE(TREE_TYPE(ptr1_rhs)) != POINTER_TYPE && TREE_CODE(TREE_TYPE(ptr2_rhs)) != POINTER_TYPE)
110970 + return false;
110971 +
110972 + create_mark_asm(stmt, MARK_YES);
110973 + return true;
110974 +}
110975 +
110976 +static void walk_use_def_ptr(struct pointer_set_t *visited, const_tree lhs)
110977 +{
110978 + gimple def_stmt;
110979 +
110980 + def_stmt = get_def_stmt(lhs);
110981 + if (!def_stmt)
110982 + return;
110983 +
110984 + if (pointer_set_insert(visited, def_stmt))
110985 + return;
110986 +
110987 + switch (gimple_code(def_stmt)) {
110988 + case GIMPLE_NOP:
110989 + case GIMPLE_ASM:
110990 + case GIMPLE_CALL:
110991 + break;
110992 + case GIMPLE_PHI: {
110993 + unsigned int i, n = gimple_phi_num_args(def_stmt);
110994 +
110995 + pointer_set_insert(visited, def_stmt);
110996 +
110997 + for (i = 0; i < n; i++) {
110998 + tree arg = gimple_phi_arg_def(def_stmt, i);
110999 +
111000 + walk_use_def_ptr(visited, arg);
111001 + }
111002 + }
111003 + case GIMPLE_ASSIGN:
111004 + switch (gimple_num_ops(def_stmt)) {
111005 + case 2:
111006 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
111007 + return;
111008 + case 3:
111009 + if (skip_ptr_minus(def_stmt))
111010 + return;
111011 +
111012 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
111013 + walk_use_def_ptr(visited, gimple_assign_rhs2(def_stmt));
111014 + return;
111015 + default:
111016 + return;
111017 + }
111018 + default:
111019 + debug_gimple_stmt((gimple)def_stmt);
111020 + error("%s: unknown gimple code", __func__);
111021 + gcc_unreachable();
111022 + }
111023 +}
111024 +
111025 +// Look for a ptr - ptr expression (e.g., cpuset_common_file_read() s - page)
111026 +static void insert_mark_not_intentional_asm_at_ptr(const_tree arg)
111027 +{
111028 + struct pointer_set_t *visited;
111029 +
111030 + visited = pointer_set_create();
111031 + walk_use_def_ptr(visited, arg);
111032 + pointer_set_destroy(visited);
111033 +}
111034 +
111035 +// Determine the return value and insert the asm stmt to mark the return stmt.
111036 +static void insert_asm_ret(gimple stmt)
111037 +{
111038 + tree ret;
111039 +
111040 + ret = gimple_return_retval(stmt);
111041 + create_size_overflow_asm(stmt, ret, 0);
111042 +}
111043 +
111044 +// Determine the correct arg index and arg and insert the asm stmt to mark the stmt.
111045 +static void insert_asm_arg(gimple stmt, unsigned int orig_argnum)
111046 +{
111047 + tree arg;
111048 + unsigned int argnum;
111049 +
111050 + argnum = get_correct_arg_count(orig_argnum, gimple_call_fndecl(stmt));
111051 + gcc_assert(argnum != 0);
111052 + if (argnum == CANNOT_FIND_ARG)
111053 + return;
111054 +
111055 + arg = gimple_call_arg(stmt, argnum - 1);
111056 + gcc_assert(arg != NULL_TREE);
111057 +
111058 + // skip all ptr - ptr expressions
111059 + insert_mark_not_intentional_asm_at_ptr(arg);
111060 +
111061 + create_size_overflow_asm(stmt, arg, argnum);
111062 +}
111063 +
111064 +// If a function arg or the return value is marked by the size_overflow attribute then set its index in the array.
111065 +static void set_argnum_attribute(const_tree attr, bool *argnums)
111066 +{
111067 + unsigned int argnum;
111068 + tree attr_value;
111069 +
111070 + for (attr_value = TREE_VALUE(attr); attr_value; attr_value = TREE_CHAIN(attr_value)) {
111071 + argnum = TREE_INT_CST_LOW(TREE_VALUE(attr_value));
111072 + argnums[argnum] = true;
111073 + }
111074 +}
111075 +
111076 +// If a function arg or the return value is in the hash table then set its index in the array.
111077 +static void set_argnum_hash(tree fndecl, bool *argnums)
111078 +{
111079 + unsigned int num;
111080 + const struct size_overflow_hash *hash;
111081 +
111082 + hash = get_function_hash(DECL_ORIGIN(fndecl));
111083 + if (!hash)
111084 + return;
111085 +
111086 + for (num = 0; num <= MAX_PARAM; num++) {
111087 + if (!(hash->param & (1U << num)))
111088 + continue;
111089 +
111090 + argnums[num] = true;
111091 + }
111092 +}
111093 +
111094 +static bool is_all_the_argnums_empty(bool *argnums)
111095 +{
111096 + unsigned int i;
111097 +
111098 + for (i = 0; i <= MAX_PARAM; i++)
111099 + if (argnums[i])
111100 + return false;
111101 + return true;
111102 +}
111103 +
111104 +// Check whether the arguments or the return value of the function are in the hash table or are marked by the size_overflow attribute.
111105 +static void search_interesting_args(tree fndecl, bool *argnums)
111106 +{
111107 + const_tree attr;
111108 +
111109 + set_argnum_hash(fndecl, argnums);
111110 + if (!is_all_the_argnums_empty(argnums))
111111 + return;
111112 +
111113 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
111114 + if (attr && TREE_VALUE(attr))
111115 + set_argnum_attribute(attr, argnums);
111116 +}
111117 +
111118 +/*
111119 + * Look up the intentional_overflow attribute that turns off ipa based duplication
111120 + * on the callee function.
111121 + */
111122 +static bool is_mark_turn_off_attribute(gimple stmt)
111123 +{
111124 + enum mark mark;
111125 + const_tree fndecl = gimple_call_fndecl(stmt);
111126 +
111127 + mark = get_intentional_attr_type(DECL_ORIGIN(fndecl));
111128 + if (mark == MARK_TURN_OFF)
111129 + return true;
111130 + return false;
111131 +}
111132 +
111133 +// 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
111134 +static void handle_interesting_function(gimple stmt)
111135 +{
111136 + unsigned int argnum;
111137 + tree fndecl;
111138 + bool orig_argnums[MAX_PARAM + 1] = {false};
111139 +
111140 + if (gimple_call_num_args(stmt) == 0)
111141 + return;
111142 + fndecl = gimple_call_fndecl(stmt);
111143 + if (fndecl == NULL_TREE)
111144 + return;
111145 + fndecl = DECL_ORIGIN(fndecl);
111146 +
111147 + if (is_mark_turn_off_attribute(stmt)) {
111148 + create_mark_asm(stmt, MARK_TURN_OFF);
111149 + return;
111150 + }
111151 +
111152 + search_interesting_args(fndecl, orig_argnums);
111153 +
111154 + for (argnum = 1; argnum < MAX_PARAM; argnum++)
111155 + if (orig_argnums[argnum])
111156 + insert_asm_arg(stmt, argnum);
111157 +}
111158 +
111159 +// 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
111160 +static void handle_interesting_ret(gimple stmt)
111161 +{
111162 + bool orig_argnums[MAX_PARAM + 1] = {false};
111163 +
111164 + search_interesting_args(current_function_decl, orig_argnums);
111165 +
111166 + if (orig_argnums[0])
111167 + insert_asm_ret(stmt);
111168 +}
111169 +
111170 +// Iterate over all the stmts and search for call and return stmts and mark them if they're in the hash table
111171 +static unsigned int search_interesting_functions(void)
111172 +{
111173 + basic_block bb;
111174 +
111175 + FOR_ALL_BB_FN(bb, cfun) {
111176 + gimple_stmt_iterator gsi;
111177 +
111178 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
111179 + gimple stmt = gsi_stmt(gsi);
111180 +
111181 + if (is_size_overflow_asm(stmt))
111182 + continue;
111183 +
111184 + if (is_gimple_call(stmt))
111185 + handle_interesting_function(stmt);
111186 + else if (gimple_code(stmt) == GIMPLE_RETURN)
111187 + handle_interesting_ret(stmt);
111188 + }
111189 + }
111190 + return 0;
111191 +}
111192 +
111193 +/*
111194 + * A lot of functions get inlined before the ipa passes so after the build_ssa gimple pass
111195 + * this pass inserts asm stmts to mark the interesting args
111196 + * that the ipa pass will detect and insert the size overflow checks for.
111197 + */
111198 +#if BUILDING_GCC_VERSION >= 4009
111199 +static const struct pass_data insert_size_overflow_asm_pass_data = {
111200 +#else
111201 +static struct gimple_opt_pass insert_size_overflow_asm_pass = {
111202 + .pass = {
111203 +#endif
111204 + .type = GIMPLE_PASS,
111205 + .name = "insert_size_overflow_asm",
111206 +#if BUILDING_GCC_VERSION >= 4008
111207 + .optinfo_flags = OPTGROUP_NONE,
111208 +#endif
111209 +#if BUILDING_GCC_VERSION >= 4009
111210 + .has_gate = false,
111211 + .has_execute = true,
111212 +#else
111213 + .gate = NULL,
111214 + .execute = search_interesting_functions,
111215 + .sub = NULL,
111216 + .next = NULL,
111217 + .static_pass_number = 0,
111218 +#endif
111219 + .tv_id = TV_NONE,
111220 + .properties_required = PROP_cfg,
111221 + .properties_provided = 0,
111222 + .properties_destroyed = 0,
111223 + .todo_flags_start = 0,
111224 + .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
111225 +#if BUILDING_GCC_VERSION < 4009
111226 + }
111227 +#endif
111228 +};
111229 +
111230 +#if BUILDING_GCC_VERSION >= 4009
111231 +namespace {
111232 +class insert_size_overflow_asm_pass : public gimple_opt_pass {
111233 +public:
111234 + insert_size_overflow_asm_pass() : gimple_opt_pass(insert_size_overflow_asm_pass_data, g) {}
111235 + unsigned int execute() { return search_interesting_functions(); }
111236 +};
111237 +}
111238 +#endif
111239 +
111240 +struct opt_pass *make_insert_size_overflow_asm_pass(void)
111241 +{
111242 +#if BUILDING_GCC_VERSION >= 4009
111243 + return new insert_size_overflow_asm_pass();
111244 +#else
111245 + return &insert_size_overflow_asm_pass.pass;
111246 +#endif
111247 +}
111248 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
111249 new file mode 100644
111250 index 0000000..88469e9
111251 --- /dev/null
111252 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_check_core.c
111253 @@ -0,0 +1,902 @@
111254 +/*
111255 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
111256 + * Licensed under the GPL v2, or (at your option) v3
111257 + *
111258 + * Homepage:
111259 + * http://www.grsecurity.net/~ephox/overflow_plugin/
111260 + *
111261 + * Documentation:
111262 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
111263 + *
111264 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
111265 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
111266 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
111267 + *
111268 + * Usage:
111269 + * $ make
111270 + * $ make run
111271 + */
111272 +
111273 +#include "gcc-common.h"
111274 +#include "size_overflow.h"
111275 +
111276 +#define MIN_CHECK true
111277 +#define MAX_CHECK false
111278 +
111279 +static tree get_size_overflow_type(struct visited *visited, const_gimple stmt, const_tree node)
111280 +{
111281 + const_tree type;
111282 + tree new_type;
111283 +
111284 + gcc_assert(node != NULL_TREE);
111285 +
111286 + type = TREE_TYPE(node);
111287 +
111288 + if (pointer_set_contains(visited->my_stmts, stmt))
111289 + return TREE_TYPE(node);
111290 +
111291 + switch (TYPE_MODE(type)) {
111292 + case QImode:
111293 + new_type = size_overflow_type_HI;
111294 + break;
111295 + case HImode:
111296 + new_type = size_overflow_type_SI;
111297 + break;
111298 + case SImode:
111299 + new_type = size_overflow_type_DI;
111300 + break;
111301 + case DImode:
111302 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
111303 + new_type = TYPE_UNSIGNED(type) ? unsigned_intDI_type_node : intDI_type_node;
111304 + else
111305 + new_type = size_overflow_type_TI;
111306 + break;
111307 + case TImode:
111308 + gcc_assert(!TYPE_UNSIGNED(type));
111309 + new_type = size_overflow_type_TI;
111310 + break;
111311 + default:
111312 + debug_tree((tree)node);
111313 + error("%s: unsupported gcc configuration (%qE).", __func__, current_function_decl);
111314 + gcc_unreachable();
111315 + }
111316 +
111317 + if (TYPE_QUALS(type) != 0)
111318 + return build_qualified_type(new_type, TYPE_QUALS(type));
111319 + return new_type;
111320 +}
111321 +
111322 +static tree get_lhs(const_gimple stmt)
111323 +{
111324 + switch (gimple_code(stmt)) {
111325 + case GIMPLE_ASSIGN:
111326 + case GIMPLE_CALL:
111327 + return gimple_get_lhs(stmt);
111328 + case GIMPLE_PHI:
111329 + return gimple_phi_result(stmt);
111330 + default:
111331 + return NULL_TREE;
111332 + }
111333 +}
111334 +
111335 +static tree cast_to_new_size_overflow_type(struct visited *visited, gimple stmt, tree rhs, tree size_overflow_type, bool before)
111336 +{
111337 + gimple_stmt_iterator gsi;
111338 + tree lhs;
111339 + gimple new_stmt;
111340 +
111341 + if (rhs == NULL_TREE)
111342 + return NULL_TREE;
111343 +
111344 + gsi = gsi_for_stmt(stmt);
111345 + new_stmt = build_cast_stmt(visited, size_overflow_type, rhs, CREATE_NEW_VAR, &gsi, before, false);
111346 + pointer_set_insert(visited->my_stmts, new_stmt);
111347 +
111348 + lhs = get_lhs(new_stmt);
111349 + gcc_assert(lhs != NULL_TREE);
111350 + return lhs;
111351 +}
111352 +
111353 +tree create_assign(struct visited *visited, gimple oldstmt, tree rhs1, bool before)
111354 +{
111355 + tree lhs, dst_type;
111356 + gimple_stmt_iterator gsi;
111357 +
111358 + if (rhs1 == NULL_TREE) {
111359 + debug_gimple_stmt(oldstmt);
111360 + error("%s: rhs1 is NULL_TREE", __func__);
111361 + gcc_unreachable();
111362 + }
111363 +
111364 + switch (gimple_code(oldstmt)) {
111365 + case GIMPLE_ASM:
111366 + lhs = rhs1;
111367 + break;
111368 + case GIMPLE_CALL:
111369 + case GIMPLE_ASSIGN:
111370 + lhs = gimple_get_lhs(oldstmt);
111371 + break;
111372 + default:
111373 + debug_gimple_stmt(oldstmt);
111374 + gcc_unreachable();
111375 + }
111376 +
111377 + gsi = gsi_for_stmt(oldstmt);
111378 + pointer_set_insert(visited->stmts, oldstmt);
111379 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
111380 + basic_block next_bb, cur_bb;
111381 + const_edge e;
111382 +
111383 + gcc_assert(before == false);
111384 + gcc_assert(stmt_can_throw_internal(oldstmt));
111385 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
111386 + gcc_assert(!gsi_end_p(gsi));
111387 +
111388 + cur_bb = gimple_bb(oldstmt);
111389 + next_bb = cur_bb->next_bb;
111390 + e = find_edge(cur_bb, next_bb);
111391 + gcc_assert(e != NULL);
111392 + gcc_assert(e->flags & EDGE_FALLTHRU);
111393 +
111394 + gsi = gsi_after_labels(next_bb);
111395 + gcc_assert(!gsi_end_p(gsi));
111396 +
111397 + before = true;
111398 + oldstmt = gsi_stmt(gsi);
111399 + }
111400 +
111401 + dst_type = get_size_overflow_type(visited, oldstmt, lhs);
111402 +
111403 + if (is_gimple_constant(rhs1))
111404 + return cast_a_tree(dst_type, rhs1);
111405 + return cast_to_new_size_overflow_type(visited, oldstmt, rhs1, dst_type, before);
111406 +}
111407 +
111408 +tree dup_assign(struct visited *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3)
111409 +{
111410 + gimple stmt;
111411 + gimple_stmt_iterator gsi;
111412 + tree size_overflow_type, new_var, lhs = gimple_assign_lhs(oldstmt);
111413 +
111414 + if (pointer_set_contains(visited->my_stmts, oldstmt))
111415 + return lhs;
111416 +
111417 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
111418 + rhs1 = gimple_assign_rhs1(oldstmt);
111419 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
111420 + }
111421 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
111422 + rhs2 = gimple_assign_rhs2(oldstmt);
111423 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
111424 + }
111425 +
111426 + stmt = gimple_copy(oldstmt);
111427 + gimple_set_location(stmt, gimple_location(oldstmt));
111428 + pointer_set_insert(visited->my_stmts, stmt);
111429 +
111430 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
111431 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
111432 +
111433 + size_overflow_type = get_size_overflow_type(visited, oldstmt, node);
111434 +
111435 + new_var = create_new_var(size_overflow_type);
111436 + new_var = make_ssa_name(new_var, stmt);
111437 + gimple_assign_set_lhs(stmt, new_var);
111438 +
111439 + if (rhs1 != NULL_TREE)
111440 + gimple_assign_set_rhs1(stmt, rhs1);
111441 +
111442 + if (rhs2 != NULL_TREE)
111443 + gimple_assign_set_rhs2(stmt, rhs2);
111444 +#if BUILDING_GCC_VERSION >= 4006
111445 + if (rhs3 != NULL_TREE)
111446 + gimple_assign_set_rhs3(stmt, rhs3);
111447 +#endif
111448 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
111449 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
111450 +
111451 + gsi = gsi_for_stmt(oldstmt);
111452 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
111453 + update_stmt(stmt);
111454 + pointer_set_insert(visited->stmts, oldstmt);
111455 + return gimple_assign_lhs(stmt);
111456 +}
111457 +
111458 +static tree cast_parm_decl(struct visited *visited, tree phi_ssa_name, tree arg, tree size_overflow_type, basic_block bb)
111459 +{
111460 + gimple assign;
111461 + gimple_stmt_iterator gsi;
111462 + basic_block first_bb;
111463 +
111464 + gcc_assert(SSA_NAME_IS_DEFAULT_DEF(arg));
111465 +
111466 + if (bb->index == 0) {
111467 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
111468 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
111469 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
111470 + bb = first_bb;
111471 + }
111472 +
111473 + gsi = gsi_after_labels(bb);
111474 + assign = build_cast_stmt(visited, size_overflow_type, arg, phi_ssa_name, &gsi, BEFORE_STMT, false);
111475 + pointer_set_insert(visited->my_stmts, assign);
111476 +
111477 + return gimple_assign_lhs(assign);
111478 +}
111479 +
111480 +static tree use_phi_ssa_name(struct visited *visited, tree ssa_name_var, tree new_arg)
111481 +{
111482 + gimple_stmt_iterator gsi;
111483 + gimple assign, def_stmt = get_def_stmt(new_arg);
111484 +
111485 + if (gimple_code(def_stmt) == GIMPLE_PHI) {
111486 + gsi = gsi_after_labels(gimple_bb(def_stmt));
111487 + assign = build_cast_stmt(visited, TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, BEFORE_STMT, true);
111488 + } else {
111489 + gsi = gsi_for_stmt(def_stmt);
111490 + assign = build_cast_stmt(visited, TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, AFTER_STMT, true);
111491 + }
111492 +
111493 + pointer_set_insert(visited->my_stmts, assign);
111494 + return gimple_assign_lhs(assign);
111495 +}
111496 +
111497 +static tree cast_visited_phi_arg(struct visited *visited, tree ssa_name_var, tree arg, tree size_overflow_type)
111498 +{
111499 + basic_block bb;
111500 + gimple_stmt_iterator gsi;
111501 + const_gimple def_stmt;
111502 + gimple assign;
111503 +
111504 + def_stmt = get_def_stmt(arg);
111505 + bb = gimple_bb(def_stmt);
111506 + gcc_assert(bb->index != 0);
111507 + gsi = gsi_after_labels(bb);
111508 +
111509 + assign = build_cast_stmt(visited, size_overflow_type, arg, ssa_name_var, &gsi, BEFORE_STMT, false);
111510 + pointer_set_insert(visited->my_stmts, assign);
111511 + return gimple_assign_lhs(assign);
111512 +}
111513 +
111514 +static tree create_new_phi_arg(struct visited *visited, tree ssa_name_var, tree new_arg, gimple oldstmt, unsigned int i)
111515 +{
111516 + tree size_overflow_type;
111517 + tree arg;
111518 + const_gimple def_stmt;
111519 +
111520 + if (new_arg != NULL_TREE && is_gimple_constant(new_arg))
111521 + return new_arg;
111522 +
111523 + arg = gimple_phi_arg_def(oldstmt, i);
111524 + def_stmt = get_def_stmt(arg);
111525 + gcc_assert(def_stmt != NULL);
111526 + size_overflow_type = get_size_overflow_type(visited, oldstmt, arg);
111527 +
111528 + switch (gimple_code(def_stmt)) {
111529 + case GIMPLE_PHI:
111530 + return cast_visited_phi_arg(visited, ssa_name_var, arg, size_overflow_type);
111531 + case GIMPLE_NOP: {
111532 + basic_block bb;
111533 +
111534 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
111535 + return cast_parm_decl(visited, ssa_name_var, arg, size_overflow_type, bb);
111536 + }
111537 + case GIMPLE_ASM: {
111538 + gimple_stmt_iterator gsi;
111539 + gimple assign, stmt = get_def_stmt(arg);
111540 +
111541 + gsi = gsi_for_stmt(stmt);
111542 + assign = build_cast_stmt(visited, size_overflow_type, arg, ssa_name_var, &gsi, AFTER_STMT, false);
111543 + pointer_set_insert(visited->my_stmts, assign);
111544 + return gimple_assign_lhs(assign);
111545 + }
111546 + default:
111547 + gcc_assert(new_arg != NULL_TREE);
111548 + gcc_assert(types_compatible_p(TREE_TYPE(new_arg), size_overflow_type));
111549 + return use_phi_ssa_name(visited, ssa_name_var, new_arg);
111550 + }
111551 +}
111552 +
111553 +static gimple overflow_create_phi_node(struct visited *visited, gimple oldstmt, tree result)
111554 +{
111555 + basic_block bb;
111556 + gimple phi;
111557 + gimple_seq seq;
111558 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
111559 +
111560 + bb = gsi_bb(gsi);
111561 +
111562 + if (result == NULL_TREE) {
111563 + tree old_result = gimple_phi_result(oldstmt);
111564 + tree size_overflow_type = get_size_overflow_type(visited, oldstmt, old_result);
111565 +
111566 + result = create_new_var(size_overflow_type);
111567 + }
111568 +
111569 + phi = create_phi_node(result, bb);
111570 + gimple_phi_set_result(phi, make_ssa_name(result, phi));
111571 + seq = phi_nodes(bb);
111572 + gsi = gsi_last(seq);
111573 + gsi_remove(&gsi, false);
111574 +
111575 + gsi = gsi_for_stmt(oldstmt);
111576 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
111577 + gimple_set_bb(phi, bb);
111578 + return phi;
111579 +}
111580 +
111581 +#if BUILDING_GCC_VERSION <= 4007
111582 +static tree create_new_phi_node(struct visited *visited, VEC(tree, heap) **args, tree ssa_name_var, gimple oldstmt)
111583 +#else
111584 +static tree create_new_phi_node(struct visited *visited, vec<tree, va_heap, vl_embed> *&args, tree ssa_name_var, gimple oldstmt)
111585 +#endif
111586 +{
111587 + gimple new_phi;
111588 + unsigned int i;
111589 + tree arg, result;
111590 + location_t loc = gimple_location(oldstmt);
111591 +
111592 +#if BUILDING_GCC_VERSION <= 4007
111593 + gcc_assert(!VEC_empty(tree, *args));
111594 +#else
111595 + gcc_assert(!args->is_empty());
111596 +#endif
111597 +
111598 + new_phi = overflow_create_phi_node(visited, oldstmt, ssa_name_var);
111599 + result = gimple_phi_result(new_phi);
111600 + ssa_name_var = SSA_NAME_VAR(result);
111601 +
111602 +#if BUILDING_GCC_VERSION <= 4007
111603 + FOR_EACH_VEC_ELT(tree, *args, i, arg) {
111604 +#else
111605 + FOR_EACH_VEC_SAFE_ELT(args, i, arg) {
111606 +#endif
111607 + arg = create_new_phi_arg(visited, ssa_name_var, arg, oldstmt, i);
111608 + add_phi_arg(new_phi, arg, gimple_phi_arg_edge(oldstmt, i), loc);
111609 + }
111610 +
111611 +#if BUILDING_GCC_VERSION <= 4007
111612 + VEC_free(tree, heap, *args);
111613 +#else
111614 + vec_free(args);
111615 +#endif
111616 + update_stmt(new_phi);
111617 + pointer_set_insert(visited->my_stmts, new_phi);
111618 + return result;
111619 +}
111620 +
111621 +static tree handle_phi(struct visited *visited, struct cgraph_node *caller_node, tree orig_result)
111622 +{
111623 + tree ssa_name_var = NULL_TREE;
111624 +#if BUILDING_GCC_VERSION <= 4007
111625 + VEC(tree, heap) *args = NULL;
111626 +#else
111627 + vec<tree, va_heap, vl_embed> *args = NULL;
111628 +#endif
111629 + gimple oldstmt = get_def_stmt(orig_result);
111630 + unsigned int i, len = gimple_phi_num_args(oldstmt);
111631 +
111632 + pointer_set_insert(visited->stmts, oldstmt);
111633 + for (i = 0; i < len; i++) {
111634 + tree arg, new_arg;
111635 +
111636 + arg = gimple_phi_arg_def(oldstmt, i);
111637 + new_arg = expand(visited, caller_node, arg);
111638 +
111639 + if (ssa_name_var == NULL_TREE && new_arg != NULL_TREE)
111640 + ssa_name_var = SSA_NAME_VAR(new_arg);
111641 +
111642 + if (is_gimple_constant(arg)) {
111643 + tree size_overflow_type = get_size_overflow_type(visited, oldstmt, arg);
111644 +
111645 + new_arg = cast_a_tree(size_overflow_type, arg);
111646 + }
111647 +
111648 +#if BUILDING_GCC_VERSION <= 4007
111649 + VEC_safe_push(tree, heap, args, new_arg);
111650 +#else
111651 + vec_safe_push(args, new_arg);
111652 +#endif
111653 + }
111654 +
111655 +#if BUILDING_GCC_VERSION <= 4007
111656 + return create_new_phi_node(visited, &args, ssa_name_var, oldstmt);
111657 +#else
111658 + return create_new_phi_node(visited, args, ssa_name_var, oldstmt);
111659 +#endif
111660 +}
111661 +
111662 +static tree create_cast_assign(struct visited *visited, gimple stmt)
111663 +{
111664 + tree rhs1 = gimple_assign_rhs1(stmt);
111665 + tree lhs = gimple_assign_lhs(stmt);
111666 + const_tree rhs1_type = TREE_TYPE(rhs1);
111667 + const_tree lhs_type = TREE_TYPE(lhs);
111668 +
111669 + if (TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
111670 + return create_assign(visited, stmt, lhs, AFTER_STMT);
111671 +
111672 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
111673 +}
111674 +
111675 +static bool skip_lhs_cast_check(const_gimple stmt)
111676 +{
111677 + const_tree rhs = gimple_assign_rhs1(stmt);
111678 + const_gimple def_stmt = get_def_stmt(rhs);
111679 +
111680 + // 3.8.2 kernel/futex_compat.c compat_exit_robust_list(): get_user() 64 ulong -> int (compat_long_t), int max
111681 + if (gimple_code(def_stmt) == GIMPLE_ASM)
111682 + return true;
111683 +
111684 + if (is_const_plus_unsigned_signed_truncation(rhs))
111685 + return true;
111686 +
111687 + return false;
111688 +}
111689 +
111690 +static tree create_string_param(tree string)
111691 +{
111692 + tree i_type, a_type;
111693 + const int length = TREE_STRING_LENGTH(string);
111694 +
111695 + gcc_assert(length > 0);
111696 +
111697 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
111698 + a_type = build_array_type(char_type_node, i_type);
111699 +
111700 + TREE_TYPE(string) = a_type;
111701 + TREE_CONSTANT(string) = 1;
111702 + TREE_READONLY(string) = 1;
111703 +
111704 + return build1(ADDR_EXPR, ptr_type_node, string);
111705 +}
111706 +
111707 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
111708 +{
111709 + gimple cond_stmt;
111710 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
111711 +
111712 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
111713 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
111714 + update_stmt(cond_stmt);
111715 +}
111716 +
111717 +static void insert_cond_result(struct cgraph_node *caller_node, basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
111718 +{
111719 + gimple func_stmt;
111720 + const_gimple def_stmt;
111721 + const_tree loc_line;
111722 + tree loc_file, ssa_name, current_func;
111723 + expanded_location xloc;
111724 + char *ssa_name_buf;
111725 + int len;
111726 + struct cgraph_edge *edge;
111727 + struct cgraph_node *callee_node;
111728 + int frequency;
111729 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
111730 +
111731 + def_stmt = get_def_stmt(arg);
111732 + xloc = expand_location(gimple_location(def_stmt));
111733 +
111734 + if (!gimple_has_location(def_stmt)) {
111735 + xloc = expand_location(gimple_location(stmt));
111736 + if (!gimple_has_location(stmt))
111737 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
111738 + }
111739 +
111740 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
111741 +
111742 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
111743 + loc_file = create_string_param(loc_file);
111744 +
111745 + current_func = build_string(DECL_NAME_LENGTH(current_function_decl) + 1, DECL_NAME_POINTER(current_function_decl));
111746 + current_func = create_string_param(current_func);
111747 +
111748 + gcc_assert(DECL_NAME(SSA_NAME_VAR(arg)) != NULL);
111749 + call_count++;
111750 + 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);
111751 + gcc_assert(len > 0);
111752 + ssa_name = build_string(len + 1, ssa_name_buf);
111753 + free(ssa_name_buf);
111754 + ssa_name = create_string_param(ssa_name);
111755 +
111756 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
111757 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
111758 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
111759 +
111760 + callee_node = cgraph_get_create_node(report_size_overflow_decl);
111761 + frequency = compute_call_stmt_bb_frequency(current_function_decl, bb_true);
111762 +
111763 + edge = cgraph_create_edge(caller_node, callee_node, func_stmt, bb_true->count, frequency, bb_true->loop_depth);
111764 + gcc_assert(edge != NULL);
111765 +}
111766 +
111767 +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)
111768 +{
111769 + basic_block cond_bb, join_bb, bb_true;
111770 + edge e;
111771 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
111772 +
111773 + cond_bb = gimple_bb(stmt);
111774 + if (before)
111775 + gsi_prev(&gsi);
111776 + if (gsi_end_p(gsi))
111777 + e = split_block_after_labels(cond_bb);
111778 + else
111779 + e = split_block(cond_bb, gsi_stmt(gsi));
111780 + cond_bb = e->src;
111781 + join_bb = e->dest;
111782 + e->flags = EDGE_FALSE_VALUE;
111783 + e->probability = REG_BR_PROB_BASE;
111784 +
111785 + bb_true = create_empty_bb(cond_bb);
111786 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
111787 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
111788 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
111789 +
111790 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
111791 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
111792 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
111793 +
111794 + if (current_loops != NULL) {
111795 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
111796 + add_bb_to_loop(bb_true, cond_bb->loop_father);
111797 + }
111798 +
111799 + insert_cond(cond_bb, arg, cond_code, type_value);
111800 + insert_cond_result(caller_node, bb_true, stmt, arg, min);
111801 +
111802 +// print_the_code_insertions(stmt);
111803 +}
111804 +
111805 +void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
111806 +{
111807 + const_tree rhs_type = TREE_TYPE(rhs);
111808 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
111809 +
111810 + gcc_assert(rhs_type != NULL_TREE);
111811 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
111812 + return;
111813 +
111814 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
111815 +
111816 + if (is_const_plus_unsigned_signed_truncation(rhs))
111817 + return;
111818 +
111819 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
111820 + // typemax (-1) < typemin (0)
111821 + if (TREE_OVERFLOW(type_max))
111822 + return;
111823 +
111824 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
111825 +
111826 + cast_rhs_type = TREE_TYPE(cast_rhs);
111827 + type_max_type = TREE_TYPE(type_max);
111828 + gcc_assert(types_compatible_p(cast_rhs_type, type_max_type));
111829 +
111830 + insert_check_size_overflow(caller_node, stmt, GT_EXPR, cast_rhs, type_max, before, MAX_CHECK);
111831 +
111832 + // special case: get_size_overflow_type(), 32, u64->s
111833 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode) && TYPE_UNSIGNED(size_overflow_type) && !TYPE_UNSIGNED(rhs_type))
111834 + return;
111835 +
111836 + type_min_type = TREE_TYPE(type_min);
111837 + gcc_assert(types_compatible_p(type_max_type, type_min_type));
111838 + insert_check_size_overflow(caller_node, stmt, LT_EXPR, cast_rhs, type_min, before, MIN_CHECK);
111839 +}
111840 +
111841 +static tree create_cast_overflow_check(struct visited *visited, struct cgraph_node *caller_node, tree new_rhs1, gimple stmt)
111842 +{
111843 + bool cast_lhs, cast_rhs;
111844 + tree lhs = gimple_assign_lhs(stmt);
111845 + tree rhs = gimple_assign_rhs1(stmt);
111846 + const_tree lhs_type = TREE_TYPE(lhs);
111847 + const_tree rhs_type = TREE_TYPE(rhs);
111848 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
111849 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
111850 + unsigned int lhs_size = GET_MODE_BITSIZE(lhs_mode);
111851 + unsigned int rhs_size = GET_MODE_BITSIZE(rhs_mode);
111852 +
111853 + static bool check_lhs[3][4] = {
111854 + // ss su us uu
111855 + { false, true, true, false }, // lhs > rhs
111856 + { false, false, false, false }, // lhs = rhs
111857 + { true, true, true, true }, // lhs < rhs
111858 + };
111859 +
111860 + static bool check_rhs[3][4] = {
111861 + // ss su us uu
111862 + { true, false, true, true }, // lhs > rhs
111863 + { true, false, true, true }, // lhs = rhs
111864 + { true, false, true, true }, // lhs < rhs
111865 + };
111866 +
111867 + // skip lhs check on signed SI -> HI cast or signed SI -> QI cast !!!!
111868 + if (rhs_mode == SImode && !TYPE_UNSIGNED(rhs_type) && (lhs_mode == HImode || lhs_mode == QImode))
111869 + return create_assign(visited, stmt, lhs, AFTER_STMT);
111870 +
111871 + if (lhs_size > rhs_size) {
111872 + cast_lhs = check_lhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
111873 + cast_rhs = check_rhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
111874 + } else if (lhs_size == rhs_size) {
111875 + cast_lhs = check_lhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
111876 + cast_rhs = check_rhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
111877 + } else {
111878 + cast_lhs = check_lhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
111879 + cast_rhs = check_rhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
111880 + }
111881 +
111882 + if (!cast_lhs && !cast_rhs)
111883 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
111884 +
111885 + if (cast_lhs && !skip_lhs_cast_check(stmt))
111886 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, lhs, BEFORE_STMT);
111887 +
111888 + if (cast_rhs)
111889 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, rhs, BEFORE_STMT);
111890 +
111891 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
111892 +}
111893 +
111894 +static tree handle_unary_rhs(struct visited *visited, struct cgraph_node *caller_node, gimple stmt)
111895 +{
111896 + enum tree_code rhs_code;
111897 + tree rhs1, new_rhs1, lhs = gimple_assign_lhs(stmt);
111898 +
111899 + if (pointer_set_contains(visited->my_stmts, stmt))
111900 + return lhs;
111901 +
111902 + rhs1 = gimple_assign_rhs1(stmt);
111903 + if (TREE_CODE(TREE_TYPE(rhs1)) == POINTER_TYPE)
111904 + return create_assign(visited, stmt, lhs, AFTER_STMT);
111905 +
111906 + new_rhs1 = expand(visited, caller_node, rhs1);
111907 +
111908 + if (new_rhs1 == NULL_TREE)
111909 + return create_cast_assign(visited, stmt);
111910 +
111911 + if (pointer_set_contains(visited->no_cast_check, stmt))
111912 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
111913 +
111914 + rhs_code = gimple_assign_rhs_code(stmt);
111915 + if (rhs_code == BIT_NOT_EXPR || rhs_code == NEGATE_EXPR) {
111916 + tree size_overflow_type = get_size_overflow_type(visited, stmt, rhs1);
111917 +
111918 + new_rhs1 = cast_to_new_size_overflow_type(visited, stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
111919 + check_size_overflow(caller_node, stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
111920 + return create_assign(visited, stmt, lhs, AFTER_STMT);
111921 + }
111922 +
111923 + if (!gimple_assign_cast_p(stmt))
111924 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
111925 +
111926 + return create_cast_overflow_check(visited, caller_node, new_rhs1, stmt);
111927 +}
111928 +
111929 +static tree handle_unary_ops(struct visited *visited, struct cgraph_node *caller_node, gimple stmt)
111930 +{
111931 + tree rhs1, lhs = gimple_assign_lhs(stmt);
111932 + gimple def_stmt = get_def_stmt(lhs);
111933 +
111934 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP);
111935 + rhs1 = gimple_assign_rhs1(def_stmt);
111936 +
111937 + if (is_gimple_constant(rhs1))
111938 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
111939 +
111940 + switch (TREE_CODE(rhs1)) {
111941 + case SSA_NAME: {
111942 + tree ret = handle_unary_rhs(visited, caller_node, def_stmt);
111943 +
111944 + if (gimple_assign_cast_p(stmt))
111945 + unsigned_signed_cast_intentional_overflow(visited, stmt);
111946 + return ret;
111947 + }
111948 + case ARRAY_REF:
111949 + case BIT_FIELD_REF:
111950 + case ADDR_EXPR:
111951 + case COMPONENT_REF:
111952 + case INDIRECT_REF:
111953 +#if BUILDING_GCC_VERSION >= 4006
111954 + case MEM_REF:
111955 +#endif
111956 + case TARGET_MEM_REF:
111957 + case VIEW_CONVERT_EXPR:
111958 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
111959 + case PARM_DECL:
111960 + case VAR_DECL:
111961 + return create_assign(visited, stmt, lhs, AFTER_STMT);
111962 +
111963 + default:
111964 + debug_gimple_stmt(def_stmt);
111965 + debug_tree(rhs1);
111966 + gcc_unreachable();
111967 + }
111968 +}
111969 +
111970 +static void __unused print_the_code_insertions(const_gimple stmt)
111971 +{
111972 + location_t loc = gimple_location(stmt);
111973 +
111974 + inform(loc, "Integer size_overflow check applied here.");
111975 +}
111976 +
111977 +static tree handle_binary_ops(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
111978 +{
111979 + enum intentional_overflow_type res;
111980 + tree rhs1, rhs2, new_lhs;
111981 + gimple def_stmt = get_def_stmt(lhs);
111982 + tree new_rhs1 = NULL_TREE;
111983 + tree new_rhs2 = NULL_TREE;
111984 +
111985 + rhs1 = gimple_assign_rhs1(def_stmt);
111986 + rhs2 = gimple_assign_rhs2(def_stmt);
111987 +
111988 + /* no DImode/TImode division in the 32/64 bit kernel */
111989 + switch (gimple_assign_rhs_code(def_stmt)) {
111990 + case RDIV_EXPR:
111991 + case TRUNC_DIV_EXPR:
111992 + case CEIL_DIV_EXPR:
111993 + case FLOOR_DIV_EXPR:
111994 + case ROUND_DIV_EXPR:
111995 + case TRUNC_MOD_EXPR:
111996 + case CEIL_MOD_EXPR:
111997 + case FLOOR_MOD_EXPR:
111998 + case ROUND_MOD_EXPR:
111999 + case EXACT_DIV_EXPR:
112000 + case POINTER_PLUS_EXPR:
112001 + case BIT_AND_EXPR:
112002 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
112003 + default:
112004 + break;
112005 + }
112006 +
112007 + new_lhs = handle_integer_truncation(visited, caller_node, lhs);
112008 + if (new_lhs != NULL_TREE)
112009 + return new_lhs;
112010 +
112011 + if (TREE_CODE(rhs1) == SSA_NAME)
112012 + new_rhs1 = expand(visited, caller_node, rhs1);
112013 + if (TREE_CODE(rhs2) == SSA_NAME)
112014 + new_rhs2 = expand(visited, caller_node, rhs2);
112015 +
112016 + res = add_mul_intentional_overflow(def_stmt);
112017 + if (res != NO_INTENTIONAL_OVERFLOW) {
112018 + new_lhs = dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
112019 + insert_cast_expr(visited, get_def_stmt(new_lhs), res);
112020 + return new_lhs;
112021 + }
112022 +
112023 + if (skip_expr_on_double_type(def_stmt)) {
112024 + new_lhs = dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
112025 + insert_cast_expr(visited, get_def_stmt(new_lhs), NO_INTENTIONAL_OVERFLOW);
112026 + return new_lhs;
112027 + }
112028 +
112029 + if (is_a_neg_overflow(def_stmt, rhs2))
112030 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs1, NULL_TREE);
112031 + if (is_a_neg_overflow(def_stmt, rhs1))
112032 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs2, new_rhs2);
112033 +
112034 +
112035 + if (is_a_constant_overflow(def_stmt, rhs2))
112036 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, NULL_TREE);
112037 + if (is_a_constant_overflow(def_stmt, rhs1))
112038 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, new_rhs2);
112039 +
112040 + // the const is between 0 and (signed) MAX
112041 + if (is_gimple_constant(rhs1))
112042 + new_rhs1 = create_assign(visited, def_stmt, rhs1, BEFORE_STMT);
112043 + if (is_gimple_constant(rhs2))
112044 + new_rhs2 = create_assign(visited, def_stmt, rhs2, BEFORE_STMT);
112045 +
112046 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
112047 +}
112048 +
112049 +#if BUILDING_GCC_VERSION >= 4006
112050 +static tree get_new_rhs(struct visited *visited, struct cgraph_node *caller_node, tree size_overflow_type, tree rhs)
112051 +{
112052 + if (is_gimple_constant(rhs))
112053 + return cast_a_tree(size_overflow_type, rhs);
112054 + if (TREE_CODE(rhs) != SSA_NAME)
112055 + return NULL_TREE;
112056 + return expand(visited, caller_node, rhs);
112057 +}
112058 +
112059 +static tree handle_ternary_ops(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
112060 +{
112061 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
112062 + gimple def_stmt = get_def_stmt(lhs);
112063 +
112064 + size_overflow_type = get_size_overflow_type(visited, def_stmt, lhs);
112065 +
112066 + rhs1 = gimple_assign_rhs1(def_stmt);
112067 + rhs2 = gimple_assign_rhs2(def_stmt);
112068 + rhs3 = gimple_assign_rhs3(def_stmt);
112069 + new_rhs1 = get_new_rhs(visited, caller_node, size_overflow_type, rhs1);
112070 + new_rhs2 = get_new_rhs(visited, caller_node, size_overflow_type, rhs2);
112071 + new_rhs3 = get_new_rhs(visited, caller_node, size_overflow_type, rhs3);
112072 +
112073 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
112074 +}
112075 +#endif
112076 +
112077 +static tree get_my_stmt_lhs(struct visited *visited, gimple stmt)
112078 +{
112079 + gimple_stmt_iterator gsi;
112080 + gimple next_stmt = NULL;
112081 +
112082 + gsi = gsi_for_stmt(stmt);
112083 +
112084 + do {
112085 + gsi_next(&gsi);
112086 + next_stmt = gsi_stmt(gsi);
112087 +
112088 + if (gimple_code(stmt) == GIMPLE_PHI && !pointer_set_contains(visited->my_stmts, next_stmt))
112089 + return NULL_TREE;
112090 +
112091 + if (pointer_set_contains(visited->my_stmts, next_stmt) && !pointer_set_contains(visited->skip_expr_casts, next_stmt))
112092 + break;
112093 +
112094 + gcc_assert(pointer_set_contains(visited->my_stmts, next_stmt));
112095 + } while (!gsi_end_p(gsi));
112096 +
112097 + gcc_assert(next_stmt);
112098 + return get_lhs(next_stmt);
112099 +}
112100 +
112101 +static tree expand_visited(struct visited *visited, gimple def_stmt)
112102 +{
112103 + gimple_stmt_iterator gsi;
112104 + enum gimple_code code = gimple_code(def_stmt);
112105 +
112106 + if (code == GIMPLE_ASM)
112107 + return NULL_TREE;
112108 +
112109 + gsi = gsi_for_stmt(def_stmt);
112110 + gsi_next(&gsi);
112111 +
112112 + if (gimple_code(def_stmt) == GIMPLE_PHI && gsi_end_p(gsi))
112113 + return NULL_TREE;
112114 + return get_my_stmt_lhs(visited, def_stmt);
112115 +}
112116 +
112117 +tree expand(struct visited *visited, struct cgraph_node *caller_node, tree lhs)
112118 +{
112119 + gimple def_stmt;
112120 +
112121 + def_stmt = get_def_stmt(lhs);
112122 +
112123 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
112124 + return NULL_TREE;
112125 +
112126 + if (pointer_set_contains(visited->my_stmts, def_stmt))
112127 + return lhs;
112128 +
112129 + if (pointer_set_contains(visited->stmts, def_stmt))
112130 + return expand_visited(visited, def_stmt);
112131 +
112132 + switch (gimple_code(def_stmt)) {
112133 + case GIMPLE_PHI:
112134 + return handle_phi(visited, caller_node, lhs);
112135 + case GIMPLE_CALL:
112136 + case GIMPLE_ASM:
112137 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
112138 + case GIMPLE_ASSIGN:
112139 + switch (gimple_num_ops(def_stmt)) {
112140 + case 2:
112141 + return handle_unary_ops(visited, caller_node, def_stmt);
112142 + case 3:
112143 + return handle_binary_ops(visited, caller_node, lhs);
112144 +#if BUILDING_GCC_VERSION >= 4006
112145 + case 4:
112146 + return handle_ternary_ops(visited, caller_node, lhs);
112147 +#endif
112148 + }
112149 + default:
112150 + debug_gimple_stmt(def_stmt);
112151 + error("%s: unknown gimple code", __func__);
112152 + gcc_unreachable();
112153 + }
112154 +}
112155 +
112156 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
112157 new file mode 100644
112158 index 0000000..f8f5dd5
112159 --- /dev/null
112160 +++ b/tools/gcc/size_overflow_plugin/insert_size_overflow_check_ipa.c
112161 @@ -0,0 +1,1133 @@
112162 +/*
112163 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
112164 + * Licensed under the GPL v2, or (at your option) v3
112165 + *
112166 + * Homepage:
112167 + * http://www.grsecurity.net/~ephox/overflow_plugin/
112168 + *
112169 + * Documentation:
112170 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
112171 + *
112172 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
112173 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
112174 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
112175 + *
112176 + * Usage:
112177 + * $ make
112178 + * $ make run
112179 + */
112180 +
112181 +#include "gcc-common.h"
112182 +#include "size_overflow.h"
112183 +
112184 +#define VEC_LEN 128
112185 +#define RET_CHECK NULL_TREE
112186 +#define WRONG_NODE 32
112187 +#define NOT_INTENTIONAL_ASM NULL
112188 +
112189 +unsigned int call_count;
112190 +
112191 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs);
112192 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs);
112193 +
112194 +struct visited_fns {
112195 + struct visited_fns *next;
112196 + const_tree fndecl;
112197 + unsigned int num;
112198 + const_gimple first_stmt;
112199 +};
112200 +
112201 +struct next_cgraph_node {
112202 + struct next_cgraph_node *next;
112203 + struct cgraph_node *current_function;
112204 + tree callee_fndecl;
112205 + unsigned int num;
112206 +};
112207 +
112208 +// Don't want to duplicate entries in next_cgraph_node
112209 +static bool is_in_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, const_tree fndecl, unsigned int num)
112210 +{
112211 + const_tree new_callee_fndecl;
112212 + struct next_cgraph_node *cur_node;
112213 +
112214 + if (fndecl == RET_CHECK)
112215 + new_callee_fndecl = NODE_DECL(node);
112216 + else
112217 + new_callee_fndecl = fndecl;
112218 +
112219 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
112220 + if (!operand_equal_p(NODE_DECL(cur_node->current_function), NODE_DECL(node), 0))
112221 + continue;
112222 + if (!operand_equal_p(cur_node->callee_fndecl, new_callee_fndecl, 0))
112223 + continue;
112224 + if (num == cur_node->num)
112225 + return true;
112226 + }
112227 + return false;
112228 +}
112229 +
112230 +/* Add a next_cgraph_node into the list for handle_function().
112231 + * handle_function() iterates over all the next cgraph nodes and
112232 + * starts the overflow check insertion process.
112233 + */
112234 +static struct next_cgraph_node *create_new_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, tree fndecl, unsigned int num)
112235 +{
112236 + struct next_cgraph_node *new_node;
112237 +
112238 + if (is_in_next_cgraph_node(head, node, fndecl, num))
112239 + return head;
112240 +
112241 + new_node = (struct next_cgraph_node *)xmalloc(sizeof(*new_node));
112242 + new_node->current_function = node;
112243 + new_node->next = NULL;
112244 + new_node->num = num;
112245 + if (fndecl == RET_CHECK)
112246 + new_node->callee_fndecl = NODE_DECL(node);
112247 + else
112248 + new_node->callee_fndecl = fndecl;
112249 +
112250 + if (!head)
112251 + return new_node;
112252 +
112253 + new_node->next = head;
112254 + return new_node;
112255 +}
112256 +
112257 +static struct next_cgraph_node *create_new_next_cgraph_nodes(struct next_cgraph_node *head, struct cgraph_node *node, unsigned int num)
112258 +{
112259 + struct cgraph_edge *e;
112260 +
112261 + if (num == 0)
112262 + return create_new_next_cgraph_node(head, node, RET_CHECK, num);
112263 +
112264 + for (e = node->callers; e; e = e->next_caller) {
112265 + tree fndecl = gimple_call_fndecl(e->call_stmt);
112266 +
112267 + gcc_assert(fndecl != NULL_TREE);
112268 + head = create_new_next_cgraph_node(head, e->caller, fndecl, num);
112269 + }
112270 +
112271 + return head;
112272 +}
112273 +
112274 +struct missing_functions {
112275 + struct missing_functions *next;
112276 + const_tree node;
112277 + tree fndecl;
112278 +};
112279 +
112280 +static struct missing_functions *create_new_missing_function(struct missing_functions *missing_fn_head, tree node)
112281 +{
112282 + struct missing_functions *new_function;
112283 +
112284 + new_function = (struct missing_functions *)xmalloc(sizeof(*new_function));
112285 + new_function->node = node;
112286 + new_function->next = NULL;
112287 +
112288 + if (TREE_CODE(node) == FUNCTION_DECL)
112289 + new_function->fndecl = node;
112290 + else
112291 + new_function->fndecl = current_function_decl;
112292 + gcc_assert(new_function->fndecl);
112293 +
112294 + if (!missing_fn_head)
112295 + return new_function;
112296 +
112297 + new_function->next = missing_fn_head;
112298 + return new_function;
112299 +}
112300 +
112301 +/* If the function is missing from the hash table and it is a static function
112302 + * then create a next_cgraph_node from it for handle_function()
112303 + */
112304 +static struct next_cgraph_node *check_missing_overflow_attribute_and_create_next_node(struct next_cgraph_node *cnodes, struct missing_functions *missing_fn_head)
112305 +{
112306 + unsigned int num;
112307 + const_tree orig_fndecl;
112308 + struct cgraph_node *next_node = NULL;
112309 +
112310 + orig_fndecl = DECL_ORIGIN(missing_fn_head->fndecl);
112311 +
112312 + num = get_function_num(missing_fn_head->node, orig_fndecl);
112313 + if (num == CANNOT_FIND_ARG)
112314 + return cnodes;
112315 +
112316 + if (!is_missing_function(orig_fndecl, num))
112317 + return cnodes;
112318 +
112319 + next_node = cgraph_get_node(missing_fn_head->fndecl);
112320 + if (next_node && next_node->local.local)
112321 + cnodes = create_new_next_cgraph_nodes(cnodes, next_node, num);
112322 + return cnodes;
112323 +}
112324 +
112325 +/* Search for missing size_overflow attributes on the last nodes in ipa and collect them
112326 + * into the next_cgraph_node list. They will be the next interesting returns or callees.
112327 + */
112328 +static struct next_cgraph_node *search_overflow_attribute(struct next_cgraph_node *cnodes, struct interesting_node *cur_node)
112329 +{
112330 + unsigned int i;
112331 + tree node;
112332 + struct missing_functions *cur, *missing_fn_head = NULL;
112333 +
112334 +#if BUILDING_GCC_VERSION <= 4007
112335 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, node) {
112336 +#else
112337 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, node) {
112338 +#endif
112339 + switch (TREE_CODE(node)) {
112340 + case PARM_DECL:
112341 + if (TREE_CODE(TREE_TYPE(node)) != INTEGER_TYPE)
112342 + break;
112343 + case FUNCTION_DECL:
112344 + missing_fn_head = create_new_missing_function(missing_fn_head, node);
112345 + break;
112346 + default:
112347 + break;
112348 + }
112349 + }
112350 +
112351 + while (missing_fn_head) {
112352 + cnodes = check_missing_overflow_attribute_and_create_next_node(cnodes, missing_fn_head);
112353 +
112354 + cur = missing_fn_head->next;
112355 + free(missing_fn_head);
112356 + missing_fn_head = cur;
112357 + }
112358 +
112359 + return cnodes;
112360 +}
112361 +
112362 +static void walk_phi_set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree result)
112363 +{
112364 + gimple phi = get_def_stmt(result);
112365 + unsigned int i, n = gimple_phi_num_args(phi);
112366 +
112367 + pointer_set_insert(visited, phi);
112368 + for (i = 0; i < n; i++) {
112369 + const_tree arg = gimple_phi_arg_def(phi, i);
112370 +
112371 + set_conditions(visited, interesting_conditions, arg);
112372 + }
112373 +}
112374 +
112375 +enum conditions {
112376 + FROM_CONST, NOT_UNARY, CAST
112377 +};
112378 +
112379 +// Search for constants, cast assignments and binary/ternary assignments
112380 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs)
112381 +{
112382 + gimple def_stmt = get_def_stmt(lhs);
112383 +
112384 + if (is_gimple_constant(lhs)) {
112385 + interesting_conditions[FROM_CONST] = true;
112386 + return;
112387 + }
112388 +
112389 + if (!def_stmt)
112390 + return;
112391 +
112392 + if (pointer_set_contains(visited, def_stmt))
112393 + return;
112394 +
112395 + switch (gimple_code(def_stmt)) {
112396 + case GIMPLE_NOP:
112397 + case GIMPLE_CALL:
112398 + case GIMPLE_ASM:
112399 + return;
112400 + case GIMPLE_PHI:
112401 + return walk_phi_set_conditions(visited, interesting_conditions, lhs);
112402 + case GIMPLE_ASSIGN:
112403 + if (gimple_num_ops(def_stmt) == 2) {
112404 + const_tree rhs = gimple_assign_rhs1(def_stmt);
112405 +
112406 + if (gimple_assign_cast_p(def_stmt))
112407 + interesting_conditions[CAST] = true;
112408 +
112409 + return set_conditions(visited, interesting_conditions, rhs);
112410 + } else {
112411 + interesting_conditions[NOT_UNARY] = true;
112412 + return;
112413 + }
112414 + default:
112415 + debug_gimple_stmt(def_stmt);
112416 + gcc_unreachable();
112417 + }
112418 +}
112419 +
112420 +// determine whether duplication will be necessary or not.
112421 +static void search_interesting_conditions(struct interesting_node *cur_node, bool *interesting_conditions)
112422 +{
112423 + struct pointer_set_t *visited;
112424 +
112425 + if (gimple_assign_cast_p(cur_node->first_stmt))
112426 + interesting_conditions[CAST] = true;
112427 + else if (is_gimple_assign(cur_node->first_stmt) && gimple_num_ops(cur_node->first_stmt) > 2)
112428 + interesting_conditions[NOT_UNARY] = true;
112429 +
112430 + visited = pointer_set_create();
112431 + set_conditions(visited, interesting_conditions, cur_node->node);
112432 + pointer_set_destroy(visited);
112433 +}
112434 +
112435 +// Remove the size_overflow asm stmt and create an assignment from the input and output of the asm
112436 +static void replace_size_overflow_asm_with_assign(gimple asm_stmt, tree lhs, tree rhs)
112437 +{
112438 + gimple assign;
112439 + gimple_stmt_iterator gsi;
112440 +
112441 + // already removed
112442 + if (gimple_bb(asm_stmt) == NULL)
112443 + return;
112444 + gsi = gsi_for_stmt(asm_stmt);
112445 +
112446 + assign = gimple_build_assign(lhs, rhs);
112447 + gsi_insert_before(&gsi, assign, GSI_SAME_STMT);
112448 + SSA_NAME_DEF_STMT(lhs) = assign;
112449 +
112450 + gsi_remove(&gsi, true);
112451 +}
112452 +
112453 +/* Get the fndecl of an interesting stmt, the fndecl is the caller function if the interesting
112454 + * stmt is a return otherwise it is the callee function.
112455 + */
112456 +const_tree get_interesting_orig_fndecl(const_gimple stmt, unsigned int argnum)
112457 +{
112458 + const_tree fndecl;
112459 +
112460 + if (argnum == 0)
112461 + fndecl = current_function_decl;
112462 + else
112463 + fndecl = gimple_call_fndecl(stmt);
112464 +
112465 + if (fndecl == NULL_TREE)
112466 + return NULL_TREE;
112467 +
112468 + return DECL_ORIGIN(fndecl);
112469 +}
112470 +
112471 +// e.g., 3.8.2, 64, arch/x86/ia32/ia32_signal.c copy_siginfo_from_user32(): compat_ptr() u32 max
112472 +static bool skip_asm(const_tree arg)
112473 +{
112474 + gimple def_stmt = get_def_stmt(arg);
112475 +
112476 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
112477 + return false;
112478 +
112479 + def_stmt = get_def_stmt(gimple_assign_rhs1(def_stmt));
112480 + return def_stmt && gimple_code(def_stmt) == GIMPLE_ASM;
112481 +}
112482 +
112483 +static void walk_use_def_phi(struct pointer_set_t *visited, struct interesting_node *cur_node, tree result)
112484 +{
112485 + gimple phi = get_def_stmt(result);
112486 + unsigned int i, n = gimple_phi_num_args(phi);
112487 +
112488 + pointer_set_insert(visited, phi);
112489 + for (i = 0; i < n; i++) {
112490 + tree arg = gimple_phi_arg_def(phi, i);
112491 +
112492 + walk_use_def(visited, cur_node, arg);
112493 + }
112494 +}
112495 +
112496 +static void walk_use_def_binary(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
112497 +{
112498 + gimple def_stmt = get_def_stmt(lhs);
112499 + tree rhs1, rhs2;
112500 +
112501 + rhs1 = gimple_assign_rhs1(def_stmt);
112502 + rhs2 = gimple_assign_rhs2(def_stmt);
112503 +
112504 + walk_use_def(visited, cur_node, rhs1);
112505 + walk_use_def(visited, cur_node, rhs2);
112506 +}
112507 +
112508 +static void insert_last_node(struct interesting_node *cur_node, tree node)
112509 +{
112510 + unsigned int i;
112511 + tree element;
112512 + enum tree_code code;
112513 +
112514 + gcc_assert(node != NULL_TREE);
112515 +
112516 + if (is_gimple_constant(node))
112517 + return;
112518 +
112519 + code = TREE_CODE(node);
112520 + if (code == VAR_DECL) {
112521 + node = DECL_ORIGIN(node);
112522 + code = TREE_CODE(node);
112523 + }
112524 +
112525 + if (code != PARM_DECL && code != FUNCTION_DECL && code != COMPONENT_REF)
112526 + return;
112527 +
112528 +#if BUILDING_GCC_VERSION <= 4007
112529 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, element) {
112530 +#else
112531 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, element) {
112532 +#endif
112533 + if (operand_equal_p(node, element, 0))
112534 + return;
112535 + }
112536 +
112537 +#if BUILDING_GCC_VERSION <= 4007
112538 + gcc_assert(VEC_length(tree, cur_node->last_nodes) < VEC_LEN);
112539 + VEC_safe_push(tree, gc, cur_node->last_nodes, node);
112540 +#else
112541 + gcc_assert(cur_node->last_nodes->length() < VEC_LEN);
112542 + vec_safe_push(cur_node->last_nodes, node);
112543 +#endif
112544 +}
112545 +
112546 +// a size_overflow asm stmt in the control flow doesn't stop the recursion
112547 +static void handle_asm_stmt(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs, const_gimple stmt)
112548 +{
112549 + if (!is_size_overflow_asm(stmt))
112550 + walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
112551 +}
112552 +
112553 +/* collect the parm_decls and fndecls (for checking a missing size_overflow attribute (ret or arg) or intentional_overflow)
112554 + * and component refs (for checking the intentional_overflow attribute).
112555 + */
112556 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
112557 +{
112558 + const_gimple def_stmt;
112559 +
112560 + if (TREE_CODE(lhs) != SSA_NAME) {
112561 + insert_last_node(cur_node, lhs);
112562 + return;
112563 + }
112564 +
112565 + def_stmt = get_def_stmt(lhs);
112566 + if (!def_stmt)
112567 + return;
112568 +
112569 + if (pointer_set_insert(visited, def_stmt))
112570 + return;
112571 +
112572 + switch (gimple_code(def_stmt)) {
112573 + case GIMPLE_NOP:
112574 + return walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
112575 + case GIMPLE_ASM:
112576 + return handle_asm_stmt(visited, cur_node, lhs, def_stmt);
112577 + case GIMPLE_CALL: {
112578 + tree fndecl = gimple_call_fndecl(def_stmt);
112579 +
112580 + if (fndecl == NULL_TREE)
112581 + return;
112582 + insert_last_node(cur_node, fndecl);
112583 + return;
112584 + }
112585 + case GIMPLE_PHI:
112586 + return walk_use_def_phi(visited, cur_node, lhs);
112587 + case GIMPLE_ASSIGN:
112588 + switch (gimple_num_ops(def_stmt)) {
112589 + case 2:
112590 + return walk_use_def(visited, cur_node, gimple_assign_rhs1(def_stmt));
112591 + case 3:
112592 + return walk_use_def_binary(visited, cur_node, lhs);
112593 + }
112594 + default:
112595 + debug_gimple_stmt((gimple)def_stmt);
112596 + error("%s: unknown gimple code", __func__);
112597 + gcc_unreachable();
112598 + }
112599 +}
112600 +
112601 +// Collect all the last nodes for checking the intentional_overflow and size_overflow attributes
112602 +static void set_last_nodes(struct interesting_node *cur_node)
112603 +{
112604 + struct pointer_set_t *visited;
112605 +
112606 + visited = pointer_set_create();
112607 + walk_use_def(visited, cur_node, cur_node->node);
112608 + pointer_set_destroy(visited);
112609 +}
112610 +
112611 +enum precond {
112612 + NO_ATTRIBUTE_SEARCH, NO_CHECK_INSERT, NONE
112613 +};
112614 +
112615 +/* 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.
112616 + * There is only missing size_overflow attribute checking if the intentional_overflow attribute is the mark_no type.
112617 + * Stmt duplication is unnecessary if there are no binary/ternary assignements or if the unary assignment isn't a cast.
112618 + * It skips the possible error codes too. If the def_stmts trace back to a constant and there are no binary/ternary assigments then we assume that it is some kind of error code.
112619 + */
112620 +static enum precond check_preconditions(struct interesting_node *cur_node)
112621 +{
112622 + bool interesting_conditions[3] = {false, false, false};
112623 +
112624 + set_last_nodes(cur_node);
112625 +
112626 + check_intentional_attribute_ipa(cur_node);
112627 + if (cur_node->intentional_attr_decl == MARK_TURN_OFF || cur_node->intentional_attr_cur_fndecl == MARK_TURN_OFF)
112628 + return NO_ATTRIBUTE_SEARCH;
112629 +
112630 + search_interesting_conditions(cur_node, interesting_conditions);
112631 +
112632 + // error code
112633 + if (interesting_conditions[CAST] && interesting_conditions[FROM_CONST] && !interesting_conditions[NOT_UNARY])
112634 + return NO_ATTRIBUTE_SEARCH;
112635 +
112636 + // unnecessary overflow check
112637 + if (!interesting_conditions[CAST] && !interesting_conditions[NOT_UNARY])
112638 + return NO_CHECK_INSERT;
112639 +
112640 + if (cur_node->intentional_attr_cur_fndecl != MARK_NO)
112641 + return NO_CHECK_INSERT;
112642 +
112643 + return NONE;
112644 +}
112645 +
112646 +static tree cast_to_orig_type(struct visited *visited, gimple stmt, const_tree orig_node, tree new_node)
112647 +{
112648 + const_gimple assign;
112649 + tree orig_type = TREE_TYPE(orig_node);
112650 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
112651 +
112652 + assign = build_cast_stmt(visited, orig_type, new_node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
112653 + return gimple_assign_lhs(assign);
112654 +}
112655 +
112656 +static void change_orig_node(struct visited *visited, struct interesting_node *cur_node, tree new_node)
112657 +{
112658 + void (*set_rhs)(gimple, tree);
112659 + gimple stmt = cur_node->first_stmt;
112660 + const_tree orig_node = cur_node->node;
112661 +
112662 + switch (gimple_code(stmt)) {
112663 + case GIMPLE_RETURN:
112664 + gimple_return_set_retval(stmt, cast_to_orig_type(visited, stmt, orig_node, new_node));
112665 + break;
112666 + case GIMPLE_CALL:
112667 + gimple_call_set_arg(stmt, cur_node->num - 1, cast_to_orig_type(visited, stmt, orig_node, new_node));
112668 + break;
112669 + case GIMPLE_ASSIGN:
112670 + switch (cur_node->num) {
112671 + case 1:
112672 + set_rhs = &gimple_assign_set_rhs1;
112673 + break;
112674 + case 2:
112675 + set_rhs = &gimple_assign_set_rhs2;
112676 + break;
112677 +#if BUILDING_GCC_VERSION >= 4006
112678 + case 3:
112679 + set_rhs = &gimple_assign_set_rhs3;
112680 + break;
112681 +#endif
112682 + default:
112683 + gcc_unreachable();
112684 + }
112685 +
112686 + set_rhs(stmt, cast_to_orig_type(visited, stmt, orig_node, new_node));
112687 + break;
112688 + default:
112689 + debug_gimple_stmt(stmt);
112690 + gcc_unreachable();
112691 + }
112692 +
112693 + update_stmt(stmt);
112694 +}
112695 +
112696 +static struct visited *create_visited(void)
112697 +{
112698 + struct visited *new_node;
112699 +
112700 + new_node = (struct visited *)xmalloc(sizeof(*new_node));
112701 + new_node->stmts = pointer_set_create();
112702 + new_node->my_stmts = pointer_set_create();
112703 + new_node->skip_expr_casts = pointer_set_create();
112704 + new_node->no_cast_check = pointer_set_create();
112705 + return new_node;
112706 +}
112707 +
112708 +static void free_visited(struct visited *visited)
112709 +{
112710 + pointer_set_destroy(visited->stmts);
112711 + pointer_set_destroy(visited->my_stmts);
112712 + pointer_set_destroy(visited->skip_expr_casts);
112713 + pointer_set_destroy(visited->no_cast_check);
112714 +
112715 + free(visited);
112716 +}
112717 +
112718 +/* This function calls the main recursion function (expand) that duplicates the stmts. Before that it checks the intentional_overflow attribute and asm stmts,
112719 + * 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
112720 + * in the original stmt (first stmt) and it inserts the overflow check for the arg of the callee or for the return value.
112721 + */
112722 +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)
112723 +{
112724 + enum precond ret;
112725 + tree new_node, orig_node = cur_node->node;
112726 +
112727 + ret = check_preconditions(cur_node);
112728 + if (ret == NO_ATTRIBUTE_SEARCH)
112729 + return cnodes;
112730 +
112731 + cnodes = search_overflow_attribute(cnodes, cur_node);
112732 +
112733 + if (ret == NO_CHECK_INSERT)
112734 + return cnodes;
112735 +
112736 + new_node = expand(visited, caller_node, orig_node);
112737 + if (new_node == NULL_TREE)
112738 + return cnodes;
112739 +
112740 + change_orig_node(visited, cur_node, new_node);
112741 + check_size_overflow(caller_node, cur_node->first_stmt, TREE_TYPE(new_node), new_node, orig_node, BEFORE_STMT);
112742 +
112743 + return cnodes;
112744 +}
112745 +
112746 +// Check visited_fns interesting nodes.
112747 +static bool is_in_interesting_node(struct interesting_node *head, const_gimple first_stmt, const_tree node, unsigned int num)
112748 +{
112749 + struct interesting_node *cur;
112750 +
112751 + for (cur = head; cur; cur = cur->next) {
112752 + if (!operand_equal_p(node, cur->node, 0))
112753 + continue;
112754 + if (num != cur->num)
112755 + continue;
112756 + if (first_stmt == cur->first_stmt)
112757 + return true;
112758 + }
112759 + return false;
112760 +}
112761 +
112762 +/* Create an interesting node. The ipa pass starts to duplicate from these stmts.
112763 + 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
112764 + 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
112765 + the intentional_overflow attribute check. They are collected by set_last_nodes().
112766 + num: arg count of a call stmt or 0 when it is a ret
112767 + node: the recursion starts from here, it is a call arg or a return value
112768 + 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.
112769 + intentional_attr_decl: intentional_overflow attribute of the callee function
112770 + intentional_attr_cur_fndecl: intentional_overflow attribute of the caller function
112771 + intentional_mark_from_gimple: the intentional overflow type of size_overflow asm stmt from gimple if it exists
112772 + */
112773 +static struct interesting_node *create_new_interesting_node(struct interesting_node *head, gimple first_stmt, tree node, unsigned int num, gimple asm_stmt)
112774 +{
112775 + struct interesting_node *new_node;
112776 + tree fndecl;
112777 + enum gimple_code code;
112778 +
112779 + gcc_assert(node != NULL_TREE);
112780 + code = gimple_code(first_stmt);
112781 + gcc_assert(code == GIMPLE_CALL || code == GIMPLE_ASM || code == GIMPLE_ASSIGN || code == GIMPLE_RETURN);
112782 +
112783 + if (num == CANNOT_FIND_ARG)
112784 + return head;
112785 +
112786 + if (skip_types(node))
112787 + return head;
112788 +
112789 + if (skip_asm(node))
112790 + return head;
112791 +
112792 + if (is_gimple_call(first_stmt))
112793 + fndecl = gimple_call_fndecl(first_stmt);
112794 + else
112795 + fndecl = current_function_decl;
112796 +
112797 + if (fndecl == NULL_TREE)
112798 + return head;
112799 +
112800 + if (is_in_interesting_node(head, first_stmt, node, num))
112801 + return head;
112802 +
112803 + new_node = (struct interesting_node *)xmalloc(sizeof(*new_node));
112804 +
112805 + new_node->next = NULL;
112806 + new_node->first_stmt = first_stmt;
112807 +#if BUILDING_GCC_VERSION <= 4007
112808 + new_node->last_nodes = VEC_alloc(tree, gc, VEC_LEN);
112809 +#else
112810 + vec_alloc(new_node->last_nodes, VEC_LEN);
112811 +#endif
112812 + new_node->num = num;
112813 + new_node->node = node;
112814 + new_node->fndecl = fndecl;
112815 + new_node->intentional_attr_decl = MARK_NO;
112816 + new_node->intentional_attr_cur_fndecl = MARK_NO;
112817 + new_node->intentional_mark_from_gimple = asm_stmt;
112818 +
112819 + if (!head)
112820 + return new_node;
112821 +
112822 + new_node->next = head;
112823 + return new_node;
112824 +}
112825 +
112826 +/* 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).
112827 + * If the ret stmt is in the next cgraph node list then it's an interesting ret.
112828 + */
112829 +static struct interesting_node *handle_stmt_by_cgraph_nodes_ret(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
112830 +{
112831 + struct next_cgraph_node *cur_node;
112832 + tree ret = gimple_return_retval(stmt);
112833 +
112834 + if (ret == NULL_TREE)
112835 + return head;
112836 +
112837 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
112838 + if (!operand_equal_p(cur_node->callee_fndecl, DECL_ORIGIN(current_function_decl), 0))
112839 + continue;
112840 + if (cur_node->num == 0)
112841 + head = create_new_interesting_node(head, stmt, ret, 0, NOT_INTENTIONAL_ASM);
112842 + }
112843 +
112844 + return head;
112845 +}
112846 +
112847 +/* 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).
112848 + * If the call stmt is in the next cgraph node list then it's an interesting call.
112849 + */
112850 +static struct interesting_node *handle_stmt_by_cgraph_nodes_call(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
112851 +{
112852 + unsigned int argnum;
112853 + tree arg;
112854 + const_tree fndecl;
112855 + struct next_cgraph_node *cur_node;
112856 +
112857 + fndecl = gimple_call_fndecl(stmt);
112858 + if (fndecl == NULL_TREE)
112859 + return head;
112860 +
112861 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
112862 + if (!operand_equal_p(cur_node->callee_fndecl, fndecl, 0))
112863 + continue;
112864 + argnum = get_correct_arg_count(cur_node->num, fndecl);
112865 + gcc_assert(argnum != CANNOT_FIND_ARG);
112866 + if (argnum == 0)
112867 + continue;
112868 +
112869 + arg = gimple_call_arg(stmt, argnum - 1);
112870 + head = create_new_interesting_node(head, stmt, arg, argnum, NOT_INTENTIONAL_ASM);
112871 + }
112872 +
112873 + return head;
112874 +}
112875 +
112876 +static unsigned int check_ops(const_tree orig_node, const_tree node, unsigned int ret_count)
112877 +{
112878 + if (!operand_equal_p(orig_node, node, 0))
112879 + return WRONG_NODE;
112880 + if (skip_types(node))
112881 + return WRONG_NODE;
112882 + return ret_count;
112883 +}
112884 +
112885 +// Get the index of the rhs node in an assignment
112886 +static unsigned int get_assign_ops_count(const_gimple stmt, tree node)
112887 +{
112888 + const_tree rhs1, rhs2;
112889 + unsigned int ret;
112890 +
112891 + gcc_assert(stmt);
112892 + gcc_assert(is_gimple_assign(stmt));
112893 +
112894 + rhs1 = gimple_assign_rhs1(stmt);
112895 + gcc_assert(rhs1 != NULL_TREE);
112896 +
112897 + switch (gimple_num_ops(stmt)) {
112898 + case 2:
112899 + return check_ops(node, rhs1, 1);
112900 + case 3:
112901 + ret = check_ops(node, rhs1, 1);
112902 + if (ret != WRONG_NODE)
112903 + return ret;
112904 +
112905 + rhs2 = gimple_assign_rhs2(stmt);
112906 + gcc_assert(rhs2 != NULL_TREE);
112907 + return check_ops(node, rhs2, 2);
112908 + default:
112909 + gcc_unreachable();
112910 + }
112911 +}
112912 +
112913 +// Find the correct arg number of a call stmt. It is needed when the interesting function is a cloned function.
112914 +static unsigned int find_arg_number_gimple(const_tree arg, const_gimple stmt)
112915 +{
112916 + unsigned int i;
112917 +
112918 + if (gimple_call_fndecl(stmt) == NULL_TREE)
112919 + return CANNOT_FIND_ARG;
112920 +
112921 + for (i = 0; i < gimple_call_num_args(stmt); i++) {
112922 + tree node;
112923 +
112924 + node = gimple_call_arg(stmt, i);
112925 + if (!operand_equal_p(arg, node, 0))
112926 + continue;
112927 + if (!skip_types(node))
112928 + return i + 1;
112929 + }
112930 +
112931 + return CANNOT_FIND_ARG;
112932 +}
112933 +
112934 +/* starting from the size_overflow asm stmt collect interesting stmts. They can be
112935 + * any of return, call or assignment stmts (because of inlining).
112936 + */
112937 +static struct interesting_node *get_interesting_ret_or_call(struct pointer_set_t *visited, struct interesting_node *head, tree node, gimple intentional_asm)
112938 +{
112939 + use_operand_p use_p;
112940 + imm_use_iterator imm_iter;
112941 + unsigned int argnum;
112942 +
112943 + gcc_assert(TREE_CODE(node) == SSA_NAME);
112944 +
112945 + if (pointer_set_insert(visited, node))
112946 + return head;
112947 +
112948 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
112949 + gimple stmt = USE_STMT(use_p);
112950 +
112951 + if (stmt == NULL)
112952 + return head;
112953 + if (is_gimple_debug(stmt))
112954 + continue;
112955 +
112956 + switch (gimple_code(stmt)) {
112957 + case GIMPLE_CALL:
112958 + argnum = find_arg_number_gimple(node, stmt);
112959 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
112960 + break;
112961 + case GIMPLE_RETURN:
112962 + head = create_new_interesting_node(head, stmt, node, 0, intentional_asm);
112963 + break;
112964 + case GIMPLE_ASSIGN:
112965 + argnum = get_assign_ops_count(stmt, node);
112966 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
112967 + break;
112968 + case GIMPLE_PHI: {
112969 + tree result = gimple_phi_result(stmt);
112970 + head = get_interesting_ret_or_call(visited, head, result, intentional_asm);
112971 + break;
112972 + }
112973 + case GIMPLE_ASM:
112974 + if (gimple_asm_noutputs(stmt) != 0)
112975 + break;
112976 + if (!is_size_overflow_asm(stmt))
112977 + break;
112978 + head = create_new_interesting_node(head, stmt, node, 1, intentional_asm);
112979 + break;
112980 + case GIMPLE_COND:
112981 + case GIMPLE_SWITCH:
112982 + break;
112983 + default:
112984 + debug_gimple_stmt(stmt);
112985 + gcc_unreachable();
112986 + break;
112987 + }
112988 + }
112989 + return head;
112990 +}
112991 +
112992 +static void remove_size_overflow_asm(gimple stmt)
112993 +{
112994 + gimple_stmt_iterator gsi;
112995 + tree input, output;
112996 +
112997 + if (!is_size_overflow_asm(stmt))
112998 + return;
112999 +
113000 + if (gimple_asm_noutputs(stmt) == 0) {
113001 + gsi = gsi_for_stmt(stmt);
113002 + ipa_remove_stmt_references(cgraph_get_create_node(current_function_decl), stmt);
113003 + gsi_remove(&gsi, true);
113004 + return;
113005 + }
113006 +
113007 + input = gimple_asm_input_op(stmt, 0);
113008 + output = gimple_asm_output_op(stmt, 0);
113009 + replace_size_overflow_asm_with_assign(stmt, TREE_VALUE(output), TREE_VALUE(input));
113010 +}
113011 +
113012 +/* handle the size_overflow asm stmts from the gimple pass and collect the interesting stmts.
113013 + * If the asm stmt is a parm_decl kind (noutputs == 0) then remove it.
113014 + * If it is a simple asm stmt then replace it with an assignment from the asm input to the asm output.
113015 + */
113016 +static struct interesting_node *handle_stmt_by_size_overflow_asm(gimple stmt, struct interesting_node *head)
113017 +{
113018 + const_tree output;
113019 + struct pointer_set_t *visited;
113020 + gimple intentional_asm = NOT_INTENTIONAL_ASM;
113021 +
113022 + if (!is_size_overflow_asm(stmt))
113023 + return head;
113024 +
113025 + if (is_size_overflow_intentional_asm_yes(stmt) || is_size_overflow_intentional_asm_turn_off(stmt))
113026 + intentional_asm = stmt;
113027 +
113028 + gcc_assert(gimple_asm_ninputs(stmt) == 1);
113029 +
113030 + if (gimple_asm_noutputs(stmt) == 0 && is_size_overflow_intentional_asm_turn_off(stmt))
113031 + return head;
113032 +
113033 + if (gimple_asm_noutputs(stmt) == 0) {
113034 + const_tree input;
113035 +
113036 + if (!is_size_overflow_intentional_asm_turn_off(stmt))
113037 + return head;
113038 +
113039 + input = gimple_asm_input_op(stmt, 0);
113040 + remove_size_overflow_asm(stmt);
113041 + if (is_gimple_constant(TREE_VALUE(input)))
113042 + return head;
113043 + visited = pointer_set_create();
113044 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(input), intentional_asm);
113045 + pointer_set_destroy(visited);
113046 + return head;
113047 + }
113048 +
113049 + if (!is_size_overflow_intentional_asm_yes(stmt) && !is_size_overflow_intentional_asm_turn_off(stmt))
113050 + remove_size_overflow_asm(stmt);
113051 +
113052 + visited = pointer_set_create();
113053 + output = gimple_asm_output_op(stmt, 0);
113054 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(output), intentional_asm);
113055 + pointer_set_destroy(visited);
113056 + return head;
113057 +}
113058 +
113059 +/* Iterate over all the stmts of a function and look for the size_overflow asm stmts (they were created in the gimple pass)
113060 + * or a call stmt or a return stmt and store them in the interesting_node list
113061 + */
113062 +static struct interesting_node *collect_interesting_stmts(struct next_cgraph_node *next_node)
113063 +{
113064 + basic_block bb;
113065 + struct interesting_node *head = NULL;
113066 +
113067 + FOR_ALL_BB_FN(bb, cfun) {
113068 + gimple_stmt_iterator gsi;
113069 +
113070 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
113071 + enum gimple_code code;
113072 + gimple stmt = gsi_stmt(gsi);
113073 +
113074 + code = gimple_code(stmt);
113075 +
113076 + if (code == GIMPLE_ASM)
113077 + head = handle_stmt_by_size_overflow_asm(stmt, head);
113078 +
113079 + if (!next_node)
113080 + continue;
113081 + if (code == GIMPLE_CALL)
113082 + head = handle_stmt_by_cgraph_nodes_call(head, stmt, next_node);
113083 + if (code == GIMPLE_RETURN)
113084 + head = handle_stmt_by_cgraph_nodes_ret(head, stmt, next_node);
113085 + }
113086 + }
113087 + return head;
113088 +}
113089 +
113090 +static void free_interesting_node(struct interesting_node *head)
113091 +{
113092 + struct interesting_node *cur;
113093 +
113094 + while (head) {
113095 + cur = head->next;
113096 +#if BUILDING_GCC_VERSION <= 4007
113097 + VEC_free(tree, gc, head->last_nodes);
113098 +#else
113099 + vec_free(head->last_nodes);
113100 +#endif
113101 + free(head);
113102 + head = cur;
113103 + }
113104 +}
113105 +
113106 +static struct visited_fns *insert_visited_fns_function(struct visited_fns *head, struct interesting_node *cur_node)
113107 +{
113108 + struct visited_fns *new_visited_fns;
113109 +
113110 + new_visited_fns = (struct visited_fns *)xmalloc(sizeof(*new_visited_fns));
113111 + new_visited_fns->fndecl = cur_node->fndecl;
113112 + new_visited_fns->num = cur_node->num;
113113 + new_visited_fns->first_stmt = cur_node->first_stmt;
113114 + new_visited_fns->next = NULL;
113115 +
113116 + if (!head)
113117 + return new_visited_fns;
113118 +
113119 + new_visited_fns->next = head;
113120 + return new_visited_fns;
113121 +}
113122 +
113123 +/* 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
113124 + * it is a visited_fns function.
113125 + */
113126 +static bool is_visited_fns_function(struct visited_fns *head, struct interesting_node *cur_node)
113127 +{
113128 + struct visited_fns *cur;
113129 +
113130 + if (!head)
113131 + return false;
113132 +
113133 + for (cur = head; cur; cur = cur->next) {
113134 + if (cur_node->first_stmt != cur->first_stmt)
113135 + continue;
113136 + if (!operand_equal_p(cur_node->fndecl, cur->fndecl, 0))
113137 + continue;
113138 + if (cur_node->num == cur->num)
113139 + return true;
113140 + }
113141 + return false;
113142 +}
113143 +
113144 +static void free_next_cgraph_node(struct next_cgraph_node *head)
113145 +{
113146 + struct next_cgraph_node *cur;
113147 +
113148 + while (head) {
113149 + cur = head->next;
113150 + free(head);
113151 + head = cur;
113152 + }
113153 +}
113154 +
113155 +static void remove_all_size_overflow_asm(void)
113156 +{
113157 + basic_block bb;
113158 +
113159 + FOR_ALL_BB_FN(bb, cfun) {
113160 + gimple_stmt_iterator si;
113161 +
113162 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
113163 + remove_size_overflow_asm(gsi_stmt(si));
113164 + }
113165 +}
113166 +
113167 +/* Main recursive walk of the ipa pass: iterate over the collected interesting stmts in a function
113168 + * (they are interesting if they have an associated size_overflow asm stmt) and recursively walk
113169 + * the newly collected interesting functions (they are interesting if there is control flow between
113170 + * the interesting stmts and them).
113171 + */
113172 +static struct visited_fns *handle_function(struct cgraph_node *node, struct next_cgraph_node *next_node, struct visited_fns *visited_fns)
113173 +{
113174 + struct visited *visited;
113175 + struct interesting_node *head, *cur_node;
113176 + struct next_cgraph_node *cur_cnodes, *cnodes_head = NULL;
113177 +
113178 + set_current_function_decl(NODE_DECL(node));
113179 + call_count = 0;
113180 +
113181 + head = collect_interesting_stmts(next_node);
113182 +
113183 + visited = create_visited();
113184 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
113185 + if (is_visited_fns_function(visited_fns, cur_node))
113186 + continue;
113187 + cnodes_head = handle_interesting_stmt(visited, cnodes_head, cur_node, node);
113188 + visited_fns = insert_visited_fns_function(visited_fns, cur_node);
113189 + }
113190 +
113191 + free_visited(visited);
113192 + free_interesting_node(head);
113193 + remove_all_size_overflow_asm();
113194 + unset_current_function_decl();
113195 +
113196 + for (cur_cnodes = cnodes_head; cur_cnodes; cur_cnodes = cur_cnodes->next)
113197 + visited_fns = handle_function(cur_cnodes->current_function, cur_cnodes, visited_fns);
113198 +
113199 + free_next_cgraph_node(cnodes_head);
113200 + return visited_fns;
113201 +}
113202 +
113203 +static void free_visited_fns(struct visited_fns *head)
113204 +{
113205 + struct visited_fns *cur;
113206 +
113207 + while (head) {
113208 + cur = head->next;
113209 + free(head);
113210 + head = cur;
113211 + }
113212 +}
113213 +
113214 +// Main entry point of the ipa pass: erases the plf flag of all stmts and iterates over all the functions
113215 +unsigned int search_function(void)
113216 +{
113217 + struct cgraph_node *node;
113218 + struct visited_fns *visited_fns = NULL;
113219 +
113220 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
113221 + gcc_assert(cgraph_function_flags_ready);
113222 +#if BUILDING_GCC_VERSION <= 4007
113223 + gcc_assert(node->reachable);
113224 +#endif
113225 +
113226 + visited_fns = handle_function(node, NULL, visited_fns);
113227 + }
113228 +
113229 + free_visited_fns(visited_fns);
113230 + return 0;
113231 +}
113232 +
113233 +#if BUILDING_GCC_VERSION >= 4009
113234 +static const struct pass_data insert_size_overflow_check_data = {
113235 +#else
113236 +static struct ipa_opt_pass_d insert_size_overflow_check = {
113237 + .pass = {
113238 +#endif
113239 + .type = SIMPLE_IPA_PASS,
113240 + .name = "size_overflow",
113241 +#if BUILDING_GCC_VERSION >= 4008
113242 + .optinfo_flags = OPTGROUP_NONE,
113243 +#endif
113244 +#if BUILDING_GCC_VERSION >= 4009
113245 + .has_gate = false,
113246 + .has_execute = true,
113247 +#else
113248 + .gate = NULL,
113249 + .execute = search_function,
113250 + .sub = NULL,
113251 + .next = NULL,
113252 + .static_pass_number = 0,
113253 +#endif
113254 + .tv_id = TV_NONE,
113255 + .properties_required = 0,
113256 + .properties_provided = 0,
113257 + .properties_destroyed = 0,
113258 + .todo_flags_start = 0,
113259 + .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,
113260 +#if BUILDING_GCC_VERSION < 4009
113261 + },
113262 + .generate_summary = NULL,
113263 + .write_summary = NULL,
113264 + .read_summary = NULL,
113265 +#if BUILDING_GCC_VERSION >= 4006
113266 + .write_optimization_summary = NULL,
113267 + .read_optimization_summary = NULL,
113268 +#endif
113269 + .stmt_fixup = NULL,
113270 + .function_transform_todo_flags_start = 0,
113271 + .function_transform = NULL,
113272 + .variable_transform = NULL,
113273 +#endif
113274 +};
113275 +
113276 +#if BUILDING_GCC_VERSION >= 4009
113277 +namespace {
113278 +class insert_size_overflow_check : public ipa_opt_pass_d {
113279 +public:
113280 + insert_size_overflow_check() : ipa_opt_pass_d(insert_size_overflow_check_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
113281 + unsigned int execute() { return search_function(); }
113282 +};
113283 +}
113284 +#endif
113285 +
113286 +struct opt_pass *make_insert_size_overflow_check(void)
113287 +{
113288 +#if BUILDING_GCC_VERSION >= 4009
113289 + return new insert_size_overflow_check();
113290 +#else
113291 + return &insert_size_overflow_check.pass;
113292 +#endif
113293 +}
113294 +
113295 diff --git a/tools/gcc/size_overflow_plugin/intentional_overflow.c b/tools/gcc/size_overflow_plugin/intentional_overflow.c
113296 new file mode 100644
113297 index 0000000..38904bc
113298 --- /dev/null
113299 +++ b/tools/gcc/size_overflow_plugin/intentional_overflow.c
113300 @@ -0,0 +1,733 @@
113301 +/*
113302 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
113303 + * Licensed under the GPL v2, or (at your option) v3
113304 + *
113305 + * Homepage:
113306 + * http://www.grsecurity.net/~ephox/overflow_plugin/
113307 + *
113308 + * Documentation:
113309 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
113310 + *
113311 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
113312 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
113313 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
113314 + *
113315 + * Usage:
113316 + * $ make
113317 + * $ make run
113318 + */
113319 +
113320 +#include "gcc-common.h"
113321 +#include "size_overflow.h"
113322 +
113323 +/* Get the param of the intentional_overflow attribute.
113324 + * * 0: MARK_NOT_INTENTIONAL
113325 + * * 1..MAX_PARAM: MARK_YES
113326 + * * -1: MARK_TURN_OFF
113327 + */
113328 +static tree get_attribute_param(const_tree decl)
113329 +{
113330 + const_tree attr;
113331 +
113332 + if (decl == NULL_TREE)
113333 + return NULL_TREE;
113334 +
113335 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(decl));
113336 + if (!attr || !TREE_VALUE(attr))
113337 + return NULL_TREE;
113338 +
113339 + return TREE_VALUE(attr);
113340 +}
113341 +
113342 +// MARK_TURN_OFF
113343 +bool is_turn_off_intentional_attr(const_tree decl)
113344 +{
113345 + const_tree param_head;
113346 +
113347 + param_head = get_attribute_param(decl);
113348 + if (param_head == NULL_TREE)
113349 + return false;
113350 +
113351 + if (TREE_INT_CST_HIGH(TREE_VALUE(param_head)) == -1)
113352 + return true;
113353 + return false;
113354 +}
113355 +
113356 +// MARK_NOT_INTENTIONAL
113357 +bool is_end_intentional_intentional_attr(const_tree decl, unsigned int argnum)
113358 +{
113359 + const_tree param_head;
113360 +
113361 + if (argnum == 0)
113362 + return false;
113363 +
113364 + param_head = get_attribute_param(decl);
113365 + if (param_head == NULL_TREE)
113366 + return false;
113367 +
113368 + if (!TREE_INT_CST_LOW(TREE_VALUE(param_head)))
113369 + return true;
113370 + return false;
113371 +}
113372 +
113373 +// MARK_YES
113374 +bool is_yes_intentional_attr(const_tree decl, unsigned int argnum)
113375 +{
113376 + tree param, param_head;
113377 +
113378 + if (argnum == 0)
113379 + return false;
113380 +
113381 + param_head = get_attribute_param(decl);
113382 + for (param = param_head; param; param = TREE_CHAIN(param))
113383 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(param)))
113384 + return true;
113385 + return false;
113386 +}
113387 +
113388 +void print_missing_intentional(enum mark callee_attr, enum mark caller_attr, const_tree decl, unsigned int argnum)
113389 +{
113390 + location_t loc;
113391 +
113392 + if (caller_attr == MARK_NO || caller_attr == MARK_NOT_INTENTIONAL || caller_attr == MARK_TURN_OFF)
113393 + return;
113394 +
113395 + if (callee_attr == MARK_NOT_INTENTIONAL || callee_attr == MARK_YES)
113396 + return;
113397 +
113398 + loc = DECL_SOURCE_LOCATION(decl);
113399 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", DECL_NAME_POINTER(decl), argnum);
113400 +}
113401 +
113402 +// Get the field decl of a component ref for intentional_overflow checking
113403 +static const_tree search_field_decl(const_tree comp_ref)
113404 +{
113405 + const_tree field = NULL_TREE;
113406 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
113407 +
113408 + for (i = 0; i < len; i++) {
113409 + field = TREE_OPERAND(comp_ref, i);
113410 + if (TREE_CODE(field) == FIELD_DECL)
113411 + break;
113412 + }
113413 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
113414 + return field;
113415 +}
113416 +
113417 +/* Get the type of the intentional_overflow attribute of a node
113418 + * * MARK_TURN_OFF
113419 + * * MARK_YES
113420 + * * MARK_NO
113421 + * * MARK_NOT_INTENTIONAL
113422 + */
113423 +enum mark get_intentional_attr_type(const_tree node)
113424 +{
113425 + const_tree cur_decl;
113426 +
113427 + if (node == NULL_TREE)
113428 + return MARK_NO;
113429 +
113430 + switch (TREE_CODE(node)) {
113431 + case COMPONENT_REF:
113432 + cur_decl = search_field_decl(node);
113433 + if (is_turn_off_intentional_attr(cur_decl))
113434 + return MARK_TURN_OFF;
113435 + if (is_end_intentional_intentional_attr(cur_decl, 1))
113436 + return MARK_YES;
113437 + break;
113438 + case PARM_DECL: {
113439 + unsigned int argnum;
113440 +
113441 + cur_decl = DECL_ORIGIN(current_function_decl);
113442 + argnum = find_arg_number_tree(node, cur_decl);
113443 + if (argnum == CANNOT_FIND_ARG)
113444 + return MARK_NO;
113445 + if (is_yes_intentional_attr(cur_decl, argnum))
113446 + return MARK_YES;
113447 + if (is_end_intentional_intentional_attr(cur_decl, argnum))
113448 + return MARK_NOT_INTENTIONAL;
113449 + break;
113450 + }
113451 + case FUNCTION_DECL:
113452 + if (is_turn_off_intentional_attr(DECL_ORIGIN(node)))
113453 + return MARK_TURN_OFF;
113454 + break;
113455 + default:
113456 + break;
113457 + }
113458 + return MARK_NO;
113459 +}
113460 +
113461 +// Search for the intentional_overflow attribute on the last nodes
113462 +static enum mark search_last_nodes_intentional(struct interesting_node *cur_node)
113463 +{
113464 + unsigned int i;
113465 + tree last_node;
113466 + enum mark mark = MARK_NO;
113467 +
113468 +#if BUILDING_GCC_VERSION <= 4007
113469 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, last_node) {
113470 +#else
113471 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, last_node) {
113472 +#endif
113473 + mark = get_intentional_attr_type(last_node);
113474 + if (mark != MARK_NO)
113475 + break;
113476 + }
113477 + return mark;
113478 +}
113479 +
113480 +/* Check the intentional kind of size_overflow asm stmt (created by the gimple pass) and
113481 + * set the appropriate intentional_overflow type. Delete the asm stmt in the end.
113482 + */
113483 +static bool is_intentional_attribute_from_gimple(struct interesting_node *cur_node)
113484 +{
113485 + if (!cur_node->intentional_mark_from_gimple)
113486 + return false;
113487 +
113488 + if (is_size_overflow_intentional_asm_yes(cur_node->intentional_mark_from_gimple))
113489 + cur_node->intentional_attr_cur_fndecl = MARK_YES;
113490 + else
113491 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
113492 +
113493 + // skip param decls
113494 + if (gimple_asm_noutputs(cur_node->intentional_mark_from_gimple) == 0)
113495 + return true;
113496 + return true;
113497 +}
113498 +
113499 +/* Search intentional_overflow attribute on caller and on callee too.
113500 + * 0</MARK_YES: no dup, search size_overflow and intentional_overflow attributes
113501 + * 0/MARK_NOT_INTENTIONAL: no dup, search size_overflow attribute (int)
113502 + * -1/MARK_TURN_OFF: no dup, no search, current_function_decl -> no dup
113503 +*/
113504 +void check_intentional_attribute_ipa(struct interesting_node *cur_node)
113505 +{
113506 + const_tree fndecl;
113507 +
113508 + if (is_intentional_attribute_from_gimple(cur_node))
113509 + return;
113510 +
113511 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
113512 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
113513 + return;
113514 + }
113515 +
113516 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASM) {
113517 + cur_node->intentional_attr_cur_fndecl = MARK_NOT_INTENTIONAL;
113518 + return;
113519 + }
113520 +
113521 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASSIGN)
113522 + return;
113523 +
113524 + fndecl = get_interesting_orig_fndecl(cur_node->first_stmt, cur_node->num);
113525 + if (is_turn_off_intentional_attr(fndecl)) {
113526 + cur_node->intentional_attr_decl = MARK_TURN_OFF;
113527 + return;
113528 + }
113529 +
113530 + if (is_end_intentional_intentional_attr(fndecl, cur_node->num))
113531 + cur_node->intentional_attr_decl = MARK_NOT_INTENTIONAL;
113532 + else if (is_yes_intentional_attr(fndecl, cur_node->num))
113533 + cur_node->intentional_attr_decl = MARK_YES;
113534 +
113535 + cur_node->intentional_attr_cur_fndecl = search_last_nodes_intentional(cur_node);
113536 + print_missing_intentional(cur_node->intentional_attr_decl, cur_node->intentional_attr_cur_fndecl, cur_node->fndecl, cur_node->num);
113537 +}
113538 +
113539 +bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
113540 +{
113541 + const_tree rhs1, lhs, rhs1_type, lhs_type;
113542 + enum machine_mode lhs_mode, rhs_mode;
113543 + gimple def_stmt = get_def_stmt(no_const_rhs);
113544 +
113545 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
113546 + return false;
113547 +
113548 + rhs1 = gimple_assign_rhs1(def_stmt);
113549 + lhs = gimple_assign_lhs(def_stmt);
113550 + rhs1_type = TREE_TYPE(rhs1);
113551 + lhs_type = TREE_TYPE(lhs);
113552 + rhs_mode = TYPE_MODE(rhs1_type);
113553 + lhs_mode = TYPE_MODE(lhs_type);
113554 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
113555 + return false;
113556 +
113557 + return true;
113558 +}
113559 +
113560 +static unsigned int uses_num(tree node)
113561 +{
113562 + imm_use_iterator imm_iter;
113563 + use_operand_p use_p;
113564 + unsigned int num = 0;
113565 +
113566 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
113567 + gimple use_stmt = USE_STMT(use_p);
113568 +
113569 + if (use_stmt == NULL)
113570 + return num;
113571 + if (is_gimple_debug(use_stmt))
113572 + continue;
113573 + if (gimple_assign_cast_p(use_stmt) && is_size_overflow_type(gimple_assign_lhs(use_stmt)))
113574 + continue;
113575 + num++;
113576 + }
113577 + return num;
113578 +}
113579 +
113580 +static bool no_uses(tree node)
113581 +{
113582 + return !uses_num(node);
113583 +}
113584 +
113585 +// 3.8.5 mm/page-writeback.c __ilog2_u64(): ret, uint + uintmax; uint -> int; int max
113586 +bool is_const_plus_unsigned_signed_truncation(const_tree lhs)
113587 +{
113588 + tree rhs1, lhs_type, rhs_type, rhs2, not_const_rhs;
113589 + gimple def_stmt = get_def_stmt(lhs);
113590 +
113591 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
113592 + return false;
113593 +
113594 + rhs1 = gimple_assign_rhs1(def_stmt);
113595 + rhs_type = TREE_TYPE(rhs1);
113596 + lhs_type = TREE_TYPE(lhs);
113597 + if (TYPE_UNSIGNED(lhs_type) || !TYPE_UNSIGNED(rhs_type))
113598 + return false;
113599 + if (TYPE_MODE(lhs_type) != TYPE_MODE(rhs_type))
113600 + return false;
113601 +
113602 + def_stmt = get_def_stmt(rhs1);
113603 + if (!def_stmt || !is_gimple_assign(def_stmt) || gimple_num_ops(def_stmt) != 3)
113604 + return false;
113605 +
113606 + if (gimple_assign_rhs_code(def_stmt) != PLUS_EXPR)
113607 + return false;
113608 +
113609 + rhs1 = gimple_assign_rhs1(def_stmt);
113610 + rhs2 = gimple_assign_rhs2(def_stmt);
113611 + if (!is_gimple_constant(rhs1) && !is_gimple_constant(rhs2))
113612 + return false;
113613 +
113614 + if (is_gimple_constant(rhs2))
113615 + not_const_rhs = rhs1;
113616 + else
113617 + not_const_rhs = rhs2;
113618 +
113619 + return no_uses(not_const_rhs);
113620 +}
113621 +
113622 +static bool is_lt_signed_type_max(const_tree rhs)
113623 +{
113624 + const_tree new_type, type_max, type = TREE_TYPE(rhs);
113625 +
113626 + if (!TYPE_UNSIGNED(type))
113627 + return true;
113628 +
113629 + switch (TYPE_MODE(type)) {
113630 + case QImode:
113631 + new_type = intQI_type_node;
113632 + break;
113633 + case HImode:
113634 + new_type = intHI_type_node;
113635 + break;
113636 + case SImode:
113637 + new_type = intSI_type_node;
113638 + break;
113639 + case DImode:
113640 + new_type = intDI_type_node;
113641 + break;
113642 + default:
113643 + debug_tree((tree)type);
113644 + gcc_unreachable();
113645 + }
113646 +
113647 + type_max = TYPE_MAX_VALUE(new_type);
113648 + if (!tree_int_cst_lt(type_max, rhs))
113649 + return true;
113650 +
113651 + return false;
113652 +}
113653 +
113654 +static bool is_gt_zero(const_tree rhs)
113655 +{
113656 + const_tree type = TREE_TYPE(rhs);
113657 +
113658 + if (TYPE_UNSIGNED(type))
113659 + return true;
113660 +
113661 + if (!tree_int_cst_lt(rhs, integer_zero_node))
113662 + return true;
113663 +
113664 + return false;
113665 +}
113666 +
113667 +bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
113668 +{
113669 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
113670 + return false;
113671 + if (!is_gimple_constant(rhs))
113672 + return false;
113673 +
113674 + // If the const is between 0 and the max value of the signed type of the same bitsize then there is no intentional overflow
113675 + if (is_lt_signed_type_max(rhs) && is_gt_zero(rhs))
113676 + return false;
113677 +
113678 + return true;
113679 +}
113680 +
113681 +static tree change_assign_rhs(struct visited *visited, gimple stmt, const_tree orig_rhs, tree new_rhs)
113682 +{
113683 + gimple assign;
113684 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
113685 + tree origtype = TREE_TYPE(orig_rhs);
113686 +
113687 + gcc_assert(is_gimple_assign(stmt));
113688 +
113689 + assign = build_cast_stmt(visited, origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
113690 + pointer_set_insert(visited->my_stmts, assign);
113691 + return gimple_assign_lhs(assign);
113692 +}
113693 +
113694 +tree handle_intentional_overflow(struct visited *visited, struct cgraph_node *caller_node, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs2)
113695 +{
113696 + tree new_rhs, orig_rhs;
113697 + void (*gimple_assign_set_rhs)(gimple, tree);
113698 + tree rhs1 = gimple_assign_rhs1(stmt);
113699 + tree rhs2 = gimple_assign_rhs2(stmt);
113700 + tree lhs = gimple_assign_lhs(stmt);
113701 +
113702 + if (!check_overflow)
113703 + return create_assign(visited, stmt, lhs, AFTER_STMT);
113704 +
113705 + if (change_rhs == NULL_TREE)
113706 + return create_assign(visited, stmt, lhs, AFTER_STMT);
113707 +
113708 + if (new_rhs2 == NULL_TREE) {
113709 + orig_rhs = rhs1;
113710 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
113711 + } else {
113712 + orig_rhs = rhs2;
113713 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
113714 + }
113715 +
113716 + check_size_overflow(caller_node, stmt, TREE_TYPE(change_rhs), change_rhs, orig_rhs, BEFORE_STMT);
113717 +
113718 + new_rhs = change_assign_rhs(visited, stmt, orig_rhs, change_rhs);
113719 + gimple_assign_set_rhs(stmt, new_rhs);
113720 + update_stmt(stmt);
113721 +
113722 + return create_assign(visited, stmt, lhs, AFTER_STMT);
113723 +}
113724 +
113725 +static bool is_subtraction_special(struct visited *visited, const_gimple stmt)
113726 +{
113727 + gimple rhs1_def_stmt, rhs2_def_stmt;
113728 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1, rhs1_def_stmt_lhs, rhs2_def_stmt_lhs;
113729 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode, rhs1_def_stmt_lhs_mode, rhs2_def_stmt_lhs_mode;
113730 + const_tree rhs1 = gimple_assign_rhs1(stmt);
113731 + const_tree rhs2 = gimple_assign_rhs2(stmt);
113732 +
113733 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
113734 + return false;
113735 +
113736 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
113737 +
113738 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
113739 + return false;
113740 +
113741 + rhs1_def_stmt = get_def_stmt(rhs1);
113742 + rhs2_def_stmt = get_def_stmt(rhs2);
113743 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
113744 + return false;
113745 +
113746 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
113747 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
113748 + rhs1_def_stmt_lhs = gimple_assign_lhs(rhs1_def_stmt);
113749 + rhs2_def_stmt_lhs = gimple_assign_lhs(rhs2_def_stmt);
113750 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
113751 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
113752 + rhs1_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_lhs));
113753 + rhs2_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_lhs));
113754 + if (GET_MODE_BITSIZE(rhs1_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs1_def_stmt_lhs_mode))
113755 + return false;
113756 + if (GET_MODE_BITSIZE(rhs2_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs2_def_stmt_lhs_mode))
113757 + return false;
113758 +
113759 + pointer_set_insert(visited->no_cast_check, rhs1_def_stmt);
113760 + pointer_set_insert(visited->no_cast_check, rhs2_def_stmt);
113761 + return true;
113762 +}
113763 +
113764 +static gimple create_binary_assign(struct visited *visited, enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
113765 +{
113766 + gimple assign;
113767 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
113768 + tree type = TREE_TYPE(rhs1);
113769 + tree lhs = create_new_var(type);
113770 +
113771 + gcc_assert(types_compatible_p(type, TREE_TYPE(rhs2)));
113772 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
113773 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
113774 +
113775 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
113776 + update_stmt(assign);
113777 + pointer_set_insert(visited->my_stmts, assign);
113778 + return assign;
113779 +}
113780 +
113781 +static tree cast_to_TI_type(struct visited *visited, gimple stmt, tree node)
113782 +{
113783 + gimple_stmt_iterator gsi;
113784 + gimple cast_stmt;
113785 + tree type = TREE_TYPE(node);
113786 +
113787 + if (types_compatible_p(type, intTI_type_node))
113788 + return node;
113789 +
113790 + gsi = gsi_for_stmt(stmt);
113791 + cast_stmt = build_cast_stmt(visited, intTI_type_node, node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
113792 + pointer_set_insert(visited->my_stmts, cast_stmt);
113793 + return gimple_assign_lhs(cast_stmt);
113794 +}
113795 +
113796 +static tree get_def_stmt_rhs(struct visited *visited, const_tree var)
113797 +{
113798 + tree rhs1, def_stmt_rhs1;
113799 + gimple rhs1_def_stmt, def_stmt_rhs1_def_stmt, def_stmt;
113800 +
113801 + def_stmt = get_def_stmt(var);
113802 + if (!gimple_assign_cast_p(def_stmt))
113803 + return NULL_TREE;
113804 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP && pointer_set_contains(visited->my_stmts, def_stmt) && gimple_assign_cast_p(def_stmt));
113805 +
113806 + rhs1 = gimple_assign_rhs1(def_stmt);
113807 + rhs1_def_stmt = get_def_stmt(rhs1);
113808 + if (!gimple_assign_cast_p(rhs1_def_stmt))
113809 + return rhs1;
113810 +
113811 + def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
113812 + def_stmt_rhs1_def_stmt = get_def_stmt(def_stmt_rhs1);
113813 +
113814 + switch (gimple_code(def_stmt_rhs1_def_stmt)) {
113815 + case GIMPLE_CALL:
113816 + case GIMPLE_NOP:
113817 + case GIMPLE_ASM:
113818 + case GIMPLE_PHI:
113819 + return def_stmt_rhs1;
113820 + case GIMPLE_ASSIGN:
113821 + return rhs1;
113822 + default:
113823 + debug_gimple_stmt(def_stmt_rhs1_def_stmt);
113824 + gcc_unreachable();
113825 + }
113826 +}
113827 +
113828 +tree handle_integer_truncation(struct visited *visited, struct cgraph_node *caller_node, const_tree lhs)
113829 +{
113830 + tree new_rhs1, new_rhs2;
113831 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
113832 + gimple assign, stmt = get_def_stmt(lhs);
113833 + tree rhs1 = gimple_assign_rhs1(stmt);
113834 + tree rhs2 = gimple_assign_rhs2(stmt);
113835 +
113836 + if (!is_subtraction_special(visited, stmt))
113837 + return NULL_TREE;
113838 +
113839 + new_rhs1 = expand(visited, caller_node, rhs1);
113840 + new_rhs2 = expand(visited, caller_node, rhs2);
113841 +
113842 + new_rhs1_def_stmt_rhs1 = get_def_stmt_rhs(visited, new_rhs1);
113843 + new_rhs2_def_stmt_rhs1 = get_def_stmt_rhs(visited, new_rhs2);
113844 +
113845 + if (new_rhs1_def_stmt_rhs1 == NULL_TREE || new_rhs2_def_stmt_rhs1 == NULL_TREE)
113846 + return NULL_TREE;
113847 +
113848 + if (!types_compatible_p(TREE_TYPE(new_rhs1_def_stmt_rhs1), TREE_TYPE(new_rhs2_def_stmt_rhs1))) {
113849 + new_rhs1_def_stmt_rhs1 = cast_to_TI_type(visited, stmt, new_rhs1_def_stmt_rhs1);
113850 + new_rhs2_def_stmt_rhs1 = cast_to_TI_type(visited, stmt, new_rhs2_def_stmt_rhs1);
113851 + }
113852 +
113853 + assign = create_binary_assign(visited, MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
113854 + new_lhs = gimple_assign_lhs(assign);
113855 + check_size_overflow(caller_node, assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
113856 +
113857 + return dup_assign(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
113858 +}
113859 +
113860 +bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
113861 +{
113862 + const_gimple def_stmt;
113863 +
113864 + if (TREE_CODE(rhs) != SSA_NAME)
113865 + return false;
113866 +
113867 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
113868 + return false;
113869 +
113870 + def_stmt = get_def_stmt(rhs);
113871 + if (!is_gimple_assign(def_stmt) || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
113872 + return false;
113873 +
113874 + return true;
113875 +}
113876 +
113877 +/* e.g., drivers/acpi/acpica/utids.c acpi_ut_execute_CID()
113878 + * ((count - 1) * sizeof(struct acpi_pnp_dee_id_list) -> (count + fffffff) * 16
113879 + * fffffff * 16 > signed max -> truncate
113880 + */
113881 +static bool look_for_mult_and_add(const_gimple stmt)
113882 +{
113883 + const_tree res;
113884 + tree rhs1, rhs2, def_rhs1, def_rhs2, const_rhs, def_const_rhs;
113885 + const_gimple def_stmt;
113886 +
113887 + if (!stmt || gimple_code(stmt) == GIMPLE_NOP)
113888 + return false;
113889 + if (!is_gimple_assign(stmt))
113890 + return false;
113891 + if (gimple_assign_rhs_code(stmt) != MULT_EXPR)
113892 + return false;
113893 +
113894 + rhs1 = gimple_assign_rhs1(stmt);
113895 + rhs2 = gimple_assign_rhs2(stmt);
113896 + if (is_gimple_constant(rhs1)) {
113897 + const_rhs = rhs1;
113898 + def_stmt = get_def_stmt(rhs2);
113899 + } else if (is_gimple_constant(rhs2)) {
113900 + const_rhs = rhs2;
113901 + def_stmt = get_def_stmt(rhs1);
113902 + } else
113903 + return false;
113904 +
113905 + if (gimple_assign_rhs_code(def_stmt) != PLUS_EXPR && gimple_assign_rhs_code(def_stmt) != MINUS_EXPR)
113906 + return false;
113907 +
113908 + def_rhs1 = gimple_assign_rhs1(def_stmt);
113909 + def_rhs2 = gimple_assign_rhs2(def_stmt);
113910 + if (is_gimple_constant(def_rhs1))
113911 + def_const_rhs = def_rhs1;
113912 + else if (is_gimple_constant(def_rhs2))
113913 + def_const_rhs = def_rhs2;
113914 + else
113915 + return false;
113916 +
113917 + res = fold_binary_loc(gimple_location(def_stmt), MULT_EXPR, TREE_TYPE(const_rhs), const_rhs, def_const_rhs);
113918 + if (is_lt_signed_type_max(res) && is_gt_zero(res))
113919 + return false;
113920 + return true;
113921 +}
113922 +
113923 +enum intentional_overflow_type add_mul_intentional_overflow(const_gimple stmt)
113924 +{
113925 + const_gimple def_stmt_1, def_stmt_2;
113926 + const_tree rhs1, rhs2;
113927 + bool add_mul_rhs1, add_mul_rhs2;
113928 +
113929 + rhs1 = gimple_assign_rhs1(stmt);
113930 + def_stmt_1 = get_def_stmt(rhs1);
113931 + add_mul_rhs1 = look_for_mult_and_add(def_stmt_1);
113932 +
113933 + rhs2 = gimple_assign_rhs2(stmt);
113934 + def_stmt_2 = get_def_stmt(rhs2);
113935 + add_mul_rhs2 = look_for_mult_and_add(def_stmt_2);
113936 +
113937 + if (add_mul_rhs1)
113938 + return RHS1_INTENTIONAL_OVERFLOW;
113939 + if (add_mul_rhs2)
113940 + return RHS2_INTENTIONAL_OVERFLOW;
113941 + return NO_INTENTIONAL_OVERFLOW;
113942 +}
113943 +
113944 +static gimple get_dup_stmt(struct visited *visited, gimple stmt)
113945 +{
113946 + gimple my_stmt;
113947 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
113948 +
113949 + gsi_next(&gsi);
113950 + my_stmt = gsi_stmt(gsi);
113951 +
113952 + gcc_assert(pointer_set_contains(visited->my_stmts, my_stmt));
113953 + gcc_assert(gimple_assign_rhs_code(stmt) == gimple_assign_rhs_code(my_stmt));
113954 +
113955 + return my_stmt;
113956 +}
113957 +
113958 +/* unsigned type -> unary or binary assign (rhs1 or rhs2 is constant)
113959 + * unsigned type cast to signed type, unsigned type: no more uses
113960 + * e.g., lib/vsprintf.c:simple_strtol()
113961 + * _10 = (unsigned long int) _9
113962 + * _11 = -_10;
113963 + * _12 = (long int) _11; (_11_ no more uses)
113964 + */
113965 +static bool is_call_or_cast(gimple stmt)
113966 +{
113967 + return gimple_assign_cast_p(stmt) || is_gimple_call(stmt);
113968 +}
113969 +
113970 +static bool is_unsigned_cast_or_call_def_stmt(const_tree node)
113971 +{
113972 + const_tree rhs;
113973 + gimple def_stmt;
113974 +
113975 + if (node == NULL_TREE)
113976 + return true;
113977 + if (is_gimple_constant(node))
113978 + return true;
113979 +
113980 + def_stmt = get_def_stmt(node);
113981 + if (!def_stmt)
113982 + return false;
113983 +
113984 + if (is_call_or_cast(def_stmt))
113985 + return true;
113986 +
113987 + if (!is_gimple_assign(def_stmt) || gimple_num_ops(def_stmt) != 2)
113988 + return false;
113989 + rhs = gimple_assign_rhs1(def_stmt);
113990 + def_stmt = get_def_stmt(rhs);
113991 + if (!def_stmt)
113992 + return false;
113993 + return is_call_or_cast(def_stmt);
113994 +}
113995 +
113996 +void unsigned_signed_cast_intentional_overflow(struct visited *visited, gimple stmt)
113997 +{
113998 + unsigned int use_num;
113999 + gimple so_stmt;
114000 + const_gimple def_stmt;
114001 + const_tree rhs1, rhs2;
114002 + tree rhs = gimple_assign_rhs1(stmt);
114003 + tree lhs_type = TREE_TYPE(gimple_assign_lhs(stmt));
114004 + const_tree rhs_type = TREE_TYPE(rhs);
114005 +
114006 + if (!(TYPE_UNSIGNED(rhs_type) && !TYPE_UNSIGNED(lhs_type)))
114007 + return;
114008 + if (GET_MODE_BITSIZE(TYPE_MODE(rhs_type)) != GET_MODE_BITSIZE(TYPE_MODE(lhs_type)))
114009 + return;
114010 + use_num = uses_num(rhs);
114011 + if (use_num != 1)
114012 + return;
114013 +
114014 + def_stmt = get_def_stmt(rhs);
114015 + if (!def_stmt)
114016 + return;
114017 + if (!is_gimple_assign(def_stmt))
114018 + return;
114019 +
114020 + rhs1 = gimple_assign_rhs1(def_stmt);
114021 + if (!is_unsigned_cast_or_call_def_stmt(rhs1))
114022 + return;
114023 +
114024 + rhs2 = gimple_assign_rhs2(def_stmt);
114025 + if (!is_unsigned_cast_or_call_def_stmt(rhs2))
114026 + return;
114027 + if (gimple_num_ops(def_stmt) == 3 && !is_gimple_constant(rhs1) && !is_gimple_constant(rhs2))
114028 + return;
114029 +
114030 + so_stmt = get_dup_stmt(visited, stmt);
114031 + create_up_and_down_cast(visited, so_stmt, lhs_type, gimple_assign_rhs1(so_stmt));
114032 +}
114033 +
114034 diff --git a/tools/gcc/size_overflow_plugin/misc.c b/tools/gcc/size_overflow_plugin/misc.c
114035 new file mode 100644
114036 index 0000000..4bddad2
114037 --- /dev/null
114038 +++ b/tools/gcc/size_overflow_plugin/misc.c
114039 @@ -0,0 +1,203 @@
114040 +/*
114041 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
114042 + * Licensed under the GPL v2, or (at your option) v3
114043 + *
114044 + * Homepage:
114045 + * http://www.grsecurity.net/~ephox/overflow_plugin/
114046 + *
114047 + * Documentation:
114048 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
114049 + *
114050 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
114051 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
114052 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
114053 + *
114054 + * Usage:
114055 + * $ make
114056 + * $ make run
114057 + */
114058 +
114059 +#include "gcc-common.h"
114060 +#include "size_overflow.h"
114061 +
114062 +void set_current_function_decl(tree fndecl)
114063 +{
114064 + gcc_assert(fndecl != NULL_TREE);
114065 +
114066 + push_cfun(DECL_STRUCT_FUNCTION(fndecl));
114067 + calculate_dominance_info(CDI_DOMINATORS);
114068 + current_function_decl = fndecl;
114069 +}
114070 +
114071 +void unset_current_function_decl(void)
114072 +{
114073 + free_dominance_info(CDI_DOMINATORS);
114074 + pop_cfun();
114075 + current_function_decl = NULL_TREE;
114076 +}
114077 +
114078 +static bool is_bool(const_tree node)
114079 +{
114080 + const_tree type;
114081 +
114082 + if (node == NULL_TREE)
114083 + return false;
114084 +
114085 + type = TREE_TYPE(node);
114086 + if (!INTEGRAL_TYPE_P(type))
114087 + return false;
114088 + if (TREE_CODE(type) == BOOLEAN_TYPE)
114089 + return true;
114090 + if (TYPE_PRECISION(type) == 1)
114091 + return true;
114092 + return false;
114093 +}
114094 +
114095 +bool skip_types(const_tree var)
114096 +{
114097 + tree type;
114098 + enum tree_code code;
114099 +
114100 + if (is_gimple_constant(var))
114101 + return true;
114102 +
114103 + switch (TREE_CODE(var)) {
114104 + case ADDR_EXPR:
114105 +#if BUILDING_GCC_VERSION >= 4006
114106 + case MEM_REF:
114107 +#endif
114108 + case ARRAY_REF:
114109 + case BIT_FIELD_REF:
114110 + case INDIRECT_REF:
114111 + case TARGET_MEM_REF:
114112 + case COMPONENT_REF:
114113 + case VAR_DECL:
114114 + case VIEW_CONVERT_EXPR:
114115 + return true;
114116 + default:
114117 + break;
114118 + }
114119 +
114120 + code = TREE_CODE(var);
114121 + gcc_assert(code == SSA_NAME || code == PARM_DECL);
114122 +
114123 + type = TREE_TYPE(var);
114124 + switch (TREE_CODE(type)) {
114125 + case INTEGER_TYPE:
114126 + case ENUMERAL_TYPE:
114127 + return false;
114128 + case BOOLEAN_TYPE:
114129 + return is_bool(var);
114130 + default:
114131 + return true;
114132 + }
114133 +}
114134 +
114135 +gimple get_def_stmt(const_tree node)
114136 +{
114137 + gcc_assert(node != NULL_TREE);
114138 +
114139 + if (skip_types(node))
114140 + return NULL;
114141 +
114142 + if (TREE_CODE(node) != SSA_NAME)
114143 + return NULL;
114144 + return SSA_NAME_DEF_STMT(node);
114145 +}
114146 +
114147 +tree create_new_var(tree type)
114148 +{
114149 + tree new_var = create_tmp_var(type, "cicus");
114150 +
114151 + add_referenced_var(new_var);
114152 + return new_var;
114153 +}
114154 +
114155 +static bool skip_cast(tree dst_type, const_tree rhs, bool force)
114156 +{
114157 + const_gimple def_stmt = get_def_stmt(rhs);
114158 +
114159 + if (force)
114160 + return false;
114161 +
114162 + if (is_gimple_constant(rhs))
114163 + return false;
114164 +
114165 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
114166 + return false;
114167 +
114168 + if (!types_compatible_p(dst_type, TREE_TYPE(rhs)))
114169 + return false;
114170 +
114171 + // DI type can be on 32 bit (from create_assign) but overflow type stays DI
114172 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
114173 + return false;
114174 +
114175 + return true;
114176 +}
114177 +
114178 +tree cast_a_tree(tree type, tree var)
114179 +{
114180 + gcc_assert(type != NULL_TREE);
114181 + gcc_assert(var != NULL_TREE);
114182 + gcc_assert(fold_convertible_p(type, var));
114183 +
114184 + return fold_convert(type, var);
114185 +}
114186 +
114187 +gimple build_cast_stmt(struct visited *visited, tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before, bool force)
114188 +{
114189 + gimple assign, def_stmt;
114190 +
114191 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
114192 + gcc_assert(!is_gimple_constant(rhs));
114193 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
114194 + gcc_unreachable();
114195 +
114196 + def_stmt = get_def_stmt(rhs);
114197 + if (def_stmt && gimple_code(def_stmt) != GIMPLE_NOP && skip_cast(dst_type, rhs, force) && pointer_set_contains(visited->my_stmts, def_stmt))
114198 + return def_stmt;
114199 +
114200 + if (lhs == CREATE_NEW_VAR)
114201 + lhs = create_new_var(dst_type);
114202 +
114203 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
114204 +
114205 + if (!gsi_end_p(*gsi)) {
114206 + location_t loc = gimple_location(gsi_stmt(*gsi));
114207 + gimple_set_location(assign, loc);
114208 + }
114209 +
114210 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
114211 +
114212 + if (before)
114213 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
114214 + else
114215 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
114216 + update_stmt(assign);
114217 + return assign;
114218 +}
114219 +
114220 +bool is_size_overflow_type(const_tree var)
114221 +{
114222 + const char *name;
114223 + const_tree type_name, type;
114224 +
114225 + if (var == NULL_TREE)
114226 + return false;
114227 +
114228 + type = TREE_TYPE(var);
114229 + type_name = TYPE_NAME(type);
114230 + if (type_name == NULL_TREE)
114231 + return false;
114232 +
114233 + if (DECL_P(type_name))
114234 + name = DECL_NAME_POINTER(type_name);
114235 + else
114236 + name = IDENTIFIER_POINTER(type_name);
114237 +
114238 + if (!strncmp(name, "size_overflow_type", 18))
114239 + return true;
114240 + return false;
114241 +}
114242 +
114243 diff --git a/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c b/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c
114244 new file mode 100644
114245 index 0000000..7c9e6d1
114246 --- /dev/null
114247 +++ b/tools/gcc/size_overflow_plugin/remove_unnecessary_dup.c
114248 @@ -0,0 +1,138 @@
114249 +/*
114250 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
114251 + * Licensed under the GPL v2, or (at your option) v3
114252 + *
114253 + * Homepage:
114254 + * http://www.grsecurity.net/~ephox/overflow_plugin/
114255 + *
114256 + * Documentation:
114257 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
114258 + *
114259 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
114260 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
114261 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
114262 + *
114263 + * Usage:
114264 + * $ make
114265 + * $ make run
114266 + */
114267 +
114268 +#include "gcc-common.h"
114269 +#include "size_overflow.h"
114270 +
114271 +bool skip_expr_on_double_type(const_gimple stmt)
114272 +{
114273 + enum tree_code code = gimple_assign_rhs_code(stmt);
114274 +
114275 + switch (code) {
114276 + case RSHIFT_EXPR:
114277 + case TRUNC_DIV_EXPR:
114278 + case CEIL_DIV_EXPR:
114279 + case FLOOR_DIV_EXPR:
114280 + case ROUND_DIV_EXPR:
114281 + case EXACT_DIV_EXPR:
114282 + case RDIV_EXPR:
114283 + case TRUNC_MOD_EXPR:
114284 + case CEIL_MOD_EXPR:
114285 + case FLOOR_MOD_EXPR:
114286 + case ROUND_MOD_EXPR:
114287 + return true;
114288 + default:
114289 + return false;
114290 + }
114291 +}
114292 +
114293 +void create_up_and_down_cast(struct visited *visited, gimple use_stmt, tree orig_type, tree rhs)
114294 +{
114295 + const_tree orig_rhs1;
114296 + tree down_lhs, new_lhs, dup_type = TREE_TYPE(rhs);
114297 + gimple down_cast, up_cast;
114298 + gimple_stmt_iterator gsi = gsi_for_stmt(use_stmt);
114299 +
114300 + down_cast = build_cast_stmt(visited, orig_type, rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
114301 + down_lhs = gimple_assign_lhs(down_cast);
114302 +
114303 + gsi = gsi_for_stmt(use_stmt);
114304 + up_cast = build_cast_stmt(visited, dup_type, down_lhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
114305 + new_lhs = gimple_assign_lhs(up_cast);
114306 +
114307 + orig_rhs1 = gimple_assign_rhs1(use_stmt);
114308 + if (operand_equal_p(orig_rhs1, rhs, 0))
114309 + gimple_assign_set_rhs1(use_stmt, new_lhs);
114310 + else
114311 + gimple_assign_set_rhs2(use_stmt, new_lhs);
114312 + update_stmt(use_stmt);
114313 +
114314 + pointer_set_insert(visited->my_stmts, up_cast);
114315 + pointer_set_insert(visited->my_stmts, down_cast);
114316 + pointer_set_insert(visited->skip_expr_casts, up_cast);
114317 + pointer_set_insert(visited->skip_expr_casts, down_cast);
114318 +}
114319 +
114320 +static tree get_proper_unsigned_half_type(const_tree node)
114321 +{
114322 + tree new_type, type;
114323 +
114324 + gcc_assert(is_size_overflow_type(node));
114325 +
114326 + type = TREE_TYPE(node);
114327 + switch (TYPE_MODE(type)) {
114328 + case HImode:
114329 + new_type = unsigned_intQI_type_node;
114330 + break;
114331 + case SImode:
114332 + new_type = unsigned_intHI_type_node;
114333 + break;
114334 + case DImode:
114335 + new_type = unsigned_intSI_type_node;
114336 + break;
114337 + case TImode:
114338 + new_type = unsigned_intDI_type_node;
114339 + break;
114340 + default:
114341 + gcc_unreachable();
114342 + }
114343 +
114344 + if (TYPE_QUALS(type) != 0)
114345 + return build_qualified_type(new_type, TYPE_QUALS(type));
114346 + return new_type;
114347 +}
114348 +
114349 +static void insert_cast_rhs(struct visited *visited, gimple stmt, tree rhs)
114350 +{
114351 + tree type;
114352 +
114353 + if (rhs == NULL_TREE)
114354 + return;
114355 + if (!is_size_overflow_type(rhs))
114356 + return;
114357 +
114358 + type = get_proper_unsigned_half_type(rhs);
114359 + if (is_gimple_constant(rhs))
114360 + return;
114361 + create_up_and_down_cast(visited, stmt, type, rhs);
114362 +}
114363 +
114364 +static void insert_cast(struct visited *visited, gimple stmt, tree rhs)
114365 +{
114366 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode) && !is_size_overflow_type(rhs))
114367 + return;
114368 + gcc_assert(is_size_overflow_type(rhs));
114369 + insert_cast_rhs(visited, stmt, rhs);
114370 +}
114371 +
114372 +void insert_cast_expr(struct visited *visited, gimple stmt, enum intentional_overflow_type type)
114373 +{
114374 + tree rhs1, rhs2;
114375 +
114376 + if (type == NO_INTENTIONAL_OVERFLOW || type == RHS1_INTENTIONAL_OVERFLOW) {
114377 + rhs1 = gimple_assign_rhs1(stmt);
114378 + insert_cast(visited, stmt, rhs1);
114379 + }
114380 +
114381 + if (type == NO_INTENTIONAL_OVERFLOW || type == RHS2_INTENTIONAL_OVERFLOW) {
114382 + rhs2 = gimple_assign_rhs2(stmt);
114383 + insert_cast(visited, stmt, rhs2);
114384 + }
114385 +}
114386 +
114387 diff --git a/tools/gcc/size_overflow_plugin/size_overflow.h b/tools/gcc/size_overflow_plugin/size_overflow.h
114388 new file mode 100644
114389 index 0000000..e5b4e50
114390 --- /dev/null
114391 +++ b/tools/gcc/size_overflow_plugin/size_overflow.h
114392 @@ -0,0 +1,127 @@
114393 +#ifndef SIZE_OVERFLOW_H
114394 +#define SIZE_OVERFLOW_H
114395 +
114396 +#define CREATE_NEW_VAR NULL_TREE
114397 +#define CANNOT_FIND_ARG 32
114398 +#define MAX_PARAM 31
114399 +#define BEFORE_STMT true
114400 +#define AFTER_STMT false
114401 +
114402 +#define TURN_OFF_ASM_STR "# size_overflow MARK_TURN_OFF "
114403 +#define YES_ASM_STR "# size_overflow MARK_YES "
114404 +#define OK_ASM_STR "# size_overflow "
114405 +
114406 +enum mark {
114407 + MARK_NO, MARK_YES, MARK_NOT_INTENTIONAL, MARK_TURN_OFF
114408 +};
114409 +
114410 +enum intentional_overflow_type {
114411 + NO_INTENTIONAL_OVERFLOW, RHS1_INTENTIONAL_OVERFLOW, RHS2_INTENTIONAL_OVERFLOW
114412 +};
114413 +
114414 +struct visited {
114415 + struct pointer_set_t *stmts;
114416 + struct pointer_set_t *my_stmts;
114417 + struct pointer_set_t *skip_expr_casts;
114418 + struct pointer_set_t *no_cast_check;
114419 +};
114420 +
114421 +// size_overflow_plugin.c
114422 +extern tree report_size_overflow_decl;
114423 +extern tree size_overflow_type_HI;
114424 +extern tree size_overflow_type_SI;
114425 +extern tree size_overflow_type_DI;
114426 +extern tree size_overflow_type_TI;
114427 +
114428 +
114429 +// size_overflow_plugin_hash.c
114430 +struct size_overflow_hash {
114431 + const struct size_overflow_hash * const next;
114432 + const char * const name;
114433 + const unsigned int param;
114434 +};
114435 +
114436 +struct interesting_node {
114437 + struct interesting_node *next;
114438 + gimple first_stmt;
114439 + const_tree fndecl;
114440 + tree node;
114441 +#if BUILDING_GCC_VERSION <= 4007
114442 + VEC(tree, gc) *last_nodes;
114443 +#else
114444 + vec<tree, va_gc> *last_nodes;
114445 +#endif
114446 + unsigned int num;
114447 + enum mark intentional_attr_decl;
114448 + enum mark intentional_attr_cur_fndecl;
114449 + gimple intentional_mark_from_gimple;
114450 +};
114451 +
114452 +extern bool is_size_overflow_asm(const_gimple stmt);
114453 +extern unsigned int get_function_num(const_tree node, const_tree orig_fndecl);
114454 +extern unsigned int get_correct_arg_count(unsigned int argnum, const_tree fndecl);
114455 +extern bool is_missing_function(const_tree orig_fndecl, unsigned int num);
114456 +extern bool is_a_return_check(const_tree node);
114457 +extern const struct size_overflow_hash *get_function_hash(const_tree fndecl);
114458 +extern unsigned int find_arg_number_tree(const_tree arg, const_tree func);
114459 +
114460 +
114461 +// size_overflow_debug.c
114462 +extern struct opt_pass *make_dump_pass(void);
114463 +
114464 +
114465 +// intentional_overflow.c
114466 +extern enum mark get_intentional_attr_type(const_tree node);
114467 +extern bool is_size_overflow_intentional_asm_yes(const_gimple stmt);
114468 +extern bool is_size_overflow_intentional_asm_turn_off(const_gimple stmt);
114469 +extern bool is_end_intentional_intentional_attr(const_tree decl, unsigned int argnum);
114470 +extern bool is_yes_intentional_attr(const_tree decl, unsigned int argnum);
114471 +extern bool is_turn_off_intentional_attr(const_tree decl);
114472 +extern void print_missing_intentional(enum mark callee_attr, enum mark caller_attr, const_tree decl, unsigned int argnum);
114473 +extern void check_intentional_attribute_ipa(struct interesting_node *cur_node);
114474 +extern bool is_a_cast_and_const_overflow(const_tree no_const_rhs);
114475 +extern bool is_const_plus_unsigned_signed_truncation(const_tree lhs);
114476 +extern bool is_a_constant_overflow(const_gimple stmt, const_tree rhs);
114477 +extern tree handle_intentional_overflow(struct visited *visited, struct cgraph_node *caller_node, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs2);
114478 +extern tree handle_integer_truncation(struct visited *visited, struct cgraph_node *caller_node, const_tree lhs);
114479 +extern bool is_a_neg_overflow(const_gimple stmt, const_tree rhs);
114480 +extern enum intentional_overflow_type add_mul_intentional_overflow(const_gimple def_stmt);
114481 +extern void unsigned_signed_cast_intentional_overflow(struct visited *visited, gimple stmt);
114482 +
114483 +
114484 +// insert_size_overflow_check_ipa.c
114485 +extern unsigned int search_function(void);
114486 +extern unsigned int call_count;
114487 +extern struct opt_pass *make_insert_size_overflow_check(void);
114488 +extern const_tree get_interesting_orig_fndecl(const_gimple stmt, unsigned int argnum);
114489 +
114490 +
114491 +// insert_size_overflow_asm.c
114492 +extern struct opt_pass *make_insert_size_overflow_asm_pass(void);
114493 +
114494 +
114495 +// misc.c
114496 +extern void set_current_function_decl(tree fndecl);
114497 +extern void unset_current_function_decl(void);
114498 +extern gimple get_def_stmt(const_tree node);
114499 +extern tree create_new_var(tree type);
114500 +extern gimple build_cast_stmt(struct visited *visited, tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before, bool force);
114501 +extern bool skip_types(const_tree var);
114502 +extern tree cast_a_tree(tree type, tree var);
114503 +extern bool is_size_overflow_type(const_tree var);
114504 +
114505 +
114506 +// insert_size_overflow_check_core.c
114507 +extern tree expand(struct visited *visited, struct cgraph_node *caller_node, tree lhs);
114508 +extern void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
114509 +extern tree dup_assign(struct visited *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3);
114510 +extern tree create_assign(struct visited *visited, gimple oldstmt, tree rhs1, bool before);
114511 +
114512 +
114513 +// remove_unnecessary_dup.c
114514 +extern struct opt_pass *make_remove_unnecessary_dup_pass(void);
114515 +extern void insert_cast_expr(struct visited *visited, gimple stmt, enum intentional_overflow_type type);
114516 +extern bool skip_expr_on_double_type(const_gimple stmt);
114517 +extern void create_up_and_down_cast(struct visited *visited, gimple use_stmt, tree orig_type, tree rhs);
114518 +
114519 +#endif
114520 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_debug.c b/tools/gcc/size_overflow_plugin/size_overflow_debug.c
114521 new file mode 100644
114522 index 0000000..4378111
114523 --- /dev/null
114524 +++ b/tools/gcc/size_overflow_plugin/size_overflow_debug.c
114525 @@ -0,0 +1,116 @@
114526 +/*
114527 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
114528 + * Licensed under the GPL v2, or (at your option) v3
114529 + *
114530 + * Homepage:
114531 + * http://www.grsecurity.net/~ephox/overflow_plugin/
114532 + *
114533 + * Documentation:
114534 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
114535 + *
114536 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
114537 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
114538 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
114539 + *
114540 + * Usage:
114541 + * $ make
114542 + * $ make run
114543 + */
114544 +
114545 +#include "gcc-common.h"
114546 +
114547 +static unsigned int dump_functions(void)
114548 +{
114549 + struct cgraph_node *node;
114550 +
114551 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
114552 + basic_block bb;
114553 +
114554 + push_cfun(DECL_STRUCT_FUNCTION(NODE_DECL(node)));
114555 + current_function_decl = NODE_DECL(node);
114556 +
114557 + fprintf(stderr, "-----------------------------------------\n%s\n-----------------------------------------\n", DECL_NAME_POINTER(current_function_decl));
114558 +
114559 + FOR_ALL_BB_FN(bb, cfun) {
114560 + gimple_stmt_iterator si;
114561 +
114562 + fprintf(stderr, "<bb %u>:\n", bb->index);
114563 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
114564 + debug_gimple_stmt(gsi_stmt(si));
114565 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
114566 + debug_gimple_stmt(gsi_stmt(si));
114567 + fprintf(stderr, "\n");
114568 + }
114569 +
114570 + fprintf(stderr, "-------------------------------------------------------------------------\n");
114571 +
114572 + pop_cfun();
114573 + current_function_decl = NULL_TREE;
114574 + }
114575 +
114576 + fprintf(stderr, "###############################################################################\n");
114577 +
114578 + return 0;
114579 +}
114580 +
114581 +#if BUILDING_GCC_VERSION >= 4009
114582 +static const struct pass_data dump_pass_data = {
114583 +#else
114584 +static struct ipa_opt_pass_d dump_pass = {
114585 + .pass = {
114586 +#endif
114587 + .type = SIMPLE_IPA_PASS,
114588 + .name = "dump",
114589 +#if BUILDING_GCC_VERSION >= 4008
114590 + .optinfo_flags = OPTGROUP_NONE,
114591 +#endif
114592 +#if BUILDING_GCC_VERSION >= 4009
114593 + .has_gate = false,
114594 + .has_execute = true,
114595 +#else
114596 + .gate = NULL,
114597 + .execute = dump_functions,
114598 + .sub = NULL,
114599 + .next = NULL,
114600 + .static_pass_number = 0,
114601 +#endif
114602 + .tv_id = TV_NONE,
114603 + .properties_required = 0,
114604 + .properties_provided = 0,
114605 + .properties_destroyed = 0,
114606 + .todo_flags_start = 0,
114607 + .todo_flags_finish = 0,
114608 +#if BUILDING_GCC_VERSION < 4009
114609 + },
114610 + .generate_summary = NULL,
114611 + .write_summary = NULL,
114612 + .read_summary = NULL,
114613 +#if BUILDING_GCC_VERSION >= 4006
114614 + .write_optimization_summary = NULL,
114615 + .read_optimization_summary = NULL,
114616 +#endif
114617 + .stmt_fixup = NULL,
114618 + .function_transform_todo_flags_start = 0,
114619 + .function_transform = NULL,
114620 + .variable_transform = NULL,
114621 +#endif
114622 +};
114623 +
114624 +#if BUILDING_GCC_VERSION >= 4009
114625 +namespace {
114626 +class dump_pass : public ipa_opt_pass_d {
114627 +public:
114628 + dump_pass() : ipa_opt_pass_d(dump_pass_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
114629 + unsigned int execute() { return dump_functions(); }
114630 +};
114631 +}
114632 +#endif
114633 +
114634 +struct opt_pass *make_dump_pass(void)
114635 +{
114636 +#if BUILDING_GCC_VERSION >= 4009
114637 + return new dump_pass();
114638 +#else
114639 + return &dump_pass.pass;
114640 +#endif
114641 +}
114642 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_hash.data b/tools/gcc/size_overflow_plugin/size_overflow_hash.data
114643 new file mode 100644
114644 index 0000000..386f2d1
114645 --- /dev/null
114646 +++ b/tools/gcc/size_overflow_plugin/size_overflow_hash.data
114647 @@ -0,0 +1,5801 @@
114648 +intel_fake_agp_alloc_by_type_1 intel_fake_agp_alloc_by_type 1 1 NULL
114649 +storvsc_connect_to_vsp_22 storvsc_connect_to_vsp 2 22 NULL
114650 +compat_sock_setsockopt_23 compat_sock_setsockopt 5 23 NULL
114651 +carl9170_alloc_27 carl9170_alloc 1 27 NULL
114652 +sel_read_policyvers_55 sel_read_policyvers 3 55 NULL nohasharray
114653 +padzero_55 padzero 1 55 &sel_read_policyvers_55
114654 +cfg80211_disconnected_57 cfg80211_disconnected 4 57 NULL
114655 +__skb_to_sgvec_72 __skb_to_sgvec 0 72 NULL
114656 +snd_korg1212_copy_to_92 snd_korg1212_copy_to 6 92 NULL
114657 +load_msg_95 load_msg 2 95 NULL
114658 +ipath_verbs_send_117 ipath_verbs_send 5-3 117 NULL
114659 +init_q_132 init_q 4 132 NULL
114660 +memstick_alloc_host_142 memstick_alloc_host 1 142 NULL
114661 +hva_to_gfn_memslot_149 hva_to_gfn_memslot 0-1 149 NULL
114662 +ping_v6_sendmsg_152 ping_v6_sendmsg 4 152 NULL
114663 +tracing_trace_options_write_153 tracing_trace_options_write 3 153 NULL nohasharray
114664 +ext4_ext_get_actual_len_153 ext4_ext_get_actual_len 0 153 &tracing_trace_options_write_153
114665 +pci_request_selected_regions_169 pci_request_selected_regions 0 169 NULL
114666 +xfs_buf_item_get_format_189 xfs_buf_item_get_format 2 189 NULL
114667 +iscsi_session_setup_196 iscsi_session_setup 4-5 196 NULL
114668 +ll_xattr_cache_seq_write_250 ll_xattr_cache_seq_write 3 250 NULL
114669 +br_port_info_size_268 br_port_info_size 0 268 NULL
114670 +read_file_war_stats_292 read_file_war_stats 3 292 NULL
114671 +SYSC_connect_304 SYSC_connect 3 304 NULL
114672 +syslog_print_307 syslog_print 2 307 NULL
114673 +dn_setsockopt_314 dn_setsockopt 5 314 NULL
114674 +mlx5_core_access_reg_361 mlx5_core_access_reg 3-5 361 NULL
114675 +aio_read_events_ring_410 aio_read_events_ring 3 410 NULL
114676 +lbs_rdmac_read_418 lbs_rdmac_read 3 418 NULL
114677 +snd_ca0106_ptr_read_467 snd_ca0106_ptr_read 0 467 NULL
114678 +cfs_trace_set_debug_mb_usrstr_486 cfs_trace_set_debug_mb_usrstr 2 486 NULL
114679 +nvme_trans_modesel_data_488 nvme_trans_modesel_data 4 488 NULL
114680 +iwl_dbgfs_protection_mode_write_502 iwl_dbgfs_protection_mode_write 3 502 NULL
114681 +rx_rx_defrag_end_read_505 rx_rx_defrag_end_read 3 505 NULL
114682 +ocfs2_validate_meta_ecc_bhs_527 ocfs2_validate_meta_ecc_bhs 0 527 NULL
114683 +zlib_deflate_workspacesize_537 zlib_deflate_workspacesize 0-1-2 537 NULL
114684 +iwl_dbgfs_wowlan_sram_read_540 iwl_dbgfs_wowlan_sram_read 3 540 NULL
114685 +sco_sock_setsockopt_552 sco_sock_setsockopt 5 552 NULL
114686 +lpfc_nlp_state_name_556 lpfc_nlp_state_name 2 556 NULL
114687 +snd_aw2_saa7146_get_hw_ptr_playback_558 snd_aw2_saa7146_get_hw_ptr_playback 0 558 NULL
114688 +start_isoc_chain_565 start_isoc_chain 2 565 NULL nohasharray
114689 +dev_hard_header_565 dev_hard_header 0 565 &start_isoc_chain_565
114690 +smk_write_load_self2_591 smk_write_load_self2 3 591 NULL
114691 +btrfs_stack_file_extent_offset_607 btrfs_stack_file_extent_offset 0 607 NULL
114692 +ni_gpct_device_construct_610 ni_gpct_device_construct 5 610 NULL
114693 +fuse_request_alloc_nofs_617 fuse_request_alloc_nofs 1 617 NULL
114694 +ptlrpc_lprocfs_nrs_seq_write_621 ptlrpc_lprocfs_nrs_seq_write 3 621 NULL
114695 +viafb_dfpl_proc_write_627 viafb_dfpl_proc_write 3 627 NULL
114696 +ceph_osdc_new_request_635 ceph_osdc_new_request 6 635 NULL
114697 +cfs_hash_bkt_size_643 cfs_hash_bkt_size 0 643 NULL
114698 +unlink_queued_645 unlink_queued 4 645 NULL
114699 +dtim_interval_read_654 dtim_interval_read 3 654 NULL
114700 +mem_rx_free_mem_blks_read_675 mem_rx_free_mem_blks_read 3 675 NULL
114701 +persistent_ram_vmap_709 persistent_ram_vmap 2-1 709 NULL
114702 +sctp_setsockopt_peer_addr_params_734 sctp_setsockopt_peer_addr_params 3 734 NULL
114703 +dvb_video_write_754 dvb_video_write 3 754 NULL
114704 +cfs_trace_allocate_string_buffer_781 cfs_trace_allocate_string_buffer 2 781 NULL
114705 +ath6kl_disconnect_timeout_write_794 ath6kl_disconnect_timeout_write 3 794 NULL
114706 +snd_pcm_drain_811 snd_pcm_drain 0 811 NULL
114707 +if_writecmd_815 if_writecmd 2 815 NULL
114708 +aac_change_queue_depth_825 aac_change_queue_depth 2 825 NULL
114709 +error_state_read_859 error_state_read 6 859 NULL
114710 +o2net_send_message_vec_879 o2net_send_message_vec 4 879 NULL nohasharray
114711 +iwl_dbgfs_fh_reg_read_879 iwl_dbgfs_fh_reg_read 3 879 &o2net_send_message_vec_879
114712 +snd_pcm_action_single_905 snd_pcm_action_single 0 905 NULL
114713 +carl9170_cmd_buf_950 carl9170_cmd_buf 3 950 NULL
114714 +__nodes_weight_956 __nodes_weight 0 956 NULL
114715 +bnx2x_fill_fw_str_968 bnx2x_fill_fw_str 3 968 NULL
114716 +mnt_want_write_975 mnt_want_write 0 975 NULL
114717 +usnic_ib_qp_grp_dump_hdr_989 usnic_ib_qp_grp_dump_hdr 2 989 NULL
114718 +memcmp_990 memcmp 0 990 NULL
114719 +smk_write_cipso2_1021 smk_write_cipso2 3 1021 NULL
114720 +gigaset_initdriver_1060 gigaset_initdriver 2 1060 NULL
114721 +mce_request_packet_1073 mce_request_packet 3 1073 NULL
114722 +agp_create_memory_1075 agp_create_memory 1 1075 NULL
114723 +_scsih_adjust_queue_depth_1083 _scsih_adjust_queue_depth 2 1083 NULL
114724 +llcp_sock_sendmsg_1092 llcp_sock_sendmsg 4 1092 NULL
114725 +nfs4_init_nonuniform_client_string_1097 nfs4_init_nonuniform_client_string 3 1097 NULL
114726 +cfg80211_report_obss_beacon_1133 cfg80211_report_obss_beacon 3 1133 NULL
114727 +i2400m_rx_ctl_1157 i2400m_rx_ctl 4 1157 NULL
114728 +ipc_alloc_1192 ipc_alloc 1 1192 NULL
114729 +ib_create_send_mad_1196 ib_create_send_mad 5 1196 NULL
114730 +pstore_ftrace_knob_write_1198 pstore_ftrace_knob_write 3 1198 NULL
114731 +i2400m_rx_ctl_ack_1199 i2400m_rx_ctl_ack 3 1199 NULL
114732 +dgrp_dpa_read_1204 dgrp_dpa_read 3 1204 NULL
114733 +i2cdev_read_1206 i2cdev_read 3 1206 NULL
114734 +lov_ost_pool_init_1215 lov_ost_pool_init 2 1215 NULL
114735 +fsync_buffers_list_1219 fsync_buffers_list 0 1219 NULL
114736 +kernfs_file_direct_read_1238 kernfs_file_direct_read 3 1238 NULL
114737 +acpi_battery_write_alarm_1240 acpi_battery_write_alarm 3 1240 NULL
114738 +drm_primary_helper_create_plane_1262 drm_primary_helper_create_plane 3 1262 NULL
114739 +ocfs2_extend_file_1266 ocfs2_extend_file 3 1266 NULL
114740 +qla4xxx_change_queue_depth_1268 qla4xxx_change_queue_depth 2 1268 NULL
114741 +ioctl_private_iw_point_1273 ioctl_private_iw_point 7 1273 NULL
114742 +SyS_flistxattr_1287 SyS_flistxattr 3 1287 NULL
114743 +tx_frag_in_process_called_read_1290 tx_frag_in_process_called_read 3 1290 NULL
114744 +posix_acl_xattr_set_1301 posix_acl_xattr_set 4 1301 NULL
114745 +ffs_1322 ffs 0 1322 NULL
114746 +qlcnic_pci_sriov_configure_1327 qlcnic_pci_sriov_configure 2 1327 NULL
114747 +btrfs_submit_compressed_write_1347 btrfs_submit_compressed_write 5 1347 NULL
114748 +snd_pcm_lib_write1_1358 snd_pcm_lib_write1 0-3 1358 NULL
114749 +ipx_sendmsg_1362 ipx_sendmsg 4 1362 NULL
114750 +fw_stats_raw_read_1369 fw_stats_raw_read 3 1369 NULL
114751 +ocfs2_prepare_inode_for_write_1372 ocfs2_prepare_inode_for_write 3 1372 NULL
114752 +sctp_setsockopt_initmsg_1383 sctp_setsockopt_initmsg 3 1383 NULL
114753 +do_msgsnd_1387 do_msgsnd 4 1387 NULL
114754 +SYSC_io_getevents_1392 SYSC_io_getevents 3 1392 NULL
114755 +cfs_trace_copyout_string_1416 cfs_trace_copyout_string 2 1416 NULL
114756 +init_rs_internal_1436 init_rs_internal 1 1436 NULL
114757 +stack_max_size_read_1445 stack_max_size_read 3 1445 NULL
114758 +tx_queue_len_read_1463 tx_queue_len_read 3 1463 NULL
114759 +xprt_alloc_1475 xprt_alloc 2 1475 NULL
114760 +SYSC_syslog_1477 SYSC_syslog 3 1477 NULL
114761 +sta_num_ps_buf_frames_read_1488 sta_num_ps_buf_frames_read 3 1488 NULL
114762 +fpregs_set_1497 fpregs_set 4 1497 NULL
114763 +tomoyo_round2_1518 tomoyo_round2 0 1518 NULL
114764 +alloc_perm_bits_1532 alloc_perm_bits 2 1532 NULL
114765 +ath6kl_init_get_fwcaps_1557 ath6kl_init_get_fwcaps 3 1557 NULL
114766 +ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime_1589 ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 NULL
114767 +ipath_ht_handle_hwerrors_1592 ipath_ht_handle_hwerrors 3 1592 NULL
114768 +packet_buffer_init_1607 packet_buffer_init 2 1607 NULL
114769 +btmrvl_hscmd_read_1614 btmrvl_hscmd_read 3 1614 NULL
114770 +v9fs_fid_xattr_get_1618 v9fs_fid_xattr_get 0 1618 NULL
114771 +ikconfig_read_current_1658 ikconfig_read_current 3 1658 NULL
114772 +mei_cl_recv_1665 mei_cl_recv 3 1665 NULL
114773 +rmap_add_1677 rmap_add 3 1677 NULL
114774 +configfs_read_file_1683 configfs_read_file 3 1683 NULL
114775 +iwl_dbgfs_d0i3_refs_read_1705 iwl_dbgfs_d0i3_refs_read 3 1705 NULL
114776 +pdu_write_u_1710 pdu_write_u 3 1710 NULL
114777 +coda_psdev_write_1711 coda_psdev_write 3 1711 NULL
114778 +btrfs_dir_data_len_1714 btrfs_dir_data_len 0 1714 NULL
114779 +internal_create_group_1733 internal_create_group 0 1733 NULL
114780 +dev_irnet_read_1741 dev_irnet_read 3 1741 NULL
114781 +usb_ep_align_maybe_1743 usb_ep_align_maybe 0-3 1743 NULL
114782 +tx_frag_called_read_1748 tx_frag_called_read 3 1748 NULL
114783 +cosa_write_1774 cosa_write 3 1774 NULL
114784 +fcoe_ctlr_device_add_1793 fcoe_ctlr_device_add 3 1793 NULL
114785 +__nodelist_scnprintf_1815 __nodelist_scnprintf 2-0 1815 NULL
114786 +sb_issue_zeroout_1884 sb_issue_zeroout 3 1884 NULL
114787 +rx_defrag_called_read_1897 rx_defrag_called_read 3 1897 NULL
114788 +nfs_parse_server_name_1899 nfs_parse_server_name 2 1899 NULL
114789 +SyS_add_key_1900 SyS_add_key 4 1900 NULL
114790 +uhid_char_read_1920 uhid_char_read 3 1920 NULL
114791 +tx_tx_retry_data_read_1926 tx_tx_retry_data_read 3 1926 NULL
114792 +bdev_erase_1933 bdev_erase 3 1933 NULL
114793 +ext3_fiemap_1936 ext3_fiemap 4 1936 NULL
114794 +cyttsp_probe_1940 cyttsp_probe 4 1940 NULL
114795 +ieee80211_if_fmt_dot11MeshConfirmTimeout_1945 ieee80211_if_fmt_dot11MeshConfirmTimeout 3 1945 NULL
114796 +__assign_irq_vector_1961 __assign_irq_vector 0 1961 NULL
114797 +ivtv_v4l2_read_1964 ivtv_v4l2_read 3 1964 NULL
114798 +sel_read_avc_hash_stats_1984 sel_read_avc_hash_stats 3 1984 NULL
114799 +gpio_power_write_1991 gpio_power_write 3 1991 NULL
114800 +__alloc_bootmem_node_1992 __alloc_bootmem_node 2 1992 NULL
114801 +rx_rx_defrag_read_2010 rx_rx_defrag_read 3 2010 NULL
114802 +ocfs2_global_qinit_alloc_2018 ocfs2_global_qinit_alloc 0 2018 NULL
114803 +write_flush_pipefs_2021 write_flush_pipefs 3 2021 NULL
114804 +BcmCopySection_2035 BcmCopySection 5 2035 NULL
114805 +ath6kl_fwlog_mask_read_2050 ath6kl_fwlog_mask_read 3 2050 NULL
114806 +ocfs2_expand_inline_dir_2063 ocfs2_expand_inline_dir 3 2063 NULL
114807 +__generic_copy_from_user_intel_2073 __generic_copy_from_user_intel 0-3 2073 NULL
114808 +diva_set_driver_dbg_mask_2077 diva_set_driver_dbg_mask 0 2077 NULL
114809 +iwl_dbgfs_current_sleep_command_read_2081 iwl_dbgfs_current_sleep_command_read 3 2081 NULL
114810 +idetape_chrdev_read_2097 idetape_chrdev_read 3 2097 NULL
114811 +__set_print_fmt_2106 __set_print_fmt 0 2106 NULL
114812 +iwl_dbgfs_log_event_read_2107 iwl_dbgfs_log_event_read 3 2107 NULL
114813 +ecryptfs_encrypt_and_encode_filename_2109 ecryptfs_encrypt_and_encode_filename 6 2109 NULL
114814 +btrfs_file_extent_inline_len_2116 btrfs_file_extent_inline_len 0 2116 NULL
114815 +enable_read_2117 enable_read 3 2117 NULL
114816 +pcf50633_write_block_2124 pcf50633_write_block 2-3 2124 NULL
114817 +check_load_and_stores_2143 check_load_and_stores 2 2143 NULL
114818 +iov_iter_count_2152 iov_iter_count 0 2152 NULL
114819 +__copy_to_user_ll_2157 __copy_to_user_ll 0-3 2157 NULL
114820 +_ore_get_io_state_2166 _ore_get_io_state 3-4-5 2166 NULL
114821 +bio_integrity_alloc_2194 bio_integrity_alloc 3 2194 NULL
114822 +picolcd_debug_reset_write_2195 picolcd_debug_reset_write 3 2195 NULL
114823 +u32_array_read_2219 u32_array_read 3 2219 NULL nohasharray
114824 +mei_dbgfs_read_meclients_2219 mei_dbgfs_read_meclients 3 2219 &u32_array_read_2219
114825 +ieee80211_if_read_dot11MeshHWMPRannInterval_2249 ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 NULL
114826 +netlbl_secattr_catmap_walk_2255 netlbl_secattr_catmap_walk 0-2 2255 NULL
114827 +sel_write_avc_cache_threshold_2256 sel_write_avc_cache_threshold 3 2256 NULL
114828 +do_update_counters_2259 do_update_counters 4 2259 NULL
114829 +ath6kl_wmi_bssinfo_event_rx_2275 ath6kl_wmi_bssinfo_event_rx 3 2275 NULL
114830 +debug_debug5_read_2291 debug_debug5_read 3 2291 NULL
114831 +sr_read_cmd_2299 sr_read_cmd 5 2299 NULL
114832 +kvm_clear_guest_page_2308 kvm_clear_guest_page 4 2308 NULL
114833 +intel_sdvo_set_value_2311 intel_sdvo_set_value 4 2311 NULL
114834 +picolcd_fb_write_2318 picolcd_fb_write 3 2318 NULL nohasharray
114835 +hfsplus_find_init_2318 hfsplus_find_init 0 2318 &picolcd_fb_write_2318
114836 +dice_hwdep_read_2326 dice_hwdep_read 3 2326 NULL
114837 +__erst_read_to_erange_2341 __erst_read_to_erange 0 2341 NULL
114838 +zr364xx_read_2354 zr364xx_read 3 2354 NULL
114839 +viafb_iga2_odev_proc_write_2363 viafb_iga2_odev_proc_write 3 2363 NULL
114840 +xfs_buf_map_from_irec_2368 xfs_buf_map_from_irec 5 2368 NULL nohasharray
114841 +rose_recvmsg_2368 rose_recvmsg 4 2368 &xfs_buf_map_from_irec_2368
114842 +il_dbgfs_sensitivity_read_2370 il_dbgfs_sensitivity_read 3 2370 NULL
114843 +rxpipe_rx_prep_beacon_drop_read_2403 rxpipe_rx_prep_beacon_drop_read 3 2403 NULL
114844 +isdn_v110_open_2418 isdn_v110_open 3 2418 NULL
114845 +raid1_size_2419 raid1_size 0-2 2419 NULL
114846 +arch_msi_check_device_2449 arch_msi_check_device 0 2449 NULL
114847 +b43legacy_debugfs_read_2473 b43legacy_debugfs_read 3 2473 NULL
114848 +wiphy_new_2482 wiphy_new 2 2482 NULL
114849 +bio_alloc_bioset_2484 bio_alloc_bioset 2 2484 NULL
114850 +squashfs_read_fragment_index_table_2506 squashfs_read_fragment_index_table 4 2506 NULL
114851 +v9fs_cached_file_read_2514 v9fs_cached_file_read 3 2514 NULL
114852 +ext4_get_inode_loc_2516 ext4_get_inode_loc 0 2516 NULL
114853 +batadv_tvlv_container_list_size_2524 batadv_tvlv_container_list_size 0 2524 NULL
114854 +smk_write_syslog_2529 smk_write_syslog 3 2529 NULL
114855 +__ceph_setxattr_2532 __ceph_setxattr 4 2532 NULL
114856 +gspca_dev_probe_2570 gspca_dev_probe 4 2570 NULL
114857 +pcm_sanity_check_2574 pcm_sanity_check 0 2574 NULL
114858 +mdc_max_rpcs_in_flight_seq_write_2594 mdc_max_rpcs_in_flight_seq_write 3 2594 NULL
114859 +slot_bytes_2609 slot_bytes 0 2609 NULL
114860 +smk_write_logging_2618 smk_write_logging 3 2618 NULL
114861 +switch_status_2629 switch_status 5 2629 NULL
114862 +tcp_xmit_size_goal_2661 tcp_xmit_size_goal 2 2661 NULL
114863 +osc_build_ppga_2670 osc_build_ppga 2 2670 NULL
114864 +ffs_ep0_read_2672 ffs_ep0_read 3 2672 NULL
114865 +oti6858_write_2692 oti6858_write 4 2692 NULL
114866 +nfc_llcp_send_ui_frame_2702 nfc_llcp_send_ui_frame 5 2702 NULL
114867 +memcpy_fromiovecend_2707 memcpy_fromiovecend 3-4 2707 NULL
114868 +lprocfs_stats_counter_size_2708 lprocfs_stats_counter_size 0 2708 NULL
114869 +xfs_readdir_2767 xfs_readdir 3 2767 NULL
114870 +fsl_edma_alloc_desc_2769 fsl_edma_alloc_desc 2 2769 NULL
114871 +mon_bin_ioctl_2771 mon_bin_ioctl 3 2771 NULL
114872 +set_msr_hyperv_pw_2785 set_msr_hyperv_pw 3 2785 NULL
114873 +device_add_attrs_2789 device_add_attrs 0 2789 NULL
114874 +iwl_dbgfs_clear_ucode_statistics_write_2804 iwl_dbgfs_clear_ucode_statistics_write 3 2804 NULL
114875 +sel_read_enforce_2828 sel_read_enforce 3 2828 NULL
114876 +vb2_dc_get_userptr_2829 vb2_dc_get_userptr 2-3 2829 NULL nohasharray
114877 +snd_pcm_reset_2829 snd_pcm_reset 0 2829 &vb2_dc_get_userptr_2829
114878 +wait_for_avail_2847 wait_for_avail 0 2847 NULL
114879 +sfq_alloc_2861 sfq_alloc 1 2861 NULL
114880 +irnet_ctrl_read_2863 irnet_ctrl_read 4 2863 NULL
114881 +move_addr_to_user_2868 move_addr_to_user 2 2868 NULL
114882 +nla_padlen_2883 nla_padlen 1 2883 NULL
114883 +cmm_write_2896 cmm_write 3 2896 NULL
114884 +osc_import_seq_write_2923 osc_import_seq_write 3 2923 NULL
114885 +xfs_trans_get_buf_map_2927 xfs_trans_get_buf_map 4 2927 NULL
114886 +nes_read_indexed_2946 nes_read_indexed 0 2946 NULL
114887 +tm6000_i2c_recv_regs16_2949 tm6000_i2c_recv_regs16 5 2949 NULL
114888 +i40e_dbg_prep_dump_buf_2951 i40e_dbg_prep_dump_buf 2 2951 NULL
114889 +set_fast_connectable_2952 set_fast_connectable 4 2952 NULL
114890 +free_area_init_core_2962 free_area_init_core 2-3 2962 NULL
114891 +bio_setup_sector_2970 bio_setup_sector 3 2970 NULL
114892 +do_strnlen_user_2976 do_strnlen_user 0-2 2976 NULL
114893 +p9_nr_pages_2992 p9_nr_pages 0-2 2992 NULL
114894 +lov_stripetype_seq_write_3013 lov_stripetype_seq_write 3 3013 NULL
114895 +do_dmabuf_dirty_sou_3017 do_dmabuf_dirty_sou 7 3017 NULL
114896 +depth_write_3021 depth_write 3 3021 NULL
114897 +snd_azf3328_codec_inl_3022 snd_azf3328_codec_inl 0 3022 NULL
114898 +nvme_split_and_submit_3027 nvme_split_and_submit 3 3027 NULL
114899 +kvm_unmap_hva_3028 kvm_unmap_hva 2 3028 NULL
114900 +xfrm_dst_alloc_copy_3034 xfrm_dst_alloc_copy 3 3034 NULL
114901 +lpfc_idiag_mbxacc_write_3038 lpfc_idiag_mbxacc_write 3 3038 NULL nohasharray
114902 +iwl_dbgfs_sleep_level_override_read_3038 iwl_dbgfs_sleep_level_override_read 3 3038 &lpfc_idiag_mbxacc_write_3038
114903 +nr_free_buffer_pages_3044 nr_free_buffer_pages 0 3044 NULL
114904 +il3945_ucode_rx_stats_read_3048 il3945_ucode_rx_stats_read 3 3048 NULL
114905 +qp_alloc_ppn_set_3068 qp_alloc_ppn_set 2-4 3068 NULL
114906 +__blk_end_bidi_request_3070 __blk_end_bidi_request 3-4 3070 NULL
114907 +dac960_user_command_proc_write_3071 dac960_user_command_proc_write 3 3071 NULL
114908 +read_file_antenna_diversity_3077 read_file_antenna_diversity 3 3077 NULL
114909 +ttusb2_msg_3100 ttusb2_msg 4 3100 NULL
114910 +rb_alloc_3102 rb_alloc 1 3102 NULL
114911 +simple_write_to_buffer_3122 simple_write_to_buffer 5-2 3122 NULL
114912 +print_time_3132 print_time 0 3132 NULL
114913 +fill_write_buffer_3142 fill_write_buffer 3 3142 NULL
114914 +CIFSSMBSetPosixACL_3154 CIFSSMBSetPosixACL 5 3154 NULL
114915 +uv_num_possible_blades_3177 uv_num_possible_blades 0 3177 NULL
114916 +uinput_ioctl_handler_3181 uinput_ioctl_handler 2 3181 NULL nohasharray
114917 +uvc_video_stats_dump_3181 uvc_video_stats_dump 3 3181 &uinput_ioctl_handler_3181
114918 +compat_do_ip6t_set_ctl_3184 compat_do_ip6t_set_ctl 4 3184 NULL
114919 +mempool_create_node_3191 mempool_create_node 1 3191 NULL
114920 +alloc_context_3194 alloc_context 1 3194 NULL
114921 +shmem_pread_slow_3198 shmem_pread_slow 3-2 3198 NULL
114922 +codec_reg_write_file_3204 codec_reg_write_file 3 3204 NULL
114923 +SyS_sendto_3219 SyS_sendto 6 3219 NULL
114924 +btrfs_prealloc_file_range_3227 btrfs_prealloc_file_range 3 3227 NULL
114925 +kimage_crash_alloc_3233 kimage_crash_alloc 3 3233 NULL
114926 +do_read_log_to_user_3236 do_read_log_to_user 4 3236 NULL
114927 +ext3_xattr_find_entry_3237 ext3_xattr_find_entry 0 3237 NULL
114928 +key_key_read_3241 key_key_read 3 3241 NULL
114929 +__ilog2_u64_3284 __ilog2_u64 0 3284 NULL
114930 +ieee80211_if_write_beacon_loss_3296 ieee80211_if_write_beacon_loss 3 3296 NULL
114931 +cgroup_name_3300 cgroup_name 3 3300 NULL
114932 +__set_extent_bit_3305 __set_extent_bit 0 3305 NULL
114933 +__iovec_copy_from_user_inatomic_3314 __iovec_copy_from_user_inatomic 4-3-0 3314 NULL
114934 +_iwl_dbgfs_d3_sram_write_3315 _iwl_dbgfs_d3_sram_write 3 3315 NULL
114935 +dbDiscardAG_3322 dbDiscardAG 3 3322 NULL
114936 +read_from_oldmem_3337 read_from_oldmem 2 3337 NULL
114937 +sysfs_create_group_3339 sysfs_create_group 0 3339 NULL
114938 +tty_port_register_device_attr_3341 tty_port_register_device_attr 3 3341 NULL
114939 +il_dbgfs_interrupt_read_3351 il_dbgfs_interrupt_read 3 3351 NULL
114940 +gsm_control_rls_3353 gsm_control_rls 3 3353 NULL
114941 +scnprintf_3360 scnprintf 0-2 3360 NULL
114942 +sr_read_3366 sr_read 3 3366 NULL
114943 +mtdchar_writeoob_3393 mtdchar_writeoob 4 3393 NULL
114944 +isdn_readbchan_3401 isdn_readbchan 0-5 3401 NULL
114945 +mei_io_cb_alloc_resp_buf_3414 mei_io_cb_alloc_resp_buf 2 3414 NULL
114946 +pci_add_cap_save_buffer_3426 pci_add_cap_save_buffer 3 3426 NULL
114947 +crystalhd_create_dio_pool_3427 crystalhd_create_dio_pool 2 3427 NULL
114948 +SyS_msgsnd_3436 SyS_msgsnd 3 3436 NULL
114949 +softsynth_write_3455 softsynth_write 3 3455 NULL
114950 +snd_pcm_lib_readv_transfer_3464 snd_pcm_lib_readv_transfer 5-4-2 3464 NULL
114951 +security_context_to_sid_default_3492 security_context_to_sid_default 2 3492 NULL
114952 +xfrm_migrate_msgsize_3496 xfrm_migrate_msgsize 1 3496 NULL
114953 +mem_tx_free_mem_blks_read_3521 mem_tx_free_mem_blks_read 3 3521 NULL
114954 +SyS_semtimedop_3532 SyS_semtimedop 3 3532 NULL
114955 +SyS_readv_3539 SyS_readv 3 3539 NULL
114956 +btrfs_dir_name_len_3549 btrfs_dir_name_len 0 3549 NULL
114957 +alloc_smp_resp_3566 alloc_smp_resp 1 3566 NULL
114958 +evtchn_read_3569 evtchn_read 3 3569 NULL
114959 +ll_track_ppid_seq_write_3582 ll_track_ppid_seq_write 3 3582 NULL
114960 +vc_resize_3585 vc_resize 3-2 3585 NULL
114961 +kvm_mmu_notifier_change_pte_3596 kvm_mmu_notifier_change_pte 3 3596 NULL
114962 +sctp_getsockopt_events_3607 sctp_getsockopt_events 2 3607 NULL
114963 +edac_mc_alloc_3611 edac_mc_alloc 4 3611 NULL
114964 +tx_tx_starts_read_3617 tx_tx_starts_read 3 3617 NULL
114965 +aligned_kmalloc_3628 aligned_kmalloc 1 3628 NULL
114966 +ath6kl_disconnect_timeout_read_3650 ath6kl_disconnect_timeout_read 3 3650 NULL
114967 +i915_compat_ioctl_3656 i915_compat_ioctl 2 3656 NULL
114968 +_iwl_dbgfs_tx_flush_write_3675 _iwl_dbgfs_tx_flush_write 3 3675 NULL
114969 +snd_m3_assp_read_3703 snd_m3_assp_read 0 3703 NULL
114970 +ci_ll_write_3740 ci_ll_write 4 3740 NULL
114971 +sctp_setsockopt_auth_key_3793 sctp_setsockopt_auth_key 3 3793 NULL
114972 +ncp_file_write_3813 ncp_file_write 3 3813 NULL
114973 +llc_ui_recvmsg_3826 llc_ui_recvmsg 4 3826 NULL
114974 +hfsplus_direct_IO_3835 hfsplus_direct_IO 4 3835 NULL
114975 +create_one_cdev_3852 create_one_cdev 2 3852 NULL
114976 +smk_read_onlycap_3855 smk_read_onlycap 3 3855 NULL
114977 +get_fd_set_3866 get_fd_set 1 3866 NULL
114978 +garp_attr_create_3883 garp_attr_create 3 3883 NULL
114979 +efivarfs_file_read_3893 efivarfs_file_read 3 3893 NULL
114980 +nvram_write_3894 nvram_write 3 3894 NULL
114981 +pipeline_pre_proc_swi_read_3898 pipeline_pre_proc_swi_read 3 3898 NULL
114982 +comedi_buf_read_n_available_3899 comedi_buf_read_n_available 0 3899 NULL
114983 +vcs_write_3910 vcs_write 3 3910 NULL
114984 +SyS_move_pages_3920 SyS_move_pages 2 3920 NULL
114985 +brcmf_debugfs_fws_stats_read_3947 brcmf_debugfs_fws_stats_read 3 3947 NULL
114986 +mite_bytes_written_to_memory_lb_3987 mite_bytes_written_to_memory_lb 0 3987 NULL
114987 +do_add_counters_3992 do_add_counters 3 3992 NULL
114988 +obd_alloc_memmd_4002 obd_alloc_memmd 0 4002 NULL
114989 +userspace_status_4004 userspace_status 4 4004 NULL
114990 +mei_write_4005 mei_write 3 4005 NULL nohasharray
114991 +xfs_check_block_4005 xfs_check_block 4 4005 &mei_write_4005
114992 +snd_hdsp_capture_copy_4011 snd_hdsp_capture_copy 5 4011 NULL
114993 +blk_end_request_4024 blk_end_request 3 4024 NULL
114994 +ext4_xattr_find_entry_4025 ext4_xattr_find_entry 0 4025 NULL
114995 +mtip_hw_read_registers_4037 mtip_hw_read_registers 3 4037 NULL
114996 +read_file_queues_4078 read_file_queues 3 4078 NULL
114997 +fbcon_do_set_font_4079 fbcon_do_set_font 2-3 4079 NULL
114998 +tm6000_read_4151 tm6000_read 3 4151 NULL
114999 +mpt_raid_phys_disk_get_num_paths_4155 mpt_raid_phys_disk_get_num_paths 0 4155 NULL
115000 +msg_bits_4158 msg_bits 0-3-4 4158 NULL
115001 +get_alua_req_4166 get_alua_req 3 4166 NULL
115002 +blk_dropped_read_4168 blk_dropped_read 3 4168 NULL
115003 +read_file_bool_4180 read_file_bool 3 4180 NULL
115004 +vring_new_virtqueue_4199 vring_new_virtqueue 2 4199 NULL
115005 +_osd_req_list_objects_4204 _osd_req_list_objects 6 4204 NULL
115006 +__snd_gf1_read_addr_4210 __snd_gf1_read_addr 0 4210 NULL
115007 +ath6kl_force_roam_write_4282 ath6kl_force_roam_write 3 4282 NULL
115008 +goldfish_audio_write_4284 goldfish_audio_write 3 4284 NULL
115009 +get_connectors_for_crtc_4291 get_connectors_for_crtc 0 4291 NULL
115010 +__usbnet_read_cmd_4299 __usbnet_read_cmd 7 4299 NULL
115011 +dvb_ringbuffer_pkt_read_user_4303 dvb_ringbuffer_pkt_read_user 2-3-5 4303 NULL
115012 +count_strings_4315 count_strings 0 4315 NULL
115013 +nouveau_fifo_create__4327 nouveau_fifo_create_ 5-6 4327 NULL
115014 +snd_rawmidi_kernel_read_4328 snd_rawmidi_kernel_read 3 4328 NULL
115015 +ima_eventdigest_init_common_4338 ima_eventdigest_init_common 2 4338 NULL
115016 +__copy_from_user_inatomic_4365 __copy_from_user_inatomic 3-0 4365 NULL
115017 +irda_sendmsg_4388 irda_sendmsg 4 4388 NULL
115018 +cxacru_cm_get_array_4412 cxacru_cm_get_array 4 4412 NULL nohasharray
115019 +access_process_vm_4412 access_process_vm 0 4412 &cxacru_cm_get_array_4412
115020 +libfc_vport_create_4415 libfc_vport_create 2 4415 NULL
115021 +rtw_android_get_rssi_4421 rtw_android_get_rssi 0 4421 NULL
115022 +do_pages_stat_4437 do_pages_stat 2 4437 NULL
115023 +at76_set_card_command_4471 at76_set_card_command 4 4471 NULL
115024 +snd_seq_expand_var_event_4481 snd_seq_expand_var_event 0-5 4481 NULL
115025 +vmbus_establish_gpadl_4495 vmbus_establish_gpadl 3 4495 NULL
115026 +set_link_security_4502 set_link_security 4 4502 NULL
115027 +ll_max_readahead_per_file_mb_seq_write_4531 ll_max_readahead_per_file_mb_seq_write 3 4531 NULL
115028 +tty_register_device_4544 tty_register_device 2 4544 NULL
115029 +fsl_edma_prep_slave_sg_4555 fsl_edma_prep_slave_sg 3 4555 NULL
115030 +btrfs_file_extent_inline_item_len_4575 btrfs_file_extent_inline_item_len 0 4575 NULL
115031 +xfs_buf_get_maps_4581 xfs_buf_get_maps 2 4581 NULL
115032 +bch_alloc_4593 bch_alloc 1 4593 NULL
115033 +ll_rw_extents_stats_seq_write_4633 ll_rw_extents_stats_seq_write 3 4633 NULL
115034 +iwl_dbgfs_tx_queue_read_4635 iwl_dbgfs_tx_queue_read 3 4635 NULL
115035 +skb_add_data_nocache_4682 skb_add_data_nocache 4 4682 NULL
115036 +cx18_read_pos_4683 cx18_read_pos 3 4683 NULL
115037 +short_retry_limit_read_4687 short_retry_limit_read 3 4687 NULL
115038 +kone_receive_4690 kone_receive 4 4690 NULL
115039 +hash_netportnet6_expire_4702 hash_netportnet6_expire 4 4702 NULL
115040 +cxgbi_alloc_big_mem_4707 cxgbi_alloc_big_mem 1 4707 NULL
115041 +show_header_4722 show_header 3 4722 NULL nohasharray
115042 +ati_create_gatt_pages_4722 ati_create_gatt_pages 1 4722 &show_header_4722
115043 +ll_rw_offset_stats_seq_write_4736 ll_rw_offset_stats_seq_write 3 4736 NULL nohasharray
115044 +bitmap_startwrite_4736 bitmap_startwrite 2 4736 &ll_rw_offset_stats_seq_write_4736
115045 +lu_buf_alloc_4753 lu_buf_alloc 2 4753 NULL
115046 +pwr_rcvd_bcns_cnt_read_4774 pwr_rcvd_bcns_cnt_read 3 4774 NULL
115047 +create_subvol_4791 create_subvol 4 4791 NULL
115048 +ncp__vol2io_4804 ncp__vol2io 5 4804 NULL
115049 +C_SYSC_setsockopt_4806 C_SYSC_setsockopt 5 4806 NULL
115050 +repair_io_failure_4815 repair_io_failure 4-3 4815 NULL
115051 +comedi_buf_write_free_4847 comedi_buf_write_free 2 4847 NULL
115052 +gigaset_if_receive_4861 gigaset_if_receive 3 4861 NULL
115053 +key_tx_spec_read_4862 key_tx_spec_read 3 4862 NULL
115054 +ocfs2_defrag_extent_4873 ocfs2_defrag_extent 2 4873 NULL
115055 +hid_register_field_4874 hid_register_field 2-3 4874 NULL
115056 +vga_arb_read_4886 vga_arb_read 3 4886 NULL
115057 +ieee80211_if_fmt_ave_beacon_4941 ieee80211_if_fmt_ave_beacon 3 4941 NULL
115058 +compat_rawv6_setsockopt_4967 compat_rawv6_setsockopt 5 4967 NULL
115059 +ath10k_read_chip_id_4969 ath10k_read_chip_id 3 4969 NULL
115060 +skb_network_header_len_4971 skb_network_header_len 0 4971 NULL
115061 +ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval_4976 ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval 3 4976 NULL
115062 +compat_SyS_ipc_5000 compat_SyS_ipc 3 5000 NULL
115063 +do_mincore_5018 do_mincore 0-2-1 5018 NULL
115064 +btrfs_punch_hole_5041 btrfs_punch_hole 2 5041 NULL
115065 +cfg80211_rx_mgmt_5056 cfg80211_rx_mgmt 5 5056 NULL
115066 +ocfs2_check_range_for_holes_5066 ocfs2_check_range_for_holes 2-3 5066 NULL
115067 +snd_mixart_BA1_read_5082 snd_mixart_BA1_read 5 5082 NULL
115068 +snd_emu10k1_ptr20_read_5087 snd_emu10k1_ptr20_read 0 5087 NULL
115069 +kfifo_copy_from_user_5091 kfifo_copy_from_user 3-4-0 5091 NULL nohasharray
115070 +get_random_bytes_5091 get_random_bytes 2 5091 &kfifo_copy_from_user_5091 nohasharray
115071 +blk_rq_sectors_5091 blk_rq_sectors 0 5091 &get_random_bytes_5091
115072 +sound_write_5102 sound_write 3 5102 NULL
115073 +i40e_dbg_netdev_ops_write_5117 i40e_dbg_netdev_ops_write 3 5117 NULL
115074 +qib_7220_handle_hwerrors_5142 qib_7220_handle_hwerrors 3 5142 NULL
115075 +__uwb_addr_print_5161 __uwb_addr_print 2 5161 NULL
115076 +iwl_dbgfs_status_read_5171 iwl_dbgfs_status_read 3 5171 NULL
115077 +acpi_pcc_get_sqty_5176 acpi_pcc_get_sqty 0 5176 NULL
115078 +trf7970a_read_cont_5179 trf7970a_read_cont 4 5179 NULL
115079 +ppp_cp_parse_cr_5214 ppp_cp_parse_cr 4 5214 NULL
115080 +dwc2_hcd_urb_alloc_5217 dwc2_hcd_urb_alloc 2 5217 NULL
115081 +ath6kl_debug_roam_tbl_event_5224 ath6kl_debug_roam_tbl_event 3 5224 NULL
115082 +r592_write_fifo_pio_5315 r592_write_fifo_pio 3 5315 NULL
115083 +sbc_get_write_same_sectors_5317 sbc_get_write_same_sectors 0 5317 NULL
115084 +pwr_elp_enter_read_5324 pwr_elp_enter_read 3 5324 NULL
115085 +uinput_ioctl_5342 uinput_ioctl 2 5342 NULL
115086 +cq_free_res_5355 cq_free_res 5 5355 NULL
115087 +ps_pspoll_utilization_read_5361 ps_pspoll_utilization_read 3 5361 NULL
115088 +cciss_allocate_sg_chain_blocks_5368 cciss_allocate_sg_chain_blocks 3-2 5368 NULL
115089 +xfs_efd_init_5463 xfs_efd_init 3 5463 NULL
115090 +ll_xattr_cache_refill_5468 ll_xattr_cache_refill 0 5468 NULL
115091 +kernfs_fop_write_5471 kernfs_fop_write 3 5471 NULL
115092 +xfs_efi_init_5476 xfs_efi_init 2 5476 NULL
115093 +pci_enable_msix_exact_5482 pci_enable_msix_exact 3-0 5482 NULL
115094 +cifs_security_flags_proc_write_5484 cifs_security_flags_proc_write 3 5484 NULL
115095 +tty_write_5494 tty_write 3 5494 NULL
115096 +tomoyo_update_domain_5498 tomoyo_update_domain 2 5498 NULL nohasharray
115097 +ieee80211_if_fmt_last_beacon_5498 ieee80211_if_fmt_last_beacon 3 5498 &tomoyo_update_domain_5498
115098 +__max_nr_grant_frames_5505 __max_nr_grant_frames 0 5505 NULL
115099 +ieee80211_if_fmt_auto_open_plinks_5534 ieee80211_if_fmt_auto_open_plinks 3 5534 NULL
115100 +get_entry_msg_len_5552 get_entry_msg_len 0 5552 NULL
115101 +le_readq_5557 le_readq 0 5557 NULL
115102 +inw_5558 inw 0 5558 NULL
115103 +bioset_create_5580 bioset_create 1 5580 NULL
115104 +oz_ep_alloc_5587 oz_ep_alloc 1 5587 NULL
115105 +__remove_suid_5618 __remove_suid 0 5618 NULL
115106 +SYSC_fsetxattr_5639 SYSC_fsetxattr 4 5639 NULL
115107 +ext4_xattr_get_5661 ext4_xattr_get 0 5661 NULL
115108 +posix_clock_register_5662 posix_clock_register 2 5662 NULL
115109 +get_arg_5694 get_arg 3 5694 NULL
115110 +subbuf_read_actor_5708 subbuf_read_actor 3 5708 NULL
115111 +vmw_kms_readback_5727 vmw_kms_readback 6 5727 NULL
115112 +rts51x_transfer_data_partial_5735 rts51x_transfer_data_partial 6 5735 NULL
115113 +sctp_setsockopt_autoclose_5775 sctp_setsockopt_autoclose 3 5775 NULL
115114 +__vxge_hw_blockpool_malloc_5786 __vxge_hw_blockpool_malloc 2 5786 NULL
115115 +nvme_trans_bdev_char_page_5797 nvme_trans_bdev_char_page 3 5797 NULL
115116 +skb_copy_datagram_iovec_5806 skb_copy_datagram_iovec 2-4 5806 NULL
115117 +nv50_disp_pioc_create__5812 nv50_disp_pioc_create_ 5 5812 NULL
115118 +ceph_x_encrypt_buflen_5829 ceph_x_encrypt_buflen 0-1 5829 NULL
115119 +ceph_msg_new_5846 ceph_msg_new 2 5846 NULL
115120 +setup_req_5848 setup_req 3 5848 NULL
115121 +ria_page_count_5849 ria_page_count 0 5849 NULL
115122 +rx_filter_max_arp_queue_dep_read_5851 rx_filter_max_arp_queue_dep_read 3 5851 NULL
115123 +uinput_compat_ioctl_5861 uinput_compat_ioctl 2 5861 NULL
115124 +lprocfs_fid_width_seq_write_5889 lprocfs_fid_width_seq_write 3 5889 NULL
115125 +port_show_regs_5904 port_show_regs 3 5904 NULL
115126 +rbd_segment_length_5907 rbd_segment_length 0-3-2 5907 NULL
115127 +uhci_debug_read_5911 uhci_debug_read 3 5911 NULL
115128 +lbs_highsnr_read_5931 lbs_highsnr_read 3 5931 NULL
115129 +ps_poll_ps_poll_timeouts_read_5934 ps_poll_ps_poll_timeouts_read 3 5934 NULL
115130 +edac_device_alloc_ctl_info_5941 edac_device_alloc_ctl_info 1 5941 NULL
115131 +ll_statahead_one_5962 ll_statahead_one 3 5962 NULL
115132 +__apu_get_register_5967 __apu_get_register 0 5967 NULL
115133 +ieee80211_if_fmt_rc_rateidx_mask_5ghz_5971 ieee80211_if_fmt_rc_rateidx_mask_5ghz 3 5971 NULL
115134 +SyS_semop_5980 SyS_semop 3 5980 NULL
115135 +alloc_msg_6072 alloc_msg 1 6072 NULL
115136 +sctp_setsockopt_connectx_6073 sctp_setsockopt_connectx 3 6073 NULL
115137 +rts51x_ms_rw_multi_sector_6076 rts51x_ms_rw_multi_sector 3-4 6076 NULL
115138 +__mnt_want_write_6091 __mnt_want_write 0 6091 NULL
115139 +ipmi_addr_length_6110 ipmi_addr_length 0 6110 NULL nohasharray
115140 +force_static_address_read_6110 force_static_address_read 3 6110 &ipmi_addr_length_6110
115141 +dfs_global_file_write_6112 dfs_global_file_write 3 6112 NULL
115142 +nouveau_parent_create__6131 nouveau_parent_create_ 7 6131 NULL
115143 +ieee80211_if_fmt_beacon_timeout_6153 ieee80211_if_fmt_beacon_timeout 3 6153 NULL
115144 +ivtv_copy_buf_to_user_6159 ivtv_copy_buf_to_user 4 6159 NULL
115145 +maybe_insert_hole_6167 maybe_insert_hole 3 6167 NULL
115146 +wl1251_cmd_template_set_6172 wl1251_cmd_template_set 4 6172 NULL
115147 +SyS_setgroups_6182 SyS_setgroups 1 6182 NULL
115148 +mxt_show_instance_6207 mxt_show_instance 2-0 6207 NULL
115149 +v4l2_ctrl_new_std_menu_6221 v4l2_ctrl_new_std_menu 4 6221 NULL
115150 +mqueue_read_file_6228 mqueue_read_file 3 6228 NULL
115151 +f_hidg_read_6238 f_hidg_read 3 6238 NULL
115152 +fbcon_prepare_logo_6246 fbcon_prepare_logo 5 6246 NULL
115153 +of_gpio_count_6270 of_gpio_count 0 6270 NULL
115154 +tx_tx_start_null_frame_read_6281 tx_tx_start_null_frame_read 3 6281 NULL
115155 +snd_hda_override_conn_list_6282 snd_hda_override_conn_list 3-0 6282 NULL nohasharray
115156 +xenbus_file_write_6282 xenbus_file_write 3 6282 &snd_hda_override_conn_list_6282
115157 +posix_acl_fix_xattr_to_user_6283 posix_acl_fix_xattr_to_user 2 6283 NULL
115158 +serial_port_in_6291 serial_port_in 0 6291 NULL
115159 +qlcnic_sriov_alloc_bc_msg_6309 qlcnic_sriov_alloc_bc_msg 2 6309 NULL
115160 +hfa384x_inw_6329 hfa384x_inw 0 6329 NULL nohasharray
115161 +SyS_mincore_6329 SyS_mincore 1-2 6329 &hfa384x_inw_6329
115162 +fuse_get_req_for_background_6337 fuse_get_req_for_background 2 6337 NULL
115163 +ucs2_strnlen_6342 ucs2_strnlen 0 6342 NULL
115164 +regcache_sync_block_raw_6350 regcache_sync_block_raw 5-4 6350 NULL
115165 +mei_dbgfs_read_devstate_6352 mei_dbgfs_read_devstate 3 6352 NULL
115166 +_proc_do_string_6376 _proc_do_string 2 6376 NULL
115167 +osd_req_read_sg_kern_6378 osd_req_read_sg_kern 5 6378 NULL
115168 +posix_acl_fix_xattr_userns_6420 posix_acl_fix_xattr_userns 4 6420 NULL
115169 +add_transaction_credits_6422 add_transaction_credits 2-3 6422 NULL
115170 +ipr_change_queue_depth_6431 ipr_change_queue_depth 2 6431 NULL
115171 +__alloc_bootmem_node_nopanic_6432 __alloc_bootmem_node_nopanic 2 6432 NULL
115172 +ieee80211_if_fmt_dot11MeshMaxRetries_6476 ieee80211_if_fmt_dot11MeshMaxRetries 3 6476 NULL
115173 +qp_memcpy_from_queue_6479 qp_memcpy_from_queue 5-4 6479 NULL
115174 +cipso_v4_map_lvl_hton_6490 cipso_v4_map_lvl_hton 0 6490 NULL
115175 +dbg_intr_buf_6501 dbg_intr_buf 2 6501 NULL
115176 +mei_read_6507 mei_read 3 6507 NULL
115177 +rndis_set_oid_6547 rndis_set_oid 4 6547 NULL
115178 +wdm_read_6549 wdm_read 3 6549 NULL
115179 +dm_stats_create_6551 dm_stats_create 4-2-3 6551 NULL
115180 +fb_alloc_cmap_6554 fb_alloc_cmap 2 6554 NULL
115181 +SyS_semtimedop_6563 SyS_semtimedop 3 6563 NULL
115182 +snd_pcm_hw_refine_old_user_6586 snd_pcm_hw_refine_old_user 0 6586 NULL
115183 +ecryptfs_filldir_6622 ecryptfs_filldir 3 6622 NULL
115184 +process_rcvd_data_6679 process_rcvd_data 3 6679 NULL
115185 +pvscsi_allocate_rings_6689 pvscsi_allocate_rings 0 6689 NULL
115186 +btrfs_lookup_csums_range_6696 btrfs_lookup_csums_range 2-3 6696 NULL
115187 +ps_pspoll_max_apturn_read_6699 ps_pspoll_max_apturn_read 3 6699 NULL
115188 +bnad_debugfs_write_regrd_6706 bnad_debugfs_write_regrd 3 6706 NULL
115189 +mpeg_read_6708 mpeg_read 3 6708 NULL
115190 +ibmpex_query_sensor_count_6709 ibmpex_query_sensor_count 0 6709 NULL
115191 +video_proc_write_6724 video_proc_write 3 6724 NULL
115192 +posix_acl_xattr_count_6725 posix_acl_xattr_count 0-1 6725 NULL
115193 +kobject_add_varg_6781 kobject_add_varg 0 6781 NULL
115194 +iwl_dbgfs_channels_read_6784 iwl_dbgfs_channels_read 3 6784 NULL
115195 +ieee80211_if_read_6785 ieee80211_if_read 3 6785 NULL
115196 +zone_spanned_pages_in_node_6787 zone_spanned_pages_in_node 0-3-4 6787 NULL
115197 +hdlcdrv_register_6792 hdlcdrv_register 2 6792 NULL
115198 +ll_xattr_cache_find_6798 ll_xattr_cache_find 0 6798 NULL
115199 +tx_tx_done_data_read_6799 tx_tx_done_data_read 3 6799 NULL
115200 +lbs_rdrf_write_6826 lbs_rdrf_write 3 6826 NULL
115201 +calc_pages_for_6838 calc_pages_for 0-2-1 6838 NULL
115202 +mon_bin_read_6841 mon_bin_read 3 6841 NULL
115203 +snd_cs4281_BA0_read_6847 snd_cs4281_BA0_read 5 6847 NULL
115204 +perf_output_sample_ustack_6868 perf_output_sample_ustack 2 6868 NULL
115205 +dio_complete_6879 dio_complete 0-3-2 6879 NULL
115206 +raw_seticmpfilter_6888 raw_seticmpfilter 3 6888 NULL nohasharray
115207 +ieee80211_if_fmt_path_refresh_time_6888 ieee80211_if_fmt_path_refresh_time 3 6888 &raw_seticmpfilter_6888
115208 +dlmfs_file_write_6892 dlmfs_file_write 3 6892 NULL
115209 +proc_sessionid_read_6911 proc_sessionid_read 3 6911 NULL nohasharray
115210 +spi_show_regs_6911 spi_show_regs 3 6911 &proc_sessionid_read_6911 nohasharray
115211 +acm_alloc_minor_6911 acm_alloc_minor 0 6911 &spi_show_regs_6911
115212 +__kfifo_dma_in_finish_r_6913 __kfifo_dma_in_finish_r 2-3 6913 NULL
115213 +cache_do_downcall_6926 cache_do_downcall 3 6926 NULL
115214 +ipath_verbs_send_dma_6929 ipath_verbs_send_dma 6 6929 NULL
115215 +qsfp_cks_6945 qsfp_cks 2-0 6945 NULL
115216 +tg3_nvram_write_block_unbuffered_6955 tg3_nvram_write_block_unbuffered 3 6955 NULL
115217 +pch_uart_hal_read_6961 pch_uart_hal_read 0 6961 NULL
115218 +i40e_dbg_dump_write_6973 i40e_dbg_dump_write 3 6973 NULL nohasharray
115219 +rsa_extract_mpi_6973 rsa_extract_mpi 5 6973 &i40e_dbg_dump_write_6973
115220 +request_key_async_6990 request_key_async 4 6990 NULL
115221 +tpl_write_6998 tpl_write 3 6998 NULL
115222 +r871x_set_wpa_ie_7000 r871x_set_wpa_ie 3 7000 NULL
115223 +cipso_v4_gentag_enum_7006 cipso_v4_gentag_enum 0 7006 NULL
115224 +tracing_cpumask_read_7010 tracing_cpumask_read 3 7010 NULL
115225 +ld_usb_write_7022 ld_usb_write 3 7022 NULL
115226 +wimax_msg_7030 wimax_msg 4 7030 NULL
115227 +ceph_kvmalloc_7033 ceph_kvmalloc 1 7033 NULL
115228 +ipath_get_base_info_7043 ipath_get_base_info 3 7043 NULL
115229 +snd_pcm_oss_bytes_7051 snd_pcm_oss_bytes 2 7051 NULL
115230 +nouveau_device_create__7063 nouveau_device_create_ 7 7063 NULL
115231 +hci_sock_recvmsg_7072 hci_sock_recvmsg 4 7072 NULL
115232 +event_enable_read_7074 event_enable_read 3 7074 NULL
115233 +tipc_send_packet_7091 tipc_send_packet 4 7091 NULL nohasharray
115234 +beacon_interval_read_7091 beacon_interval_read 3 7091 &tipc_send_packet_7091
115235 +pipeline_enc_rx_stat_fifo_int_read_7107 pipeline_enc_rx_stat_fifo_int_read 3 7107 NULL
115236 +osc_resend_count_seq_write_7120 osc_resend_count_seq_write 3 7120 NULL
115237 +qib_format_hwerrors_7133 qib_format_hwerrors 5 7133 NULL
115238 +kvm_mmu_notifier_test_young_7139 kvm_mmu_notifier_test_young 3 7139 NULL
115239 +qlcnic_enable_msix_7144 qlcnic_enable_msix 2 7144 NULL
115240 +__alloc_objio_seg_7203 __alloc_objio_seg 1 7203 NULL
115241 +rx_rate_rx_frames_per_rates_read_7282 rx_rate_rx_frames_per_rates_read 3 7282 NULL
115242 +security_inode_need_killpriv_7322 security_inode_need_killpriv 0 7322 NULL
115243 +pci_vpd_info_field_size_7324 pci_vpd_info_field_size 0 7324 NULL
115244 +mgmt_control_7349 mgmt_control 3 7349 NULL
115245 +at_est2timeout_7365 at_est2timeout 0-1 7365 NULL
115246 +ieee80211_if_read_dot11MeshHWMPactivePathTimeout_7368 ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 NULL
115247 +ath10k_read_fw_stats_7387 ath10k_read_fw_stats 3 7387 NULL
115248 +hweight_long_7388 hweight_long 0 7388 NULL
115249 +sl_change_mtu_7396 sl_change_mtu 2 7396 NULL
115250 +_ore_add_stripe_unit_7399 _ore_add_stripe_unit 6-3 7399 NULL
115251 +audmux_read_file_7400 audmux_read_file 3 7400 NULL
115252 +readb_7401 readb 0 7401 NULL
115253 +tipc_recvmsg_7402 tipc_recvmsg 4 7402 NULL
115254 +drm_property_create_blob_7414 drm_property_create_blob 2 7414 NULL
115255 +__copy_to_user_nocheck_7443 __copy_to_user_nocheck 0-3 7443 NULL
115256 +ip_options_get_alloc_7448 ip_options_get_alloc 1 7448 NULL
115257 +SYSC_setgroups_7454 SYSC_setgroups 1 7454 NULL
115258 +rt2x00debug_read_queue_stats_7455 rt2x00debug_read_queue_stats 3 7455 NULL
115259 +l2tp_ip6_sendmsg_7461 l2tp_ip6_sendmsg 4 7461 NULL
115260 +garp_request_join_7471 garp_request_join 4 7471 NULL
115261 +snd_pcm_lib_read1_7491 snd_pcm_lib_read1 0-3 7491 NULL
115262 +ahash_instance_headroom_7509 ahash_instance_headroom 0 7509 NULL nohasharray
115263 +sdhci_alloc_host_7509 sdhci_alloc_host 2 7509 &ahash_instance_headroom_7509
115264 +array_zalloc_7519 array_zalloc 1-2 7519 NULL
115265 +sk_convert_filter_7541 sk_convert_filter 2 7541 NULL
115266 +ath10k_read_htt_stats_mask_7557 ath10k_read_htt_stats_mask 3 7557 NULL
115267 +smk_read_mapped_7562 smk_read_mapped 3 7562 NULL
115268 +netvsc_get_slots_7565 netvsc_get_slots 0 7565 NULL
115269 +cfs_cpt_num_estimate_7571 cfs_cpt_num_estimate 0 7571 NULL
115270 +groups_alloc_7614 groups_alloc 1 7614 NULL nohasharray
115271 +create_dir_7614 create_dir 0 7614 &groups_alloc_7614
115272 +_rtw_zmalloc_7636 _rtw_zmalloc 1 7636 NULL
115273 +fault_inject_write_7662 fault_inject_write 3 7662 NULL
115274 +acpi_ex_allocate_name_string_7685 acpi_ex_allocate_name_string 2-1 7685 NULL
115275 +acpi_ns_get_pathname_length_7699 acpi_ns_get_pathname_length 0 7699 NULL
115276 +dev_write_7708 dev_write 3 7708 NULL
115277 +pci_raw_set_power_state_7729 pci_raw_set_power_state 0 7729 NULL
115278 +vxge_device_register_7752 vxge_device_register 4 7752 NULL
115279 +ubi_io_read_vid_hdr_7766 ubi_io_read_vid_hdr 0 7766 NULL
115280 +iwl_dbgfs_bt_cmd_read_7770 iwl_dbgfs_bt_cmd_read 3 7770 NULL
115281 +alloc_candev_7776 alloc_candev 1-2 7776 NULL
115282 +dfs_global_file_read_7787 dfs_global_file_read 3 7787 NULL
115283 +bnx2_nvram_write_7790 bnx2_nvram_write 4-2 7790 NULL
115284 +lustre_packed_msg_size_7792 lustre_packed_msg_size 0 7792 NULL nohasharray
115285 +diva_os_copy_from_user_7792 diva_os_copy_from_user 4 7792 &lustre_packed_msg_size_7792
115286 +cfs_trace_dump_debug_buffer_usrstr_7861 cfs_trace_dump_debug_buffer_usrstr 2 7861 NULL
115287 +tipc_alloc_entry_7875 tipc_alloc_entry 2 7875 NULL
115288 +dvb_dmxdev_read_sec_7892 dvb_dmxdev_read_sec 4 7892 NULL
115289 +xfs_trans_get_efi_7898 xfs_trans_get_efi 2 7898 NULL
115290 +libfc_host_alloc_7917 libfc_host_alloc 2 7917 NULL
115291 +f_hidg_write_7932 f_hidg_write 3 7932 NULL
115292 +integrity_digsig_verify_7956 integrity_digsig_verify 3-0 7956 NULL
115293 +smk_write_load_self_7958 smk_write_load_self 3 7958 NULL
115294 +tt3650_ci_msg_locked_8013 tt3650_ci_msg_locked 4 8013 NULL
115295 +vcs_read_8017 vcs_read 3 8017 NULL
115296 +vhost_add_used_and_signal_n_8038 vhost_add_used_and_signal_n 4 8038 NULL
115297 +ms_read_multiple_pages_8052 ms_read_multiple_pages 5-4 8052 NULL
115298 +dgrp_mon_read_8065 dgrp_mon_read 3 8065 NULL
115299 +spi_write_then_read_8073 spi_write_then_read 5-3 8073 NULL
115300 +qla4xxx_post_ping_evt_work_8074 qla4xxx_post_ping_evt_work 4 8074 NULL
115301 +venus_lookup_8121 venus_lookup 4 8121 NULL
115302 +ieee80211_if_fmt_num_buffered_multicast_8127 ieee80211_if_fmt_num_buffered_multicast 3 8127 NULL
115303 +__sk_mem_schedule_8185 __sk_mem_schedule 2 8185 NULL
115304 +ieee80211_if_fmt_dot11MeshHoldingTimeout_8187 ieee80211_if_fmt_dot11MeshHoldingTimeout 3 8187 NULL
115305 +recent_mt_proc_write_8206 recent_mt_proc_write 3 8206 NULL
115306 +rt2x00debug_write_bbp_8212 rt2x00debug_write_bbp 3 8212 NULL
115307 +ad7879_spi_multi_read_8218 ad7879_spi_multi_read 3 8218 NULL
115308 +play_iframe_8219 play_iframe 3 8219 NULL
115309 +kvm_mmu_page_set_gfn_8225 kvm_mmu_page_set_gfn 2 8225 NULL
115310 +sctp_ssnmap_size_8228 sctp_ssnmap_size 0-1-2 8228 NULL
115311 +check_xattr_ref_inode_8244 check_xattr_ref_inode 0 8244 NULL
115312 +t3_init_l2t_8261 t3_init_l2t 1 8261 NULL
115313 +init_cdev_8274 init_cdev 1 8274 NULL
115314 +rproc_recovery_write_8281 rproc_recovery_write 3 8281 NULL
115315 +qib_decode_7220_err_8315 qib_decode_7220_err 3 8315 NULL
115316 +snd_pcm_update_state_8320 snd_pcm_update_state 0 8320 NULL
115317 +ipwireless_send_packet_8328 ipwireless_send_packet 4 8328 NULL
115318 +rtw_cfg80211_rx_action_8329 rtw_cfg80211_rx_action 3 8329 NULL
115319 +tracing_entries_read_8345 tracing_entries_read 3 8345 NULL
115320 +ieee80211_if_fmt_ht_opmode_8347 ieee80211_if_fmt_ht_opmode 3 8347 NULL
115321 +generic_write_sync_8358 generic_write_sync 0 8358 NULL
115322 +ping_getfrag_8360 ping_getfrag 4-3 8360 NULL
115323 +ath6kl_lrssi_roam_write_8362 ath6kl_lrssi_roam_write 3 8362 NULL
115324 +xdi_copy_from_user_8395 xdi_copy_from_user 4 8395 NULL
115325 +zd_rf_scnprint_id_8406 zd_rf_scnprint_id 0-3 8406 NULL
115326 +smk_write_change_rule_8411 smk_write_change_rule 3 8411 NULL nohasharray
115327 +uvc_v4l2_ioctl_8411 uvc_v4l2_ioctl 2 8411 &smk_write_change_rule_8411
115328 +roccat_common2_sysfs_read_8431 roccat_common2_sysfs_read 6 8431 NULL
115329 +afs_cell_lookup_8482 afs_cell_lookup 2 8482 NULL
115330 +fore200e_chunk_alloc_8501 fore200e_chunk_alloc 4-3 8501 NULL
115331 +batadv_tt_len_8502 batadv_tt_len 0-1 8502 NULL
115332 +dev_config_8506 dev_config 3 8506 NULL
115333 +ACL_to_cifs_posix_8509 ACL_to_cifs_posix 3 8509 NULL
115334 +opticon_process_data_packet_8524 opticon_process_data_packet 3 8524 NULL
115335 +user_on_off_8552 user_on_off 2 8552 NULL
115336 +profile_remove_8556 profile_remove 3 8556 NULL
115337 +cache_slow_downcall_8570 cache_slow_downcall 2 8570 NULL nohasharray
115338 +pci_msi_check_device_8570 pci_msi_check_device 0 8570 &cache_slow_downcall_8570
115339 +isr_dma0_done_read_8574 isr_dma0_done_read 3 8574 NULL
115340 +tower_write_8580 tower_write 3 8580 NULL
115341 +cfs_cpt_number_8618 cfs_cpt_number 0 8618 NULL
115342 +shash_setkey_unaligned_8620 shash_setkey_unaligned 3 8620 NULL
115343 +it821x_firmware_command_8628 it821x_firmware_command 3 8628 NULL
115344 +scsi_dma_map_8632 scsi_dma_map 0 8632 NULL
115345 +fuse_send_write_pages_8636 fuse_send_write_pages 0-5 8636 NULL
115346 +mlx5_vzalloc_8663 mlx5_vzalloc 1 8663 NULL
115347 +dio_bio_alloc_8677 dio_bio_alloc 5 8677 NULL
115348 +lbs_bcnmiss_read_8678 lbs_bcnmiss_read 3 8678 NULL
115349 +rproc_trace_read_8686 rproc_trace_read 3 8686 NULL
115350 +skb_frag_size_8695 skb_frag_size 0 8695 NULL
115351 +arcfb_write_8702 arcfb_write 3 8702 NULL
115352 +i_size_read_8703 i_size_read 0 8703 NULL nohasharray
115353 +init_header_8703 init_header 0 8703 &i_size_read_8703
115354 +ctrl_out_8712 ctrl_out 3-5 8712 NULL
115355 +tracing_max_lat_write_8728 tracing_max_lat_write 3 8728 NULL
115356 +jffs2_acl_count_8729 jffs2_acl_count 0-1 8729 NULL
115357 +__create_irqs_8733 __create_irqs 2 8733 NULL
115358 +tx_tx_exch_expiry_read_8749 tx_tx_exch_expiry_read 3 8749 NULL
115359 +compound_order_8750 compound_order 0 8750 NULL
115360 +yurex_write_8761 yurex_write 3 8761 NULL
115361 +joydev_compat_ioctl_8765 joydev_compat_ioctl 2 8765 NULL
115362 +kstrtoint_from_user_8778 kstrtoint_from_user 2 8778 NULL
115363 +paging32_prefetch_gpte_8783 paging32_prefetch_gpte 4 8783 NULL
115364 +ext4_try_to_write_inline_data_8785 ext4_try_to_write_inline_data 3-4 8785 NULL
115365 +__bitmap_weight_8796 __bitmap_weight 0 8796 NULL
115366 +metronomefb_write_8823 metronomefb_write 3 8823 NULL
115367 +SyS_llistxattr_8824 SyS_llistxattr 3 8824 NULL
115368 +extent_read_full_page_8826 extent_read_full_page 0 8826 NULL
115369 +ll_xattr_cache_get_8829 ll_xattr_cache_get 0 8829 NULL
115370 +get_queue_depth_8833 get_queue_depth 0 8833 NULL
115371 +dvb_ringbuffer_pkt_next_8834 dvb_ringbuffer_pkt_next 0-2 8834 NULL
115372 +usb_ep_queue_8839 usb_ep_queue 0 8839 NULL
115373 +iwl_rx_packet_len_8854 iwl_rx_packet_len 0 8854 NULL
115374 +debug_debug1_read_8856 debug_debug1_read 3 8856 NULL
115375 +wa_nep_queue_8858 wa_nep_queue 2 8858 NULL
115376 +radeon_drm_ioctl_8875 radeon_drm_ioctl 2 8875 NULL
115377 +compressed_bio_size_8887 compressed_bio_size 0-2 8887 NULL
115378 +ab3100_get_set_reg_8890 ab3100_get_set_reg 3 8890 NULL nohasharray
115379 +tracing_max_lat_read_8890 tracing_max_lat_read 3 8890 &ab3100_get_set_reg_8890
115380 +sdio_max_byte_size_8907 sdio_max_byte_size 0 8907 NULL
115381 +sysfs_merge_group_8917 sysfs_merge_group 0 8917 NULL
115382 +write_file_ani_8918 write_file_ani 3 8918 NULL
115383 +layout_commit_8926 layout_commit 3 8926 NULL
115384 +cp2112_hid_get_8933 cp2112_hid_get 4 8933 NULL
115385 +adjust_priv_size_8935 adjust_priv_size 0-1 8935 NULL
115386 +driver_stats_read_8944 driver_stats_read 3 8944 NULL
115387 +read_file_tgt_stats_8959 read_file_tgt_stats 3 8959 NULL
115388 +usb_allocate_stream_buffers_8964 usb_allocate_stream_buffers 3 8964 NULL
115389 +qib_qsfp_dump_8966 qib_qsfp_dump 0-3 8966 NULL
115390 +venus_mkdir_8967 venus_mkdir 4 8967 NULL
115391 +seq_open_net_8968 seq_open_net 4 8968 NULL nohasharray
115392 +vol_cdev_read_8968 vol_cdev_read 3 8968 &seq_open_net_8968
115393 +bio_integrity_get_tag_8974 bio_integrity_get_tag 3 8974 NULL
115394 +sony_register_touchpad_8981 sony_register_touchpad 2 8981 NULL
115395 +jbd2_journal_blocks_per_page_9004 jbd2_journal_blocks_per_page 0 9004 NULL
115396 +il_dbgfs_clear_ucode_stats_write_9016 il_dbgfs_clear_ucode_stats_write 3 9016 NULL
115397 +snd_emu10k1_ptr_read_9026 snd_emu10k1_ptr_read 0-2 9026 NULL
115398 +nla_put_9042 nla_put 3 9042 NULL
115399 +sta_tx_latency_stat_header_9050 sta_tx_latency_stat_header 0-3-4 9050 NULL
115400 +snd_emu10k1_synth_copy_from_user_9061 snd_emu10k1_synth_copy_from_user 3-5 9061 NULL
115401 +snd_gus_dram_peek_9062 snd_gus_dram_peek 4 9062 NULL
115402 +fib_info_hash_alloc_9075 fib_info_hash_alloc 1 9075 NULL
115403 +create_queues_9088 create_queues 2-3 9088 NULL
115404 +ftdi_prepare_write_buffer_9093 ftdi_prepare_write_buffer 3 9093 NULL
115405 +adxl34x_spi_read_block_9108 adxl34x_spi_read_block 3 9108 NULL
115406 +caif_stream_sendmsg_9110 caif_stream_sendmsg 4 9110 NULL nohasharray
115407 +gfn_to_rmap_9110 gfn_to_rmap 2-3 9110 &caif_stream_sendmsg_9110
115408 +udf_direct_IO_9111 udf_direct_IO 4 9111 NULL
115409 +pmcraid_change_queue_depth_9116 pmcraid_change_queue_depth 2 9116 NULL
115410 +vb2_dma_sg_alloc_9157 vb2_dma_sg_alloc 2 9157 NULL
115411 +dbg_command_buf_9165 dbg_command_buf 2 9165 NULL
115412 +isr_irqs_read_9181 isr_irqs_read 3 9181 NULL
115413 +count_leading_zeros_9183 count_leading_zeros 0 9183 NULL
115414 +altera_swap_ir_9194 altera_swap_ir 2 9194 NULL
115415 +snd_m3_get_pointer_9206 snd_m3_get_pointer 0 9206 NULL
115416 +iwl_dbgfs_frame_stats_read_9211 iwl_dbgfs_frame_stats_read 3 9211 NULL
115417 +virtqueue_add_9217 virtqueue_add 4-5 9217 NULL
115418 +tx_tx_prepared_descs_read_9221 tx_tx_prepared_descs_read 3 9221 NULL
115419 +sctp_getsockopt_delayed_ack_9232 sctp_getsockopt_delayed_ack 2 9232 NULL
115420 +hfsplus_bnode_read_u16_9262 hfsplus_bnode_read_u16 0 9262 NULL
115421 +hdpvr_read_9273 hdpvr_read 3 9273 NULL
115422 +flakey_status_9274 flakey_status 5 9274 NULL
115423 +iwl_dbgfs_stations_read_9309 iwl_dbgfs_stations_read 3 9309 NULL
115424 +ceph_sync_setxattr_9310 ceph_sync_setxattr 4 9310 NULL
115425 +ieee80211_if_fmt_txpower_9334 ieee80211_if_fmt_txpower 3 9334 NULL
115426 +nvme_trans_fmt_get_parm_header_9340 nvme_trans_fmt_get_parm_header 2 9340 NULL
115427 +ocfs2_orphan_for_truncate_9342 ocfs2_orphan_for_truncate 4 9342 NULL
115428 +ll_direct_rw_pages_9361 ll_direct_rw_pages 0 9361 NULL
115429 +sta_beacon_loss_count_read_9370 sta_beacon_loss_count_read 3 9370 NULL
115430 +virtqueue_add_outbuf_9395 virtqueue_add_outbuf 3 9395 NULL
115431 +read_9397 read 3 9397 NULL
115432 +hash_ipportip4_expire_9415 hash_ipportip4_expire 4 9415 NULL
115433 +btrfs_drop_extents_9423 btrfs_drop_extents 4 9423 NULL
115434 +bm_realloc_pages_9431 bm_realloc_pages 2 9431 NULL
115435 +ffs_ep0_write_9438 ffs_ep0_write 3 9438 NULL
115436 +ieee80211_if_fmt_fwded_unicast_9454 ieee80211_if_fmt_fwded_unicast 3 9454 NULL
115437 +get_registers_9470 get_registers 4 9470 NULL nohasharray
115438 +agp_generic_alloc_user_9470 agp_generic_alloc_user 1 9470 &get_registers_9470
115439 +crypt_status_9492 crypt_status 5 9492 NULL
115440 +lbs_threshold_write_9502 lbs_threshold_write 5 9502 NULL
115441 +lp_write_9511 lp_write 3 9511 NULL
115442 +mext_calc_swap_extents_9517 mext_calc_swap_extents 4 9517 NULL
115443 +scsi_tgt_kspace_exec_9522 scsi_tgt_kspace_exec 8 9522 NULL
115444 +ll_max_read_ahead_whole_mb_seq_write_9528 ll_max_read_ahead_whole_mb_seq_write 3 9528 NULL
115445 +read_file_dma_9530 read_file_dma 3 9530 NULL
115446 +iwl_dbgfs_bf_params_read_9542 iwl_dbgfs_bf_params_read 3 9542 NULL
115447 +il_dbgfs_missed_beacon_write_9546 il_dbgfs_missed_beacon_write 3 9546 NULL
115448 +compat_SyS_pwritev64_9548 compat_SyS_pwritev64 3 9548 NULL
115449 +fw_node_create_9559 fw_node_create 2 9559 NULL
115450 +kobj_map_9566 kobj_map 2-3 9566 NULL
115451 +f2fs_read_data_pages_9574 f2fs_read_data_pages 4 9574 NULL
115452 +snd_emu10k1_fx8010_read_9605 snd_emu10k1_fx8010_read 5-6 9605 NULL
115453 +lov_ost_pool_add_9626 lov_ost_pool_add 3 9626 NULL
115454 +saa7164_buffer_alloc_user_9627 saa7164_buffer_alloc_user 2 9627 NULL
115455 +ceph_copy_user_to_page_vector_9635 ceph_copy_user_to_page_vector 4-3 9635 NULL
115456 +acpi_ex_insert_into_field_9638 acpi_ex_insert_into_field 3 9638 NULL
115457 +ll_checksum_seq_write_9648 ll_checksum_seq_write 3 9648 NULL
115458 +ocfs2_xattr_get_rec_9652 ocfs2_xattr_get_rec 0 9652 NULL
115459 +queue_received_packet_9657 queue_received_packet 5 9657 NULL
115460 +tipc_port_mcast_xmit_9663 tipc_port_mcast_xmit 4 9663 NULL
115461 +snd_opl4_mem_proc_write_9670 snd_opl4_mem_proc_write 5 9670 NULL
115462 +dns_query_9676 dns_query 3 9676 NULL
115463 +qib_7322_handle_hwerrors_9678 qib_7322_handle_hwerrors 3 9678 NULL
115464 +__erst_read_from_storage_9690 __erst_read_from_storage 0 9690 NULL
115465 +vx_transfer_end_9701 vx_transfer_end 0 9701 NULL
115466 +fuse_iter_npages_9705 fuse_iter_npages 0 9705 NULL nohasharray
115467 +ieee80211_if_read_aid_9705 ieee80211_if_read_aid 3 9705 &fuse_iter_npages_9705
115468 +cfg80211_tx_mlme_mgmt_9715 cfg80211_tx_mlme_mgmt 3 9715 NULL
115469 +parse_uac2_sample_rate_range_9718 parse_uac2_sample_rate_range 0 9718 NULL
115470 +btrfs_stack_file_extent_num_bytes_9720 btrfs_stack_file_extent_num_bytes 0 9720 NULL
115471 +SYSC_ppoll_9721 SYSC_ppoll 2 9721 NULL
115472 +nla_get_u8_9736 nla_get_u8 0 9736 NULL
115473 +ieee80211_if_fmt_num_mcast_sta_9738 ieee80211_if_fmt_num_mcast_sta 3 9738 NULL
115474 +ddb_input_read_9743 ddb_input_read 3-0 9743 NULL
115475 +regmap_multi_reg_write_bypassed_9751 regmap_multi_reg_write_bypassed 3 9751 NULL nohasharray
115476 +sta_last_ack_signal_read_9751 sta_last_ack_signal_read 3 9751 &regmap_multi_reg_write_bypassed_9751
115477 +btrfs_super_root_9763 btrfs_super_root 0 9763 NULL
115478 +__blk_queue_init_tags_9778 __blk_queue_init_tags 2 9778 NULL
115479 +kvm_age_hva_9795 kvm_age_hva 2 9795 NULL
115480 +udpv6_recvmsg_9813 udpv6_recvmsg 4 9813 NULL nohasharray
115481 +ieee80211_if_read_state_9813 ieee80211_if_read_state 3 9813 &udpv6_recvmsg_9813
115482 +pmcraid_alloc_sglist_9864 pmcraid_alloc_sglist 1 9864 NULL
115483 +btrfs_free_reserved_extent_9867 btrfs_free_reserved_extent 2 9867 NULL
115484 +wil_read_file_ioblob_9878 wil_read_file_ioblob 3 9878 NULL
115485 +snd_midi_event_new_9893 snd_midi_event_new 1 9893 NULL nohasharray
115486 +bm_register_write_9893 bm_register_write 3 9893 &snd_midi_event_new_9893
115487 +snd_gf1_pcm_playback_copy_9895 snd_gf1_pcm_playback_copy 3-5 9895 NULL
115488 +nonpaging_page_fault_9908 nonpaging_page_fault 2 9908 NULL
115489 +iwl_dbgfs_prph_reg_read_9928 iwl_dbgfs_prph_reg_read 3 9928 NULL
115490 +root_nfs_parse_options_9937 root_nfs_parse_options 3 9937 NULL
115491 +pstore_ftrace_knob_read_9947 pstore_ftrace_knob_read 3 9947 NULL
115492 +read_file_misc_9948 read_file_misc 3 9948 NULL
115493 +csum_partial_copy_fromiovecend_9957 csum_partial_copy_fromiovecend 3-4 9957 NULL
115494 +SyS_gethostname_9964 SyS_gethostname 2 9964 NULL
115495 +get_free_serial_index_9969 get_free_serial_index 0 9969 NULL
115496 +btrfs_add_link_9973 btrfs_add_link 5 9973 NULL
115497 +SYSC_move_pages_9986 SYSC_move_pages 2 9986 NULL
115498 +aat2870_dump_reg_10019 aat2870_dump_reg 0 10019 NULL
115499 +ieee80211_set_probe_resp_10077 ieee80211_set_probe_resp 3 10077 NULL
115500 +get_elem_size_10110 get_elem_size 0-2 10110 NULL nohasharray
115501 +dynamic_ps_timeout_read_10110 dynamic_ps_timeout_read 3 10110 &get_elem_size_10110
115502 +gfs2_meta_read_10112 gfs2_meta_read 0 10112 NULL
115503 +SyS_migrate_pages_10134 SyS_migrate_pages 2 10134 NULL
115504 +aes_decrypt_packets_read_10155 aes_decrypt_packets_read 3 10155 NULL
115505 +rx_out_of_mem_read_10157 rx_out_of_mem_read 3 10157 NULL
115506 +hidg_alloc_ep_req_10159 hidg_alloc_ep_req 2 10159 NULL
115507 +asd_store_update_bios_10165 asd_store_update_bios 4 10165 NULL
115508 +kstrtol_from_user_10168 kstrtol_from_user 2 10168 NULL
115509 +proc_pid_attr_read_10173 proc_pid_attr_read 3 10173 NULL
115510 +jffs2_user_setxattr_10182 jffs2_user_setxattr 4 10182 NULL
115511 +cciss_proc_write_10259 cciss_proc_write 3 10259 NULL
115512 +__qlcnic_pci_sriov_enable_10281 __qlcnic_pci_sriov_enable 2 10281 NULL
115513 +snd_rme9652_capture_copy_10287 snd_rme9652_capture_copy 5 10287 NULL
115514 +ubi_leb_change_10289 ubi_leb_change 0 10289 NULL
115515 +read_emulate_10310 read_emulate 2-4 10310 NULL
115516 +read_file_spectral_count_10320 read_file_spectral_count 3 10320 NULL
115517 +compat_SyS_writev_10327 compat_SyS_writev 3 10327 NULL
115518 +tun_sendmsg_10337 tun_sendmsg 4 10337 NULL
115519 +ufx_alloc_urb_list_10349 ufx_alloc_urb_list 3 10349 NULL
115520 +dbAllocAny_10354 dbAllocAny 0 10354 NULL
115521 +ath6kl_listen_int_read_10355 ath6kl_listen_int_read 3 10355 NULL
115522 +ms_write_multiple_pages_10362 ms_write_multiple_pages 6-5 10362 NULL
115523 +sta_ht_capa_read_10366 sta_ht_capa_read 3 10366 NULL
115524 +ecryptfs_decode_and_decrypt_filename_10379 ecryptfs_decode_and_decrypt_filename 5 10379 NULL
115525 +led_classdev_register_10384 led_classdev_register 0 10384 NULL
115526 +do_compat_pselect_10398 do_compat_pselect 1 10398 NULL
115527 +fwtty_rx_10434 fwtty_rx 3 10434 NULL
115528 +event_phy_transmit_error_read_10471 event_phy_transmit_error_read 3 10471 NULL
115529 +hash_ipportip6_expire_10478 hash_ipportip6_expire 4 10478 NULL
115530 +nouveau_pwr_create__10483 nouveau_pwr_create_ 4 10483 NULL
115531 +ext4_itable_unused_count_10501 ext4_itable_unused_count 0 10501 NULL
115532 +qib_alloc_fast_reg_page_list_10507 qib_alloc_fast_reg_page_list 2 10507 NULL
115533 +sel_write_disable_10511 sel_write_disable 3 10511 NULL
115534 +osd_req_write_sg_kern_10514 osd_req_write_sg_kern 5 10514 NULL
115535 +rds_message_alloc_10517 rds_message_alloc 1 10517 NULL
115536 +qlcnic_pci_sriov_enable_10519 qlcnic_pci_sriov_enable 2 10519 NULL
115537 +snd_pcm_hw_params_user_10520 snd_pcm_hw_params_user 0 10520 NULL
115538 +kstrtouint_from_user_10536 kstrtouint_from_user 2 10536 NULL nohasharray
115539 +snd_pcm_lib_read_10536 snd_pcm_lib_read 0-3 10536 &kstrtouint_from_user_10536
115540 +ext4_write_begin_10576 ext4_write_begin 3-4 10576 NULL
115541 +scrub_remap_extent_10588 scrub_remap_extent 2 10588 NULL
115542 +otp_read_10594 otp_read 2-4-5 10594 NULL
115543 +supply_map_read_file_10608 supply_map_read_file 3 10608 NULL
115544 +ima_show_htable_violations_10619 ima_show_htable_violations 3 10619 NULL
115545 +fq_alloc_node_10633 fq_alloc_node 1 10633 NULL
115546 +nfs_idmap_lookup_id_10660 nfs_idmap_lookup_id 2 10660 NULL nohasharray
115547 +ubi_io_write_vid_hdr_10660 ubi_io_write_vid_hdr 0 10660 &nfs_idmap_lookup_id_10660
115548 +efx_max_tx_len_10662 efx_max_tx_len 0-2 10662 NULL
115549 +parport_write_10669 parport_write 0 10669 NULL
115550 +edge_write_10692 edge_write 4 10692 NULL
115551 +ubi_wl_get_peb_10699 ubi_wl_get_peb 0 10699 NULL
115552 +selinux_inode_setxattr_10708 selinux_inode_setxattr 4 10708 NULL nohasharray
115553 +inl_10708 inl 0 10708 &selinux_inode_setxattr_10708
115554 +shash_async_setkey_10720 shash_async_setkey 3 10720 NULL nohasharray
115555 +pvr2_ioread_read_10720 pvr2_ioread_read 3 10720 &shash_async_setkey_10720
115556 +spi_sync_10731 spi_sync 0 10731 NULL
115557 +sctp_getsockopt_maxseg_10737 sctp_getsockopt_maxseg 2 10737 NULL nohasharray
115558 +apu_get_register_10737 apu_get_register 0 10737 &sctp_getsockopt_maxseg_10737
115559 +SyS_io_getevents_10756 SyS_io_getevents 3 10756 NULL
115560 +vhost_add_used_n_10760 vhost_add_used_n 3 10760 NULL
115561 +rd_build_prot_space_10761 rd_build_prot_space 2-3 10761 NULL
115562 +kvm_read_guest_atomic_10765 kvm_read_guest_atomic 4 10765 NULL
115563 +__qp_memcpy_to_queue_10779 __qp_memcpy_to_queue 2-4 10779 NULL
115564 +diva_set_trace_filter_10820 diva_set_trace_filter 0-1 10820 NULL
115565 +lbs_sleepparams_read_10840 lbs_sleepparams_read 3 10840 NULL
115566 +ida_get_new_above_10853 ida_get_new_above 0 10853 NULL
115567 +fuse_conn_max_background_read_10855 fuse_conn_max_background_read 3 10855 NULL
115568 +snd_pcm_oss_write1_10872 snd_pcm_oss_write1 3 10872 NULL
115569 +wiidebug_drm_write_10879 wiidebug_drm_write 3 10879 NULL
115570 +get_scq_10897 get_scq 2 10897 NULL
115571 +tifm_alloc_adapter_10903 tifm_alloc_adapter 1 10903 NULL
115572 +lprocfs_wr_atomic_10912 lprocfs_wr_atomic 3 10912 NULL
115573 +__copy_from_user_10918 __copy_from_user 0-3 10918 NULL
115574 +kobject_add_10919 kobject_add 0 10919 NULL
115575 +ar9003_dump_modal_eeprom_10959 ar9003_dump_modal_eeprom 3-2-0 10959 NULL
115576 +ci_port_test_write_10962 ci_port_test_write 3 10962 NULL
115577 +bm_entry_read_10976 bm_entry_read 3 10976 NULL
115578 +sched_autogroup_write_10984 sched_autogroup_write 3 10984 NULL
115579 +xfrm_hash_alloc_10997 xfrm_hash_alloc 1 10997 NULL
115580 +rx_filter_accum_arp_pend_requests_read_11003 rx_filter_accum_arp_pend_requests_read 3 11003 NULL
115581 +SetLineNumber_11023 SetLineNumber 0 11023 NULL
115582 +pci_msi_vec_count_11046 pci_msi_vec_count 0 11046 NULL
115583 +tda10048_writeregbulk_11050 tda10048_writeregbulk 4 11050 NULL
115584 +qlcnic_83xx_calculate_msix_vector_11063 qlcnic_83xx_calculate_msix_vector 0 11063 NULL nohasharray
115585 +insert_inline_extent_backref_11063 insert_inline_extent_backref 8 11063 &qlcnic_83xx_calculate_msix_vector_11063
115586 +tcp_send_mss_11079 tcp_send_mss 0 11079 NULL
115587 +snd_pcm_delay_11081 snd_pcm_delay 0 11081 NULL
115588 +count_argc_11083 count_argc 0 11083 NULL
115589 +kvm_write_guest_cached_11106 kvm_write_guest_cached 4 11106 NULL
115590 +tw_change_queue_depth_11116 tw_change_queue_depth 2 11116 NULL
115591 +page_offset_11120 page_offset 0 11120 NULL
115592 +cea_db_payload_len_11124 cea_db_payload_len 0 11124 NULL nohasharray
115593 +tracing_buffers_read_11124 tracing_buffers_read 3 11124 &cea_db_payload_len_11124
115594 +snd_gf1_pcm_playback_silence_11172 snd_gf1_pcm_playback_silence 3-4 11172 NULL
115595 +il_dbgfs_rx_queue_read_11221 il_dbgfs_rx_queue_read 3 11221 NULL
115596 +comedi_alloc_spriv_11234 comedi_alloc_spriv 2 11234 NULL
115597 +of_irq_count_11253 of_irq_count 0 11253 NULL
115598 +hugetlbfs_read_11268 hugetlbfs_read 3 11268 NULL
115599 +ath6kl_power_params_write_11274 ath6kl_power_params_write 3 11274 NULL
115600 +__proc_daemon_file_11305 __proc_daemon_file 5 11305 NULL
115601 +ext4_xattr_check_names_11314 ext4_xattr_check_names 0 11314 NULL
115602 +bcache_dev_sectors_dirty_add_11315 bcache_dev_sectors_dirty_add 3-4 11315 NULL
115603 +sk_filter_size_11316 sk_filter_size 0 11316 NULL nohasharray
115604 +tcp_send_rcvq_11316 tcp_send_rcvq 3 11316 &sk_filter_size_11316
115605 +construct_key_11329 construct_key 3 11329 NULL nohasharray
115606 +__kfifo_out_peek_11329 __kfifo_out_peek 0-3 11329 &construct_key_11329
115607 +next_segment_11330 next_segment 0-2-1 11330 NULL
115608 +persistent_ram_buffer_map_11332 persistent_ram_buffer_map 1-2 11332 NULL
115609 +ext4_get_inline_size_11349 ext4_get_inline_size 0 11349 NULL
115610 +sel_write_create_11353 sel_write_create 3 11353 NULL nohasharray
115611 +nl80211_send_mgmt_11353 nl80211_send_mgmt 7 11353 &sel_write_create_11353
115612 +of_get_available_child_count_11361 of_get_available_child_count 0 11361 NULL
115613 +qib_get_base_info_11369 qib_get_base_info 3 11369 NULL
115614 +tcf_register_action_11381 tcf_register_action 2 11381 NULL nohasharray
115615 +nft_value_dump_11381 nft_value_dump 3 11381 &tcf_register_action_11381
115616 +isku_sysfs_read_keys_capslock_11392 isku_sysfs_read_keys_capslock 6 11392 NULL
115617 +dev_irnet_write_11398 dev_irnet_write 3 11398 NULL
115618 +lprocfs_wr_evict_client_11402 lprocfs_wr_evict_client 3 11402 NULL
115619 +___alloc_bootmem_11410 ___alloc_bootmem 1 11410 NULL
115620 +str_to_user_11411 str_to_user 2 11411 NULL
115621 +mem_fw_gen_free_mem_blks_read_11413 mem_fw_gen_free_mem_blks_read 3 11413 NULL
115622 +ath6kl_wmi_test_rx_11414 ath6kl_wmi_test_rx 3 11414 NULL
115623 +adis16480_show_firmware_revision_11417 adis16480_show_firmware_revision 3 11417 NULL
115624 +trace_options_read_11419 trace_options_read 3 11419 NULL
115625 +i40e_dbg_command_write_11421 i40e_dbg_command_write 3 11421 NULL
115626 +xd_read_multiple_pages_11422 xd_read_multiple_pages 5-4 11422 NULL
115627 +bttv_read_11432 bttv_read 3 11432 NULL
115628 +create_zero_mask_11453 create_zero_mask 0-1 11453 NULL
115629 +do_blockdev_direct_IO_11455 do_blockdev_direct_IO 0-6 11455 NULL
115630 +sca3000_read_first_n_hw_rb_11479 sca3000_read_first_n_hw_rb 2 11479 NULL nohasharray
115631 +pci_set_power_state_11479 pci_set_power_state 0 11479 &sca3000_read_first_n_hw_rb_11479
115632 +xfs_file_buffered_aio_write_11492 xfs_file_buffered_aio_write 4 11492 NULL
115633 +sd_do_mode_sense_11507 sd_do_mode_sense 5 11507 NULL
115634 +kmem_zalloc_11510 kmem_zalloc 1 11510 NULL
115635 +ll_direct_IO_26_seg_11518 ll_direct_IO_26_seg 0 11518 NULL
115636 +twl_direction_in_11527 twl_direction_in 2 11527 NULL
115637 +skb_cow_data_11565 skb_cow_data 0 11565 NULL
115638 +lpfc_idiag_ctlacc_write_11576 lpfc_idiag_ctlacc_write 3 11576 NULL
115639 +oprofilefs_ulong_to_user_11582 oprofilefs_ulong_to_user 3 11582 NULL
115640 +batadv_iv_ogm_orig_add_if_11586 batadv_iv_ogm_orig_add_if 2 11586 NULL
115641 +snd_pcm_action_11589 snd_pcm_action 0 11589 NULL
115642 +fw_device_op_ioctl_11595 fw_device_op_ioctl 2 11595 NULL
115643 +batadv_iv_ogm_orig_del_if_11604 batadv_iv_ogm_orig_del_if 2 11604 NULL
115644 +SYSC_mq_timedsend_11607 SYSC_mq_timedsend 3 11607 NULL
115645 +C_SYSC_migrate_pages_11618 C_SYSC_migrate_pages 2 11618 NULL
115646 +sisusb_send_bridge_packet_11649 sisusb_send_bridge_packet 2 11649 NULL
115647 +nla_total_size_11658 nla_total_size 1-0 11658 NULL
115648 +slab_ksize_11664 slab_ksize 0 11664 NULL
115649 +ide_queue_pc_tail_11673 ide_queue_pc_tail 5 11673 NULL
115650 +compat_SyS_msgsnd_11675 compat_SyS_msgsnd 3 11675 NULL
115651 +btrfs_alloc_delayed_item_11678 btrfs_alloc_delayed_item 1 11678 NULL
115652 +sctp_setsockopt_hmac_ident_11687 sctp_setsockopt_hmac_ident 3 11687 NULL
115653 +split_11691 split 2 11691 NULL
115654 +compat_SyS_keyctl_11695 compat_SyS_keyctl 4 11695 NULL nohasharray
115655 +snd_ctl_elem_user_tlv_11695 snd_ctl_elem_user_tlv 3 11695 &compat_SyS_keyctl_11695
115656 +blk_rq_cur_bytes_11723 blk_rq_cur_bytes 0 11723 NULL
115657 +dm_bio_prison_create_11749 dm_bio_prison_create 1 11749 NULL
115658 +iwl_dbgfs_qos_read_11753 iwl_dbgfs_qos_read 3 11753 NULL
115659 +ieee80211_get_num_supported_channels_11768 ieee80211_get_num_supported_channels 0 11768 NULL
115660 +tipc_sendmsg_11769 tipc_sendmsg 4 11769 NULL
115661 +ps_pspoll_timeouts_read_11776 ps_pspoll_timeouts_read 3 11776 NULL
115662 +btrfs_key_blockptr_11786 btrfs_key_blockptr 0 11786 NULL
115663 +pcpu_fc_alloc_11818 pcpu_fc_alloc 2 11818 NULL
115664 +zerocopy_sg_from_iovec_11828 zerocopy_sg_from_iovec 3 11828 NULL
115665 +sctp_setsockopt_maxseg_11829 sctp_setsockopt_maxseg 3 11829 NULL
115666 +rts51x_read_status_11830 rts51x_read_status 4 11830 NULL
115667 +unix_stream_connect_11844 unix_stream_connect 3 11844 NULL
115668 +pci_enable_msix_range_11852 pci_enable_msix_range 0-4 11852 NULL
115669 +ecryptfs_copy_filename_11868 ecryptfs_copy_filename 4 11868 NULL
115670 +ieee80211_rx_bss_info_11887 ieee80211_rx_bss_info 3 11887 NULL
115671 +mdc_rename_11899 mdc_rename 4-6 11899 NULL
115672 +xstateregs_get_11906 xstateregs_get 4 11906 NULL
115673 +ti_write_11916 ti_write 4 11916 NULL
115674 +fs_devrw_entry_11924 fs_devrw_entry 3 11924 NULL
115675 +atomic_sub_return_11939 atomic_sub_return 0-1 11939 NULL
115676 +r1_sync_page_io_11963 r1_sync_page_io 3 11963 NULL
115677 +read_and_add_raw_conns_11987 read_and_add_raw_conns 0 11987 NULL
115678 +ftdi_elan_total_command_size_12045 ftdi_elan_total_command_size 0 12045 NULL
115679 +ieee80211_if_read_user_power_level_12050 ieee80211_if_read_user_power_level 3 12050 NULL
115680 +il4965_ucode_tx_stats_read_12064 il4965_ucode_tx_stats_read 3 12064 NULL
115681 +ptc_proc_write_12076 ptc_proc_write 3 12076 NULL
115682 +batadv_tt_global_size_mod_12085 batadv_tt_global_size_mod 3 12085 NULL
115683 +rtw_malloc2d_12102 rtw_malloc2d 1-2-3 12102 NULL
115684 +alloc_bulk_urbs_generic_12127 alloc_bulk_urbs_generic 5 12127 NULL
115685 +set_powered_12129 set_powered 4 12129 NULL
115686 +ramoops_init_prz_12134 ramoops_init_prz 5 12134 NULL
115687 +xfs_handle_to_dentry_12135 xfs_handle_to_dentry 3 12135 NULL
115688 +rawv6_seticmpfilter_12137 rawv6_seticmpfilter 5 12137 NULL
115689 +rawsock_recvmsg_12144 rawsock_recvmsg 4 12144 NULL
115690 +get_idx_gc_leb_12148 get_idx_gc_leb 0 12148 NULL
115691 +btmrvl_sdio_host_to_card_12152 btmrvl_sdio_host_to_card 3 12152 NULL
115692 +vmbus_open_12154 vmbus_open 2-3 12154 NULL
115693 +fnic_reset_stats_write_12177 fnic_reset_stats_write 3 12177 NULL
115694 +LNetEQAlloc_12178 LNetEQAlloc 1 12178 NULL
115695 +ddp_make_gl_12179 ddp_make_gl 1 12179 NULL
115696 +compat_do_arpt_set_ctl_12184 compat_do_arpt_set_ctl 4 12184 NULL
115697 +ip_generic_getfrag_12187 ip_generic_getfrag 3-4 12187 NULL
115698 +snd_pcm_kernel_ioctl_12219 snd_pcm_kernel_ioctl 0 12219 NULL
115699 +fuse_get_req_12221 fuse_get_req 2 12221 NULL nohasharray
115700 +aat2870_reg_read_file_12221 aat2870_reg_read_file 3 12221 &fuse_get_req_12221
115701 +__alloc_bootmem_low_nopanic_12235 __alloc_bootmem_low_nopanic 1 12235 NULL
115702 +usnic_ib_qp_grp_dump_rows_12239 usnic_ib_qp_grp_dump_rows 3 12239 NULL
115703 +ib_uverbs_unmarshall_recv_12251 ib_uverbs_unmarshall_recv 5 12251 NULL
115704 +shash_compat_setkey_12267 shash_compat_setkey 3 12267 NULL
115705 +add_sctp_bind_addr_12269 add_sctp_bind_addr 3 12269 NULL
115706 +SYSC_vm86_12279 SYSC_vm86 2 12279 NULL
115707 +note_last_dentry_12285 note_last_dentry 3 12285 NULL
115708 +roundup_to_multiple_of_64_12288 roundup_to_multiple_of_64 0-1 12288 NULL nohasharray
115709 +il_dbgfs_nvm_read_12288 il_dbgfs_nvm_read 3 12288 &roundup_to_multiple_of_64_12288
115710 +bt_sock_recvmsg_12316 bt_sock_recvmsg 4 12316 NULL
115711 +usnic_transport_sock_to_str_12322 usnic_transport_sock_to_str 2-0 12322 NULL
115712 +pcbit_writecmd_12332 pcbit_writecmd 2 12332 NULL
115713 +mptctl_ioctl_12355 mptctl_ioctl 2 12355 NULL
115714 +__nf_ct_ext_add_length_12364 __nf_ct_ext_add_length 3 12364 NULL
115715 +xfs_iext_inline_to_direct_12384 xfs_iext_inline_to_direct 2 12384 NULL
115716 +write_file_dump_12391 write_file_dump 3 12391 NULL nohasharray
115717 +populate_dir_12391 populate_dir 0 12391 &write_file_dump_12391
115718 +hbucket_elem_add_12416 hbucket_elem_add 3 12416 NULL
115719 +ieee80211_if_read_num_mcast_sta_12419 ieee80211_if_read_num_mcast_sta 3 12419 NULL
115720 +cfs_array_alloc_12441 cfs_array_alloc 2 12441 NULL
115721 +skb_do_copy_data_nocache_12465 skb_do_copy_data_nocache 5 12465 NULL
115722 +x25_sendmsg_12487 x25_sendmsg 4 12487 NULL
115723 +fnic_trace_ctrl_read_12497 fnic_trace_ctrl_read 3 12497 NULL
115724 +qib_alloc_fast_reg_mr_12526 qib_alloc_fast_reg_mr 2 12526 NULL
115725 +write_inode_now_12565 write_inode_now 0 12565 NULL
115726 +hvc_alloc_12579 hvc_alloc 4 12579 NULL
115727 +pcpu_extend_area_map_12589 pcpu_extend_area_map 2 12589 NULL
115728 +_iwl_dbgfs_prph_reg_write_12597 _iwl_dbgfs_prph_reg_write 3 12597 NULL
115729 +tlbflush_write_file_12598 tlbflush_write_file 3 12598 NULL
115730 +vhci_put_user_12604 vhci_put_user 4 12604 NULL
115731 +sdhci_pltfm_init_12627 sdhci_pltfm_init 3 12627 NULL
115732 +pwr_rcvd_awake_bcns_cnt_read_12632 pwr_rcvd_awake_bcns_cnt_read 3 12632 NULL
115733 +pn_sendmsg_12640 pn_sendmsg 4 12640 NULL
115734 +dwc3_link_state_write_12641 dwc3_link_state_write 3 12641 NULL
115735 +nr_recvmsg_12649 nr_recvmsg 4 12649 NULL
115736 +rtw_android_get_link_speed_12655 rtw_android_get_link_speed 0 12655 NULL
115737 +ocfs2_read_block_12659 ocfs2_read_block 0 12659 NULL
115738 +sel_read_class_12669 sel_read_class 3 12669 NULL nohasharray
115739 +sparse_mem_maps_populate_node_12669 sparse_mem_maps_populate_node 4 12669 &sel_read_class_12669
115740 +ext4_writepage_trans_blocks_12674 ext4_writepage_trans_blocks 0 12674 NULL
115741 +iwl_dbgfs_calib_disabled_write_12707 iwl_dbgfs_calib_disabled_write 3 12707 NULL
115742 +ieee80211_if_read_num_buffered_multicast_12716 ieee80211_if_read_num_buffered_multicast 3 12716 NULL
115743 +ivtv_write_12721 ivtv_write 3 12721 NULL
115744 +key_rx_spec_read_12736 key_rx_spec_read 3 12736 NULL
115745 +__mei_cl_async_send_12737 __mei_cl_async_send 3 12737 NULL
115746 +ieee80211_if_read_dot11MeshMaxRetries_12756 ieee80211_if_read_dot11MeshMaxRetries 3 12756 NULL
115747 +listxattr_12769 listxattr 3 12769 NULL
115748 +sctp_ssnmap_init_12772 sctp_ssnmap_init 3-2 12772 NULL
115749 +scsi_adjust_queue_depth_12802 scsi_adjust_queue_depth 3 12802 NULL
115750 +xfs_inumbers_fmt_12817 xfs_inumbers_fmt 3 12817 NULL
115751 +SyS_add_key_12834 SyS_add_key 4 12834 NULL
115752 +TSS_authhmac_12839 TSS_authhmac 3 12839 NULL
115753 +spidev_sync_12842 spidev_sync 0 12842 NULL
115754 +spidev_ioctl_12846 spidev_ioctl 2 12846 NULL
115755 +ath9k_dump_4k_modal_eeprom_12883 ath9k_dump_4k_modal_eeprom 3-2 12883 NULL
115756 +get_leb_cnt_12892 get_leb_cnt 0-2 12892 NULL
115757 +get_virtual_node_size_12908 get_virtual_node_size 0 12908 NULL
115758 +rds_pages_in_vec_12922 rds_pages_in_vec 0 12922 NULL
115759 +do_inode_permission_12946 do_inode_permission 0 12946 NULL
115760 +bm_status_write_12964 bm_status_write 3 12964 NULL
115761 +raid56_parity_recover_12987 raid56_parity_recover 5 12987 NULL
115762 +TransmitTcb_12989 TransmitTcb 4 12989 NULL
115763 +sk_peek_offset_12991 sk_peek_offset 0 12991 NULL
115764 +__btrfs_direct_write_13007 __btrfs_direct_write 4-0 13007 NULL
115765 +bset_prev_bytes_13020 bset_prev_bytes 0 13020 NULL
115766 +subsystem_filter_write_13022 subsystem_filter_write 3 13022 NULL
115767 +generic_segment_checks_13041 generic_segment_checks 0 13041 NULL
115768 +ocfs2_write_begin_13045 ocfs2_write_begin 3-4 13045 NULL
115769 +__dn_setsockopt_13060 __dn_setsockopt 5 13060 NULL nohasharray
115770 +ptlrpc_lprocfs_threads_min_seq_write_13060 ptlrpc_lprocfs_threads_min_seq_write 3 13060 &__dn_setsockopt_13060
115771 +biovec_create_pool_13079 biovec_create_pool 2 13079 NULL
115772 +xattr_getsecurity_13090 xattr_getsecurity 0 13090 NULL
115773 +ttm_dma_pool_alloc_new_pages_13105 ttm_dma_pool_alloc_new_pages 3 13105 NULL
115774 +snd_rme96_playback_copy_13111 snd_rme96_playback_copy 5 13111 NULL
115775 +bfad_debugfs_read_13119 bfad_debugfs_read 3 13119 NULL
115776 +blk_update_request_13146 blk_update_request 3 13146 NULL
115777 +caif_stream_recvmsg_13173 caif_stream_recvmsg 4 13173 NULL
115778 +pwr_disable_ps_read_13176 pwr_disable_ps_read 3 13176 NULL
115779 +ucs2_strlen_13178 ucs2_strlen 0 13178 NULL
115780 +dgrp_net_ioctl_13183 dgrp_net_ioctl 2 13183 NULL
115781 +create_trace_uprobe_13184 create_trace_uprobe 1 13184 NULL
115782 +comedi_read_13199 comedi_read 3 13199 NULL
115783 +hash_ipport4_expire_13201 hash_ipport4_expire 4 13201 NULL
115784 +mmc_ext_csd_read_13205 mmc_ext_csd_read 3 13205 NULL
115785 +svm_msrpm_offset_13220 svm_msrpm_offset 0-1 13220 NULL
115786 +fnic_trace_ctrl_write_13229 fnic_trace_ctrl_write 3 13229 NULL
115787 +_iwl_dbgfs_disable_power_off_write_13243 _iwl_dbgfs_disable_power_off_write 3 13243 NULL
115788 +asix_read_cmd_13245 asix_read_cmd 5 13245 NULL
115789 +init_tid_tabs_13252 init_tid_tabs 2-3-4 13252 NULL
115790 +bio_integrity_trim_13259 bio_integrity_trim 3-2 13259 NULL
115791 +simple_attr_write_13260 simple_attr_write 3 13260 NULL
115792 +pmcraid_notify_aen_13274 pmcraid_notify_aen 3 13274 NULL
115793 +il4965_stats_flag_13281 il4965_stats_flag 0-3 13281 NULL
115794 +lpfc_idiag_mbxacc_get_setup_13282 lpfc_idiag_mbxacc_get_setup 0 13282 NULL
115795 +sd_major_13294 sd_major 0-1 13294 NULL
115796 +read_file_phy_err_13318 read_file_phy_err 3 13318 NULL
115797 +kvm_read_nested_guest_page_13337 kvm_read_nested_guest_page 5 13337 NULL
115798 +round_event_name_len_13348 round_event_name_len 0 13348 NULL
115799 +iso_sched_alloc_13377 iso_sched_alloc 1 13377 NULL nohasharray
115800 +wep_key_not_found_read_13377 wep_key_not_found_read 3 13377 &iso_sched_alloc_13377
115801 +ext4_meta_trans_blocks_13380 ext4_meta_trans_blocks 0-3-2 13380 NULL
115802 +lov_mds_md_size_13388 lov_mds_md_size 0-1 13388 NULL nohasharray
115803 +dis_bypass_write_13388 dis_bypass_write 3 13388 &lov_mds_md_size_13388
115804 +netxen_alloc_sds_rings_13417 netxen_alloc_sds_rings 2 13417 NULL
115805 +sctp_setsockopt_peer_primary_addr_13440 sctp_setsockopt_peer_primary_addr 3 13440 NULL
115806 +ath6kl_cfg80211_connect_event_13443 ath6kl_cfg80211_connect_event 7-8-9 13443 NULL
115807 +sb_init_dio_done_wq_13482 sb_init_dio_done_wq 0 13482 NULL
115808 +data_read_13494 data_read 3 13494 NULL
115809 +core_status_13515 core_status 4 13515 NULL
115810 +smk_write_mapped_13519 smk_write_mapped 3 13519 NULL
115811 +bm_init_13529 bm_init 2 13529 NULL
115812 +request_any_context_irq_13530 request_any_context_irq 0 13530 NULL
115813 +llcp_sock_recvmsg_13556 llcp_sock_recvmsg 4 13556 NULL
115814 +SyS_vm86_13557 SyS_vm86 2 13557 NULL
115815 +ieee80211_if_read_ap_power_level_13558 ieee80211_if_read_ap_power_level 3 13558 NULL
115816 +hash_net4_expire_13559 hash_net4_expire 4 13559 NULL
115817 +ubifs_get_idx_gc_leb_13566 ubifs_get_idx_gc_leb 0 13566 NULL
115818 +read_file_antenna_13574 read_file_antenna 3 13574 NULL
115819 +cache_write_13589 cache_write 3 13589 NULL
115820 +Rd_Indx_13602 Rd_Indx 3-2 13602 NULL
115821 +wm8994_bulk_write_13615 wm8994_bulk_write 2-3 13615 NULL
115822 +pmcraid_get_minor_13619 pmcraid_get_minor 0 13619 NULL
115823 +packet_snd_13634 packet_snd 3 13634 NULL
115824 +blk_msg_write_13655 blk_msg_write 3 13655 NULL
115825 +cache_downcall_13666 cache_downcall 3 13666 NULL
115826 +ext3_xattr_list_entries_13682 ext3_xattr_list_entries 0 13682 NULL
115827 +fw_iso_buffer_alloc_13704 fw_iso_buffer_alloc 2 13704 NULL
115828 +audit_unpack_string_13748 audit_unpack_string 3 13748 NULL
115829 +ieee802154_alloc_device_13767 ieee802154_alloc_device 1 13767 NULL
115830 +fb_sys_read_13778 fb_sys_read 3 13778 NULL
115831 +ath6kl_mgmt_powersave_ap_13791 ath6kl_mgmt_powersave_ap 6 13791 NULL
115832 +random_read_13815 random_read 3 13815 NULL
115833 +mutex_lock_interruptible_nested_13817 mutex_lock_interruptible_nested 0 13817 NULL
115834 +hsi_register_board_info_13820 hsi_register_board_info 2 13820 NULL
115835 +___mei_cl_send_13821 ___mei_cl_send 3 13821 NULL
115836 +enc_pools_insert_13849 enc_pools_insert 3 13849 NULL
115837 +evdev_ioctl_compat_13851 evdev_ioctl_compat 2 13851 NULL
115838 +compat_ip_setsockopt_13870 compat_ip_setsockopt 5 13870 NULL
115839 +qp_memcpy_to_queue_13886 qp_memcpy_to_queue 5-2 13886 NULL
115840 +snd_pcm_aio_read_13900 snd_pcm_aio_read 3 13900 NULL
115841 +cfg80211_inform_bss_width_13933 cfg80211_inform_bss_width 9 13933 NULL
115842 +ext3_xattr_block_get_13936 ext3_xattr_block_get 0 13936 NULL
115843 +ieee80211_if_read_dot11MeshForwarding_13940 ieee80211_if_read_dot11MeshForwarding 3 13940 NULL nohasharray
115844 +ocfs2_xa_value_truncate_13940 ocfs2_xa_value_truncate 2 13940 &ieee80211_if_read_dot11MeshForwarding_13940
115845 +iwl_dbgfs_protection_mode_read_13943 iwl_dbgfs_protection_mode_read 3 13943 NULL
115846 +ieee80211_if_read_min_discovery_timeout_13946 ieee80211_if_read_min_discovery_timeout 3 13946 NULL
115847 +lpfc_idiag_queacc_read_13950 lpfc_idiag_queacc_read 3 13950 NULL nohasharray
115848 +pagecache_write_end_13950 pagecache_write_end 0 13950 &lpfc_idiag_queacc_read_13950
115849 +osc_grant_shrink_interval_seq_write_13952 osc_grant_shrink_interval_seq_write 3 13952 NULL
115850 +snd_pcm_plug_slave_size_13967 snd_pcm_plug_slave_size 0-2 13967 NULL
115851 +qcam_read_13977 qcam_read 3 13977 NULL
115852 +dsp_read_13980 dsp_read 2 13980 NULL
115853 +dvb_demux_read_13981 dvb_demux_read 3 13981 NULL
115854 +sddr09_write_data_14014 sddr09_write_data 3 14014 NULL
115855 +btrfs_get_blocks_direct_14016 btrfs_get_blocks_direct 2 14016 NULL
115856 +dmi_format_ids_14018 dmi_format_ids 2 14018 NULL
115857 +iscsi_create_flashnode_conn_14022 iscsi_create_flashnode_conn 4 14022 NULL
115858 +pci_add_ext_cap_save_buffer_14032 pci_add_ext_cap_save_buffer 3 14032 NULL
115859 +dvb_usercopy_14036 dvb_usercopy 2 14036 NULL
115860 +read_def_modal_eeprom_14041 read_def_modal_eeprom 3 14041 NULL
115861 +ieee80211_if_fmt_aid_14055 ieee80211_if_fmt_aid 3 14055 NULL
115862 +ovs_nla_alloc_flow_actions_14056 ovs_nla_alloc_flow_actions 1 14056 NULL
115863 +sta_agg_status_read_14058 sta_agg_status_read 3 14058 NULL
115864 +lov_stripeoffset_seq_write_14078 lov_stripeoffset_seq_write 3 14078 NULL
115865 +do_proc_readlink_14096 do_proc_readlink 3 14096 NULL
115866 +ext4_journal_blocks_per_page_14127 ext4_journal_blocks_per_page 0 14127 NULL
115867 +isku_sysfs_read_light_14140 isku_sysfs_read_light 6 14140 NULL
115868 +em_canid_change_14150 em_canid_change 3 14150 NULL
115869 +gsm_dlci_data_14155 gsm_dlci_data 3 14155 NULL
115870 +midi_alloc_ep_req_14159 midi_alloc_ep_req 2 14159 NULL
115871 +print_input_mask_14168 print_input_mask 3-0 14168 NULL
115872 +ocfs2_xattr_value_truncate_14183 ocfs2_xattr_value_truncate 3 14183 NULL
115873 +datafab_read_data_14186 datafab_read_data 4 14186 NULL
115874 +hfsplus_brec_find_14200 hfsplus_brec_find 0 14200 NULL
115875 +alloc_async_14208 alloc_async 1 14208 NULL
115876 +ath6kl_regread_write_14220 ath6kl_regread_write 3 14220 NULL
115877 +ieee80211_if_write_uapsd_max_sp_len_14233 ieee80211_if_write_uapsd_max_sp_len 3 14233 NULL
115878 +dma_declare_coherent_memory_14244 dma_declare_coherent_memory 4 14244 NULL
115879 +btrfs_token_file_extent_ram_bytes_14247 btrfs_token_file_extent_ram_bytes 0 14247 NULL
115880 +ath6kl_connect_event_14267 ath6kl_connect_event 7-8-9 14267 NULL
115881 +rr_status_14293 rr_status 5 14293 NULL
115882 +read_default_ldt_14302 read_default_ldt 2 14302 NULL
115883 +oo_objects_14319 oo_objects 0 14319 NULL
115884 +ll_get_user_pages_14328 ll_get_user_pages 3-2-0 14328 NULL
115885 +p9_client_zc_rpc_14345 p9_client_zc_rpc 7 14345 NULL
115886 +alloc_tx_struct_14349 alloc_tx_struct 1 14349 NULL
115887 +hash_ipportnet4_expire_14354 hash_ipportnet4_expire 4 14354 NULL
115888 +snd_pcm_lib_readv_14363 snd_pcm_lib_readv 0-3 14363 NULL
115889 +lowpan_read_14369 lowpan_read 3 14369 NULL
115890 +ath6kl_regdump_read_14393 ath6kl_regdump_read 3 14393 NULL
115891 +smk_write_onlycap_14400 smk_write_onlycap 3 14400 NULL
115892 +mtd_concat_create_14416 mtd_concat_create 2 14416 NULL
115893 +get_kcore_size_14425 get_kcore_size 0 14425 NULL
115894 +_iwl_dbgfs_sram_write_14439 _iwl_dbgfs_sram_write 3 14439 NULL
115895 +block_size_14443 block_size 0 14443 NULL
115896 +lmv_user_md_size_14456 lmv_user_md_size 0-1 14456 NULL
115897 +snd_emu10k1_proc_spdif_status_14457 snd_emu10k1_proc_spdif_status 4-5 14457 NULL
115898 +ath10k_write_htt_stats_mask_14458 ath10k_write_htt_stats_mask 3 14458 NULL
115899 +lustre_msg_size_v2_14470 lustre_msg_size_v2 0 14470 NULL
115900 +dma_transfer_size_14473 dma_transfer_size 0 14473 NULL
115901 +udplite_getfrag_14479 udplite_getfrag 3-4 14479 NULL
115902 +ieee80211_if_read_dot11MeshGateAnnouncementProtocol_14486 ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 NULL
115903 +split_state_14491 split_state 0 14491 NULL
115904 +ocfs2_debug_read_14507 ocfs2_debug_read 3 14507 NULL
115905 +dataflash_read_user_otp_14536 dataflash_read_user_otp 3-2 14536 NULL nohasharray
115906 +ep0_write_14536 ep0_write 3 14536 &dataflash_read_user_otp_14536
115907 +picolcd_debug_eeprom_read_14549 picolcd_debug_eeprom_read 3 14549 NULL
115908 +qp_host_alloc_queue_14566 qp_host_alloc_queue 1 14566 NULL
115909 +SyS_setdomainname_14569 SyS_setdomainname 2 14569 NULL
115910 +idmap_pipe_downcall_14591 idmap_pipe_downcall 3 14591 NULL
115911 +ceph_osdc_alloc_request_14597 ceph_osdc_alloc_request 3 14597 NULL
115912 +dbJoin_14644 dbJoin 0 14644 NULL
115913 +profile_replace_14652 profile_replace 3 14652 NULL
115914 +usnic_vnic_dump_14662 usnic_vnic_dump 3 14662 NULL
115915 +min_bytes_needed_14675 min_bytes_needed 0 14675 NULL
115916 +nvme_trans_log_info_exceptions_14677 nvme_trans_log_info_exceptions 3 14677 NULL
115917 +pipeline_enc_tx_stat_fifo_int_read_14680 pipeline_enc_tx_stat_fifo_int_read 3 14680 NULL
115918 +ieee80211_if_fmt_rc_rateidx_mask_2ghz_14683 ieee80211_if_fmt_rc_rateidx_mask_2ghz 3 14683 NULL
115919 +SyS_fsetxattr_14702 SyS_fsetxattr 4 14702 NULL
115920 +persistent_ram_ecc_string_14704 persistent_ram_ecc_string 0 14704 NULL
115921 +u_audio_playback_14709 u_audio_playback 3 14709 NULL
115922 +rtw_cbuf_alloc_14710 rtw_cbuf_alloc 1 14710 NULL
115923 +vfd_write_14717 vfd_write 3 14717 NULL
115924 +__blk_end_request_14729 __blk_end_request 3 14729 NULL
115925 +raid1_resize_14740 raid1_resize 2 14740 NULL
115926 +i915_error_state_buf_init_14742 i915_error_state_buf_init 2 14742 NULL
115927 +btrfs_inode_extref_name_len_14752 btrfs_inode_extref_name_len 0 14752 NULL
115928 +rx_rx_cmplt_read_14753 rx_rx_cmplt_read 3 14753 NULL
115929 +regmap_range_read_file_14775 regmap_range_read_file 3 14775 NULL
115930 +sta_dev_read_14782 sta_dev_read 3 14782 NULL
115931 +keys_proc_write_14792 keys_proc_write 3 14792 NULL
115932 +ext4_kvmalloc_14796 ext4_kvmalloc 1 14796 NULL
115933 +__kfifo_in_14797 __kfifo_in 3-0 14797 NULL
115934 +hpet_readl_14801 hpet_readl 0 14801 NULL nohasharray
115935 +snd_als300_gcr_read_14801 snd_als300_gcr_read 0 14801 &hpet_readl_14801
115936 +mrp_attr_create_14853 mrp_attr_create 3 14853 NULL
115937 +lcd_write_14857 lcd_write 3 14857 NULL
115938 +get_user_cpu_mask_14861 get_user_cpu_mask 2 14861 NULL
115939 +gmux_index_read8_14890 gmux_index_read8 0 14890 NULL
115940 +acpi_os_allocate_14892 acpi_os_allocate 1 14892 NULL
115941 +SYSC_readv_14901 SYSC_readv 3 14901 NULL
115942 +__arch_hweight64_14923 __arch_hweight64 0 14923 NULL nohasharray
115943 +qp_memcpy_to_queue_iov_14923 qp_memcpy_to_queue_iov 5-2 14923 &__arch_hweight64_14923
115944 +ocfs2_expand_nonsparse_inode_14936 ocfs2_expand_nonsparse_inode 3-4 14936 NULL
115945 +queue_cnt_14951 queue_cnt 0 14951 NULL
115946 +unix_dgram_recvmsg_14952 unix_dgram_recvmsg 4 14952 NULL
115947 +videobuf_read_stream_14956 videobuf_read_stream 3 14956 NULL
115948 +mce_flush_rx_buffer_14976 mce_flush_rx_buffer 2 14976 NULL
115949 +setkey_14987 setkey 3 14987 NULL nohasharray
115950 +gpio_twl4030_write_14987 gpio_twl4030_write 1 14987 &setkey_14987
115951 +blk_integrity_tuple_size_15027 blk_integrity_tuple_size 0 15027 NULL
115952 +read_file_node_aggr_15040 read_file_node_aggr 3 15040 NULL
115953 +cld_pipe_downcall_15058 cld_pipe_downcall 3 15058 NULL
115954 +ieee80211_if_read_uapsd_max_sp_len_15067 ieee80211_if_read_uapsd_max_sp_len 3 15067 NULL
115955 +nfs4_write_cached_acl_15070 nfs4_write_cached_acl 4 15070 NULL
115956 +ntfs_copy_from_user_15072 ntfs_copy_from_user 0-5-3 15072 NULL
115957 +pppoe_recvmsg_15073 pppoe_recvmsg 4 15073 NULL
115958 +smscore_load_firmware_family2_15086 smscore_load_firmware_family2 3 15086 NULL
115959 +btrfs_readpage_15094 btrfs_readpage 0 15094 NULL
115960 +compat_SyS_pwritev_15118 compat_SyS_pwritev 3 15118 NULL
115961 +hex_dump_to_buffer_15121 hex_dump_to_buffer 6 15121 NULL
115962 +start_port_15124 start_port 0 15124 NULL
115963 +ipwireless_ppp_mru_15153 ipwireless_ppp_mru 0 15153 NULL
115964 +self_check_not_bad_15175 self_check_not_bad 0 15175 NULL
115965 +SYSC_setdomainname_15180 SYSC_setdomainname 2 15180 NULL
115966 +iscsi_create_endpoint_15193 iscsi_create_endpoint 1 15193 NULL
115967 +mtt_alloc_res_15211 mtt_alloc_res 5 15211 NULL
115968 +bfad_debugfs_write_regrd_15218 bfad_debugfs_write_regrd 3 15218 NULL
115969 +iwl_dbgfs_sram_write_15239 iwl_dbgfs_sram_write 3 15239 NULL
115970 +il_dbgfs_rx_stats_read_15243 il_dbgfs_rx_stats_read 3 15243 NULL
115971 +simple_strtol_15273 simple_strtol 0 15273 NULL
115972 +fw_realloc_buffer_15280 fw_realloc_buffer 2 15280 NULL
115973 +kovaplus_sysfs_read_15337 kovaplus_sysfs_read 6 15337 NULL
115974 +ioread16_15342 ioread16 0 15342 NULL
115975 +ept_prefetch_gpte_15348 ept_prefetch_gpte 4 15348 NULL
115976 +acpi_ut_create_string_object_15360 acpi_ut_create_string_object 1 15360 NULL
115977 +ext4_direct_IO_15369 ext4_direct_IO 4 15369 NULL
115978 +graph_depth_read_15371 graph_depth_read 3 15371 NULL
115979 +fq_codel_zalloc_15378 fq_codel_zalloc 1 15378 NULL
115980 +alloc_fddidev_15382 alloc_fddidev 1 15382 NULL
115981 +pipeline_csum_to_rx_xfer_swi_read_15403 pipeline_csum_to_rx_xfer_swi_read 3 15403 NULL
115982 +get_modalias_15406 get_modalias 2 15406 NULL
115983 +blockdev_direct_IO_15408 blockdev_direct_IO 5 15408 NULL
115984 +__videobuf_copy_to_user_15423 __videobuf_copy_to_user 4-0 15423 NULL
115985 +rtw_cfg80211_rx_action_p2p_15432 rtw_cfg80211_rx_action_p2p 3 15432 NULL
115986 +tcp_mtu_to_mss_15438 tcp_mtu_to_mss 2-0 15438 NULL
115987 +hpsa_change_queue_depth_15449 hpsa_change_queue_depth 2 15449 NULL
115988 +insert_old_idx_znode_15500 insert_old_idx_znode 0 15500 NULL
115989 +zd_chip_is_zd1211b_15518 zd_chip_is_zd1211b 0 15518 NULL
115990 +ifx_spi_write_15531 ifx_spi_write 3 15531 NULL
115991 +p9_check_zc_errors_15534 p9_check_zc_errors 4 15534 NULL
115992 +xfrm_state_mtu_15548 xfrm_state_mtu 0-2 15548 NULL
115993 +snd_pcm_channel_info_15572 snd_pcm_channel_info 0 15572 NULL
115994 +persistent_status_15574 persistent_status 4 15574 NULL
115995 +bnx2fc_process_unsol_compl_15576 bnx2fc_process_unsol_compl 2 15576 NULL
115996 +vme_user_write_15587 vme_user_write 3 15587 NULL
115997 +compat_fillonedir_15620 compat_fillonedir 3 15620 NULL
115998 +proc_loginuid_read_15631 proc_loginuid_read 3 15631 NULL
115999 +tomoyo_scan_bprm_15642 tomoyo_scan_bprm 2-4 15642 NULL nohasharray
116000 +pipeline_hs_tx_stat_fifo_int_read_15642 pipeline_hs_tx_stat_fifo_int_read 3 15642 &tomoyo_scan_bprm_15642 nohasharray
116001 +sk_memory_allocated_add_15642 sk_memory_allocated_add 2 15642 &pipeline_hs_tx_stat_fifo_int_read_15642
116002 +joydev_handle_JSIOCSBTNMAP_15643 joydev_handle_JSIOCSBTNMAP 3 15643 NULL
116003 +fs_path_add_15648 fs_path_add 3 15648 NULL
116004 +__do_readpage_15652 __do_readpage 0 15652 NULL
116005 +xsd_read_15653 xsd_read 3 15653 NULL
116006 +unix_bind_15668 unix_bind 3 15668 NULL
116007 +dm_read_15674 dm_read 3 15674 NULL nohasharray
116008 +SyS_connect_15674 SyS_connect 3 15674 &dm_read_15674
116009 +uinput_str_to_user_15695 uinput_str_to_user 3 15695 NULL
116010 +__sk_migrate_realloc_15709 __sk_migrate_realloc 3 15709 NULL
116011 +tracing_snapshot_write_15719 tracing_snapshot_write 3 15719 NULL
116012 +HiSax_readstatus_15752 HiSax_readstatus 2 15752 NULL
116013 +smk_read_direct_15803 smk_read_direct 3 15803 NULL
116014 +gnttab_expand_15817 gnttab_expand 1 15817 NULL nohasharray
116015 +nameseq_list_15817 nameseq_list 3-0 15817 &gnttab_expand_15817
116016 +afs_proc_rootcell_write_15822 afs_proc_rootcell_write 3 15822 NULL
116017 +table_size_15851 table_size 0-1-2 15851 NULL
116018 +write_file_tx99_15856 write_file_tx99 3 15856 NULL
116019 +media_entity_init_15870 media_entity_init 2-4 15870 NULL nohasharray
116020 +ubi_io_write_15870 ubi_io_write 0 15870 &media_entity_init_15870
116021 +__mptctl_ioctl_15875 __mptctl_ioctl 2 15875 NULL
116022 +parse_audio_stream_data_15937 parse_audio_stream_data 3 15937 NULL
116023 +power_read_15939 power_read 3 15939 NULL
116024 +lpfc_idiag_drbacc_read_15948 lpfc_idiag_drbacc_read 3 15948 NULL
116025 +snd_pcm_lib_read_transfer_15952 snd_pcm_lib_read_transfer 5-2-4 15952 NULL
116026 +memblock_virt_alloc_try_nid_15954 memblock_virt_alloc_try_nid 1 15954 NULL
116027 +viafb_vt1636_proc_write_16018 viafb_vt1636_proc_write 3 16018 NULL
116028 +dccp_recvmsg_16056 dccp_recvmsg 4 16056 NULL
116029 +read_file_spectral_period_16057 read_file_spectral_period 3 16057 NULL
116030 +si5351_msynth_params_address_16062 si5351_msynth_params_address 0-1 16062 NULL
116031 +isr_tx_exch_complete_read_16103 isr_tx_exch_complete_read 3 16103 NULL
116032 +isr_hw_pm_mode_changes_read_16110 isr_hw_pm_mode_changes_read 3 16110 NULL nohasharray
116033 +dma_tx_requested_read_16110 dma_tx_requested_read 3 16110 &isr_hw_pm_mode_changes_read_16110
116034 +snd_dma_pointer_16126 snd_dma_pointer 0-2 16126 NULL
116035 +fsm_init_16134 fsm_init 2 16134 NULL
116036 +ext4_xattr_block_get_16148 ext4_xattr_block_get 0 16148 NULL
116037 +optimal_reclaimed_pages_16172 optimal_reclaimed_pages 0 16172 NULL
116038 +mapping_level_16188 mapping_level 2-0 16188 NULL
116039 +i40e_allocate_virt_mem_d_16191 i40e_allocate_virt_mem_d 3 16191 NULL
116040 +ath10k_htt_rx_ring_size_16201 ath10k_htt_rx_ring_size 0 16201 NULL
116041 +cipso_v4_map_cat_rng_hton_16203 cipso_v4_map_cat_rng_hton 0 16203 NULL
116042 +SyS_pselect6_16210 SyS_pselect6 1 16210 NULL
116043 +create_table_16213 create_table 2 16213 NULL
116044 +ath9k_hw_ar9287_dump_eeprom_16224 ath9k_hw_ar9287_dump_eeprom 5-4 16224 NULL
116045 +atomic_read_file_16227 atomic_read_file 3 16227 NULL
116046 +BcmGetSectionValStartOffset_16235 BcmGetSectionValStartOffset 0 16235 NULL
116047 +lov_prep_brw_set_16246 lov_prep_brw_set 3 16246 NULL
116048 +i40e_dbg_dump_read_16247 i40e_dbg_dump_read 3 16247 NULL
116049 +il_dbgfs_disable_ht40_write_16249 il_dbgfs_disable_ht40_write 3 16249 NULL
116050 +SyS_fgetxattr_16254 SyS_fgetxattr 4 16254 NULL
116051 +reiserfs_acl_count_16265 reiserfs_acl_count 0-1 16265 NULL
116052 +ocfs2_xattr_bucket_value_truncate_16279 ocfs2_xattr_bucket_value_truncate 4 16279 NULL
116053 +nand_bch_init_16280 nand_bch_init 3-2 16280 NULL nohasharray
116054 +drbd_setsockopt_16280 drbd_setsockopt 5 16280 &nand_bch_init_16280
116055 +account_16283 account 0-4-2 16283 NULL nohasharray
116056 +mirror_status_16283 mirror_status 5 16283 &account_16283
116057 +jumpshot_read_data_16287 jumpshot_read_data 4 16287 NULL
116058 +mo_xattr_get_16288 mo_xattr_get 0 16288 NULL
116059 +stk_allocate_buffers_16291 stk_allocate_buffers 2 16291 NULL
116060 +rbd_segment_offset_16293 rbd_segment_offset 0-2 16293 NULL
116061 +rsc_mgr_init_16299 rsc_mgr_init 3 16299 NULL
116062 +kvm_handle_hva_range_16312 kvm_handle_hva_range 3-2 16312 NULL
116063 +sysfs_create_groups_16360 sysfs_create_groups 0 16360 NULL
116064 +total_ps_buffered_read_16365 total_ps_buffered_read 3 16365 NULL
116065 +iscsi_tcp_conn_setup_16376 iscsi_tcp_conn_setup 2 16376 NULL
116066 +i8042_create_kbd_port_16379 i8042_create_kbd_port 0 16379 NULL
116067 +ieee80211_if_read_tsf_16420 ieee80211_if_read_tsf 3 16420 NULL
116068 +rxrpc_server_keyring_16431 rxrpc_server_keyring 3 16431 NULL
116069 +__bio_add_page_16435 __bio_add_page 0-4 16435 NULL
116070 +cmdline_store_16442 cmdline_store 4 16442 NULL
116071 +btrfs_truncate_inode_items_16452 btrfs_truncate_inode_items 4 16452 NULL
116072 +netlink_change_ngroups_16457 netlink_change_ngroups 2 16457 NULL
116073 +req_capsule_get_size_16467 req_capsule_get_size 0 16467 NULL
116074 +tracing_readme_read_16493 tracing_readme_read 3 16493 NULL
116075 +KEY_OFFSET_16504 KEY_OFFSET 0 16504 NULL
116076 +snd_interval_max_16529 snd_interval_max 0 16529 NULL
116077 +raid10_resize_16537 raid10_resize 2 16537 NULL
116078 +lpfc_debugfs_read_16566 lpfc_debugfs_read 3 16566 NULL
116079 +agp_allocate_memory_wrap_16576 agp_allocate_memory_wrap 1 16576 NULL
116080 +lustre_msg_hdr_size_v2_16589 lustre_msg_hdr_size_v2 0 16589 NULL
116081 +gmux_index_read32_16604 gmux_index_read32 0 16604 NULL
116082 +compat_SyS_migrate_pages_16618 compat_SyS_migrate_pages 2 16618 NULL
116083 +rtw_set_wpa_ie_16633 rtw_set_wpa_ie 3 16633 NULL
116084 +btrfs_get_token_32_16651 btrfs_get_token_32 0 16651 NULL
116085 +__wa_populate_dto_urb_16699 __wa_populate_dto_urb 3-4 16699 NULL
116086 +__proc_lnet_buffers_16717 __proc_lnet_buffers 5 16717 NULL
116087 +__copy_to_user_swizzled_16748 __copy_to_user_swizzled 3-4 16748 NULL
116088 +arcmsr_adjust_disk_queue_depth_16756 arcmsr_adjust_disk_queue_depth 2 16756 NULL
116089 +blk_rq_map_user_iov_16772 blk_rq_map_user_iov 5 16772 NULL
116090 +i2o_parm_issue_16790 i2o_parm_issue 0 16790 NULL
116091 +get_server_iovec_16804 get_server_iovec 2 16804 NULL
116092 +drm_malloc_ab_16831 drm_malloc_ab 1-2 16831 NULL
116093 +scsi_mode_sense_16835 scsi_mode_sense 5 16835 NULL
116094 +hfsplus_min_io_size_16859 hfsplus_min_io_size 0 16859 NULL
116095 +alloc_idx_lebs_16872 alloc_idx_lebs 2 16872 NULL
116096 +carl9170_debugfs_ampdu_state_read_16873 carl9170_debugfs_ampdu_state_read 3 16873 NULL
116097 +st_write_16874 st_write 3 16874 NULL
116098 +__kfifo_peek_n_16877 __kfifo_peek_n 0 16877 NULL
116099 +psb_unlocked_ioctl_16926 psb_unlocked_ioctl 2 16926 NULL nohasharray
116100 +snd_gf1_mem_proc_dump_16926 snd_gf1_mem_proc_dump 5 16926 &psb_unlocked_ioctl_16926
116101 +_sp2d_alloc_16944 _sp2d_alloc 1-2-3 16944 NULL
116102 +squashfs_read_table_16945 squashfs_read_table 3 16945 NULL
116103 +keyctl_instantiate_key_iov_16969 keyctl_instantiate_key_iov 3 16969 NULL
116104 +ceph_read_dir_17005 ceph_read_dir 3 17005 NULL
116105 +copy_counters_to_user_17027 copy_counters_to_user 5 17027 NULL
116106 +C_SYSC_keyctl_17041 C_SYSC_keyctl 4 17041 NULL
116107 +jffs2_trusted_setxattr_17048 jffs2_trusted_setxattr 4 17048 NULL
116108 +__arch_hweight32_17060 __arch_hweight32 0 17060 NULL
116109 +sddr55_read_data_17072 sddr55_read_data 4 17072 NULL
116110 +dvb_dvr_read_17073 dvb_dvr_read 3 17073 NULL
116111 +simple_transaction_read_17076 simple_transaction_read 3 17076 NULL
116112 +carl9170_debugfs_mem_usage_read_17084 carl9170_debugfs_mem_usage_read 3 17084 NULL
116113 +entry_length_17093 entry_length 0 17093 NULL
116114 +write_mem_17114 write_mem 3 17114 NULL
116115 +pvr2_hdw_state_report_17121 pvr2_hdw_state_report 3 17121 NULL
116116 +nouveau_instobj_create__17144 nouveau_instobj_create_ 4 17144 NULL
116117 +jumpshot_write_data_17151 jumpshot_write_data 4 17151 NULL
116118 +sep_read_17161 sep_read 3 17161 NULL
116119 +befs_nls2utf_17163 befs_nls2utf 3 17163 NULL
116120 +tx_tx_start_templates_read_17164 tx_tx_start_templates_read 3 17164 NULL
116121 +UniStrnlen_17169 UniStrnlen 0 17169 NULL
116122 +access_remote_vm_17189 access_remote_vm 0 17189 NULL nohasharray
116123 +iwl_dbgfs_txfifo_flush_write_17189 iwl_dbgfs_txfifo_flush_write 3 17189 &access_remote_vm_17189
116124 +iscsit_find_cmd_from_itt_or_dump_17194 iscsit_find_cmd_from_itt_or_dump 3 17194 NULL nohasharray
116125 +driver_state_read_17194 driver_state_read 3 17194 &iscsit_find_cmd_from_itt_or_dump_17194
116126 +sync_request_17208 sync_request 2 17208 NULL
116127 +dn_recvmsg_17213 dn_recvmsg 4 17213 NULL
116128 +lprocfs_read_frac_helper_17261 lprocfs_read_frac_helper 0 17261 NULL
116129 +error_error_frame_cts_nul_flid_read_17262 error_error_frame_cts_nul_flid_read 3 17262 NULL
116130 +alloc_ep_17269 alloc_ep 1 17269 NULL
116131 +pg_read_17276 pg_read 3 17276 NULL
116132 +raw_recvmsg_17277 raw_recvmsg 4 17277 NULL
116133 +hmac_sha256_17278 hmac_sha256 2 17278 NULL
116134 +neigh_hash_grow_17283 neigh_hash_grow 2 17283 NULL
116135 +minstrel_stats_read_17290 minstrel_stats_read 3 17290 NULL
116136 +ieee80211_if_fmt_dot11MeshForwarding_17301 ieee80211_if_fmt_dot11MeshForwarding 3 17301 NULL
116137 +mb_cache_create_17307 mb_cache_create 2 17307 NULL
116138 +gnttab_map_frames_v2_17314 gnttab_map_frames_v2 2 17314 NULL
116139 +ieee80211_if_read_dot11MeshHWMPperrMinInterval_17346 ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 NULL
116140 +ath6kl_wmi_send_mgmt_cmd_17347 ath6kl_wmi_send_mgmt_cmd 7 17347 NULL
116141 +mdc_import_seq_write_17409 mdc_import_seq_write 3 17409 NULL
116142 +lpfc_debugfs_dif_err_write_17424 lpfc_debugfs_dif_err_write 3 17424 NULL
116143 +sta_connected_time_read_17435 sta_connected_time_read 3 17435 NULL
116144 +libcfs_ipif_enumerate_17445 libcfs_ipif_enumerate 0 17445 NULL
116145 +nla_get_u32_17455 nla_get_u32 0 17455 NULL
116146 +__ref_totlen_17461 __ref_totlen 0 17461 NULL
116147 +probe_kernel_write_17481 probe_kernel_write 3 17481 NULL
116148 +TSS_rawhmac_17486 TSS_rawhmac 3 17486 NULL
116149 +lbs_highrssi_write_17515 lbs_highrssi_write 3 17515 NULL
116150 +qp_free_res_17541 qp_free_res 5 17541 NULL
116151 +__copy_to_user_17551 __copy_to_user 0-3 17551 NULL
116152 +copy_from_user_17559 copy_from_user 3-0 17559 NULL
116153 +snd_pcm_action_lock_irq_17569 snd_pcm_action_lock_irq 0 17569 NULL
116154 +hash_netport4_expire_17573 hash_netport4_expire 4 17573 NULL
116155 +acpi_ut_create_package_object_17594 acpi_ut_create_package_object 1 17594 NULL
116156 +neigh_hash_alloc_17595 neigh_hash_alloc 1 17595 NULL
116157 +osst_execute_17607 osst_execute 7-6 17607 NULL
116158 +ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout_17618 ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 NULL
116159 +dma_map_page_17628 dma_map_page 0 17628 NULL
116160 +twl4030_set_gpio_direction_17645 twl4030_set_gpio_direction 1 17645 NULL
116161 +SYSC_migrate_pages_17657 SYSC_migrate_pages 2 17657 NULL
116162 +packet_setsockopt_17662 packet_setsockopt 5 17662 NULL nohasharray
116163 +ubi_io_read_data_17662 ubi_io_read_data 0 17662 &packet_setsockopt_17662
116164 +pwr_enable_ps_read_17686 pwr_enable_ps_read 3 17686 NULL
116165 +filemap_fdatawait_17688 filemap_fdatawait 0 17688 NULL
116166 +venus_rename_17707 venus_rename 4-5 17707 NULL
116167 +exofs_read_lookup_dev_table_17733 exofs_read_lookup_dev_table 3 17733 NULL
116168 +sctpprobe_read_17741 sctpprobe_read 3 17741 NULL
116169 +ubifs_leb_change_17789 ubifs_leb_change 0 17789 NULL
116170 +shrink_slab_node_17794 shrink_slab_node 3 17794 NULL
116171 +lpuart_copy_rx_to_tty_17801 lpuart_copy_rx_to_tty 3 17801 NULL
116172 +gnet_stats_copy_app_17821 gnet_stats_copy_app 3 17821 NULL
116173 +cipso_v4_gentag_rbm_17836 cipso_v4_gentag_rbm 0 17836 NULL
116174 +em28xx_audio_ep_packet_size_17844 em28xx_audio_ep_packet_size 0 17844 NULL
116175 +dm_stats_message_17863 dm_stats_message 5 17863 NULL
116176 +sisusb_send_bulk_msg_17864 sisusb_send_bulk_msg 3 17864 NULL
116177 +alloc_sja1000dev_17868 alloc_sja1000dev 1 17868 NULL
116178 +virtio_cread32_17873 virtio_cread32 0 17873 NULL
116179 +ray_cs_essid_proc_write_17875 ray_cs_essid_proc_write 3 17875 NULL
116180 +orinoco_set_key_17878 orinoco_set_key 5-7 17878 NULL nohasharray
116181 +i40e_align_l2obj_base_17878 i40e_align_l2obj_base 0-1 17878 &orinoco_set_key_17878
116182 +init_per_cpu_17880 init_per_cpu 1 17880 NULL
116183 +ieee80211_if_fmt_dot11MeshMaxPeerLinks_17883 ieee80211_if_fmt_dot11MeshMaxPeerLinks 3 17883 NULL
116184 +ieee80211_if_fmt_dot11MeshHWMPRootMode_17890 ieee80211_if_fmt_dot11MeshHWMPRootMode 3 17890 NULL
116185 +dev_pm_opp_get_opp_count_17911 dev_pm_opp_get_opp_count 0 17911 NULL
116186 +xfs_buf_associate_memory_17915 xfs_buf_associate_memory 3 17915 NULL
116187 +tipc_port_iovec_rcv_17921 tipc_port_iovec_rcv 3 17921 NULL
116188 +scsi_bufflen_17933 scsi_bufflen 0 17933 NULL
116189 +__mutex_lock_check_stamp_17947 __mutex_lock_check_stamp 0 17947 NULL
116190 +beacon_interval_write_17952 beacon_interval_write 3 17952 NULL
116191 +calc_nr_buckets_17976 calc_nr_buckets 0 17976 NULL
116192 +ext4_ext_calc_credits_for_single_extent_17983 ext4_ext_calc_credits_for_single_extent 0-2 17983 NULL
116193 +smk_write_cipso_17989 smk_write_cipso 3 17989 NULL
116194 +gnttab_max_grant_frames_17993 gnttab_max_grant_frames 0 17993 NULL
116195 +pvr2_v4l2_read_18006 pvr2_v4l2_read 3 18006 NULL
116196 +cpufreq_add_dev_symlink_18028 cpufreq_add_dev_symlink 0 18028 NULL
116197 +o2hb_highest_node_18034 o2hb_highest_node 0 18034 NULL
116198 +cryptd_alloc_instance_18048 cryptd_alloc_instance 2-3 18048 NULL
116199 +__btrfs_drop_extents_18049 __btrfs_drop_extents 5 18049 NULL
116200 +ddebug_proc_write_18055 ddebug_proc_write 3 18055 NULL
116201 +lua_sysfs_read_18062 lua_sysfs_read 6 18062 NULL
116202 +fpregs_get_18066 fpregs_get 4 18066 NULL
116203 +kvm_read_guest_page_18074 kvm_read_guest_page 5 18074 NULL
116204 +SYSC_pselect6_18076 SYSC_pselect6 1 18076 NULL
116205 +SYSC_semtimedop_18091 SYSC_semtimedop 3 18091 NULL
116206 +mpi_alloc_18094 mpi_alloc 1 18094 NULL
116207 +hfs_direct_IO_18104 hfs_direct_IO 4 18104 NULL
116208 +dfs_file_read_18116 dfs_file_read 3 18116 NULL
116209 +svc_getnl_18120 svc_getnl 0 18120 NULL
116210 +paging32_gpte_to_gfn_lvl_18131 paging32_gpte_to_gfn_lvl 0-2-1 18131 NULL
116211 +selinux_inode_setsecurity_18148 selinux_inode_setsecurity 4 18148 NULL
116212 +is_idx_node_in_use_18165 is_idx_node_in_use 0 18165 NULL
116213 +pccard_store_cis_18176 pccard_store_cis 6 18176 NULL
116214 +snd_pcm_hw_refine_user_18204 snd_pcm_hw_refine_user 0 18204 NULL
116215 +orinoco_add_extscan_result_18207 orinoco_add_extscan_result 3 18207 NULL
116216 +gsm_control_message_18209 gsm_control_message 4 18209 NULL
116217 +do_ipv6_setsockopt_18215 do_ipv6_setsockopt 5 18215 NULL
116218 +gnttab_alloc_grant_references_18240 gnttab_alloc_grant_references 1 18240 NULL
116219 +alloc_trace_uprobe_18247 alloc_trace_uprobe 3 18247 NULL
116220 +rfcomm_sock_setsockopt_18254 rfcomm_sock_setsockopt 5 18254 NULL
116221 +qdisc_class_hash_alloc_18262 qdisc_class_hash_alloc 1 18262 NULL
116222 +gfs2_alloc_sort_buffer_18275 gfs2_alloc_sort_buffer 1 18275 NULL
116223 +alloc_ring_18278 alloc_ring 2-4 18278 NULL
116224 +find_dirty_idx_leb_18280 find_dirty_idx_leb 0 18280 NULL
116225 +bio_phys_segments_18281 bio_phys_segments 0 18281 NULL nohasharray
116226 +nouveau_subdev_create__18281 nouveau_subdev_create_ 7 18281 &bio_phys_segments_18281
116227 +ext4_readpages_18283 ext4_readpages 4 18283 NULL
116228 +mmc_send_bus_test_18285 mmc_send_bus_test 4 18285 NULL
116229 +um_idi_write_18293 um_idi_write 3 18293 NULL
116230 +nouveau_disp_create__18305 nouveau_disp_create_ 4-7 18305 NULL
116231 +vga_r_18310 vga_r 0 18310 NULL
116232 +class_add_profile_18315 class_add_profile 1-3-5 18315 NULL
116233 +csio_mem_read_18319 csio_mem_read 3 18319 NULL
116234 +alloc_and_copy_string_18321 alloc_and_copy_string 2 18321 NULL
116235 +ecryptfs_send_message_18322 ecryptfs_send_message 2 18322 NULL
116236 +bio_integrity_advance_18324 bio_integrity_advance 2 18324 NULL
116237 +copy_page_to_iter_18345 copy_page_to_iter 3-0 18345 NULL
116238 +lcd_proc_write_18351 lcd_proc_write 3 18351 NULL
116239 +pwr_power_save_off_read_18355 pwr_power_save_off_read 3 18355 NULL
116240 +SyS_process_vm_readv_18366 SyS_process_vm_readv 3-5 18366 NULL
116241 +ep_io_18367 ep_io 0 18367 NULL
116242 +qib_user_sdma_num_pages_18371 qib_user_sdma_num_pages 0 18371 NULL
116243 +__ceph_getxattr_18386 __ceph_getxattr 0 18386 NULL
116244 +ci_role_write_18388 ci_role_write 3 18388 NULL
116245 +adis16136_show_serial_18402 adis16136_show_serial 3 18402 NULL
116246 +memblock_virt_alloc_node_nopanic_18431 memblock_virt_alloc_node_nopanic 1 18431 NULL
116247 +iscsi_create_flashnode_sess_18433 iscsi_create_flashnode_sess 4 18433 NULL
116248 +snd_hda_get_connections_18437 snd_hda_get_connections 0 18437 NULL
116249 +fuse_perform_write_18457 fuse_perform_write 4 18457 NULL
116250 +regset_tls_set_18459 regset_tls_set 4 18459 NULL
116251 +pci_vpd_lrdt_size_18479 pci_vpd_lrdt_size 0 18479 NULL nohasharray
116252 +mite_bytes_in_transit_18479 mite_bytes_in_transit 0 18479 &pci_vpd_lrdt_size_18479
116253 +udpv6_setsockopt_18487 udpv6_setsockopt 5 18487 NULL
116254 +btrfs_fiemap_18501 btrfs_fiemap 3 18501 NULL
116255 +__copy_user_zeroing_intel_18510 __copy_user_zeroing_intel 0-3 18510 NULL
116256 +snd_vx_inb_18514 snd_vx_inb 0 18514 NULL
116257 +snd_gus_dram_poke_18525 snd_gus_dram_poke 4 18525 NULL
116258 +nouveau_fifo_channel_create__18530 nouveau_fifo_channel_create_ 9 18530 NULL
116259 +tipc_send2port_18531 tipc_send2port 4 18531 NULL
116260 +seq_copy_in_user_18543 seq_copy_in_user 3 18543 NULL
116261 +sas_change_queue_depth_18555 sas_change_queue_depth 2 18555 NULL
116262 +smk_write_rules_list_18565 smk_write_rules_list 3 18565 NULL
116263 +debug_output_18575 debug_output 3 18575 NULL
116264 +filemap_fdatawait_range_18600 filemap_fdatawait_range 0 18600 NULL
116265 +iowarrior_write_18604 iowarrior_write 3 18604 NULL
116266 +from_buffer_18625 from_buffer 3 18625 NULL
116267 +snd_pcm_oss_write3_18657 snd_pcm_oss_write3 0-3 18657 NULL
116268 +ieee80211_if_fmt_rssi_threshold_18664 ieee80211_if_fmt_rssi_threshold 3 18664 NULL
116269 +xfs_iext_insert_18667 xfs_iext_insert 3 18667 NULL
116270 +fnic_stats_debugfs_read_18688 fnic_stats_debugfs_read 3 18688 NULL
116271 +echo_client_prep_commit_18693 echo_client_prep_commit 8 18693 NULL
116272 +iwl_dbgfs_rx_handlers_read_18708 iwl_dbgfs_rx_handlers_read 3 18708 NULL
116273 +ceph_alloc_page_vector_18710 ceph_alloc_page_vector 1 18710 NULL
116274 +blk_rq_bytes_18715 blk_rq_bytes 0 18715 NULL
116275 +nfs4_init_callback_netid_18717 nfs4_init_callback_netid 3 18717 NULL
116276 +snd_als4k_gcr_read_addr_18741 snd_als4k_gcr_read_addr 0 18741 NULL
116277 +o2hb_debug_create_18744 o2hb_debug_create 4 18744 NULL
116278 +__erst_read_to_erange_from_nvram_18748 __erst_read_to_erange_from_nvram 0 18748 NULL
116279 +wep_packets_read_18751 wep_packets_read 3 18751 NULL
116280 +read_file_dump_nfcal_18766 read_file_dump_nfcal 3 18766 NULL
116281 +SyS_lsetxattr_18776 SyS_lsetxattr 4 18776 NULL
116282 +alloc_fcdev_18780 alloc_fcdev 1 18780 NULL
116283 +dm_stats_print_18815 dm_stats_print 7 18815 NULL
116284 +sys_modify_ldt_18824 sys_modify_ldt 3 18824 NULL
116285 +mtf_test_write_18844 mtf_test_write 3 18844 NULL
116286 +sctp_setsockopt_events_18862 sctp_setsockopt_events 3 18862 NULL
116287 +ieee80211_if_read_element_ttl_18869 ieee80211_if_read_element_ttl 3 18869 NULL
116288 +xlog_find_verify_log_record_18870 xlog_find_verify_log_record 2 18870 NULL
116289 +ceph_setxattr_18913 ceph_setxattr 4 18913 NULL
116290 +ieee80211_rx_mgmt_disassoc_18927 ieee80211_rx_mgmt_disassoc 3 18927 NULL
116291 +snapshot_write_next_18937 snapshot_write_next 0 18937 NULL
116292 +__nla_reserve_18974 __nla_reserve 3 18974 NULL
116293 +__blockdev_direct_IO_18977 __blockdev_direct_IO 0-6 18977 NULL
116294 +find_dirtiest_idx_leb_19001 find_dirtiest_idx_leb 0 19001 NULL
116295 +layout_in_gaps_19006 layout_in_gaps 2 19006 NULL
116296 +huge_page_size_19008 huge_page_size 0 19008 NULL
116297 +hash_netport6_expire_19013 hash_netport6_expire 4 19013 NULL
116298 +sysfs_create_dir_ns_19033 sysfs_create_dir_ns 0 19033 NULL
116299 +revalidate_19043 revalidate 2 19043 NULL
116300 +afs_vnode_store_data_19048 afs_vnode_store_data 2-3-4-5 19048 NULL
116301 +osc_pinger_recov_seq_write_19056 osc_pinger_recov_seq_write 3 19056 NULL nohasharray
116302 +do_vm86_irq_handling_19056 do_vm86_irq_handling 2 19056 &osc_pinger_recov_seq_write_19056
116303 +create_gpadl_header_19064 create_gpadl_header 2 19064 NULL
116304 +ceph_create_snap_context_19082 ceph_create_snap_context 1 19082 NULL
116305 +sta_last_seq_ctrl_read_19106 sta_last_seq_ctrl_read 3 19106 NULL
116306 +cifs_readv_from_socket_19109 cifs_readv_from_socket 3 19109 NULL
116307 +skb_gro_offset_19123 skb_gro_offset 0 19123 NULL
116308 +snd_als4k_iobase_readl_19136 snd_als4k_iobase_readl 0 19136 NULL
116309 +alloc_irdadev_19140 alloc_irdadev 1 19140 NULL
116310 +sleep_auth_read_19159 sleep_auth_read 3 19159 NULL
116311 +smk_write_access2_19170 smk_write_access2 3 19170 NULL
116312 +iwl_dbgfs_reply_tx_error_read_19205 iwl_dbgfs_reply_tx_error_read 3 19205 NULL
116313 +__copy_to_user_inatomic_19214 __copy_to_user_inatomic 3-0 19214 NULL
116314 +dev_counters_read_19216 dev_counters_read 3 19216 NULL
116315 +wbcir_tx_19219 wbcir_tx 3 19219 NULL
116316 +snd_mask_max_19224 snd_mask_max 0 19224 NULL
116317 +snd_pcm_capture_rewind_19229 snd_pcm_capture_rewind 0-2 19229 NULL
116318 +bio_alloc_mddev_19238 bio_alloc_mddev 2 19238 NULL
116319 +ucma_query_19260 ucma_query 4 19260 NULL
116320 +il_dbgfs_rxon_filter_flags_read_19281 il_dbgfs_rxon_filter_flags_read 3 19281 NULL
116321 +batadv_tt_save_orig_buffer_19288 batadv_tt_save_orig_buffer 4 19288 NULL nohasharray
116322 +cfg80211_rx_unprot_mlme_mgmt_19288 cfg80211_rx_unprot_mlme_mgmt 3 19288 &batadv_tt_save_orig_buffer_19288
116323 +qc_capture_19298 qc_capture 3 19298 NULL
116324 +ocfs2_prepare_inode_for_refcount_19303 ocfs2_prepare_inode_for_refcount 3-4 19303 NULL
116325 +event_tx_stuck_read_19305 event_tx_stuck_read 3 19305 NULL
116326 +debug_read_19322 debug_read 3 19322 NULL
116327 +cfg80211_inform_bss_19332 cfg80211_inform_bss 8 19332 NULL nohasharray
116328 +lbs_host_sleep_write_19332 lbs_host_sleep_write 3 19332 &cfg80211_inform_bss_19332
116329 +closure_sub_19359 closure_sub 2 19359 NULL
116330 +firmware_data_write_19360 firmware_data_write 6-5 19360 NULL
116331 +read_zero_19366 read_zero 3 19366 NULL
116332 +interpret_user_input_19393 interpret_user_input 2 19393 NULL
116333 +sync_fill_pt_info_19397 sync_fill_pt_info 0 19397 NULL
116334 +pep_recvmsg_19402 pep_recvmsg 4 19402 NULL
116335 +hid_hw_raw_request_19408 hid_hw_raw_request 0 19408 NULL
116336 +dvbdmx_write_19423 dvbdmx_write 3 19423 NULL
116337 +SyS_sched_getaffinity_19444 SyS_sched_getaffinity 2 19444 NULL
116338 +xfrm_alg_auth_len_19454 xfrm_alg_auth_len 0 19454 NULL
116339 +gnet_stats_copy_19458 gnet_stats_copy 4 19458 NULL
116340 +gp2ap020a00f_get_thresh_reg_19468 gp2ap020a00f_get_thresh_reg 0 19468 NULL
116341 +sky2_read16_19475 sky2_read16 0 19475 NULL
116342 +kstrtoll_from_user_19500 kstrtoll_from_user 2 19500 NULL
116343 +ext4_add_new_descs_19509 ext4_add_new_descs 3 19509 NULL
116344 +batadv_tvlv_container_register_19520 batadv_tvlv_container_register 5 19520 NULL
116345 +cfc_write_array_to_buffer_19529 cfc_write_array_to_buffer 3 19529 NULL
116346 +nfc_llcp_build_tlv_19536 nfc_llcp_build_tlv 3 19536 NULL
116347 +gfn_to_index_19558 gfn_to_index 0-1-3-2 19558 NULL
116348 +ocfs2_control_message_19564 ocfs2_control_message 3 19564 NULL
116349 +nfsd_read_19568 nfsd_read 5 19568 NULL
116350 +ieee80211_key_alloc_19575 ieee80211_key_alloc 3 19575 NULL
116351 +mnt_want_write_file_19579 mnt_want_write_file 0 19579 NULL
116352 +bm_status_read_19583 bm_status_read 3 19583 NULL
116353 +load_xattr_datum_19594 load_xattr_datum 0 19594 NULL
116354 +__mei_cl_recv_19636 __mei_cl_recv 3 19636 NULL
116355 +LoadBitmap_19658 LoadBitmap 2 19658 NULL
116356 +memblock_virt_alloc_low_nopanic_19714 memblock_virt_alloc_low_nopanic 1 19714 NULL
116357 +ocfs2_control_get_this_node_19721 ocfs2_control_get_this_node 0 19721 NULL
116358 +read_reg_19723 read_reg 0 19723 NULL
116359 +wm8350_block_write_19727 wm8350_block_write 2-3 19727 NULL
116360 +memcpy_toiovecend_19736 memcpy_toiovecend 4-3 19736 NULL
116361 +snd_es1968_get_dma_ptr_19747 snd_es1968_get_dma_ptr 0 19747 NULL
116362 +p9_client_read_19750 p9_client_read 5-0 19750 NULL
116363 +pnpbios_proc_write_19758 pnpbios_proc_write 3 19758 NULL
116364 +ocfs2_readpages_19759 ocfs2_readpages 4 19759 NULL
116365 +jffs2_acl_from_medium_19762 jffs2_acl_from_medium 2 19762 NULL
116366 +irda_setsockopt_19824 irda_setsockopt 5 19824 NULL
116367 +vfs_getxattr_19832 vfs_getxattr 0 19832 NULL
116368 +crypt_alloc_buffer_19846 crypt_alloc_buffer 2 19846 NULL
116369 +cfg80211_mlme_register_mgmt_19852 cfg80211_mlme_register_mgmt 5 19852 NULL
116370 +__nla_put_19857 __nla_put 3 19857 NULL
116371 +mrp_request_join_19882 mrp_request_join 4 19882 NULL
116372 +aes_decrypt_interrupt_read_19910 aes_decrypt_interrupt_read 3 19910 NULL
116373 +ps_upsd_max_apturn_read_19918 ps_upsd_max_apturn_read 3 19918 NULL
116374 +mangle_name_19923 mangle_name 0 19923 NULL
116375 +cgroup_task_count_19930 cgroup_task_count 0 19930 NULL
116376 +guest_read_tsc_19931 guest_read_tsc 0 19931 NULL
116377 +iwl_dbgfs_rx_queue_read_19943 iwl_dbgfs_rx_queue_read 3 19943 NULL
116378 +cfg80211_rx_assoc_resp_19944 cfg80211_rx_assoc_resp 4 19944 NULL
116379 +ll_xattr_cache_list_19954 ll_xattr_cache_list 0 19954 NULL
116380 +get_jack_mode_name_19976 get_jack_mode_name 4 19976 NULL
116381 +attach_hdlc_protocol_19986 attach_hdlc_protocol 3 19986 NULL
116382 +rtw_set_wps_probe_resp_19989 rtw_set_wps_probe_resp 3 19989 NULL nohasharray
116383 +i40e_reserve_msix_vectors_19989 i40e_reserve_msix_vectors 2 19989 &rtw_set_wps_probe_resp_19989
116384 +diva_um_idi_read_20003 diva_um_idi_read 0 20003 NULL
116385 +lov_stripe_md_size_20009 lov_stripe_md_size 0-1 20009 NULL nohasharray
116386 +event_trigger_write_20009 event_trigger_write 3 20009 &lov_stripe_md_size_20009
116387 +tree_mod_log_eb_move_20011 tree_mod_log_eb_move 5 20011 NULL
116388 +SYSC_fgetxattr_20027 SYSC_fgetxattr 4 20027 NULL
116389 +split_scan_timeout_read_20029 split_scan_timeout_read 3 20029 NULL
116390 +iwl_mvm_power_mac_dbgfs_read_20067 iwl_mvm_power_mac_dbgfs_read 0-4 20067 NULL
116391 +target_message_20072 target_message 2 20072 NULL
116392 +rawv6_sendmsg_20080 rawv6_sendmsg 4 20080 NULL
116393 +fuse_conn_limit_read_20084 fuse_conn_limit_read 3 20084 NULL
116394 +aat2870_reg_write_file_20086 aat2870_reg_write_file 3 20086 NULL
116395 +team_options_register_20091 team_options_register 3 20091 NULL
116396 +qla2x00_adjust_sdev_qdepth_up_20097 qla2x00_adjust_sdev_qdepth_up 2 20097 NULL
116397 +root_nfs_copy_20111 root_nfs_copy 3 20111 NULL
116398 +hptiop_adjust_disk_queue_depth_20122 hptiop_adjust_disk_queue_depth 2 20122 NULL
116399 +self_check_vid_hdr_20131 self_check_vid_hdr 0 20131 NULL
116400 +tomoyo_commit_ok_20167 tomoyo_commit_ok 2 20167 NULL
116401 +read_flush_pipefs_20171 read_flush_pipefs 3 20171 NULL
116402 +wep_addr_key_count_read_20174 wep_addr_key_count_read 3 20174 NULL
116403 +crystalhd_map_dio_20181 crystalhd_map_dio 3 20181 NULL
116404 +pvr2_ctrl_value_to_sym_20229 pvr2_ctrl_value_to_sym 5 20229 NULL
116405 +rose_sendmsg_20249 rose_sendmsg 4 20249 NULL
116406 +tm6000_i2c_send_regs_20250 tm6000_i2c_send_regs 5 20250 NULL
116407 +btrfs_header_nritems_20296 btrfs_header_nritems 0 20296 NULL
116408 +r10_sync_page_io_20307 r10_sync_page_io 3 20307 NULL
116409 +dm_get_reserved_bio_based_ios_20315 dm_get_reserved_bio_based_ios 0 20315 NULL
116410 +tx_tx_burst_programmed_read_20320 tx_tx_burst_programmed_read 3 20320 NULL
116411 +vx_send_msg_nolock_20322 vx_send_msg_nolock 0 20322 NULL
116412 +snd_cs4281_BA1_read_20323 snd_cs4281_BA1_read 5 20323 NULL
116413 +gfs2_glock_nq_m_20347 gfs2_glock_nq_m 1 20347 NULL
116414 +handle_arr_calc_size_20355 handle_arr_calc_size 0-1 20355 NULL
116415 +snd_pcm_stop_20376 snd_pcm_stop 0 20376 NULL
116416 +smk_set_cipso_20379 smk_set_cipso 3 20379 NULL
116417 +snd_nm256_readl_20394 snd_nm256_readl 0 20394 NULL
116418 +SyS_get_mempolicy_20399 SyS_get_mempolicy 3 20399 NULL nohasharray
116419 +__kfifo_from_user_20399 __kfifo_from_user 3 20399 &SyS_get_mempolicy_20399
116420 +compat_ipv6_setsockopt_20468 compat_ipv6_setsockopt 5 20468 NULL
116421 +read_buf_20469 read_buf 2 20469 NULL
116422 +bio_trim_20472 bio_trim 2 20472 NULL
116423 +btrfs_get_32_20476 btrfs_get_32 0 20476 NULL
116424 +xfs_iext_realloc_direct_20521 xfs_iext_realloc_direct 2 20521 NULL
116425 +drbd_bm_resize_20522 drbd_bm_resize 2 20522 NULL
116426 +amd_create_gatt_pages_20537 amd_create_gatt_pages 1 20537 NULL
116427 +scsi_report_opcode_20551 scsi_report_opcode 3 20551 NULL
116428 +venus_create_20555 venus_create 4 20555 NULL
116429 +btrfs_super_log_root_20565 btrfs_super_log_root 0 20565 NULL
116430 +crypto_ahash_reqsize_20569 crypto_ahash_reqsize 0 20569 NULL
116431 +kvm_test_age_hva_20593 kvm_test_age_hva 2 20593 NULL
116432 +set_secure_conn_20596 set_secure_conn 4 20596 NULL
116433 +sync_timeline_create_20601 sync_timeline_create 2 20601 NULL
116434 +lirc_write_20604 lirc_write 3 20604 NULL
116435 +qib_qsfp_write_20614 qib_qsfp_write 0-2-4 20614 NULL
116436 +snd_pcm_oss_prepare_20641 snd_pcm_oss_prepare 0 20641 NULL
116437 +get_extent_skip_holes_20642 get_extent_skip_holes 2 20642 NULL
116438 +kfifo_copy_to_user_20646 kfifo_copy_to_user 3-4 20646 NULL
116439 +cpulist_scnprintf_20648 cpulist_scnprintf 2-0 20648 NULL
116440 +oz_add_farewell_20652 oz_add_farewell 5 20652 NULL
116441 +oz_cdev_read_20659 oz_cdev_read 3 20659 NULL
116442 +snd_hdsp_playback_copy_20676 snd_hdsp_playback_copy 5 20676 NULL nohasharray
116443 +btrfs_qgroup_reserve_20676 btrfs_qgroup_reserve 0 20676 &snd_hdsp_playback_copy_20676
116444 +dvb_dmxdev_buffer_read_20682 dvb_dmxdev_buffer_read 0-4 20682 NULL
116445 +cpumask_size_20683 cpumask_size 0 20683 NULL
116446 +btrfs_node_blockptr_20685 btrfs_node_blockptr 0 20685 NULL
116447 +read_file_tgt_int_stats_20697 read_file_tgt_int_stats 3 20697 NULL
116448 +__maestro_read_20700 __maestro_read 0 20700 NULL
116449 +cipso_v4_gentag_rng_20703 cipso_v4_gentag_rng 0 20703 NULL
116450 +pcpu_page_first_chunk_20712 pcpu_page_first_chunk 1 20712 NULL
116451 +ocfs2_read_xattr_bucket_20722 ocfs2_read_xattr_bucket 0 20722 NULL
116452 +security_context_to_sid_force_20724 security_context_to_sid_force 2 20724 NULL
116453 +fb_prepare_logo_20743 fb_prepare_logo 0 20743 NULL
116454 +vol_cdev_direct_write_20751 vol_cdev_direct_write 3 20751 NULL
116455 +ocfs2_align_bytes_to_clusters_20754 ocfs2_align_bytes_to_clusters 2 20754 NULL
116456 +brcmf_p2p_escan_20763 brcmf_p2p_escan 2 20763 NULL nohasharray
116457 +mnt_clone_write_20763 mnt_clone_write 0 20763 &brcmf_p2p_escan_20763
116458 +ubi_io_read_20767 ubi_io_read 0 20767 NULL
116459 +fb_alloc_cmap_gfp_20792 fb_alloc_cmap_gfp 2 20792 NULL
116460 +iwl_dbgfs_rxon_flags_read_20795 iwl_dbgfs_rxon_flags_read 3 20795 NULL
116461 +lowpan_write_20800 lowpan_write 3 20800 NULL
116462 +strndup_user_20819 strndup_user 2 20819 NULL
116463 +tipc_msg_build_20825 tipc_msg_build 3 20825 NULL
116464 +wl1271_format_buffer_20834 wl1271_format_buffer 2 20834 NULL
116465 +uvc_alloc_entity_20836 uvc_alloc_entity 4-3 20836 NULL
116466 +p9_tag_alloc_20845 p9_tag_alloc 3 20845 NULL
116467 +nvme_trans_supported_vpd_pages_20847 nvme_trans_supported_vpd_pages 4 20847 NULL
116468 +get_name_20855 get_name 4 20855 NULL
116469 +iwl_dbgfs_pm_params_read_20866 iwl_dbgfs_pm_params_read 3 20866 NULL
116470 +snd_pcm_capture_avail_20867 snd_pcm_capture_avail 0 20867 NULL
116471 +srq_free_res_20868 srq_free_res 5 20868 NULL
116472 +cfs_cpt_table_create_20884 cfs_cpt_table_create 1 20884 NULL
116473 +rb_simple_write_20890 rb_simple_write 3 20890 NULL
116474 +sisusb_send_packet_20891 sisusb_send_packet 2 20891 NULL
116475 +key_icverrors_read_20895 key_icverrors_read 3 20895 NULL
116476 +vfio_msi_enable_20906 vfio_msi_enable 2 20906 NULL
116477 +lbs_rdbbp_write_20918 lbs_rdbbp_write 3 20918 NULL
116478 +htable_bits_20933 htable_bits 0 20933 NULL
116479 +altera_set_ir_post_20948 altera_set_ir_post 2 20948 NULL
116480 +rx_rx_phy_hdr_read_20950 rx_rx_phy_hdr_read 3 20950 NULL
116481 +rsxx_cram_read_20957 rsxx_cram_read 3 20957 NULL
116482 +nfs_map_name_to_uid_20962 nfs_map_name_to_uid 3 20962 NULL
116483 +snd_rme9652_playback_copy_20970 snd_rme9652_playback_copy 5 20970 NULL
116484 +alg_setsockopt_20985 alg_setsockopt 5 20985 NULL
116485 +qib_verbs_send_20999 qib_verbs_send 5-3 20999 NULL
116486 +btrfs_dirty_pages_21019 btrfs_dirty_pages 0 21019 NULL
116487 +btrfs_inode_ref_name_len_21024 btrfs_inode_ref_name_len 0 21024 NULL
116488 +rx_defrag_tkip_called_read_21031 rx_defrag_tkip_called_read 3 21031 NULL
116489 +srp_change_queue_depth_21038 srp_change_queue_depth 2 21038 NULL
116490 +fsl_edma_prep_dma_cyclic_21042 fsl_edma_prep_dma_cyclic 4-3 21042 NULL
116491 +lbs_threshold_read_21046 lbs_threshold_read 5 21046 NULL
116492 +reiserfs_direct_IO_21051 reiserfs_direct_IO 4 21051 NULL
116493 +proc_fault_inject_write_21058 proc_fault_inject_write 3 21058 NULL
116494 +qdisc_get_default_21072 qdisc_get_default 2 21072 NULL
116495 +event_calibration_read_21083 event_calibration_read 3 21083 NULL
116496 +bl_add_page_to_bio_21094 bl_add_page_to_bio 2 21094 NULL nohasharray
116497 +multipath_status_21094 multipath_status 5 21094 &bl_add_page_to_bio_21094
116498 +rate_control_pid_events_read_21099 rate_control_pid_events_read 3 21099 NULL
116499 +ath6kl_send_go_probe_resp_21113 ath6kl_send_go_probe_resp 3 21113 NULL
116500 +_efx_mcdi_rpc_async_21119 _efx_mcdi_rpc_async 4-5 21119 NULL
116501 +i2400m_rx_trace_21127 i2400m_rx_trace 3 21127 NULL
116502 +mei_dbgfs_read_active_21172 mei_dbgfs_read_active 3 21172 NULL
116503 +cx18_v4l2_read_21196 cx18_v4l2_read 3 21196 NULL
116504 +__generic_file_aio_write_21201 __generic_file_aio_write 0 21201 NULL
116505 +ipc_rcu_alloc_21208 ipc_rcu_alloc 1 21208 NULL
116506 +scsi_execute_req_flags_21215 scsi_execute_req_flags 5 21215 NULL
116507 +get_numpages_21227 get_numpages 0-2-1 21227 NULL
116508 +input_ff_create_21240 input_ff_create 2 21240 NULL
116509 +cfg80211_notify_new_peer_candidate_21242 cfg80211_notify_new_peer_candidate 4 21242 NULL
116510 +fru_length_21257 fru_length 0 21257 NULL
116511 +rtw_set_wps_beacon_21262 rtw_set_wps_beacon 3 21262 NULL
116512 +drm_universal_plane_init_21296 drm_universal_plane_init 6 21296 NULL
116513 +do_msg_fill_21307 do_msg_fill 3 21307 NULL
116514 +add_res_range_21310 add_res_range 4 21310 NULL
116515 +get_zeroed_page_21322 get_zeroed_page 0 21322 NULL
116516 +ftrace_profile_read_21327 ftrace_profile_read 3 21327 NULL
116517 +read_file_bool_bmps_21344 read_file_bool_bmps 3 21344 NULL
116518 +gfs2_ea_get_copy_21353 gfs2_ea_get_copy 0 21353 NULL
116519 +alloc_orinocodev_21371 alloc_orinocodev 1 21371 NULL
116520 +SYSC_rt_sigpending_21379 SYSC_rt_sigpending 2 21379 NULL
116521 +video_ioctl2_21380 video_ioctl2 2 21380 NULL
116522 +insert_ptr_21386 insert_ptr 6 21386 NULL
116523 +diva_get_driver_dbg_mask_21399 diva_get_driver_dbg_mask 0 21399 NULL
116524 +__clone_and_map_simple_bio_21404 __clone_and_map_simple_bio 4 21404 NULL
116525 +snd_m3_inw_21406 snd_m3_inw 0 21406 NULL
116526 +usnic_ib_dump_vf_hdr_21423 usnic_ib_dump_vf_hdr 3 21423 NULL
116527 +snapshot_read_next_21426 snapshot_read_next 0 21426 NULL
116528 +tcp_bound_to_half_wnd_21429 tcp_bound_to_half_wnd 0-2 21429 NULL
116529 +tracing_saved_cmdlines_read_21434 tracing_saved_cmdlines_read 3 21434 NULL
116530 +aggr_size_tx_agg_vs_rate_read_21438 aggr_size_tx_agg_vs_rate_read 3 21438 NULL
116531 +__ertm_hdr_size_21450 __ertm_hdr_size 0 21450 NULL
116532 +mei_nfc_send_21477 mei_nfc_send 3 21477 NULL
116533 +read_file_xmit_21487 read_file_xmit 3 21487 NULL
116534 +mmc_alloc_sg_21504 mmc_alloc_sg 1 21504 NULL
116535 +btrfs_file_aio_write_21520 btrfs_file_aio_write 4 21520 NULL
116536 +il_dbgfs_stations_read_21532 il_dbgfs_stations_read 3 21532 NULL
116537 +cipso_v4_map_cat_enum_hton_21540 cipso_v4_map_cat_enum_hton 0 21540 NULL
116538 +rxrpc_send_data_21553 rxrpc_send_data 5 21553 NULL
116539 +rx_rx_beacon_early_term_read_21559 rx_rx_beacon_early_term_read 3 21559 NULL
116540 +xfs_buf_read_uncached_21585 xfs_buf_read_uncached 3 21585 NULL
116541 +snd_es18xx_mixer_read_21586 snd_es18xx_mixer_read 0 21586 NULL
116542 +ocfs2_acl_from_xattr_21604 ocfs2_acl_from_xattr 2 21604 NULL
116543 +filemap_get_page_21606 filemap_get_page 2 21606 NULL
116544 +__jfs_getxattr_21631 __jfs_getxattr 0 21631 NULL
116545 +atalk_sendmsg_21677 atalk_sendmsg 4 21677 NULL
116546 +ocfs2_xattr_get_nolock_21678 ocfs2_xattr_get_nolock 0 21678 NULL
116547 +regmap_register_patch_21681 regmap_register_patch 3 21681 NULL
116548 +rtllib_alloc_txb_21687 rtllib_alloc_txb 1 21687 NULL
116549 +evdev_ioctl_handler_21705 evdev_ioctl_handler 2 21705 NULL
116550 +update_time_21719 update_time 0 21719 NULL
116551 +unix_skb_len_21722 unix_skb_len 0 21722 NULL
116552 +lprocfs_wr_import_21728 lprocfs_wr_import 3 21728 NULL
116553 +mthca_alloc_init_21754 mthca_alloc_init 2 21754 NULL
116554 +usbat_flash_read_data_21762 usbat_flash_read_data 4 21762 NULL
116555 +gen_pool_add_21776 gen_pool_add 3 21776 NULL
116556 +xfs_da_grow_inode_int_21785 xfs_da_grow_inode_int 3 21785 NULL
116557 +dvb_generic_ioctl_21810 dvb_generic_ioctl 2 21810 NULL
116558 +_iwl_dbgfs_sta_drain_write_21837 _iwl_dbgfs_sta_drain_write 3 21837 NULL
116559 +oom_adj_read_21847 oom_adj_read 3 21847 NULL
116560 +lpfc_idiag_extacc_avail_get_21865 lpfc_idiag_extacc_avail_get 0-3 21865 NULL
116561 +brcms_debugfs_hardware_read_21867 brcms_debugfs_hardware_read 3 21867 NULL
116562 +msix_capability_init_21870 msix_capability_init 0 21870 NULL
116563 +sisusbcon_bmove_21873 sisusbcon_bmove 6-5-7 21873 NULL
116564 +ldlm_lock_create_21888 ldlm_lock_create 7 21888 NULL
116565 +dbAllocCtl_21911 dbAllocCtl 0 21911 NULL
116566 +qsfp_1_read_21915 qsfp_1_read 3 21915 NULL
116567 +twl_i2c_write_u16_21953 twl_i2c_write_u16 3 21953 NULL
116568 +__build_xattrs_21979 __build_xattrs 0 21979 NULL
116569 +SYSC_prctl_21980 SYSC_prctl 4 21980 NULL
116570 +compat_rw_copy_check_uvector_22001 compat_rw_copy_check_uvector 3-0 22001 NULL nohasharray
116571 +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
116572 +regcache_sync_block_raw_flush_22021 regcache_sync_block_raw_flush 3-4 22021 NULL
116573 +btrfs_get_16_22023 btrfs_get_16 0 22023 NULL
116574 +_sp2d_min_pg_22032 _sp2d_min_pg 0 22032 NULL
116575 +zd_usb_read_fw_22049 zd_usb_read_fw 4 22049 NULL
116576 +ieee80211_if_fmt_dropped_frames_ttl_22054 ieee80211_if_fmt_dropped_frames_ttl 3 22054 NULL
116577 +btrfs_reloc_clone_csums_22077 btrfs_reloc_clone_csums 2-3 22077 NULL
116578 +mem_rw_22085 mem_rw 3 22085 NULL
116579 +kstrtos32_from_user_22087 kstrtos32_from_user 2 22087 NULL
116580 +snd_pcm_xrun_22088 snd_pcm_xrun 0 22088 NULL
116581 +rt2x00debug_read_crypto_stats_22109 rt2x00debug_read_crypto_stats 3 22109 NULL
116582 +snd_hda_codec_read_22130 snd_hda_codec_read 0 22130 NULL
116583 +SyS_sched_setaffinity_22148 SyS_sched_setaffinity 2 22148 NULL
116584 +do_tcp_sendpages_22155 do_tcp_sendpages 4 22155 NULL
116585 +pci_request_region_22164 pci_request_region 0 22164 NULL
116586 +__kfifo_alloc_22173 __kfifo_alloc 3 22173 NULL
116587 +rfcomm_sock_recvmsg_22227 rfcomm_sock_recvmsg 4 22227 NULL
116588 +mem_write_22232 mem_write 3 22232 NULL
116589 +p9_virtio_zc_request_22240 p9_virtio_zc_request 6-5 22240 NULL
116590 +prepare_to_wait_event_22247 prepare_to_wait_event 0 22247 NULL
116591 +compat_process_vm_rw_22254 compat_process_vm_rw 3-5 22254 NULL
116592 +ping_common_sendmsg_22261 ping_common_sendmsg 5 22261 NULL
116593 +add_res_tree_22263 add_res_tree 7 22263 NULL
116594 +queue_max_sectors_22280 queue_max_sectors 0 22280 NULL
116595 +pci_vpd_srdt_size_22300 pci_vpd_srdt_size 0 22300 NULL nohasharray
116596 +__tun_chr_ioctl_22300 __tun_chr_ioctl 4 22300 &pci_vpd_srdt_size_22300
116597 +mesh_table_alloc_22305 mesh_table_alloc 1 22305 NULL
116598 +lov_setstripe_22307 lov_setstripe 2 22307 NULL
116599 +udpv6_sendmsg_22316 udpv6_sendmsg 4 22316 NULL
116600 +atomic_read_22342 atomic_read 0 22342 NULL
116601 +ll_lazystatfs_seq_write_22353 ll_lazystatfs_seq_write 3 22353 NULL
116602 +snd_pcm_alsa_frames_22363 snd_pcm_alsa_frames 2 22363 NULL
116603 +evdev_ioctl_22371 evdev_ioctl 2 22371 NULL
116604 +alloc_large_system_hash_22391 alloc_large_system_hash 2 22391 NULL
116605 +zoran_write_22404 zoran_write 3 22404 NULL
116606 +queue_reply_22416 queue_reply 3 22416 NULL
116607 +__set_enter_print_fmt_22431 __set_enter_print_fmt 0 22431 NULL
116608 +queue_max_segments_22441 queue_max_segments 0 22441 NULL
116609 +handle_received_packet_22457 handle_received_packet 3 22457 NULL
116610 +ecryptfs_write_22488 ecryptfs_write 4-3 22488 NULL
116611 +qib_user_sdma_alloc_header_22490 qib_user_sdma_alloc_header 2 22490 NULL
116612 +cache_write_procfs_22491 cache_write_procfs 3 22491 NULL
116613 +trim_no_bitmap_22524 trim_no_bitmap 4-3 22524 NULL
116614 +ntb_setup_bwd_msix_22549 ntb_setup_bwd_msix 2-0 22549 NULL
116615 +ocfs2_read_extent_block_22550 ocfs2_read_extent_block 0 22550 NULL
116616 +agp_alloc_page_array_22554 agp_alloc_page_array 1 22554 NULL
116617 +dbFindCtl_22587 dbFindCtl 0 22587 NULL
116618 +snapshot_read_22601 snapshot_read 3 22601 NULL
116619 +sctp_setsockopt_connectx_old_22631 sctp_setsockopt_connectx_old 3 22631 NULL
116620 +ide_core_cp_entry_22636 ide_core_cp_entry 3 22636 NULL
116621 +wl1271_rx_filter_get_fields_size_22638 wl1271_rx_filter_get_fields_size 0 22638 NULL
116622 +pwr_wake_on_timer_exp_read_22640 pwr_wake_on_timer_exp_read 3 22640 NULL
116623 +iwl_dbgfs_calib_disabled_read_22649 iwl_dbgfs_calib_disabled_read 3 22649 NULL
116624 +ext4_ext_direct_IO_22679 ext4_ext_direct_IO 4 22679 NULL
116625 +fill_gap_22681 fill_gap 0 22681 NULL nohasharray
116626 +l2tp_ip_recvmsg_22681 l2tp_ip_recvmsg 4 22681 &fill_gap_22681
116627 +bch_dump_read_22685 bch_dump_read 3 22685 NULL
116628 +reg_umr_22686 reg_umr 5 22686 NULL
116629 +SYSC_vmsplice_22697 SYSC_vmsplice 3 22697 NULL
116630 +alloc_libipw_22708 alloc_libipw 1 22708 NULL
116631 +cx18_copy_buf_to_user_22735 cx18_copy_buf_to_user 4-0 22735 NULL
116632 +ceph_decode_32_22738 ceph_decode_32 0 22738 NULL nohasharray
116633 +__mei_cl_send_22738 __mei_cl_send 3 22738 &ceph_decode_32_22738
116634 +__writeback_single_inode_22739 __writeback_single_inode 0 22739 NULL
116635 +iio_debugfs_write_reg_22742 iio_debugfs_write_reg 3 22742 NULL
116636 +qlcnic_sriov_init_22762 qlcnic_sriov_init 2 22762 NULL
116637 +print_frame_22769 print_frame 0 22769 NULL
116638 +ftrace_arch_read_dyn_info_22773 ftrace_arch_read_dyn_info 0 22773 NULL
116639 +__break_lease_22777 __break_lease 0 22777 NULL
116640 +vnic_dev_get_res_count_22791 vnic_dev_get_res_count 0 22791 NULL
116641 +pla_ocp_write_22802 pla_ocp_write 4 22802 NULL
116642 +__generic_copy_to_user_intel_22806 __generic_copy_to_user_intel 0-3 22806 NULL
116643 +create_attr_set_22861 create_attr_set 1 22861 NULL
116644 +hash_ip6_expire_22867 hash_ip6_expire 4 22867 NULL
116645 +vmw_execbuf_process_22885 vmw_execbuf_process 5 22885 NULL
116646 +usblp_new_writeurb_22894 usblp_new_writeurb 2 22894 NULL
116647 +mdc800_device_read_22896 mdc800_device_read 3 22896 NULL
116648 +ion_handle_test_kernel_22900 ion_handle_test_kernel 4-3 22900 NULL nohasharray
116649 +policy_emit_config_values_22900 policy_emit_config_values 3 22900 &ion_handle_test_kernel_22900
116650 +__set_xattr_22923 __set_xattr 0 22923 NULL
116651 +xstateregs_set_22932 xstateregs_set 4 22932 NULL
116652 +pcpu_mem_zalloc_22948 pcpu_mem_zalloc 1 22948 NULL
116653 +alloc_sglist_22960 alloc_sglist 2-3 22960 NULL
116654 +caif_seqpkt_sendmsg_22961 caif_seqpkt_sendmsg 4 22961 NULL
116655 +vme_get_size_22964 vme_get_size 0 22964 NULL
116656 +tx_frag_key_not_found_read_22971 tx_frag_key_not_found_read 3 22971 NULL
116657 +cached_dev_cache_miss_22979 cached_dev_cache_miss 4 22979 NULL
116658 +usb_get_langid_22983 usb_get_langid 0 22983 NULL
116659 +remote_settings_file_write_22987 remote_settings_file_write 3 22987 NULL
116660 +viafb_dvp0_proc_write_23023 viafb_dvp0_proc_write 3 23023 NULL
116661 +cifs_local_to_utf16_bytes_23025 cifs_local_to_utf16_bytes 0 23025 NULL
116662 +st_status_23032 st_status 5 23032 NULL
116663 +nv50_disp_chan_create__23056 nv50_disp_chan_create_ 5 23056 NULL
116664 +comedi_buf_write_n_available_23057 comedi_buf_write_n_available 0 23057 NULL
116665 +security_inode_killpriv_23060 security_inode_killpriv 0 23060 NULL
116666 +reiserfs_add_entry_23062 reiserfs_add_entry 4 23062 NULL nohasharray
116667 +unix_seqpacket_recvmsg_23062 unix_seqpacket_recvmsg 4 23062 &reiserfs_add_entry_23062
116668 +mei_cl_send_23068 mei_cl_send 3 23068 NULL
116669 +raw_sendmsg_23078 raw_sendmsg 4 23078 NULL
116670 +get_user_hdr_len_23079 get_user_hdr_len 0 23079 NULL
116671 +isr_tx_procs_read_23084 isr_tx_procs_read 3 23084 NULL
116672 +rt2x00debug_write_eeprom_23091 rt2x00debug_write_eeprom 3 23091 NULL
116673 +ntfs_ucstonls_23097 ntfs_ucstonls 3-5 23097 NULL
116674 +pipe_iov_copy_from_user_23102 pipe_iov_copy_from_user 3 23102 NULL
116675 +dgram_recvmsg_23104 dgram_recvmsg 4 23104 NULL
116676 +mwl8k_cmd_set_beacon_23110 mwl8k_cmd_set_beacon 4 23110 NULL
116677 +bset_tree_bytes_23111 bset_tree_bytes 0 23111 NULL nohasharray
116678 +nl80211_send_rx_auth_23111 nl80211_send_rx_auth 4 23111 &bset_tree_bytes_23111
116679 +__clear_user_23118 __clear_user 0-2 23118 NULL
116680 +drm_mode_create_tv_properties_23122 drm_mode_create_tv_properties 2 23122 NULL
116681 +ata_scsi_change_queue_depth_23126 ata_scsi_change_queue_depth 2 23126 NULL
116682 +read_file_ani_23161 read_file_ani 3 23161 NULL
116683 +usblp_write_23178 usblp_write 3 23178 NULL
116684 +gss_pipe_downcall_23182 gss_pipe_downcall 3 23182 NULL
116685 +mpi_alloc_limb_space_23190 mpi_alloc_limb_space 1 23190 NULL
116686 +nft_hash_tbl_alloc_23224 nft_hash_tbl_alloc 1 23224 NULL
116687 +tty_buffer_request_room_23228 tty_buffer_request_room 2-0 23228 NULL
116688 +xlog_get_bp_23229 xlog_get_bp 2 23229 NULL
116689 +ft1000_read_dpram_mag_32_23232 ft1000_read_dpram_mag_32 0 23232 NULL
116690 +rxrpc_client_sendmsg_23236 rxrpc_client_sendmsg 5 23236 NULL
116691 +__gfn_to_rmap_23240 __gfn_to_rmap 1-2 23240 NULL
116692 +nv50_ram_create__23241 nv50_ram_create_ 4 23241 NULL
116693 +sctp_recvmsg_23265 sctp_recvmsg 4 23265 NULL
116694 +uwb_dev_addr_print_23282 uwb_dev_addr_print 2 23282 NULL
116695 +diva_get_trace_filter_23286 diva_get_trace_filter 0 23286 NULL
116696 +i2cdev_write_23310 i2cdev_write 3 23310 NULL
116697 +__aa_kvmalloc_23320 __aa_kvmalloc 1 23320 NULL
116698 +page_readlink_23346 page_readlink 3 23346 NULL
116699 +kmem_zalloc_large_23351 kmem_zalloc_large 1 23351 NULL
116700 +get_dst_timing_23358 get_dst_timing 0 23358 NULL nohasharray
116701 +write_inode_23358 write_inode 0 23358 &get_dst_timing_23358
116702 +fd_setup_write_same_buf_23369 fd_setup_write_same_buf 3 23369 NULL
116703 +iscsi_change_queue_depth_23416 iscsi_change_queue_depth 2 23416 NULL
116704 +vga_mm_r_23419 vga_mm_r 0 23419 NULL
116705 +ocfs2_zero_tail_23447 ocfs2_zero_tail 3 23447 NULL
116706 +hidraw_send_report_23449 hidraw_send_report 3 23449 NULL
116707 +__ata_change_queue_depth_23484 __ata_change_queue_depth 3 23484 NULL
116708 +linear_conf_23485 linear_conf 2 23485 NULL nohasharray
116709 +sync_mapping_buffers_23485 sync_mapping_buffers 0 23485 &linear_conf_23485
116710 +event_filter_read_23494 event_filter_read 3 23494 NULL
116711 +lustre_acl_xattr_merge2ext_23502 lustre_acl_xattr_merge2ext 2 23502 NULL
116712 +devm_iio_device_alloc_23511 devm_iio_device_alloc 2 23511 NULL
116713 +__proc_cpt_table_23516 __proc_cpt_table 5 23516 NULL
116714 +hash_ipmark6_expire_23518 hash_ipmark6_expire 4 23518 NULL
116715 +ima_show_measurements_count_23536 ima_show_measurements_count 3 23536 NULL
116716 +tcp_current_mss_23552 tcp_current_mss 0 23552 NULL
116717 +dbg_leb_change_23555 dbg_leb_change 0 23555 NULL
116718 +btrfs_super_bytenr_23561 btrfs_super_bytenr 0 23561 NULL
116719 +venus_symlink_23570 venus_symlink 6-4 23570 NULL
116720 +iwl_dbgfs_interrupt_read_23574 iwl_dbgfs_interrupt_read 3 23574 NULL
116721 +xfpregs_get_23586 xfpregs_get 4 23586 NULL
116722 +snd_interval_min_23590 snd_interval_min 0 23590 NULL
116723 +islpci_mgt_transaction_23610 islpci_mgt_transaction 5 23610 NULL
116724 +__i2400mu_send_barker_23652 __i2400mu_send_barker 3 23652 NULL
116725 +sInW_23663 sInW 0 23663 NULL
116726 +SyS_connect_23669 SyS_connect 3 23669 NULL
116727 +cx18_read_23699 cx18_read 3 23699 NULL
116728 +at_get_23708 at_get 0 23708 NULL
116729 +rx_rx_dropped_frame_read_23748 rx_rx_dropped_frame_read 3 23748 NULL
116730 +__kfifo_max_r_23768 __kfifo_max_r 0-2-1 23768 NULL
116731 +__build_packet_message_23778 __build_packet_message 4-10 23778 NULL
116732 +security_inode_getxattr_23781 security_inode_getxattr 0 23781 NULL
116733 +cfg80211_inform_bss_width_frame_23782 cfg80211_inform_bss_width_frame 5 23782 NULL
116734 +mpt_free_res_23793 mpt_free_res 5 23793 NULL
116735 +map_write_23795 map_write 3 23795 NULL
116736 +rx_path_reset_read_23801 rx_path_reset_read 3 23801 NULL
116737 +__earlyonly_bootmem_alloc_23824 __earlyonly_bootmem_alloc 2 23824 NULL
116738 +lustre_msg_buflen_23827 lustre_msg_buflen 0 23827 NULL
116739 +ceph_copy_page_vector_to_user_23829 ceph_copy_page_vector_to_user 0-3-4 23829 NULL
116740 +pgdat_end_pfn_23842 pgdat_end_pfn 0 23842 NULL
116741 +iwl_dbgfs_nvm_read_23845 iwl_dbgfs_nvm_read 3 23845 NULL
116742 +p54_init_common_23850 p54_init_common 1 23850 NULL
116743 +bin_to_hex_dup_23853 bin_to_hex_dup 2 23853 NULL
116744 +ocfs2_xattr_get_clusters_23857 ocfs2_xattr_get_clusters 0 23857 NULL
116745 +ieee80211_if_read_dot11MeshMaxPeerLinks_23878 ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 NULL
116746 +nouveau_clock_create__23881 nouveau_clock_create_ 5 23881 NULL nohasharray
116747 +writeback_single_inode_23881 writeback_single_inode 0 23881 &nouveau_clock_create__23881
116748 +tipc_snprintf_23893 tipc_snprintf 2-0 23893 NULL
116749 +add_new_gdb_meta_bg_23911 add_new_gdb_meta_bg 3 23911 NULL nohasharray
116750 +ieee80211_if_read_hw_queues_23911 ieee80211_if_read_hw_queues 3 23911 &add_new_gdb_meta_bg_23911
116751 +f2fs_getxattr_23917 f2fs_getxattr 0 23917 NULL
116752 +ipath_reg_phys_mr_23918 ipath_reg_phys_mr 3 23918 NULL nohasharray
116753 +mpihelp_mul_karatsuba_case_23918 mpihelp_mul_karatsuba_case 5-3 23918 &ipath_reg_phys_mr_23918
116754 +kvm_read_guest_23928 kvm_read_guest 4-2 23928 NULL
116755 +uvc_endpoint_max_bpi_23944 uvc_endpoint_max_bpi 0 23944 NULL
116756 +cifs_setxattr_23957 cifs_setxattr 4 23957 NULL
116757 +size_roundup_power2_23958 size_roundup_power2 0-1 23958 NULL
116758 +sddr55_write_data_23983 sddr55_write_data 4 23983 NULL
116759 +zd_usb_iowrite16v_async_23984 zd_usb_iowrite16v_async 3 23984 NULL
116760 +cxgb_alloc_mem_24007 cxgb_alloc_mem 1 24007 NULL
116761 +give_pages_24021 give_pages 3 24021 NULL
116762 +adis16400_show_serial_number_24037 adis16400_show_serial_number 3 24037 NULL
116763 +hmac_setkey_24043 hmac_setkey 3 24043 NULL
116764 +afs_cell_alloc_24052 afs_cell_alloc 2 24052 NULL
116765 +iwl_dbgfs_low_latency_read_24062 iwl_dbgfs_low_latency_read 3 24062 NULL
116766 +vb2_fop_read_24080 vb2_fop_read 3 24080 NULL
116767 +C_SYSC_process_vm_writev_24102 C_SYSC_process_vm_writev 3-5 24102 NULL
116768 +pipeline_post_proc_swi_read_24108 pipeline_post_proc_swi_read 3 24108 NULL
116769 +request_key_auth_read_24109 request_key_auth_read 3 24109 NULL
116770 +lov_brw_24122 lov_brw 4 24122 NULL
116771 +mpu401_read_24126 mpu401_read 3 24126 NULL
116772 +_picolcd_flash_write_24134 _picolcd_flash_write 4 24134 NULL
116773 +irnet_ctrl_write_24139 irnet_ctrl_write 3 24139 NULL
116774 +SyS_sethostname_24150 SyS_sethostname 2 24150 NULL
116775 +trim_bitmaps_24158 trim_bitmaps 3 24158 NULL
116776 +adu_read_24177 adu_read 3 24177 NULL
116777 +safe_prepare_write_buffer_24187 safe_prepare_write_buffer 3 24187 NULL
116778 +irq_remapping_setup_msi_irqs_24194 irq_remapping_setup_msi_irqs 2 24194 NULL
116779 +ieee80211_if_read_dot11MeshHWMPpreqMinInterval_24208 ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 NULL
116780 +efx_vf_size_24213 efx_vf_size 0 24213 NULL
116781 +tcpprobe_sprint_24222 tcpprobe_sprint 0-2 24222 NULL
116782 +mei_amthif_read_24224 mei_amthif_read 4 24224 NULL nohasharray
116783 +pcpu_embed_first_chunk_24224 pcpu_embed_first_chunk 3-2-1 24224 &mei_amthif_read_24224
116784 +pci_num_vf_24235 pci_num_vf 0 24235 NULL
116785 +sel_read_bool_24236 sel_read_bool 3 24236 NULL
116786 +em28xx_alloc_urbs_24260 em28xx_alloc_urbs 4-6 24260 NULL
116787 +calculate_sizes_24273 calculate_sizes 2 24273 NULL
116788 +thin_status_24278 thin_status 5 24278 NULL
116789 +msg_size_24288 msg_size 0 24288 NULL
116790 +btmrvl_pscmd_read_24308 btmrvl_pscmd_read 3 24308 NULL
116791 +reserve_metadata_bytes_24313 reserve_metadata_bytes 0 24313 NULL
116792 +ath6kl_add_bss_if_needed_24317 ath6kl_add_bss_if_needed 6 24317 NULL
116793 +si476x_radio_read_acf_blob_24336 si476x_radio_read_acf_blob 3 24336 NULL
116794 +C_SYSC_pwritev_24345 C_SYSC_pwritev 3 24345 NULL
116795 +prepare_pages_24349 prepare_pages 0 24349 NULL
116796 +kzalloc_node_24352 kzalloc_node 1 24352 NULL
116797 +qla2x00_handle_queue_full_24365 qla2x00_handle_queue_full 2 24365 NULL
116798 +cfi_read_pri_24366 cfi_read_pri 3 24366 NULL
116799 +btrfs_item_size_nr_24367 btrfs_item_size_nr 0 24367 NULL
116800 +igetword_24373 igetword 0 24373 NULL nohasharray
116801 +break_deleg_24373 break_deleg 0 24373 &igetword_24373
116802 +max_io_len_24384 max_io_len 0-1 24384 NULL
116803 +mpt_alloc_res_24387 mpt_alloc_res 5 24387 NULL
116804 +osc_cur_grant_bytes_seq_write_24396 osc_cur_grant_bytes_seq_write 3 24396 NULL
116805 +getxattr_24398 getxattr 4 24398 NULL nohasharray
116806 +pvr2_v4l2_ioctl_24398 pvr2_v4l2_ioctl 2 24398 &getxattr_24398
116807 +populate_msi_sysfs_24399 populate_msi_sysfs 0 24399 NULL
116808 +blk_update_bidi_request_24415 blk_update_bidi_request 3-4 24415 NULL
116809 +nvme_trans_log_supp_pages_24418 nvme_trans_log_supp_pages 3 24418 NULL
116810 +b43_debugfs_read_24425 b43_debugfs_read 3 24425 NULL
116811 +xenbus_file_read_24427 xenbus_file_read 3 24427 NULL
116812 +ieee80211_rx_mgmt_beacon_24430 ieee80211_rx_mgmt_beacon 3 24430 NULL
116813 +copy_and_ioctl_24434 copy_and_ioctl 4 24434 NULL
116814 +ixgbe_alloc_q_vector_24439 ixgbe_alloc_q_vector 4-6 24439 NULL
116815 +rtw_set_wps_assoc_resp_24440 rtw_set_wps_assoc_resp 3 24440 NULL nohasharray
116816 +smk_user_access_24440 smk_user_access 3 24440 &rtw_set_wps_assoc_resp_24440
116817 +evdev_do_ioctl_24459 evdev_do_ioctl 2 24459 NULL
116818 +lbs_highsnr_write_24460 lbs_highsnr_write 3 24460 NULL
116819 +skb_copy_and_csum_datagram_iovec_24466 skb_copy_and_csum_datagram_iovec 2 24466 NULL
116820 +dut_mode_read_24489 dut_mode_read 3 24489 NULL
116821 +read_file_spec_scan_ctl_24491 read_file_spec_scan_ctl 3 24491 NULL
116822 +pd_video_read_24510 pd_video_read 3 24510 NULL
116823 +request_key_with_auxdata_24515 request_key_with_auxdata 4 24515 NULL
116824 +xfs_buf_get_map_24522 xfs_buf_get_map 3 24522 NULL
116825 +do_mpage_readpage_24536 do_mpage_readpage 3 24536 NULL
116826 +write_cache_pages_24562 write_cache_pages 0 24562 NULL
116827 +SyS_pselect6_24582 SyS_pselect6 1 24582 NULL
116828 +udf_compute_nr_groups_24594 udf_compute_nr_groups 0 24594 NULL
116829 +sensor_hub_get_physical_device_count_24605 sensor_hub_get_physical_device_count 0 24605 NULL nohasharray
116830 +lov_alloc_memmd_24605 lov_alloc_memmd 2 24605 &sensor_hub_get_physical_device_count_24605
116831 +SyS_poll_24620 SyS_poll 2 24620 NULL
116832 +context_alloc_24645 context_alloc 3 24645 NULL
116833 +blk_rq_err_bytes_24650 blk_rq_err_bytes 0 24650 NULL
116834 +btrfs_check_data_free_space_24692 btrfs_check_data_free_space 0 24692 NULL
116835 +datafab_write_data_24696 datafab_write_data 4 24696 NULL
116836 +intelfbhw_get_p1p2_24703 intelfbhw_get_p1p2 2 24703 NULL
116837 +simple_attr_read_24738 simple_attr_read 3 24738 NULL
116838 +qla2x00_change_queue_depth_24742 qla2x00_change_queue_depth 2 24742 NULL
116839 +get_dma_residue_24749 get_dma_residue 0 24749 NULL
116840 +kgdb_hex2mem_24755 kgdb_hex2mem 3 24755 NULL
116841 +ocfs2_read_blocks_24777 ocfs2_read_blocks 0 24777 NULL
116842 +datablob_hmac_verify_24786 datablob_hmac_verify 4 24786 NULL
116843 +cache_read_24790 cache_read 3 24790 NULL
116844 +user_regset_copyout_24796 user_regset_copyout 7 24796 NULL
116845 +kvm_read_guest_virt_helper_24804 kvm_read_guest_virt_helper 3-1 24804 NULL
116846 +ath6kl_fwlog_mask_write_24810 ath6kl_fwlog_mask_write 3 24810 NULL
116847 +snd_als4k_gcr_read_24840 snd_als4k_gcr_read 0 24840 NULL
116848 +snd_pcm_lib_buffer_bytes_24865 snd_pcm_lib_buffer_bytes 0 24865 NULL
116849 +pnp_alloc_24869 pnp_alloc 1 24869 NULL nohasharray
116850 +l2cap_create_basic_pdu_24869 l2cap_create_basic_pdu 3 24869 &pnp_alloc_24869
116851 +queues_read_24877 queues_read 3 24877 NULL
116852 +codec_list_read_file_24910 codec_list_read_file 3 24910 NULL
116853 +v4l2_ctrl_new_24927 v4l2_ctrl_new 7 24927 NULL nohasharray
116854 +__btrfs_free_extent_24927 __btrfs_free_extent 7 24927 &v4l2_ctrl_new_24927
116855 +ocfs2_fiemap_24949 ocfs2_fiemap 3-4 24949 NULL
116856 +packet_sendmsg_24954 packet_sendmsg 4 24954 NULL
116857 +security_inode_rename_24971 security_inode_rename 0 24971 NULL
116858 +twl_i2c_write_u8_24976 twl_i2c_write_u8 3 24976 NULL
116859 +llc_ui_sendmsg_24987 llc_ui_sendmsg 4 24987 NULL
116860 +key_conf_hw_key_idx_read_25003 key_conf_hw_key_idx_read 3 25003 NULL
116861 +il_dbgfs_channels_read_25005 il_dbgfs_channels_read 3 25005 NULL
116862 +ni_660x_num_counters_25031 ni_660x_num_counters 0 25031 NULL
116863 +nfs_dns_resolve_name_25036 nfs_dns_resolve_name 3 25036 NULL
116864 +btrfs_stack_key_blockptr_25058 btrfs_stack_key_blockptr 0 25058 NULL
116865 +gs_buf_alloc_25067 gs_buf_alloc 2 25067 NULL
116866 +ll_track_pid_seq_write_25068 ll_track_pid_seq_write 3 25068 NULL
116867 +SYSC_listxattr_25072 SYSC_listxattr 3 25072 NULL
116868 +ima_appraise_measurement_25093 ima_appraise_measurement 6 25093 NULL
116869 +snd_rawmidi_kernel_write_25106 snd_rawmidi_kernel_write 3 25106 NULL
116870 +ipath_init_qp_table_25167 ipath_init_qp_table 2 25167 NULL
116871 +_iwl_dbgfs_reduced_txp_write_25169 _iwl_dbgfs_reduced_txp_write 3 25169 NULL nohasharray
116872 +kvm_mmu_notifier_change_pte_25169 kvm_mmu_notifier_change_pte 3 25169 &_iwl_dbgfs_reduced_txp_write_25169
116873 +sctp_getsockopt_local_addrs_25178 sctp_getsockopt_local_addrs 2 25178 NULL
116874 +mon_stat_read_25238 mon_stat_read 3 25238 NULL
116875 +stripe_status_25259 stripe_status 5 25259 NULL
116876 +snd_pcm_start_25273 snd_pcm_start 0 25273 NULL
116877 +crypto_alloc_instance2_25277 crypto_alloc_instance2 3 25277 NULL
116878 +vfs_writev_25278 vfs_writev 3 25278 NULL
116879 +l2tp_session_create_25286 l2tp_session_create 1 25286 NULL
116880 +ath9k_debugfs_read_buf_25316 ath9k_debugfs_read_buf 3 25316 NULL
116881 +rng_buffer_size_25348 rng_buffer_size 0 25348 NULL
116882 +SYSC_kexec_load_25361 SYSC_kexec_load 2 25361 NULL
116883 +unix_mkname_25368 unix_mkname 0-2 25368 NULL
116884 +sel_read_mls_25369 sel_read_mls 3 25369 NULL
116885 +vsp1_entity_init_25407 vsp1_entity_init 3 25407 NULL
116886 +dai_list_read_file_25421 dai_list_read_file 3 25421 NULL
116887 +ipath_decode_err_25468 ipath_decode_err 3 25468 NULL
116888 +crypto_hash_digestsize_25469 crypto_hash_digestsize 0 25469 NULL
116889 +ivtv_buf_copy_from_user_25502 ivtv_buf_copy_from_user 4-0 25502 NULL
116890 +snd_pcm_plugin_build_25505 snd_pcm_plugin_build 5 25505 NULL
116891 +sb_permission_25523 sb_permission 0 25523 NULL
116892 +ext3_get_inode_loc_25542 ext3_get_inode_loc 0 25542 NULL
116893 +ieee80211_if_read_path_refresh_time_25545 ieee80211_if_read_path_refresh_time 3 25545 NULL
116894 +wimax_addr_scnprint_25548 wimax_addr_scnprint 2 25548 NULL
116895 +ht_print_chan_25556 ht_print_chan 0-3-4 25556 NULL
116896 +skb_tailroom_25567 skb_tailroom 0 25567 NULL
116897 +ping_recvmsg_25597 ping_recvmsg 4 25597 NULL
116898 +copy_user_generic_25611 copy_user_generic 0 25611 NULL
116899 +proc_coredump_filter_write_25625 proc_coredump_filter_write 3 25625 NULL
116900 +befs_utf2nls_25628 befs_utf2nls 3 25628 NULL nohasharray
116901 +__get_user_pages_25628 __get_user_pages 0 25628 &befs_utf2nls_25628
116902 +__direct_map_25647 __direct_map 5-6 25647 NULL
116903 +aircable_prepare_write_buffer_25669 aircable_prepare_write_buffer 3 25669 NULL
116904 +lpfc_idiag_cmd_get_25672 lpfc_idiag_cmd_get 2 25672 NULL
116905 +sta_inactive_ms_read_25690 sta_inactive_ms_read 3 25690 NULL
116906 +prom_early_alloc_25692 prom_early_alloc 1 25692 NULL
116907 +rx_filter_mc_filter_read_25712 rx_filter_mc_filter_read 3 25712 NULL
116908 +ibmasm_new_command_25714 ibmasm_new_command 2 25714 NULL
116909 +__alloc_bootmem_low_node_25726 __alloc_bootmem_low_node 2 25726 NULL nohasharray
116910 +sel_write_context_25726 sel_write_context 3 25726 &__alloc_bootmem_low_node_25726
116911 +cxgbi_device_portmap_create_25747 cxgbi_device_portmap_create 3 25747 NULL
116912 +event_rx_pool_read_25792 event_rx_pool_read 3 25792 NULL
116913 +sg_read_25799 sg_read 3 25799 NULL
116914 +system_enable_read_25815 system_enable_read 3 25815 NULL
116915 +realloc_buffer_25816 realloc_buffer 2 25816 NULL
116916 +pwr_missing_bcns_read_25824 pwr_missing_bcns_read 3 25824 NULL
116917 +parport_read_25855 parport_read 0 25855 NULL
116918 +xfs_dir2_sf_hdr_size_25858 xfs_dir2_sf_hdr_size 0 25858 NULL
116919 +key_attr_size_25865 key_attr_size 0 25865 NULL
116920 +ath6kl_regread_read_25884 ath6kl_regread_read 3 25884 NULL
116921 +run_delalloc_nocow_25896 run_delalloc_nocow 3-4 25896 NULL
116922 +sisusbcon_scroll_area_25899 sisusbcon_scroll_area 4-3 25899 NULL
116923 +lpfc_change_queue_depth_25905 lpfc_change_queue_depth 2 25905 NULL
116924 +nvme_trans_mode_page_create_25908 nvme_trans_mode_page_create 7-4 25908 NULL
116925 +do_jffs2_setxattr_25910 do_jffs2_setxattr 5 25910 NULL
116926 +rcname_read_25919 rcname_read 3 25919 NULL
116927 +snd_es1938_capture_copy_25930 snd_es1938_capture_copy 5 25930 NULL
116928 +key_flags_read_25931 key_flags_read 3 25931 NULL
116929 +copy_play_buf_25932 copy_play_buf 3 25932 NULL
116930 +flush_25957 flush 2 25957 NULL
116931 +_regmap_multi_reg_write_25967 _regmap_multi_reg_write 3 25967 NULL
116932 +udp_setsockopt_25985 udp_setsockopt 5 25985 NULL
116933 +lustre_msg_buflen_v2_25997 lustre_msg_buflen_v2 0 25997 NULL
116934 +SyS_process_vm_readv_26019 SyS_process_vm_readv 3-5 26019 NULL
116935 +mptscsih_change_queue_depth_26036 mptscsih_change_queue_depth 2 26036 NULL
116936 +selinux_inode_post_setxattr_26037 selinux_inode_post_setxattr 4 26037 NULL
116937 +keyctl_update_key_26061 keyctl_update_key 3 26061 NULL
116938 +pri_wm_latency_write_26063 pri_wm_latency_write 3 26063 NULL
116939 +rx_rx_wa_density_dropped_frame_read_26095 rx_rx_wa_density_dropped_frame_read 3 26095 NULL
116940 +i8042_pnp_id_to_string_26108 i8042_pnp_id_to_string 3 26108 NULL
116941 +read_sb_page_26119 read_sb_page 5 26119 NULL
116942 +ath9k_hw_name_26146 ath9k_hw_name 3 26146 NULL
116943 +copy_oldmem_page_26164 copy_oldmem_page 3 26164 NULL
116944 +gfs2_xattr_acl_get_26166 gfs2_xattr_acl_get 0 26166 NULL nohasharray
116945 +ath6kl_roam_table_read_26166 ath6kl_roam_table_read 3 26166 &gfs2_xattr_acl_get_26166
116946 +disk_devt_26180 disk_devt 0 26180 NULL
116947 +ieee80211_if_fmt_dot11MeshTTL_26198 ieee80211_if_fmt_dot11MeshTTL 3 26198 NULL
116948 +xfs_idata_realloc_26199 xfs_idata_realloc 2 26199 NULL
116949 +mce_write_26201 mce_write 3 26201 NULL
116950 +mwifiex_regrdwr_write_26225 mwifiex_regrdwr_write 3 26225 NULL
116951 +_scsih_change_queue_depth_26230 _scsih_change_queue_depth 2 26230 NULL
116952 +rxrpc_recvmsg_26233 rxrpc_recvmsg 4 26233 NULL
116953 +simple_setattr_26234 simple_setattr 0 26234 NULL
116954 +genwqe_ffdc_buff_size_26263 genwqe_ffdc_buff_size 0 26263 NULL
116955 +crypto_ctxsize_26278 crypto_ctxsize 0 26278 NULL
116956 +wacom_set_device_mode_26280 wacom_set_device_mode 3 26280 NULL
116957 +snd_pcm_plug_client_channels_buf_26309 snd_pcm_plug_client_channels_buf 0-3 26309 NULL
116958 +pwr_wake_on_host_read_26321 pwr_wake_on_host_read 3 26321 NULL
116959 +check_can_nocow_26336 check_can_nocow 2 26336 NULL
116960 +snd_vx_check_reg_bit_26344 snd_vx_check_reg_bit 0 26344 NULL
116961 +ocfs2_duplicate_clusters_by_page_26357 ocfs2_duplicate_clusters_by_page 6-3 26357 NULL
116962 +cifs_readdata_alloc_26360 cifs_readdata_alloc 1 26360 NULL
116963 +invalidate_inode_pages2_range_26403 invalidate_inode_pages2_range 0 26403 NULL
116964 +ntty_write_26404 ntty_write 3 26404 NULL
116965 +firmware_store_26408 firmware_store 4 26408 NULL
116966 +pagemap_read_26441 pagemap_read 3 26441 NULL
116967 +enc_pools_add_pages_26461 enc_pools_add_pages 1 26461 NULL nohasharray
116968 +tower_read_26461 tower_read 3 26461 &enc_pools_add_pages_26461
116969 +ib_alloc_device_26483 ib_alloc_device 1 26483 NULL
116970 +ulong_write_file_26485 ulong_write_file 3 26485 NULL
116971 +dvb_ca_en50221_io_ioctl_26490 dvb_ca_en50221_io_ioctl 2 26490 NULL
116972 +read_vmcore_26501 read_vmcore 3 26501 NULL
116973 +uhid_char_write_26502 uhid_char_write 3 26502 NULL
116974 +vfio_pci_set_msi_trigger_26507 vfio_pci_set_msi_trigger 4-3 26507 NULL
116975 +iwl_dbgfs_rf_reset_read_26512 iwl_dbgfs_rf_reset_read 3 26512 NULL
116976 +alloc_ep_req_26521 alloc_ep_req 3-2 26521 NULL
116977 +SyS_rt_sigpending_26538 SyS_rt_sigpending 2 26538 NULL
116978 +__vhost_add_used_n_26554 __vhost_add_used_n 3 26554 NULL
116979 +dio_new_bio_26562 dio_new_bio 0 26562 NULL
116980 +rts51x_read_mem_26577 rts51x_read_mem 4 26577 NULL
116981 +kernfs_name_locked_26617 kernfs_name_locked 3 26617 NULL
116982 +pwr_fix_tsf_ps_read_26627 pwr_fix_tsf_ps_read 3 26627 NULL
116983 +irq_alloc_generic_chip_26650 irq_alloc_generic_chip 2 26650 NULL nohasharray
116984 +inb_p_26650 inb_p 0 26650 &irq_alloc_generic_chip_26650
116985 +nouveau_volt_create__26654 nouveau_volt_create_ 4 26654 NULL
116986 +cipso_v4_map_cat_rbm_hton_26680 cipso_v4_map_cat_rbm_hton 0 26680 NULL
116987 +flowinfo_read_26683 flowinfo_read 3 26683 NULL
116988 +sysfs_add_file_26716 sysfs_add_file 0 26716 NULL
116989 +nouveau_namedb_create__26732 nouveau_namedb_create_ 7 26732 NULL
116990 +pipeline_tcp_rx_stat_fifo_int_read_26745 pipeline_tcp_rx_stat_fifo_int_read 3 26745 NULL
116991 +snd_hda_get_raw_connections_26762 snd_hda_get_raw_connections 0 26762 NULL
116992 +dma_map_single_attrs_26779 dma_map_single_attrs 0 26779 NULL
116993 +qlcnic_alloc_sds_rings_26795 qlcnic_alloc_sds_rings 2 26795 NULL
116994 +cipso_v4_genopt_26812 cipso_v4_genopt 0 26812 NULL
116995 +iwl_trans_read_mem32_26825 iwl_trans_read_mem32 0 26825 NULL
116996 +smk_write_load_26829 smk_write_load 3 26829 NULL
116997 +scnprint_id_26842 scnprint_id 3-0 26842 NULL
116998 +ecryptfs_miscdev_write_26847 ecryptfs_miscdev_write 3 26847 NULL
116999 +ss_alloc_ep_req_26848 ss_alloc_ep_req 2 26848 NULL
117000 +tipc_conn_sendmsg_26867 tipc_conn_sendmsg 5 26867 NULL
117001 +ath6kl_create_qos_write_26879 ath6kl_create_qos_write 3 26879 NULL
117002 +svc_print_xprts_26881 svc_print_xprts 0 26881 NULL
117003 +skb_zerocopy_headlen_26910 skb_zerocopy_headlen 0 26910 NULL
117004 +hhf_zalloc_26912 hhf_zalloc 1 26912 NULL
117005 +cfg80211_process_auth_26916 cfg80211_process_auth 3 26916 NULL
117006 +x25_asy_change_mtu_26928 x25_asy_change_mtu 2 26928 NULL
117007 +scsi_tgt_copy_sense_26933 scsi_tgt_copy_sense 3 26933 NULL
117008 +sctp_setsockopt_adaptation_layer_26935 sctp_setsockopt_adaptation_layer 3 26935 NULL nohasharray
117009 +pwr_ps_enter_read_26935 pwr_ps_enter_read 3 26935 &sctp_setsockopt_adaptation_layer_26935
117010 +hecubafb_write_26942 hecubafb_write 3 26942 NULL
117011 +extract_entropy_user_26952 extract_entropy_user 3 26952 NULL nohasharray
117012 +do_trimming_26952 do_trimming 3 26952 &extract_entropy_user_26952
117013 +do_direct_IO_26979 do_direct_IO 0 26979 NULL
117014 +__videobuf_alloc_vb_27062 __videobuf_alloc_vb 1 27062 NULL
117015 +ext4_convert_unwritten_extents_27064 ext4_convert_unwritten_extents 4-3-0 27064 NULL
117016 +snd_pcm_lib_period_bytes_27071 snd_pcm_lib_period_bytes 0 27071 NULL
117017 +paravirt_read_msr_27077 paravirt_read_msr 0 27077 NULL
117018 +alloc_fdmem_27083 alloc_fdmem 1 27083 NULL
117019 +btmrvl_hscmd_write_27089 btmrvl_hscmd_write 3 27089 NULL nohasharray
117020 +ath9k_hw_4k_dump_eeprom_27089 ath9k_hw_4k_dump_eeprom 5-4 27089 &btmrvl_hscmd_write_27089
117021 +__devcgroup_inode_permission_27108 __devcgroup_inode_permission 0 27108 NULL
117022 +get_kernel_page_27133 get_kernel_page 0 27133 NULL
117023 +drbd_get_capacity_27141 drbd_get_capacity 0 27141 NULL
117024 +pms_capture_27142 pms_capture 4 27142 NULL
117025 +btmrvl_hscfgcmd_write_27143 btmrvl_hscfgcmd_write 3 27143 NULL
117026 +snd_compr_calc_avail_27165 snd_compr_calc_avail 0 27165 NULL
117027 +ieee80211_if_read_rc_rateidx_mask_5ghz_27183 ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 NULL
117028 +write_kmem_27225 write_kmem 3 27225 NULL
117029 +dbAllocAG_27228 dbAllocAG 0 27228 NULL
117030 +rxrpc_request_key_27235 rxrpc_request_key 3 27235 NULL
117031 +ll_track_gid_seq_write_27267 ll_track_gid_seq_write 3 27267 NULL
117032 +comedi_alloc_devpriv_27272 comedi_alloc_devpriv 2 27272 NULL
117033 +copy_from_buf_27308 copy_from_buf 4-2 27308 NULL
117034 +virtqueue_add_inbuf_27312 virtqueue_add_inbuf 3 27312 NULL
117035 +snd_pcm_oss_write2_27332 snd_pcm_oss_write2 3-0 27332 NULL
117036 +afs_cell_create_27346 afs_cell_create 2 27346 NULL
117037 +iwl_dbgfs_csr_write_27363 iwl_dbgfs_csr_write 3 27363 NULL
117038 +pcbit_stat_27364 pcbit_stat 2 27364 NULL
117039 +seq_read_27411 seq_read 3 27411 NULL
117040 +ib_dma_map_sg_27413 ib_dma_map_sg 0 27413 NULL
117041 +ieee80211_if_read_smps_27416 ieee80211_if_read_smps 3 27416 NULL
117042 +cypress_write_27423 cypress_write 4 27423 NULL
117043 +sddr09_read_data_27447 sddr09_read_data 3 27447 NULL
117044 +v4l2_ctrl_new_std_menu_items_27487 v4l2_ctrl_new_std_menu_items 4 27487 NULL
117045 +hcd_buffer_alloc_27495 hcd_buffer_alloc 2 27495 NULL
117046 +ip_set_get_h32_27498 ip_set_get_h32 0 27498 NULL
117047 +btrfs_get_64_27499 btrfs_get_64 0 27499 NULL
117048 +garmin_read_process_27509 garmin_read_process 3 27509 NULL
117049 +oti_alloc_cookies_27510 oti_alloc_cookies 2 27510 NULL
117050 +ib_copy_to_udata_27525 ib_copy_to_udata 3 27525 NULL
117051 +snd_sonicvibes_getdmaa_27552 snd_sonicvibes_getdmaa 0 27552 NULL
117052 +SyS_fgetxattr_27571 SyS_fgetxattr 4 27571 NULL
117053 +sco_sock_recvmsg_27572 sco_sock_recvmsg 4 27572 NULL
117054 +libipw_alloc_txb_27579 libipw_alloc_txb 1 27579 NULL
117055 +C_SYSC_mbind_27636 C_SYSC_mbind 5 27636 NULL
117056 +ocfs2_xattr_ibody_get_27642 ocfs2_xattr_ibody_get 0 27642 NULL nohasharray
117057 +read_flush_procfs_27642 read_flush_procfs 3 27642 &ocfs2_xattr_ibody_get_27642 nohasharray
117058 +nl80211_send_connect_result_27642 nl80211_send_connect_result 5-7 27642 &read_flush_procfs_27642 nohasharray
117059 +ocfs2_direct_IO_27642 ocfs2_direct_IO 4 27642 &nl80211_send_connect_result_27642
117060 +add_new_gdb_27643 add_new_gdb 3 27643 NULL
117061 +btrfs_fallocate_27647 btrfs_fallocate 3-4 27647 NULL
117062 +qnx6_readpages_27657 qnx6_readpages 4 27657 NULL
117063 +cdrom_read_cdda_old_27664 cdrom_read_cdda_old 4 27664 NULL
117064 +ocfs2_extend_dir_27695 ocfs2_extend_dir 4 27695 NULL
117065 +fs_path_add_from_extent_buffer_27702 fs_path_add_from_extent_buffer 4 27702 NULL
117066 +evm_write_key_27715 evm_write_key 3 27715 NULL
117067 +ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol_27722 ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol 3 27722 NULL
117068 +xfs_dir2_block_sfsize_27727 xfs_dir2_block_sfsize 0 27727 NULL
117069 +SyS_setsockopt_27759 SyS_setsockopt 5 27759 NULL
117070 +transport_init_session_tags_27776 transport_init_session_tags 1-2 27776 NULL
117071 +__lov_setstripe_27782 __lov_setstripe 2 27782 NULL
117072 +twl4030_set_gpio_dataout_27792 twl4030_set_gpio_dataout 1 27792 NULL
117073 +SyS_readv_27804 SyS_readv 3 27804 NULL
117074 +mpihelp_mul_27805 mpihelp_mul 5-3 27805 NULL
117075 +hpt374_read_freq_27828 hpt374_read_freq 0 27828 NULL
117076 +init_header_complete_27833 init_header_complete 0 27833 NULL
117077 +read_profile_27859 read_profile 3 27859 NULL
117078 +sky2_pci_read16_27863 sky2_pci_read16 0 27863 NULL
117079 +ieee80211_if_read_dot11MeshHWMProotInterval_27873 ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 NULL
117080 +unix_seqpacket_sendmsg_27893 unix_seqpacket_sendmsg 4 27893 NULL
117081 +i915_error_object_create_sized_27919 i915_error_object_create_sized 4 27919 NULL
117082 +check_mapped_name_27943 check_mapped_name 3 27943 NULL
117083 +tracing_clock_write_27961 tracing_clock_write 3 27961 NULL nohasharray
117084 +bio_next_split_27961 bio_next_split 2 27961 &tracing_clock_write_27961
117085 +security_path_chown_27966 security_path_chown 0 27966 NULL
117086 +tipc_media_addr_printf_27971 tipc_media_addr_printf 2 27971 NULL
117087 +mic_rx_pkts_read_27972 mic_rx_pkts_read 3 27972 NULL nohasharray
117088 +device_register_27972 device_register 0 27972 &mic_rx_pkts_read_27972
117089 +compat_SyS_set_mempolicy_27975 compat_SyS_set_mempolicy 3 27975 NULL
117090 +pci_enable_device_flags_27977 pci_enable_device_flags 0 27977 NULL
117091 +edt_ft5x06_debugfs_raw_data_read_28002 edt_ft5x06_debugfs_raw_data_read 3 28002 NULL
117092 +seq_get_buf_28006 seq_get_buf 0 28006 NULL
117093 +snd_rawmidi_write_28008 snd_rawmidi_write 3 28008 NULL
117094 +powercap_register_zone_28028 powercap_register_zone 6 28028 NULL
117095 +sctp_setsockopt_maxburst_28041 sctp_setsockopt_maxburst 3 28041 NULL
117096 +rts51x_xd_rw_28046 rts51x_xd_rw 3-4 28046 NULL
117097 +cx231xx_init_vbi_isoc_28053 cx231xx_init_vbi_isoc 3-2-4 28053 NULL
117098 +pool_status_28055 pool_status 5 28055 NULL
117099 +init_rs_non_canonical_28059 init_rs_non_canonical 1 28059 NULL
117100 +lpfc_idiag_mbxacc_read_28061 lpfc_idiag_mbxacc_read 3 28061 NULL
117101 +tx_frag_bad_mblk_num_read_28064 tx_frag_bad_mblk_num_read 3 28064 NULL
117102 +mmc_test_alloc_mem_28102 mmc_test_alloc_mem 3-2 28102 NULL
117103 +rx_defrag_need_defrag_read_28117 rx_defrag_need_defrag_read 3 28117 NULL
117104 +vgacon_adjust_height_28124 vgacon_adjust_height 2 28124 NULL
117105 +video_read_28148 video_read 3 28148 NULL
117106 +snd_midi_channel_alloc_set_28153 snd_midi_channel_alloc_set 1 28153 NULL
117107 +stats_dot11FCSErrorCount_read_28154 stats_dot11FCSErrorCount_read 3 28154 NULL
117108 +vread_28173 vread 0-3 28173 NULL
117109 +macvtap_get_user_28185 macvtap_get_user 4 28185 NULL
117110 +counter_free_res_28187 counter_free_res 5 28187 NULL
117111 +read_disk_sb_28188 read_disk_sb 2 28188 NULL
117112 +nouveau_mxm_create__28200 nouveau_mxm_create_ 4 28200 NULL
117113 +__qp_memcpy_from_queue_28220 __qp_memcpy_from_queue 3-4 28220 NULL
117114 +line6_alloc_sysex_buffer_28225 line6_alloc_sysex_buffer 4 28225 NULL
117115 +amd_nb_num_28228 amd_nb_num 0 28228 NULL
117116 +fuse_direct_IO_28275 fuse_direct_IO 4 28275 NULL
117117 +usemap_size_28281 usemap_size 0 28281 NULL
117118 +inline_xattr_size_28285 inline_xattr_size 0 28285 NULL
117119 +dma_map_sg_attrs_28289 dma_map_sg_attrs 0 28289 NULL
117120 +SyS_ppoll_28290 SyS_ppoll 2 28290 NULL
117121 +kstrtos16_from_user_28300 kstrtos16_from_user 2 28300 NULL
117122 +nouveau_compat_ioctl_28305 nouveau_compat_ioctl 2 28305 NULL
117123 +snd_pcm_oss_read_28317 snd_pcm_oss_read 3 28317 NULL
117124 +security_inode_link_28327 security_inode_link 0 28327 NULL
117125 +generic_write_checks_28329 generic_write_checks 0 28329 NULL
117126 +bm_entry_write_28338 bm_entry_write 3 28338 NULL
117127 +tcp_copy_to_iovec_28344 tcp_copy_to_iovec 3 28344 NULL
117128 +snapshot_write_28351 snapshot_write 3 28351 NULL
117129 +xfs_iomap_write_unwritten_28365 xfs_iomap_write_unwritten 3-2 28365 NULL
117130 +batadv_handle_tt_response_28370 batadv_handle_tt_response 4 28370 NULL
117131 +dlmfs_file_read_28385 dlmfs_file_read 3 28385 NULL
117132 +tx_frag_cache_miss_read_28394 tx_frag_cache_miss_read 3 28394 NULL
117133 +bypass_pwup_write_28416 bypass_pwup_write 3 28416 NULL
117134 +subdev_ioctl_28417 subdev_ioctl 2 28417 NULL
117135 +ksocknal_alloc_tx_28426 ksocknal_alloc_tx 2 28426 NULL
117136 +mpage_readpages_28436 mpage_readpages 3 28436 NULL
117137 +snd_emu10k1_efx_read_28452 snd_emu10k1_efx_read 2 28452 NULL
117138 +key_mic_failures_read_28457 key_mic_failures_read 3 28457 NULL
117139 +alloc_irq_cpu_rmap_28459 alloc_irq_cpu_rmap 1 28459 NULL
117140 +ps_poll_upsd_utilization_read_28519 ps_poll_upsd_utilization_read 3 28519 NULL
117141 +i2400m_tx_stats_read_28527 i2400m_tx_stats_read 3 28527 NULL
117142 +early_init_dt_alloc_memory_arch_28528 early_init_dt_alloc_memory_arch 1 28528 NULL
117143 +sel_read_policycap_28544 sel_read_policycap 3 28544 NULL
117144 +mptctl_getiocinfo_28545 mptctl_getiocinfo 2 28545 NULL nohasharray
117145 +aio_read_events_28545 aio_read_events 3 28545 &mptctl_getiocinfo_28545 nohasharray
117146 +run_delalloc_range_28545 run_delalloc_range 3-4 28545 &aio_read_events_28545
117147 +sysfs_create_bin_file_28551 sysfs_create_bin_file 0 28551 NULL
117148 +b43legacy_debugfs_write_28556 b43legacy_debugfs_write 3 28556 NULL
117149 +asymmetric_verify_28567 asymmetric_verify 3 28567 NULL
117150 +oxygen_read32_28582 oxygen_read32 0 28582 NULL
117151 +task_cgroup_path_28599 task_cgroup_path 3 28599 NULL
117152 +extract_entropy_28604 extract_entropy 5-3 28604 NULL
117153 +kfifo_unused_28612 kfifo_unused 0 28612 NULL
117154 +snd_nm256_capture_copy_28622 snd_nm256_capture_copy 3-5 28622 NULL
117155 +setup_usemap_28636 setup_usemap 3-4 28636 NULL
117156 +qib_handle_6120_hwerrors_28642 qib_handle_6120_hwerrors 3 28642 NULL
117157 +p9_fcall_alloc_28652 p9_fcall_alloc 1 28652 NULL
117158 +read_nic_io_byte_28654 read_nic_io_byte 0 28654 NULL
117159 +blk_queue_resize_tags_28670 blk_queue_resize_tags 2 28670 NULL
117160 +SyS_setgroups16_28686 SyS_setgroups16 1 28686 NULL
117161 +kvm_mmu_get_page_28692 kvm_mmu_get_page 2 28692 NULL
117162 +drm_plane_init_28731 drm_plane_init 6 28731 NULL
117163 +spi_execute_28736 spi_execute 5 28736 NULL
117164 +snd_pcm_aio_write_28738 snd_pcm_aio_write 3 28738 NULL
117165 +read_file_btcoex_28743 read_file_btcoex 3 28743 NULL
117166 +max_hw_blocks_28748 max_hw_blocks 0 28748 NULL
117167 +rpc_pipe_generic_upcall_28766 rpc_pipe_generic_upcall 4 28766 NULL
117168 +ath6kl_get_num_reg_28780 ath6kl_get_num_reg 0 28780 NULL
117169 +sel_write_member_28800 sel_write_member 3 28800 NULL
117170 +iwl_dbgfs_rxon_filter_flags_read_28832 iwl_dbgfs_rxon_filter_flags_read 3 28832 NULL
117171 +kernel_tree_alloc_28833 kernel_tree_alloc 1 28833 NULL
117172 +vp_request_msix_vectors_28849 vp_request_msix_vectors 2 28849 NULL
117173 +ipv6_renew_options_28867 ipv6_renew_options 5 28867 NULL
117174 +max_io_len_target_boundary_28879 max_io_len_target_boundary 0-1 28879 NULL
117175 +packet_sendmsg_spkt_28885 packet_sendmsg_spkt 4 28885 NULL
117176 +da9055_group_write_28904 da9055_group_write 2-3 28904 NULL
117177 +ps_upsd_timeouts_read_28924 ps_upsd_timeouts_read 3 28924 NULL
117178 +iwl_dbgfs_sleep_level_override_write_28925 iwl_dbgfs_sleep_level_override_write 3 28925 NULL
117179 +push_rx_28939 push_rx 3 28939 NULL
117180 +mxuport_prepare_write_buffer_28943 mxuport_prepare_write_buffer 3 28943 NULL
117181 +btrfs_trim_block_group_28963 btrfs_trim_block_group 3-4 28963 NULL
117182 +alloc_sched_domains_28972 alloc_sched_domains 1 28972 NULL
117183 +hash_net6_expire_28979 hash_net6_expire 4 28979 NULL
117184 +hci_sock_setsockopt_28993 hci_sock_setsockopt 5 28993 NULL
117185 +bin_uuid_28999 bin_uuid 3 28999 NULL
117186 +fd_execute_rw_29004 fd_execute_rw 3 29004 NULL
117187 +ieee80211_if_read_ht_opmode_29044 ieee80211_if_read_ht_opmode 3 29044 NULL
117188 +rxrpc_sendmsg_29049 rxrpc_sendmsg 4 29049 NULL
117189 +btrfs_root_bytenr_29058 btrfs_root_bytenr 0 29058 NULL
117190 +iso_packets_buffer_init_29061 iso_packets_buffer_init 3-4 29061 NULL
117191 +lpfc_idiag_extacc_drivr_get_29067 lpfc_idiag_extacc_drivr_get 0-3 29067 NULL
117192 +sctp_getsockopt_assoc_stats_29074 sctp_getsockopt_assoc_stats 2 29074 NULL
117193 +iwl_dbgfs_log_event_write_29088 iwl_dbgfs_log_event_write 3 29088 NULL
117194 +ccp_init_dm_workarea_29097 ccp_init_dm_workarea 3 29097 NULL
117195 +__compat_sys_preadv64_29103 __compat_sys_preadv64 3 29103 NULL
117196 +isdn_ppp_write_29109 isdn_ppp_write 4 29109 NULL
117197 +snprintf_29125 snprintf 0 29125 NULL
117198 +iov_shorten_29130 iov_shorten 0 29130 NULL
117199 +proc_scsi_write_29142 proc_scsi_write 3 29142 NULL
117200 +kvm_mmu_notifier_clear_flush_young_29154 kvm_mmu_notifier_clear_flush_young 3 29154 NULL
117201 +drm_property_create_enum_29201 drm_property_create_enum 5 29201 NULL
117202 +wusb_prf_256_29203 wusb_prf_256 7 29203 NULL
117203 +iwl_dbgfs_temperature_read_29224 iwl_dbgfs_temperature_read 3 29224 NULL
117204 +nvme_trans_copy_from_user_29227 nvme_trans_copy_from_user 3 29227 NULL
117205 +irq_domain_add_linear_29236 irq_domain_add_linear 2 29236 NULL
117206 +recover_peb_29238 recover_peb 0 29238 NULL
117207 +evdev_handle_get_val_29242 evdev_handle_get_val 5-6 29242 NULL
117208 +security_context_to_sid_core_29248 security_context_to_sid_core 2 29248 NULL
117209 +rbd_osd_req_create_29260 rbd_osd_req_create 3 29260 NULL
117210 +prism2_set_genericelement_29277 prism2_set_genericelement 3 29277 NULL
117211 +ext4_fiemap_29296 ext4_fiemap 4 29296 NULL
117212 +sn9c102_read_29305 sn9c102_read 3 29305 NULL
117213 +__fuse_get_req_29315 __fuse_get_req 2 29315 NULL
117214 +lprocfs_write_helper_29323 lprocfs_write_helper 2 29323 NULL
117215 +kvm_handle_hva_29326 kvm_handle_hva 2 29326 NULL
117216 +tun_put_user_29337 tun_put_user 5 29337 NULL
117217 +__alloc_ei_netdev_29338 __alloc_ei_netdev 1 29338 NULL
117218 +l2cap_sock_setsockopt_old_29346 l2cap_sock_setsockopt_old 4 29346 NULL
117219 +read_file_tx99_power_29405 read_file_tx99_power 3 29405 NULL
117220 +mempool_create_29437 mempool_create 1 29437 NULL
117221 +crypto_ahash_alignmask_29445 crypto_ahash_alignmask 0 29445 NULL
117222 +p9_client_prepare_req_29448 p9_client_prepare_req 3 29448 NULL
117223 +validate_scan_freqs_29462 validate_scan_freqs 0 29462 NULL
117224 +SyS_flistxattr_29474 SyS_flistxattr 3 29474 NULL
117225 +do_register_entry_29478 do_register_entry 4 29478 NULL
117226 +simple_strtoul_29480 simple_strtoul 0 29480 NULL
117227 +btmrvl_pscmd_write_29504 btmrvl_pscmd_write 3 29504 NULL
117228 +btrfs_file_extent_disk_bytenr_29505 btrfs_file_extent_disk_bytenr 0 29505 NULL
117229 +i2c_add_adapter_29507 i2c_add_adapter 0 29507 NULL
117230 +usnic_vnic_spec_dump_29508 usnic_vnic_spec_dump 2 29508 NULL
117231 +write_file_regidx_29517 write_file_regidx 3 29517 NULL
117232 +atk_debugfs_ggrp_read_29522 atk_debugfs_ggrp_read 3 29522 NULL
117233 +pci_enable_msix_29524 pci_enable_msix 0 29524 NULL
117234 +ftrace_write_29551 ftrace_write 3 29551 NULL
117235 +idetape_queue_rw_tail_29562 idetape_queue_rw_tail 3 29562 NULL
117236 +leaf_dealloc_29566 leaf_dealloc 3 29566 NULL
117237 +kvm_read_guest_virt_system_29569 kvm_read_guest_virt_system 4-2 29569 NULL
117238 +lbs_lowsnr_read_29571 lbs_lowsnr_read 3 29571 NULL
117239 +security_path_chmod_29578 security_path_chmod 0 29578 NULL
117240 +iwl_dbgfs_missed_beacon_write_29586 iwl_dbgfs_missed_beacon_write 3 29586 NULL
117241 +pvr2_hdw_report_unlocked_29589 pvr2_hdw_report_unlocked 4-0 29589 NULL
117242 +dio_set_defer_completion_29599 dio_set_defer_completion 0 29599 NULL
117243 +slots_per_page_29601 slots_per_page 0 29601 NULL
117244 +osc_cached_mb_seq_write_29610 osc_cached_mb_seq_write 3 29610 NULL
117245 +nla_get_u16_29624 nla_get_u16 0 29624 NULL
117246 +tx_frag_cache_hit_read_29639 tx_frag_cache_hit_read 3 29639 NULL
117247 +sctp_make_abort_user_29654 sctp_make_abort_user 3 29654 NULL nohasharray
117248 +spmi_controller_alloc_29654 spmi_controller_alloc 2 29654 &sctp_make_abort_user_29654
117249 +sisusb_write_mem_bulk_29678 sisusb_write_mem_bulk 4 29678 NULL
117250 +lustre_posix_acl_xattr_2ext_29693 lustre_posix_acl_xattr_2ext 2 29693 NULL
117251 +posix_acl_from_xattr_29708 posix_acl_from_xattr 3 29708 NULL
117252 +probes_write_29711 probes_write 3 29711 NULL
117253 +read_cis_cache_29735 read_cis_cache 4 29735 NULL
117254 +xfs_new_eof_29737 xfs_new_eof 2 29737 NULL
117255 +std_nic_write_29752 std_nic_write 3 29752 NULL
117256 +tg3_irq_count_29786 tg3_irq_count 0 29786 NULL
117257 +dbAlloc_29794 dbAlloc 0 29794 NULL
117258 +tcp_sendpage_29829 tcp_sendpage 4 29829 NULL
117259 +__probe_kernel_write_29842 __probe_kernel_write 3 29842 NULL
117260 +kvm_read_hva_atomic_29848 kvm_read_hva_atomic 3 29848 NULL
117261 +count_partial_29850 count_partial 0 29850 NULL
117262 +write_file_bool_bmps_29870 write_file_bool_bmps 3 29870 NULL
117263 +ipv6_setsockopt_29871 ipv6_setsockopt 5 29871 NULL
117264 +scsi_end_request_29876 scsi_end_request 3 29876 NULL
117265 +crypto_aead_alignmask_29885 crypto_aead_alignmask 0 29885 NULL
117266 +rtw_cfg80211_indicate_sta_assoc_29897 rtw_cfg80211_indicate_sta_assoc 3 29897 NULL
117267 +lov_ost_pool_extend_29914 lov_ost_pool_extend 2 29914 NULL
117268 +write_file_queue_29922 write_file_queue 3 29922 NULL
117269 +__btrfs_getxattr_29947 __btrfs_getxattr 0 29947 NULL nohasharray
117270 +ipv6_recv_error_29947 ipv6_recv_error 3 29947 &__btrfs_getxattr_29947
117271 +arch_setup_dmar_msi_29992 arch_setup_dmar_msi 0 29992 NULL
117272 +dev_mem_write_30028 dev_mem_write 3 30028 NULL
117273 +alloc_netdev_mqs_30030 alloc_netdev_mqs 1 30030 NULL
117274 +sysfs_add_file_mode_ns_30038 sysfs_add_file_mode_ns 0 30038 NULL
117275 +scsi_vpd_inquiry_30040 scsi_vpd_inquiry 0-4 30040 NULL
117276 +drp_wmove_30043 drp_wmove 4 30043 NULL
117277 +__pci_request_selected_regions_30058 __pci_request_selected_regions 0 30058 NULL
117278 +cxgbi_ddp_reserve_30091 cxgbi_ddp_reserve 4 30091 NULL
117279 +snd_midi_channel_init_set_30092 snd_midi_channel_init_set 1 30092 NULL
117280 +rx_filter_data_filter_read_30098 rx_filter_data_filter_read 3 30098 NULL
117281 +defragment_dma_buffer_30113 defragment_dma_buffer 0 30113 NULL
117282 +spi_async_locked_30117 spi_async_locked 0 30117 NULL
117283 +u_memcpya_30139 u_memcpya 3-2 30139 NULL
117284 +dbg_port_buf_30145 dbg_port_buf 2 30145 NULL
117285 +elfcorehdr_read_30159 elfcorehdr_read 2 30159 NULL
117286 +alloc_switch_ctx_30165 alloc_switch_ctx 2 30165 NULL
117287 +expand_inode_data_30169 expand_inode_data 3-2 30169 NULL
117288 +mempool_create_page_pool_30189 mempool_create_page_pool 1 30189 NULL
117289 +drm_property_create_bitmask_30195 drm_property_create_bitmask 5 30195 NULL
117290 +__genwqe_readq_30197 __genwqe_readq 0 30197 NULL
117291 +snd_pcm_playback_forward_30201 snd_pcm_playback_forward 0-2 30201 NULL
117292 +usblp_ioctl_30203 usblp_ioctl 2 30203 NULL
117293 +read_4k_modal_eeprom_30212 read_4k_modal_eeprom 3 30212 NULL
117294 +SyS_semop_30227 SyS_semop 3 30227 NULL
117295 +bitmap_file_set_bit_30228 bitmap_file_set_bit 2 30228 NULL
117296 +rawv6_recvmsg_30265 rawv6_recvmsg 4 30265 NULL
117297 +isr_pci_pm_read_30271 isr_pci_pm_read 3 30271 NULL nohasharray
117298 +try_break_deleg_30271 try_break_deleg 0 30271 &isr_pci_pm_read_30271
117299 +compat_readv_30273 compat_readv 3 30273 NULL
117300 +skcipher_sendmsg_30290 skcipher_sendmsg 4 30290 NULL
117301 +pipeline_sec_frag_swi_read_30294 pipeline_sec_frag_swi_read 3 30294 NULL
117302 +tcp_sendmsg_30296 tcp_sendmsg 4 30296 NULL
117303 +osc_contention_seconds_seq_write_30305 osc_contention_seconds_seq_write 3 30305 NULL
117304 +ext4_acl_from_disk_30320 ext4_acl_from_disk 2 30320 NULL
117305 +i8254_read_30330 i8254_read 0 30330 NULL
117306 +resource_from_user_30341 resource_from_user 3 30341 NULL
117307 +o2nm_this_node_30342 o2nm_this_node 0 30342 NULL
117308 +kstrtou32_from_user_30361 kstrtou32_from_user 2 30361 NULL
117309 +pagecache_write_begin_30364 pagecache_write_begin 0 30364 NULL
117310 +pvscsi_change_queue_depth_30365 pvscsi_change_queue_depth 2 30365 NULL
117311 +C_SYSC_readv_30369 C_SYSC_readv 3 30369 NULL
117312 +blkdev_issue_zeroout_30392 blkdev_issue_zeroout 3 30392 NULL
117313 +c4iw_init_resource_30393 c4iw_init_resource 2-3 30393 NULL
117314 +get_kernel_pages_30397 get_kernel_pages 0 30397 NULL
117315 +vb2_fop_write_30420 vb2_fop_write 3 30420 NULL
117316 +tx_tx_template_prepared_read_30424 tx_tx_template_prepared_read 3 30424 NULL
117317 +lstcon_session_info_30425 lstcon_session_info 6 30425 NULL
117318 +enable_write_30456 enable_write 3 30456 NULL
117319 +tx_tx_template_programmed_read_30461 tx_tx_template_programmed_read 3 30461 NULL
117320 +urandom_read_30462 urandom_read 3 30462 NULL
117321 +zoran_ioctl_30465 zoran_ioctl 2 30465 NULL
117322 +i2c_ctrl_read_30467 i2c_ctrl_read 0 30467 NULL
117323 +adu_write_30487 adu_write 3 30487 NULL
117324 +dtim_interval_write_30489 dtim_interval_write 3 30489 NULL
117325 +batadv_send_tt_request_30493 batadv_send_tt_request 5 30493 NULL
117326 +__send_duplicate_bios_30498 __send_duplicate_bios 4 30498 NULL
117327 +memblock_virt_alloc_node_30515 memblock_virt_alloc_node 1 30515 NULL
117328 +dwc3_testmode_write_30516 dwc3_testmode_write 3 30516 NULL
117329 +debug_debug2_read_30526 debug_debug2_read 3 30526 NULL
117330 +ixgbevf_acquire_msix_vectors_30559 ixgbevf_acquire_msix_vectors 2 30559 NULL
117331 +disk_expand_part_tbl_30561 disk_expand_part_tbl 2 30561 NULL
117332 +set_le_30581 set_le 4 30581 NULL
117333 +blk_init_tags_30592 blk_init_tags 1 30592 NULL
117334 +sgl_map_user_pages_30610 sgl_map_user_pages 2 30610 NULL
117335 +macvtap_sendmsg_30629 macvtap_sendmsg 4 30629 NULL
117336 +ieee80211_if_read_dot11MeshAwakeWindowDuration_30631 ieee80211_if_read_dot11MeshAwakeWindowDuration 3 30631 NULL
117337 +compat_raw_setsockopt_30634 compat_raw_setsockopt 5 30634 NULL
117338 +mlx5_ib_alloc_fast_reg_page_list_30638 mlx5_ib_alloc_fast_reg_page_list 2 30638 NULL
117339 +SyS_listxattr_30647 SyS_listxattr 3 30647 NULL
117340 +jffs2_flash_read_30667 jffs2_flash_read 0 30667 NULL
117341 +ni_ai_fifo_read_30681 ni_ai_fifo_read 3 30681 NULL
117342 +sst_hsw_get_dsp_position_30691 sst_hsw_get_dsp_position 0 30691 NULL
117343 +dccp_setsockopt_ccid_30701 dccp_setsockopt_ccid 4 30701 NULL
117344 +lbs_wrbbp_write_30712 lbs_wrbbp_write 3 30712 NULL
117345 +lbs_debugfs_read_30721 lbs_debugfs_read 3 30721 NULL
117346 +snd_nm256_playback_silence_30727 snd_nm256_playback_silence 3-4 30727 NULL
117347 +snapshot_status_30744 snapshot_status 5 30744 NULL
117348 +fuse_conn_limit_write_30777 fuse_conn_limit_write 3 30777 NULL
117349 +__bio_alloc_30787 __bio_alloc 3 30787 NULL
117350 +smk_read_doi_30813 smk_read_doi 3 30813 NULL
117351 +get_kobj_path_length_30831 get_kobj_path_length 0 30831 NULL
117352 +ath10k_write_fw_dbglog_30835 ath10k_write_fw_dbglog 3 30835 NULL
117353 +of_gpio_named_count_30841 of_gpio_named_count 0 30841 NULL
117354 +sctp_setsockopt_auth_chunk_30843 sctp_setsockopt_auth_chunk 3 30843 NULL
117355 +wd_autoreset_write_30862 wd_autoreset_write 3 30862 NULL
117356 +ieee80211_if_fmt_dropped_frames_no_route_30884 ieee80211_if_fmt_dropped_frames_no_route 3 30884 NULL
117357 +pn_recvmsg_30887 pn_recvmsg 4 30887 NULL
117358 +usnic_debugfs_buildinfo_read_30928 usnic_debugfs_buildinfo_read 3 30928 NULL
117359 +sctp_setsockopt_rtoinfo_30941 sctp_setsockopt_rtoinfo 3 30941 NULL
117360 +tty_insert_flip_string_flags_30969 tty_insert_flip_string_flags 4 30969 NULL
117361 +huge_page_mask_30981 huge_page_mask 0 30981 NULL
117362 +read_file_bt_ant_diversity_30983 read_file_bt_ant_diversity 3 30983 NULL
117363 +lbs_host_sleep_read_31013 lbs_host_sleep_read 3 31013 NULL
117364 +ima_eventsig_init_31022 ima_eventsig_init 5 31022 NULL
117365 +template_fmt_size_31033 template_fmt_size 0 31033 NULL
117366 +do_setup_msi_irqs_31043 do_setup_msi_irqs 2 31043 NULL
117367 +stride_pg_count_31053 stride_pg_count 0-3-2-1-4-5 31053 NULL
117368 +lbs_failcount_read_31063 lbs_failcount_read 3 31063 NULL
117369 +sctp_setsockopt_context_31091 sctp_setsockopt_context 3 31091 NULL
117370 +proc_gid_map_write_31093 proc_gid_map_write 3 31093 NULL
117371 +depth_read_31112 depth_read 3 31112 NULL
117372 +hash_ipportnet6_expire_31118 hash_ipportnet6_expire 4 31118 NULL
117373 +kimage_normal_alloc_31140 kimage_normal_alloc 3 31140 NULL
117374 +size_inside_page_31141 size_inside_page 0 31141 NULL
117375 +w9966_v4l_read_31148 w9966_v4l_read 3 31148 NULL
117376 +ch_do_scsi_31171 ch_do_scsi 4 31171 NULL
117377 +r592_read_fifo_pio_31198 r592_read_fifo_pio 3 31198 NULL
117378 +mtdchar_readoob_31200 mtdchar_readoob 4 31200 NULL
117379 +__btrfs_free_reserved_extent_31207 __btrfs_free_reserved_extent 2 31207 NULL
117380 +cpumask_weight_31215 cpumask_weight 0 31215 NULL
117381 +__read_reg_31216 __read_reg 0 31216 NULL
117382 +atm_get_addr_31221 atm_get_addr 3 31221 NULL
117383 +tcp_recvmsg_31238 tcp_recvmsg 4 31238 NULL
117384 +cyy_readb_31240 cyy_readb 0 31240 NULL
117385 +_create_sg_bios_31244 _create_sg_bios 4 31244 NULL
117386 +ieee80211_if_read_last_beacon_31257 ieee80211_if_read_last_beacon 3 31257 NULL
117387 +hash_netportnet4_expire_31290 hash_netportnet4_expire 4 31290 NULL
117388 +uvc_simplify_fraction_31303 uvc_simplify_fraction 3 31303 NULL
117389 +sisusbcon_scroll_31315 sisusbcon_scroll 5-2-3 31315 NULL
117390 +command_file_write_31318 command_file_write 3 31318 NULL
117391 +hwerr_crcbits_31334 hwerr_crcbits 4 31334 NULL
117392 +_regmap_raw_multi_reg_write_31336 _regmap_raw_multi_reg_write 3 31336 NULL
117393 +em28xx_init_usb_xfer_31337 em28xx_init_usb_xfer 4-6 31337 NULL
117394 +outlen_write_31358 outlen_write 3 31358 NULL
117395 +ieee80211_rx_mgmt_auth_31366 ieee80211_rx_mgmt_auth 3 31366 NULL
117396 +xprt_rdma_allocate_31372 xprt_rdma_allocate 2 31372 NULL
117397 +vb2_vmalloc_get_userptr_31374 vb2_vmalloc_get_userptr 3-2 31374 NULL
117398 +trace_parser_get_init_31379 trace_parser_get_init 2 31379 NULL
117399 +inb_31388 inb 0 31388 NULL
117400 +key_ifindex_read_31411 key_ifindex_read 3 31411 NULL
117401 +_sp2d_max_pg_31422 _sp2d_max_pg 0 31422 NULL
117402 +TSS_checkhmac1_31429 TSS_checkhmac1 5 31429 NULL
117403 +snd_aw2_saa7146_get_hw_ptr_capture_31431 snd_aw2_saa7146_get_hw_ptr_capture 0 31431 NULL
117404 +transport_alloc_session_tags_31449 transport_alloc_session_tags 2-3 31449 NULL
117405 +opera1_xilinx_rw_31453 opera1_xilinx_rw 5 31453 NULL
117406 +xfs_btree_get_numrecs_31477 xfs_btree_get_numrecs 0 31477 NULL
117407 +alg_setkey_31485 alg_setkey 3 31485 NULL
117408 +rds_message_map_pages_31487 rds_message_map_pages 2 31487 NULL
117409 +qsfp_2_read_31491 qsfp_2_read 3 31491 NULL
117410 +__alloc_bootmem_31498 __alloc_bootmem 1 31498 NULL
117411 +hidraw_write_31536 hidraw_write 3 31536 NULL
117412 +usbvision_read_31555 usbvision_read 3 31555 NULL
117413 +tx_frag_tkip_called_read_31575 tx_frag_tkip_called_read 3 31575 NULL
117414 +get_max_inline_xattr_value_size_31578 get_max_inline_xattr_value_size 0 31578 NULL
117415 +osst_write_31581 osst_write 3 31581 NULL
117416 +snd_compr_get_avail_31584 snd_compr_get_avail 0 31584 NULL
117417 +iwl_dbgfs_ucode_tx_stats_read_31611 iwl_dbgfs_ucode_tx_stats_read 3 31611 NULL
117418 +arvo_sysfs_read_31617 arvo_sysfs_read 6 31617 NULL nohasharray
117419 +memblock_virt_alloc_nopanic_31617 memblock_virt_alloc_nopanic 1 31617 &arvo_sysfs_read_31617
117420 +usnic_ib_dump_vf_31623 usnic_ib_dump_vf 3 31623 NULL
117421 +videobuf_read_one_31637 videobuf_read_one 3 31637 NULL
117422 +pod_alloc_sysex_buffer_31651 pod_alloc_sysex_buffer 3 31651 NULL
117423 +xfer_secondary_pool_31661 xfer_secondary_pool 2 31661 NULL
117424 +__lgread_31668 __lgread 4 31668 NULL
117425 +copy_from_user_nmi_31672 copy_from_user_nmi 3-0 31672 NULL
117426 +forced_ps_read_31685 forced_ps_read 3 31685 NULL
117427 +fst_recover_rx_error_31687 fst_recover_rx_error 3 31687 NULL
117428 +rs_pretty_print_rate_31727 rs_pretty_print_rate 0 31727 NULL
117429 +lu_buf_check_and_grow_31735 lu_buf_check_and_grow 2 31735 NULL nohasharray
117430 +utf16s_to_utf8s_31735 utf16s_to_utf8s 0 31735 &lu_buf_check_and_grow_31735
117431 +shmem_pwrite_slow_31741 shmem_pwrite_slow 3-2 31741 NULL
117432 +input_abs_get_max_31742 input_abs_get_max 0 31742 NULL nohasharray
117433 +NCR_700_change_queue_depth_31742 NCR_700_change_queue_depth 2 31742 &input_abs_get_max_31742
117434 +bcm_char_read_31750 bcm_char_read 3 31750 NULL
117435 +snd_seq_device_new_31753 snd_seq_device_new 4 31753 NULL
117436 +SyS_lsetxattr_31766 SyS_lsetxattr 4 31766 NULL
117437 +osync_buffers_list_31789 osync_buffers_list 0 31789 NULL
117438 +usblp_cache_device_id_string_31790 usblp_cache_device_id_string 0 31790 NULL
117439 +ecryptfs_send_message_locked_31801 ecryptfs_send_message_locked 2 31801 NULL
117440 +isr_rx_procs_read_31804 isr_rx_procs_read 3 31804 NULL
117441 +data_write_31805 data_write 3 31805 NULL
117442 +SyS_msgsnd_31814 SyS_msgsnd 3 31814 NULL
117443 +strnlen_user_31815 strnlen_user 0-2 31815 NULL
117444 +sta_last_signal_read_31818 sta_last_signal_read 3 31818 NULL
117445 +clone_bio_31854 clone_bio 4-3 31854 NULL
117446 +SyS_ppoll_31855 SyS_ppoll 2 31855 NULL
117447 +iwl_dbgfs_disable_ht40_write_31876 iwl_dbgfs_disable_ht40_write 3 31876 NULL
117448 +drm_mode_crtc_set_gamma_size_31881 drm_mode_crtc_set_gamma_size 2 31881 NULL
117449 +ddb_output_write_31902 ddb_output_write 3-0 31902 NULL
117450 +xattr_permission_31907 xattr_permission 0 31907 NULL
117451 +lu_buf_realloc_31915 lu_buf_realloc 2 31915 NULL
117452 +new_dir_31919 new_dir 3 31919 NULL
117453 +kmem_alloc_31920 kmem_alloc 1 31920 NULL
117454 +era_status_31934 era_status 5 31934 NULL
117455 +SYSC_sethostname_31940 SYSC_sethostname 2 31940 NULL
117456 +read_mem_31942 read_mem 3 31942 NULL nohasharray
117457 +iov_iter_copy_from_user_31942 iov_iter_copy_from_user 4-0 31942 &read_mem_31942
117458 +ext4_zero_range_31944 ext4_zero_range 3-2 31944 NULL
117459 +vb2_write_31948 vb2_write 3 31948 NULL
117460 +pvr2_ctrl_get_valname_31951 pvr2_ctrl_get_valname 4 31951 NULL
117461 +regcache_rbtree_sync_31964 regcache_rbtree_sync 2 31964 NULL
117462 +iwl_rx_packet_payload_len_31965 iwl_rx_packet_payload_len 0 31965 NULL
117463 +copy_from_user_toio_31966 copy_from_user_toio 3 31966 NULL
117464 +iblock_execute_rw_31982 iblock_execute_rw 3 31982 NULL nohasharray
117465 +vx_read_status_31982 vx_read_status 0 31982 &iblock_execute_rw_31982
117466 +find_next_zero_bit_31990 find_next_zero_bit 0 31990 NULL
117467 +lustre_acl_xattr_merge2posix_31992 lustre_acl_xattr_merge2posix 2 31992 NULL
117468 +sysfs_create_file_31996 sysfs_create_file 0 31996 NULL
117469 +calc_hmac_32010 calc_hmac 3 32010 NULL
117470 +aead_len_32021 aead_len 0 32021 NULL nohasharray
117471 +aer_init_32021 aer_init 0 32021 &aead_len_32021
117472 +stk_read_32038 stk_read 3 32038 NULL
117473 +SYSC_llistxattr_32061 SYSC_llistxattr 3 32061 NULL
117474 +proc_scsi_devinfo_write_32064 proc_scsi_devinfo_write 3 32064 NULL
117475 +cow_file_range_inline_32091 cow_file_range_inline 3 32091 NULL
117476 +bio_alloc_32095 bio_alloc 2 32095 NULL
117477 +ath6kl_fwlog_read_32101 ath6kl_fwlog_read 3 32101 NULL
117478 +disk_status_32120 disk_status 4 32120 NULL
117479 +kobject_add_internal_32133 kobject_add_internal 0 32133 NULL
117480 +venus_link_32165 venus_link 5 32165 NULL
117481 +do_writepages_32173 do_writepages 0 32173 NULL
117482 +del_ptr_32197 del_ptr 4 32197 NULL
117483 +wusb_ccm_mac_32199 wusb_ccm_mac 7 32199 NULL
117484 +riva_get_cmap_len_32218 riva_get_cmap_len 0 32218 NULL
117485 +caif_seqpkt_recvmsg_32241 caif_seqpkt_recvmsg 4 32241 NULL
117486 +lbs_lowrssi_read_32242 lbs_lowrssi_read 3 32242 NULL
117487 +ocfs2_xattr_find_entry_32260 ocfs2_xattr_find_entry 0 32260 NULL
117488 +kvm_set_spte_hva_32312 kvm_set_spte_hva 2 32312 NULL
117489 +cas_calc_tabort_32316 cas_calc_tabort 0 32316 NULL
117490 +SyS_select_32319 SyS_select 1 32319 NULL
117491 +nouveau_bar_create__32332 nouveau_bar_create_ 4 32332 NULL
117492 +nl80211_send_mlme_event_32337 nl80211_send_mlme_event 4 32337 NULL
117493 +t4_alloc_mem_32342 t4_alloc_mem 1 32342 NULL
117494 +dispatch_ioctl_32357 dispatch_ioctl 2 32357 NULL nohasharray
117495 +rx_streaming_always_write_32357 rx_streaming_always_write 3 32357 &dispatch_ioctl_32357
117496 +sel_read_initcon_32362 sel_read_initcon 3 32362 NULL
117497 +ll_setxattr_common_32398 ll_setxattr_common 4 32398 NULL
117498 +xfs_iext_add_indirect_multi_32400 xfs_iext_add_indirect_multi 3 32400 NULL
117499 +vmci_qp_alloc_32405 vmci_qp_alloc 5-3 32405 NULL
117500 +snd_pcm_sync_ptr_32461 snd_pcm_sync_ptr 0 32461 NULL
117501 +cache_status_32462 cache_status 5 32462 NULL
117502 +fill_readbuf_32464 fill_readbuf 3 32464 NULL
117503 +ide_driver_proc_write_32493 ide_driver_proc_write 3 32493 NULL
117504 +bypass_pwoff_write_32499 bypass_pwoff_write 3 32499 NULL
117505 +mdc_pinger_recov_seq_write_32510 mdc_pinger_recov_seq_write 3 32510 NULL
117506 +ctrl_std_val_to_sym_32516 ctrl_std_val_to_sym 5 32516 NULL
117507 +disconnect_32521 disconnect 4 32521 NULL
117508 +qsfp_read_32522 qsfp_read 0-2-4 32522 NULL
117509 +ilo_read_32531 ilo_read 3 32531 NULL
117510 +ieee80211_if_read_estab_plinks_32533 ieee80211_if_read_estab_plinks 3 32533 NULL
117511 +format_devstat_counter_32550 format_devstat_counter 3 32550 NULL
117512 +aes_encrypt_fail_read_32562 aes_encrypt_fail_read 3 32562 NULL
117513 +osc_iocontrol_32565 osc_iocontrol 3 32565 NULL
117514 +mem_swapout_entry_32586 mem_swapout_entry 3 32586 NULL
117515 +pipeline_tcp_tx_stat_fifo_int_read_32589 pipeline_tcp_tx_stat_fifo_int_read 3 32589 NULL
117516 +read_file_beacon_32595 read_file_beacon 3 32595 NULL
117517 +ieee80211_if_read_dropped_frames_congestion_32603 ieee80211_if_read_dropped_frames_congestion 3 32603 NULL
117518 +__pci_request_region_32618 __pci_request_region 0 32618 NULL
117519 +irda_recvmsg_dgram_32631 irda_recvmsg_dgram 4 32631 NULL
117520 +cfg80211_roamed_32632 cfg80211_roamed 5-7 32632 NULL
117521 +kvmalloc_32646 kvmalloc 1 32646 NULL
117522 +ib_sg_dma_len_32649 ib_sg_dma_len 0 32649 NULL
117523 +generic_readlink_32654 generic_readlink 3 32654 NULL
117524 +move_addr_to_kernel_32673 move_addr_to_kernel 2 32673 NULL
117525 +compat_SyS_preadv_32679 compat_SyS_preadv 3 32679 NULL
117526 +jfs_readpages_32702 jfs_readpages 4 32702 NULL
117527 +rt2x00debug_read_queue_dump_32712 rt2x00debug_read_queue_dump 3 32712 NULL
117528 +megasas_change_queue_depth_32747 megasas_change_queue_depth 2 32747 NULL
117529 +stats_read_ul_32751 stats_read_ul 3 32751 NULL
117530 +vmci_transport_dgram_dequeue_32775 vmci_transport_dgram_dequeue 4 32775 NULL
117531 +sctp_tsnmap_grow_32784 sctp_tsnmap_grow 2 32784 NULL
117532 +rproc_name_read_32805 rproc_name_read 3 32805 NULL
117533 +sta_tx_latency_stat_read_32862 sta_tx_latency_stat_read 3 32862 NULL
117534 +new_tape_buffer_32866 new_tape_buffer 2 32866 NULL
117535 +ath6kl_usb_submit_ctrl_in_32880 ath6kl_usb_submit_ctrl_in 6 32880 NULL nohasharray
117536 +cifs_writedata_alloc_32880 cifs_writedata_alloc 1 32880 &ath6kl_usb_submit_ctrl_in_32880
117537 +vp702x_usb_inout_cmd_32884 vp702x_usb_inout_cmd 4-6 32884 NULL
117538 +tipc_link_iovec_xmit_fast_32913 tipc_link_iovec_xmit_fast 3 32913 NULL nohasharray
117539 +il_dbgfs_tx_stats_read_32913 il_dbgfs_tx_stats_read 3 32913 &tipc_link_iovec_xmit_fast_32913
117540 +zlib_inflate_workspacesize_32927 zlib_inflate_workspacesize 0 32927 NULL
117541 +rmap_recycle_32938 rmap_recycle 3 32938 NULL
117542 +compat_filldir_32999 compat_filldir 3 32999 NULL
117543 +SyS_syslog_33007 SyS_syslog 3 33007 NULL
117544 +br_multicast_set_hash_max_33012 br_multicast_set_hash_max 2 33012 NULL
117545 +write_file_bt_ant_diversity_33019 write_file_bt_ant_diversity 3 33019 NULL
117546 +snd_pcm_prepare_33036 snd_pcm_prepare 0 33036 NULL
117547 +mic_virtio_copy_to_user_33048 mic_virtio_copy_to_user 3 33048 NULL
117548 +SYSC_lgetxattr_33049 SYSC_lgetxattr 4 33049 NULL
117549 +pipeline_dec_packet_in_fifo_full_read_33052 pipeline_dec_packet_in_fifo_full_read 3 33052 NULL
117550 +ebt_compat_match_offset_33053 ebt_compat_match_offset 0-2 33053 NULL
117551 +bitmap_resize_33054 bitmap_resize 2 33054 NULL
117552 +stats_dot11RTSSuccessCount_read_33065 stats_dot11RTSSuccessCount_read 3 33065 NULL
117553 +sel_read_checkreqprot_33068 sel_read_checkreqprot 3 33068 NULL
117554 +alloc_tio_33077 alloc_tio 3 33077 NULL
117555 +acl_permission_check_33083 acl_permission_check 0 33083 NULL
117556 +fb_sys_write_33130 fb_sys_write 3 33130 NULL
117557 +notify_change_33143 notify_change 0 33143 NULL
117558 +SyS_poll_33152 SyS_poll 2 33152 NULL
117559 +_pci_add_cap_save_buffer_33153 _pci_add_cap_save_buffer 4 33153 NULL
117560 +debug_debug6_read_33168 debug_debug6_read 3 33168 NULL
117561 +dataflash_read_fact_otp_33204 dataflash_read_fact_otp 3-2 33204 NULL
117562 +pp_read_33210 pp_read 3 33210 NULL
117563 +xfs_file_aio_write_33234 xfs_file_aio_write 4 33234 NULL
117564 +snd_pcm_plug_client_size_33267 snd_pcm_plug_client_size 0-2 33267 NULL
117565 +cachefiles_cook_key_33274 cachefiles_cook_key 2 33274 NULL
117566 +sync_pt_create_33282 sync_pt_create 2 33282 NULL
117567 +mcs7830_get_reg_33308 mcs7830_get_reg 3 33308 NULL
117568 +isku_sysfs_read_keys_easyzone_33318 isku_sysfs_read_keys_easyzone 6 33318 NULL
117569 +vx_send_irq_dsp_33329 vx_send_irq_dsp 0 33329 NULL
117570 +joydev_ioctl_33343 joydev_ioctl 2 33343 NULL
117571 +lov_stripesize_seq_write_33353 lov_stripesize_seq_write 3 33353 NULL
117572 +create_xattr_datum_33356 create_xattr_datum 5 33356 NULL nohasharray
117573 +irq_pkt_threshold_read_33356 irq_pkt_threshold_read 3 33356 &create_xattr_datum_33356
117574 +pvscsi_allocate_sg_33357 pvscsi_allocate_sg 0 33357 NULL
117575 +read_file_regidx_33370 read_file_regidx 3 33370 NULL
117576 +ieee80211_if_read_dropped_frames_no_route_33383 ieee80211_if_read_dropped_frames_no_route 3 33383 NULL
117577 +scsi_varlen_cdb_length_33385 scsi_varlen_cdb_length 0 33385 NULL
117578 +nvc0_ram_create__33391 nvc0_ram_create_ 5 33391 NULL
117579 +ocfs2_allocate_unwritten_extents_33394 ocfs2_allocate_unwritten_extents 2-3 33394 NULL
117580 +cfs_trace_copyin_string_33396 cfs_trace_copyin_string 4 33396 NULL
117581 +snd_pcm_capture_ioctl1_33408 snd_pcm_capture_ioctl1 0 33408 NULL
117582 +hash_netiface6_expire_33421 hash_netiface6_expire 4 33421 NULL
117583 +dis_tap_write_33426 dis_tap_write 3 33426 NULL
117584 +message_stats_list_33440 message_stats_list 5 33440 NULL
117585 +ovs_vport_alloc_33475 ovs_vport_alloc 1 33475 NULL
117586 +create_entry_33479 create_entry 2 33479 NULL
117587 +ip_setsockopt_33487 ip_setsockopt 5 33487 NULL
117588 +res_counter_read_33499 res_counter_read 4 33499 NULL
117589 +hash_netnet4_expire_33500 hash_netnet4_expire 4 33500 NULL
117590 +fb_read_33506 fb_read 3 33506 NULL
117591 +musb_test_mode_write_33518 musb_test_mode_write 3 33518 NULL
117592 +ahash_setkey_unaligned_33521 ahash_setkey_unaligned 3 33521 NULL
117593 +nes_alloc_fast_reg_page_list_33523 nes_alloc_fast_reg_page_list 2 33523 NULL
117594 +aggr_size_rx_size_read_33526 aggr_size_rx_size_read 3 33526 NULL
117595 +tomoyo_read_self_33539 tomoyo_read_self 3 33539 NULL nohasharray
117596 +osc_max_rpcs_in_flight_seq_write_33539 osc_max_rpcs_in_flight_seq_write 3 33539 &tomoyo_read_self_33539
117597 +count_subheaders_33591 count_subheaders 0 33591 NULL
117598 +scsi_execute_33596 scsi_execute 5 33596 NULL
117599 +comedi_buf_write_n_allocated_33604 comedi_buf_write_n_allocated 0 33604 NULL
117600 +xt_compat_target_offset_33608 xt_compat_target_offset 0 33608 NULL
117601 +usb_gstrings_attach_33615 usb_gstrings_attach 3 33615 NULL nohasharray
117602 +il_dbgfs_qos_read_33615 il_dbgfs_qos_read 3 33615 &usb_gstrings_attach_33615
117603 +stride_page_count_33641 stride_page_count 2 33641 NULL
117604 +irq_blk_threshold_read_33666 irq_blk_threshold_read 3 33666 NULL
117605 +inw_p_33668 inw_p 0 33668 NULL
117606 +arp_hdr_len_33671 arp_hdr_len 0 33671 NULL
117607 +i2c_hid_alloc_buffers_33673 i2c_hid_alloc_buffers 2 33673 NULL
117608 +submit_one_bio_33683 submit_one_bio 0 33683 NULL
117609 +nv50_disp_dmac_create__33696 nv50_disp_dmac_create_ 6 33696 NULL
117610 +netlink_sendmsg_33708 netlink_sendmsg 4 33708 NULL
117611 +tipc_link_stats_33716 tipc_link_stats 3 33716 NULL
117612 +pvr2_stream_buffer_count_33719 pvr2_stream_buffer_count 2 33719 NULL
117613 +write_file_spectral_count_33723 write_file_spectral_count 3 33723 NULL
117614 +read_file_node_recv_33729 read_file_node_recv 3 33729 NULL
117615 +rtw_cbuf_alloc23a_33740 rtw_cbuf_alloc23a 1 33740 NULL
117616 +vifs_state_read_33762 vifs_state_read 3 33762 NULL
117617 +hashtab_create_33769 hashtab_create 3 33769 NULL
117618 +i8042_create_aux_port_33777 i8042_create_aux_port 0 33777 NULL
117619 +if_sdio_read_rx_len_33800 if_sdio_read_rx_len 0 33800 NULL
117620 +filter_write_33819 filter_write 3 33819 NULL
117621 +sep_create_msgarea_context_33829 sep_create_msgarea_context 4 33829 NULL
117622 +scrub_setup_recheck_block_33831 scrub_setup_recheck_block 5-4 33831 NULL
117623 +ext4_journal_extend_33835 ext4_journal_extend 2 33835 NULL
117624 +snd_pcm_action_nonatomic_33844 snd_pcm_action_nonatomic 0 33844 NULL
117625 +oz_cdev_write_33852 oz_cdev_write 3 33852 NULL
117626 +get_user_pages_33908 get_user_pages 0 33908 NULL
117627 +sg_nents_33909 sg_nents 0 33909 NULL
117628 +ath6kl_roam_mode_write_33912 ath6kl_roam_mode_write 3 33912 NULL
117629 +queue_logical_block_size_33918 queue_logical_block_size 0 33918 NULL
117630 +sel_read_avc_cache_threshold_33942 sel_read_avc_cache_threshold 3 33942 NULL
117631 +lpfc_idiag_ctlacc_read_33943 lpfc_idiag_ctlacc_read 3 33943 NULL
117632 +read_file_tgt_rx_stats_33944 read_file_tgt_rx_stats 3 33944 NULL
117633 +__proc_dump_kernel_33954 __proc_dump_kernel 5 33954 NULL
117634 +btrfs_delalloc_reserve_metadata_33963 btrfs_delalloc_reserve_metadata 0 33963 NULL
117635 +vga_switcheroo_debugfs_write_33984 vga_switcheroo_debugfs_write 3 33984 NULL
117636 +lbs_lowrssi_write_34025 lbs_lowrssi_write 3 34025 NULL
117637 +ppp_write_34034 ppp_write 3 34034 NULL
117638 +tty_insert_flip_string_34042 tty_insert_flip_string 3-0 34042 NULL
117639 +calc_linear_pos_34067 calc_linear_pos 0-4 34067 NULL
117640 +memcg_update_all_caches_34068 memcg_update_all_caches 1 34068 NULL
117641 +pipeline_pipeline_fifo_full_read_34095 pipeline_pipeline_fifo_full_read 3 34095 NULL
117642 +__irq_domain_add_34101 __irq_domain_add 2 34101 NULL
117643 +proc_scsi_host_write_34107 proc_scsi_host_write 3 34107 NULL
117644 +islpci_mgt_transmit_34133 islpci_mgt_transmit 5 34133 NULL
117645 +ttm_dma_page_pool_free_34135 ttm_dma_page_pool_free 2-0 34135 NULL
117646 +ixgbe_dbg_netdev_ops_write_34141 ixgbe_dbg_netdev_ops_write 3 34141 NULL
117647 +shmem_pread_fast_34147 shmem_pread_fast 3 34147 NULL
117648 +skb_to_sgvec_34171 skb_to_sgvec 0 34171 NULL
117649 +rsi_debug_zone_write_34206 rsi_debug_zone_write 3 34206 NULL
117650 +ext4_da_write_begin_34215 ext4_da_write_begin 3-4 34215 NULL
117651 +bl_pipe_downcall_34264 bl_pipe_downcall 3 34264 NULL
117652 +device_private_init_34279 device_private_init 0 34279 NULL
117653 +ext4_get_groups_count_34324 ext4_get_groups_count 0 34324 NULL
117654 +pcpu_need_to_extend_34326 pcpu_need_to_extend 0 34326 NULL nohasharray
117655 +iov_iter_single_seg_count_34326 iov_iter_single_seg_count 0 34326 &pcpu_need_to_extend_34326
117656 +crypto_ablkcipher_ivsize_34363 crypto_ablkcipher_ivsize 0 34363 NULL nohasharray
117657 +sync_page_io_34363 sync_page_io 3 34363 &crypto_ablkcipher_ivsize_34363
117658 +rngapi_reset_34366 rngapi_reset 3 34366 NULL
117659 +_iwl_dbgfs_low_latency_write_34378 _iwl_dbgfs_low_latency_write 3 34378 NULL nohasharray
117660 +ea_read_34378 ea_read 0 34378 &_iwl_dbgfs_low_latency_write_34378
117661 +fuse_send_read_34379 fuse_send_read 4 34379 NULL
117662 +av7110_vbi_write_34384 av7110_vbi_write 3 34384 NULL
117663 +usbvision_v4l2_read_34386 usbvision_v4l2_read 3 34386 NULL
117664 +read_rbu_image_type_34387 read_rbu_image_type 6 34387 NULL
117665 +iwl_calib_set_34400 iwl_calib_set 3 34400 NULL nohasharray
117666 +ivtv_read_pos_34400 ivtv_read_pos 3 34400 &iwl_calib_set_34400
117667 +wd_exp_mode_write_34407 wd_exp_mode_write 3 34407 NULL
117668 +nl80211_send_disassoc_34424 nl80211_send_disassoc 4 34424 NULL
117669 +__extent_read_full_page_34437 __extent_read_full_page 0 34437 NULL
117670 +usbtest_alloc_urb_34446 usbtest_alloc_urb 3-5 34446 NULL
117671 +mwifiex_regrdwr_read_34472 mwifiex_regrdwr_read 3 34472 NULL
117672 +skcipher_sndbuf_34476 skcipher_sndbuf 0 34476 NULL
117673 +i2o_parm_field_get_34477 i2o_parm_field_get 5 34477 NULL
117674 +security_inode_permission_34488 security_inode_permission 0 34488 NULL
117675 +SyS_pwritev_34494 SyS_pwritev 3 34494 NULL
117676 +qp_alloc_res_34496 qp_alloc_res 5 34496 NULL
117677 +lu_buf_check_and_alloc_34505 lu_buf_check_and_alloc 2 34505 NULL
117678 +tracing_stats_read_34537 tracing_stats_read 3 34537 NULL nohasharray
117679 +ext4_fallocate_34537 ext4_fallocate 4-3 34537 &tracing_stats_read_34537
117680 +hugetlbfs_read_actor_34547 hugetlbfs_read_actor 2-5-4-0 34547 NULL
117681 +dbBackSplit_34561 dbBackSplit 0 34561 NULL
117682 +alloc_ieee80211_rsl_34564 alloc_ieee80211_rsl 1 34564 NULL nohasharray
117683 +self_check_peb_ec_hdr_34564 self_check_peb_ec_hdr 0 34564 &alloc_ieee80211_rsl_34564
117684 +lov_stripecount_seq_write_34582 lov_stripecount_seq_write 3 34582 NULL
117685 +init_send_hfcd_34586 init_send_hfcd 1 34586 NULL
117686 +inet6_ifla6_size_34591 inet6_ifla6_size 0 34591 NULL
117687 +ceph_msgpool_init_34599 ceph_msgpool_init 4 34599 NULL nohasharray
117688 +cw1200_queue_init_34599 cw1200_queue_init 4 34599 &ceph_msgpool_init_34599
117689 +bio_integrity_bytes_34602 bio_integrity_bytes 2 34602 NULL
117690 +__jffs2_ref_totlen_34609 __jffs2_ref_totlen 0 34609 NULL nohasharray
117691 +mtd_write_34609 mtd_write 0 34609 &__jffs2_ref_totlen_34609
117692 +__cfg80211_disconnected_34622 __cfg80211_disconnected 3 34622 NULL
117693 +cnic_alloc_dma_34641 cnic_alloc_dma 3 34641 NULL
117694 +kvm_set_spte_hva_34671 kvm_set_spte_hva 2 34671 NULL
117695 +sleep_auth_write_34676 sleep_auth_write 3 34676 NULL
117696 +isr_fiqs_read_34687 isr_fiqs_read 3 34687 NULL
117697 +batadv_tvlv_realloc_packet_buff_34688 batadv_tvlv_realloc_packet_buff 3-4 34688 NULL
117698 +port_print_34704 port_print 3 34704 NULL
117699 +ieee80211_if_read_num_sta_ps_34722 ieee80211_if_read_num_sta_ps 3 34722 NULL
117700 +platform_list_read_file_34734 platform_list_read_file 3 34734 NULL
117701 +reg_w_ixbuf_34736 reg_w_ixbuf 4 34736 NULL
117702 +lsm_alloc_plain_34755 lsm_alloc_plain 1 34755 NULL
117703 +bootmode_store_34762 bootmode_store 4 34762 NULL
117704 +device_add_34766 device_add 0 34766 NULL
117705 +qib_cdev_init_34778 qib_cdev_init 1 34778 NULL
117706 +SYSC_keyctl_34800 SYSC_keyctl 4 34800 NULL
117707 +can_nocow_extent_34801 can_nocow_extent 2 34801 NULL
117708 +drbd_get_max_capacity_34804 drbd_get_max_capacity 0 34804 NULL
117709 +ll_setxattr_34806 ll_setxattr 4 34806 NULL
117710 +file_page_index_34820 file_page_index 0-2 34820 NULL
117711 +bio_segments_34832 bio_segments 0 34832 NULL
117712 +b43_debugfs_write_34838 b43_debugfs_write 3 34838 NULL
117713 +nl_portid_hash_zalloc_34843 nl_portid_hash_zalloc 1 34843 NULL
117714 +acpi_system_write_wakeup_device_34853 acpi_system_write_wakeup_device 3 34853 NULL
117715 +usb_serial_generic_prepare_write_buffer_34857 usb_serial_generic_prepare_write_buffer 3 34857 NULL
117716 +ieee80211_if_read_txpower_34871 ieee80211_if_read_txpower 3 34871 NULL
117717 +msg_print_text_34889 msg_print_text 0 34889 NULL
117718 +ieee80211_if_write_34894 ieee80211_if_write 3 34894 NULL
117719 +si476x_radio_read_rsq_primary_blob_34916 si476x_radio_read_rsq_primary_blob 3 34916 NULL
117720 +__inode_permission_34925 __inode_permission 0 34925 NULL nohasharray
117721 +btrfs_super_chunk_root_34925 btrfs_super_chunk_root 0 34925 &__inode_permission_34925
117722 +ceph_aio_write_34930 ceph_aio_write 4 34930 NULL
117723 +sec_flags2str_34933 sec_flags2str 3 34933 NULL
117724 +snd_info_entry_read_34938 snd_info_entry_read 3 34938 NULL
117725 +do_add_page_to_bio_34974 do_add_page_to_bio 2-10 34974 NULL
117726 +schedule_erase_34996 schedule_erase 0 34996 NULL
117727 +rx_rx_hdr_overflow_read_35002 rx_rx_hdr_overflow_read 3 35002 NULL
117728 +l2cap_skbuff_fromiovec_35003 l2cap_skbuff_fromiovec 4-3 35003 NULL
117729 +rtw_cfg80211_rx_p2p_action_public_35010 rtw_cfg80211_rx_p2p_action_public 3 35010 NULL
117730 +sisusb_copy_memory_35016 sisusb_copy_memory 4 35016 NULL
117731 +coda_psdev_read_35029 coda_psdev_read 3 35029 NULL
117732 +pwr_connection_out_of_sync_read_35061 pwr_connection_out_of_sync_read 3 35061 NULL
117733 +__kfifo_uint_must_check_helper_35097 __kfifo_uint_must_check_helper 0-1 35097 NULL
117734 +capi_write_35104 capi_write 3 35104 NULL nohasharray
117735 +tx_tx_done_template_read_35104 tx_tx_done_template_read 3 35104 &capi_write_35104
117736 +ide_settings_proc_write_35110 ide_settings_proc_write 3 35110 NULL
117737 +message_stats_print_35158 message_stats_print 6 35158 NULL
117738 +iscsi_conn_setup_35159 iscsi_conn_setup 2 35159 NULL
117739 +ieee80211_if_read_bssid_35161 ieee80211_if_read_bssid 3 35161 NULL
117740 +compat_SyS_pselect6_35203 compat_SyS_pselect6 1 35203 NULL
117741 +unix_stream_recvmsg_35210 unix_stream_recvmsg 4 35210 NULL
117742 +security_key_getsecurity_35218 security_key_getsecurity 0 35218 NULL nohasharray
117743 +striped_read_35218 striped_read 0-2 35218 &security_key_getsecurity_35218
117744 +rx_rx_cmplt_task_read_35226 rx_rx_cmplt_task_read 3 35226 NULL
117745 +set_fd_set_35249 set_fd_set 1 35249 NULL
117746 +ioapic_setup_resources_35255 ioapic_setup_resources 1 35255 NULL
117747 +dis_disc_write_35265 dis_disc_write 3 35265 NULL
117748 +dma_show_regs_35266 dma_show_regs 3 35266 NULL
117749 +irda_recvmsg_stream_35280 irda_recvmsg_stream 4 35280 NULL
117750 +i2o_block_end_request_35282 i2o_block_end_request 3 35282 NULL
117751 +isr_rx_rdys_read_35283 isr_rx_rdys_read 3 35283 NULL
117752 +__btrfs_buffered_write_35311 __btrfs_buffered_write 3-0 35311 NULL nohasharray
117753 +brcmf_sdio_forensic_read_35311 brcmf_sdio_forensic_read 3 35311 &__btrfs_buffered_write_35311
117754 +tracing_read_pipe_35312 tracing_read_pipe 3 35312 NULL
117755 +sta_tx_latency_stat_write_35323 sta_tx_latency_stat_write 3 35323 NULL
117756 +ieee80211_if_fmt_ap_power_level_35347 ieee80211_if_fmt_ap_power_level 3 35347 NULL
117757 +nouveau_devinit_create__35348 nouveau_devinit_create_ 4 35348 NULL
117758 +ieee80211_rx_mgmt_deauth_35351 ieee80211_rx_mgmt_deauth 3 35351 NULL
117759 +compat_filldir64_35354 compat_filldir64 3 35354 NULL
117760 +read_kmem_35372 read_kmem 3 35372 NULL
117761 +SyS_getxattr_35408 SyS_getxattr 4 35408 NULL
117762 +rawv6_send_hdrinc_35425 rawv6_send_hdrinc 3 35425 NULL
117763 +iwl_dbgfs_drv_rx_stats_read_35430 iwl_dbgfs_drv_rx_stats_read 3 35430 NULL
117764 +buffer_to_user_35439 buffer_to_user 3 35439 NULL
117765 +efx_mcdi_rpc_async_quiet_35460 efx_mcdi_rpc_async_quiet 4-5 35460 NULL
117766 +macvtap_do_read_35475 macvtap_do_read 3 35475 NULL
117767 +fiemap_prepare_and_copy_exts_35494 fiemap_prepare_and_copy_exts 5 35494 NULL
117768 +btrfs_prealloc_file_range_trans_35500 btrfs_prealloc_file_range_trans 4 35500 NULL
117769 +async_setkey_35521 async_setkey 3 35521 NULL
117770 +__filemap_fdatawrite_range_35528 __filemap_fdatawrite_range 0 35528 NULL
117771 +iwl_dbgfs_bt_traffic_read_35534 iwl_dbgfs_bt_traffic_read 3 35534 NULL
117772 +pstore_mkfile_35536 pstore_mkfile 7 35536 NULL
117773 +rxpipe_tx_xfr_host_int_trig_rx_data_read_35538 rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 NULL
117774 +ocfs2_write_zero_page_35539 ocfs2_write_zero_page 3 35539 NULL
117775 +ibnl_put_attr_35541 ibnl_put_attr 3 35541 NULL
117776 +ieee80211_if_write_smps_35550 ieee80211_if_write_smps 3 35550 NULL
117777 +ext4_blocks_for_truncate_35579 ext4_blocks_for_truncate 0 35579 NULL
117778 +ext2_acl_from_disk_35580 ext2_acl_from_disk 2 35580 NULL
117779 +spk_msg_set_35586 spk_msg_set 3 35586 NULL
117780 +kernel_readv_35617 kernel_readv 3 35617 NULL
117781 +reiserfs_readpages_35629 reiserfs_readpages 4 35629 NULL
117782 +pci_request_regions_35635 pci_request_regions 0 35635 NULL
117783 +ptlrpcd_steal_rqset_35637 ptlrpcd_steal_rqset 0 35637 NULL
117784 +spi_register_board_info_35651 spi_register_board_info 2 35651 NULL
117785 +rdmaltWithLock_35669 rdmaltWithLock 0 35669 NULL
117786 +SYSC_pwritev_35690 SYSC_pwritev 3 35690 NULL
117787 +rds_page_copy_user_35691 rds_page_copy_user 4 35691 NULL
117788 +md_super_write_35703 md_super_write 4 35703 NULL
117789 +iwl_dbgfs_disable_ht40_read_35761 iwl_dbgfs_disable_ht40_read 3 35761 NULL
117790 +udf_alloc_i_data_35786 udf_alloc_i_data 2 35786 NULL
117791 +pvr2_hdw_cpufw_get_35824 pvr2_hdw_cpufw_get 0-4-2 35824 NULL
117792 +tx_tx_cmplt_read_35854 tx_tx_cmplt_read 3 35854 NULL
117793 +vx_query_hbuffer_size_35859 vx_query_hbuffer_size 0 35859 NULL
117794 +mthca_buf_alloc_35861 mthca_buf_alloc 2 35861 NULL
117795 +fls64_35862 fls64 0 35862 NULL
117796 +kvm_dirty_bitmap_bytes_35886 kvm_dirty_bitmap_bytes 0 35886 NULL
117797 +ieee80211_if_fmt_dot11MeshRetryTimeout_35890 ieee80211_if_fmt_dot11MeshRetryTimeout 3 35890 NULL
117798 +uwb_rc_cmd_done_35892 uwb_rc_cmd_done 4 35892 NULL
117799 +kernel_setsockopt_35913 kernel_setsockopt 5 35913 NULL
117800 +rbio_nr_pages_35916 rbio_nr_pages 0-1-2 35916 NULL
117801 +sctp_tsnmap_mark_35929 sctp_tsnmap_mark 2 35929 NULL
117802 +rx_defrag_init_called_read_35935 rx_defrag_init_called_read 3 35935 NULL
117803 +put_cmsg_compat_35937 put_cmsg_compat 4 35937 NULL
117804 +ext_rts51x_sd_execute_write_data_35971 ext_rts51x_sd_execute_write_data 9 35971 NULL
117805 +generic_ocp_read_35974 generic_ocp_read 3 35974 NULL nohasharray
117806 +ceph_buffer_new_35974 ceph_buffer_new 1 35974 &generic_ocp_read_35974
117807 +acl_alloc_35979 acl_alloc 1 35979 NULL
117808 +device_add_class_symlinks_35985 device_add_class_symlinks 0 35985 NULL
117809 +kuc_alloc_35998 kuc_alloc 1 35998 NULL nohasharray
117810 +write_file_antenna_35998 write_file_antenna 3 35998 &kuc_alloc_35998
117811 +scsi_transfer_length_36011 scsi_transfer_length 0 36011 NULL
117812 +il3945_ucode_tx_stats_read_36016 il3945_ucode_tx_stats_read 3 36016 NULL
117813 +ubi_eba_write_leb_36029 ubi_eba_write_leb 0 36029 NULL
117814 +__videobuf_alloc_36031 __videobuf_alloc 1 36031 NULL
117815 +account_shadowed_36048 account_shadowed 2 36048 NULL
117816 +gpio_power_read_36059 gpio_power_read 3 36059 NULL
117817 +snd_pcm_playback_hw_avail_36061 snd_pcm_playback_hw_avail 0 36061 NULL
117818 +write_emulate_36065 write_emulate 2-4 36065 NULL
117819 +stack_max_size_write_36068 stack_max_size_write 3 36068 NULL
117820 +radeon_vm_num_pdes_36070 radeon_vm_num_pdes 0 36070 NULL
117821 +ieee80211_if_fmt_peer_36071 ieee80211_if_fmt_peer 3 36071 NULL
117822 +ieee80211_if_write_tsf_36077 ieee80211_if_write_tsf 3 36077 NULL
117823 +snd_pcm_plug_read_transfer_36080 snd_pcm_plug_read_transfer 0-3 36080 NULL
117824 +mtip_hw_read_device_status_36082 mtip_hw_read_device_status 3 36082 NULL
117825 +vga_arb_write_36112 vga_arb_write 3 36112 NULL
117826 +simple_xattr_alloc_36118 simple_xattr_alloc 2 36118 NULL
117827 +ext3_readpages_36144 ext3_readpages 4 36144 NULL
117828 +twl_set_36154 twl_set 2 36154 NULL
117829 +b1_alloc_card_36155 b1_alloc_card 1 36155 NULL
117830 +snd_korg1212_copy_from_36169 snd_korg1212_copy_from 6 36169 NULL
117831 +SyS_kexec_load_36176 SyS_kexec_load 2 36176 NULL
117832 +ramoops_init_przs_36199 ramoops_init_przs 4 36199 NULL
117833 +SYSC_sched_getaffinity_36208 SYSC_sched_getaffinity 2 36208 NULL
117834 +SYSC_process_vm_readv_36216 SYSC_process_vm_readv 3-5 36216 NULL
117835 +atomic_stats_read_36228 atomic_stats_read 3 36228 NULL
117836 +rtw_cfg80211_set_wpa_ie_36236 rtw_cfg80211_set_wpa_ie 3 36236 NULL
117837 +viafb_iga1_odev_proc_write_36241 viafb_iga1_odev_proc_write 3 36241 NULL
117838 +SYSC_getxattr_36242 SYSC_getxattr 4 36242 NULL
117839 +vmsplice_to_user_36245 vmsplice_to_user 3 36245 NULL nohasharray
117840 +rproc_recovery_read_36245 rproc_recovery_read 3 36245 &vmsplice_to_user_36245
117841 +cfs_hash_buckets_realloc_36276 cfs_hash_buckets_realloc 4 36276 NULL nohasharray
117842 +usb_buffer_alloc_36276 usb_buffer_alloc 2 36276 &cfs_hash_buckets_realloc_36276
117843 +codec_reg_read_file_36280 codec_reg_read_file 3 36280 NULL
117844 +crypto_shash_digestsize_36284 crypto_shash_digestsize 0 36284 NULL
117845 +lpfc_debugfs_dif_err_read_36303 lpfc_debugfs_dif_err_read 3 36303 NULL
117846 +cfg80211_rx_mlme_mgmt_36306 cfg80211_rx_mlme_mgmt 3 36306 NULL
117847 +ad7879_spi_xfer_36311 ad7879_spi_xfer 3 36311 NULL
117848 +__compat_sys_pwritev64_36328 __compat_sys_pwritev64 3 36328 NULL nohasharray
117849 +fat_compat_ioctl_filldir_36328 fat_compat_ioctl_filldir 3 36328 &__compat_sys_pwritev64_36328
117850 +lc_create_36332 lc_create 4 36332 NULL
117851 +jbd2_journal_init_revoke_table_36336 jbd2_journal_init_revoke_table 1 36336 NULL
117852 +isku_sysfs_read_key_mask_36343 isku_sysfs_read_key_mask 6 36343 NULL
117853 +ath6kl_regwrite_write_36351 ath6kl_regwrite_write 3 36351 NULL
117854 +v9fs_file_readn_36353 v9fs_file_readn 4 36353 NULL
117855 +to_sector_36361 to_sector 0-1 36361 NULL
117856 +tunables_read_36385 tunables_read 3 36385 NULL
117857 +afs_alloc_flat_call_36399 afs_alloc_flat_call 2-3 36399 NULL
117858 +sierra_write_36402 sierra_write 4 36402 NULL
117859 +SyS_sethostname_36417 SyS_sethostname 2 36417 NULL
117860 +sctp_tsnmap_init_36446 sctp_tsnmap_init 2 36446 NULL
117861 +alloc_etherdev_mqs_36450 alloc_etherdev_mqs 1 36450 NULL
117862 +SyS_process_vm_writev_36476 SyS_process_vm_writev 3-5 36476 NULL
117863 +lock_and_cleanup_extent_if_need_36480 lock_and_cleanup_extent_if_need 0 36480 NULL
117864 +b43_nphy_load_samples_36481 b43_nphy_load_samples 3 36481 NULL
117865 +tx_tx_checksum_result_read_36490 tx_tx_checksum_result_read 3 36490 NULL nohasharray
117866 +ip6_append_data_36490 ip6_append_data 4 36490 &tx_tx_checksum_result_read_36490
117867 +__hwahc_op_set_ptk_36510 __hwahc_op_set_ptk 5 36510 NULL
117868 +mcam_v4l_read_36513 mcam_v4l_read 3 36513 NULL
117869 +_iwl_dbgfs_fw_nmi_write_36515 _iwl_dbgfs_fw_nmi_write 3 36515 NULL
117870 +get_param_l_36518 get_param_l 0 36518 NULL
117871 +ieee80211_if_read_fwded_frames_36520 ieee80211_if_read_fwded_frames 3 36520 NULL
117872 +crypto_aead_authsize_36537 crypto_aead_authsize 0 36537 NULL
117873 +cpu_type_read_36540 cpu_type_read 3 36540 NULL
117874 +__kfifo_to_user_36555 __kfifo_to_user 3-0 36555 NULL
117875 +btrfs_get_token_64_36572 btrfs_get_token_64 0 36572 NULL
117876 +__erst_read_36579 __erst_read 0 36579 NULL
117877 +put_cmsg_36589 put_cmsg 4 36589 NULL
117878 +fat_ioctl_filldir_36621 fat_ioctl_filldir 3 36621 NULL
117879 +vxge_config_vpaths_36636 vxge_config_vpaths 0 36636 NULL
117880 +convert_extent_item_v0_36645 convert_extent_item_v0 4 36645 NULL
117881 +ced_ioctl_36647 ced_ioctl 2 36647 NULL
117882 +lpfc_idiag_extacc_alloc_get_36648 lpfc_idiag_extacc_alloc_get 0-3 36648 NULL
117883 +osd_req_list_collection_objects_36664 osd_req_list_collection_objects 5 36664 NULL
117884 +iscsi_host_alloc_36671 iscsi_host_alloc 2 36671 NULL
117885 +xillybus_read_36678 xillybus_read 3 36678 NULL
117886 +gsmtty_write_36702 gsmtty_write 3 36702 NULL
117887 +snd_rawmidi_kernel_read1_36740 snd_rawmidi_kernel_read1 4-0 36740 NULL
117888 +cxgbi_device_register_36746 cxgbi_device_register 1-2 36746 NULL
117889 +ps_poll_upsd_timeouts_read_36755 ps_poll_upsd_timeouts_read 3 36755 NULL
117890 +i40e_init_lan_hmc_36796 i40e_init_lan_hmc 5-4-3-2 36796 NULL
117891 +proc_fault_inject_read_36802 proc_fault_inject_read 3 36802 NULL
117892 +hiddev_ioctl_36816 hiddev_ioctl 2 36816 NULL
117893 +int_hardware_entry_36833 int_hardware_entry 3 36833 NULL
117894 +fc_change_queue_depth_36841 fc_change_queue_depth 2 36841 NULL
117895 +keyctl_describe_key_36853 keyctl_describe_key 3 36853 NULL
117896 +cm_write_36858 cm_write 3 36858 NULL
117897 +tipc_link_iovec_long_xmit_36871 tipc_link_iovec_long_xmit 3 36871 NULL nohasharray
117898 +tx_tx_data_programmed_read_36871 tx_tx_data_programmed_read 3 36871 &tipc_link_iovec_long_xmit_36871
117899 +svc_setsockopt_36876 svc_setsockopt 5 36876 NULL
117900 +raid56_parity_write_36877 raid56_parity_write 5 36877 NULL
117901 +__btrfs_map_block_36883 __btrfs_map_block 3 36883 NULL
117902 +ib_ucm_alloc_data_36885 ib_ucm_alloc_data 3 36885 NULL
117903 +selinux_inode_notifysecctx_36896 selinux_inode_notifysecctx 3 36896 NULL
117904 +OS_kmalloc_36909 OS_kmalloc 1 36909 NULL
117905 +il4965_rs_sta_dbgfs_scale_table_write_36979 il4965_rs_sta_dbgfs_scale_table_write 3 36979 NULL
117906 +drbd_new_dev_size_36998 drbd_new_dev_size 0-3 36998 NULL
117907 +auok190xfb_write_37001 auok190xfb_write 3 37001 NULL
117908 +setxattr_37006 setxattr 4 37006 NULL
117909 +command_file_read_37038 command_file_read 3 37038 NULL
117910 +figure_loop_size_37051 figure_loop_size 2-3 37051 NULL
117911 +qp_broker_create_37053 qp_broker_create 6-5 37053 NULL nohasharray
117912 +ieee80211_if_read_drop_unencrypted_37053 ieee80211_if_read_drop_unencrypted 3 37053 &qp_broker_create_37053
117913 +_iwl_dbgfs_bcast_filters_macs_write_37069 _iwl_dbgfs_bcast_filters_macs_write 3 37069 NULL
117914 +SYSC_setxattr_37078 SYSC_setxattr 4 37078 NULL
117915 +parse_command_37079 parse_command 2 37079 NULL
117916 +pipeline_cs_rx_packet_in_read_37089 pipeline_cs_rx_packet_in_read 3 37089 NULL
117917 +tun_get_user_37094 tun_get_user 5 37094 NULL
117918 +has_wrprotected_page_37123 has_wrprotected_page 2-3 37123 NULL
117919 +snd_hda_get_conn_list_37132 snd_hda_get_conn_list 0 37132 NULL
117920 +mtt_free_res_37144 mtt_free_res 5 37144 NULL
117921 +msg_word_37164 msg_word 0 37164 NULL
117922 +f2fs_direct_IO_37167 f2fs_direct_IO 4 37167 NULL
117923 +vcc_recvmsg_37198 vcc_recvmsg 4 37198 NULL
117924 +forced_ps_write_37209 forced_ps_write 3 37209 NULL
117925 +crypto_shash_descsize_37212 crypto_shash_descsize 0 37212 NULL nohasharray
117926 +ext4_ind_direct_IO_37212 ext4_ind_direct_IO 4-0 37212 &crypto_shash_descsize_37212
117927 +regmap_access_read_file_37223 regmap_access_read_file 3 37223 NULL
117928 +__do_replace_37227 __do_replace 5 37227 NULL
117929 +iwl_dbgfs_d3_sram_read_37237 iwl_dbgfs_d3_sram_read 3 37237 NULL
117930 +rx_filter_dup_filter_read_37238 rx_filter_dup_filter_read 3 37238 NULL
117931 +prot_queue_del_37258 prot_queue_del 0 37258 NULL
117932 +exofs_max_io_pages_37263 exofs_max_io_pages 0-2 37263 NULL
117933 +_iwl_dbgfs_fw_restart_write_37270 _iwl_dbgfs_fw_restart_write 3 37270 NULL
117934 +request_threaded_irq_37303 request_threaded_irq 0 37303 NULL
117935 +ieee80211_if_read_power_mode_37305 ieee80211_if_read_power_mode 3 37305 NULL
117936 +ext3_direct_IO_37308 ext3_direct_IO 4 37308 NULL
117937 +jffs2_write_dirent_37311 jffs2_write_dirent 5 37311 NULL
117938 +tipc_send_37315 tipc_send 3 37315 NULL
117939 +l2cap_create_connless_pdu_37327 l2cap_create_connless_pdu 3 37327 NULL nohasharray
117940 +bnx2x_vf_fill_fw_str_37327 bnx2x_vf_fill_fw_str 3 37327 &l2cap_create_connless_pdu_37327
117941 +scsi_mode_select_37330 scsi_mode_select 6 37330 NULL
117942 +rxrpc_server_sendmsg_37331 rxrpc_server_sendmsg 4 37331 NULL
117943 +security_inode_getsecurity_37354 security_inode_getsecurity 0 37354 NULL
117944 +hci_sock_sendmsg_37420 hci_sock_sendmsg 4 37420 NULL
117945 +acpi_os_allocate_zeroed_37422 acpi_os_allocate_zeroed 1 37422 NULL
117946 +tty_insert_flip_string_fixed_flag_37428 tty_insert_flip_string_fixed_flag 4-0 37428 NULL
117947 +iwl_print_last_event_logs_37433 iwl_print_last_event_logs 0-7-9 37433 NULL
117948 +fru_alloc_37442 fru_alloc 1 37442 NULL
117949 +tcp_established_options_37450 tcp_established_options 0 37450 NULL
117950 +brcmf_sdio_dump_console_37455 brcmf_sdio_dump_console 4 37455 NULL
117951 +get_est_timing_37484 get_est_timing 0 37484 NULL
117952 +kmem_realloc_37489 kmem_realloc 2 37489 NULL
117953 +bitmap_dirty_bits_37503 bitmap_dirty_bits 2 37503 NULL
117954 +osc_active_seq_write_37514 osc_active_seq_write 3 37514 NULL
117955 +bdev_writeseg_37519 bdev_writeseg 2-3 37519 NULL
117956 +xz_dec_test_write_37527 xz_dec_test_write 3 37527 NULL
117957 +fault_inject_read_37534 fault_inject_read 3 37534 NULL
117958 +hdr_size_37536 hdr_size 0 37536 NULL
117959 +extent_map_end_37550 extent_map_end 0 37550 NULL
117960 +sep_create_dcb_dmatables_context_37551 sep_create_dcb_dmatables_context 6 37551 NULL
117961 +fat_cont_expand_37552 fat_cont_expand 0 37552 NULL
117962 +xhci_alloc_streams_37586 xhci_alloc_streams 5 37586 NULL
117963 +qla2x00_debounce_register_37597 qla2x00_debounce_register 0 37597 NULL
117964 +kvm_read_guest_page_mmu_37611 kvm_read_guest_page_mmu 6 37611 NULL
117965 +SYSC_mbind_37622 SYSC_mbind 5 37622 NULL
117966 +SyS_mbind_37638 SyS_mbind 5 37638 NULL
117967 +may_delete_37656 may_delete 0 37656 NULL
117968 +bio_copy_user_iov_37660 bio_copy_user_iov 4 37660 NULL
117969 +vmw_framebuffer_dmabuf_dirty_37661 vmw_framebuffer_dmabuf_dirty 6 37661 NULL nohasharray
117970 +rfcomm_sock_sendmsg_37661 rfcomm_sock_sendmsg 4 37661 &vmw_framebuffer_dmabuf_dirty_37661
117971 +SYSC_get_mempolicy_37664 SYSC_get_mempolicy 3 37664 NULL
117972 +__wa_seg_calculate_isoc_frame_count_37672 __wa_seg_calculate_isoc_frame_count 0 37672 NULL
117973 +ieee80211_if_read_rc_rateidx_mcs_mask_2ghz_37675 ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 NULL
117974 +regmap_map_read_file_37685 regmap_map_read_file 3 37685 NULL
117975 +nametbl_header_37698 nametbl_header 2-0 37698 NULL
117976 +__le32_to_cpup_37702 __le32_to_cpup 0 37702 NULL
117977 +dynamic_ps_timeout_write_37713 dynamic_ps_timeout_write 3 37713 NULL
117978 +read_enabled_file_bool_37744 read_enabled_file_bool 3 37744 NULL
117979 +ocfs2_control_cfu_37750 ocfs2_control_cfu 2 37750 NULL
117980 +ipath_cdev_init_37752 ipath_cdev_init 1 37752 NULL
117981 +dccp_setsockopt_cscov_37766 dccp_setsockopt_cscov 2 37766 NULL
117982 +il4965_rs_sta_dbgfs_rate_scale_data_read_37792 il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 NULL
117983 +smk_read_logging_37804 smk_read_logging 3 37804 NULL
117984 +ocrdma_alloc_frmr_page_list_37815 ocrdma_alloc_frmr_page_list 2 37815 NULL
117985 +rx_decrypt_key_not_found_read_37820 rx_decrypt_key_not_found_read 3 37820 NULL
117986 +android_get_p2p_addr_37832 android_get_p2p_addr 0 37832 NULL
117987 +o2hb_debug_read_37851 o2hb_debug_read 3 37851 NULL
117988 +xfs_dir2_block_to_sf_37868 xfs_dir2_block_to_sf 3 37868 NULL
117989 +set_registers_37883 set_registers 4 37883 NULL
117990 +btrfs_stack_file_extent_disk_bytenr_37888 btrfs_stack_file_extent_disk_bytenr 0 37888 NULL
117991 +_rtw_malloc_37928 _rtw_malloc 1 37928 NULL nohasharray
117992 +pkt_alloc_packet_data_37928 pkt_alloc_packet_data 1 37928 &_rtw_malloc_37928
117993 +read_rbu_packet_size_37939 read_rbu_packet_size 6 37939 NULL
117994 +write_file_bool_37957 write_file_bool 3 37957 NULL
117995 +fifo_alloc_37961 fifo_alloc 1 37961 NULL
117996 +rds_rdma_extra_size_37990 rds_rdma_extra_size 0 37990 NULL
117997 +persistent_ram_old_size_37997 persistent_ram_old_size 0 37997 NULL
117998 +vfs_readv_38011 vfs_readv 3 38011 NULL
117999 +aggr_recv_addba_req_evt_38037 aggr_recv_addba_req_evt 4 38037 NULL
118000 +il_dbgfs_chain_noise_read_38044 il_dbgfs_chain_noise_read 3 38044 NULL nohasharray
118001 +klsi_105_prepare_write_buffer_38044 klsi_105_prepare_write_buffer 3 38044 &il_dbgfs_chain_noise_read_38044
118002 +SyS_llistxattr_38048 SyS_llistxattr 3 38048 NULL
118003 +sysfs_do_create_link_38051 sysfs_do_create_link 0 38051 NULL
118004 +_xfs_buf_alloc_38058 _xfs_buf_alloc 3 38058 NULL
118005 +nsm_create_handle_38060 nsm_create_handle 4 38060 NULL
118006 +alloc_ltalkdev_38071 alloc_ltalkdev 1 38071 NULL
118007 +wcn36xx_smd_rsp_process_38081 wcn36xx_smd_rsp_process 3 38081 NULL nohasharray
118008 +xfs_buf_readahead_map_38081 xfs_buf_readahead_map 3 38081 &wcn36xx_smd_rsp_process_38081
118009 +uwb_mac_addr_print_38085 uwb_mac_addr_print 2 38085 NULL
118010 +request_key_auth_new_38092 request_key_auth_new 3 38092 NULL
118011 +proc_self_readlink_38094 proc_self_readlink 3 38094 NULL
118012 +ep0_read_38095 ep0_read 3 38095 NULL
118013 +osc_checksum_seq_write_38096 osc_checksum_seq_write 3 38096 NULL nohasharray
118014 +sk_wmem_schedule_38096 sk_wmem_schedule 2 38096 &osc_checksum_seq_write_38096
118015 +o2hb_read_slots_38105 o2hb_read_slots 2 38105 NULL
118016 +snd_pcm_oss_write_38108 snd_pcm_oss_write 3 38108 NULL
118017 +vmw_kms_present_38130 vmw_kms_present 9 38130 NULL
118018 +__ntfs_copy_from_user_iovec_inatomic_38153 __ntfs_copy_from_user_iovec_inatomic 4-3-0 38153 NULL
118019 +btrfs_extent_same_38163 btrfs_extent_same 3-2 38163 NULL
118020 +kvm_clear_guest_38164 kvm_clear_guest 3-2 38164 NULL
118021 +cdev_add_38176 cdev_add 2-3 38176 NULL
118022 +rt2x00debug_write_rf_38195 rt2x00debug_write_rf 3 38195 NULL
118023 +get_ucode_user_38202 get_ucode_user 3 38202 NULL
118024 +osd_req_list_partition_collections_38223 osd_req_list_partition_collections 5 38223 NULL
118025 +ceph_decode_16_38239 ceph_decode_16 0 38239 NULL
118026 +_ipw_read_reg32_38245 _ipw_read_reg32 0 38245 NULL
118027 +snd_pcm_playback_rewind_38249 snd_pcm_playback_rewind 0-2 38249 NULL
118028 +mthca_alloc_icm_table_38268 mthca_alloc_icm_table 4-3 38268 NULL nohasharray
118029 +ieee80211_if_read_auto_open_plinks_38268 ieee80211_if_read_auto_open_plinks 3 38268 &mthca_alloc_icm_table_38268
118030 +xfs_bmbt_to_bmdr_38275 xfs_bmbt_to_bmdr 3 38275 NULL nohasharray
118031 +xfs_bmdr_to_bmbt_38275 xfs_bmdr_to_bmbt 5 38275 &xfs_bmbt_to_bmdr_38275
118032 +ftdi_process_packet_38281 ftdi_process_packet 4 38281 NULL
118033 +C_SYSC_pselect6_38296 C_SYSC_pselect6 1 38296 NULL
118034 +ucma_query_path_38305 ucma_query_path 3 38305 NULL
118035 +isr_rx_headers_read_38325 isr_rx_headers_read 3 38325 NULL
118036 +ida_simple_get_38326 ida_simple_get 0 38326 NULL
118037 +__snd_gf1_look8_38333 __snd_gf1_look8 0 38333 NULL
118038 +btrfs_file_extent_disk_num_bytes_38363 btrfs_file_extent_disk_num_bytes 0 38363 NULL
118039 +dn_sendmsg_38390 dn_sendmsg 4 38390 NULL
118040 +ieee80211_if_read_dtim_count_38419 ieee80211_if_read_dtim_count 3 38419 NULL
118041 +pmcraid_copy_sglist_38431 pmcraid_copy_sglist 3 38431 NULL
118042 +kvm_write_guest_38454 kvm_write_guest 4-2 38454 NULL
118043 +_iwl_dbgfs_scan_ant_rxchain_write_38479 _iwl_dbgfs_scan_ant_rxchain_write 3 38479 NULL
118044 +blk_end_bidi_request_38482 blk_end_bidi_request 3-4 38482 NULL
118045 +dev_names_read_38509 dev_names_read 3 38509 NULL
118046 +iscsi_create_iface_38510 iscsi_create_iface 5 38510 NULL
118047 +event_rx_mismatch_read_38518 event_rx_mismatch_read 3 38518 NULL
118048 +set_queue_count_38519 set_queue_count 0 38519 NULL
118049 +ubifs_idx_node_sz_38546 ubifs_idx_node_sz 0-2 38546 NULL
118050 +btrfs_discard_extent_38547 btrfs_discard_extent 2 38547 NULL
118051 +kuc_len_38557 kuc_len 0-1 38557 NULL
118052 +irda_sendmsg_dgram_38563 irda_sendmsg_dgram 4 38563 NULL
118053 +il4965_rs_sta_dbgfs_scale_table_read_38564 il4965_rs_sta_dbgfs_scale_table_read 3 38564 NULL
118054 +_ipw_read32_38565 _ipw_read32 0 38565 NULL
118055 +snd_nm256_playback_copy_38567 snd_nm256_playback_copy 3-5 38567 NULL
118056 +copy_ctl_value_to_user_38587 copy_ctl_value_to_user 4 38587 NULL
118057 +rd_allocate_sgl_table_38607 rd_allocate_sgl_table 3 38607 NULL
118058 +icn_writecmd_38629 icn_writecmd 2 38629 NULL
118059 +write_enabled_file_bool_38630 write_enabled_file_bool 3 38630 NULL
118060 +ext2_readpages_38640 ext2_readpages 4 38640 NULL
118061 +audit_init_entry_38644 audit_init_entry 1 38644 NULL
118062 +qp_broker_alloc_38646 qp_broker_alloc 6-5 38646 NULL
118063 +mmc_send_cxd_data_38655 mmc_send_cxd_data 5 38655 NULL
118064 +nouveau_instmem_create__38664 nouveau_instmem_create_ 4 38664 NULL
118065 +snd_es1371_wait_src_ready_38673 snd_es1371_wait_src_ready 0 38673 NULL
118066 +iscsit_dump_data_payload_38683 iscsit_dump_data_payload 2 38683 NULL
118067 +validate_vid_hdr_38699 validate_vid_hdr 0 38699 NULL
118068 +rbio_add_io_page_38700 rbio_add_io_page 6 38700 NULL
118069 +udf_readpages_38761 udf_readpages 4 38761 NULL
118070 +iwl_dbgfs_thermal_throttling_read_38779 iwl_dbgfs_thermal_throttling_read 3 38779 NULL
118071 +bcache_device_init_38781 bcache_device_init 3 38781 NULL
118072 +snd_gus_dram_write_38784 snd_gus_dram_write 4 38784 NULL
118073 +do_pci_enable_device_38802 do_pci_enable_device 0 38802 NULL
118074 +err_decode_38804 err_decode 2 38804 NULL
118075 +ipv6_renew_option_38813 ipv6_renew_option 3 38813 NULL
118076 +direct_entry_38836 direct_entry 3 38836 NULL
118077 +compat_udp_setsockopt_38840 compat_udp_setsockopt 5 38840 NULL
118078 +read_nic_io_word_38853 read_nic_io_word 0 38853 NULL
118079 +interfaces_38859 interfaces 2 38859 NULL
118080 +dbgfs_state_38894 dbgfs_state 3 38894 NULL
118081 +il_dbgfs_sram_write_38942 il_dbgfs_sram_write 3 38942 NULL
118082 +__ath6kl_wmi_send_mgmt_cmd_38971 __ath6kl_wmi_send_mgmt_cmd 7 38971 NULL
118083 +usb_maxpacket_38977 usb_maxpacket 0 38977 NULL nohasharray
118084 +C_SYSC_preadv64_38977 C_SYSC_preadv64 3 38977 &usb_maxpacket_38977
118085 +OSDSetBlock_38986 OSDSetBlock 2-4 38986 NULL
118086 +bio_clone_range_38997 bio_clone_range 2 38997 NULL
118087 +lpfc_idiag_extacc_write_38998 lpfc_idiag_extacc_write 3 38998 NULL
118088 +get_nodes_39012 get_nodes 3 39012 NULL
118089 +twl6030_interrupt_unmask_39013 twl6030_interrupt_unmask 2 39013 NULL
118090 +force_sc_support_read_39014 force_sc_support_read 3 39014 NULL
118091 +__blkdev_issue_zeroout_39020 __blkdev_issue_zeroout 3 39020 NULL
118092 +_zd_iowrite32v_async_locked_39034 _zd_iowrite32v_async_locked 3 39034 NULL
118093 +do_write_kmem_39051 do_write_kmem 0-1-3 39051 NULL
118094 +tomoyo_truncate_39105 tomoyo_truncate 0 39105 NULL
118095 +leb_write_lock_39111 leb_write_lock 0 39111 NULL
118096 +__kfifo_to_user_r_39123 __kfifo_to_user_r 5-3 39123 NULL
118097 +ea_foreach_39133 ea_foreach 0 39133 NULL
118098 +generic_permission_39150 generic_permission 0 39150 NULL
118099 +proc_coredump_filter_read_39153 proc_coredump_filter_read 3 39153 NULL
118100 +ath9k_hw_ar9003_dump_eeprom_39156 ath9k_hw_ar9003_dump_eeprom 5-4 39156 NULL
118101 +echo_client_kbrw_39170 echo_client_kbrw 6 39170 NULL
118102 +ext3_xattr_check_names_39174 ext3_xattr_check_names 0 39174 NULL
118103 +ubi_more_update_data_39189 ubi_more_update_data 4 39189 NULL
118104 +qcam_read_bytes_39205 qcam_read_bytes 0 39205 NULL
118105 +ivtv_v4l2_write_39226 ivtv_v4l2_write 3 39226 NULL
118106 +posix_acl_to_xattr_39237 posix_acl_to_xattr 0 39237 NULL
118107 +snd_pcm_capture_forward_39248 snd_pcm_capture_forward 0-2 39248 NULL
118108 +r128_compat_ioctl_39250 r128_compat_ioctl 2 39250 NULL nohasharray
118109 +pwr_cont_miss_bcns_spread_read_39250 pwr_cont_miss_bcns_spread_read 3 39250 &r128_compat_ioctl_39250
118110 +i915_error_state_read_39254 i915_error_state_read 3 39254 NULL
118111 +rx_filter_protection_filter_read_39282 rx_filter_protection_filter_read 3 39282 NULL
118112 +_iwl_dbgfs_pm_params_write_39325 _iwl_dbgfs_pm_params_write 3 39325 NULL
118113 +__cfg80211_connect_result_39326 __cfg80211_connect_result 4-6 39326 NULL
118114 +insert_reserved_file_extent_39327 insert_reserved_file_extent 3 39327 NULL
118115 +wimax_msg_alloc_39343 wimax_msg_alloc 4 39343 NULL
118116 +ide_complete_rq_39354 ide_complete_rq 3 39354 NULL
118117 +do_write_log_from_user_39362 do_write_log_from_user 3-0 39362 NULL
118118 +vortex_wtdma_getlinearpos_39371 vortex_wtdma_getlinearpos 0 39371 NULL
118119 +regmap_name_read_file_39379 regmap_name_read_file 3 39379 NULL
118120 +fnic_trace_debugfs_read_39380 fnic_trace_debugfs_read 3 39380 NULL
118121 +ps_poll_ps_poll_utilization_read_39383 ps_poll_ps_poll_utilization_read 3 39383 NULL
118122 +__send_to_port_39386 __send_to_port 3 39386 NULL
118123 +user_power_read_39414 user_power_read 3 39414 NULL
118124 +hash_ipmark4_expire_39419 hash_ipmark4_expire 4 39419 NULL
118125 +alloc_agpphysmem_i8xx_39427 alloc_agpphysmem_i8xx 1 39427 NULL
118126 +mic_desc_size_39464 mic_desc_size 0 39464 NULL
118127 +setkey_unaligned_39474 setkey_unaligned 3 39474 NULL
118128 +ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries_39499 ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries 3 39499 NULL
118129 +cl_req_alloc_39523 cl_req_alloc 4 39523 NULL
118130 +int_proc_write_39542 int_proc_write 3 39542 NULL
118131 +ext4_alloc_file_blocks_39551 ext4_alloc_file_blocks 3 39551 NULL
118132 +pp_write_39554 pp_write 3 39554 NULL
118133 +datablob_format_39571 datablob_format 2 39571 NULL nohasharray
118134 +ieee80211_if_read_fwded_mcast_39571 ieee80211_if_read_fwded_mcast 3 39571 &datablob_format_39571
118135 +memblock_virt_alloc_internal_39600 memblock_virt_alloc_internal 1 39600 NULL
118136 +ext_depth_39607 ext_depth 0 39607 NULL
118137 +batadv_tt_tvlv_generate_39615 batadv_tt_tvlv_generate 4 39615 NULL
118138 +nfs_idmap_get_key_39616 nfs_idmap_get_key 2 39616 NULL
118139 +sdio_readb_39618 sdio_readb 0 39618 NULL
118140 +prepare_uptodate_page_39622 prepare_uptodate_page 0 39622 NULL
118141 +set_dev_class_39645 set_dev_class 4 39645 NULL
118142 +snd_rme32_capture_copy_39653 snd_rme32_capture_copy 5 39653 NULL
118143 +tcp_try_rmem_schedule_39657 tcp_try_rmem_schedule 3 39657 NULL
118144 +kvm_read_guest_cached_39666 kvm_read_guest_cached 4 39666 NULL
118145 +v4l_stk_read_39672 v4l_stk_read 3 39672 NULL
118146 +hsc_msg_len_get_39673 hsc_msg_len_get 0 39673 NULL
118147 +do_surface_dirty_sou_39678 do_surface_dirty_sou 7 39678 NULL
118148 +sd_completed_bytes_39705 sd_completed_bytes 0 39705 NULL
118149 +ftrace_pid_write_39710 ftrace_pid_write 3 39710 NULL
118150 +adt7316_spi_multi_read_39765 adt7316_spi_multi_read 3 39765 NULL
118151 +security_inode_listsecurity_39812 security_inode_listsecurity 0 39812 NULL
118152 +snd_pcm_oss_writev3_39818 snd_pcm_oss_writev3 3 39818 NULL
118153 +get_priv_size_39828 get_priv_size 0-1 39828 NULL
118154 +pkt_add_39897 pkt_add 3 39897 NULL
118155 +read_file_modal_eeprom_39909 read_file_modal_eeprom 3 39909 NULL
118156 +gen_pool_add_virt_39913 gen_pool_add_virt 4 39913 NULL
118157 +dw210x_op_rw_39915 dw210x_op_rw 6 39915 NULL
118158 +__mnt_want_write_file_39917 __mnt_want_write_file 0 39917 NULL
118159 +aes_encrypt_interrupt_read_39919 aes_encrypt_interrupt_read 3 39919 NULL
118160 +exofs_read_kern_39921 exofs_read_kern 6 39921 NULL nohasharray
118161 +oom_score_adj_read_39921 oom_score_adj_read 3 39921 &exofs_read_kern_39921
118162 +__spi_async_39932 __spi_async 0 39932 NULL
118163 +__get_order_39935 __get_order 0 39935 NULL
118164 +error_error_frame_read_39947 error_error_frame_read 3 39947 NULL
118165 +tty_prepare_flip_string_39955 tty_prepare_flip_string 3-0 39955 NULL
118166 +lstcon_group_list_39958 lstcon_group_list 2 39958 NULL
118167 +bio_chain_clone_range_39967 bio_chain_clone_range 3 39967 NULL
118168 +dma_push_rx_39973 dma_push_rx 2 39973 NULL
118169 +broadsheetfb_write_39976 broadsheetfb_write 3 39976 NULL
118170 +mthca_array_init_39987 mthca_array_init 2 39987 NULL
118171 +fw_device_op_read_39990 fw_device_op_read 3 39990 NULL
118172 +server_name2svname_39998 server_name2svname 4 39998 NULL
118173 +xen_hvm_config_40018 xen_hvm_config 2 40018 NULL
118174 +ivtvfb_write_40023 ivtvfb_write 3 40023 NULL
118175 +disc_pwup_write_40027 disc_pwup_write 3 40027 NULL
118176 +ea_foreach_i_40028 ea_foreach_i 0 40028 NULL
118177 +datablob_hmac_append_40038 datablob_hmac_append 3 40038 NULL
118178 +l2cap_create_iframe_pdu_40055 l2cap_create_iframe_pdu 3 40055 NULL nohasharray
118179 +add_tty_40055 add_tty 1 40055 &l2cap_create_iframe_pdu_40055
118180 +atomic_xchg_40070 atomic_xchg 0 40070 NULL
118181 +snd_pcm_sw_params_user_40095 snd_pcm_sw_params_user 0 40095 NULL
118182 +sctp_setsockopt_delayed_ack_40129 sctp_setsockopt_delayed_ack 3 40129 NULL
118183 +dwc2_max_desc_num_40132 dwc2_max_desc_num 0 40132 NULL
118184 +rx_rx_frame_checksum_read_40140 rx_rx_frame_checksum_read 3 40140 NULL
118185 +ath10k_write_simulate_fw_crash_40143 ath10k_write_simulate_fw_crash 3 40143 NULL
118186 +iwch_alloc_fastreg_pbl_40153 iwch_alloc_fastreg_pbl 2 40153 NULL
118187 +pt_write_40159 pt_write 3 40159 NULL
118188 +scsi_sg_count_40182 scsi_sg_count 0 40182 NULL
118189 +ipr_alloc_ucode_buffer_40199 ipr_alloc_ucode_buffer 1 40199 NULL
118190 +allocate_probes_40204 allocate_probes 1 40204 NULL
118191 +au0828_v4l2_read_40220 au0828_v4l2_read 3 40220 NULL
118192 +compress_file_range_40225 compress_file_range 3-4 40225 NULL
118193 +ocrdma_dbgfs_ops_read_40232 ocrdma_dbgfs_ops_read 3 40232 NULL
118194 +osst_read_40237 osst_read 3 40237 NULL
118195 +lpage_info_slot_40243 lpage_info_slot 1-3 40243 NULL
118196 +ocfs2_zero_extend_get_range_40248 ocfs2_zero_extend_get_range 4 40248 NULL
118197 +of_get_child_count_40254 of_get_child_count 0 40254 NULL
118198 +rs_sta_dbgfs_scale_table_read_40262 rs_sta_dbgfs_scale_table_read 3 40262 NULL
118199 +ext2_fiemap_40271 ext2_fiemap 4 40271 NULL
118200 +usbnet_read_cmd_40275 usbnet_read_cmd 7 40275 NULL
118201 +rx_xfr_hint_trig_read_40283 rx_xfr_hint_trig_read 3 40283 NULL
118202 +SyS_bind_40303 SyS_bind 3 40303 NULL
118203 +ubi_io_write_data_40305 ubi_io_write_data 0 40305 NULL
118204 +ib_get_mad_data_offset_40336 ib_get_mad_data_offset 0 40336 NULL
118205 +mmio_read_40348 mmio_read 4 40348 NULL
118206 +event_rx_mem_empty_read_40363 event_rx_mem_empty_read 3 40363 NULL
118207 +ocfs2_check_range_for_refcount_40365 ocfs2_check_range_for_refcount 2-3 40365 NULL
118208 +get_chars_40373 get_chars 3 40373 NULL
118209 +fb_prepare_extra_logos_40429 fb_prepare_extra_logos 0-2 40429 NULL
118210 +tomoyo_update_policy_40458 tomoyo_update_policy 2 40458 NULL
118211 +zd_usb_scnprint_id_40459 zd_usb_scnprint_id 0-3 40459 NULL
118212 +gp2ap020a00f_write_event_threshold_40461 gp2ap020a00f_write_event_threshold 2 40461 NULL
118213 +SyS_writev_40467 SyS_writev 3 40467 NULL
118214 +SyS_select_40473 SyS_select 1 40473 NULL
118215 +afs_fs_store_data_40484 afs_fs_store_data 3-4-5-6 40484 NULL
118216 +batadv_hash_new_40491 batadv_hash_new 1 40491 NULL
118217 +devcgroup_inode_permission_40492 devcgroup_inode_permission 0 40492 NULL
118218 +__ethtool_get_sset_count_40511 __ethtool_get_sset_count 0 40511 NULL
118219 +TSS_checkhmac2_40520 TSS_checkhmac2 5-7 40520 NULL
118220 +ixgbe_dbg_reg_ops_read_40540 ixgbe_dbg_reg_ops_read 3 40540 NULL
118221 +ima_write_policy_40548 ima_write_policy 3 40548 NULL
118222 +esp_alloc_tmp_40558 esp_alloc_tmp 3-2 40558 NULL
118223 +get_priv_descr_and_size_40612 get_priv_descr_and_size 0 40612 NULL
118224 +i2c_register_adapter_40660 i2c_register_adapter 0 40660 NULL
118225 +twl4030_kpwrite_u8_40665 twl4030_kpwrite_u8 3 40665 NULL
118226 +__cfg80211_roamed_40668 __cfg80211_roamed 4-6 40668 NULL
118227 +pipeline_rx_complete_stat_fifo_int_read_40671 pipeline_rx_complete_stat_fifo_int_read 3 40671 NULL
118228 +fops_read_40672 fops_read 3 40672 NULL
118229 +idr_get_empty_slot_40674 idr_get_empty_slot 0 40674 NULL
118230 +alloc_rbio_40676 alloc_rbio 4 40676 NULL
118231 +videobuf_dma_init_user_locked_40678 videobuf_dma_init_user_locked 4-3 40678 NULL
118232 +pci_enable_resources_40680 pci_enable_resources 0 40680 NULL
118233 +nfc_hci_set_param_40697 nfc_hci_set_param 5 40697 NULL
118234 +__seq_open_private_40715 __seq_open_private 3 40715 NULL
118235 +set_extent_bit_40719 set_extent_bit 0 40719 NULL
118236 +of_pdt_build_one_prop_40735 of_pdt_build_one_prop 5 40735 NULL
118237 +fuse_readpages_40737 fuse_readpages 4 40737 NULL
118238 +xfs_iext_remove_direct_40744 xfs_iext_remove_direct 3 40744 NULL
118239 +security_inode_listxattr_40752 security_inode_listxattr 0 40752 NULL
118240 +card_send_command_40757 card_send_command 3 40757 NULL
118241 +ad1889_readl_40765 ad1889_readl 0 40765 NULL
118242 +pg_write_40766 pg_write 3 40766 NULL
118243 +kernfs_fop_read_40770 kernfs_fop_read 3 40770 NULL
118244 +show_list_40775 show_list 3-0 40775 NULL
118245 +kfifo_out_copy_r_40784 kfifo_out_copy_r 0-3 40784 NULL
118246 +bitmap_weight_40791 bitmap_weight 0 40791 NULL
118247 +pyra_sysfs_read_40795 pyra_sysfs_read 6 40795 NULL
118248 +rtw_add_beacon_40801 rtw_add_beacon 3-5 40801 NULL
118249 +add_action_40811 add_action 4 40811 NULL
118250 +nl80211_send_roamed_40825 nl80211_send_roamed 5-7 40825 NULL
118251 +nilfs_mdt_init_40849 nilfs_mdt_init 3 40849 NULL
118252 +v9fs_file_read_40858 v9fs_file_read 3 40858 NULL
118253 +read_file_queue_40895 read_file_queue 3 40895 NULL
118254 +waiters_read_40902 waiters_read 3 40902 NULL
118255 +isdn_add_channels_40905 isdn_add_channels 3 40905 NULL
118256 +gfs2_ea_find_40913 gfs2_ea_find 0 40913 NULL
118257 +vol_cdev_write_40915 vol_cdev_write 3 40915 NULL
118258 +snd_vx_create_40948 snd_vx_create 4 40948 NULL
118259 +rds_sendmsg_40976 rds_sendmsg 4 40976 NULL
118260 +insert_old_idx_40987 insert_old_idx 0 40987 NULL
118261 +il_dbgfs_fh_reg_read_40993 il_dbgfs_fh_reg_read 3 40993 NULL
118262 +iwl_dbgfs_scan_ant_rxchain_read_40999 iwl_dbgfs_scan_ant_rxchain_read 3 40999 NULL
118263 +mac80211_format_buffer_41010 mac80211_format_buffer 2 41010 NULL
118264 +mtd_block_isbad_41015 mtd_block_isbad 0 41015 NULL
118265 +__proc_dobitmasks_41029 __proc_dobitmasks 5 41029 NULL
118266 +_req_append_segment_41031 _req_append_segment 2 41031 NULL
118267 +mISDN_sock_sendmsg_41035 mISDN_sock_sendmsg 4 41035 NULL
118268 +ocfs2_xattr_index_block_find_41040 ocfs2_xattr_index_block_find 0 41040 NULL
118269 +lprocfs_write_frac_helper_41050 lprocfs_write_frac_helper 2 41050 NULL
118270 +vfs_listxattr_41062 vfs_listxattr 0 41062 NULL nohasharray
118271 +beacon_filtering_write_41062 beacon_filtering_write 3 41062 &vfs_listxattr_41062
118272 +sc_only_mode_read_41076 sc_only_mode_read 3 41076 NULL
118273 +cfg80211_inform_bss_frame_41078 cfg80211_inform_bss_frame 4 41078 NULL
118274 +nvme_map_user_pages_41093 nvme_map_user_pages 4-3 41093 NULL nohasharray
118275 +roccat_read_41093 roccat_read 3 41093 &nvme_map_user_pages_41093
118276 +dma_attach_41094 dma_attach 5-6 41094 NULL
118277 +provide_user_output_41105 provide_user_output 3 41105 NULL
118278 +f_audio_buffer_alloc_41110 f_audio_buffer_alloc 1 41110 NULL
118279 +ath10k_read_wmi_services_41112 ath10k_read_wmi_services 3 41112 NULL
118280 +v4l2_ctrl_new_int_menu_41151 v4l2_ctrl_new_int_menu 4 41151 NULL
118281 +tx_frag_mpdu_alloc_failed_read_41167 tx_frag_mpdu_alloc_failed_read 3 41167 NULL
118282 +dvb_ca_write_41171 dvb_ca_write 3 41171 NULL
118283 +netif_get_num_default_rss_queues_41187 netif_get_num_default_rss_queues 0 41187 NULL
118284 +request_irq_41192 request_irq 0 41192 NULL
118285 +dfs_file_write_41196 dfs_file_write 3 41196 NULL
118286 +nfs_page_array_len_41219 nfs_page_array_len 0-2-1 41219 NULL
118287 +cfg80211_process_disassoc_41231 cfg80211_process_disassoc 3 41231 NULL
118288 +hiddev_compat_ioctl_41255 hiddev_compat_ioctl 2 41255 NULL
118289 +erst_read_41260 erst_read 0 41260 NULL
118290 +alloc_context_41283 alloc_context 1 41283 NULL
118291 +of_count_phandle_with_args_41291 of_count_phandle_with_args 0 41291 NULL
118292 +o2hb_setup_one_bio_41341 o2hb_setup_one_bio 4 41341 NULL
118293 +twl_change_queue_depth_41342 twl_change_queue_depth 2 41342 NULL
118294 +rtw_android_set_block_41347 rtw_android_set_block 0 41347 NULL
118295 +ceph_do_getattr_41349 ceph_do_getattr 0 41349 NULL
118296 +cnic_init_id_tbl_41354 cnic_init_id_tbl 2 41354 NULL
118297 +kmp_init_41373 kmp_init 2 41373 NULL
118298 +isr_commands_read_41398 isr_commands_read 3 41398 NULL
118299 +rx_defrag_decrypt_failed_read_41411 rx_defrag_decrypt_failed_read 3 41411 NULL
118300 +xfs_iext_add_41422 xfs_iext_add 3 41422 NULL
118301 +isdn_ppp_fill_rq_41428 isdn_ppp_fill_rq 2 41428 NULL
118302 +lbs_rdrf_read_41431 lbs_rdrf_read 3 41431 NULL
118303 +iio_device_alloc_41440 iio_device_alloc 1 41440 NULL
118304 +ntfs_file_buffered_write_41442 ntfs_file_buffered_write 6-4 41442 NULL
118305 +pcpu_build_alloc_info_41443 pcpu_build_alloc_info 1-2-3 41443 NULL
118306 +se_io_cb_41461 se_io_cb 3 41461 NULL
118307 +layout_leb_in_gaps_41470 layout_leb_in_gaps 0 41470 NULL
118308 +snd_pcm_status_41472 snd_pcm_status 0 41472 NULL
118309 +rt2x00debug_write_rfcsr_41473 rt2x00debug_write_rfcsr 3 41473 NULL
118310 +bl_alloc_init_bio_41478 bl_alloc_init_bio 1 41478 NULL
118311 +kvm_unmap_hva_range_41484 kvm_unmap_hva_range 3-2 41484 NULL
118312 +wep_interrupt_read_41492 wep_interrupt_read 3 41492 NULL
118313 +hpfs_translate_name_41497 hpfs_translate_name 3 41497 NULL
118314 +xfrm_hash_new_size_41505 xfrm_hash_new_size 0-1 41505 NULL
118315 +SyS_preadv_41523 SyS_preadv 3 41523 NULL
118316 +dm_get_reserved_rq_based_ios_41529 dm_get_reserved_rq_based_ios 0 41529 NULL
118317 +tx_tx_frame_checksum_read_41553 tx_tx_frame_checksum_read 3 41553 NULL
118318 +ath6kl_endpoint_stats_read_41554 ath6kl_endpoint_stats_read 3 41554 NULL
118319 +nr_status_frames_41559 nr_status_frames 0-1 41559 NULL nohasharray
118320 +si476x_radio_fops_read_41559 si476x_radio_fops_read 3 41559 &nr_status_frames_41559
118321 +rng_dev_read_41581 rng_dev_read 3 41581 NULL
118322 +batadv_tvlv_container_ogm_append_41588 batadv_tvlv_container_ogm_append 4 41588 NULL
118323 +vga_io_r_41609 vga_io_r 0 41609 NULL
118324 +tcp_hdrlen_41610 tcp_hdrlen 0 41610 NULL
118325 +usb_endpoint_maxp_41613 usb_endpoint_maxp 0 41613 NULL nohasharray
118326 +lbs_bcnmiss_write_41613 lbs_bcnmiss_write 3 41613 &usb_endpoint_maxp_41613
118327 +a2mp_send_41615 a2mp_send 4 41615 NULL
118328 +lstcon_batch_list_41627 lstcon_batch_list 2 41627 NULL
118329 +mempool_create_kmalloc_pool_41650 mempool_create_kmalloc_pool 1 41650 NULL
118330 +rx_rx_pre_complt_read_41653 rx_rx_pre_complt_read 3 41653 NULL
118331 +get_std_timing_41654 get_std_timing 0 41654 NULL
118332 +ieee80211_if_fmt_bssid_41677 ieee80211_if_fmt_bssid 3 41677 NULL
118333 +fill_pcm_stream_name_41685 fill_pcm_stream_name 2 41685 NULL
118334 +lov_unpackmd_41701 lov_unpackmd 4 41701 NULL
118335 +fillonedir_41746 fillonedir 3 41746 NULL
118336 +iwl_dbgfs_bt_notif_read_41794 iwl_dbgfs_bt_notif_read 3 41794 NULL
118337 +hsi_alloc_controller_41802 hsi_alloc_controller 1 41802 NULL
118338 +rtw_android_get_macaddr_41812 rtw_android_get_macaddr 0 41812 NULL
118339 +sco_send_frame_41815 sco_send_frame 3 41815 NULL
118340 +ixgbe_dbg_netdev_ops_read_41839 ixgbe_dbg_netdev_ops_read 3 41839 NULL
118341 +do_ip_setsockopt_41852 do_ip_setsockopt 5 41852 NULL
118342 +keyctl_instantiate_key_41855 keyctl_instantiate_key 3 41855 NULL
118343 +pci_map_single_41869 pci_map_single 0 41869 NULL
118344 +v_APCI3120_InterruptDmaMoveBlock16bit_41914 v_APCI3120_InterruptDmaMoveBlock16bit 4 41914 NULL
118345 +get_fdb_entries_41916 get_fdb_entries 3 41916 NULL
118346 +ext4_da_write_inline_data_begin_41935 ext4_da_write_inline_data_begin 3-4 41935 NULL
118347 +sci_rxfill_41945 sci_rxfill 0 41945 NULL
118348 +read_gssp_41947 read_gssp 3 41947 NULL
118349 +ocfs2_xattr_bucket_get_name_value_41949 ocfs2_xattr_bucket_get_name_value 0 41949 NULL
118350 +portnames_read_41958 portnames_read 3 41958 NULL
118351 +ubi_self_check_all_ff_41959 ubi_self_check_all_ff 0 41959 NULL
118352 +dst_mtu_41969 dst_mtu 0 41969 NULL
118353 +cx24116_writeregN_41975 cx24116_writeregN 4 41975 NULL
118354 +ubi_io_is_bad_41983 ubi_io_is_bad 0 41983 NULL
118355 +pool_allocate_42012 pool_allocate 3 42012 NULL
118356 +spidev_sync_read_42014 spidev_sync_read 0 42014 NULL
118357 +rs_sta_dbgfs_scale_table_write_42017 rs_sta_dbgfs_scale_table_write 3 42017 NULL
118358 +acpi_ut_create_buffer_object_42030 acpi_ut_create_buffer_object 1 42030 NULL
118359 +__hwahc_op_set_gtk_42038 __hwahc_op_set_gtk 4 42038 NULL
118360 +alloc_trace_kprobe_42041 alloc_trace_kprobe 6 42041 NULL
118361 +irda_sendmsg_ultra_42047 irda_sendmsg_ultra 4 42047 NULL
118362 +jffs2_do_link_42048 jffs2_do_link 6 42048 NULL
118363 +ps_poll_upsd_max_ap_turn_read_42050 ps_poll_upsd_max_ap_turn_read 3 42050 NULL
118364 +InterfaceTransmitPacket_42058 InterfaceTransmitPacket 3 42058 NULL
118365 +scsi_execute_req_42088 scsi_execute_req 5 42088 NULL
118366 +sk_chk_filter_42095 sk_chk_filter 2 42095 NULL
118367 +submit_inquiry_42108 submit_inquiry 3 42108 NULL
118368 +dw_dma_cyclic_prep_42113 dw_dma_cyclic_prep 3-4 42113 NULL
118369 +blk_ioctl_zeroout_42160 blk_ioctl_zeroout 3 42160 NULL
118370 +mmc_align_data_size_42161 mmc_align_data_size 0-2 42161 NULL
118371 +read_file_base_eeprom_42168 read_file_base_eeprom 3 42168 NULL
118372 +oprofilefs_str_to_user_42182 oprofilefs_str_to_user 3 42182 NULL
118373 +write_file_beacon_42185 write_file_beacon 3 42185 NULL
118374 +get_znodes_to_commit_42201 get_znodes_to_commit 0 42201 NULL
118375 +pla_ocp_read_42235 pla_ocp_read 3 42235 NULL
118376 +rx_defrag_need_decrypt_read_42253 rx_defrag_need_decrypt_read 3 42253 NULL
118377 +find_last_bit_42260 find_last_bit 0 42260 NULL
118378 +__pcpu_size_to_slot_42271 __pcpu_size_to_slot 0 42271 NULL
118379 +__tty_buffer_request_room_42276 __tty_buffer_request_room 2-0 42276 NULL
118380 +snd_pcm_hw_param_value_max_42280 snd_pcm_hw_param_value_max 0 42280 NULL
118381 +__cpus_weight_42299 __cpus_weight 0 42299 NULL
118382 +sel_read_perm_42302 sel_read_perm 3 42302 NULL
118383 +sctp_setsockopt_del_key_42304 sctp_setsockopt_del_key 3 42304 NULL nohasharray
118384 +ulong_read_file_42304 ulong_read_file 3 42304 &sctp_setsockopt_del_key_42304
118385 +xfs_vm_readpages_42308 xfs_vm_readpages 4 42308 NULL
118386 +hysdn_conf_read_42324 hysdn_conf_read 3 42324 NULL
118387 +tcp_sync_mss_42330 tcp_sync_mss 2-0 42330 NULL
118388 +ide_raw_taskfile_42355 ide_raw_taskfile 4 42355 NULL
118389 +drbd_md_last_sector_42378 drbd_md_last_sector 0 42378 NULL
118390 +il_dbgfs_disable_ht40_read_42386 il_dbgfs_disable_ht40_read 3 42386 NULL
118391 +msnd_fifo_read_42406 msnd_fifo_read 0-3 42406 NULL
118392 +krng_get_random_42420 krng_get_random 3 42420 NULL
118393 +gsm_data_alloc_42437 gsm_data_alloc 3 42437 NULL
118394 +spr_wm_latency_write_42441 spr_wm_latency_write 3 42441 NULL
118395 +key_conf_keyidx_read_42443 key_conf_keyidx_read 3 42443 NULL
118396 +snd_pcm_action_group_42452 snd_pcm_action_group 0 42452 NULL
118397 +tcm_loop_change_queue_depth_42454 tcm_loop_change_queue_depth 2 42454 NULL
118398 +kuc_free_42455 kuc_free 2 42455 NULL
118399 +__simple_xattr_set_42474 __simple_xattr_set 4 42474 NULL
118400 +omfs_readpages_42490 omfs_readpages 4 42490 NULL
118401 +bypass_write_42498 bypass_write 3 42498 NULL
118402 +SyS_mincore_42511 SyS_mincore 2-1 42511 NULL
118403 +kvm_write_wall_clock_42520 kvm_write_wall_clock 2 42520 NULL
118404 +dio_bio_complete_42524 dio_bio_complete 0 42524 NULL
118405 +smk_write_netlbladdr_42525 smk_write_netlbladdr 3 42525 NULL
118406 +self_check_ec_hdr_42528 self_check_ec_hdr 0 42528 NULL
118407 +dbAllocNear_42546 dbAllocNear 0 42546 NULL
118408 +ath6kl_wmi_proc_events_vif_42549 ath6kl_wmi_proc_events_vif 5 42549 NULL
118409 +udp_recvmsg_42558 udp_recvmsg 4 42558 NULL
118410 +iwl_print_event_log_42566 iwl_print_event_log 7-5-0 42566 NULL
118411 +xfrm_new_hash_mask_42579 xfrm_new_hash_mask 0-1 42579 NULL
118412 +oom_score_adj_write_42594 oom_score_adj_write 3 42594 NULL
118413 +ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout_42635 ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout 3 42635 NULL
118414 +scsi_activate_tcq_42640 scsi_activate_tcq 2 42640 NULL
118415 +br_mdb_rehash_42643 br_mdb_rehash 2 42643 NULL
118416 +_regmap_raw_write_42652 _regmap_raw_write 4-2 42652 NULL
118417 +request_key_and_link_42693 request_key_and_link 4 42693 NULL
118418 +vb2_read_42703 vb2_read 3 42703 NULL
118419 +dvb_demux_ioctl_42733 dvb_demux_ioctl 2 42733 NULL
118420 +set_aoe_iflist_42737 set_aoe_iflist 2 42737 NULL
118421 +ax25_setsockopt_42740 ax25_setsockopt 5 42740 NULL
118422 +dpm_sysfs_add_42756 dpm_sysfs_add 0 42756 NULL
118423 +x25_recvmsg_42777 x25_recvmsg 4 42777 NULL
118424 +snd_midi_event_decode_42780 snd_midi_event_decode 0 42780 NULL
118425 +cryptd_hash_setkey_42781 cryptd_hash_setkey 3 42781 NULL nohasharray
118426 +isku_sysfs_read_info_42781 isku_sysfs_read_info 6 42781 &cryptd_hash_setkey_42781
118427 +elfcorehdr_read_notes_42786 elfcorehdr_read_notes 2 42786 NULL
118428 +koneplus_sysfs_read_42792 koneplus_sysfs_read 6 42792 NULL
118429 +ntfs_attr_extend_allocation_42796 ntfs_attr_extend_allocation 0 42796 NULL
118430 +fw_device_op_compat_ioctl_42804 fw_device_op_compat_ioctl 2 42804 NULL
118431 +drm_ioctl_42813 drm_ioctl 2 42813 NULL
118432 +iwl_dbgfs_ucode_bt_stats_read_42820 iwl_dbgfs_ucode_bt_stats_read 3 42820 NULL
118433 +set_arg_42824 set_arg 3 42824 NULL
118434 +si476x_radio_read_rsq_blob_42827 si476x_radio_read_rsq_blob 3 42827 NULL
118435 +ocfs2_clusters_for_bytes_42872 ocfs2_clusters_for_bytes 0-2 42872 NULL
118436 +nvme_trans_unit_serial_page_42879 nvme_trans_unit_serial_page 4 42879 NULL
118437 +xpc_kmalloc_cacheline_aligned_42895 xpc_kmalloc_cacheline_aligned 1 42895 NULL
118438 +hd_end_request_42904 hd_end_request 2 42904 NULL
118439 +sta_last_rx_rate_read_42909 sta_last_rx_rate_read 3 42909 NULL
118440 +sctp_getsockopt_maxburst_42941 sctp_getsockopt_maxburst 2 42941 NULL
118441 +vx_reset_chk_42946 vx_reset_chk 0 42946 NULL
118442 +blkdev_direct_IO_42962 blkdev_direct_IO 4 42962 NULL
118443 +ntb_setup_snb_msix_42971 ntb_setup_snb_msix 2-0 42971 NULL
118444 +compat_udpv6_setsockopt_42981 compat_udpv6_setsockopt 5 42981 NULL
118445 +nfs_idmap_get_desc_42990 nfs_idmap_get_desc 4-2 42990 NULL nohasharray
118446 +rtw_os_xmit_resource_alloc_42990 rtw_os_xmit_resource_alloc 3 42990 &nfs_idmap_get_desc_42990
118447 +isr_rx_mem_overflow_read_43025 isr_rx_mem_overflow_read 3 43025 NULL
118448 +wep_default_key_count_read_43035 wep_default_key_count_read 3 43035 NULL
118449 +nouveau_gpuobj_create__43072 nouveau_gpuobj_create_ 9 43072 NULL
118450 +nfs_map_group_to_gid_43082 nfs_map_group_to_gid 3 43082 NULL
118451 +_xfer_secondary_pool_43089 _xfer_secondary_pool 2 43089 NULL
118452 +sysfs_create_file_ns_43103 sysfs_create_file_ns 0 43103 NULL
118453 +ieee80211_if_fmt_drop_unencrypted_43107 ieee80211_if_fmt_drop_unencrypted 3 43107 NULL
118454 +calculate_node_totalpages_43118 calculate_node_totalpages 2-3 43118 NULL
118455 +e1000_request_msix_43134 e1000_request_msix 0 43134 NULL
118456 +read_file_dfs_43145 read_file_dfs 3 43145 NULL
118457 +cfs_cpt_table_alloc_43159 cfs_cpt_table_alloc 1 43159 NULL
118458 +usb_string_sub_43164 usb_string_sub 0 43164 NULL
118459 +il_dbgfs_power_save_status_read_43165 il_dbgfs_power_save_status_read 3 43165 NULL
118460 +ath6kl_set_assoc_req_ies_43185 ath6kl_set_assoc_req_ies 3 43185 NULL
118461 +ext4_xattr_ibody_get_43200 ext4_xattr_ibody_get 0 43200 NULL
118462 +uio_write_43202 uio_write 3 43202 NULL
118463 +iso_callback_43208 iso_callback 3 43208 NULL
118464 +ath10k_p2p_calc_noa_ie_len_43209 ath10k_p2p_calc_noa_ie_len 0 43209 NULL
118465 +f2fs_acl_from_disk_43210 f2fs_acl_from_disk 2 43210 NULL
118466 +atomic_long_add_return_43217 atomic_long_add_return 1-0 43217 NULL
118467 +batadv_tt_tvlv_unicast_handler_v1_43239 batadv_tt_tvlv_unicast_handler_v1 5 43239 NULL
118468 +vmemmap_alloc_block_43245 vmemmap_alloc_block 1 43245 NULL
118469 +ide_end_rq_43269 ide_end_rq 4 43269 NULL
118470 +nilfs_direct_IO_43271 nilfs_direct_IO 4 43271 NULL
118471 +evtchn_write_43278 evtchn_write 3 43278 NULL
118472 +filemap_write_and_wait_range_43279 filemap_write_and_wait_range 0 43279 NULL
118473 +mpage_alloc_43299 mpage_alloc 3 43299 NULL
118474 +mmu_set_spte_43327 mmu_set_spte 6-7 43327 NULL
118475 +__ext4_get_inode_loc_43332 __ext4_get_inode_loc 0 43332 NULL
118476 +xenfb_write_43412 xenfb_write 3 43412 NULL
118477 +__alloc_bootmem_low_43423 __alloc_bootmem_low 1 43423 NULL nohasharray
118478 +msi_capability_init_43423 msi_capability_init 0 43423 &__alloc_bootmem_low_43423
118479 +usb_alloc_urb_43436 usb_alloc_urb 1 43436 NULL
118480 +ath6kl_wmi_roam_tbl_event_rx_43440 ath6kl_wmi_roam_tbl_event_rx 3 43440 NULL
118481 +usb_string_43443 usb_string 0 43443 NULL nohasharray
118482 +usemap_size_43443 usemap_size 0-1-2 43443 &usb_string_43443
118483 +get_vm_area_size_43444 get_vm_area_size 0 43444 NULL
118484 +fs_path_prepare_for_add_43453 fs_path_prepare_for_add 2 43453 NULL
118485 +nvme_trans_device_id_page_43466 nvme_trans_device_id_page 4 43466 NULL
118486 +tx_tx_data_prepared_read_43497 tx_tx_data_prepared_read 3 43497 NULL
118487 +ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime_43505 ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime 3 43505 NULL
118488 +dvb_ca_en50221_io_write_43533 dvb_ca_en50221_io_write 3 43533 NULL
118489 +read_events_43534 read_events 3 43534 NULL
118490 +cachefiles_daemon_write_43535 cachefiles_daemon_write 3 43535 NULL
118491 +tx_frag_failed_read_43540 tx_frag_failed_read 3 43540 NULL
118492 +rpc_malloc_43573 rpc_malloc 2 43573 NULL
118493 +handle_frequent_errors_43599 handle_frequent_errors 4 43599 NULL
118494 +lpfc_idiag_drbacc_read_reg_43606 lpfc_idiag_drbacc_read_reg 0-3 43606 NULL
118495 +proc_read_43614 proc_read 3 43614 NULL
118496 +disable_dma_on_even_43618 disable_dma_on_even 0 43618 NULL
118497 +alloc_thread_groups_43625 alloc_thread_groups 2 43625 NULL
118498 +random_write_43656 random_write 3 43656 NULL
118499 +bio_integrity_tag_43658 bio_integrity_tag 3 43658 NULL
118500 +ext4_acl_count_43659 ext4_acl_count 0-1 43659 NULL
118501 +write_file_tx99_power_43670 write_file_tx99_power 3 43670 NULL
118502 +dmam_declare_coherent_memory_43679 dmam_declare_coherent_memory 4 43679 NULL
118503 +max77693_bulk_write_43698 max77693_bulk_write 2-3 43698 NULL
118504 +drbd_md_first_sector_43729 drbd_md_first_sector 0 43729 NULL
118505 +snd_rme32_playback_copy_43732 snd_rme32_playback_copy 5 43732 NULL
118506 +fuse_conn_congestion_threshold_write_43736 fuse_conn_congestion_threshold_write 3 43736 NULL
118507 +gigaset_initcs_43753 gigaset_initcs 2 43753 NULL
118508 +sctp_setsockopt_active_key_43755 sctp_setsockopt_active_key 3 43755 NULL
118509 +generic_file_direct_write_43770 generic_file_direct_write 0 43770 NULL
118510 +ocfs2_xattr_get_value_outside_43787 ocfs2_xattr_get_value_outside 0 43787 NULL nohasharray
118511 +byte_pos_43787 byte_pos 0 43787 &ocfs2_xattr_get_value_outside_43787
118512 +btrfs_copy_from_user_43806 btrfs_copy_from_user 3-1-0 43806 NULL
118513 +ieee80211_if_fmt_element_ttl_43825 ieee80211_if_fmt_element_ttl 3 43825 NULL
118514 +ieee80211_alloc_hw_43829 ieee80211_alloc_hw 1 43829 NULL
118515 +read_flush_43851 read_flush 3 43851 NULL
118516 +pm860x_bulk_write_43875 pm860x_bulk_write 2-3 43875 NULL
118517 +ec_dbgfs_cmd_write_43895 ec_dbgfs_cmd_write 3 43895 NULL
118518 +SendString_43928 SendString 3 43928 NULL
118519 +stats_dot11RTSFailureCount_read_43948 stats_dot11RTSFailureCount_read 3 43948 NULL
118520 +__get_required_blob_size_43980 __get_required_blob_size 0-3-2 43980 NULL
118521 +nla_reserve_43984 nla_reserve 3 43984 NULL
118522 +__clkdev_alloc_43990 __clkdev_alloc 1 43990 NULL
118523 +scsi_command_size_43992 scsi_command_size 0 43992 NULL nohasharray
118524 +bcm_recvmsg_43992 bcm_recvmsg 4 43992 &scsi_command_size_43992 nohasharray
118525 +kvm_read_guest_virt_43992 kvm_read_guest_virt 4-2 43992 &bcm_recvmsg_43992
118526 +ulist_add_43994 ulist_add 0 43994 NULL
118527 +emit_flags_44006 emit_flags 4-3 44006 NULL
118528 +write_flush_procfs_44011 write_flush_procfs 3 44011 NULL
118529 +fru_strlen_44046 fru_strlen 0 44046 NULL
118530 +ath9k_def_dump_modal_eeprom_44078 ath9k_def_dump_modal_eeprom 3-2-0 44078 NULL
118531 +SYSC_add_key_44079 SYSC_add_key 4 44079 NULL
118532 +pci_msix_vec_count_44093 pci_msix_vec_count 0 44093 NULL
118533 +xlog_recover_add_to_cont_trans_44102 xlog_recover_add_to_cont_trans 4 44102 NULL
118534 +skb_frag_dma_map_44112 skb_frag_dma_map 0 44112 NULL
118535 +tracing_set_trace_read_44122 tracing_set_trace_read 3 44122 NULL nohasharray
118536 +file_remove_suid_44122 file_remove_suid 0 44122 &tracing_set_trace_read_44122
118537 +SyS_process_vm_writev_44129 SyS_process_vm_writev 3-5 44129 NULL
118538 +ttm_get_pages_44142 ttm_get_pages 2 44142 NULL
118539 +scsi_get_resid_44147 scsi_get_resid 0 44147 NULL
118540 +ubifs_find_dirty_idx_leb_44169 ubifs_find_dirty_idx_leb 0 44169 NULL
118541 +ocfs2_xattr_bucket_find_44174 ocfs2_xattr_bucket_find 0 44174 NULL
118542 +SYSC_set_mempolicy_44176 SYSC_set_mempolicy 3 44176 NULL
118543 +handle_eviocgbit_44193 handle_eviocgbit 3 44193 NULL
118544 +srp_alloc_iu_44227 srp_alloc_iu 2 44227 NULL
118545 +scsi_track_queue_full_44239 scsi_track_queue_full 2 44239 NULL
118546 +sigma_action_write_regmap_44240 sigma_action_write_regmap 3 44240 NULL
118547 +device_create_file_44285 device_create_file 0 44285 NULL
118548 +ath6kl_keepalive_read_44303 ath6kl_keepalive_read 3 44303 NULL
118549 +bitmap_scnprintf_44318 bitmap_scnprintf 0-2 44318 NULL
118550 +dispatch_proc_write_44320 dispatch_proc_write 3 44320 NULL
118551 +ccp_init_data_44324 ccp_init_data 5 44324 NULL
118552 +rs_init_44327 rs_init 1 44327 NULL
118553 +blk_queue_init_tags_44355 blk_queue_init_tags 2 44355 NULL nohasharray
118554 +nfs_fscache_get_super_cookie_44355 nfs_fscache_get_super_cookie 3 44355 &blk_queue_init_tags_44355
118555 +rts_threshold_read_44384 rts_threshold_read 3 44384 NULL
118556 +mtip_hw_read_flags_44396 mtip_hw_read_flags 3 44396 NULL
118557 +aoedev_flush_44398 aoedev_flush 2 44398 NULL
118558 +strlcpy_44400 strlcpy 3 44400 NULL
118559 +drm_buffer_alloc_44405 drm_buffer_alloc 2 44405 NULL
118560 +osst_do_scsi_44410 osst_do_scsi 4 44410 NULL
118561 +ieee80211_if_read_rc_rateidx_mcs_mask_5ghz_44423 ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 NULL
118562 +write_file_debug_44476 write_file_debug 3 44476 NULL
118563 +btrfs_chunk_item_size_44478 btrfs_chunk_item_size 0-1 44478 NULL
118564 +sdio_align_size_44489 sdio_align_size 0-2 44489 NULL
118565 +bio_advance_44496 bio_advance 2 44496 NULL
118566 +ieee80211_if_read_dropped_frames_ttl_44500 ieee80211_if_read_dropped_frames_ttl 3 44500 NULL
118567 +ac_register_board_44504 ac_register_board 3 44504 NULL
118568 +security_getprocattr_44505 security_getprocattr 0 44505 NULL nohasharray
118569 +iwl_dbgfs_sram_read_44505 iwl_dbgfs_sram_read 3 44505 &security_getprocattr_44505
118570 +spidev_write_44510 spidev_write 3 44510 NULL
118571 +SyS_io_getevents_44519 SyS_io_getevents 3 44519 NULL
118572 +ieee80211_rx_mgmt_assoc_resp_44525 ieee80211_rx_mgmt_assoc_resp 3 44525 NULL
118573 +comm_write_44537 comm_write 3 44537 NULL
118574 +snd_pcm_drop_44542 snd_pcm_drop 0 44542 NULL
118575 +dgrp_config_proc_write_44571 dgrp_config_proc_write 3 44571 NULL
118576 +btrfs_set_extent_delalloc_44587 btrfs_set_extent_delalloc 0 44587 NULL
118577 +nouveau_perfmon_create__44602 nouveau_perfmon_create_ 4 44602 NULL
118578 +alloc_ctrl_packet_44667 alloc_ctrl_packet 1 44667 NULL
118579 +mpi_resize_44674 mpi_resize 2 44674 NULL
118580 +sysfs_create_link_44685 sysfs_create_link 0 44685 NULL
118581 +ts_read_44687 ts_read 3 44687 NULL
118582 +lov_emerg_alloc_44698 lov_emerg_alloc 1 44698 NULL
118583 +C_SYSC_select_44701 C_SYSC_select 1 44701 NULL
118584 +__generic_block_fiemap_44713 __generic_block_fiemap 4 44713 NULL nohasharray
118585 +xfer_to_user_44713 xfer_to_user 3 44713 &__generic_block_fiemap_44713
118586 +_zd_iowrite32v_locked_44725 _zd_iowrite32v_locked 3 44725 NULL
118587 +clusterip_proc_write_44729 clusterip_proc_write 3 44729 NULL
118588 +fib_count_nexthops_44730 fib_count_nexthops 0 44730 NULL
118589 +efx_wanted_parallelism_44732 efx_wanted_parallelism 0 44732 NULL
118590 +key_tx_rx_count_read_44742 key_tx_rx_count_read 3 44742 NULL
118591 +bch_bio_max_sectors_44755 bch_bio_max_sectors 0 44755 NULL
118592 +tnode_new_44757 tnode_new 3 44757 NULL nohasharray
118593 +pty_write_44757 pty_write 3 44757 &tnode_new_44757
118594 +__videobuf_copy_stream_44769 __videobuf_copy_stream 4-0 44769 NULL
118595 +handsfree_ramp_44777 handsfree_ramp 2 44777 NULL
118596 +irq_domain_add_legacy_44781 irq_domain_add_legacy 4-2 44781 NULL
118597 +sctp_setsockopt_44788 sctp_setsockopt 5 44788 NULL
118598 +rx_dropped_read_44799 rx_dropped_read 3 44799 NULL
118599 +qla4xxx_alloc_work_44813 qla4xxx_alloc_work 2 44813 NULL
118600 +force_static_address_write_44819 force_static_address_write 3 44819 NULL
118601 +mei_cl_read_start_44824 mei_cl_read_start 2 44824 NULL
118602 +rmap_write_protect_44833 rmap_write_protect 2 44833 NULL
118603 +sisusb_write_44834 sisusb_write 3 44834 NULL
118604 +kvm_read_hva_44847 kvm_read_hva 3 44847 NULL
118605 +qib_verbs_send_dma_44850 qib_verbs_send_dma 6 44850 NULL
118606 +copydesc_user_44855 copydesc_user 3 44855 NULL
118607 +set_advertising_44870 set_advertising 4 44870 NULL
118608 +init_rs_44873 init_rs 1 44873 NULL
118609 +skb_availroom_44883 skb_availroom 0 44883 NULL
118610 +do_tty_write_44896 do_tty_write 5 44896 NULL
118611 +regmap_spi_read_44921 regmap_spi_read 3-5 44921 NULL
118612 +tx_queue_status_read_44978 tx_queue_status_read 3 44978 NULL
118613 +bytepos_delta_45017 bytepos_delta 0 45017 NULL
118614 +ptrace_writedata_45021 ptrace_writedata 4 45021 NULL
118615 +dm_kvzalloc_45025 dm_kvzalloc 1 45025 NULL
118616 +sysfs_do_create_link_sd_45057 sysfs_do_create_link_sd 0 45057 NULL
118617 +sel_write_user_45060 sel_write_user 3 45060 NULL
118618 +snd_mixart_BA0_read_45069 snd_mixart_BA0_read 5 45069 NULL
118619 +snd_card_new_45104 snd_card_new 5 45104 NULL
118620 +kvm_mmu_page_get_gfn_45110 kvm_mmu_page_get_gfn 0-2 45110 NULL
118621 +pwr_missing_bcns_cnt_read_45113 pwr_missing_bcns_cnt_read 3 45113 NULL
118622 +usbdev_read_45114 usbdev_read 3 45114 NULL
118623 +send_to_tty_45141 send_to_tty 3 45141 NULL
118624 +cfs_trace_daemon_command_usrstr_45147 cfs_trace_daemon_command_usrstr 2 45147 NULL
118625 +gen_bitmask_string_45149 gen_bitmask_string 6 45149 NULL
118626 +device_write_45156 device_write 3 45156 NULL nohasharray
118627 +ocfs2_remove_inode_range_45156 ocfs2_remove_inode_range 3 45156 &device_write_45156
118628 +tomoyo_write_self_45161 tomoyo_write_self 3 45161 NULL
118629 +sta_agg_status_write_45164 sta_agg_status_write 3 45164 NULL
118630 +sctp_pack_cookie_45190 sctp_pack_cookie 6 45190 NULL nohasharray
118631 +snd_sb_csp_load_user_45190 snd_sb_csp_load_user 3 45190 &sctp_pack_cookie_45190
118632 +iso_alloc_urb_45206 iso_alloc_urb 4-5 45206 NULL
118633 +spi_alloc_master_45223 spi_alloc_master 2 45223 NULL
118634 +ieee80211_if_read_peer_45233 ieee80211_if_read_peer 3 45233 NULL
118635 +event_enable_write_45238 event_enable_write 3 45238 NULL
118636 +prism2_pda_proc_read_45246 prism2_pda_proc_read 3 45246 NULL
118637 +input_mt_init_slots_45279 input_mt_init_slots 2 45279 NULL
118638 +gfs2_fiemap_45282 gfs2_fiemap 4 45282 NULL
118639 +snd_pcm_oss_sync1_45298 snd_pcm_oss_sync1 2 45298 NULL
118640 +e1000_tx_map_45309 e1000_tx_map 5 45309 NULL
118641 +copy_vm86_regs_from_user_45340 copy_vm86_regs_from_user 3 45340 NULL
118642 +brcmf_sdio_died_dump_45359 brcmf_sdio_died_dump 3 45359 NULL
118643 +null_alloc_repbuf_45375 null_alloc_repbuf 3 45375 NULL
118644 +count_skb_frag_slots_45395 count_skb_frag_slots 0 45395 NULL
118645 +sock_recv_errqueue_45412 sock_recv_errqueue 3 45412 NULL
118646 +ieee80211_if_fmt_dot11MeshHWMProotInterval_45421 ieee80211_if_fmt_dot11MeshHWMProotInterval 3 45421 NULL
118647 +ll_iocontrol_register_45430 ll_iocontrol_register 2 45430 NULL
118648 +tty_buffer_alloc_45437 tty_buffer_alloc 2 45437 NULL
118649 +rds_ib_set_wr_signal_state_45463 rds_ib_set_wr_signal_state 0 45463 NULL
118650 +tracing_read_dyn_info_45468 tracing_read_dyn_info 3 45468 NULL
118651 +snd_pcm_hwsync_45479 snd_pcm_hwsync 0 45479 NULL
118652 +rds_message_copy_from_user_45510 rds_message_copy_from_user 3 45510 NULL
118653 +copy_macs_45534 copy_macs 4 45534 NULL
118654 +nla_attr_size_45545 nla_attr_size 0-1 45545 NULL
118655 +v9fs_direct_read_45546 v9fs_direct_read 3 45546 NULL
118656 +cx18_copy_mdl_to_user_45549 cx18_copy_mdl_to_user 4 45549 NULL
118657 +stats_dot11ACKFailureCount_read_45558 stats_dot11ACKFailureCount_read 3 45558 NULL
118658 +_regmap_bus_raw_write_45559 _regmap_bus_raw_write 2 45559 NULL
118659 +posix_acl_xattr_size_45561 posix_acl_xattr_size 0-1 45561 NULL
118660 +venus_rmdir_45564 venus_rmdir 4 45564 NULL
118661 +ath6kl_keepalive_write_45600 ath6kl_keepalive_write 3 45600 NULL
118662 +hidraw_get_report_45609 hidraw_get_report 3 45609 NULL
118663 +compat_mpctl_ioctl_45671 compat_mpctl_ioctl 2 45671 NULL
118664 +dgram_sendmsg_45679 dgram_sendmsg 4 45679 NULL
118665 +smk_write_ambient_45691 smk_write_ambient 3 45691 NULL
118666 +bscnl_emit_45699 bscnl_emit 2-5-0 45699 NULL nohasharray
118667 +unix_dgram_sendmsg_45699 unix_dgram_sendmsg 4 45699 &bscnl_emit_45699
118668 +sg_proc_write_adio_45704 sg_proc_write_adio 3 45704 NULL
118669 +snd_cs46xx_io_read_45734 snd_cs46xx_io_read 5 45734 NULL
118670 +rw_copy_check_uvector_45748 rw_copy_check_uvector 3-0 45748 NULL nohasharray
118671 +v4l2_ctrl_new_std_45748 v4l2_ctrl_new_std 5 45748 &rw_copy_check_uvector_45748
118672 +lkdtm_debugfs_read_45752 lkdtm_debugfs_read 3 45752 NULL
118673 +alloc_ts_config_45775 alloc_ts_config 1 45775 NULL
118674 +osc_checksum_type_seq_write_45785 osc_checksum_type_seq_write 3 45785 NULL
118675 +raw_setsockopt_45800 raw_setsockopt 5 45800 NULL
118676 +rds_tcp_inc_copy_to_user_45804 rds_tcp_inc_copy_to_user 3 45804 NULL
118677 +lbs_rdbbp_read_45805 lbs_rdbbp_read 3 45805 NULL
118678 +pcpu_alloc_alloc_info_45813 pcpu_alloc_alloc_info 1-2 45813 NULL
118679 +ll_max_readahead_mb_seq_write_45815 ll_max_readahead_mb_seq_write 3 45815 NULL
118680 +memcg_update_cache_size_45828 memcg_update_cache_size 2 45828 NULL
118681 +ipv6_recv_rxpmtu_45830 ipv6_recv_rxpmtu 3 45830 NULL
118682 +insert_state_45848 insert_state 0 45848 NULL
118683 +x509_process_extension_45854 x509_process_extension 5 45854 NULL
118684 +efx_tx_queue_insert_45859 efx_tx_queue_insert 2 45859 NULL
118685 +isdn_write_45863 isdn_write 3 45863 NULL
118686 +get_rdac_req_45882 get_rdac_req 3 45882 NULL
118687 +ocfs2_xattr_block_find_45891 ocfs2_xattr_block_find 0 45891 NULL
118688 +cfs_cpt_weight_45903 cfs_cpt_weight 0 45903 NULL
118689 +wm_adsp_region_to_reg_45915 wm_adsp_region_to_reg 0-2 45915 NULL
118690 +dbgfs_frame_45917 dbgfs_frame 3 45917 NULL
118691 +btree_keys_cachelines_45928 btree_keys_cachelines 0 45928 NULL
118692 +alloc_mr_45935 alloc_mr 1 45935 NULL
118693 +copy_to_45969 copy_to 3 45969 NULL
118694 +rb_simple_read_45972 rb_simple_read 3 45972 NULL
118695 +ioat2_dca_count_dca_slots_45984 ioat2_dca_count_dca_slots 0 45984 NULL
118696 +kobject_init_and_add_46003 kobject_init_and_add 0 46003 NULL
118697 +sierra_setup_urb_46029 sierra_setup_urb 5 46029 NULL
118698 +get_free_entries_46030 get_free_entries 1 46030 NULL nohasharray
118699 +fnic_reset_stats_read_46030 fnic_reset_stats_read 3 46030 &get_free_entries_46030
118700 +__access_remote_vm_46031 __access_remote_vm 0 46031 NULL
118701 +snd_emu10k1x_ptr_read_46049 snd_emu10k1x_ptr_read 0 46049 NULL
118702 +__ocfs2_move_extent_46060 __ocfs2_move_extent 3-4 46060 NULL nohasharray
118703 +dma_tx_errors_read_46060 dma_tx_errors_read 3 46060 &__ocfs2_move_extent_46060
118704 +sel_commit_bools_write_46077 sel_commit_bools_write 3 46077 NULL
118705 +memcg_update_array_size_46111 memcg_update_array_size 1 46111 NULL nohasharray
118706 +il3945_ucode_general_stats_read_46111 il3945_ucode_general_stats_read 3 46111 &memcg_update_array_size_46111
118707 +C_SYSC_writev_46113 C_SYSC_writev 3 46113 NULL
118708 +mlx4_ib_alloc_fast_reg_page_list_46119 mlx4_ib_alloc_fast_reg_page_list 2 46119 NULL
118709 +rtw_buf_update_46138 rtw_buf_update 4 46138 NULL
118710 +vb2_dma_sg_get_userptr_46146 vb2_dma_sg_get_userptr 3-2 46146 NULL
118711 +__netlink_change_ngroups_46156 __netlink_change_ngroups 2 46156 NULL
118712 +twl_direction_out_46182 twl_direction_out 2 46182 NULL
118713 +vxge_os_dma_malloc_46184 vxge_os_dma_malloc 2 46184 NULL
118714 +fq_resize_46195 fq_resize 2 46195 NULL
118715 +add_conn_list_46197 add_conn_list 3-0 46197 NULL
118716 +i2400m_op_msg_from_user_46213 i2400m_op_msg_from_user 4 46213 NULL
118717 +tm6000_i2c_recv_regs_46215 tm6000_i2c_recv_regs 5 46215 NULL
118718 +dsp_write_46218 dsp_write 2 46218 NULL
118719 +hash_netiface4_expire_46226 hash_netiface4_expire 4 46226 NULL
118720 +xen_setup_msi_irqs_46245 xen_setup_msi_irqs 2 46245 NULL
118721 +mpi_read_raw_data_46248 mpi_read_raw_data 2 46248 NULL
118722 +sg_proc_write_dressz_46316 sg_proc_write_dressz 3 46316 NULL
118723 +C_SYSC_ppoll_46319 C_SYSC_ppoll 2 46319 NULL
118724 +compat_SyS_readv_46328 compat_SyS_readv 3 46328 NULL nohasharray
118725 +__hwahc_dev_set_key_46328 __hwahc_dev_set_key 5 46328 &compat_SyS_readv_46328
118726 +iwl_dbgfs_chain_noise_read_46355 iwl_dbgfs_chain_noise_read 3 46355 NULL
118727 +smk_write_direct_46363 smk_write_direct 3 46363 NULL
118728 +fuse_file_aio_write_46399 fuse_file_aio_write 4 46399 NULL
118729 +crypto_ablkcipher_reqsize_46411 crypto_ablkcipher_reqsize 0 46411 NULL
118730 +ttm_page_pool_get_pages_46431 ttm_page_pool_get_pages 0-5 46431 NULL
118731 +cfs_power2_roundup_46433 cfs_power2_roundup 0-1 46433 NULL
118732 +cp210x_set_config_46447 cp210x_set_config 4 46447 NULL
118733 +il_dbgfs_clear_traffic_stats_write_46458 il_dbgfs_clear_traffic_stats_write 3 46458 NULL
118734 +filldir64_46469 filldir64 3 46469 NULL
118735 +fill_in_write_vector_46498 fill_in_write_vector 0 46498 NULL
118736 +pin_code_reply_46510 pin_code_reply 4 46510 NULL
118737 +mthca_alloc_cq_buf_46512 mthca_alloc_cq_buf 3 46512 NULL
118738 +nouveau_drm_ioctl_46514 nouveau_drm_ioctl 2 46514 NULL nohasharray
118739 +kmsg_read_46514 kmsg_read 3 46514 &nouveau_drm_ioctl_46514
118740 +nl80211_send_rx_assoc_46538 nl80211_send_rx_assoc 4 46538 NULL
118741 +dn_current_mss_46574 dn_current_mss 0 46574 NULL
118742 +serverworks_create_gatt_pages_46582 serverworks_create_gatt_pages 1 46582 NULL
118743 +snd_compr_write_data_46592 snd_compr_write_data 3 46592 NULL
118744 +il3945_stats_flag_46606 il3945_stats_flag 0-3 46606 NULL
118745 +vscnprintf_46617 vscnprintf 0-2 46617 NULL
118746 +__kfifo_out_r_46623 __kfifo_out_r 0-3 46623 NULL
118747 +request_key_async_with_auxdata_46624 request_key_async_with_auxdata 4 46624 NULL
118748 +pci_enable_device_46642 pci_enable_device 0 46642 NULL
118749 +vfs_getxattr_alloc_46649 vfs_getxattr_alloc 0 46649 NULL
118750 +e1000_tx_map_46672 e1000_tx_map 4 46672 NULL
118751 +l2cap_create_le_flowctl_pdu_46682 l2cap_create_le_flowctl_pdu 3 46682 NULL
118752 +alloc_data_packet_46698 alloc_data_packet 1 46698 NULL
118753 +__ilog2_u32_46706 __ilog2_u32 0 46706 NULL
118754 +erst_dbg_write_46715 erst_dbg_write 3 46715 NULL
118755 +wl1271_rx_filter_alloc_field_46721 wl1271_rx_filter_alloc_field 5 46721 NULL
118756 +irq_domain_add_simple_46734 irq_domain_add_simple 2 46734 NULL
118757 +read_file_tx99_46741 read_file_tx99 3 46741 NULL
118758 +hest_ghes_dev_register_46766 hest_ghes_dev_register 1 46766 NULL
118759 +int_hw_irq_en_46776 int_hw_irq_en 3 46776 NULL
118760 +_xfs_buf_get_pages_46811 _xfs_buf_get_pages 2 46811 NULL
118761 +xfs_iroot_realloc_46826 xfs_iroot_realloc 2 46826 NULL
118762 +shmem_pwrite_fast_46842 shmem_pwrite_fast 3 46842 NULL
118763 +spi_async_46857 spi_async 0 46857 NULL
118764 +vsnprintf_46863 vsnprintf 0 46863 NULL
118765 +nvme_alloc_queue_46865 nvme_alloc_queue 3 46865 NULL
118766 +qp_memcpy_from_queue_iov_46874 qp_memcpy_from_queue_iov 5-4 46874 NULL
118767 +lov_iocontrol_46876 lov_iocontrol 3 46876 NULL
118768 +ixgbe_dbg_reg_ops_write_46895 ixgbe_dbg_reg_ops_write 3 46895 NULL
118769 +sk_mem_pages_46896 sk_mem_pages 0-1 46896 NULL
118770 +ieee80211_if_fmt_power_mode_46906 ieee80211_if_fmt_power_mode 3 46906 NULL
118771 +wlcore_alloc_hw_46917 wlcore_alloc_hw 3-1 46917 NULL
118772 +fb_write_46924 fb_write 3 46924 NULL
118773 +__sctp_setsockopt_connectx_46949 __sctp_setsockopt_connectx 3 46949 NULL
118774 +qla4xxx_post_aen_work_46953 qla4xxx_post_aen_work 3 46953 NULL
118775 +SYSC_poll_46965 SYSC_poll 2 46965 NULL
118776 +crypto_tfm_alg_alignmask_46971 crypto_tfm_alg_alignmask 0 46971 NULL
118777 +mgmt_pending_add_46976 mgmt_pending_add 5 46976 NULL
118778 +strlcat_46985 strlcat 3 46985 NULL
118779 +bitmap_file_clear_bit_46990 bitmap_file_clear_bit 2 46990 NULL
118780 +sel_write_bool_46996 sel_write_bool 3 46996 NULL
118781 +blk_rq_map_kern_47004 blk_rq_map_kern 4 47004 NULL
118782 +cx231xx_init_bulk_47024 cx231xx_init_bulk 3-2-4 47024 NULL
118783 +fs_path_len_47060 fs_path_len 0 47060 NULL
118784 +event_trigger_regex_write_47067 event_trigger_regex_write 3 47067 NULL
118785 +ext4_xattr_list_entries_47070 ext4_xattr_list_entries 0 47070 NULL
118786 +pipeline_dec_packet_in_read_47076 pipeline_dec_packet_in_read 3 47076 NULL
118787 +scsi_deactivate_tcq_47086 scsi_deactivate_tcq 2 47086 NULL
118788 +iwl_dump_nic_event_log_47089 iwl_dump_nic_event_log 0 47089 NULL
118789 +ptlrpc_lprocfs_threads_max_seq_write_47104 ptlrpc_lprocfs_threads_max_seq_write 3 47104 NULL
118790 +mousedev_read_47123 mousedev_read 3 47123 NULL
118791 +upcall_msg_size_47141 upcall_msg_size 2 47141 NULL
118792 +acpi_ut_initialize_buffer_47143 acpi_ut_initialize_buffer 2 47143 NULL nohasharray
118793 +ses_recv_diag_47143 ses_recv_diag 4 47143 &acpi_ut_initialize_buffer_47143
118794 +mxms_headerlen_47161 mxms_headerlen 0 47161 NULL
118795 +rs_sta_dbgfs_rate_scale_data_read_47165 rs_sta_dbgfs_rate_scale_data_read 3 47165 NULL
118796 +rts51x_ms_rw_47171 rts51x_ms_rw 3-4 47171 NULL
118797 +options_write_47243 options_write 3 47243 NULL
118798 +portcntrs_1_read_47253 portcntrs_1_read 3 47253 NULL
118799 +ablkcipher_next_slow_47274 ablkcipher_next_slow 4-3 47274 NULL
118800 +gfs2_readpages_47285 gfs2_readpages 4 47285 NULL
118801 +vsnprintf_47291 vsnprintf 0 47291 NULL
118802 +SYSC_semop_47292 SYSC_semop 3 47292 NULL
118803 +tx_internal_desc_overflow_read_47300 tx_internal_desc_overflow_read 3 47300 NULL
118804 +nouveau_fb_create__47316 nouveau_fb_create_ 4 47316 NULL
118805 +ieee80211_if_read_dot11MeshHoldingTimeout_47356 ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 NULL
118806 +avc_get_hash_stats_47359 avc_get_hash_stats 0 47359 NULL
118807 +kvm_arch_create_memslot_47364 kvm_arch_create_memslot 3 47364 NULL nohasharray
118808 +__output_copy_user_47364 __output_copy_user 3 47364 &kvm_arch_create_memslot_47364
118809 +__bio_map_kern_47379 __bio_map_kern 3 47379 NULL
118810 +nv_rd32_47390 nv_rd32 0 47390 NULL nohasharray
118811 +trace_options_core_read_47390 trace_options_core_read 3 47390 &nv_rd32_47390
118812 +nametbl_list_47391 nametbl_list 2 47391 NULL
118813 +dgrp_net_write_47392 dgrp_net_write 3 47392 NULL
118814 +pfkey_sendmsg_47394 pfkey_sendmsg 4 47394 NULL
118815 +lbs_wrmac_write_47400 lbs_wrmac_write 3 47400 NULL
118816 +sta_vht_capa_read_47409 sta_vht_capa_read 3 47409 NULL
118817 +crypto_ablkcipher_alignmask_47410 crypto_ablkcipher_alignmask 0 47410 NULL
118818 +lbs_wrrf_write_47418 lbs_wrrf_write 3 47418 NULL
118819 +C_SYSC_set_mempolicy_47466 C_SYSC_set_mempolicy 3 47466 NULL
118820 +nvme_trans_send_fw_cmd_47479 nvme_trans_send_fw_cmd 4 47479 NULL
118821 +newpart_47485 newpart 6-4 47485 NULL
118822 +mcp23s17_read_regs_47491 mcp23s17_read_regs 4 47491 NULL
118823 +core_sys_select_47494 core_sys_select 1 47494 NULL
118824 +as3722_block_write_47503 as3722_block_write 2-3 47503 NULL
118825 +unlink_simple_47506 unlink_simple 3 47506 NULL
118826 +pstore_decompress_47510 pstore_decompress 0 47510 NULL
118827 +__proc_lnet_portal_rotor_47529 __proc_lnet_portal_rotor 5 47529 NULL
118828 +snd_pcm_resume_47530 snd_pcm_resume 0 47530 NULL
118829 +process_vm_rw_47533 process_vm_rw 3-5 47533 NULL nohasharray
118830 +vscnprintf_47533 vscnprintf 0-2 47533 &process_vm_rw_47533
118831 +ieee80211_if_fmt_min_discovery_timeout_47539 ieee80211_if_fmt_min_discovery_timeout 3 47539 NULL
118832 +rtw_cfg80211_set_assoc_resp_wpsp2pie_47558 rtw_cfg80211_set_assoc_resp_wpsp2pie 3 47558 NULL
118833 +read_ldt_47570 read_ldt 2 47570 NULL
118834 +isku_sysfs_read_last_set_47572 isku_sysfs_read_last_set 6 47572 NULL
118835 +btrfs_stack_header_bytenr_47589 btrfs_stack_header_bytenr 0 47589 NULL
118836 +ext4_kvzalloc_47605 ext4_kvzalloc 1 47605 NULL
118837 +sctp_ssnmap_new_47608 sctp_ssnmap_new 2-1 47608 NULL
118838 +cache_read_pipefs_47615 cache_read_pipefs 3 47615 NULL
118839 +twl4030_clear_set_47624 twl4030_clear_set 4 47624 NULL
118840 +ccp_sha_setkey_47633 ccp_sha_setkey 3 47633 NULL
118841 +get_size_47644 get_size 1-2 47644 NULL
118842 +snd_pcm_info_47699 snd_pcm_info 0 47699 NULL
118843 +packet_recvmsg_47700 packet_recvmsg 4 47700 NULL nohasharray
118844 +ipath_format_hwmsg_47700 ipath_format_hwmsg 2 47700 &packet_recvmsg_47700
118845 +save_microcode_47717 save_microcode 3 47717 NULL
118846 +bits_to_user_47733 bits_to_user 2-3 47733 NULL
118847 +carl9170_debugfs_read_47738 carl9170_debugfs_read 3 47738 NULL
118848 +ir_prepare_write_buffer_47747 ir_prepare_write_buffer 3 47747 NULL
118849 +mvumi_alloc_mem_resource_47750 mvumi_alloc_mem_resource 3 47750 NULL
118850 +alloc_sched_domains_47756 alloc_sched_domains 1 47756 NULL
118851 +uwb_ie_dump_hex_47774 uwb_ie_dump_hex 4 47774 NULL
118852 +SyS_setgroups16_47780 SyS_setgroups16 1 47780 NULL
118853 +error_error_numll_frame_cts_start_read_47781 error_error_numll_frame_cts_start_read 3 47781 NULL
118854 +posix_acl_fix_xattr_from_user_47793 posix_acl_fix_xattr_from_user 2 47793 NULL
118855 +lov_packmd_47810 lov_packmd 0 47810 NULL
118856 +tree_mod_log_insert_move_47823 tree_mod_log_insert_move 5 47823 NULL
118857 +pinconf_dbg_config_write_47835 pinconf_dbg_config_write 3 47835 NULL
118858 +KEY_SIZE_47855 KEY_SIZE 0 47855 NULL
118859 +vhci_read_47878 vhci_read 3 47878 NULL
118860 +ubi_wl_put_peb_47886 ubi_wl_put_peb 0 47886 NULL
118861 +keyctl_instantiate_key_common_47889 keyctl_instantiate_key_common 4 47889 NULL
118862 +cfs_percpt_alloc_47918 cfs_percpt_alloc 2 47918 NULL
118863 +comedi_write_47926 comedi_write 3 47926 NULL
118864 +nvme_trans_get_blk_desc_len_47946 nvme_trans_get_blk_desc_len 0-2 47946 NULL
118865 +arch_setup_msi_irq_47959 arch_setup_msi_irq 0 47959 NULL
118866 +gether_get_ifname_47972 gether_get_ifname 3 47972 NULL
118867 +mempool_resize_47983 mempool_resize 2 47983 NULL nohasharray
118868 +iwl_dbgfs_ucode_tracing_read_47983 iwl_dbgfs_ucode_tracing_read 3 47983 &mempool_resize_47983
118869 +dbg_port_buf_47990 dbg_port_buf 2 47990 NULL
118870 +ib_umad_write_47993 ib_umad_write 3 47993 NULL
118871 +lustre_cfg_len_48002 lustre_cfg_len 0 48002 NULL
118872 +gdm_tty_recv_complete_48011 gdm_tty_recv_complete 2 48011 NULL
118873 +bio_integrity_set_tag_48035 bio_integrity_set_tag 3 48035 NULL
118874 +pppoe_sendmsg_48039 pppoe_sendmsg 4 48039 NULL
118875 +SYSC_writev_48040 SYSC_writev 3 48040 NULL
118876 +wpan_phy_alloc_48056 wpan_phy_alloc 1 48056 NULL
118877 +posix_acl_alloc_48063 posix_acl_alloc 1 48063 NULL
118878 +palmas_bulk_write_48068 palmas_bulk_write 2-3-5 48068 NULL
118879 +disc_write_48070 disc_write 3 48070 NULL
118880 +mmc_alloc_host_48097 mmc_alloc_host 1 48097 NULL
118881 +skb_copy_datagram_const_iovec_48102 skb_copy_datagram_const_iovec 4-2-5 48102 NULL
118882 +wm_latency_write_48125 wm_latency_write 3 48125 NULL
118883 +vmw_framebuffer_surface_dirty_48132 vmw_framebuffer_surface_dirty 6 48132 NULL
118884 +set_discoverable_48141 set_discoverable 4 48141 NULL
118885 +dn_fib_count_nhs_48145 dn_fib_count_nhs 0 48145 NULL
118886 +SyS_vmsplice_48150 SyS_vmsplice 3 48150 NULL
118887 +_add_to_r4w_48152 _add_to_r4w 4 48152 NULL
118888 +isr_dma1_done_read_48159 isr_dma1_done_read 3 48159 NULL
118889 +c4iw_id_table_alloc_48163 c4iw_id_table_alloc 3 48163 NULL
118890 +rbd_obj_method_sync_48170 rbd_obj_method_sync 8 48170 NULL
118891 +alloc_cc770dev_48186 alloc_cc770dev 1 48186 NULL
118892 +cfg80211_process_deauth_48200 cfg80211_process_deauth 3 48200 NULL
118893 +ext4_index_trans_blocks_48205 ext4_index_trans_blocks 0-2 48205 NULL
118894 +snd_seq_dump_var_event_48209 snd_seq_dump_var_event 0 48209 NULL
118895 +ll_direct_IO_26_48216 ll_direct_IO_26 4 48216 NULL
118896 +uv_blade_nr_possible_cpus_48226 uv_blade_nr_possible_cpus 0 48226 NULL
118897 +nilfs_readpages_48229 nilfs_readpages 4 48229 NULL
118898 +read_file_recv_48232 read_file_recv 3 48232 NULL
118899 +unaccount_shadowed_48233 unaccount_shadowed 2 48233 NULL
118900 +nouveau_i2c_port_create__48240 nouveau_i2c_port_create_ 7 48240 NULL
118901 +nfsctl_transaction_read_48250 nfsctl_transaction_read 3 48250 NULL
118902 +batadv_socket_read_48257 batadv_socket_read 3 48257 NULL
118903 +cache_write_pipefs_48270 cache_write_pipefs 3 48270 NULL
118904 +trace_options_write_48275 trace_options_write 3 48275 NULL
118905 +send_set_info_48288 send_set_info 7 48288 NULL
118906 +lpfc_idiag_extacc_read_48301 lpfc_idiag_extacc_read 3 48301 NULL
118907 +timblogiw_read_48305 timblogiw_read 3 48305 NULL
118908 +hash_setkey_48310 hash_setkey 3 48310 NULL
118909 +skb_add_data_48363 skb_add_data 3 48363 NULL
118910 +tx_frag_init_called_read_48377 tx_frag_init_called_read 3 48377 NULL
118911 +lbs_debugfs_write_48413 lbs_debugfs_write 3 48413 NULL
118912 +uhid_event_from_user_48417 uhid_event_from_user 2 48417 NULL
118913 +div64_u64_rem_48418 div64_u64_rem 0-1-2 48418 NULL
118914 +snd_power_wait_48422 snd_power_wait 0 48422 NULL
118915 +pwr_tx_without_ps_read_48423 pwr_tx_without_ps_read 3 48423 NULL
118916 +print_filtered_48442 print_filtered 2-0 48442 NULL
118917 +tun_recvmsg_48463 tun_recvmsg 4 48463 NULL
118918 +compat_SyS_preadv64_48469 compat_SyS_preadv64 3 48469 NULL
118919 +_iwl_dbgfs_bt_tx_prio_write_48473 _iwl_dbgfs_bt_tx_prio_write 3 48473 NULL
118920 +ipath_format_hwerrors_48487 ipath_format_hwerrors 5 48487 NULL
118921 +r8712_usbctrl_vendorreq_48489 r8712_usbctrl_vendorreq 6 48489 NULL
118922 +send_control_msg_48498 send_control_msg 6 48498 NULL
118923 +count_masked_bytes_48507 count_masked_bytes 0-1 48507 NULL
118924 +diva_os_copy_to_user_48508 diva_os_copy_to_user 4 48508 NULL
118925 +brcmf_sdio_trap_info_48510 brcmf_sdio_trap_info 4 48510 NULL
118926 +phantom_get_free_48514 phantom_get_free 0 48514 NULL
118927 +drbd_bm_capacity_48530 drbd_bm_capacity 0 48530 NULL
118928 +raid10_size_48571 raid10_size 0-2-3 48571 NULL
118929 +llog_data_len_48607 llog_data_len 1 48607 NULL
118930 +do_ip_vs_set_ctl_48641 do_ip_vs_set_ctl 4 48641 NULL
118931 +ll_rw_extents_stats_pp_seq_write_48651 ll_rw_extents_stats_pp_seq_write 3 48651 NULL
118932 +mtd_read_48655 mtd_read 0 48655 NULL
118933 +aes_encrypt_packets_read_48666 aes_encrypt_packets_read 3 48666 NULL
118934 +sm501_create_subdev_48668 sm501_create_subdev 3-4 48668 NULL
118935 +ubi_eba_unmap_leb_48671 ubi_eba_unmap_leb 0 48671 NULL
118936 +security_inode_setattr_48689 security_inode_setattr 0 48689 NULL
118937 +hysdn_log_write_48694 hysdn_log_write 3 48694 NULL
118938 +altera_drscan_48698 altera_drscan 2 48698 NULL
118939 +kvm_set_irq_routing_48704 kvm_set_irq_routing 3 48704 NULL
118940 +lpfc_idiag_drbacc_write_48712 lpfc_idiag_drbacc_write 3 48712 NULL
118941 +SyS_lgetxattr_48719 SyS_lgetxattr 4 48719 NULL
118942 +ath6kl_usb_bmi_read_48745 ath6kl_usb_bmi_read 3 48745 NULL
118943 +ath6kl_regwrite_read_48747 ath6kl_regwrite_read 3 48747 NULL
118944 +l2cap_segment_sdu_48772 l2cap_segment_sdu 4 48772 NULL
118945 +gfs2_direct_IO_48774 gfs2_direct_IO 4 48774 NULL
118946 +il3945_sta_dbgfs_stats_table_read_48802 il3945_sta_dbgfs_stats_table_read 3 48802 NULL
118947 +twa_change_queue_depth_48808 twa_change_queue_depth 2 48808 NULL
118948 +atomic_counters_read_48827 atomic_counters_read 3 48827 NULL
118949 +azx_get_position_48841 azx_get_position 0 48841 NULL
118950 +vc_do_resize_48842 vc_do_resize 3-4 48842 NULL
118951 +comedi_buf_write_alloc_48846 comedi_buf_write_alloc 0-2 48846 NULL
118952 +suspend_dtim_interval_write_48854 suspend_dtim_interval_write 3 48854 NULL
118953 +C_SYSC_pwritev64_48864 C_SYSC_pwritev64 3 48864 NULL nohasharray
118954 +viafb_dvp1_proc_write_48864 viafb_dvp1_proc_write 3 48864 &C_SYSC_pwritev64_48864
118955 +__ffs_ep0_read_events_48868 __ffs_ep0_read_events 3 48868 NULL
118956 +crypto_cipher_ctxsize_48890 crypto_cipher_ctxsize 0 48890 NULL
118957 +joydev_handle_JSIOCSAXMAP_48898 joydev_handle_JSIOCSAXMAP 3 48898 NULL
118958 +xdi_copy_to_user_48900 xdi_copy_to_user 4 48900 NULL
118959 +msg_hdr_sz_48908 msg_hdr_sz 0 48908 NULL
118960 +snd_pcm_update_hw_ptr_48925 snd_pcm_update_hw_ptr 0 48925 NULL
118961 +sep_crypto_dma_48937 sep_crypto_dma 0 48937 NULL
118962 +si5351_write_parameters_48940 si5351_write_parameters 2 48940 NULL
118963 +event_heart_beat_read_48961 event_heart_beat_read 3 48961 NULL
118964 +nand_ecc_test_run_48966 nand_ecc_test_run 1 48966 NULL
118965 +vmci_handle_arr_create_48971 vmci_handle_arr_create 1 48971 NULL
118966 +rds_rm_size_48996 rds_rm_size 0-2 48996 NULL
118967 +sel_write_enforce_48998 sel_write_enforce 3 48998 NULL
118968 +null_alloc_rs_49019 null_alloc_rs 2 49019 NULL
118969 +filemap_check_errors_49022 filemap_check_errors 0 49022 NULL
118970 +transient_status_49027 transient_status 4 49027 NULL
118971 +ll_xattr_cache_add_49032 ll_xattr_cache_add 4-0 49032 NULL
118972 +scsi_register_49094 scsi_register 2 49094 NULL
118973 +compat_do_readv_writev_49102 compat_do_readv_writev 4 49102 NULL
118974 +xfrm_replay_state_esn_len_49119 xfrm_replay_state_esn_len 0 49119 NULL
118975 +ll_max_cached_mb_seq_write_49122 ll_max_cached_mb_seq_write 3 49122 NULL
118976 +pt_read_49136 pt_read 3 49136 NULL nohasharray
118977 +netxen_setup_msi_interrupts_49136 netxen_setup_msi_interrupts 2 49136 &pt_read_49136
118978 +ipwireless_tty_received_49154 ipwireless_tty_received 3 49154 NULL
118979 +f2fs_acl_count_49155 f2fs_acl_count 0-1 49155 NULL
118980 +ipw_queue_tx_init_49161 ipw_queue_tx_init 3 49161 NULL
118981 +__jfs_setxattr_49175 __jfs_setxattr 5 49175 NULL
118982 +ath6kl_bgscan_int_write_49178 ath6kl_bgscan_int_write 3 49178 NULL
118983 +dvb_dvr_ioctl_49182 dvb_dvr_ioctl 2 49182 NULL
118984 +print_queue_49191 print_queue 0-4 49191 NULL
118985 +root_nfs_cat_49192 root_nfs_cat 3 49192 NULL
118986 +iwl_dbgfs_ucode_general_stats_read_49199 iwl_dbgfs_ucode_general_stats_read 3 49199 NULL
118987 +il4965_rs_sta_dbgfs_stats_table_read_49206 il4965_rs_sta_dbgfs_stats_table_read 3 49206 NULL
118988 +do_jffs2_getxattr_49210 do_jffs2_getxattr 0 49210 NULL
118989 +nouveau_therm_create__49228 nouveau_therm_create_ 4 49228 NULL
118990 +ieee80211_if_read_rssi_threshold_49260 ieee80211_if_read_rssi_threshold 3 49260 NULL
118991 +isku_sysfs_read_keys_media_49268 isku_sysfs_read_keys_media 6 49268 NULL
118992 +ptlrpc_check_set_49277 ptlrpc_check_set 0 49277 NULL
118993 +rx_filter_beacon_filter_read_49279 rx_filter_beacon_filter_read 3 49279 NULL
118994 +viafb_dfph_proc_write_49288 viafb_dfph_proc_write 3 49288 NULL
118995 +uio_read_49300 uio_read 3 49300 NULL
118996 +isku_sysfs_read_keys_macro_49312 isku_sysfs_read_keys_macro 6 49312 NULL
118997 +SYSC_mincore_49319 SYSC_mincore 2-1 49319 NULL
118998 +fwtty_port_handler_49327 fwtty_port_handler 9 49327 NULL
118999 +srpt_alloc_ioctx_ring_49330 srpt_alloc_ioctx_ring 2-4-3 49330 NULL
119000 +joydev_ioctl_common_49359 joydev_ioctl_common 2 49359 NULL
119001 +iscsi_alloc_session_49390 iscsi_alloc_session 3 49390 NULL
119002 +ext4_ext_index_trans_blocks_49396 ext4_ext_index_trans_blocks 0 49396 NULL
119003 +rx_streaming_always_read_49401 rx_streaming_always_read 3 49401 NULL
119004 +tnode_alloc_49407 tnode_alloc 1 49407 NULL
119005 +samples_to_bytes_49426 samples_to_bytes 0-2 49426 NULL
119006 +compat_do_msg_fill_49440 compat_do_msg_fill 3 49440 NULL
119007 +__hfsplus_getxattr_49460 __hfsplus_getxattr 0 49460 NULL
119008 +agp_3_5_isochronous_node_enable_49465 agp_3_5_isochronous_node_enable 3 49465 NULL
119009 +xfs_iformat_local_49472 xfs_iformat_local 4 49472 NULL
119010 +isr_decrypt_done_read_49490 isr_decrypt_done_read 3 49490 NULL
119011 +iwl_dbgfs_disable_power_off_read_49517 iwl_dbgfs_disable_power_off_read 3 49517 NULL
119012 +SyS_listxattr_49519 SyS_listxattr 3 49519 NULL
119013 +emulator_write_phys_49520 emulator_write_phys 2-4 49520 NULL
119014 +smk_write_access_49561 smk_write_access 3 49561 NULL
119015 +alloc_chunk_49575 alloc_chunk 1 49575 NULL
119016 +sctp_setsockopt_default_send_param_49578 sctp_setsockopt_default_send_param 3 49578 NULL
119017 +evm_inode_setattr_49594 evm_inode_setattr 0 49594 NULL
119018 +tap_write_49595 tap_write 3 49595 NULL
119019 +isr_wakeups_read_49607 isr_wakeups_read 3 49607 NULL
119020 +btrfs_mksubvol_49616 btrfs_mksubvol 3 49616 NULL
119021 +heap_init_49617 heap_init 2 49617 NULL
119022 +smk_write_doi_49621 smk_write_doi 3 49621 NULL
119023 +port_fops_read_49626 port_fops_read 3 49626 NULL
119024 +btrfsic_cmp_log_and_dev_bytenr_49628 btrfsic_cmp_log_and_dev_bytenr 2 49628 NULL
119025 +aa_simple_write_to_buffer_49683 aa_simple_write_to_buffer 3-4 49683 NULL
119026 +SyS_pwritev_49688 SyS_pwritev 3 49688 NULL
119027 +__setup_irq_49696 __setup_irq 0 49696 NULL
119028 +__copy_from_user_nocheck_49699 __copy_from_user_nocheck 0-3 49699 NULL
119029 +cx2341x_ctrl_new_menu_49700 cx2341x_ctrl_new_menu 3 49700 NULL
119030 +write_pool_49718 write_pool 3 49718 NULL
119031 +kvm_mmu_notifier_invalidate_page_49723 kvm_mmu_notifier_invalidate_page 3 49723 NULL
119032 +sep_create_dcb_dmatables_context_kernel_49728 sep_create_dcb_dmatables_context_kernel 6 49728 NULL
119033 +zd_usb_iowrite16v_49744 zd_usb_iowrite16v 3 49744 NULL
119034 +btrfs_chunk_num_stripes_49751 btrfs_chunk_num_stripes 0 49751 NULL
119035 +fuse_wr_pages_49753 fuse_wr_pages 0-2-1 49753 NULL
119036 +key_conf_keylen_read_49758 key_conf_keylen_read 3 49758 NULL
119037 +fuse_conn_waiting_read_49762 fuse_conn_waiting_read 3 49762 NULL
119038 +ceph_osdc_readpages_49789 ceph_osdc_readpages 0 49789 NULL
119039 +nfs4_acl_new_49806 nfs4_acl_new 1 49806 NULL
119040 +__of_parse_phandle_with_args_49807 __of_parse_phandle_with_args 0 49807 NULL
119041 +ntfs_copy_from_user_iovec_49829 ntfs_copy_from_user_iovec 6-3-0 49829 NULL
119042 +add_uuid_49831 add_uuid 4 49831 NULL
119043 +twl4030_write_49846 twl4030_write 2 49846 NULL
119044 +scsi_dispatch_cmd_entry_49848 scsi_dispatch_cmd_entry 3 49848 NULL
119045 +timeradd_entry_49850 timeradd_entry 3 49850 NULL
119046 +fiemap_count_to_size_49869 fiemap_count_to_size 0-1 49869 NULL
119047 +sctp_setsockopt_bindx_49870 sctp_setsockopt_bindx 3 49870 NULL
119048 +osc_brw_49896 osc_brw 4 49896 NULL
119049 +ieee80211_if_fmt_dtim_count_49987 ieee80211_if_fmt_dtim_count 3 49987 NULL
119050 +drm_buffer_copy_from_user_49990 drm_buffer_copy_from_user 3 49990 NULL
119051 +l2cap_chan_send_49995 l2cap_chan_send 3 49995 NULL
119052 +dn_mss_from_pmtu_50011 dn_mss_from_pmtu 0-2 50011 NULL
119053 +security_context_to_sid_50019 security_context_to_sid 2 50019 NULL
119054 +isdn_read_50021 isdn_read 3 50021 NULL
119055 +mdc_rename_pack_50023 mdc_rename_pack 4-6 50023 NULL
119056 +brcmf_debugfs_chipinfo_read_50033 brcmf_debugfs_chipinfo_read 3 50033 NULL
119057 +ioread8_50049 ioread8 0 50049 NULL
119058 +fuse_conn_max_background_write_50061 fuse_conn_max_background_write 3 50061 NULL
119059 +__kfifo_dma_in_prepare_50081 __kfifo_dma_in_prepare 4 50081 NULL
119060 +dev_set_alias_50084 dev_set_alias 3 50084 NULL
119061 +libcfs_ioctl_popdata_50087 libcfs_ioctl_popdata 3 50087 NULL
119062 +sock_setsockopt_50088 sock_setsockopt 5 50088 NULL
119063 +altera_swap_dr_50090 altera_swap_dr 2 50090 NULL
119064 +android_set_cntry_50100 android_set_cntry 0 50100 NULL
119065 +read_file_slot_50111 read_file_slot 3 50111 NULL
119066 +rx_streaming_interval_write_50120 rx_streaming_interval_write 3 50120 NULL
119067 +jfs_direct_IO_50125 jfs_direct_IO 4 50125 NULL
119068 +SYSC_preadv_50134 SYSC_preadv 3 50134 NULL
119069 +tx_frag_need_fragmentation_read_50153 tx_frag_need_fragmentation_read 3 50153 NULL
119070 +kmalloc_node_50163 kmalloc_node 1 50163 NULL
119071 +rx_filter_ibss_filter_read_50167 rx_filter_ibss_filter_read 3 50167 NULL
119072 +ahd_probe_stack_size_50168 ahd_probe_stack_size 0 50168 NULL
119073 +odev_update_50169 odev_update 2 50169 NULL
119074 +ubi_resize_volume_50172 ubi_resize_volume 2 50172 NULL nohasharray
119075 +ieee80211_if_fmt_dot11MeshHWMPRannInterval_50172 ieee80211_if_fmt_dot11MeshHWMPRannInterval 3 50172 &ubi_resize_volume_50172
119076 +cfg80211_roamed_bss_50198 cfg80211_roamed_bss 4-6 50198 NULL
119077 +cyttsp4_probe_50201 cyttsp4_probe 4 50201 NULL
119078 +rx_rx_timeout_wa_read_50204 rx_rx_timeout_wa_read 3 50204 NULL
119079 +l2cap_sock_setsockopt_50207 l2cap_sock_setsockopt 5 50207 NULL
119080 +mon_bin_compat_ioctl_50234 mon_bin_compat_ioctl 3 50234 NULL
119081 +sg_kmalloc_50240 sg_kmalloc 1 50240 NULL
119082 +rxrpc_setsockopt_50286 rxrpc_setsockopt 5 50286 NULL
119083 +soc_codec_reg_show_50302 soc_codec_reg_show 0-3 50302 NULL
119084 +SYSC_flistxattr_50307 SYSC_flistxattr 3 50307 NULL
119085 +SYSC_sched_setaffinity_50310 SYSC_sched_setaffinity 2 50310 NULL
119086 +soc_camera_read_50319 soc_camera_read 3 50319 NULL
119087 +do_launder_page_50329 do_launder_page 0 50329 NULL
119088 +nouveau_engine_create__50331 nouveau_engine_create_ 7 50331 NULL
119089 +lpfc_idiag_pcicfg_read_50334 lpfc_idiag_pcicfg_read 3 50334 NULL
119090 +snd_pcm_lib_writev_50337 snd_pcm_lib_writev 0-3 50337 NULL
119091 +tpm_read_50344 tpm_read 3 50344 NULL
119092 +isdn_ppp_read_50356 isdn_ppp_read 4 50356 NULL
119093 +iwl_dbgfs_echo_test_write_50362 iwl_dbgfs_echo_test_write 3 50362 NULL
119094 +xfrm_send_migrate_50365 xfrm_send_migrate 5 50365 NULL
119095 +roccat_common2_receive_50369 roccat_common2_receive 4 50369 NULL
119096 +sl_alloc_bufs_50380 sl_alloc_bufs 2 50380 NULL
119097 +l2tp_ip_sendmsg_50411 l2tp_ip_sendmsg 4 50411 NULL
119098 +iscsi_create_conn_50425 iscsi_create_conn 2 50425 NULL
119099 +validate_acl_mac_addrs_50429 validate_acl_mac_addrs 0 50429 NULL
119100 +btrfs_error_discard_extent_50444 btrfs_error_discard_extent 2 50444 NULL
119101 +pgctrl_write_50453 pgctrl_write 3 50453 NULL
119102 +device_create_sys_dev_entry_50458 device_create_sys_dev_entry 0 50458 NULL
119103 +cfs_size_round_50472 cfs_size_round 0-1 50472 NULL
119104 +cdrom_read_cdda_50478 cdrom_read_cdda 4 50478 NULL
119105 +mei_io_cb_alloc_req_buf_50493 mei_io_cb_alloc_req_buf 2 50493 NULL
119106 +pwr_rcvd_awake_beacons_read_50505 pwr_rcvd_awake_beacons_read 3 50505 NULL
119107 +ath6kl_set_ap_probe_resp_ies_50539 ath6kl_set_ap_probe_resp_ies 3 50539 NULL
119108 +usbat_flash_write_data_50553 usbat_flash_write_data 4 50553 NULL
119109 +self_check_peb_vid_hdr_50563 self_check_peb_vid_hdr 0 50563 NULL
119110 +fat_readpages_50582 fat_readpages 4 50582 NULL
119111 +iwl_dbgfs_missed_beacon_read_50584 iwl_dbgfs_missed_beacon_read 3 50584 NULL
119112 +xillybus_write_50605 xillybus_write 3 50605 NULL
119113 +rx_rx_checksum_result_read_50617 rx_rx_checksum_result_read 3 50617 NULL
119114 +sparse_early_usemaps_alloc_node_50623 sparse_early_usemaps_alloc_node 4 50623 NULL
119115 +simple_transaction_get_50633 simple_transaction_get 3 50633 NULL
119116 +ath6kl_tm_rx_event_50664 ath6kl_tm_rx_event 3 50664 NULL
119117 +bnad_debugfs_read_50665 bnad_debugfs_read 3 50665 NULL
119118 +prism2_read_fid_reg_50689 prism2_read_fid_reg 0 50689 NULL
119119 +xfs_growfs_get_hdr_buf_50697 xfs_growfs_get_hdr_buf 3 50697 NULL
119120 +dev_mem_read_50706 dev_mem_read 3 50706 NULL
119121 +blk_check_plugged_50736 blk_check_plugged 3 50736 NULL
119122 +__ext3_get_inode_loc_50744 __ext3_get_inode_loc 0 50744 NULL
119123 +ocfs2_xattr_block_get_50773 ocfs2_xattr_block_get 0 50773 NULL
119124 +tm6000_read_write_usb_50774 tm6000_read_write_usb 7 50774 NULL
119125 +bio_alloc_map_data_50782 bio_alloc_map_data 2 50782 NULL
119126 +ixgbe_acquire_msix_vectors_50789 ixgbe_acquire_msix_vectors 2 50789 NULL
119127 +tpm_write_50798 tpm_write 3 50798 NULL
119128 +tun_do_read_50800 tun_do_read 4 50800 NULL
119129 +write_flush_50803 write_flush 3 50803 NULL
119130 +dvb_play_50814 dvb_play 3 50814 NULL
119131 +btrfs_stack_file_extent_disk_num_bytes_50825 btrfs_stack_file_extent_disk_num_bytes 0 50825 NULL
119132 +dpcm_show_state_50827 dpcm_show_state 0 50827 NULL
119133 +SetArea_50835 SetArea 4 50835 NULL
119134 +videobuf_dma_init_user_50839 videobuf_dma_init_user 4-3 50839 NULL
119135 +self_check_write_50856 self_check_write 0 50856 NULL
119136 +carl9170_debugfs_write_50857 carl9170_debugfs_write 3 50857 NULL
119137 +SyS_lgetxattr_50889 SyS_lgetxattr 4 50889 NULL
119138 +netlbl_secattr_catmap_walk_rng_50894 netlbl_secattr_catmap_walk_rng 0-2 50894 NULL
119139 +__bdev_writeseg_50903 __bdev_writeseg 4 50903 NULL
119140 +xfs_iext_remove_50909 xfs_iext_remove 3 50909 NULL
119141 +blk_rq_cur_sectors_50910 blk_rq_cur_sectors 0 50910 NULL
119142 +hash_recvmsg_50924 hash_recvmsg 4 50924 NULL
119143 +chd_dec_fetch_cdata_50926 chd_dec_fetch_cdata 3 50926 NULL
119144 +show_device_status_50947 show_device_status 0 50947 NULL
119145 +irq_timeout_write_50950 irq_timeout_write 3 50950 NULL
119146 +virtio_cread16_50951 virtio_cread16 0 50951 NULL
119147 +sdio_uart_write_50954 sdio_uart_write 3 50954 NULL
119148 +SyS_setxattr_50957 SyS_setxattr 4 50957 NULL
119149 +of_modalias_node_50975 of_modalias_node 3 50975 NULL
119150 +iwl_statistics_flag_50981 iwl_statistics_flag 0-3 50981 NULL
119151 +timeout_write_50991 timeout_write 3 50991 NULL
119152 +proc_write_51003 proc_write 3 51003 NULL
119153 +jbd2_journal_extend_51012 jbd2_journal_extend 2 51012 NULL
119154 +lbs_dev_info_51023 lbs_dev_info 3 51023 NULL
119155 +fuse_conn_congestion_threshold_read_51028 fuse_conn_congestion_threshold_read 3 51028 NULL
119156 +BcmGetSectionValEndOffset_51039 BcmGetSectionValEndOffset 0 51039 NULL
119157 +dump_midi_51040 dump_midi 3 51040 NULL
119158 +usb_get_descriptor_51041 usb_get_descriptor 0 51041 NULL
119159 +srpt_alloc_ioctx_51042 srpt_alloc_ioctx 2-3 51042 NULL
119160 +do_arpt_set_ctl_51053 do_arpt_set_ctl 4 51053 NULL
119161 +wusb_prf_64_51065 wusb_prf_64 7 51065 NULL
119162 +jbd2_journal_init_revoke_51088 jbd2_journal_init_revoke 2 51088 NULL
119163 +__ocfs2_find_path_51096 __ocfs2_find_path 0 51096 NULL
119164 +ti_recv_51110 ti_recv 3 51110 NULL
119165 +alloc_rtllib_51136 alloc_rtllib 1 51136 NULL
119166 +simple_xattr_set_51140 simple_xattr_set 4 51140 NULL
119167 +xfs_trans_get_efd_51148 xfs_trans_get_efd 3 51148 NULL
119168 +snd_pcm_unlink_51210 snd_pcm_unlink 0 51210 NULL
119169 +iwl_dbgfs_bcast_filters_macs_read_51231 iwl_dbgfs_bcast_filters_macs_read 3 51231 NULL
119170 +nf_ct_ext_create_51232 nf_ct_ext_create 3 51232 NULL
119171 +snd_pcm_write_51235 snd_pcm_write 3 51235 NULL
119172 +drm_property_create_51239 drm_property_create 4 51239 NULL
119173 +st_read_51251 st_read 3 51251 NULL
119174 +compat_dccp_setsockopt_51263 compat_dccp_setsockopt 5 51263 NULL
119175 +target_alloc_sgl_51264 target_alloc_sgl 3 51264 NULL
119176 +dvb_audio_write_51275 dvb_audio_write 3 51275 NULL
119177 +ipwireless_network_packet_received_51277 ipwireless_network_packet_received 4 51277 NULL
119178 +pvr2_std_id_to_str_51288 pvr2_std_id_to_str 2 51288 NULL
119179 +bnad_debugfs_read_regrd_51308 bnad_debugfs_read_regrd 3 51308 NULL
119180 +init_map_ipmac_51317 init_map_ipmac 5 51317 NULL
119181 +alloc_hippi_dev_51320 alloc_hippi_dev 1 51320 NULL
119182 +ext2_xattr_get_51327 ext2_xattr_get 0 51327 NULL
119183 +alloc_smp_req_51337 alloc_smp_req 1 51337 NULL
119184 +ipw_get_event_log_len_51341 ipw_get_event_log_len 0 51341 NULL
119185 +ieee80211_if_fmt_estab_plinks_51370 ieee80211_if_fmt_estab_plinks 3 51370 NULL
119186 +radeon_kms_compat_ioctl_51371 radeon_kms_compat_ioctl 2 51371 NULL
119187 +blk_register_region_51424 blk_register_region 1-2 51424 NULL
119188 +mwifiex_rdeeprom_read_51429 mwifiex_rdeeprom_read 3 51429 NULL
119189 +hfsplus_brec_read_51436 hfsplus_brec_read 0 51436 NULL
119190 +ieee80211_if_read_dot11MeshHWMPRootMode_51441 ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 NULL
119191 +print_devstats_dot11ACKFailureCount_51443 print_devstats_dot11ACKFailureCount 3 51443 NULL
119192 +vmxnet3_acquire_msix_vectors_51462 vmxnet3_acquire_msix_vectors 2 51462 NULL
119193 +____alloc_ei_netdev_51475 ____alloc_ei_netdev 1 51475 NULL
119194 +xfs_buf_get_uncached_51477 xfs_buf_get_uncached 2 51477 NULL
119195 +kvm_fetch_guest_virt_51493 kvm_fetch_guest_virt 4-2 51493 NULL
119196 +ieee80211_if_write_uapsd_queues_51526 ieee80211_if_write_uapsd_queues 3 51526 NULL
119197 +__alloc_eip_netdev_51549 __alloc_eip_netdev 1 51549 NULL
119198 +batadv_tt_prepare_tvlv_local_data_51568 batadv_tt_prepare_tvlv_local_data 0 51568 NULL
119199 +ixgb_get_eeprom_len_51586 ixgb_get_eeprom_len 0 51586 NULL
119200 +aac_convert_sgraw2_51598 aac_convert_sgraw2 4 51598 NULL
119201 +table_size_to_number_of_entries_51613 table_size_to_number_of_entries 0-1 51613 NULL
119202 +extent_fiemap_51621 extent_fiemap 3 51621 NULL
119203 +sctp_auth_create_key_51641 sctp_auth_create_key 1 51641 NULL
119204 +iscsi_create_session_51647 iscsi_create_session 3 51647 NULL
119205 +ps_upsd_utilization_read_51669 ps_upsd_utilization_read 3 51669 NULL
119206 +sctp_setsockopt_associnfo_51684 sctp_setsockopt_associnfo 3 51684 NULL
119207 +rtw_os_xmit_resource_alloc23a_51693 rtw_os_xmit_resource_alloc23a 3 51693 NULL
119208 +host_mapping_level_51696 host_mapping_level 0 51696 NULL
119209 +sel_write_access_51704 sel_write_access 3 51704 NULL
119210 +tty_cdev_add_51714 tty_cdev_add 2-4 51714 NULL
119211 +v9fs_alloc_rdir_buf_51716 v9fs_alloc_rdir_buf 2 51716 NULL
119212 +drm_compat_ioctl_51717 drm_compat_ioctl 2 51717 NULL
119213 +sg_read_oxfer_51724 sg_read_oxfer 3 51724 NULL
119214 +cm4040_read_51732 cm4040_read 3 51732 NULL
119215 +get_user_pages_fast_51751 get_user_pages_fast 0 51751 NULL
119216 +ifx_spi_insert_flip_string_51752 ifx_spi_insert_flip_string 3 51752 NULL
119217 +if_write_51756 if_write 3 51756 NULL
119218 +ssd1307fb_alloc_array_51788 ssd1307fb_alloc_array 1 51788 NULL
119219 +qib_alloc_devdata_51819 qib_alloc_devdata 2 51819 NULL
119220 +buffer_from_user_51826 buffer_from_user 3 51826 NULL
119221 +ioread32_51847 ioread32 0 51847 NULL nohasharray
119222 +read_file_tgt_tx_stats_51847 read_file_tgt_tx_stats 3 51847 &ioread32_51847
119223 +do_readv_writev_51849 do_readv_writev 4 51849 NULL
119224 +SYSC_sendto_51852 SYSC_sendto 6 51852 NULL
119225 +bm_page_io_async_51858 bm_page_io_async 2 51858 NULL
119226 +pointer_size_read_51863 pointer_size_read 3 51863 NULL
119227 +get_indirect_ea_51869 get_indirect_ea 4 51869 NULL
119228 +user_read_51881 user_read 3 51881 NULL
119229 +dbAdjCtl_51888 dbAdjCtl 0 51888 NULL
119230 +SyS_mq_timedsend_51896 SyS_mq_timedsend 3 51896 NULL
119231 +wmi_set_ie_51919 wmi_set_ie 3 51919 NULL
119232 +dbg_status_buf_51930 dbg_status_buf 2 51930 NULL
119233 +__tcp_mtu_to_mss_51938 __tcp_mtu_to_mss 0-2 51938 NULL
119234 +xfrm_alg_len_51940 xfrm_alg_len 0 51940 NULL
119235 +scsi_get_vpd_page_51951 scsi_get_vpd_page 4 51951 NULL
119236 +snd_mask_min_51969 snd_mask_min 0 51969 NULL
119237 +__blkdev_get_51972 __blkdev_get 0 51972 NULL
119238 +get_zone_51981 get_zone 0-1 51981 NULL
119239 +ath6kl_sdio_alloc_prep_scat_req_51986 ath6kl_sdio_alloc_prep_scat_req 2 51986 NULL
119240 +dwc3_mode_write_51997 dwc3_mode_write 3 51997 NULL
119241 +scsi_sysfs_add_host_52010 scsi_sysfs_add_host 0 52010 NULL
119242 +skb_copy_datagram_from_iovec_52014 skb_copy_datagram_from_iovec 4-2-5 52014 NULL
119243 +rdmalt_52022 rdmalt 0 52022 NULL
119244 +override_release_52032 override_release 2 52032 NULL
119245 +end_port_52042 end_port 0 52042 NULL
119246 +dma_rx_errors_read_52045 dma_rx_errors_read 3 52045 NULL
119247 +msnd_fifo_write_52052 msnd_fifo_write 0-3 52052 NULL
119248 +dvb_ringbuffer_avail_52057 dvb_ringbuffer_avail 0 52057 NULL
119249 +__fuse_request_alloc_52060 __fuse_request_alloc 1 52060 NULL
119250 +isofs_readpages_52067 isofs_readpages 4 52067 NULL
119251 +mxuport_process_read_urb_data_52072 mxuport_process_read_urb_data 3 52072 NULL
119252 +nsm_get_handle_52089 nsm_get_handle 4 52089 NULL
119253 +ulist_add_merge_52096 ulist_add_merge 0 52096 NULL
119254 +o2net_debug_read_52105 o2net_debug_read 3 52105 NULL
119255 +split_scan_timeout_write_52128 split_scan_timeout_write 3 52128 NULL
119256 +retry_count_read_52129 retry_count_read 3 52129 NULL
119257 +snd_pcm_channel_info_user_52135 snd_pcm_channel_info_user 0 52135 NULL
119258 +gdm_usb_hci_send_52138 gdm_usb_hci_send 3 52138 NULL
119259 +sub_alloc_52140 sub_alloc 0 52140 NULL
119260 +hysdn_conf_write_52145 hysdn_conf_write 3 52145 NULL
119261 +htable_size_52148 htable_size 0-1 52148 NULL
119262 +smk_write_load2_52155 smk_write_load2 3 52155 NULL
119263 +ieee80211_if_read_dot11MeshRetryTimeout_52168 ieee80211_if_read_dot11MeshRetryTimeout 3 52168 NULL
119264 +mga_compat_ioctl_52170 mga_compat_ioctl 2 52170 NULL
119265 +print_prefix_52176 print_prefix 0 52176 NULL
119266 +proc_pid_readlink_52186 proc_pid_readlink 3 52186 NULL
119267 +reiserfs_posix_acl_from_disk_52191 reiserfs_posix_acl_from_disk 2 52191 NULL
119268 +vmci_qp_broker_alloc_52216 vmci_qp_broker_alloc 6-5 52216 NULL
119269 +fuse_request_alloc_52243 fuse_request_alloc 1 52243 NULL
119270 +mdiobus_alloc_size_52259 mdiobus_alloc_size 1 52259 NULL
119271 +shrink_slab_52261 shrink_slab 2 52261 NULL
119272 +sisusbcon_do_font_op_52271 sisusbcon_do_font_op 9 52271 NULL
119273 +handle_supp_msgs_52284 handle_supp_msgs 4 52284 NULL
119274 +kobject_set_name_vargs_52309 kobject_set_name_vargs 0 52309 NULL
119275 +read_file_reset_52310 read_file_reset 3 52310 NULL
119276 +ssd1307fb_write_52315 ssd1307fb_write 3 52315 NULL
119277 +request_asymmetric_key_52317 request_asymmetric_key 2-4 52317 NULL
119278 +hwflags_read_52318 hwflags_read 3 52318 NULL
119279 +snd_pcm_hw_free_52327 snd_pcm_hw_free 0 52327 NULL
119280 +test_unaligned_bulk_52333 test_unaligned_bulk 3 52333 NULL
119281 +hur_len_52339 hur_len 0 52339 NULL
119282 +bytes_to_frames_52362 bytes_to_frames 0-2 52362 NULL nohasharray
119283 +cap_inode_killpriv_52362 cap_inode_killpriv 0 52362 &bytes_to_frames_52362
119284 +copy_entries_to_user_52367 copy_entries_to_user 1 52367 NULL
119285 +iwl_dump_fh_52371 iwl_dump_fh 0 52371 NULL
119286 +hfsplus_find_attr_52374 hfsplus_find_attr 0 52374 NULL
119287 +mq_emit_config_values_52378 mq_emit_config_values 3 52378 NULL
119288 +isdn_writebuf_stub_52383 isdn_writebuf_stub 4 52383 NULL
119289 +jfs_setxattr_52389 jfs_setxattr 4 52389 NULL
119290 +aer_inject_write_52399 aer_inject_write 3 52399 NULL
119291 +line6_midibuf_init_52425 line6_midibuf_init 2 52425 NULL
119292 +hso_serial_common_create_52428 hso_serial_common_create 4 52428 NULL
119293 +delay_status_52431 delay_status 5 52431 NULL
119294 +ath6kl_delete_qos_write_52435 ath6kl_delete_qos_write 3 52435 NULL
119295 +ieee80211_if_fmt_num_sta_ps_52438 ieee80211_if_fmt_num_sta_ps 3 52438 NULL
119296 +alauda_read_data_52452 alauda_read_data 3 52452 NULL
119297 +ieee80211_alloc_txb_52477 ieee80211_alloc_txb 1 52477 NULL
119298 +usb_tranzport_write_52479 usb_tranzport_write 3 52479 NULL
119299 +ocfs2_extend_no_holes_52483 ocfs2_extend_no_holes 3-4 52483 NULL
119300 +fd_do_rw_52495 fd_do_rw 3 52495 NULL
119301 +int_tasklet_entry_52500 int_tasklet_entry 3 52500 NULL
119302 +lmv_get_easize_52504 lmv_get_easize 0 52504 NULL
119303 +pm_qos_power_write_52513 pm_qos_power_write 3 52513 NULL
119304 +bt_sock_stream_recvmsg_52518 bt_sock_stream_recvmsg 4 52518 NULL
119305 +dup_variable_bug_52525 dup_variable_bug 3 52525 NULL
119306 +raw_recvmsg_52529 raw_recvmsg 4 52529 NULL
119307 +SyS_vmsplice_52540 SyS_vmsplice 3 52540 NULL
119308 +dccpprobe_read_52549 dccpprobe_read 3 52549 NULL
119309 +debug_level_proc_write_52572 debug_level_proc_write 3 52572 NULL
119310 +isku_sysfs_read_macro_52587 isku_sysfs_read_macro 6 52587 NULL
119311 +snd_pcm_sw_params_52594 snd_pcm_sw_params 0 52594 NULL
119312 +SyS_setsockopt_52610 SyS_setsockopt 5 52610 NULL
119313 +ll_sa_entry_alloc_52611 ll_sa_entry_alloc 4 52611 NULL
119314 +tps80031_writes_52638 tps80031_writes 3-4 52638 NULL
119315 +brcmf_sdio_assert_info_52653 brcmf_sdio_assert_info 4 52653 NULL
119316 +nvme_queue_extra_52661 nvme_queue_extra 0-1 52661 NULL
119317 +SYSC_gethostname_52677 SYSC_gethostname 2 52677 NULL
119318 +nvd0_disp_pioc_create__52693 nvd0_disp_pioc_create_ 5 52693 NULL
119319 +nouveau_client_create__52715 nouveau_client_create_ 5 52715 NULL
119320 +__dm_stat_bio_52722 __dm_stat_bio 3 52722 NULL
119321 +cx25840_ir_rx_read_52724 cx25840_ir_rx_read 3 52724 NULL
119322 +blkcipher_next_slow_52733 blkcipher_next_slow 3-4 52733 NULL
119323 +relay_alloc_page_array_52735 relay_alloc_page_array 1 52735 NULL
119324 +carl9170_debugfs_vif_dump_read_52755 carl9170_debugfs_vif_dump_read 3 52755 NULL
119325 +ieee80211_if_read_beacon_timeout_52756 ieee80211_if_read_beacon_timeout 3 52756 NULL
119326 +nvme_trans_ext_inq_page_52776 nvme_trans_ext_inq_page 3 52776 NULL
119327 +pwr_rcvd_beacons_read_52836 pwr_rcvd_beacons_read 3 52836 NULL
119328 +lb_alloc_ep_req_52837 lb_alloc_ep_req 2 52837 NULL
119329 +mon_bin_get_event_52863 mon_bin_get_event 4-6 52863 NULL
119330 +twl6030_gpadc_write_52867 twl6030_gpadc_write 1 52867 NULL
119331 +qib_decode_6120_err_52876 qib_decode_6120_err 3 52876 NULL
119332 +twlreg_write_52880 twlreg_write 3 52880 NULL
119333 +pvr2_ctrl_value_to_sym_internal_52881 pvr2_ctrl_value_to_sym_internal 5 52881 NULL
119334 +cache_read_procfs_52882 cache_read_procfs 3 52882 NULL
119335 +kvm_kvzalloc_52894 kvm_kvzalloc 1 52894 NULL
119336 +dio_bio_reap_52913 dio_bio_reap 0 52913 NULL
119337 +__kfifo_out_peek_r_52919 __kfifo_out_peek_r 3 52919 NULL
119338 +iblock_get_bio_52936 iblock_get_bio 3 52936 NULL
119339 +ieee80211_if_fmt_fwded_mcast_52961 ieee80211_if_fmt_fwded_mcast 3 52961 NULL
119340 +tx_tx_exch_read_52986 tx_tx_exch_read 3 52986 NULL
119341 +num_node_state_52989 num_node_state 0 52989 NULL
119342 +efivarfs_file_write_53000 efivarfs_file_write 3 53000 NULL
119343 +btrfs_free_and_pin_reserved_extent_53016 btrfs_free_and_pin_reserved_extent 2 53016 NULL
119344 +tx_tx_exch_pending_read_53018 tx_tx_exch_pending_read 3 53018 NULL
119345 +bio_cur_bytes_53037 bio_cur_bytes 0 53037 NULL
119346 +regcache_lzo_block_count_53056 regcache_lzo_block_count 0 53056 NULL
119347 +cfi_read_query_53066 cfi_read_query 0 53066 NULL
119348 +iwl_dbgfs_interrupt_write_53069 iwl_dbgfs_interrupt_write 3 53069 NULL
119349 +mwifiex_debug_read_53074 mwifiex_debug_read 3 53074 NULL
119350 +vmci_check_host_caps_53087 vmci_check_host_caps 0 53087 NULL
119351 +mic_virtio_copy_from_user_53107 mic_virtio_copy_from_user 3 53107 NULL
119352 +verity_status_53120 verity_status 5 53120 NULL
119353 +brcmf_usb_dl_cmd_53130 brcmf_usb_dl_cmd 4 53130 NULL
119354 +ps_poll_ps_poll_max_ap_turn_read_53140 ps_poll_ps_poll_max_ap_turn_read 3 53140 NULL nohasharray
119355 +inode_newsize_ok_53140 inode_newsize_ok 0 53140 &ps_poll_ps_poll_max_ap_turn_read_53140
119356 +ieee80211_bss_info_update_53170 ieee80211_bss_info_update 4 53170 NULL
119357 +btrfs_io_bio_alloc_53179 btrfs_io_bio_alloc 2 53179 NULL
119358 +clear_capture_buf_53192 clear_capture_buf 2 53192 NULL
119359 +tx_tx_start_data_read_53219 tx_tx_start_data_read 3 53219 NULL
119360 +ptlrpc_lprocfs_req_history_max_seq_write_53243 ptlrpc_lprocfs_req_history_max_seq_write 3 53243 NULL
119361 +xfs_trans_read_buf_map_53258 xfs_trans_read_buf_map 5 53258 NULL
119362 +wil_write_file_ssid_53266 wil_write_file_ssid 3 53266 NULL
119363 +btrfs_file_extent_num_bytes_53269 btrfs_file_extent_num_bytes 0 53269 NULL
119364 +ftrace_profile_write_53327 ftrace_profile_write 3 53327 NULL
119365 +find_nr_power_limit_53330 find_nr_power_limit 0 53330 NULL
119366 +gsm_control_reply_53333 gsm_control_reply 4 53333 NULL
119367 +btree_keys_bytes_53348 btree_keys_bytes 0 53348 NULL
119368 +sock_setbindtodevice_53369 sock_setbindtodevice 3 53369 NULL
119369 +get_random_bytes_arch_53370 get_random_bytes_arch 2 53370 NULL
119370 +isr_cmd_cmplt_read_53439 isr_cmd_cmplt_read 3 53439 NULL
119371 +mwifiex_info_read_53447 mwifiex_info_read 3 53447 NULL
119372 +apei_exec_run_optional_53452 apei_exec_run_optional 0 53452 NULL
119373 +paging64_prefetch_gpte_53468 paging64_prefetch_gpte 4 53468 NULL
119374 +ima_write_template_field_data_53475 ima_write_template_field_data 2 53475 NULL nohasharray
119375 +create_trace_kprobe_53475 create_trace_kprobe 1 53475 &ima_write_template_field_data_53475
119376 +iowarrior_read_53483 iowarrior_read 3 53483 NULL
119377 +osd_req_write_kern_53486 osd_req_write_kern 5 53486 NULL
119378 +do_verify_xattr_datum_53499 do_verify_xattr_datum 0 53499 NULL
119379 +snd_pcm_format_physical_width_53505 snd_pcm_format_physical_width 0 53505 NULL
119380 +dbAllocNext_53506 dbAllocNext 0 53506 NULL
119381 +force_sc_support_write_53512 force_sc_support_write 3 53512 NULL nohasharray
119382 +check_acl_53512 check_acl 0 53512 &force_sc_support_write_53512
119383 +nft_data_dump_53549 nft_data_dump 5 53549 NULL
119384 +SYSC_bind_53582 SYSC_bind 3 53582 NULL
119385 +cifs_utf16_bytes_53593 cifs_utf16_bytes 0 53593 NULL
119386 +proc_uid_map_write_53596 proc_uid_map_write 3 53596 NULL
119387 +pfkey_recvmsg_53604 pfkey_recvmsg 4 53604 NULL
119388 +___alloc_bootmem_nopanic_53626 ___alloc_bootmem_nopanic 1 53626 NULL
119389 +xd_write_multiple_pages_53633 xd_write_multiple_pages 6-5 53633 NULL
119390 +ccid_getsockopt_builtin_ccids_53634 ccid_getsockopt_builtin_ccids 2 53634 NULL
119391 +nr_sendmsg_53656 nr_sendmsg 4 53656 NULL
119392 +fuse_fill_write_pages_53682 fuse_fill_write_pages 4-0 53682 NULL
119393 +v4l2_event_subscribe_53687 v4l2_event_subscribe 3 53687 NULL
119394 +bdev_logical_block_size_53690 bdev_logical_block_size 0 53690 NULL nohasharray
119395 +igb_alloc_q_vector_53690 igb_alloc_q_vector 4-6 53690 &bdev_logical_block_size_53690
119396 +find_overflow_devnum_53711 find_overflow_devnum 0 53711 NULL
119397 +__proc_debug_mb_53732 __proc_debug_mb 5 53732 NULL
119398 +wdm_write_53735 wdm_write 3 53735 NULL
119399 +lpfc_idiag_queacc_read_qe_53755 lpfc_idiag_queacc_read_qe 0-2 53755 NULL nohasharray
119400 +amdtp_out_stream_get_max_payload_53755 amdtp_out_stream_get_max_payload 0 53755 &lpfc_idiag_queacc_read_qe_53755
119401 +wa_populate_buf_in_urb_53758 wa_populate_buf_in_urb 3-4 53758 NULL
119402 +ext2_acl_count_53773 ext2_acl_count 0-1 53773 NULL
119403 +__kfifo_dma_in_prepare_r_53792 __kfifo_dma_in_prepare_r 4-5 53792 NULL
119404 +qp_alloc_host_work_53798 qp_alloc_host_work 5-3 53798 NULL
119405 +regmap_raw_write_53803 regmap_raw_write 2-4 53803 NULL
119406 +lpfc_idiag_ctlacc_read_reg_53809 lpfc_idiag_ctlacc_read_reg 0-3 53809 NULL
119407 +nls_nullsize_53815 nls_nullsize 0 53815 NULL
119408 +setup_data_read_53822 setup_data_read 3 53822 NULL
119409 +pms_read_53873 pms_read 3 53873 NULL
119410 +ieee80211_if_fmt_dropped_frames_congestion_53883 ieee80211_if_fmt_dropped_frames_congestion 3 53883 NULL
119411 +SyS_setgroups_53900 SyS_setgroups 1 53900 NULL
119412 +batadv_tt_tvlv_ogm_handler_v1_53909 batadv_tt_tvlv_ogm_handler_v1 5 53909 NULL
119413 +azx_via_get_position_53916 azx_via_get_position 0 53916 NULL
119414 +usb_serial_generic_write_53927 usb_serial_generic_write 4 53927 NULL
119415 +idetape_chrdev_write_53976 idetape_chrdev_write 3 53976 NULL
119416 +__ocfs2_xattr_set_value_outside_53981 __ocfs2_xattr_set_value_outside 5 53981 NULL
119417 +ieee80211_if_fmt_dot11MeshHWMPperrMinInterval_53998 ieee80211_if_fmt_dot11MeshHWMPperrMinInterval 3 53998 NULL
119418 +hfsplus_attr_build_key_54013 hfsplus_attr_build_key 0 54013 NULL
119419 +snd_pcm_lib_write_transfer_54018 snd_pcm_lib_write_transfer 5-2-4 54018 NULL
119420 +mdc_kuc_write_54019 mdc_kuc_write 3 54019 NULL
119421 +ipxrtr_route_packet_54036 ipxrtr_route_packet 4 54036 NULL
119422 +batadv_tt_update_orig_54049 batadv_tt_update_orig 6-4 54049 NULL
119423 +pipeline_dec_packet_out_read_54052 pipeline_dec_packet_out_read 3 54052 NULL
119424 +nl80211_send_disconnected_54056 nl80211_send_disconnected 5 54056 NULL
119425 +rproc_state_read_54057 rproc_state_read 3 54057 NULL
119426 +_malloc_54077 _malloc 1 54077 NULL
119427 +lustre_posix_acl_xattr_filter_54103 lustre_posix_acl_xattr_filter 2 54103 NULL nohasharray
119428 +altera_set_ir_pre_54103 altera_set_ir_pre 2 54103 &lustre_posix_acl_xattr_filter_54103
119429 +__comedi_buf_write_alloc_54112 __comedi_buf_write_alloc 0-2 54112 NULL
119430 +strn_len_54122 strn_len 0 54122 NULL
119431 +isku_receive_54130 isku_receive 4 54130 NULL
119432 +isr_host_acknowledges_read_54136 isr_host_acknowledges_read 3 54136 NULL
119433 +irq_blk_threshold_write_54138 irq_blk_threshold_write 3 54138 NULL
119434 +memcpy_toiovec_54166 memcpy_toiovec 3 54166 NULL
119435 +nouveau_falcon_create__54169 nouveau_falcon_create_ 8 54169 NULL
119436 +p9_client_prepare_req_54175 p9_client_prepare_req 3 54175 NULL
119437 +do_sys_poll_54221 do_sys_poll 2 54221 NULL
119438 +__register_chrdev_54223 __register_chrdev 2-3 54223 NULL
119439 +pi_read_regr_54231 pi_read_regr 0 54231 NULL
119440 +mcp23s08_read_regs_54246 mcp23s08_read_regs 4 54246 NULL
119441 +reada_add_block_54247 reada_add_block 2 54247 NULL
119442 +xfs_dir2_sf_addname_hard_54254 xfs_dir2_sf_addname_hard 3 54254 NULL
119443 +ceph_msgpool_get_54258 ceph_msgpool_get 2 54258 NULL
119444 +audio_write_54261 audio_write 4 54261 NULL nohasharray
119445 +wusb_prf_54261 wusb_prf 7 54261 &audio_write_54261
119446 +mwifiex_getlog_read_54269 mwifiex_getlog_read 3 54269 NULL
119447 +kstrtou16_from_user_54274 kstrtou16_from_user 2 54274 NULL
119448 +altera_set_dr_post_54291 altera_set_dr_post 2 54291 NULL
119449 +dlm_alloc_pagevec_54296 dlm_alloc_pagevec 1 54296 NULL
119450 +reclaim_pages_54301 reclaim_pages 3 54301 NULL
119451 +sprintf_54306 sprintf 0 54306 NULL
119452 +bio_add_pc_page_54319 bio_add_pc_page 4 54319 NULL
119453 +br_fdb_fillbuf_54339 br_fdb_fillbuf 0 54339 NULL
119454 +__alloc_dev_table_54343 __alloc_dev_table 2 54343 NULL
119455 +__get_free_pages_54352 __get_free_pages 0 54352 NULL
119456 +readlink_copy_54366 readlink_copy 2 54366 NULL
119457 +read_file_credit_dist_stats_54367 read_file_credit_dist_stats 3 54367 NULL
119458 +do_dccp_setsockopt_54377 do_dccp_setsockopt 5 54377 NULL nohasharray
119459 +intel_sdvo_write_cmd_54377 intel_sdvo_write_cmd 4 54377 &do_dccp_setsockopt_54377
119460 +ah_alloc_tmp_54378 ah_alloc_tmp 3-2 54378 NULL
119461 +snd_pcm_oss_read2_54387 snd_pcm_oss_read2 0-3 54387 NULL
119462 +iwl_dbgfs_power_save_status_read_54392 iwl_dbgfs_power_save_status_read 3 54392 NULL
119463 +ll_ra_count_get_54410 ll_ra_count_get 3 54410 NULL
119464 +copy_gadget_strings_54417 copy_gadget_strings 2-3 54417 NULL
119465 +sparse_early_mem_maps_alloc_node_54485 sparse_early_mem_maps_alloc_node 4 54485 NULL
119466 +simple_strtoull_54493 simple_strtoull 0 54493 NULL
119467 +btrfs_ordered_sum_size_54509 btrfs_ordered_sum_size 0-2 54509 NULL
119468 +sst_byt_get_dsp_position_54513 sst_byt_get_dsp_position 0-3 54513 NULL
119469 +rfc4106_set_key_54519 rfc4106_set_key 3 54519 NULL
119470 +vmci_transport_dgram_enqueue_54525 vmci_transport_dgram_enqueue 4 54525 NULL
119471 +viacam_read_54526 viacam_read 3 54526 NULL
119472 +unix_dgram_connect_54535 unix_dgram_connect 3 54535 NULL
119473 +setsockopt_54539 setsockopt 5 54539 NULL
119474 +lbs_lowsnr_write_54549 lbs_lowsnr_write 3 54549 NULL
119475 +SYSC_setsockopt_54561 SYSC_setsockopt 5 54561 NULL
119476 +nfsd_vfs_write_54577 nfsd_vfs_write 6 54577 NULL
119477 +fw_iso_buffer_init_54582 fw_iso_buffer_init 3 54582 NULL
119478 +nvme_npages_54601 nvme_npages 0-1 54601 NULL
119479 +irq_pkt_threshold_write_54605 irq_pkt_threshold_write 3 54605 NULL
119480 +port_fops_write_54627 port_fops_write 3 54627 NULL
119481 +tipc_send_stream_54648 tipc_send_stream 4 54648 NULL
119482 +irq_timeout_read_54653 irq_timeout_read 3 54653 NULL
119483 +dns_resolver_read_54658 dns_resolver_read 3 54658 NULL
119484 +twl6030_interrupt_mask_54659 twl6030_interrupt_mask 2 54659 NULL
119485 +tdp_page_fault_54663 tdp_page_fault 2 54663 NULL
119486 +bus_add_device_54665 bus_add_device 0 54665 NULL
119487 +cw1200_queue_stats_init_54670 cw1200_queue_stats_init 2 54670 NULL
119488 +bio_kmalloc_54672 bio_kmalloc 2 54672 NULL
119489 +evm_read_key_54674 evm_read_key 3 54674 NULL
119490 +__btrfs_inc_extent_ref_54706 __btrfs_inc_extent_ref 7 54706 NULL
119491 +rfkill_fop_read_54711 rfkill_fop_read 3 54711 NULL
119492 +ocfs2_control_write_54737 ocfs2_control_write 3 54737 NULL
119493 +kzalloc_54740 kzalloc 1 54740 NULL
119494 +wep_iv_read_54744 wep_iv_read 3 54744 NULL
119495 +lpfc_idiag_pcicfg_write_54749 lpfc_idiag_pcicfg_write 3 54749 NULL
119496 +crystalhd_user_data_54754 crystalhd_user_data 3 54754 NULL
119497 +iio_event_chrdev_read_54757 iio_event_chrdev_read 3 54757 NULL
119498 +adis16480_show_firmware_date_54762 adis16480_show_firmware_date 3 54762 NULL
119499 +ldsem_atomic_update_54774 ldsem_atomic_update 1 54774 NULL
119500 +flexcop_device_kmalloc_54793 flexcop_device_kmalloc 1 54793 NULL
119501 +nfsd_write_54809 nfsd_write 6 54809 NULL
119502 +ar9287_dump_modal_eeprom_54814 ar9287_dump_modal_eeprom 3-2 54814 NULL
119503 +crypto_tfm_ctx_alignment_54815 crypto_tfm_ctx_alignment 0 54815 NULL nohasharray
119504 +kvzalloc_54815 kvzalloc 1 54815 &crypto_tfm_ctx_alignment_54815 nohasharray
119505 +aes_decrypt_fail_read_54815 aes_decrypt_fail_read 3 54815 &kvzalloc_54815
119506 +generic_perform_write_54832 generic_perform_write 3-0 54832 NULL
119507 +write_rio_54837 write_rio 3 54837 NULL
119508 +ext3_acl_from_disk_54839 ext3_acl_from_disk 2 54839 NULL nohasharray
119509 +nouveau_engctx_create__54839 nouveau_engctx_create_ 8 54839 &ext3_acl_from_disk_54839
119510 +ufx_ops_write_54848 ufx_ops_write 3 54848 NULL
119511 +printer_read_54851 printer_read 3 54851 NULL
119512 +assign_irq_vector_54852 assign_irq_vector 0 54852 NULL
119513 +broadsheet_spiflash_rewrite_sector_54864 broadsheet_spiflash_rewrite_sector 2 54864 NULL
119514 +prism_build_supp_rates_54865 prism_build_supp_rates 0 54865 NULL
119515 +iscsi_pool_init_54913 iscsi_pool_init 2-4 54913 NULL nohasharray
119516 +kobject_set_name_vargs_54913 kobject_set_name_vargs 0 54913 &iscsi_pool_init_54913
119517 +btrfs_stack_chunk_num_stripes_54923 btrfs_stack_chunk_num_stripes 0 54923 NULL
119518 +bio_add_page_54933 bio_add_page 0-3 54933 NULL
119519 +mxms_structlen_54939 mxms_structlen 0 54939 NULL
119520 +add_port_54941 add_port 2 54941 NULL
119521 +tipc_send2name_54946 tipc_send2name 5 54946 NULL
119522 +ath9k_dump_btcoex_54949 ath9k_dump_btcoex 0-3 54949 NULL
119523 +alauda_write_data_54967 alauda_write_data 3 54967 NULL
119524 +c4_add_card_54968 c4_add_card 3 54968 NULL
119525 +ext3_xattr_get_54989 ext3_xattr_get 0 54989 NULL
119526 +cx231xx_v4l2_read_55014 cx231xx_v4l2_read 3 55014 NULL
119527 +error_error_null_Frame_tx_start_read_55024 error_error_null_Frame_tx_start_read 3 55024 NULL
119528 +apei_exec_run_55075 apei_exec_run 0 55075 NULL
119529 +bitmap_storage_alloc_55077 bitmap_storage_alloc 2 55077 NULL
119530 +snd_pcm_capture_hw_avail_55086 snd_pcm_capture_hw_avail 0 55086 NULL
119531 +rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read_55106 rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 NULL
119532 +crypto_ahash_setkey_55134 crypto_ahash_setkey 3 55134 NULL
119533 +filldir_55137 filldir 3 55137 NULL
119534 +ocfs2_truncate_file_55148 ocfs2_truncate_file 3 55148 NULL
119535 +npages_to_npools_55149 npages_to_npools 0-1 55149 NULL
119536 +ieee80211_if_read_uapsd_queues_55150 ieee80211_if_read_uapsd_queues 3 55150 NULL
119537 +sel_write_relabel_55195 sel_write_relabel 3 55195 NULL
119538 +compat_SyS_ppoll_55196 compat_SyS_ppoll 2 55196 NULL
119539 +sched_feat_write_55202 sched_feat_write 3 55202 NULL
119540 +ht40allow_map_read_55209 ht40allow_map_read 3 55209 NULL
119541 +__kfifo_dma_out_prepare_r_55211 __kfifo_dma_out_prepare_r 4-5 55211 NULL
119542 +do_raw_setsockopt_55215 do_raw_setsockopt 5 55215 NULL
119543 +qxl_alloc_client_monitors_config_55216 qxl_alloc_client_monitors_config 2 55216 NULL
119544 +nouveau_mc_create__55217 nouveau_mc_create_ 4 55217 NULL
119545 +dbAllocDmap_55227 dbAllocDmap 0 55227 NULL
119546 +memcpy_fromiovec_55247 memcpy_fromiovec 3 55247 NULL
119547 +lbs_failcount_write_55276 lbs_failcount_write 3 55276 NULL
119548 +persistent_ram_new_55286 persistent_ram_new 1-2 55286 NULL
119549 +rx_streaming_interval_read_55291 rx_streaming_interval_read 3 55291 NULL
119550 +lov_get_stripecnt_55297 lov_get_stripecnt 0-3 55297 NULL
119551 +gsm_control_modem_55303 gsm_control_modem 3 55303 NULL
119552 +qp_alloc_guest_work_55305 qp_alloc_guest_work 5-3 55305 NULL nohasharray
119553 +compat_SyS_process_vm_readv_55305 compat_SyS_process_vm_readv 3-5 55305 &qp_alloc_guest_work_55305
119554 +compat_SyS_mbind_55329 compat_SyS_mbind 5 55329 NULL
119555 +vme_user_read_55338 vme_user_read 3 55338 NULL
119556 +__wa_xfer_setup_sizes_55342 __wa_xfer_setup_sizes 0 55342 NULL nohasharray
119557 +sctp_datamsg_from_user_55342 sctp_datamsg_from_user 4 55342 &__wa_xfer_setup_sizes_55342
119558 +cw1200_sdio_align_size_55391 cw1200_sdio_align_size 2 55391 NULL
119559 +iwl_dbgfs_plcp_delta_read_55407 iwl_dbgfs_plcp_delta_read 3 55407 NULL
119560 +nouveau_cli_create_55425 nouveau_cli_create 3 55425 NULL
119561 +si476x_radio_read_rds_blckcnt_blob_55427 si476x_radio_read_rds_blckcnt_blob 3 55427 NULL
119562 +__vxge_hw_channel_allocate_55462 __vxge_hw_channel_allocate 3 55462 NULL
119563 +cx23888_ir_rx_read_55473 cx23888_ir_rx_read 3 55473 NULL
119564 +snd_pcm_lib_write_55483 snd_pcm_lib_write 0-3 55483 NULL
119565 +i2o_pool_alloc_55485 i2o_pool_alloc 4 55485 NULL
119566 +batadv_tt_entries_55487 batadv_tt_entries 0-1 55487 NULL
119567 +ras_stride_increase_window_55501 ras_stride_increase_window 3 55501 NULL
119568 +tx_tx_done_int_template_read_55511 tx_tx_done_int_template_read 3 55511 NULL
119569 +ea_get_55522 ea_get 3-0 55522 NULL
119570 +buffer_size_55534 buffer_size 0 55534 NULL
119571 +set_msr_interception_55538 set_msr_interception 2 55538 NULL
119572 +tty_port_register_device_55543 tty_port_register_device 3 55543 NULL
119573 +hash_ipport6_expire_55549 hash_ipport6_expire 4 55549 NULL
119574 +dm_stats_list_55551 dm_stats_list 4 55551 NULL
119575 +compat_SyS_setsockopt_55581 compat_SyS_setsockopt 5 55581 NULL
119576 +add_partition_55588 add_partition 2 55588 NULL
119577 +kstrtou8_from_user_55599 kstrtou8_from_user 2 55599 NULL
119578 +SyS_keyctl_55602 SyS_keyctl 4 55602 NULL
119579 +macvtap_put_user_55609 macvtap_put_user 4 55609 NULL
119580 +selinux_setprocattr_55611 selinux_setprocattr 4 55611 NULL
119581 +edge_tty_recv_55622 edge_tty_recv 3 55622 NULL
119582 +reiserfs_xattr_get_55628 reiserfs_xattr_get 0 55628 NULL nohasharray
119583 +pktgen_if_write_55628 pktgen_if_write 3 55628 &reiserfs_xattr_get_55628
119584 +osc_obd_max_pages_per_rpc_seq_write_55636 osc_obd_max_pages_per_rpc_seq_write 3 55636 NULL
119585 +xfs_bmbt_maxrecs_55649 xfs_bmbt_maxrecs 0-2 55649 NULL
119586 +lpfc_idiag_queinfo_read_55662 lpfc_idiag_queinfo_read 3 55662 NULL
119587 +il_dbgfs_tx_queue_read_55668 il_dbgfs_tx_queue_read 3 55668 NULL
119588 +get_info_55681 get_info 3 55681 NULL
119589 +iwl_dbgfs_plcp_delta_write_55682 iwl_dbgfs_plcp_delta_write 3 55682 NULL
119590 +genl_allocate_reserve_groups_55705 genl_allocate_reserve_groups 1 55705 NULL
119591 +pm8001_store_update_fw_55716 pm8001_store_update_fw 4 55716 NULL
119592 +tap_pwup_write_55723 tap_pwup_write 3 55723 NULL
119593 +__iio_allocate_kfifo_55738 __iio_allocate_kfifo 2 55738 NULL
119594 +set_local_name_55757 set_local_name 4 55757 NULL
119595 +strlen_55778 strlen 0 55778 NULL nohasharray
119596 +is_idx_node_in_tnc_55778 is_idx_node_in_tnc 0 55778 &strlen_55778
119597 +set_spte_55783 set_spte 5-4 55783 NULL
119598 +req_bio_endio_55786 req_bio_endio 3 55786 NULL nohasharray
119599 +conf_read_55786 conf_read 3 55786 &req_bio_endio_55786
119600 +uwb_rc_neh_grok_event_55799 uwb_rc_neh_grok_event 3 55799 NULL
119601 +sb16_copy_from_user_55836 sb16_copy_from_user 10-6-7 55836 NULL
119602 +ip_hdrlen_55849 ip_hdrlen 0 55849 NULL
119603 +hcd_alloc_coherent_55862 hcd_alloc_coherent 5 55862 NULL
119604 +shmem_setxattr_55867 shmem_setxattr 4 55867 NULL
119605 +hsc_write_55875 hsc_write 3 55875 NULL
119606 +ramdisk_store_55885 ramdisk_store 4 55885 NULL
119607 +pm_qos_power_read_55891 pm_qos_power_read 3 55891 NULL
119608 +hash_ip4_expire_55911 hash_ip4_expire 4 55911 NULL
119609 +snd_pcm_hw_param_value_min_55917 snd_pcm_hw_param_value_min 0 55917 NULL
119610 +ext2_direct_IO_55932 ext2_direct_IO 4 55932 NULL
119611 +kvm_write_guest_virt_system_55944 kvm_write_guest_virt_system 4-2 55944 NULL
119612 +sel_read_policy_55947 sel_read_policy 3 55947 NULL
119613 +ceph_get_direct_page_vector_55956 ceph_get_direct_page_vector 2 55956 NULL
119614 +simple_read_from_buffer_55957 simple_read_from_buffer 2-5 55957 NULL
119615 +tx_tx_imm_resp_read_55964 tx_tx_imm_resp_read 3 55964 NULL
119616 +btrfs_clone_55977 btrfs_clone 5-3 55977 NULL
119617 +wa_xfer_create_subset_sg_55992 wa_xfer_create_subset_sg 3-2 55992 NULL
119618 +nvme_alloc_iod_56027 nvme_alloc_iod 1-2 56027 NULL
119619 +usb_ocp_write_56047 usb_ocp_write 4 56047 NULL
119620 +dccp_sendmsg_56058 dccp_sendmsg 4 56058 NULL
119621 +pscsi_get_bio_56103 pscsi_get_bio 1 56103 NULL
119622 +usb_alloc_stream_buffers_56123 usb_alloc_stream_buffers 3 56123 NULL
119623 +sel_read_handle_status_56139 sel_read_handle_status 3 56139 NULL
119624 +write_file_frameerrors_56145 write_file_frameerrors 3 56145 NULL
119625 +rawv6_setsockopt_56165 rawv6_setsockopt 5 56165 NULL
119626 +ath9k_dump_legacy_btcoex_56194 ath9k_dump_legacy_btcoex 3-0 56194 NULL
119627 +vring_add_indirect_56222 vring_add_indirect 4 56222 NULL
119628 +ocfs2_find_xe_in_bucket_56224 ocfs2_find_xe_in_bucket 0 56224 NULL
119629 +do_ipt_set_ctl_56238 do_ipt_set_ctl 4 56238 NULL
119630 +fd_copyin_56247 fd_copyin 3 56247 NULL
119631 +sk_rmem_schedule_56255 sk_rmem_schedule 3 56255 NULL
119632 +acpi_ex_get_serial_access_length_56275 acpi_ex_get_serial_access_length 0-2 56275 NULL
119633 +il4965_ucode_general_stats_read_56277 il4965_ucode_general_stats_read 3 56277 NULL
119634 +ieee80211_if_fmt_user_power_level_56283 ieee80211_if_fmt_user_power_level 3 56283 NULL
119635 +RESIZE_IF_NEEDED_56286 RESIZE_IF_NEEDED 2 56286 NULL
119636 +dvb_aplay_56296 dvb_aplay 3 56296 NULL
119637 +btmrvl_hscfgcmd_read_56303 btmrvl_hscfgcmd_read 3 56303 NULL
119638 +speakup_file_write_56310 speakup_file_write 3 56310 NULL
119639 +pipeline_pre_to_defrag_swi_read_56321 pipeline_pre_to_defrag_swi_read 3 56321 NULL
119640 +journal_init_revoke_table_56331 journal_init_revoke_table 1 56331 NULL
119641 +snd_rawmidi_read_56337 snd_rawmidi_read 3 56337 NULL
119642 +vxge_os_dma_malloc_async_56348 vxge_os_dma_malloc_async 3 56348 NULL
119643 +mite_device_bytes_transferred_56355 mite_device_bytes_transferred 0 56355 NULL
119644 +iov_iter_copy_from_user_atomic_56368 iov_iter_copy_from_user_atomic 4-0 56368 NULL
119645 +dev_read_56369 dev_read 3 56369 NULL
119646 +ath10k_read_simulate_fw_crash_56371 ath10k_read_simulate_fw_crash 3 56371 NULL
119647 +snd_pcm_common_ioctl1_56382 snd_pcm_common_ioctl1 0 56382 NULL
119648 +write_gssp_56404 write_gssp 3 56404 NULL
119649 +ocfs2_control_read_56405 ocfs2_control_read 3 56405 NULL
119650 +store_msg_56417 store_msg 3 56417 NULL
119651 +pppol2tp_sendmsg_56420 pppol2tp_sendmsg 4 56420 NULL
119652 +l2cap_segment_le_sdu_56426 l2cap_segment_le_sdu 4 56426 NULL
119653 +ec_dbgfs_cmd_read_56431 ec_dbgfs_cmd_read 3 56431 NULL
119654 +fl_create_56435 fl_create 5 56435 NULL
119655 +gnttab_map_56439 gnttab_map 2 56439 NULL
119656 +cx231xx_init_isoc_56453 cx231xx_init_isoc 3-2-4 56453 NULL
119657 +set_connectable_56458 set_connectable 4 56458 NULL
119658 +osd_req_list_partition_objects_56464 osd_req_list_partition_objects 5 56464 NULL
119659 +putused_user_56467 putused_user 3 56467 NULL
119660 +ocfs2_zero_extend_range_56468 ocfs2_zero_extend_range 3-2 56468 NULL
119661 +lbs_rdmac_write_56471 lbs_rdmac_write 3 56471 NULL
119662 +crypto_shash_alignmask_56486 crypto_shash_alignmask 0 56486 NULL
119663 +ieee80211_rx_mgmt_probe_beacon_56491 ieee80211_rx_mgmt_probe_beacon 3 56491 NULL
119664 +memblock_virt_alloc_56501 memblock_virt_alloc 1 56501 NULL
119665 +init_map_ip_56508 init_map_ip 5 56508 NULL
119666 +lustre_posix_acl_xattr_reduce_space_56512 lustre_posix_acl_xattr_reduce_space 3 56512 NULL
119667 +cfg80211_connect_result_56515 cfg80211_connect_result 4-6 56515 NULL
119668 +ip_options_get_56538 ip_options_get 4 56538 NULL
119669 +ll_wr_track_id_56544 ll_wr_track_id 2 56544 NULL
119670 +alloc_apertures_56561 alloc_apertures 1 56561 NULL
119671 +rs_sta_dbgfs_stats_table_read_56573 rs_sta_dbgfs_stats_table_read 3 56573 NULL
119672 +portcntrs_2_read_56586 portcntrs_2_read 3 56586 NULL
119673 +gro_pull_from_frag0_56593 gro_pull_from_frag0 2 56593 NULL
119674 +event_filter_write_56609 event_filter_write 3 56609 NULL
119675 +nvme_trans_log_temperature_56613 nvme_trans_log_temperature 3 56613 NULL
119676 +gather_array_56641 gather_array 3 56641 NULL
119677 +lookup_extent_backref_56644 lookup_extent_backref 9 56644 NULL
119678 +uvc_debugfs_stats_read_56651 uvc_debugfs_stats_read 3 56651 NULL
119679 +tg3_nvram_write_block_56666 tg3_nvram_write_block 3 56666 NULL
119680 +snd_gus_dram_read_56686 snd_gus_dram_read 4 56686 NULL
119681 +dvb_ringbuffer_read_user_56702 dvb_ringbuffer_read_user 3-0 56702 NULL
119682 +sta_flags_read_56710 sta_flags_read 3 56710 NULL
119683 +ipv6_getsockopt_sticky_56711 ipv6_getsockopt_sticky 5 56711 NULL
119684 +__wa_xfer_setup_segs_56725 __wa_xfer_setup_segs 2 56725 NULL
119685 +__copy_from_user_ll_56738 __copy_from_user_ll 0-3 56738 NULL
119686 +drm_agp_bind_pages_56748 drm_agp_bind_pages 3 56748 NULL
119687 +btrfsic_map_block_56751 btrfsic_map_block 2 56751 NULL
119688 +ttm_alloc_new_pages_56792 ttm_alloc_new_pages 5 56792 NULL
119689 +ion_ioctl_56806 ion_ioctl 2 56806 NULL
119690 +do_syslog_56807 do_syslog 3 56807 NULL
119691 +mtdchar_write_56831 mtdchar_write 3 56831 NULL
119692 +snd_rawmidi_kernel_write1_56847 snd_rawmidi_kernel_write1 4-0 56847 NULL
119693 +si476x_radio_read_agc_blob_56849 si476x_radio_read_agc_blob 3 56849 NULL
119694 +ext3_xattr_ibody_get_56880 ext3_xattr_ibody_get 0 56880 NULL
119695 +pvr2_debugifc_print_status_56890 pvr2_debugifc_print_status 3 56890 NULL
119696 +debug_debug3_read_56894 debug_debug3_read 3 56894 NULL
119697 +batadv_tt_update_changes_56895 batadv_tt_update_changes 3 56895 NULL nohasharray
119698 +le_auto_conn_write_56895 le_auto_conn_write 3 56895 &batadv_tt_update_changes_56895
119699 +hfsplus_find_cat_56899 hfsplus_find_cat 0 56899 NULL
119700 +strcspn_56913 strcspn 0 56913 NULL
119701 +__kfifo_out_56927 __kfifo_out 0-3 56927 NULL
119702 +journal_init_revoke_56933 journal_init_revoke 2 56933 NULL
119703 +nouveau_xtensa_create__56952 nouveau_xtensa_create_ 8 56952 NULL
119704 +diva_get_driver_info_56967 diva_get_driver_info 0 56967 NULL
119705 +sptlrpc_secflags2str_56995 sptlrpc_secflags2str 3 56995 NULL
119706 +vlsi_alloc_ring_57003 vlsi_alloc_ring 3-4 57003 NULL
119707 +btrfs_super_csum_size_57004 btrfs_super_csum_size 0 57004 NULL
119708 +aircable_process_packet_57027 aircable_process_packet 4 57027 NULL
119709 +ieee80211_if_fmt_state_57043 ieee80211_if_fmt_state 3 57043 NULL nohasharray
119710 +skb_network_offset_57043 skb_network_offset 0 57043 &ieee80211_if_fmt_state_57043
119711 +bytes_to_samples_57049 bytes_to_samples 0-2 57049 NULL
119712 +xfs_buf_read_map_57053 xfs_buf_read_map 3 57053 NULL
119713 +cx2341x_ctrl_new_std_57061 cx2341x_ctrl_new_std 4 57061 NULL
119714 +sca3000_read_data_57064 sca3000_read_data 4 57064 NULL
119715 +pcmcia_replace_cis_57066 pcmcia_replace_cis 3 57066 NULL
119716 +tracing_set_trace_write_57096 tracing_set_trace_write 3 57096 NULL
119717 +altera_get_note_57099 altera_get_note 6 57099 NULL
119718 +hpfs_readpages_57106 hpfs_readpages 4 57106 NULL
119719 +snd_pcm_hw_params_old_user_57108 snd_pcm_hw_params_old_user 0 57108 NULL
119720 +crypto_compress_ctxsize_57109 crypto_compress_ctxsize 0 57109 NULL
119721 +cipso_v4_gentag_loc_57119 cipso_v4_gentag_loc 0 57119 NULL
119722 +ima_show_htable_value_57136 ima_show_htable_value 2 57136 NULL nohasharray
119723 +rds_ib_sub_signaled_57136 rds_ib_sub_signaled 2 57136 &ima_show_htable_value_57136 nohasharray
119724 +nl80211_send_deauth_57136 nl80211_send_deauth 4 57136 &rds_ib_sub_signaled_57136
119725 +snd_sonicvibes_getdmac_57140 snd_sonicvibes_getdmac 0 57140 NULL
119726 +_iwl_dbgfs_bf_params_write_57141 _iwl_dbgfs_bf_params_write 3 57141 NULL
119727 +udl_prime_create_57159 udl_prime_create 2 57159 NULL
119728 +stk_prepare_sio_buffers_57168 stk_prepare_sio_buffers 2 57168 NULL
119729 +rx_hw_stuck_read_57179 rx_hw_stuck_read 3 57179 NULL
119730 +hash_netnet6_expire_57191 hash_netnet6_expire 4 57191 NULL
119731 +tt3650_ci_msg_57219 tt3650_ci_msg 4 57219 NULL
119732 +dma_fifo_alloc_57236 dma_fifo_alloc 2-3-5 57236 NULL
119733 +flush_space_57241 flush_space 0 57241 NULL
119734 +rsxx_cram_write_57244 rsxx_cram_write 3 57244 NULL
119735 +ieee80211_if_fmt_tsf_57249 ieee80211_if_fmt_tsf 3 57249 NULL
119736 +oprofilefs_ulong_from_user_57251 oprofilefs_ulong_from_user 3 57251 NULL
119737 +alloc_flex_gd_57259 alloc_flex_gd 1 57259 NULL
119738 +lbs_sleepparams_write_57283 lbs_sleepparams_write 3 57283 NULL
119739 +pstore_file_read_57288 pstore_file_read 3 57288 NULL
119740 +snd_pcm_read_57289 snd_pcm_read 3 57289 NULL
119741 +ftdi_elan_write_57309 ftdi_elan_write 3 57309 NULL
119742 +write_file_regval_57313 write_file_regval 3 57313 NULL
119743 +__mxt_write_reg_57326 __mxt_write_reg 3 57326 NULL
119744 +usblp_read_57342 usblp_read 3 57342 NULL
119745 +print_devstats_dot11RTSFailureCount_57347 print_devstats_dot11RTSFailureCount 3 57347 NULL
119746 +dio_send_cur_page_57348 dio_send_cur_page 0 57348 NULL
119747 +tipc_bclink_stats_57372 tipc_bclink_stats 2 57372 NULL
119748 +tty_register_device_attr_57381 tty_register_device_attr 2 57381 NULL
119749 +read_file_blob_57406 read_file_blob 3 57406 NULL
119750 +enclosure_register_57412 enclosure_register 3 57412 NULL
119751 +compat_keyctl_instantiate_key_iov_57431 compat_keyctl_instantiate_key_iov 3 57431 NULL
119752 +copy_to_user_fromio_57432 copy_to_user_fromio 3 57432 NULL
119753 +__roundup_pow_of_two_57461 __roundup_pow_of_two 0 57461 NULL
119754 +sisusb_clear_vram_57466 sisusb_clear_vram 2-3 57466 NULL
119755 +ieee80211_if_read_flags_57470 ieee80211_if_read_flags 3 57470 NULL
119756 +bnad_debugfs_write_regwr_57500 bnad_debugfs_write_regwr 3 57500 NULL
119757 +skb_headlen_57501 skb_headlen 0 57501 NULL
119758 +copy_in_user_57502 copy_in_user 3 57502 NULL
119759 +ckhdid_printf_57505 ckhdid_printf 2 57505 NULL
119760 +init_tag_map_57515 init_tag_map 3 57515 NULL
119761 +wil_read_file_ssid_57517 wil_read_file_ssid 3 57517 NULL nohasharray
119762 +il_dbgfs_force_reset_read_57517 il_dbgfs_force_reset_read 3 57517 &wil_read_file_ssid_57517
119763 +cmm_read_57520 cmm_read 3 57520 NULL
119764 +inode_permission_57531 inode_permission 0 57531 NULL
119765 +acpi_dev_get_resources_57534 acpi_dev_get_resources 0 57534 NULL
119766 +ptlrpc_lprocfs_hp_ratio_seq_write_57537 ptlrpc_lprocfs_hp_ratio_seq_write 3 57537 NULL
119767 +compat_SyS_process_vm_writev_57542 compat_SyS_process_vm_writev 3-5 57542 NULL
119768 +obd_unpackmd_57563 obd_unpackmd 0 57563 NULL
119769 +snd_pcm_playback_ioctl1_57569 snd_pcm_playback_ioctl1 0 57569 NULL
119770 +get_bridge_ifindices_57579 get_bridge_ifindices 0 57579 NULL
119771 +ldlm_cli_enqueue_local_57582 ldlm_cli_enqueue_local 11 57582 NULL
119772 +il_dbgfs_interrupt_write_57591 il_dbgfs_interrupt_write 3 57591 NULL
119773 +read_file_spectral_fft_period_57593 read_file_spectral_fft_period 3 57593 NULL
119774 +tx_tx_retry_template_read_57623 tx_tx_retry_template_read 3 57623 NULL
119775 +sisusbcon_putcs_57630 sisusbcon_putcs 3 57630 NULL
119776 +mem_read_57631 mem_read 3 57631 NULL
119777 +pci_enable_msi_block_57632 pci_enable_msi_block 0 57632 NULL
119778 +msi_compose_msg_57637 msi_compose_msg 0 57637 NULL
119779 +r3964_write_57662 r3964_write 4 57662 NULL
119780 +proc_ns_readlink_57664 proc_ns_readlink 3 57664 NULL
119781 +__lgwrite_57669 __lgwrite 4 57669 NULL
119782 +i2400m_rx_stats_read_57706 i2400m_rx_stats_read 3 57706 NULL
119783 +ieee80211_if_read_dot11MeshHWMPconfirmationInterval_57722 ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 NULL
119784 +vm_find_vqs_57729 vm_find_vqs 0 57729 NULL
119785 +nouveau_gpio_create__57735 nouveau_gpio_create_ 4-5 57735 NULL
119786 +pppol2tp_recvmsg_57742 pppol2tp_recvmsg 4 57742 NULL
119787 +ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval_57762 ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval 3 57762 NULL
119788 +SYSC_process_vm_writev_57776 SYSC_process_vm_writev 3-5 57776 NULL
119789 +security_inode_unlink_57791 security_inode_unlink 0 57791 NULL
119790 +ld2_57794 ld2 0 57794 NULL
119791 +ivtv_read_57796 ivtv_read 3 57796 NULL
119792 +ion_test_ioctl_57799 ion_test_ioctl 2 57799 NULL
119793 +bfad_debugfs_read_regrd_57830 bfad_debugfs_read_regrd 3 57830 NULL
119794 +copy_to_user_57835 copy_to_user 0-3 57835 NULL
119795 +flash_read_57843 flash_read 3 57843 NULL
119796 +kiblnd_create_tx_pool_57846 kiblnd_create_tx_pool 2 57846 NULL
119797 +radeon_ttm_gtt_read_57879 radeon_ttm_gtt_read 3 57879 NULL
119798 +xt_alloc_table_info_57903 xt_alloc_table_info 1 57903 NULL
119799 +iio_read_first_n_kfifo_57910 iio_read_first_n_kfifo 2 57910 NULL
119800 +ll_xattr_find_get_lock_57912 ll_xattr_find_get_lock 0 57912 NULL
119801 +memcg_caches_array_size_57918 memcg_caches_array_size 0-1 57918 NULL
119802 +twl_i2c_write_57923 twl_i2c_write 3-4 57923 NULL
119803 +__snd_gf1_look16_57925 __snd_gf1_look16 0 57925 NULL
119804 +sel_read_handle_unknown_57933 sel_read_handle_unknown 3 57933 NULL
119805 +xfs_mru_cache_create_57943 xfs_mru_cache_create 3 57943 NULL
119806 +key_algorithm_read_57946 key_algorithm_read 3 57946 NULL
119807 +ip_set_alloc_57953 ip_set_alloc 1 57953 NULL nohasharray
119808 +ioat3_dca_count_dca_slots_57953 ioat3_dca_count_dca_slots 0 57953 &ip_set_alloc_57953
119809 +rx_reset_counter_read_58001 rx_reset_counter_read 3 58001 NULL
119810 +iwl_dbgfs_ucode_rx_stats_read_58023 iwl_dbgfs_ucode_rx_stats_read 3 58023 NULL
119811 +io_playback_transfer_58030 io_playback_transfer 4 58030 NULL
119812 +mce_async_out_58056 mce_async_out 3 58056 NULL
119813 +ocfs2_find_leaf_58065 ocfs2_find_leaf 0 58065 NULL
119814 +dt3155_alloc_coherent_58073 dt3155_alloc_coherent 2 58073 NULL
119815 +cm4040_write_58079 cm4040_write 3 58079 NULL
119816 +ipv6_flowlabel_opt_58135 ipv6_flowlabel_opt 3 58135 NULL nohasharray
119817 +slhc_init_58135 slhc_init 1-2 58135 &ipv6_flowlabel_opt_58135
119818 +garmin_write_bulk_58191 garmin_write_bulk 3 58191 NULL
119819 +ieee80211_if_fmt_flags_58205 ieee80211_if_fmt_flags 3 58205 NULL
119820 +i40evf_allocate_virt_mem_d_58210 i40evf_allocate_virt_mem_d 3 58210 NULL
119821 +btrfsic_create_link_to_next_block_58246 btrfsic_create_link_to_next_block 4 58246 NULL
119822 +read_file_debug_58256 read_file_debug 3 58256 NULL
119823 +osc_max_dirty_mb_seq_write_58263 osc_max_dirty_mb_seq_write 3 58263 NULL
119824 +cfg80211_mgmt_tx_status_58266 cfg80211_mgmt_tx_status 4 58266 NULL
119825 +profile_load_58267 profile_load 3 58267 NULL
119826 +kstrtos8_from_user_58268 kstrtos8_from_user 2 58268 NULL
119827 +acpi_ds_build_internal_package_obj_58271 acpi_ds_build_internal_package_obj 3 58271 NULL
119828 +iscsi_decode_text_input_58292 iscsi_decode_text_input 4 58292 NULL
119829 +ieee80211_if_read_dot11MeshTTL_58307 ieee80211_if_read_dot11MeshTTL 3 58307 NULL
119830 +tx_tx_start_int_templates_read_58324 tx_tx_start_int_templates_read 3 58324 NULL
119831 +ext4_ext_truncate_extend_restart_58331 ext4_ext_truncate_extend_restart 3 58331 NULL
119832 +__copy_from_user_swizzled_58337 __copy_from_user_swizzled 2-4 58337 NULL
119833 +brcmf_debugfs_sdio_counter_read_58369 brcmf_debugfs_sdio_counter_read 3 58369 NULL
119834 +il_dbgfs_status_read_58388 il_dbgfs_status_read 3 58388 NULL
119835 +_drbd_md_sync_page_io_58403 _drbd_md_sync_page_io 6 58403 NULL
119836 +idetape_pad_zeros_58406 idetape_pad_zeros 2 58406 NULL
119837 +i2400m_pld_size_58415 i2400m_pld_size 0 58415 NULL
119838 +capabilities_read_58457 capabilities_read 3 58457 NULL
119839 +usnic_vnic_get_resources_58462 usnic_vnic_get_resources 3 58462 NULL
119840 +compat_do_ipt_set_ctl_58466 compat_do_ipt_set_ctl 4 58466 NULL nohasharray
119841 +lpfc_idiag_baracc_read_58466 lpfc_idiag_baracc_read 3 58466 &compat_do_ipt_set_ctl_58466
119842 +nv_rd08_58472 nv_rd08 0 58472 NULL
119843 +acpi_tables_sysfs_init_58477 acpi_tables_sysfs_init 0 58477 NULL
119844 +snd_gf1_read_addr_58483 snd_gf1_read_addr 0 58483 NULL
119845 +snd_rme96_capture_copy_58484 snd_rme96_capture_copy 5 58484 NULL
119846 +btrfs_cont_expand_58498 btrfs_cont_expand 2-3-0 58498 NULL
119847 +tcf_hash_create_58507 tcf_hash_create 4 58507 NULL
119848 +rndis_add_response_58544 rndis_add_response 2 58544 NULL
119849 +wep_decrypt_fail_read_58567 wep_decrypt_fail_read 3 58567 NULL
119850 +scnprint_mac_oui_58578 scnprint_mac_oui 3-0 58578 NULL
119851 +cur_wm_latency_write_58581 cur_wm_latency_write 3 58581 NULL
119852 +get_rhf_errstring_58582 get_rhf_errstring 3 58582 NULL
119853 +ea_read_inline_58589 ea_read_inline 0 58589 NULL
119854 +isku_sysfs_read_keys_thumbster_58590 isku_sysfs_read_keys_thumbster 6 58590 NULL
119855 +xip_file_read_58592 xip_file_read 3 58592 NULL
119856 +ecryptfs_write_end_58594 ecryptfs_write_end 5-3 58594 NULL
119857 +radeon_bo_size_58606 radeon_bo_size 0 58606 NULL
119858 +skb_copy_to_page_nocache_58624 skb_copy_to_page_nocache 6 58624 NULL
119859 +filemap_fdatawrite_range_58630 filemap_fdatawrite_range 0 58630 NULL
119860 +tx_tx_start_fw_gen_read_58648 tx_tx_start_fw_gen_read 3 58648 NULL
119861 +iwl_dbgfs_rx_handlers_write_58655 iwl_dbgfs_rx_handlers_write 3 58655 NULL
119862 +find_zero_58685 find_zero 0-1 58685 NULL
119863 +uwb_bce_print_IEs_58686 uwb_bce_print_IEs 4 58686 NULL
119864 +tps6586x_writes_58689 tps6586x_writes 2-3 58689 NULL
119865 +scsi_setup_command_freelist_58703 scsi_setup_command_freelist 0 58703 NULL
119866 +vx_send_msg_58711 vx_send_msg 0 58711 NULL
119867 +csum_exist_in_range_58730 csum_exist_in_range 2-3 58730 NULL
119868 +frames_to_bytes_58741 frames_to_bytes 0-2 58741 NULL
119869 +ieee80211_if_write_tkip_mic_test_58748 ieee80211_if_write_tkip_mic_test 3 58748 NULL
119870 +agp_allocate_memory_58761 agp_allocate_memory 2 58761 NULL
119871 +regmap_calc_reg_len_58795 regmap_calc_reg_len 0 58795 NULL
119872 +raw_send_hdrinc_58803 raw_send_hdrinc 4 58803 NULL
119873 +isku_sysfs_read_58806 isku_sysfs_read 5 58806 NULL
119874 +ep_read_58813 ep_read 3 58813 NULL
119875 +command_write_58841 command_write 3 58841 NULL
119876 +ath6kl_wmi_send_action_cmd_58860 ath6kl_wmi_send_action_cmd 7 58860 NULL
119877 +gs_alloc_req_58883 gs_alloc_req 2 58883 NULL
119878 +esas2r_change_queue_depth_58886 esas2r_change_queue_depth 2 58886 NULL
119879 +lprocfs_wr_pinger_recov_58914 lprocfs_wr_pinger_recov 3 58914 NULL
119880 +print_devstats_dot11FCSErrorCount_58919 print_devstats_dot11FCSErrorCount 3 58919 NULL
119881 +pipeline_cs_rx_packet_out_read_58926 pipeline_cs_rx_packet_out_read 3 58926 NULL
119882 +wait_table_hash_nr_entries_58962 wait_table_hash_nr_entries 0 58962 NULL
119883 +ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout_58965 ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout 3 58965 NULL
119884 +crypto_aead_ivsize_58970 crypto_aead_ivsize 0 58970 NULL
119885 +init_list_set_59005 init_list_set 3 59005 NULL
119886 +ep_write_59008 ep_write 3 59008 NULL
119887 +lpfc_idiag_baracc_write_59014 lpfc_idiag_baracc_write 3 59014 NULL
119888 +SyS_preadv_59029 SyS_preadv 3 59029 NULL
119889 +init_pci_cap_msi_perm_59033 init_pci_cap_msi_perm 2 59033 NULL
119890 +selinux_transaction_write_59038 selinux_transaction_write 3 59038 NULL
119891 +crypto_aead_reqsize_59039 crypto_aead_reqsize 0 59039 NULL
119892 +regmap_bulk_write_59049 regmap_bulk_write 2-4 59049 NULL nohasharray
119893 +i8042_enable_kbd_port_59049 i8042_enable_kbd_port 0 59049 &regmap_bulk_write_59049
119894 +mmc_sd_num_wr_blocks_59112 mmc_sd_num_wr_blocks 0 59112 NULL
119895 +sta_tx_latency_stat_table_59122 sta_tx_latency_stat_table 0-4-5 59122 NULL nohasharray
119896 +scsi_io_completion_59122 scsi_io_completion 2 59122 &sta_tx_latency_stat_table_59122
119897 +nfc_llcp_send_i_frame_59130 nfc_llcp_send_i_frame 3 59130 NULL
119898 +framebuffer_alloc_59145 framebuffer_alloc 1 59145 NULL nohasharray
119899 +print_devstats_dot11RTSSuccessCount_59145 print_devstats_dot11RTSSuccessCount 3 59145 &framebuffer_alloc_59145
119900 +radeon_compat_ioctl_59150 radeon_compat_ioctl 2 59150 NULL
119901 +pvr2_hdw_report_clients_59152 pvr2_hdw_report_clients 3 59152 NULL
119902 +ksize_59176 ksize 0 59176 NULL
119903 +setup_window_59178 setup_window 4-2-5-7 59178 NULL
119904 +ocfs2_move_extent_59187 ocfs2_move_extent 2-5 59187 NULL
119905 +xfs_iext_realloc_indirect_59211 xfs_iext_realloc_indirect 2 59211 NULL
119906 +check_mapped_selector_name_59216 check_mapped_selector_name 5 59216 NULL
119907 +dt3155_read_59226 dt3155_read 3 59226 NULL
119908 +paging64_gpte_to_gfn_lvl_59229 paging64_gpte_to_gfn_lvl 0-2-1 59229 NULL
119909 +nla_len_59258 nla_len 0 59258 NULL
119910 +drbd_bm_write_page_59290 drbd_bm_write_page 2 59290 NULL
119911 +btrfs_insert_dir_item_59304 btrfs_insert_dir_item 4 59304 NULL
119912 +fd_copyout_59323 fd_copyout 3 59323 NULL
119913 +read_9287_modal_eeprom_59327 read_9287_modal_eeprom 3 59327 NULL
119914 +set_state_private_59336 set_state_private 0 59336 NULL
119915 +rx_defrag_in_process_called_read_59338 rx_defrag_in_process_called_read 3 59338 NULL
119916 +xfs_attrmulti_attr_set_59346 xfs_attrmulti_attr_set 4 59346 NULL
119917 +f2fs_fallocate_59377 f2fs_fallocate 4-3 59377 NULL
119918 +pvr2_debugifc_print_info_59380 pvr2_debugifc_print_info 3 59380 NULL
119919 +journal_init_dev_59384 journal_init_dev 5 59384 NULL
119920 +__net_get_random_once_59389 __net_get_random_once 2 59389 NULL
119921 +isku_sysfs_read_keys_function_59412 isku_sysfs_read_keys_function 6 59412 NULL
119922 +pci_ctrl_read_59424 pci_ctrl_read 0 59424 NULL
119923 +vxge_hw_ring_rxds_per_block_get_59425 vxge_hw_ring_rxds_per_block_get 0 59425 NULL
119924 +snd_pcm_tstamp_59431 snd_pcm_tstamp 0 59431 NULL
119925 +SyS_sched_setaffinity_59442 SyS_sched_setaffinity 2 59442 NULL
119926 +fs_path_ensure_buf_59445 fs_path_ensure_buf 2 59445 NULL
119927 +tipc_recv_stream_59456 tipc_recv_stream 4 59456 NULL
119928 +_iwl_dbgfs_bcast_filters_write_59491 _iwl_dbgfs_bcast_filters_write 3 59491 NULL
119929 +rtw_cfg80211_set_mgnt_wpsp2pie_59497 rtw_cfg80211_set_mgnt_wpsp2pie 3 59497 NULL
119930 +ib_copy_from_udata_59502 ib_copy_from_udata 3 59502 NULL
119931 +C_SYSC_get_mempolicy_59516 C_SYSC_get_mempolicy 3 59516 NULL
119932 +mic_vringh_copy_59523 mic_vringh_copy 4 59523 NULL
119933 +msix_setup_entries_59545 msix_setup_entries 0 59545 NULL nohasharray
119934 +idr_alloc_59545 idr_alloc 0 59545 &msix_setup_entries_59545
119935 +mpi_get_nbits_59551 mpi_get_nbits 0 59551 NULL
119936 +tunables_write_59563 tunables_write 3 59563 NULL
119937 +bio_split_59564 bio_split 2 59564 NULL
119938 +__copy_from_user_ll_nozero_59571 __copy_from_user_ll_nozero 0-3 59571 NULL
119939 +memdup_user_59590 memdup_user 2 59590 NULL
119940 +xrcdn_free_res_59616 xrcdn_free_res 5 59616 NULL nohasharray
119941 +mem_fwlog_free_mem_blks_read_59616 mem_fwlog_free_mem_blks_read 3 59616 &xrcdn_free_res_59616
119942 +ath6kl_endpoint_stats_write_59621 ath6kl_endpoint_stats_write 3 59621 NULL
119943 +mtrr_write_59622 mtrr_write 3 59622 NULL
119944 +find_first_zero_bit_59636 find_first_zero_bit 0 59636 NULL
119945 +SyS_setdomainname_59646 SyS_setdomainname 2 59646 NULL
119946 +file_update_time_59647 file_update_time 0 59647 NULL
119947 +hidraw_read_59650 hidraw_read 3 59650 NULL
119948 +v9fs_xattr_set_acl_59651 v9fs_xattr_set_acl 4 59651 NULL
119949 +__devcgroup_check_permission_59665 __devcgroup_check_permission 0 59665 NULL
119950 +iwl_dbgfs_mac_params_read_59666 iwl_dbgfs_mac_params_read 3 59666 NULL
119951 +alloc_dca_provider_59670 alloc_dca_provider 2 59670 NULL
119952 +mic_calc_failure_read_59700 mic_calc_failure_read 3 59700 NULL
119953 +ioperm_get_59701 ioperm_get 4-3 59701 NULL
119954 +snd_pcm_info_user_59711 snd_pcm_info_user 0 59711 NULL
119955 +prism2_info_scanresults_59729 prism2_info_scanresults 3 59729 NULL
119956 +ieee80211_if_read_fwded_unicast_59740 ieee80211_if_read_fwded_unicast 3 59740 NULL
119957 +fat_direct_IO_59741 fat_direct_IO 4 59741 NULL
119958 +qib_decode_7220_sdma_errs_59745 qib_decode_7220_sdma_errs 4 59745 NULL
119959 +strnlen_59746 strnlen 0 59746 NULL
119960 +ext3_acl_count_59754 ext3_acl_count 0-1 59754 NULL
119961 +long_retry_limit_read_59766 long_retry_limit_read 3 59766 NULL nohasharray
119962 +cap_inode_need_killpriv_59766 cap_inode_need_killpriv 0 59766 &long_retry_limit_read_59766
119963 +venus_remove_59781 venus_remove 4 59781 NULL
119964 +mei_nfc_recv_59784 mei_nfc_recv 3 59784 NULL
119965 +C_SYSC_preadv_59801 C_SYSC_preadv 3 59801 NULL
119966 +ipw_write_59807 ipw_write 3 59807 NULL
119967 +scsi_init_shared_tag_map_59812 scsi_init_shared_tag_map 2 59812 NULL
119968 +ieee80211_if_read_dot11MeshHWMPmaxPREQretries_59829 ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 NULL
119969 +gspca_dev_probe2_59833 gspca_dev_probe2 4 59833 NULL
119970 +regmap_raw_write_async_59849 regmap_raw_write_async 2-4 59849 NULL
119971 +pvr2_ioread_set_sync_key_59882 pvr2_ioread_set_sync_key 3 59882 NULL
119972 +l2cap_sock_recvmsg_59886 l2cap_sock_recvmsg 4 59886 NULL
119973 +ffs_prepare_buffer_59892 ffs_prepare_buffer 2 59892 NULL
119974 +kvm_mmu_notifier_invalidate_range_start_59944 kvm_mmu_notifier_invalidate_range_start 3-4 59944 NULL
119975 +ath10k_read_dfs_stats_59949 ath10k_read_dfs_stats 3 59949 NULL
119976 +dapm_widget_power_read_file_59950 dapm_widget_power_read_file 3 59950 NULL nohasharray
119977 +il_dbgfs_rxon_flags_read_59950 il_dbgfs_rxon_flags_read 3 59950 &dapm_widget_power_read_file_59950
119978 +il_dbgfs_missed_beacon_read_59956 il_dbgfs_missed_beacon_read 3 59956 NULL
119979 +__arch_hweight16_59975 __arch_hweight16 0 59975 NULL
119980 +osd_req_read_kern_59990 osd_req_read_kern 5 59990 NULL
119981 +ghash_async_setkey_60001 ghash_async_setkey 3 60001 NULL
119982 +ieee80211_if_fmt_dot11MeshAwakeWindowDuration_60006 ieee80211_if_fmt_dot11MeshAwakeWindowDuration 3 60006 NULL
119983 +copy_items_60009 copy_items 7 60009 NULL
119984 +rawsock_sendmsg_60010 rawsock_sendmsg 4 60010 NULL
119985 +mthca_init_cq_60011 mthca_init_cq 2 60011 NULL
119986 +osd_req_list_dev_partitions_60027 osd_req_list_dev_partitions 4 60027 NULL
119987 +xlog_bread_offset_60030 xlog_bread_offset 3 60030 NULL
119988 +bio_integrity_hw_sectors_60039 bio_integrity_hw_sectors 0-2 60039 NULL
119989 +do_ip6t_set_ctl_60040 do_ip6t_set_ctl 4 60040 NULL
119990 +vcs_size_60050 vcs_size 0 60050 NULL
119991 +gru_alloc_gts_60056 gru_alloc_gts 3-2 60056 NULL
119992 +compat_writev_60063 compat_writev 3 60063 NULL
119993 +ath6kl_listen_int_write_60066 ath6kl_listen_int_write 3 60066 NULL
119994 +c4iw_num_stags_60073 c4iw_num_stags 0 60073 NULL
119995 +rxrpc_kernel_send_data_60083 rxrpc_kernel_send_data 3 60083 NULL
119996 +ieee80211_if_fmt_fwded_frames_60103 ieee80211_if_fmt_fwded_frames 3 60103 NULL
119997 +SYSC_msgsnd_60113 SYSC_msgsnd 3 60113 NULL
119998 +nfs_idmap_request_key_60124 nfs_idmap_request_key 2 60124 NULL
119999 +__mutex_lock_common_60134 __mutex_lock_common 0 60134 NULL
120000 +ld_usb_read_60156 ld_usb_read 3 60156 NULL
120001 +jmb38x_ms_count_slots_60164 jmb38x_ms_count_slots 0 60164 NULL
120002 +init_state_60165 init_state 2 60165 NULL
120003 +jffs2_alloc_full_dirent_60179 jffs2_alloc_full_dirent 1 60179 NULL nohasharray
120004 +sg_build_sgat_60179 sg_build_sgat 3 60179 &jffs2_alloc_full_dirent_60179
120005 +fuse_async_req_send_60183 fuse_async_req_send 0-3 60183 NULL
120006 +arch_setup_msi_irqs_60193 arch_setup_msi_irqs 0 60193 NULL nohasharray
120007 +rx_rx_tkip_replays_read_60193 rx_rx_tkip_replays_read 3 60193 &arch_setup_msi_irqs_60193
120008 +qib_reg_phys_mr_60202 qib_reg_phys_mr 3 60202 NULL
120009 +btrfs_get_token_16_60220 btrfs_get_token_16 0 60220 NULL
120010 +irq_alloc_domain_generic_chips_60264 irq_alloc_domain_generic_chips 2-3 60264 NULL
120011 +display_crc_ctl_write_60273 display_crc_ctl_write 3 60273 NULL
120012 +printer_write_60276 printer_write 3 60276 NULL
120013 +do_xip_mapping_read_60297 do_xip_mapping_read 5 60297 NULL
120014 +getDataLength_60301 getDataLength 0 60301 NULL
120015 +bch_subtract_dirty_60306 bch_subtract_dirty 3-4 60306 NULL
120016 +usb_alphatrack_write_60341 usb_alphatrack_write 3 60341 NULL
120017 +__kfifo_from_user_r_60345 __kfifo_from_user_r 5-3 60345 NULL
120018 +dccp_setsockopt_60367 dccp_setsockopt 5 60367 NULL
120019 +ubi_eba_atomic_leb_change_60379 ubi_eba_atomic_leb_change 0 60379 NULL
120020 +mthca_alloc_resize_buf_60394 mthca_alloc_resize_buf 3 60394 NULL
120021 +ocfs2_zero_extend_60396 ocfs2_zero_extend 3 60396 NULL
120022 +driver_names_read_60399 driver_names_read 3 60399 NULL
120023 +simple_alloc_urb_60420 simple_alloc_urb 3 60420 NULL
120024 +excessive_retries_read_60425 excessive_retries_read 3 60425 NULL
120025 +kmalloc_60432 kmalloc 1 60432 NULL nohasharray
120026 +tstats_write_60432 tstats_write 3 60432 &kmalloc_60432
120027 +snd_hda_get_num_raw_conns_60462 snd_hda_get_num_raw_conns 0 60462 NULL
120028 +crypto_shash_setkey_60483 crypto_shash_setkey 3 60483 NULL
120029 +lustre_msg_early_size_60496 lustre_msg_early_size 0 60496 NULL
120030 +compat_SyS_get_mempolicy_60527 compat_SyS_get_mempolicy 3 60527 NULL
120031 +v9fs_fid_readn_60544 v9fs_fid_readn 4 60544 NULL
120032 +nonpaging_map_60551 nonpaging_map 4 60551 NULL
120033 +osc_lockless_truncate_seq_write_60553 osc_lockless_truncate_seq_write 3 60553 NULL
120034 +tracing_entries_write_60563 tracing_entries_write 3 60563 NULL
120035 +memblock_virt_alloc_try_nid_nopanic_60604 memblock_virt_alloc_try_nid_nopanic 1 60604 NULL
120036 +inode_change_ok_60614 inode_change_ok 0 60614 NULL
120037 +skb_transport_offset_60619 skb_transport_offset 0 60619 NULL
120038 +wl1273_fm_fops_write_60621 wl1273_fm_fops_write 3 60621 NULL
120039 +acl_alloc_stack_init_60630 acl_alloc_stack_init 1 60630 NULL
120040 +__proc_lnet_stats_60647 __proc_lnet_stats 5 60647 NULL
120041 +if_sdio_host_to_card_60666 if_sdio_host_to_card 4 60666 NULL
120042 +ieee80211_if_read_dot11MeshConfirmTimeout_60670 ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 NULL
120043 +vga_rcrt_60731 vga_rcrt 0 60731 NULL
120044 +snd_ice1712_ds_read_60754 snd_ice1712_ds_read 0 60754 NULL
120045 +raid_status_60755 raid_status 5 60755 NULL
120046 +sel_write_checkreqprot_60774 sel_write_checkreqprot 3 60774 NULL
120047 +opticon_write_60775 opticon_write 4 60775 NULL
120048 +acl_alloc_num_60778 acl_alloc_num 1-2 60778 NULL
120049 +snd_pcm_oss_readv3_60792 snd_pcm_oss_readv3 3 60792 NULL
120050 +pwr_tx_with_ps_read_60851 pwr_tx_with_ps_read 3 60851 NULL
120051 +__clone_and_map_data_bio_60861 __clone_and_map_data_bio 3-4 60861 NULL
120052 +alloc_buf_60864 alloc_buf 3-2 60864 NULL
120053 +generic_writepages_60871 generic_writepages 0 60871 NULL
120054 +ubifs_read_one_lp_60882 ubifs_read_one_lp 0 60882 NULL
120055 +ext4_update_inline_data_60888 ext4_update_inline_data 3 60888 NULL
120056 +iio_debugfs_read_reg_60908 iio_debugfs_read_reg 3 60908 NULL
120057 +libcfs_sock_ioctl_60915 libcfs_sock_ioctl 0 60915 NULL
120058 +mgt_set_varlen_60916 mgt_set_varlen 4 60916 NULL
120059 +submit_extent_page_60928 submit_extent_page 5 60928 NULL
120060 +pti_char_write_60960 pti_char_write 3 60960 NULL
120061 +mwifiex_alloc_sdio_mpa_buffers_60961 mwifiex_alloc_sdio_mpa_buffers 2-3 60961 NULL
120062 +__a2mp_build_60987 __a2mp_build 3 60987 NULL
120063 +hsc_msg_alloc_60990 hsc_msg_alloc 1 60990 NULL
120064 +ath6kl_lrssi_roam_read_61022 ath6kl_lrssi_roam_read 3 61022 NULL
120065 +graph_depth_write_61024 graph_depth_write 3 61024 NULL
120066 +sdhci_pltfm_register_61031 sdhci_pltfm_register 3 61031 NULL
120067 +lpfc_idiag_queacc_write_61043 lpfc_idiag_queacc_write 3 61043 NULL
120068 +symtab_init_61050 symtab_init 2 61050 NULL
120069 +fuse_send_write_61053 fuse_send_write 0-4 61053 NULL
120070 +snd_pcm_pause_61054 snd_pcm_pause 0 61054 NULL
120071 +bitmap_scnlistprintf_61062 bitmap_scnlistprintf 2-0 61062 NULL
120072 +ahash_align_buffer_size_61070 ahash_align_buffer_size 0-1-2 61070 NULL
120073 +snd_pcm_update_hw_ptr0_61084 snd_pcm_update_hw_ptr0 0 61084 NULL
120074 +get_derived_key_61100 get_derived_key 4 61100 NULL
120075 +i40e_calculate_l2fpm_size_61104 i40e_calculate_l2fpm_size 0-4-3-2-1 61104 NULL
120076 +alloc_chrdev_region_61112 alloc_chrdev_region 0 61112 NULL
120077 +__probe_kernel_read_61119 __probe_kernel_read 3 61119 NULL
120078 +vmemmap_alloc_block_buf_61126 vmemmap_alloc_block_buf 1 61126 NULL
120079 +afs_proc_cells_write_61139 afs_proc_cells_write 3 61139 NULL
120080 +pair_device_61175 pair_device 4 61175 NULL nohasharray
120081 +event_oom_late_read_61175 event_oom_late_read 3 61175 &pair_device_61175
120082 +dio_bio_add_page_61178 dio_bio_add_page 0 61178 NULL
120083 +SyS_prctl_61202 SyS_prctl 4 61202 NULL
120084 +arch_hibernation_header_save_61212 arch_hibernation_header_save 0 61212 NULL
120085 +smk_read_ambient_61220 smk_read_ambient 3 61220 NULL
120086 +v9fs_mmap_file_read_61262 v9fs_mmap_file_read 3 61262 NULL
120087 +btrfs_bio_alloc_61270 btrfs_bio_alloc 3 61270 NULL nohasharray
120088 +find_get_pages_tag_61270 find_get_pages_tag 0 61270 &btrfs_bio_alloc_61270 nohasharray
120089 +ifalias_store_61270 ifalias_store 4 61270 &find_get_pages_tag_61270
120090 +vortex_adbdma_getlinearpos_61283 vortex_adbdma_getlinearpos 0 61283 NULL nohasharray
120091 +hfsplus_getxattr_finder_info_61283 hfsplus_getxattr_finder_info 0 61283 &vortex_adbdma_getlinearpos_61283
120092 +nvme_trans_copy_to_user_61288 nvme_trans_copy_to_user 3 61288 NULL
120093 +xfer_from_user_61307 xfer_from_user 3 61307 NULL
120094 +xfrm_user_sec_ctx_size_61320 xfrm_user_sec_ctx_size 0 61320 NULL
120095 +C_SYSC_msgsnd_61330 C_SYSC_msgsnd 3 61330 NULL
120096 +write_file_spectral_short_repeat_61335 write_file_spectral_short_repeat 3 61335 NULL
120097 +st5481_setup_isocpipes_61340 st5481_setup_isocpipes 6-4 61340 NULL
120098 +rx_rx_wa_ba_not_expected_read_61341 rx_rx_wa_ba_not_expected_read 3 61341 NULL
120099 +__dm_get_reserved_ios_61342 __dm_get_reserved_ios 0-3-2 61342 NULL
120100 +debug_debug4_read_61367 debug_debug4_read 3 61367 NULL
120101 +system_enable_write_61396 system_enable_write 3 61396 NULL
120102 +unix_stream_sendmsg_61455 unix_stream_sendmsg 4 61455 NULL
120103 +snd_pcm_lib_writev_transfer_61483 snd_pcm_lib_writev_transfer 5-4-2 61483 NULL
120104 +btrfs_item_size_61485 btrfs_item_size 0 61485 NULL
120105 +erst_errno_61526 erst_errno 0 61526 NULL
120106 +compat_SyS_select_61542 compat_SyS_select 1 61542 NULL
120107 +trace_options_core_write_61551 trace_options_core_write 3 61551 NULL
120108 +dvb_net_ioctl_61559 dvb_net_ioctl 2 61559 NULL
120109 +fan_proc_write_61569 fan_proc_write 3 61569 NULL
120110 +ieee80211_if_read_rc_rateidx_mask_2ghz_61570 ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 NULL
120111 +ldlm_pool_rw_atomic_seq_write_61572 ldlm_pool_rw_atomic_seq_write 3 61572 NULL
120112 +seq_open_private_61589 seq_open_private 3 61589 NULL
120113 +ept_gpte_to_gfn_lvl_61591 ept_gpte_to_gfn_lvl 0-2-1 61591 NULL
120114 +netlink_recvmsg_61600 netlink_recvmsg 4 61600 NULL
120115 +nfs4_init_uniform_client_string_61601 nfs4_init_uniform_client_string 3 61601 NULL
120116 +configfs_write_file_61621 configfs_write_file 3 61621 NULL
120117 +ieee80211_if_fmt_hw_queues_61629 ieee80211_if_fmt_hw_queues 3 61629 NULL
120118 +i2o_parm_table_get_61635 i2o_parm_table_get 6 61635 NULL
120119 +snd_pcm_oss_read3_61643 snd_pcm_oss_read3 0-3 61643 NULL nohasharray
120120 +tcf_hashinfo_init_61643 tcf_hashinfo_init 2 61643 &snd_pcm_oss_read3_61643
120121 +resize_stripes_61650 resize_stripes 2 61650 NULL
120122 +ttm_page_pool_free_61661 ttm_page_pool_free 2-0 61661 NULL
120123 +insert_one_name_61668 insert_one_name 7 61668 NULL
120124 +snd_pcm_playback_avail_61671 snd_pcm_playback_avail 0 61671 NULL
120125 +qib_format_hwmsg_61679 qib_format_hwmsg 2 61679 NULL
120126 +lock_loop_61681 lock_loop 1 61681 NULL
120127 +filter_read_61692 filter_read 3 61692 NULL
120128 +iov_length_61716 iov_length 0 61716 NULL
120129 +fragmentation_threshold_read_61718 fragmentation_threshold_read 3 61718 NULL
120130 +null_alloc_reqbuf_61719 null_alloc_reqbuf 3 61719 NULL
120131 +read_file_interrupt_61742 read_file_interrupt 3 61742 NULL nohasharray
120132 +read_file_regval_61742 read_file_regval 3 61742 &read_file_interrupt_61742
120133 +SyS_sendto_61763 SyS_sendto 6 61763 NULL
120134 +mls_compute_context_len_61812 mls_compute_context_len 0 61812 NULL
120135 +bfad_debugfs_write_regwr_61841 bfad_debugfs_write_regwr 3 61841 NULL
120136 +regcache_sync_block_61846 regcache_sync_block 5-4 61846 NULL
120137 +ath9k_hw_def_dump_eeprom_61853 ath9k_hw_def_dump_eeprom 5-4 61853 NULL
120138 +evdev_compute_buffer_size_61863 evdev_compute_buffer_size 0 61863 NULL
120139 +SYSC_lsetxattr_61869 SYSC_lsetxattr 4 61869 NULL
120140 +get_fw_name_61874 get_fw_name 3 61874 NULL
120141 +btrfs_ioctl_clone_61886 btrfs_ioctl_clone 3-4-5 61886 NULL
120142 +lprocfs_write_frac_u64_helper_61897 lprocfs_write_frac_u64_helper 2 61897 NULL
120143 +lov_mds_md_stripecnt_61899 lov_mds_md_stripecnt 0-1 61899 NULL
120144 +clear_refs_write_61904 clear_refs_write 3 61904 NULL
120145 +kernfs_name_61910 kernfs_name 3 61910 NULL
120146 +rx_filter_arp_filter_read_61914 rx_filter_arp_filter_read 3 61914 NULL
120147 +au0828_init_isoc_61917 au0828_init_isoc 3-2-4 61917 NULL
120148 +sctp_sendmsg_61919 sctp_sendmsg 4 61919 NULL
120149 +SyS_kexec_load_61946 SyS_kexec_load 2 61946 NULL
120150 +il4965_ucode_rx_stats_read_61948 il4965_ucode_rx_stats_read 3 61948 NULL
120151 +squashfs_read_id_index_table_61961 squashfs_read_id_index_table 4 61961 NULL
120152 +fix_read_error_61965 fix_read_error 4 61965 NULL
120153 +cow_file_range_61979 cow_file_range 3 61979 NULL
120154 +set_extent_delalloc_61982 set_extent_delalloc 0 61982 NULL
120155 +dequeue_event_62000 dequeue_event 3 62000 NULL
120156 +xt_compat_match_offset_62011 xt_compat_match_offset 0 62011 NULL
120157 +SyS_setxattr_62019 SyS_setxattr 4 62019 NULL
120158 +jffs2_do_unlink_62020 jffs2_do_unlink 4 62020 NULL
120159 +SYSC_select_62024 SYSC_select 1 62024 NULL
120160 +pmcraid_build_passthrough_ioadls_62034 pmcraid_build_passthrough_ioadls 2 62034 NULL
120161 +sctp_user_addto_chunk_62047 sctp_user_addto_chunk 2-3 62047 NULL
120162 +do_pselect_62061 do_pselect 1 62061 NULL
120163 +pcpu_alloc_bootmem_62074 pcpu_alloc_bootmem 2 62074 NULL
120164 +fat_setattr_62084 fat_setattr 0 62084 NULL
120165 +jffs2_security_setxattr_62107 jffs2_security_setxattr 4 62107 NULL
120166 +btrfs_direct_IO_62114 btrfs_direct_IO 4 62114 NULL
120167 +ip_recv_error_62117 ip_recv_error 3 62117 NULL
120168 +generic_block_fiemap_62122 generic_block_fiemap 4 62122 NULL
120169 +llc_ui_header_len_62131 llc_ui_header_len 0 62131 NULL
120170 +qib_diag_write_62133 qib_diag_write 3 62133 NULL nohasharray
120171 +kobject_add_varg_62133 kobject_add_varg 0 62133 &qib_diag_write_62133
120172 +ql_status_62135 ql_status 5 62135 NULL nohasharray
120173 +device_add_attrs_62135 device_add_attrs 0 62135 &ql_status_62135
120174 +video_usercopy_62151 video_usercopy 2 62151 NULL
120175 +SyS_getxattr_62166 SyS_getxattr 4 62166 NULL
120176 +prism54_wpa_bss_ie_get_62173 prism54_wpa_bss_ie_get 0 62173 NULL
120177 +write_file_dfs_62180 write_file_dfs 3 62180 NULL
120178 +alloc_upcall_62186 alloc_upcall 2 62186 NULL
120179 +sock_kmalloc_62205 sock_kmalloc 2 62205 NULL
120180 +smk_read_syslog_62227 smk_read_syslog 3 62227 NULL
120181 +SYSC_setgroups16_62232 SYSC_setgroups16 1 62232 NULL
120182 +nfsd_read_file_62241 nfsd_read_file 6 62241 NULL
120183 +ion_handle_test_dma_62262 ion_handle_test_dma 4-5 62262 NULL
120184 +il_dbgfs_sram_read_62296 il_dbgfs_sram_read 3 62296 NULL
120185 +sparse_early_usemaps_alloc_pgdat_section_62304 sparse_early_usemaps_alloc_pgdat_section 2 62304 NULL
120186 +subsystem_filter_read_62310 subsystem_filter_read 3 62310 NULL
120187 +Wb35Reg_BurstWrite_62327 Wb35Reg_BurstWrite 4 62327 NULL
120188 +subseq_list_62332 subseq_list 3-0 62332 NULL
120189 +ll_statahead_max_seq_write_62333 ll_statahead_max_seq_write 3 62333 NULL
120190 +flash_write_62354 flash_write 3 62354 NULL
120191 +xfpregs_set_62363 xfpregs_set 4 62363 NULL
120192 +rx_rx_timeout_read_62389 rx_rx_timeout_read 3 62389 NULL
120193 +altera_irscan_62396 altera_irscan 2 62396 NULL
120194 +set_ssp_62411 set_ssp 4 62411 NULL
120195 +udf_expand_file_adinicb_62470 udf_expand_file_adinicb 0 62470 NULL
120196 +ext_rts51x_sd_execute_read_data_62501 ext_rts51x_sd_execute_read_data 9 62501 NULL
120197 +pep_sendmsg_62524 pep_sendmsg 4 62524 NULL
120198 +test_iso_queue_62534 test_iso_queue 5 62534 NULL
120199 +debugfs_read_62535 debugfs_read 3 62535 NULL
120200 +sco_sock_sendmsg_62542 sco_sock_sendmsg 4 62542 NULL
120201 +qib_refresh_qsfp_cache_62547 qib_refresh_qsfp_cache 0 62547 NULL
120202 +xfrm_user_policy_62573 xfrm_user_policy 4 62573 NULL
120203 +get_subdir_62581 get_subdir 3 62581 NULL
120204 +nfsd_vfs_read_62605 nfsd_vfs_read 6 62605 NULL
120205 +dut_mode_write_62630 dut_mode_write 3 62630 NULL
120206 +vfs_fsync_range_62635 vfs_fsync_range 0 62635 NULL
120207 +lpfc_sli4_queue_alloc_62646 lpfc_sli4_queue_alloc 3 62646 NULL
120208 +printer_req_alloc_62687 printer_req_alloc 2 62687 NULL
120209 +bioset_integrity_create_62708 bioset_integrity_create 2 62708 NULL
120210 +gfs2_log_write_62717 gfs2_log_write 3 62717 NULL
120211 +rdm_62719 rdm 0 62719 NULL
120212 +obd_ioctl_popdata_62741 obd_ioctl_popdata 3 62741 NULL
120213 +key_replays_read_62746 key_replays_read 3 62746 NULL
120214 +lov_verify_lmm_62747 lov_verify_lmm 2 62747 NULL
120215 +mwifiex_rdeeprom_write_62754 mwifiex_rdeeprom_write 3 62754 NULL
120216 +ax25_sendmsg_62770 ax25_sendmsg 4 62770 NULL
120217 +C_SYSC_ipc_62776 C_SYSC_ipc 3 62776 NULL
120218 +SyS_sched_getaffinity_62786 SyS_sched_getaffinity 2 62786 NULL
120219 +dm_stats_account_io_62787 dm_stats_account_io 3 62787 NULL
120220 +tracing_total_entries_read_62817 tracing_total_entries_read 3 62817 NULL
120221 +__rounddown_pow_of_two_62836 __rounddown_pow_of_two 0 62836 NULL
120222 +bio_get_nr_vecs_62838 bio_get_nr_vecs 0 62838 NULL
120223 +xlog_recover_add_to_trans_62839 xlog_recover_add_to_trans 4 62839 NULL
120224 +rx_fcs_err_read_62844 rx_fcs_err_read 3 62844 NULL
120225 +read_nic_io_dword_62859 read_nic_io_dword 0 62859 NULL
120226 +l2tp_ip6_recvmsg_62874 l2tp_ip6_recvmsg 4 62874 NULL
120227 +aoechr_write_62883 aoechr_write 3 62883 NULL
120228 +if_spi_host_to_card_62890 if_spi_host_to_card 4 62890 NULL
120229 +mempool_create_slab_pool_62907 mempool_create_slab_pool 1 62907 NULL
120230 +getdqbuf_62908 getdqbuf 1 62908 NULL
120231 +ll_statahead_agl_seq_write_62928 ll_statahead_agl_seq_write 3 62928 NULL
120232 +agp_create_user_memory_62955 agp_create_user_memory 1 62955 NULL
120233 +kstrtoull_from_user_63026 kstrtoull_from_user 2 63026 NULL
120234 +__vb2_perform_fileio_63033 __vb2_perform_fileio 3 63033 NULL
120235 +pipeline_defrag_to_csum_swi_read_63037 pipeline_defrag_to_csum_swi_read 3 63037 NULL
120236 +scsi_host_alloc_63041 scsi_host_alloc 2 63041 NULL
120237 +unlink1_63059 unlink1 3 63059 NULL
120238 +xen_set_nslabs_63066 xen_set_nslabs 0 63066 NULL
120239 +iwl_dbgfs_fw_rx_stats_read_63070 iwl_dbgfs_fw_rx_stats_read 3 63070 NULL
120240 +sep_prepare_input_output_dma_table_in_dcb_63087 sep_prepare_input_output_dma_table_in_dcb 4-5 63087 NULL
120241 +iwl_dbgfs_sensitivity_read_63116 iwl_dbgfs_sensitivity_read 3 63116 NULL
120242 +ext4_chunk_trans_blocks_63123 ext4_chunk_trans_blocks 0-2 63123 NULL
120243 +snd_pcm_status_user_63140 snd_pcm_status_user 0 63140 NULL
120244 +ubifs_change_one_lp_63157 ubifs_change_one_lp 0 63157 NULL
120245 +smk_write_revoke_subj_63173 smk_write_revoke_subj 3 63173 NULL
120246 +SyS_syslog_63178 SyS_syslog 3 63178 NULL
120247 +vme_master_read_63221 vme_master_read 0 63221 NULL
120248 +SyS_gethostname_63227 SyS_gethostname 2 63227 NULL
120249 +ptp_read_63251 ptp_read 4 63251 NULL
120250 +xfs_dir2_leaf_getdents_63262 xfs_dir2_leaf_getdents 3 63262 NULL
120251 +iwl_dbgfs_fw_error_dump_read_63263 iwl_dbgfs_fw_error_dump_read 3 63263 NULL
120252 +raid5_resize_63306 raid5_resize 2 63306 NULL
120253 +ath10k_read_fw_dbglog_63323 ath10k_read_fw_dbglog 3 63323 NULL
120254 +proc_info_read_63344 proc_info_read 3 63344 NULL
120255 +ps_upsd_max_sptime_read_63362 ps_upsd_max_sptime_read 3 63362 NULL
120256 +idmouse_read_63374 idmouse_read 3 63374 NULL
120257 +usbnet_read_cmd_nopm_63388 usbnet_read_cmd_nopm 7 63388 NULL nohasharray
120258 +edac_pci_alloc_ctl_info_63388 edac_pci_alloc_ctl_info 1 63388 &usbnet_read_cmd_nopm_63388
120259 +rxpipe_missed_beacon_host_int_trig_rx_data_read_63405 rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 NULL
120260 +nouveau_event_create_63411 nouveau_event_create 1 63411 NULL
120261 +l2cap_sock_sendmsg_63427 l2cap_sock_sendmsg 4 63427 NULL
120262 +nfsd_symlink_63442 nfsd_symlink 6 63442 NULL
120263 +si5351_bulk_write_63468 si5351_bulk_write 2-3 63468 NULL
120264 +snd_info_entry_write_63474 snd_info_entry_write 3 63474 NULL
120265 +reada_find_extent_63486 reada_find_extent 2 63486 NULL
120266 +read_kcore_63488 read_kcore 3 63488 NULL
120267 +iwl_dbgfs_bcast_filters_read_63489 iwl_dbgfs_bcast_filters_read 3 63489 NULL
120268 +snd_pcm_plug_write_transfer_63503 snd_pcm_plug_write_transfer 0-3 63503 NULL
120269 +efx_mcdi_rpc_async_63529 efx_mcdi_rpc_async 4-5 63529 NULL
120270 +ubi_more_leb_change_data_63534 ubi_more_leb_change_data 4 63534 NULL nohasharray
120271 +generic_cont_expand_simple_63534 generic_cont_expand_simple 0 63534 &ubi_more_leb_change_data_63534
120272 +write_file_spectral_period_63536 write_file_spectral_period 3 63536 NULL
120273 +if_sdio_read_scratch_63540 if_sdio_read_scratch 0 63540 NULL
120274 +append_to_buffer_63550 append_to_buffer 3 63550 NULL
120275 +kvm_write_guest_page_63555 kvm_write_guest_page 5 63555 NULL
120276 +rproc_alloc_63577 rproc_alloc 5 63577 NULL
120277 +write_debug_level_63613 write_debug_level 3 63613 NULL
120278 +__spi_validate_63618 __spi_validate 0 63618 NULL
120279 +symbol_build_supp_rates_63634 symbol_build_supp_rates 0 63634 NULL
120280 +hid_report_len_63637 hid_report_len 0 63637 NULL
120281 +proc_loginuid_write_63648 proc_loginuid_write 3 63648 NULL
120282 +ValidateDSDParamsChecksum_63654 ValidateDSDParamsChecksum 3 63654 NULL
120283 +ldlm_cli_enqueue_63657 ldlm_cli_enqueue 8 63657 NULL
120284 +hidraw_ioctl_63658 hidraw_ioctl 2 63658 NULL
120285 +vbi_read_63673 vbi_read 3 63673 NULL
120286 +write_file_spectral_fft_period_63696 write_file_spectral_fft_period 3 63696 NULL
120287 +nouveau_object_create__63715 nouveau_object_create_ 5 63715 NULL
120288 +btrfs_insert_delayed_dir_index_63720 btrfs_insert_delayed_dir_index 4 63720 NULL
120289 +selinux_secctx_to_secid_63744 selinux_secctx_to_secid 2 63744 NULL
120290 +snd_pcm_oss_read1_63771 snd_pcm_oss_read1 3 63771 NULL
120291 +snd_pcm_link_63772 snd_pcm_link 0 63772 NULL
120292 +snd_opl4_mem_proc_read_63774 snd_opl4_mem_proc_read 5 63774 NULL
120293 +spidev_compat_ioctl_63778 spidev_compat_ioctl 2 63778 NULL
120294 +mwifiex_11n_create_rx_reorder_tbl_63806 mwifiex_11n_create_rx_reorder_tbl 4 63806 NULL
120295 +copy_nodes_to_user_63807 copy_nodes_to_user 2 63807 NULL
120296 +C_SYSC_process_vm_readv_63811 C_SYSC_process_vm_readv 3-5 63811 NULL
120297 +regmap_multi_reg_write_63826 regmap_multi_reg_write 3 63826 NULL
120298 +sel_write_load_63830 sel_write_load 3 63830 NULL
120299 +proc_pid_attr_write_63845 proc_pid_attr_write 3 63845 NULL
120300 +xhci_alloc_stream_info_63902 xhci_alloc_stream_info 3 63902 NULL
120301 +uvc_alloc_urb_buffers_63922 uvc_alloc_urb_buffers 0-2-3 63922 NULL
120302 +snd_compr_write_63923 snd_compr_write 3 63923 NULL
120303 +afs_send_simple_reply_63940 afs_send_simple_reply 3 63940 NULL
120304 +__team_options_register_63941 __team_options_register 3 63941 NULL
120305 +macvtap_recvmsg_63949 macvtap_recvmsg 4 63949 NULL
120306 +set_bredr_63975 set_bredr 4 63975 NULL
120307 +construct_key_and_link_63985 construct_key_and_link 3 63985 NULL
120308 +rs_extent_to_bm_page_63996 rs_extent_to_bm_page 0-1 63996 NULL
120309 +read_file_frameerrors_64001 read_file_frameerrors 3 64001 NULL
120310 +SyS_rt_sigpending_64018 SyS_rt_sigpending 2 64018 NULL
120311 +dbAllocDmapLev_64030 dbAllocDmapLev 0 64030 NULL
120312 +SyS_fsetxattr_64039 SyS_fsetxattr 4 64039 NULL
120313 +get_u8_64076 get_u8 0 64076 NULL
120314 +xilly_malloc_64077 xilly_malloc 2 64077 NULL
120315 +sl_realloc_bufs_64086 sl_realloc_bufs 2 64086 NULL
120316 +vmci_handle_arr_get_size_64088 vmci_handle_arr_get_size 0 64088 NULL
120317 +lbs_highrssi_read_64089 lbs_highrssi_read 3 64089 NULL
120318 +SyS_set_mempolicy_64096 SyS_set_mempolicy 3 64096 NULL
120319 +to_bytes_64103 to_bytes 0-1 64103 NULL
120320 +SyS_mq_timedsend_64107 SyS_mq_timedsend 3 64107 NULL
120321 +rdma_addr_size_64116 rdma_addr_size 0 64116 NULL
120322 +do_load_xattr_datum_64118 do_load_xattr_datum 0 64118 NULL
120323 +bypass_wd_write_64120 bypass_wd_write 3 64120 NULL
120324 +ext4_prepare_inline_data_64124 ext4_prepare_inline_data 3 64124 NULL
120325 +init_bch_64130 init_bch 1-2 64130 NULL
120326 +ablkcipher_copy_iv_64140 ablkcipher_copy_iv 3 64140 NULL
120327 +dlfb_ops_write_64150 dlfb_ops_write 3 64150 NULL
120328 +bnx2x_vf_mcast_64166 bnx2x_vf_mcast 4 64166 NULL
120329 +cpumask_scnprintf_64170 cpumask_scnprintf 0-2 64170 NULL
120330 +kernfs_iop_setxattr_64220 kernfs_iop_setxattr 4 64220 NULL
120331 +xfs_vm_direct_IO_64223 xfs_vm_direct_IO 4 64223 NULL
120332 +read_pulse_64227 read_pulse 0-3 64227 NULL
120333 +ea_len_64229 ea_len 0 64229 NULL
120334 +io_capture_transfer_64276 io_capture_transfer 4 64276 NULL
120335 +btrfs_file_extent_offset_64278 btrfs_file_extent_offset 0 64278 NULL
120336 +sta_current_tx_rate_read_64286 sta_current_tx_rate_read 3 64286 NULL
120337 +xfs_dir_cilookup_result_64288 xfs_dir_cilookup_result 3 64288 NULL nohasharray
120338 +event_id_read_64288 event_id_read 3 64288 &xfs_dir_cilookup_result_64288
120339 +ocfs2_block_check_validate_bhs_64302 ocfs2_block_check_validate_bhs 0 64302 NULL
120340 +snd_hda_get_sub_nodes_64304 snd_hda_get_sub_nodes 0 64304 NULL
120341 +error_error_bar_retry_read_64305 error_error_bar_retry_read 3 64305 NULL
120342 +sisusbcon_clear_64329 sisusbcon_clear 4-3-5 64329 NULL
120343 +ts_write_64336 ts_write 3 64336 NULL
120344 +usbtmc_write_64340 usbtmc_write 3 64340 NULL
120345 +qlcnic_82xx_calculate_msix_vector_64354 qlcnic_82xx_calculate_msix_vector 0 64354 NULL
120346 +user_regset_copyin_64360 user_regset_copyin 7 64360 NULL
120347 +wlc_phy_loadsampletable_nphy_64367 wlc_phy_loadsampletable_nphy 3 64367 NULL
120348 +reg_create_64372 reg_create 5 64372 NULL nohasharray
120349 +bnx2_enable_msix_64372 bnx2_enable_msix 2 64372 &reg_create_64372
120350 +ilo_write_64378 ilo_write 3 64378 NULL
120351 +btrfs_map_block_64379 btrfs_map_block 3 64379 NULL
120352 +vmcs_readl_64381 vmcs_readl 0 64381 NULL
120353 +nilfs_alloc_seg_bio_64383 nilfs_alloc_seg_bio 3 64383 NULL
120354 +ir_lirc_transmit_ir_64403 ir_lirc_transmit_ir 3 64403 NULL
120355 +pidlist_allocate_64404 pidlist_allocate 1 64404 NULL
120356 +rx_hdr_overflow_read_64407 rx_hdr_overflow_read 3 64407 NULL
120357 +keyctl_get_security_64418 keyctl_get_security 3 64418 NULL
120358 +oom_adj_write_64428 oom_adj_write 3 64428 NULL
120359 +read_file_spectral_short_repeat_64431 read_file_spectral_short_repeat 3 64431 NULL
120360 +ax25_recvmsg_64441 ax25_recvmsg 4 64441 NULL
120361 +__i2c_add_numbered_adapter_64445 __i2c_add_numbered_adapter 0 64445 NULL
120362 +single_open_size_64483 single_open_size 4 64483 NULL
120363 +p54_parse_rssical_64493 p54_parse_rssical 3 64493 NULL
120364 +msg_data_sz_64503 msg_data_sz 0 64503 NULL
120365 +remove_uuid_64505 remove_uuid 4 64505 NULL
120366 +opera1_usb_i2c_msgxfer_64521 opera1_usb_i2c_msgxfer 4 64521 NULL
120367 +iwl_dbgfs_ucode_tracing_write_64524 iwl_dbgfs_ucode_tracing_write 3 64524 NULL
120368 +ses_send_diag_64527 ses_send_diag 4 64527 NULL
120369 +prctl_set_mm_64538 prctl_set_mm 3 64538 NULL
120370 +SyS_bind_64544 SyS_bind 3 64544 NULL
120371 +rbd_obj_read_sync_64554 rbd_obj_read_sync 3-4 64554 NULL
120372 +__btrfs_prealloc_file_range_64557 __btrfs_prealloc_file_range 3 64557 NULL
120373 +ll_max_rw_chunk_seq_write_64561 ll_max_rw_chunk_seq_write 3 64561 NULL nohasharray
120374 +__spi_sync_64561 __spi_sync 0 64561 &ll_max_rw_chunk_seq_write_64561
120375 +__apei_exec_run_64563 __apei_exec_run 0 64563 NULL
120376 +kstrtoul_from_user_64569 kstrtoul_from_user 2 64569 NULL
120377 +do_erase_64574 do_erase 4 64574 NULL
120378 +fanotify_write_64623 fanotify_write 3 64623 NULL
120379 +_iwl_dbgfs_d0i3_refs_write_64642 _iwl_dbgfs_d0i3_refs_write 3 64642 NULL
120380 +regmap_read_debugfs_64658 regmap_read_debugfs 5 64658 NULL
120381 +tlbflush_read_file_64661 tlbflush_read_file 3 64661 NULL nohasharray
120382 +ocfs2_read_xattr_block_64661 ocfs2_read_xattr_block 0 64661 &tlbflush_read_file_64661
120383 +efx_tsoh_get_buffer_64664 efx_tsoh_get_buffer 3 64664 NULL
120384 +rx_rx_out_of_mpdu_nodes_read_64668 rx_rx_out_of_mpdu_nodes_read 3 64668 NULL
120385 +nr_free_zone_pages_64680 nr_free_zone_pages 0 64680 NULL
120386 +snd_pcm_oss_capture_position_fixup_64713 snd_pcm_oss_capture_position_fixup 0 64713 NULL
120387 +dapm_bias_read_file_64715 dapm_bias_read_file 3 64715 NULL
120388 +atomic_add_return_64720 atomic_add_return 0-1 64720 NULL
120389 +i2400m_msg_to_dev_64722 i2400m_msg_to_dev 3 64722 NULL
120390 +squashfs_read_inode_lookup_table_64739 squashfs_read_inode_lookup_table 4 64739 NULL
120391 +bio_map_kern_64751 bio_map_kern 3 64751 NULL
120392 +rt2x00debug_write_csr_64753 rt2x00debug_write_csr 3 64753 NULL
120393 +message_for_md_64777 message_for_md 5 64777 NULL
120394 +isr_low_rssi_read_64789 isr_low_rssi_read 3 64789 NULL
120395 +regmap_reg_ranges_read_file_64798 regmap_reg_ranges_read_file 3 64798 NULL
120396 +nfsctl_transaction_write_64800 nfsctl_transaction_write 3 64800 NULL
120397 +rfkill_fop_write_64808 rfkill_fop_write 3 64808 NULL
120398 +proc_projid_map_write_64810 proc_projid_map_write 3 64810 NULL
120399 +megaraid_change_queue_depth_64815 megaraid_change_queue_depth 2 64815 NULL
120400 +ecryptfs_send_miscdev_64816 ecryptfs_send_miscdev 2 64816 NULL
120401 +do_kimage_alloc_64827 do_kimage_alloc 3 64827 NULL
120402 +altera_set_dr_pre_64862 altera_set_dr_pre 2 64862 NULL
120403 +pci_vc_do_save_buffer_64876 pci_vc_do_save_buffer 0 64876 NULL
120404 +lprocfs_write_u64_helper_64880 lprocfs_write_u64_helper 2 64880 NULL
120405 +ieee80211_if_read_ave_beacon_64924 ieee80211_if_read_ave_beacon 3 64924 NULL
120406 +ip_options_get_from_user_64958 ip_options_get_from_user 4 64958 NULL nohasharray
120407 +tipc_port_iovec_reject_64958 tipc_port_iovec_reject 4 64958 &ip_options_get_from_user_64958
120408 +traceprobe_probes_write_64969 traceprobe_probes_write 3 64969 NULL
120409 +suspend_dtim_interval_read_64971 suspend_dtim_interval_read 3 64971 NULL
120410 +crypto_ahash_digestsize_65014 crypto_ahash_digestsize 0 65014 NULL
120411 +insert_dent_65034 insert_dent 7 65034 NULL
120412 +snd_hda_get_pin_label_65035 snd_hda_get_pin_label 5 65035 NULL
120413 +ext4_ind_trans_blocks_65053 ext4_ind_trans_blocks 0-2 65053 NULL
120414 +pcibios_enable_device_65059 pcibios_enable_device 0 65059 NULL
120415 +make_idx_node_65068 make_idx_node 0 65068 NULL
120416 +__alloc_bootmem_node_high_65076 __alloc_bootmem_node_high 2 65076 NULL
120417 +batadv_socket_write_65083 batadv_socket_write 3 65083 NULL
120418 +ocfs2_truncate_cluster_pages_65086 ocfs2_truncate_cluster_pages 2 65086 NULL
120419 +ath9k_dump_mci_btcoex_65090 ath9k_dump_mci_btcoex 3-0 65090 NULL
120420 +scsi_add_host_with_dma_65093 scsi_add_host_with_dma 0 65093 NULL
120421 +generic_ocp_write_65107 generic_ocp_write 4 65107 NULL
120422 +rx_rx_done_read_65217 rx_rx_done_read 3 65217 NULL
120423 +print_endpoint_stat_65232 print_endpoint_stat 0-3-4 65232 NULL
120424 +whci_n_caps_65247 whci_n_caps 0 65247 NULL
120425 +kmalloc_parameter_65279 kmalloc_parameter 1 65279 NULL
120426 +compat_core_sys_select_65285 compat_core_sys_select 1 65285 NULL
120427 +mpi_set_buffer_65294 mpi_set_buffer 3 65294 NULL
120428 +redirected_tty_write_65297 redirected_tty_write 3 65297 NULL
120429 +get_var_len_65304 get_var_len 0 65304 NULL
120430 +unpack_array_65318 unpack_array 0 65318 NULL
120431 +pci_vpd_find_tag_65325 pci_vpd_find_tag 0-2 65325 NULL
120432 +dccp_setsockopt_service_65336 dccp_setsockopt_service 4 65336 NULL
120433 +dma_rx_requested_read_65354 dma_rx_requested_read 3 65354 NULL
120434 +alloc_cpu_rmap_65363 alloc_cpu_rmap 1 65363 NULL
120435 +SyS_writev_65372 SyS_writev 3 65372 NULL
120436 +__alloc_bootmem_nopanic_65397 __alloc_bootmem_nopanic 1 65397 NULL
120437 +trace_seq_to_user_65398 trace_seq_to_user 3 65398 NULL
120438 +__read_vmcore_65402 __read_vmcore 2 65402 NULL
120439 +ocfs2_write_begin_nolock_65410 ocfs2_write_begin_nolock 3-4 65410 NULL
120440 +device_add_groups_65423 device_add_groups 0 65423 NULL
120441 +xpc_kzalloc_cacheline_aligned_65433 xpc_kzalloc_cacheline_aligned 1 65433 NULL
120442 +usb_alloc_coherent_65444 usb_alloc_coherent 2 65444 NULL
120443 +il_dbgfs_wd_timeout_write_65464 il_dbgfs_wd_timeout_write 3 65464 NULL
120444 +clear_user_65470 clear_user 2 65470 NULL
120445 +dpcm_state_read_file_65489 dpcm_state_read_file 3 65489 NULL
120446 +lookup_inline_extent_backref_65493 lookup_inline_extent_backref 9 65493 NULL
120447 +nvme_trans_standard_inquiry_page_65526 nvme_trans_standard_inquiry_page 4 65526 NULL
120448 +tree_mod_log_eb_copy_65535 tree_mod_log_eb_copy 6 65535 NULL
120449 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data b/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data
120450 new file mode 100644
120451 index 0000000..560cd7b
120452 --- /dev/null
120453 +++ b/tools/gcc/size_overflow_plugin/size_overflow_hash_aux.data
120454 @@ -0,0 +1,92 @@
120455 +spa_set_aux_vdevs_746 spa_set_aux_vdevs 3 746 NULL
120456 +zfs_lookup_2144 zfs_lookup 0 2144 NULL
120457 +mappedread_2627 mappedread 2 2627 NULL
120458 +vdev_disk_dio_alloc_2957 vdev_disk_dio_alloc 1 2957 NULL
120459 +nv_alloc_pushpage_spl_4286 nv_alloc_pushpage_spl 2 4286 NULL
120460 +zpl_xattr_get_4574 zpl_xattr_get 0 4574 NULL
120461 +sa_replace_all_by_template_5699 sa_replace_all_by_template 3 5699 NULL
120462 +dmu_write_6048 dmu_write 4-3 6048 NULL
120463 +dmu_buf_hold_array_6095 dmu_buf_hold_array 4-3 6095 NULL
120464 +update_pages_6225 update_pages 2-3 6225 NULL
120465 +bio_nr_pages_7117 bio_nr_pages 0-2 7117 NULL
120466 +dmu_buf_hold_array_by_bonus_8562 dmu_buf_hold_array_by_bonus 3-2 8562 NULL
120467 +zpios_dmu_write_8858 zpios_dmu_write 4-5 8858 NULL
120468 +ddi_copyout_9401 ddi_copyout 3 9401 NULL
120469 +avl_numnodes_12384 avl_numnodes 0 12384 NULL
120470 +dmu_write_uio_dnode_12473 dmu_write_uio_dnode 3 12473 NULL
120471 +dmu_xuio_init_12866 dmu_xuio_init 2 12866 NULL
120472 +zpl_read_common_14389 zpl_read_common 0 14389 NULL
120473 +dmu_snapshot_realname_14632 dmu_snapshot_realname 4 14632 NULL
120474 +kmem_alloc_debug_14852 kmem_alloc_debug 1 14852 NULL
120475 +kmalloc_node_nofail_15151 kmalloc_node_nofail 1 15151 NULL
120476 +dmu_write_uio_16351 dmu_write_uio 4 16351 NULL
120477 +zfs_log_write_16524 zfs_log_write 6-5 16524 NULL
120478 +sa_build_layouts_16910 sa_build_layouts 3 16910 NULL
120479 +dsl_dir_namelen_17053 dsl_dir_namelen 0 17053 NULL
120480 +kcopy_copy_to_user_17336 kcopy_copy_to_user 5 17336 NULL
120481 +sa_add_layout_entry_17507 sa_add_layout_entry 3 17507 NULL
120482 +sa_attr_table_setup_18029 sa_attr_table_setup 3 18029 NULL
120483 +uiocopy_18680 uiocopy 2 18680 NULL
120484 +dmu_buf_hold_array_by_dnode_19125 dmu_buf_hold_array_by_dnode 2-3 19125 NULL
120485 +zpl_acl_from_xattr_21141 zpl_acl_from_xattr 2 21141 NULL
120486 +dsl_pool_tx_assign_init_22518 dsl_pool_tx_assign_init 2 22518 NULL
120487 +nvlist_lookup_byte_array_22527 nvlist_lookup_byte_array 0 22527 NULL
120488 +sa_replace_all_by_template_locked_22533 sa_replace_all_by_template_locked 3 22533 NULL
120489 +tsd_hash_table_init_22559 tsd_hash_table_init 1 22559 NULL
120490 +spa_vdev_remove_aux_23966 spa_vdev_remove_aux 4 23966 NULL
120491 +zpl_xattr_acl_set_access_24129 zpl_xattr_acl_set_access 4 24129 NULL
120492 +dmu_assign_arcbuf_24622 dmu_assign_arcbuf 2 24622 NULL
120493 +zap_lookup_norm_25166 zap_lookup_norm 9 25166 NULL
120494 +dmu_prealloc_25456 dmu_prealloc 4-3 25456 NULL
120495 +kmalloc_nofail_26347 kmalloc_nofail 1 26347 NULL
120496 +zfsctl_snapshot_zpath_27578 zfsctl_snapshot_zpath 2 27578 NULL
120497 +zpios_dmu_read_30015 zpios_dmu_read 4-5 30015 NULL
120498 +splat_write_30943 splat_write 3 30943 NULL
120499 +zpl_xattr_get_sa_31183 zpl_xattr_get_sa 0 31183 NULL
120500 +dmu_read_uio_31467 dmu_read_uio 4 31467 NULL
120501 +zfs_replay_fuids_31479 zfs_replay_fuids 4 31479 NULL
120502 +spa_history_log_to_phys_31632 spa_history_log_to_phys 0-1 31632 NULL
120503 +__zpl_xattr_get_32601 __zpl_xattr_get 0 32601 NULL
120504 +proc_copyout_string_34049 proc_copyout_string 2 34049 NULL
120505 +nv_alloc_sleep_spl_34544 nv_alloc_sleep_spl 2 34544 NULL
120506 +nv_alloc_nosleep_spl_34761 nv_alloc_nosleep_spl 2 34761 NULL
120507 +zap_leaf_array_match_36922 zap_leaf_array_match 4 36922 NULL
120508 +copyinstr_36980 copyinstr 3 36980 NULL
120509 +zpl_xattr_acl_set_default_37864 zpl_xattr_acl_set_default 4 37864 NULL
120510 +splat_read_38116 splat_read 3 38116 NULL
120511 +sa_setup_38756 sa_setup 4 38756 NULL
120512 +vdev_disk_physio_39898 vdev_disk_physio 3 39898 NULL
120513 +arc_buf_size_39982 arc_buf_size 0 39982 NULL
120514 +kzalloc_nofail_40719 kzalloc_nofail 1 40719 NULL
120515 +fuidstr_to_sid_40777 fuidstr_to_sid 4 40777 NULL
120516 +vdev_raidz_matrix_reconstruct_40852 vdev_raidz_matrix_reconstruct 2-3 40852 NULL
120517 +sa_find_layout_40892 sa_find_layout 4 40892 NULL
120518 +zpl_xattr_get_dir_41918 zpl_xattr_get_dir 0 41918 NULL
120519 +zfs_sa_get_xattr_42600 zfs_sa_get_xattr 0 42600 NULL
120520 +zpl_xattr_acl_set_42808 zpl_xattr_acl_set 4 42808 NULL
120521 +xdr_dec_array_43091 xdr_dec_array 5 43091 NULL
120522 +dsl_dataset_namelen_43136 dsl_dataset_namelen 0 43136 NULL
120523 +kcopy_write_43683 kcopy_write 3 43683 NULL
120524 +uiomove_44355 uiomove 2 44355 NULL
120525 +dmu_read_44418 dmu_read 4-3 44418 NULL
120526 +ddi_copyin_44846 ddi_copyin 3 44846 NULL
120527 +kcopy_do_get_45061 kcopy_do_get 5 45061 NULL
120528 +copyin_45945 copyin 3 45945 NULL
120529 +zil_itx_create_46555 zil_itx_create 2 46555 NULL
120530 +dmu_write_uio_dbuf_48064 dmu_write_uio_dbuf 3 48064 NULL
120531 +blk_rq_pos_48233 blk_rq_pos 0 48233 NULL
120532 +spa_history_write_49650 spa_history_write 3 49650 NULL
120533 +kcopy_copy_pages_to_user_49823 kcopy_copy_pages_to_user 3-4 49823 NULL
120534 +zfs_log_write_50162 zfs_log_write 6-5 50162 NULL
120535 +i_fm_alloc_51038 i_fm_alloc 2 51038 NULL
120536 +copyout_51409 copyout 3 51409 NULL
120537 +zvol_log_write_54898 zvol_log_write 4-3 54898 NULL
120538 +zfs_acl_node_alloc_55641 zfs_acl_node_alloc 1 55641 NULL
120539 +get_nvlist_56685 get_nvlist 2 56685 NULL
120540 +zprop_get_numprops_56820 zprop_get_numprops 0 56820 NULL
120541 +splat_taskq_test4_common_59829 splat_taskq_test4_common 5 59829 NULL
120542 +zfs_replay_domain_cnt_61399 zfs_replay_domain_cnt 0 61399 NULL
120543 +zpios_write_61823 zpios_write 3 61823 NULL
120544 +proc_copyin_string_62019 proc_copyin_string 4 62019 NULL
120545 +random_get_pseudo_bytes_64611 random_get_pseudo_bytes 2 64611 NULL
120546 +zpios_read_64734 zpios_read 3 64734 NULL
120547 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin/size_overflow_plugin.c
120548 new file mode 100644
120549 index 0000000..e6fe17b
120550 --- /dev/null
120551 +++ b/tools/gcc/size_overflow_plugin/size_overflow_plugin.c
120552 @@ -0,0 +1,259 @@
120553 +/*
120554 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
120555 + * Licensed under the GPL v2, or (at your option) v3
120556 + *
120557 + * Homepage:
120558 + * http://www.grsecurity.net/~ephox/overflow_plugin/
120559 + *
120560 + * Documentation:
120561 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
120562 + *
120563 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
120564 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
120565 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
120566 + *
120567 + * Usage:
120568 + * $ make
120569 + * $ make run
120570 + */
120571 +
120572 +#include "gcc-common.h"
120573 +#include "size_overflow.h"
120574 +
120575 +int plugin_is_GPL_compatible;
120576 +
120577 +tree report_size_overflow_decl;
120578 +
120579 +tree size_overflow_type_HI;
120580 +tree size_overflow_type_SI;
120581 +tree size_overflow_type_DI;
120582 +tree size_overflow_type_TI;
120583 +
120584 +static struct plugin_info size_overflow_plugin_info = {
120585 + .version = "20140517",
120586 + .help = "no-size-overflow\tturn off size overflow checking\n",
120587 +};
120588 +
120589 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
120590 +{
120591 + unsigned int arg_count;
120592 + enum tree_code code = TREE_CODE(*node);
120593 +
120594 + switch (code) {
120595 + case FUNCTION_DECL:
120596 + arg_count = type_num_arguments(TREE_TYPE(*node));
120597 + break;
120598 + case FUNCTION_TYPE:
120599 + case METHOD_TYPE:
120600 + arg_count = type_num_arguments(*node);
120601 + break;
120602 + default:
120603 + *no_add_attrs = true;
120604 + error("%s: %qE attribute only applies to functions", __func__, name);
120605 + return NULL_TREE;
120606 + }
120607 +
120608 + for (; args; args = TREE_CHAIN(args)) {
120609 + tree position = TREE_VALUE(args);
120610 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
120611 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
120612 + *no_add_attrs = true;
120613 + }
120614 + }
120615 + return NULL_TREE;
120616 +}
120617 +
120618 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
120619 +{
120620 + unsigned int arg_count;
120621 + enum tree_code code = TREE_CODE(*node);
120622 +
120623 + switch (code) {
120624 + case FUNCTION_DECL:
120625 + arg_count = type_num_arguments(TREE_TYPE(*node));
120626 + break;
120627 + case FUNCTION_TYPE:
120628 + case METHOD_TYPE:
120629 + arg_count = type_num_arguments(*node);
120630 + break;
120631 + case FIELD_DECL:
120632 + return NULL_TREE;
120633 + default:
120634 + *no_add_attrs = true;
120635 + error("%qE attribute only applies to functions", name);
120636 + return NULL_TREE;
120637 + }
120638 +
120639 + if (TREE_INT_CST_HIGH(TREE_VALUE(args)) != 0)
120640 + return NULL_TREE;
120641 +
120642 + for (; args; args = TREE_CHAIN(args)) {
120643 + tree position = TREE_VALUE(args);
120644 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
120645 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
120646 + *no_add_attrs = true;
120647 + }
120648 + }
120649 + return NULL_TREE;
120650 +}
120651 +
120652 +static struct attribute_spec size_overflow_attr = {
120653 + .name = "size_overflow",
120654 + .min_length = 1,
120655 + .max_length = -1,
120656 + .decl_required = true,
120657 + .type_required = false,
120658 + .function_type_required = false,
120659 + .handler = handle_size_overflow_attribute,
120660 +#if BUILDING_GCC_VERSION >= 4007
120661 + .affects_type_identity = false
120662 +#endif
120663 +};
120664 +
120665 +static struct attribute_spec intentional_overflow_attr = {
120666 + .name = "intentional_overflow",
120667 + .min_length = 1,
120668 + .max_length = -1,
120669 + .decl_required = true,
120670 + .type_required = false,
120671 + .function_type_required = false,
120672 + .handler = handle_intentional_overflow_attribute,
120673 +#if BUILDING_GCC_VERSION >= 4007
120674 + .affects_type_identity = false
120675 +#endif
120676 +};
120677 +
120678 +static void register_attributes(void __unused *event_data, void __unused *data)
120679 +{
120680 + register_attribute(&size_overflow_attr);
120681 + register_attribute(&intentional_overflow_attr);
120682 +}
120683 +
120684 +static tree create_typedef(tree type, const char* ident)
120685 +{
120686 + tree new_type, decl;
120687 +
120688 + new_type = build_variant_type_copy(type);
120689 + decl = build_decl(BUILTINS_LOCATION, TYPE_DECL, get_identifier(ident), new_type);
120690 + DECL_ORIGINAL_TYPE(decl) = type;
120691 + TYPE_NAME(new_type) = decl;
120692 + return new_type;
120693 +}
120694 +
120695 +// Create the noreturn report_size_overflow() function decl.
120696 +static void size_overflow_start_unit(void __unused *gcc_data, void __unused *user_data)
120697 +{
120698 + tree const_char_ptr_type_node;
120699 + tree fntype;
120700 +
120701 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
120702 +
120703 + size_overflow_type_HI = create_typedef(intHI_type_node, "size_overflow_type_HI");
120704 + size_overflow_type_SI = create_typedef(intSI_type_node, "size_overflow_type_SI");
120705 + size_overflow_type_DI = create_typedef(intDI_type_node, "size_overflow_type_DI");
120706 + size_overflow_type_TI = create_typedef(intTI_type_node, "size_overflow_type_TI");
120707 +
120708 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
120709 + fntype = build_function_type_list(void_type_node,
120710 + const_char_ptr_type_node,
120711 + unsigned_type_node,
120712 + const_char_ptr_type_node,
120713 + const_char_ptr_type_node,
120714 + NULL_TREE);
120715 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
120716 +
120717 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
120718 + TREE_PUBLIC(report_size_overflow_decl) = 1;
120719 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
120720 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
120721 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
120722 +}
120723 +
120724 +
120725 +extern struct gimple_opt_pass pass_dce;
120726 +
120727 +static struct opt_pass *make_dce_pass(void)
120728 +{
120729 +#if BUILDING_GCC_VERSION >= 4009
120730 + return make_pass_dce(g);
120731 +#else
120732 + return &pass_dce.pass;
120733 +#endif
120734 +}
120735 +
120736 +
120737 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
120738 +{
120739 + int i;
120740 + const char * const plugin_name = plugin_info->base_name;
120741 + const int argc = plugin_info->argc;
120742 + const struct plugin_argument * const argv = plugin_info->argv;
120743 + bool enable = true;
120744 + struct register_pass_info insert_size_overflow_asm_pass_info;
120745 + struct register_pass_info __unused dump_before_pass_info;
120746 + struct register_pass_info __unused dump_after_pass_info;
120747 + struct register_pass_info insert_size_overflow_check_info;
120748 + struct register_pass_info dce_pass_info;
120749 + static const struct ggc_root_tab gt_ggc_r_gt_size_overflow[] = {
120750 + {
120751 + .base = &report_size_overflow_decl,
120752 + .nelt = 1,
120753 + .stride = sizeof(report_size_overflow_decl),
120754 + .cb = &gt_ggc_mx_tree_node,
120755 + .pchw = &gt_pch_nx_tree_node
120756 + },
120757 + LAST_GGC_ROOT_TAB
120758 + };
120759 +
120760 + insert_size_overflow_asm_pass_info.pass = make_insert_size_overflow_asm_pass();
120761 + insert_size_overflow_asm_pass_info.reference_pass_name = "ssa";
120762 + insert_size_overflow_asm_pass_info.ref_pass_instance_number = 1;
120763 + insert_size_overflow_asm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
120764 +
120765 + dump_before_pass_info.pass = make_dump_pass();
120766 + dump_before_pass_info.reference_pass_name = "increase_alignment";
120767 + dump_before_pass_info.ref_pass_instance_number = 1;
120768 + dump_before_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
120769 +
120770 + insert_size_overflow_check_info.pass = make_insert_size_overflow_check();
120771 + insert_size_overflow_check_info.reference_pass_name = "increase_alignment";
120772 + insert_size_overflow_check_info.ref_pass_instance_number = 1;
120773 + insert_size_overflow_check_info.pos_op = PASS_POS_INSERT_BEFORE;
120774 +
120775 + dump_after_pass_info.pass = make_dump_pass();
120776 + dump_after_pass_info.reference_pass_name = "increase_alignment";
120777 + dump_after_pass_info.ref_pass_instance_number = 1;
120778 + dump_after_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
120779 +
120780 + dce_pass_info.pass = make_dce_pass();
120781 + dce_pass_info.reference_pass_name = "vrp";
120782 + dce_pass_info.ref_pass_instance_number = 1;
120783 + dce_pass_info.pos_op = PASS_POS_INSERT_AFTER;
120784 +
120785 + if (!plugin_default_version_check(version, &gcc_version)) {
120786 + error(G_("incompatible gcc/plugin versions"));
120787 + return 1;
120788 + }
120789 +
120790 + for (i = 0; i < argc; ++i) {
120791 + if (!strcmp(argv[i].key, "no-size-overflow")) {
120792 + enable = false;
120793 + continue;
120794 + }
120795 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
120796 + }
120797 +
120798 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
120799 + if (enable) {
120800 + register_callback(plugin_name, PLUGIN_START_UNIT, &size_overflow_start_unit, NULL);
120801 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_size_overflow);
120802 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &insert_size_overflow_asm_pass_info);
120803 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_before_pass_info);
120804 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &insert_size_overflow_check_info);
120805 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_after_pass_info);
120806 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dce_pass_info);
120807 + }
120808 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
120809 +
120810 + return 0;
120811 +}
120812 diff --git a/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c b/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c
120813 new file mode 100644
120814 index 0000000..0888f6c
120815 --- /dev/null
120816 +++ b/tools/gcc/size_overflow_plugin/size_overflow_plugin_hash.c
120817 @@ -0,0 +1,364 @@
120818 +/*
120819 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
120820 + * Licensed under the GPL v2, or (at your option) v3
120821 + *
120822 + * Homepage:
120823 + * http://www.grsecurity.net/~ephox/overflow_plugin/
120824 + *
120825 + * Documentation:
120826 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
120827 + *
120828 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
120829 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
120830 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
120831 + *
120832 + * Usage:
120833 + * $ make
120834 + * $ make run
120835 + */
120836 +
120837 +#include "gcc-common.h"
120838 +#include "size_overflow.h"
120839 +
120840 +#include "size_overflow_hash.h"
120841 +#include "size_overflow_hash_aux.h"
120842 +
120843 +#define CODES_LIMIT 32
120844 +
120845 +static unsigned char get_tree_code(const_tree type)
120846 +{
120847 + switch (TREE_CODE(type)) {
120848 + case ARRAY_TYPE:
120849 + return 0;
120850 + case BOOLEAN_TYPE:
120851 + return 1;
120852 + case ENUMERAL_TYPE:
120853 + return 2;
120854 + case FUNCTION_TYPE:
120855 + return 3;
120856 + case INTEGER_TYPE:
120857 + return 4;
120858 + case POINTER_TYPE:
120859 + return 5;
120860 + case RECORD_TYPE:
120861 + return 6;
120862 + case UNION_TYPE:
120863 + return 7;
120864 + case VOID_TYPE:
120865 + return 8;
120866 + case REAL_TYPE:
120867 + return 9;
120868 + case VECTOR_TYPE:
120869 + return 10;
120870 + case REFERENCE_TYPE:
120871 + return 11;
120872 + case OFFSET_TYPE:
120873 + return 12;
120874 + case COMPLEX_TYPE:
120875 + return 13;
120876 + default:
120877 + debug_tree((tree)type);
120878 + gcc_unreachable();
120879 + }
120880 +}
120881 +
120882 +struct function_hash {
120883 + size_t tree_codes_len;
120884 + unsigned char tree_codes[CODES_LIMIT];
120885 + const_tree fndecl;
120886 + unsigned int hash;
120887 +};
120888 +
120889 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
120890 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
120891 +{
120892 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
120893 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
120894 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
120895 +
120896 + unsigned int m = 0x57559429;
120897 + unsigned int n = 0x5052acdb;
120898 + const unsigned int *key4 = (const unsigned int *)key;
120899 + unsigned int h = len;
120900 + unsigned int k = len + seed + n;
120901 + unsigned long long p;
120902 +
120903 + while (len >= 8) {
120904 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
120905 + len -= 8;
120906 + }
120907 + if (len >= 4) {
120908 + cwmixb(key4[0]) key4 += 1;
120909 + len -= 4;
120910 + }
120911 + if (len)
120912 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
120913 + cwmixb(h ^ (k + n));
120914 + return k ^ h;
120915 +
120916 +#undef cwfold
120917 +#undef cwmixa
120918 +#undef cwmixb
120919 +}
120920 +
120921 +static void set_hash(const char *fn_name, struct function_hash *fn_hash_data)
120922 +{
120923 + unsigned int fn, codes, seed = 0;
120924 +
120925 + fn = CrapWow(fn_name, strlen(fn_name), seed) & 0xffff;
120926 + codes = CrapWow((const char*)fn_hash_data->tree_codes, fn_hash_data->tree_codes_len, seed) & 0xffff;
120927 +
120928 + fn_hash_data->hash = fn ^ codes;
120929 +}
120930 +
120931 +static void set_node_codes(const_tree type, struct function_hash *fn_hash_data)
120932 +{
120933 + gcc_assert(type != NULL_TREE);
120934 + gcc_assert(TREE_CODE_CLASS(TREE_CODE(type)) == tcc_type);
120935 +
120936 + while (type && fn_hash_data->tree_codes_len < CODES_LIMIT) {
120937 + fn_hash_data->tree_codes[fn_hash_data->tree_codes_len] = get_tree_code(type);
120938 + fn_hash_data->tree_codes_len++;
120939 + type = TREE_TYPE(type);
120940 + }
120941 +}
120942 +
120943 +static void set_result_codes(const_tree node, struct function_hash *fn_hash_data)
120944 +{
120945 + const_tree result;
120946 +
120947 + gcc_assert(node != NULL_TREE);
120948 +
120949 + if (DECL_P(node)) {
120950 + result = DECL_RESULT(node);
120951 + if (result != NULL_TREE)
120952 + return set_node_codes(TREE_TYPE(result), fn_hash_data);
120953 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
120954 + }
120955 +
120956 + gcc_assert(TYPE_P(node));
120957 +
120958 + if (TREE_CODE(node) == FUNCTION_TYPE)
120959 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
120960 +
120961 + return set_node_codes(node, fn_hash_data);
120962 +}
120963 +
120964 +static void set_function_codes(struct function_hash *fn_hash_data)
120965 +{
120966 + const_tree arg, type = TREE_TYPE(fn_hash_data->fndecl);
120967 + enum tree_code code = TREE_CODE(type);
120968 +
120969 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
120970 +
120971 + set_result_codes(fn_hash_data->fndecl, fn_hash_data);
120972 +
120973 + for (arg = TYPE_ARG_TYPES(type); arg != NULL_TREE && fn_hash_data->tree_codes_len < CODES_LIMIT; arg = TREE_CHAIN(arg))
120974 + set_node_codes(TREE_VALUE(arg), fn_hash_data);
120975 +}
120976 +
120977 +static const struct size_overflow_hash *get_proper_hash_chain(const struct size_overflow_hash *entry, const char *func_name)
120978 +{
120979 + while (entry) {
120980 + if (!strcmp(entry->name, func_name))
120981 + return entry;
120982 + entry = entry->next;
120983 + }
120984 + return NULL;
120985 +}
120986 +
120987 +const struct size_overflow_hash *get_function_hash(const_tree fndecl)
120988 +{
120989 + const struct size_overflow_hash *entry;
120990 + struct function_hash fn_hash_data;
120991 + const char *func_name;
120992 +
120993 + // skip builtins __builtin_constant_p
120994 + if (DECL_BUILT_IN(fndecl))
120995 + return NULL;
120996 +
120997 + fn_hash_data.fndecl = fndecl;
120998 + fn_hash_data.tree_codes_len = 0;
120999 +
121000 + set_function_codes(&fn_hash_data);
121001 + gcc_assert(fn_hash_data.tree_codes_len != 0);
121002 +
121003 + func_name = DECL_NAME_POINTER(fn_hash_data.fndecl);
121004 + set_hash(func_name, &fn_hash_data);
121005 +
121006 + entry = size_overflow_hash[fn_hash_data.hash];
121007 + entry = get_proper_hash_chain(entry, func_name);
121008 + if (entry)
121009 + return entry;
121010 + entry = size_overflow_hash_aux[fn_hash_data.hash];
121011 + return get_proper_hash_chain(entry, func_name);
121012 +}
121013 +
121014 +static void print_missing_msg(const_tree func, unsigned int argnum)
121015 +{
121016 + location_t loc;
121017 + const char *curfunc;
121018 + struct function_hash fn_hash_data;
121019 +
121020 + fn_hash_data.fndecl = DECL_ORIGIN(func);
121021 + fn_hash_data.tree_codes_len = 0;
121022 +
121023 + loc = DECL_SOURCE_LOCATION(fn_hash_data.fndecl);
121024 + curfunc = DECL_NAME_POINTER(fn_hash_data.fndecl);
121025 +
121026 + set_function_codes(&fn_hash_data);
121027 + set_hash(curfunc, &fn_hash_data);
121028 +
121029 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, fn_hash_data.hash);
121030 +}
121031 +
121032 +unsigned int find_arg_number_tree(const_tree arg, const_tree func)
121033 +{
121034 + tree var;
121035 + unsigned int argnum = 1;
121036 +
121037 + if (TREE_CODE(arg) == SSA_NAME)
121038 + arg = SSA_NAME_VAR(arg);
121039 +
121040 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var), argnum++) {
121041 + if (!operand_equal_p(arg, var, 0) && strcmp(DECL_NAME_POINTER(var), DECL_NAME_POINTER(arg)))
121042 + continue;
121043 + if (!skip_types(var))
121044 + return argnum;
121045 + }
121046 +
121047 + return CANNOT_FIND_ARG;
121048 +}
121049 +
121050 +static const char *get_asm_string(const_gimple stmt)
121051 +{
121052 + if (!stmt)
121053 + return NULL;
121054 + if (gimple_code(stmt) != GIMPLE_ASM)
121055 + return NULL;
121056 +
121057 + return gimple_asm_string(stmt);
121058 +}
121059 +
121060 +bool is_size_overflow_intentional_asm_turn_off(const_gimple stmt)
121061 +{
121062 + const char *str;
121063 +
121064 + str = get_asm_string(stmt);
121065 + if (!str)
121066 + return false;
121067 + return !strncmp(str, TURN_OFF_ASM_STR, sizeof(TURN_OFF_ASM_STR) - 1);
121068 +}
121069 +
121070 +bool is_size_overflow_intentional_asm_yes(const_gimple stmt)
121071 +{
121072 + const char *str;
121073 +
121074 + str = get_asm_string(stmt);
121075 + if (!str)
121076 + return false;
121077 + return !strncmp(str, YES_ASM_STR, sizeof(YES_ASM_STR) - 1);
121078 +}
121079 +
121080 +bool is_size_overflow_asm(const_gimple stmt)
121081 +{
121082 + const char *str;
121083 +
121084 + str = get_asm_string(stmt);
121085 + if (!str)
121086 + return false;
121087 + return !strncmp(str, OK_ASM_STR, sizeof(OK_ASM_STR) - 1);
121088 +}
121089 +
121090 +bool is_a_return_check(const_tree node)
121091 +{
121092 + if (TREE_CODE(node) == FUNCTION_DECL)
121093 + return true;
121094 +
121095 + gcc_assert(TREE_CODE(node) == PARM_DECL);
121096 + return false;
121097 +}
121098 +
121099 +// Get the argnum of a function decl, if node is a return then the argnum is 0
121100 +unsigned int get_function_num(const_tree node, const_tree orig_fndecl)
121101 +{
121102 + if (is_a_return_check(node))
121103 + return 0;
121104 + else
121105 + return find_arg_number_tree(node, orig_fndecl);
121106 +}
121107 +
121108 +unsigned int get_correct_arg_count(unsigned int argnum, const_tree fndecl)
121109 +{
121110 + const struct size_overflow_hash *hash;
121111 + unsigned int new_argnum;
121112 + tree arg;
121113 + const_tree origarg;
121114 +
121115 + if (argnum == 0)
121116 + return argnum;
121117 +
121118 + hash = get_function_hash(fndecl);
121119 + if (hash && hash->param & (1U << argnum))
121120 + return argnum;
121121 +
121122 + if (DECL_EXTERNAL(fndecl))
121123 + return argnum;
121124 +
121125 + origarg = DECL_ARGUMENTS(DECL_ORIGIN(fndecl));
121126 + argnum--;
121127 + while (origarg && argnum) {
121128 + origarg = TREE_CHAIN(origarg);
121129 + argnum--;
121130 + }
121131 + gcc_assert(argnum == 0);
121132 + gcc_assert(origarg != NULL_TREE);
121133 +
121134 + for (arg = DECL_ARGUMENTS(fndecl), new_argnum = 1; arg; arg = TREE_CHAIN(arg), new_argnum++)
121135 + if (operand_equal_p(origarg, arg, 0) || !strcmp(DECL_NAME_POINTER(origarg), DECL_NAME_POINTER(arg)))
121136 + return new_argnum;
121137 +
121138 + return CANNOT_FIND_ARG;
121139 +}
121140 +
121141 +static bool is_in_hash_table(const_tree fndecl, unsigned int num)
121142 +{
121143 + const struct size_overflow_hash *hash;
121144 +
121145 + hash = get_function_hash(fndecl);
121146 + if (hash && (hash->param & (1U << num)))
121147 + return true;
121148 + return false;
121149 +}
121150 +
121151 +/* Check if the function has a size_overflow attribute or it is in the size_overflow hash table.
121152 + * If the function is missing everywhere then print the missing message into stderr.
121153 + */
121154 +bool is_missing_function(const_tree orig_fndecl, unsigned int num)
121155 +{
121156 + switch (DECL_FUNCTION_CODE(orig_fndecl)) {
121157 +#if BUILDING_GCC_VERSION >= 4008
121158 + case BUILT_IN_BSWAP16:
121159 +#endif
121160 + case BUILT_IN_BSWAP32:
121161 + case BUILT_IN_BSWAP64:
121162 + case BUILT_IN_EXPECT:
121163 + case BUILT_IN_MEMCMP:
121164 + return false;
121165 + default:
121166 + break;
121167 + }
121168 +
121169 + // skip test.c
121170 + if (strcmp(DECL_NAME_POINTER(current_function_decl), "coolmalloc")) {
121171 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(orig_fndecl)))
121172 + warning(0, "unnecessary size_overflow attribute on: %s\n", DECL_NAME_POINTER(orig_fndecl));
121173 + }
121174 +
121175 + if (is_in_hash_table(orig_fndecl, num))
121176 + return false;
121177 +
121178 + print_missing_msg(orig_fndecl, num);
121179 + return true;
121180 +}
121181 +
121182 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
121183 new file mode 100644
121184 index 0000000..dd94983
121185 --- /dev/null
121186 +++ b/tools/gcc/stackleak_plugin.c
121187 @@ -0,0 +1,376 @@
121188 +/*
121189 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
121190 + * Licensed under the GPL v2
121191 + *
121192 + * Note: the choice of the license means that the compilation process is
121193 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
121194 + * but for the kernel it doesn't matter since it doesn't link against
121195 + * any of the gcc libraries
121196 + *
121197 + * gcc plugin to help implement various PaX features
121198 + *
121199 + * - track lowest stack pointer
121200 + *
121201 + * TODO:
121202 + * - initialize all local variables
121203 + *
121204 + * BUGS:
121205 + * - none known
121206 + */
121207 +
121208 +#include "gcc-common.h"
121209 +
121210 +int plugin_is_GPL_compatible;
121211 +
121212 +static int track_frame_size = -1;
121213 +static const char track_function[] = "pax_track_stack";
121214 +static const char check_function[] = "pax_check_alloca";
121215 +static tree track_function_decl, check_function_decl;
121216 +static bool init_locals;
121217 +
121218 +static struct plugin_info stackleak_plugin_info = {
121219 + .version = "201402131920",
121220 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
121221 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
121222 +};
121223 +
121224 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
121225 +{
121226 + gimple check_alloca;
121227 + tree alloca_size;
121228 +
121229 + // insert call to void pax_check_alloca(unsigned long size)
121230 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
121231 + check_alloca = gimple_build_call(check_function_decl, 1, alloca_size);
121232 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
121233 +}
121234 +
121235 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
121236 +{
121237 + gimple track_stack;
121238 +
121239 + // insert call to void pax_track_stack(void)
121240 + track_stack = gimple_build_call(track_function_decl, 0);
121241 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
121242 +}
121243 +
121244 +static bool is_alloca(gimple stmt)
121245 +{
121246 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
121247 + return true;
121248 +
121249 +#if BUILDING_GCC_VERSION >= 4007
121250 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
121251 + return true;
121252 +#endif
121253 +
121254 + return false;
121255 +}
121256 +
121257 +static unsigned int execute_stackleak_tree_instrument(void)
121258 +{
121259 + basic_block bb, entry_bb;
121260 + bool prologue_instrumented = false, is_leaf = true;
121261 +
121262 + entry_bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb;
121263 +
121264 + // 1. loop through BBs and GIMPLE statements
121265 + FOR_EACH_BB_FN(bb, cfun) {
121266 + gimple_stmt_iterator gsi;
121267 +
121268 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
121269 + gimple stmt;
121270 +
121271 + stmt = gsi_stmt(gsi);
121272 +
121273 + if (is_gimple_call(stmt))
121274 + is_leaf = false;
121275 +
121276 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
121277 + if (!is_alloca(stmt))
121278 + continue;
121279 +
121280 + // 2. insert stack overflow check before each __builtin_alloca call
121281 + stackleak_check_alloca(&gsi);
121282 +
121283 + // 3. insert track call after each __builtin_alloca call
121284 + stackleak_add_instrumentation(&gsi);
121285 + if (bb == entry_bb)
121286 + prologue_instrumented = true;
121287 + }
121288 + }
121289 +
121290 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
121291 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
121292 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
121293 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
121294 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
121295 + return 0;
121296 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
121297 + return 0;
121298 +
121299 + // 4. insert track call at the beginning
121300 + if (!prologue_instrumented) {
121301 + gimple_stmt_iterator gsi;
121302 +
121303 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
121304 + if (dom_info_available_p(CDI_DOMINATORS))
121305 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
121306 + gsi = gsi_start_bb(bb);
121307 + stackleak_add_instrumentation(&gsi);
121308 + }
121309 +
121310 + return 0;
121311 +}
121312 +
121313 +static unsigned int execute_stackleak_final(void)
121314 +{
121315 + rtx insn, next;
121316 +
121317 + if (cfun->calls_alloca)
121318 + return 0;
121319 +
121320 + // keep calls only if function frame is big enough
121321 + if (get_frame_size() >= track_frame_size)
121322 + return 0;
121323 +
121324 + // 1. find pax_track_stack calls
121325 + for (insn = get_insns(); insn; insn = next) {
121326 + // 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))
121327 + rtx body;
121328 +
121329 + next = NEXT_INSN(insn);
121330 + if (!CALL_P(insn))
121331 + continue;
121332 + body = PATTERN(insn);
121333 + if (GET_CODE(body) != CALL)
121334 + continue;
121335 + body = XEXP(body, 0);
121336 + if (GET_CODE(body) != MEM)
121337 + continue;
121338 + body = XEXP(body, 0);
121339 + if (GET_CODE(body) != SYMBOL_REF)
121340 + continue;
121341 +// if (strcmp(XSTR(body, 0), track_function))
121342 + if (SYMBOL_REF_DECL(body) != track_function_decl)
121343 + continue;
121344 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
121345 + // 2. delete call
121346 + delete_insn_and_edges(insn);
121347 +#if BUILDING_GCC_VERSION >= 4007
121348 + if (GET_CODE(next) == NOTE && NOTE_KIND(next) == NOTE_INSN_CALL_ARG_LOCATION) {
121349 + insn = next;
121350 + next = NEXT_INSN(insn);
121351 + delete_insn_and_edges(insn);
121352 + }
121353 +#endif
121354 + }
121355 +
121356 +// print_simple_rtl(stderr, get_insns());
121357 +// print_rtl(stderr, get_insns());
121358 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
121359 +
121360 + return 0;
121361 +}
121362 +
121363 +static bool gate_stackleak_track_stack(void)
121364 +{
121365 + return track_frame_size >= 0;
121366 +}
121367 +
121368 +static void stackleak_start_unit(void *gcc_data, void *user_data)
121369 +{
121370 + tree fntype;
121371 +
121372 + // void pax_track_stack(void)
121373 + fntype = build_function_type_list(void_type_node, NULL_TREE);
121374 + track_function_decl = build_fn_decl(track_function, fntype);
121375 + DECL_ASSEMBLER_NAME(track_function_decl); // for LTO
121376 + TREE_PUBLIC(track_function_decl) = 1;
121377 + DECL_EXTERNAL(track_function_decl) = 1;
121378 + DECL_ARTIFICIAL(track_function_decl) = 1;
121379 +
121380 + // void pax_check_alloca(unsigned long)
121381 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
121382 + check_function_decl = build_fn_decl(check_function, fntype);
121383 + DECL_ASSEMBLER_NAME(check_function_decl); // for LTO
121384 + TREE_PUBLIC(check_function_decl) = 1;
121385 + DECL_EXTERNAL(check_function_decl) = 1;
121386 + DECL_ARTIFICIAL(check_function_decl) = 1;
121387 +}
121388 +
121389 +#if BUILDING_GCC_VERSION >= 4009
121390 +static const struct pass_data stackleak_tree_instrument_pass_data = {
121391 +#else
121392 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
121393 + .pass = {
121394 +#endif
121395 + .type = GIMPLE_PASS,
121396 + .name = "stackleak_tree_instrument",
121397 +#if BUILDING_GCC_VERSION >= 4008
121398 + .optinfo_flags = OPTGROUP_NONE,
121399 +#endif
121400 +#if BUILDING_GCC_VERSION >= 4009
121401 + .has_gate = true,
121402 + .has_execute = true,
121403 +#else
121404 + .gate = gate_stackleak_track_stack,
121405 + .execute = execute_stackleak_tree_instrument,
121406 + .sub = NULL,
121407 + .next = NULL,
121408 + .static_pass_number = 0,
121409 +#endif
121410 + .tv_id = TV_NONE,
121411 + .properties_required = PROP_gimple_leh | PROP_cfg,
121412 + .properties_provided = 0,
121413 + .properties_destroyed = 0,
121414 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
121415 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa | TODO_rebuild_cgraph_edges
121416 +#if BUILDING_GCC_VERSION < 4009
121417 + }
121418 +#endif
121419 +};
121420 +
121421 +#if BUILDING_GCC_VERSION >= 4009
121422 +static const struct pass_data stackleak_final_rtl_opt_pass_data = {
121423 +#else
121424 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
121425 + .pass = {
121426 +#endif
121427 + .type = RTL_PASS,
121428 + .name = "stackleak_final",
121429 +#if BUILDING_GCC_VERSION >= 4008
121430 + .optinfo_flags = OPTGROUP_NONE,
121431 +#endif
121432 +#if BUILDING_GCC_VERSION >= 4009
121433 + .has_gate = true,
121434 + .has_execute = true,
121435 +#else
121436 + .gate = gate_stackleak_track_stack,
121437 + .execute = execute_stackleak_final,
121438 + .sub = NULL,
121439 + .next = NULL,
121440 + .static_pass_number = 0,
121441 +#endif
121442 + .tv_id = TV_NONE,
121443 + .properties_required = 0,
121444 + .properties_provided = 0,
121445 + .properties_destroyed = 0,
121446 + .todo_flags_start = 0,
121447 + .todo_flags_finish = TODO_dump_func
121448 +#if BUILDING_GCC_VERSION < 4009
121449 + }
121450 +#endif
121451 +};
121452 +
121453 +#if BUILDING_GCC_VERSION >= 4009
121454 +namespace {
121455 +class stackleak_tree_instrument_pass : public gimple_opt_pass {
121456 +public:
121457 + stackleak_tree_instrument_pass() : gimple_opt_pass(stackleak_tree_instrument_pass_data, g) {}
121458 + bool gate() { return gate_stackleak_track_stack(); }
121459 + unsigned int execute() { return execute_stackleak_tree_instrument(); }
121460 +};
121461 +
121462 +class stackleak_final_rtl_opt_pass : public rtl_opt_pass {
121463 +public:
121464 + stackleak_final_rtl_opt_pass() : rtl_opt_pass(stackleak_final_rtl_opt_pass_data, g) {}
121465 + bool gate() { return gate_stackleak_track_stack(); }
121466 + unsigned int execute() { return execute_stackleak_final(); }
121467 +};
121468 +}
121469 +
121470 +static opt_pass *make_stackleak_tree_instrument_pass(void)
121471 +{
121472 + return new stackleak_tree_instrument_pass();
121473 +}
121474 +
121475 +static opt_pass *make_stackleak_final_rtl_opt_pass(void)
121476 +{
121477 + return new stackleak_final_rtl_opt_pass();
121478 +}
121479 +#else
121480 +static struct opt_pass *make_stackleak_tree_instrument_pass(void)
121481 +{
121482 + return &stackleak_tree_instrument_pass.pass;
121483 +}
121484 +
121485 +static struct opt_pass *make_stackleak_final_rtl_opt_pass(void)
121486 +{
121487 + return &stackleak_final_rtl_opt_pass.pass;
121488 +}
121489 +#endif
121490 +
121491 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
121492 +{
121493 + const char * const plugin_name = plugin_info->base_name;
121494 + const int argc = plugin_info->argc;
121495 + const struct plugin_argument * const argv = plugin_info->argv;
121496 + int i;
121497 + struct register_pass_info stackleak_tree_instrument_pass_info;
121498 + struct register_pass_info stackleak_final_pass_info;
121499 + static const struct ggc_root_tab gt_ggc_r_gt_stackleak[] = {
121500 + {
121501 + .base = &track_function_decl,
121502 + .nelt = 1,
121503 + .stride = sizeof(track_function_decl),
121504 + .cb = &gt_ggc_mx_tree_node,
121505 + .pchw = &gt_pch_nx_tree_node
121506 + },
121507 + {
121508 + .base = &check_function_decl,
121509 + .nelt = 1,
121510 + .stride = sizeof(check_function_decl),
121511 + .cb = &gt_ggc_mx_tree_node,
121512 + .pchw = &gt_pch_nx_tree_node
121513 + },
121514 + LAST_GGC_ROOT_TAB
121515 + };
121516 +
121517 + stackleak_tree_instrument_pass_info.pass = make_stackleak_tree_instrument_pass();
121518 +// stackleak_tree_instrument_pass_info.reference_pass_name = "tree_profile";
121519 + stackleak_tree_instrument_pass_info.reference_pass_name = "optimized";
121520 + stackleak_tree_instrument_pass_info.ref_pass_instance_number = 1;
121521 + stackleak_tree_instrument_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
121522 +
121523 + stackleak_final_pass_info.pass = make_stackleak_final_rtl_opt_pass();
121524 + stackleak_final_pass_info.reference_pass_name = "final";
121525 + stackleak_final_pass_info.ref_pass_instance_number = 1;
121526 + stackleak_final_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
121527 +
121528 + if (!plugin_default_version_check(version, &gcc_version)) {
121529 + error(G_("incompatible gcc/plugin versions"));
121530 + return 1;
121531 + }
121532 +
121533 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
121534 +
121535 + for (i = 0; i < argc; ++i) {
121536 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
121537 + if (!argv[i].value) {
121538 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
121539 + continue;
121540 + }
121541 + track_frame_size = atoi(argv[i].value);
121542 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
121543 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
121544 + continue;
121545 + }
121546 + if (!strcmp(argv[i].key, "initialize-locals")) {
121547 + if (argv[i].value) {
121548 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
121549 + continue;
121550 + }
121551 + init_locals = true;
121552 + continue;
121553 + }
121554 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
121555 + }
121556 +
121557 + register_callback(plugin_name, PLUGIN_START_UNIT, &stackleak_start_unit, NULL);
121558 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_stackleak);
121559 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
121560 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
121561 +
121562 + return 0;
121563 +}
121564 diff --git a/tools/gcc/structleak_plugin.c b/tools/gcc/structleak_plugin.c
121565 new file mode 100644
121566 index 0000000..4ee2231
121567 --- /dev/null
121568 +++ b/tools/gcc/structleak_plugin.c
121569 @@ -0,0 +1,274 @@
121570 +/*
121571 + * Copyright 2013-2014 by PaX Team <pageexec@freemail.hu>
121572 + * Licensed under the GPL v2
121573 + *
121574 + * Note: the choice of the license means that the compilation process is
121575 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
121576 + * but for the kernel it doesn't matter since it doesn't link against
121577 + * any of the gcc libraries
121578 + *
121579 + * gcc plugin to forcibly initialize certain local variables that could
121580 + * otherwise leak kernel stack to userland if they aren't properly initialized
121581 + * by later code
121582 + *
121583 + * Homepage: http://pax.grsecurity.net/
121584 + *
121585 + * Usage:
121586 + * $ # for 4.5/4.6/C based 4.7
121587 + * $ 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
121588 + * $ # for C++ based 4.7/4.8+
121589 + * $ 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
121590 + * $ gcc -fplugin=./structleak_plugin.so test.c -O2
121591 + *
121592 + * TODO: eliminate redundant initializers
121593 + * increase type coverage
121594 + */
121595 +
121596 +#include "gcc-common.h"
121597 +
121598 +// unused C type flag in all versions 4.5-4.9
121599 +#define TYPE_USERSPACE(TYPE) TYPE_LANG_FLAG_3(TYPE)
121600 +
121601 +int plugin_is_GPL_compatible;
121602 +
121603 +static struct plugin_info structleak_plugin_info = {
121604 + .version = "201401260140",
121605 + .help = "disable\tdo not activate plugin\n",
121606 +};
121607 +
121608 +static tree handle_user_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
121609 +{
121610 + *no_add_attrs = true;
121611 +
121612 + // check for types? for now accept everything linux has to offer
121613 + if (TREE_CODE(*node) != FIELD_DECL)
121614 + return NULL_TREE;
121615 +
121616 + *no_add_attrs = false;
121617 + return NULL_TREE;
121618 +}
121619 +
121620 +static struct attribute_spec user_attr = {
121621 + .name = "user",
121622 + .min_length = 0,
121623 + .max_length = 0,
121624 + .decl_required = false,
121625 + .type_required = false,
121626 + .function_type_required = false,
121627 + .handler = handle_user_attribute,
121628 +#if BUILDING_GCC_VERSION >= 4007
121629 + .affects_type_identity = true
121630 +#endif
121631 +};
121632 +
121633 +static void register_attributes(void *event_data, void *data)
121634 +{
121635 + register_attribute(&user_attr);
121636 +// register_attribute(&force_attr);
121637 +}
121638 +
121639 +static tree get_field_type(tree field)
121640 +{
121641 + return strip_array_types(TREE_TYPE(field));
121642 +}
121643 +
121644 +static bool is_userspace_type(tree type)
121645 +{
121646 + tree field;
121647 +
121648 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
121649 + tree fieldtype = get_field_type(field);
121650 + enum tree_code code = TREE_CODE(fieldtype);
121651 +
121652 + if (code == RECORD_TYPE || code == UNION_TYPE)
121653 + if (is_userspace_type(fieldtype))
121654 + return true;
121655 +
121656 + if (lookup_attribute("user", DECL_ATTRIBUTES(field)))
121657 + return true;
121658 + }
121659 + return false;
121660 +}
121661 +
121662 +static void finish_type(void *event_data, void *data)
121663 +{
121664 + tree type = (tree)event_data;
121665 +
121666 + if (TYPE_USERSPACE(type))
121667 + return;
121668 +
121669 + if (is_userspace_type(type))
121670 + TYPE_USERSPACE(type) = 1;
121671 +}
121672 +
121673 +static void initialize(tree var)
121674 +{
121675 + basic_block bb;
121676 + gimple_stmt_iterator gsi;
121677 + tree initializer;
121678 + gimple init_stmt;
121679 +
121680 + // this is the original entry bb before the forced split
121681 + // TODO: check further BBs in case more splits occured before us
121682 + bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb->next_bb;
121683 +
121684 + // first check if the variable is already initialized, warn otherwise
121685 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
121686 + gimple stmt = gsi_stmt(gsi);
121687 + tree rhs1;
121688 +
121689 + // we're looking for an assignment of a single rhs...
121690 + if (!gimple_assign_single_p(stmt))
121691 + continue;
121692 + rhs1 = gimple_assign_rhs1(stmt);
121693 +#if BUILDING_GCC_VERSION >= 4007
121694 + // ... of a non-clobbering expression...
121695 + if (TREE_CLOBBER_P(rhs1))
121696 + continue;
121697 +#endif
121698 + // ... to our variable...
121699 + if (gimple_get_lhs(stmt) != var)
121700 + continue;
121701 + // if it's an initializer then we're good
121702 + if (TREE_CODE(rhs1) == CONSTRUCTOR)
121703 + return;
121704 + }
121705 +
121706 + // these aren't the 0days you're looking for
121707 +// inform(DECL_SOURCE_LOCATION(var), "userspace variable will be forcibly initialized");
121708 +
121709 + // build the initializer expression
121710 + initializer = build_constructor(TREE_TYPE(var), NULL);
121711 +
121712 + // build the initializer stmt
121713 + init_stmt = gimple_build_assign(var, initializer);
121714 + gsi = gsi_start_bb(ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb);
121715 + gsi_insert_before(&gsi, init_stmt, GSI_NEW_STMT);
121716 + update_stmt(init_stmt);
121717 +}
121718 +
121719 +static unsigned int handle_function(void)
121720 +{
121721 + basic_block bb;
121722 + unsigned int ret = 0;
121723 + tree var;
121724 + unsigned int i;
121725 +
121726 + // split the first bb where we can put the forced initializers
121727 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
121728 + if (dom_info_available_p(CDI_DOMINATORS))
121729 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
121730 +
121731 + // enumarate all local variables and forcibly initialize our targets
121732 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
121733 + tree type = TREE_TYPE(var);
121734 +
121735 + gcc_assert(DECL_P(var));
121736 + if (!auto_var_in_fn_p(var, current_function_decl))
121737 + continue;
121738 +
121739 + // only care about structure types
121740 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
121741 + continue;
121742 +
121743 + // if the type is of interest, examine the variable
121744 + if (TYPE_USERSPACE(type))
121745 + initialize(var);
121746 + }
121747 +
121748 + return ret;
121749 +}
121750 +
121751 +#if BUILDING_GCC_VERSION >= 4009
121752 +static const struct pass_data structleak_pass_data = {
121753 +#else
121754 +static struct gimple_opt_pass structleak_pass = {
121755 + .pass = {
121756 +#endif
121757 + .type = GIMPLE_PASS,
121758 + .name = "structleak",
121759 +#if BUILDING_GCC_VERSION >= 4008
121760 + .optinfo_flags = OPTGROUP_NONE,
121761 +#endif
121762 +#if BUILDING_GCC_VERSION >= 4009
121763 + .has_gate = false,
121764 + .has_execute = true,
121765 +#else
121766 + .gate = NULL,
121767 + .execute = handle_function,
121768 + .sub = NULL,
121769 + .next = NULL,
121770 + .static_pass_number = 0,
121771 +#endif
121772 + .tv_id = TV_NONE,
121773 + .properties_required = PROP_cfg,
121774 + .properties_provided = 0,
121775 + .properties_destroyed = 0,
121776 + .todo_flags_start = 0,
121777 + .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
121778 +#if BUILDING_GCC_VERSION < 4009
121779 + }
121780 +#endif
121781 +};
121782 +
121783 +#if BUILDING_GCC_VERSION >= 4009
121784 +namespace {
121785 +class structleak_pass : public gimple_opt_pass {
121786 +public:
121787 + structleak_pass() : gimple_opt_pass(structleak_pass_data, g) {}
121788 + unsigned int execute() { return handle_function(); }
121789 +};
121790 +}
121791 +
121792 +static opt_pass *make_structleak_pass(void)
121793 +{
121794 + return new structleak_pass();
121795 +}
121796 +#else
121797 +static struct opt_pass *make_structleak_pass(void)
121798 +{
121799 + return &structleak_pass.pass;
121800 +}
121801 +#endif
121802 +
121803 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
121804 +{
121805 + int i;
121806 + const char * const plugin_name = plugin_info->base_name;
121807 + const int argc = plugin_info->argc;
121808 + const struct plugin_argument * const argv = plugin_info->argv;
121809 + bool enable = true;
121810 + struct register_pass_info structleak_pass_info;
121811 +
121812 + structleak_pass_info.pass = make_structleak_pass();
121813 + structleak_pass_info.reference_pass_name = "ssa";
121814 + structleak_pass_info.ref_pass_instance_number = 1;
121815 + structleak_pass_info.pos_op = PASS_POS_INSERT_AFTER;
121816 +
121817 + if (!plugin_default_version_check(version, &gcc_version)) {
121818 + error(G_("incompatible gcc/plugin versions"));
121819 + return 1;
121820 + }
121821 +
121822 + if (strcmp(lang_hooks.name, "GNU C")) {
121823 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
121824 + enable = false;
121825 + }
121826 +
121827 + for (i = 0; i < argc; ++i) {
121828 + if (!strcmp(argv[i].key, "disable")) {
121829 + enable = false;
121830 + continue;
121831 + }
121832 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
121833 + }
121834 +
121835 + register_callback(plugin_name, PLUGIN_INFO, NULL, &structleak_plugin_info);
121836 + if (enable) {
121837 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &structleak_pass_info);
121838 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
121839 + }
121840 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
121841 +
121842 + return 0;
121843 +}
121844 diff --git a/tools/include/linux/compiler.h b/tools/include/linux/compiler.h
121845 index fbc6665..5e9ce79 100644
121846 --- a/tools/include/linux/compiler.h
121847 +++ b/tools/include/linux/compiler.h
121848 @@ -35,4 +35,12 @@
121849 # define unlikely(x) __builtin_expect(!!(x), 0)
121850 #endif
121851
121852 +#ifndef __size_overflow
121853 +# define __size_overflow(...)
121854 +#endif
121855 +
121856 +#ifndef __intentional_overflow
121857 +# define __intentional_overflow(...)
121858 +#endif
121859 +
121860 #endif /* _TOOLS_LINUX_COMPILER_H */
121861 diff --git a/tools/lib/api/Makefile b/tools/lib/api/Makefile
121862 index ce00f7e..0aca5e4 100644
121863 --- a/tools/lib/api/Makefile
121864 +++ b/tools/lib/api/Makefile
121865 @@ -16,7 +16,7 @@ LIB_OBJS += $(OUTPUT)fs/fs.o
121866
121867 LIBFILE = libapikfs.a
121868
121869 -CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
121870 +CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
121871 EXTLIBS = -lelf -lpthread -lrt -lm
121872 ALL_CFLAGS = $(CFLAGS) $(BASIC_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
121873 ALL_LDFLAGS = $(LDFLAGS)
121874 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
121875 index 6789d788..4afd019e 100644
121876 --- a/tools/perf/util/include/asm/alternative-asm.h
121877 +++ b/tools/perf/util/include/asm/alternative-asm.h
121878 @@ -5,4 +5,7 @@
121879
121880 #define altinstruction_entry #
121881
121882 + .macro pax_force_retaddr rip=0, reload=0
121883 + .endm
121884 +
121885 #endif
121886 diff --git a/tools/virtio/linux/uaccess.h b/tools/virtio/linux/uaccess.h
121887 index 0a578fe..b81f62d 100644
121888 --- a/tools/virtio/linux/uaccess.h
121889 +++ b/tools/virtio/linux/uaccess.h
121890 @@ -13,7 +13,7 @@ static inline void __chk_user_ptr(const volatile void *p, size_t size)
121891 ({ \
121892 typeof(ptr) __pu_ptr = (ptr); \
121893 __chk_user_ptr(__pu_ptr, sizeof(*__pu_ptr)); \
121894 - ACCESS_ONCE(*(__pu_ptr)) = x; \
121895 + ACCESS_ONCE_RW(*(__pu_ptr)) = x; \
121896 0; \
121897 })
121898
121899 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
121900 index 56baae8..2c889c2 100644
121901 --- a/virt/kvm/kvm_main.c
121902 +++ b/virt/kvm/kvm_main.c
121903 @@ -76,12 +76,17 @@ LIST_HEAD(vm_list);
121904
121905 static cpumask_var_t cpus_hardware_enabled;
121906 static int kvm_usage_count = 0;
121907 -static atomic_t hardware_enable_failed;
121908 +static atomic_unchecked_t hardware_enable_failed;
121909
121910 struct kmem_cache *kvm_vcpu_cache;
121911 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
121912
121913 -static __read_mostly struct preempt_ops kvm_preempt_ops;
121914 +static void kvm_sched_in(struct preempt_notifier *pn, int cpu);
121915 +static void kvm_sched_out(struct preempt_notifier *pn, struct task_struct *next);
121916 +static struct preempt_ops kvm_preempt_ops = {
121917 + .sched_in = kvm_sched_in,
121918 + .sched_out = kvm_sched_out,
121919 +};
121920
121921 struct dentry *kvm_debugfs_dir;
121922
121923 @@ -755,7 +760,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
121924 /* We can read the guest memory with __xxx_user() later on. */
121925 if ((mem->slot < KVM_USER_MEM_SLOTS) &&
121926 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
121927 - !access_ok(VERIFY_WRITE,
121928 + !access_ok_noprefault(VERIFY_WRITE,
121929 (void __user *)(unsigned long)mem->userspace_addr,
121930 mem->memory_size)))
121931 goto out;
121932 @@ -1612,9 +1617,17 @@ EXPORT_SYMBOL_GPL(kvm_read_guest_cached);
121933
121934 int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len)
121935 {
121936 - const void *zero_page = (const void *) __va(page_to_phys(ZERO_PAGE(0)));
121937 + int r;
121938 + unsigned long addr;
121939
121940 - return kvm_write_guest_page(kvm, gfn, zero_page, offset, len);
121941 + addr = gfn_to_hva(kvm, gfn);
121942 + if (kvm_is_error_hva(addr))
121943 + return -EFAULT;
121944 + r = __clear_user((void __user *)addr + offset, len);
121945 + if (r)
121946 + return -EFAULT;
121947 + mark_page_dirty(kvm, gfn);
121948 + return 0;
121949 }
121950 EXPORT_SYMBOL_GPL(kvm_clear_guest_page);
121951
121952 @@ -1864,7 +1877,7 @@ static int kvm_vcpu_release(struct inode *inode, struct file *filp)
121953 return 0;
121954 }
121955
121956 -static struct file_operations kvm_vcpu_fops = {
121957 +static file_operations_no_const kvm_vcpu_fops __read_only = {
121958 .release = kvm_vcpu_release,
121959 .unlocked_ioctl = kvm_vcpu_ioctl,
121960 #ifdef CONFIG_COMPAT
121961 @@ -2534,7 +2547,7 @@ out:
121962 }
121963 #endif
121964
121965 -static struct file_operations kvm_vm_fops = {
121966 +static file_operations_no_const kvm_vm_fops __read_only = {
121967 .release = kvm_vm_release,
121968 .unlocked_ioctl = kvm_vm_ioctl,
121969 #ifdef CONFIG_COMPAT
121970 @@ -2634,7 +2647,7 @@ out:
121971 return r;
121972 }
121973
121974 -static struct file_operations kvm_chardev_ops = {
121975 +static file_operations_no_const kvm_chardev_ops __read_only = {
121976 .unlocked_ioctl = kvm_dev_ioctl,
121977 .compat_ioctl = kvm_dev_ioctl,
121978 .llseek = noop_llseek,
121979 @@ -2660,7 +2673,7 @@ static void hardware_enable_nolock(void *junk)
121980
121981 if (r) {
121982 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
121983 - atomic_inc(&hardware_enable_failed);
121984 + atomic_inc_unchecked(&hardware_enable_failed);
121985 printk(KERN_INFO "kvm: enabling virtualization on "
121986 "CPU%d failed\n", cpu);
121987 }
121988 @@ -2716,10 +2729,10 @@ static int hardware_enable_all(void)
121989
121990 kvm_usage_count++;
121991 if (kvm_usage_count == 1) {
121992 - atomic_set(&hardware_enable_failed, 0);
121993 + atomic_set_unchecked(&hardware_enable_failed, 0);
121994 on_each_cpu(hardware_enable_nolock, NULL, 1);
121995
121996 - if (atomic_read(&hardware_enable_failed)) {
121997 + if (atomic_read_unchecked(&hardware_enable_failed)) {
121998 hardware_disable_all_nolock();
121999 r = -EBUSY;
122000 }
122001 @@ -3123,7 +3136,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
122002 kvm_arch_vcpu_put(vcpu);
122003 }
122004
122005 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
122006 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
122007 struct module *module)
122008 {
122009 int r;
122010 @@ -3170,7 +3183,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
122011 if (!vcpu_align)
122012 vcpu_align = __alignof__(struct kvm_vcpu);
122013 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
122014 - 0, NULL);
122015 + SLAB_USERCOPY, NULL);
122016 if (!kvm_vcpu_cache) {
122017 r = -ENOMEM;
122018 goto out_free_3;
122019 @@ -3180,9 +3193,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
122020 if (r)
122021 goto out_free;
122022
122023 + pax_open_kernel();
122024 kvm_chardev_ops.owner = module;
122025 kvm_vm_fops.owner = module;
122026 kvm_vcpu_fops.owner = module;
122027 + pax_close_kernel();
122028
122029 r = misc_register(&kvm_dev);
122030 if (r) {
122031 @@ -3192,9 +3207,6 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
122032
122033 register_syscore_ops(&kvm_syscore_ops);
122034
122035 - kvm_preempt_ops.sched_in = kvm_sched_in;
122036 - kvm_preempt_ops.sched_out = kvm_sched_out;
122037 -
122038 r = kvm_init_debug();
122039 if (r) {
122040 printk(KERN_ERR "kvm: create debugfs files failed\n");